blob: 999552c83bbe144c7082d1b8a55929df333f3375 [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
11#include <linux/module.h>
12#include <linux/moduleparam.h>
13#include <linux/string.h>
14#include <linux/errno.h>
15#include <linux/kernel.h>
16#include <linux/etherdevice.h>
17#include <linux/mii.h>
18#include <linux/ip.h>
19#include <linux/reboot.h>
20#include <linux/inetdevice.h>
21#include <linux/igmp.h>
22
23#include <net/ip.h>
24#include <net/arp.h>
25
26#include <asm/s390_rdev.h>
27
28#include "qeth_l3.h"
29#include "qeth_core_offl.h"
30
Frank Blaschka4a71df52008-02-15 09:19:42 +010031static int qeth_l3_set_offline(struct ccwgroup_device *);
32static int qeth_l3_recover(void *);
33static int qeth_l3_stop(struct net_device *);
34static void qeth_l3_set_multicast_list(struct net_device *);
35static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
36static int qeth_l3_register_addr_entry(struct qeth_card *,
37 struct qeth_ipaddr *);
38static int qeth_l3_deregister_addr_entry(struct qeth_card *,
39 struct qeth_ipaddr *);
40static int __qeth_l3_set_online(struct ccwgroup_device *, int);
41static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
42
43
44static int qeth_l3_isxdigit(char *buf)
45{
46 while (*buf) {
47 if (!isxdigit(*buf++))
48 return 0;
49 }
50 return 1;
51}
52
53void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
54{
55 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
56}
57
58int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
59{
60 int count = 0, rc = 0;
61 int in[4];
62 char c;
63
64 rc = sscanf(buf, "%u.%u.%u.%u%c",
65 &in[0], &in[1], &in[2], &in[3], &c);
66 if (rc != 4 && (rc != 5 || c != '\n'))
67 return -EINVAL;
68 for (count = 0; count < 4; count++) {
69 if (in[count] > 255)
70 return -EINVAL;
71 addr[count] = in[count];
72 }
73 return 0;
74}
75
76void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
77{
78 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
79 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
80 addr[0], addr[1], addr[2], addr[3],
81 addr[4], addr[5], addr[6], addr[7],
82 addr[8], addr[9], addr[10], addr[11],
83 addr[12], addr[13], addr[14], addr[15]);
84}
85
86int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
87{
88 const char *end, *end_tmp, *start;
89 __u16 *in;
90 char num[5];
91 int num2, cnt, out, found, save_cnt;
92 unsigned short in_tmp[8] = {0, };
93
94 cnt = out = found = save_cnt = num2 = 0;
95 end = start = buf;
96 in = (__u16 *) addr;
97 memset(in, 0, 16);
98 while (*end) {
99 end = strchr(start, ':');
100 if (end == NULL) {
101 end = buf + strlen(buf);
102 end_tmp = strchr(start, '\n');
103 if (end_tmp != NULL)
104 end = end_tmp;
105 out = 1;
106 }
107 if ((end - start)) {
108 memset(num, 0, 5);
109 if ((end - start) > 4)
110 return -EINVAL;
111 memcpy(num, start, end - start);
112 if (!qeth_l3_isxdigit(num))
113 return -EINVAL;
114 sscanf(start, "%x", &num2);
115 if (found)
116 in_tmp[save_cnt++] = num2;
117 else
118 in[cnt++] = num2;
119 if (out)
120 break;
121 } else {
122 if (found)
123 return -EINVAL;
124 found = 1;
125 }
126 start = ++end;
127 }
128 if (cnt + save_cnt > 8)
129 return -EINVAL;
130 cnt = 7;
131 while (save_cnt)
132 in[cnt--] = in_tmp[--save_cnt];
133 return 0;
134}
135
136void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
137 char *buf)
138{
139 if (proto == QETH_PROT_IPV4)
140 qeth_l3_ipaddr4_to_string(addr, buf);
141 else if (proto == QETH_PROT_IPV6)
142 qeth_l3_ipaddr6_to_string(addr, buf);
143}
144
145int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
146 __u8 *addr)
147{
148 if (proto == QETH_PROT_IPV4)
149 return qeth_l3_string_to_ipaddr4(buf, addr);
150 else if (proto == QETH_PROT_IPV6)
151 return qeth_l3_string_to_ipaddr6(buf, addr);
152 else
153 return -EINVAL;
154}
155
156static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
157{
158 int i, j;
159 u8 octet;
160
161 for (i = 0; i < len; ++i) {
162 octet = addr[i];
163 for (j = 7; j >= 0; --j) {
164 bits[i*8 + j] = octet & 1;
165 octet >>= 1;
166 }
167 }
168}
169
170static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
171 struct qeth_ipaddr *addr)
172{
173 struct qeth_ipato_entry *ipatoe;
174 u8 addr_bits[128] = {0, };
175 u8 ipatoe_bits[128] = {0, };
176 int rc = 0;
177
178 if (!card->ipato.enabled)
179 return 0;
180
181 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
182 (addr->proto == QETH_PROT_IPV4)? 4:16);
183 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
184 if (addr->proto != ipatoe->proto)
185 continue;
186 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
187 (ipatoe->proto == QETH_PROT_IPV4) ?
188 4 : 16);
189 if (addr->proto == QETH_PROT_IPV4)
190 rc = !memcmp(addr_bits, ipatoe_bits,
191 min(32, ipatoe->mask_bits));
192 else
193 rc = !memcmp(addr_bits, ipatoe_bits,
194 min(128, ipatoe->mask_bits));
195 if (rc)
196 break;
197 }
198 /* invert? */
199 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
200 rc = !rc;
201 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
202 rc = !rc;
203
204 return rc;
205}
206
207/*
208 * Add IP to be added to todo list. If there is already an "add todo"
209 * in this list we just incremenent the reference count.
210 * Returns 0 if we just incremented reference count.
211 */
212static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
213 struct qeth_ipaddr *addr, int add)
214{
215 struct qeth_ipaddr *tmp, *t;
216 int found = 0;
217
218 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
219 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
220 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
221 return 0;
222 if ((tmp->proto == QETH_PROT_IPV4) &&
223 (addr->proto == QETH_PROT_IPV4) &&
224 (tmp->type == addr->type) &&
225 (tmp->is_multicast == addr->is_multicast) &&
226 (tmp->u.a4.addr == addr->u.a4.addr) &&
227 (tmp->u.a4.mask == addr->u.a4.mask)) {
228 found = 1;
229 break;
230 }
231 if ((tmp->proto == QETH_PROT_IPV6) &&
232 (addr->proto == QETH_PROT_IPV6) &&
233 (tmp->type == addr->type) &&
234 (tmp->is_multicast == addr->is_multicast) &&
235 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
236 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
237 sizeof(struct in6_addr)) == 0)) {
238 found = 1;
239 break;
240 }
241 }
242 if (found) {
243 if (addr->users != 0)
244 tmp->users += addr->users;
245 else
246 tmp->users += add ? 1 : -1;
247 if (tmp->users == 0) {
248 list_del(&tmp->entry);
249 kfree(tmp);
250 }
251 return 0;
252 } else {
253 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
254 list_add(&addr->entry, card->ip_tbd_list);
255 else {
256 if (addr->users == 0)
257 addr->users += add ? 1 : -1;
258 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
259 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200260 QETH_DBF_TEXT(TRACE, 2, "tkovaddr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100261 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
262 }
263 list_add_tail(&addr->entry, card->ip_tbd_list);
264 }
265 return 1;
266 }
267}
268
269static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
270{
271 unsigned long flags;
272 int rc = 0;
273
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200274 QETH_DBF_TEXT(TRACE, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100275
276 if (addr->proto == QETH_PROT_IPV4)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200277 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100278 else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200279 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
280 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100281 }
282 spin_lock_irqsave(&card->ip_lock, flags);
283 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
284 spin_unlock_irqrestore(&card->ip_lock, flags);
285 return rc;
286}
287
288static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
289{
290 unsigned long flags;
291 int rc = 0;
292
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200293 QETH_DBF_TEXT(TRACE, 4, "addip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 if (addr->proto == QETH_PROT_IPV4)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200295 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100296 else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200297 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
298 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100299 }
300 spin_lock_irqsave(&card->ip_lock, flags);
301 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
302 spin_unlock_irqrestore(&card->ip_lock, flags);
303 return rc;
304}
305
306
307static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
308 enum qeth_prot_versions prot)
309{
310 struct qeth_ipaddr *addr;
311
312 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
313 if (addr == NULL) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100314 return NULL;
315 }
316 addr->type = QETH_IP_TYPE_NORMAL;
317 addr->proto = prot;
318 return addr;
319}
320
321static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
322{
323 struct qeth_ipaddr *iptodo;
324 unsigned long flags;
325
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200326 QETH_DBF_TEXT(TRACE, 4, "delmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
328 if (!iptodo) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200329 QETH_DBF_TEXT(TRACE, 2, "dmcnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100330 return;
331 }
332 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
333 spin_lock_irqsave(&card->ip_lock, flags);
334 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
335 kfree(iptodo);
336 spin_unlock_irqrestore(&card->ip_lock, flags);
337}
338
339/*
340 * Add/remove address to/from card's ip list, i.e. try to add or remove
341 * reference to/from an IP address that is already registered on the card.
342 * Returns:
343 * 0 address was on card and its reference count has been adjusted,
344 * but is still > 0, so nothing has to be done
345 * also returns 0 if card was not on card and the todo was to delete
346 * the address -> there is also nothing to be done
347 * 1 address was not on card and the todo is to add it to the card's ip
348 * list
349 * -1 address was on card and its reference count has been decremented
350 * to <= 0 by the todo -> address must be removed from card
351 */
352static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
353 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
354{
355 struct qeth_ipaddr *addr;
356 int found = 0;
357
358 list_for_each_entry(addr, &card->ip_list, entry) {
359 if ((addr->proto == QETH_PROT_IPV4) &&
360 (todo->proto == QETH_PROT_IPV4) &&
361 (addr->type == todo->type) &&
362 (addr->u.a4.addr == todo->u.a4.addr) &&
363 (addr->u.a4.mask == todo->u.a4.mask)) {
364 found = 1;
365 break;
366 }
367 if ((addr->proto == QETH_PROT_IPV6) &&
368 (todo->proto == QETH_PROT_IPV6) &&
369 (addr->type == todo->type) &&
370 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
371 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
372 sizeof(struct in6_addr)) == 0)) {
373 found = 1;
374 break;
375 }
376 }
377 if (found) {
378 addr->users += todo->users;
379 if (addr->users <= 0) {
380 *__addr = addr;
381 return -1;
382 } else {
383 /* for VIPA and RXIP limit refcount to 1 */
384 if (addr->type != QETH_IP_TYPE_NORMAL)
385 addr->users = 1;
386 return 0;
387 }
388 }
389 if (todo->users > 0) {
390 /* for VIPA and RXIP limit refcount to 1 */
391 if (todo->type != QETH_IP_TYPE_NORMAL)
392 todo->users = 1;
393 return 1;
394 } else
395 return 0;
396}
397
398static void __qeth_l3_delete_all_mc(struct qeth_card *card,
399 unsigned long *flags)
400{
Ursula Braun2d921c32008-04-01 10:26:53 +0200401 struct list_head fail_list;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100402 struct qeth_ipaddr *addr, *tmp;
403 int rc;
Ursula Braun2d921c32008-04-01 10:26:53 +0200404
405 INIT_LIST_HEAD(&fail_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406again:
407 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
408 if (addr->is_multicast) {
409 list_del(&addr->entry);
410 spin_unlock_irqrestore(&card->ip_lock, *flags);
411 rc = qeth_l3_deregister_addr_entry(card, addr);
412 spin_lock_irqsave(&card->ip_lock, *flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200413 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100414 kfree(addr);
Ursula Braun2d921c32008-04-01 10:26:53 +0200415 else
416 list_add_tail(&addr->entry, &fail_list);
417 goto again;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100418 }
419 }
Ursula Braun2d921c32008-04-01 10:26:53 +0200420 list_splice(&fail_list, &card->ip_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100421}
422
423static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
424{
425 struct list_head *tbd_list;
426 struct qeth_ipaddr *todo, *addr;
427 unsigned long flags;
428 int rc;
429
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200430 QETH_DBF_TEXT(TRACE, 2, "sdiplist");
431 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100432
433 spin_lock_irqsave(&card->ip_lock, flags);
434 tbd_list = card->ip_tbd_list;
435 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
436 if (!card->ip_tbd_list) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200437 QETH_DBF_TEXT(TRACE, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100438 card->ip_tbd_list = tbd_list;
439 spin_unlock_irqrestore(&card->ip_lock, flags);
440 return;
441 } else
442 INIT_LIST_HEAD(card->ip_tbd_list);
443
444 while (!list_empty(tbd_list)) {
445 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
446 list_del(&todo->entry);
447 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
448 __qeth_l3_delete_all_mc(card, &flags);
449 kfree(todo);
450 continue;
451 }
452 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
453 if (rc == 0) {
454 /* nothing to be done; only adjusted refcount */
455 kfree(todo);
456 } else if (rc == 1) {
457 /* new entry to be added to on-card list */
458 spin_unlock_irqrestore(&card->ip_lock, flags);
459 rc = qeth_l3_register_addr_entry(card, todo);
460 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200461 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100462 list_add_tail(&todo->entry, &card->ip_list);
463 else
464 kfree(todo);
465 } else if (rc == -1) {
466 /* on-card entry to be removed */
467 list_del_init(&addr->entry);
468 spin_unlock_irqrestore(&card->ip_lock, flags);
469 rc = qeth_l3_deregister_addr_entry(card, addr);
470 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200471 if (!rc || (rc == IPA_RC_PRIMARY_ALREADY_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100472 kfree(addr);
473 else
474 list_add_tail(&addr->entry, &card->ip_list);
475 kfree(todo);
476 }
477 }
478 spin_unlock_irqrestore(&card->ip_lock, flags);
479 kfree(tbd_list);
480}
481
482static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
483 int recover)
484{
485 struct qeth_ipaddr *addr, *tmp;
486 unsigned long flags;
487
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200488 QETH_DBF_TEXT(TRACE, 4, "clearip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100489 spin_lock_irqsave(&card->ip_lock, flags);
490 /* clear todo list */
491 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
492 list_del(&addr->entry);
493 kfree(addr);
494 }
495
496 while (!list_empty(&card->ip_list)) {
497 addr = list_entry(card->ip_list.next,
498 struct qeth_ipaddr, entry);
499 list_del_init(&addr->entry);
500 if (clean) {
501 spin_unlock_irqrestore(&card->ip_lock, flags);
502 qeth_l3_deregister_addr_entry(card, addr);
503 spin_lock_irqsave(&card->ip_lock, flags);
504 }
505 if (!recover || addr->is_multicast) {
506 kfree(addr);
507 continue;
508 }
509 list_add_tail(&addr->entry, card->ip_tbd_list);
510 }
511 spin_unlock_irqrestore(&card->ip_lock, flags);
512}
513
514static int qeth_l3_address_exists_in_list(struct list_head *list,
515 struct qeth_ipaddr *addr, int same_type)
516{
517 struct qeth_ipaddr *tmp;
518
519 list_for_each_entry(tmp, list, entry) {
520 if ((tmp->proto == QETH_PROT_IPV4) &&
521 (addr->proto == QETH_PROT_IPV4) &&
522 ((same_type && (tmp->type == addr->type)) ||
523 (!same_type && (tmp->type != addr->type))) &&
524 (tmp->u.a4.addr == addr->u.a4.addr))
525 return 1;
526
527 if ((tmp->proto == QETH_PROT_IPV6) &&
528 (addr->proto == QETH_PROT_IPV6) &&
529 ((same_type && (tmp->type == addr->type)) ||
530 (!same_type && (tmp->type != addr->type))) &&
531 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
532 sizeof(struct in6_addr)) == 0))
533 return 1;
534
535 }
536 return 0;
537}
538
539static int qeth_l3_send_setdelmc(struct qeth_card *card,
540 struct qeth_ipaddr *addr, int ipacmd)
541{
542 int rc;
543 struct qeth_cmd_buffer *iob;
544 struct qeth_ipa_cmd *cmd;
545
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200546 QETH_DBF_TEXT(TRACE, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100547
548 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
549 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
550 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
551 if (addr->proto == QETH_PROT_IPV6)
552 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
553 sizeof(struct in6_addr));
554 else
555 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
556
557 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
558
559 return rc;
560}
561
562static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
563{
564 int i, j;
565 for (i = 0; i < 16; i++) {
566 j = (len) - (i * 8);
567 if (j >= 8)
568 netmask[i] = 0xff;
569 else if (j > 0)
570 netmask[i] = (u8)(0xFF00 >> j);
571 else
572 netmask[i] = 0;
573 }
574}
575
576static int qeth_l3_send_setdelip(struct qeth_card *card,
577 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
578{
579 int rc;
580 struct qeth_cmd_buffer *iob;
581 struct qeth_ipa_cmd *cmd;
582 __u8 netmask[16];
583
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200584 QETH_DBF_TEXT(TRACE, 4, "setdelip");
585 QETH_DBF_TEXT_(TRACE, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100586
587 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
588 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
589 if (addr->proto == QETH_PROT_IPV6) {
590 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
591 sizeof(struct in6_addr));
592 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
593 memcpy(cmd->data.setdelip6.mask, netmask,
594 sizeof(struct in6_addr));
595 cmd->data.setdelip6.flags = flags;
596 } else {
597 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
598 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
599 cmd->data.setdelip4.flags = flags;
600 }
601
602 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
603
604 return rc;
605}
606
607static int qeth_l3_send_setrouting(struct qeth_card *card,
608 enum qeth_routing_types type, enum qeth_prot_versions prot)
609{
610 int rc;
611 struct qeth_ipa_cmd *cmd;
612 struct qeth_cmd_buffer *iob;
613
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200614 QETH_DBF_TEXT(TRACE, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100615 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
616 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
617 cmd->data.setrtg.type = (type);
618 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
619
620 return rc;
621}
622
623static void qeth_l3_correct_routing_type(struct qeth_card *card,
624 enum qeth_routing_types *type, enum qeth_prot_versions prot)
625{
626 if (card->info.type == QETH_CARD_TYPE_IQD) {
627 switch (*type) {
628 case NO_ROUTER:
629 case PRIMARY_CONNECTOR:
630 case SECONDARY_CONNECTOR:
631 case MULTICAST_ROUTER:
632 return;
633 default:
634 goto out_inval;
635 }
636 } else {
637 switch (*type) {
638 case NO_ROUTER:
639 case PRIMARY_ROUTER:
640 case SECONDARY_ROUTER:
641 return;
642 case MULTICAST_ROUTER:
643 if (qeth_is_ipafunc_supported(card, prot,
644 IPA_OSA_MC_ROUTER))
645 return;
646 default:
647 goto out_inval;
648 }
649 }
650out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100651 *type = NO_ROUTER;
652}
653
654int qeth_l3_setrouting_v4(struct qeth_card *card)
655{
656 int rc;
657
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200658 QETH_DBF_TEXT(TRACE, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100659
660 qeth_l3_correct_routing_type(card, &card->options.route4.type,
661 QETH_PROT_IPV4);
662
663 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
664 QETH_PROT_IPV4);
665 if (rc) {
666 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200667 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
668 " on %s. Type set to 'no router'.\n", rc,
669 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100670 }
671 return rc;
672}
673
674int qeth_l3_setrouting_v6(struct qeth_card *card)
675{
676 int rc = 0;
677
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200678 QETH_DBF_TEXT(TRACE, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100679#ifdef CONFIG_QETH_IPV6
680
681 if (!qeth_is_supported(card, IPA_IPV6))
682 return 0;
683 qeth_l3_correct_routing_type(card, &card->options.route6.type,
684 QETH_PROT_IPV6);
685
686 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
687 QETH_PROT_IPV6);
688 if (rc) {
689 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200690 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
691 " on %s. Type set to 'no router'.\n", rc,
692 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100693 }
694#endif
695 return rc;
696}
697
698/*
699 * IP address takeover related functions
700 */
701static void qeth_l3_clear_ipato_list(struct qeth_card *card)
702{
703
704 struct qeth_ipato_entry *ipatoe, *tmp;
705 unsigned long flags;
706
707 spin_lock_irqsave(&card->ip_lock, flags);
708 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
709 list_del(&ipatoe->entry);
710 kfree(ipatoe);
711 }
712 spin_unlock_irqrestore(&card->ip_lock, flags);
713}
714
715int qeth_l3_add_ipato_entry(struct qeth_card *card,
716 struct qeth_ipato_entry *new)
717{
718 struct qeth_ipato_entry *ipatoe;
719 unsigned long flags;
720 int rc = 0;
721
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200722 QETH_DBF_TEXT(TRACE, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100723 spin_lock_irqsave(&card->ip_lock, flags);
724 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
725 if (ipatoe->proto != new->proto)
726 continue;
727 if (!memcmp(ipatoe->addr, new->addr,
728 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
729 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100730 rc = -EEXIST;
731 break;
732 }
733 }
734 if (!rc)
735 list_add_tail(&new->entry, &card->ipato.entries);
736
737 spin_unlock_irqrestore(&card->ip_lock, flags);
738 return rc;
739}
740
741void qeth_l3_del_ipato_entry(struct qeth_card *card,
742 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
743{
744 struct qeth_ipato_entry *ipatoe, *tmp;
745 unsigned long flags;
746
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200747 QETH_DBF_TEXT(TRACE, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100748 spin_lock_irqsave(&card->ip_lock, flags);
749 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
750 if (ipatoe->proto != proto)
751 continue;
752 if (!memcmp(ipatoe->addr, addr,
753 (proto == QETH_PROT_IPV4)? 4:16) &&
754 (ipatoe->mask_bits == mask_bits)) {
755 list_del(&ipatoe->entry);
756 kfree(ipatoe);
757 }
758 }
759 spin_unlock_irqrestore(&card->ip_lock, flags);
760}
761
762/*
763 * VIPA related functions
764 */
765int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
766 const u8 *addr)
767{
768 struct qeth_ipaddr *ipaddr;
769 unsigned long flags;
770 int rc = 0;
771
772 ipaddr = qeth_l3_get_addr_buffer(proto);
773 if (ipaddr) {
774 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200775 QETH_DBF_TEXT(TRACE, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100776 memcpy(&ipaddr->u.a4.addr, addr, 4);
777 ipaddr->u.a4.mask = 0;
778 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200779 QETH_DBF_TEXT(TRACE, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100780 memcpy(&ipaddr->u.a6.addr, addr, 16);
781 ipaddr->u.a6.pfxlen = 0;
782 }
783 ipaddr->type = QETH_IP_TYPE_VIPA;
784 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
785 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
786 } else
787 return -ENOMEM;
788 spin_lock_irqsave(&card->ip_lock, flags);
789 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
790 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
791 rc = -EEXIST;
792 spin_unlock_irqrestore(&card->ip_lock, flags);
793 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100794 return rc;
795 }
796 if (!qeth_l3_add_ip(card, ipaddr))
797 kfree(ipaddr);
798 qeth_l3_set_ip_addr_list(card);
799 return rc;
800}
801
802void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
803 const u8 *addr)
804{
805 struct qeth_ipaddr *ipaddr;
806
807 ipaddr = qeth_l3_get_addr_buffer(proto);
808 if (ipaddr) {
809 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200810 QETH_DBF_TEXT(TRACE, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100811 memcpy(&ipaddr->u.a4.addr, addr, 4);
812 ipaddr->u.a4.mask = 0;
813 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200814 QETH_DBF_TEXT(TRACE, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100815 memcpy(&ipaddr->u.a6.addr, addr, 16);
816 ipaddr->u.a6.pfxlen = 0;
817 }
818 ipaddr->type = QETH_IP_TYPE_VIPA;
819 } else
820 return;
821 if (!qeth_l3_delete_ip(card, ipaddr))
822 kfree(ipaddr);
823 qeth_l3_set_ip_addr_list(card);
824}
825
826/*
827 * proxy ARP related functions
828 */
829int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
830 const u8 *addr)
831{
832 struct qeth_ipaddr *ipaddr;
833 unsigned long flags;
834 int rc = 0;
835
836 ipaddr = qeth_l3_get_addr_buffer(proto);
837 if (ipaddr) {
838 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200839 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840 memcpy(&ipaddr->u.a4.addr, addr, 4);
841 ipaddr->u.a4.mask = 0;
842 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200843 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 memcpy(&ipaddr->u.a6.addr, addr, 16);
845 ipaddr->u.a6.pfxlen = 0;
846 }
847 ipaddr->type = QETH_IP_TYPE_RXIP;
848 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
849 ipaddr->del_flags = 0;
850 } else
851 return -ENOMEM;
852 spin_lock_irqsave(&card->ip_lock, flags);
853 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
854 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
855 rc = -EEXIST;
856 spin_unlock_irqrestore(&card->ip_lock, flags);
857 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100858 return rc;
859 }
860 if (!qeth_l3_add_ip(card, ipaddr))
861 kfree(ipaddr);
862 qeth_l3_set_ip_addr_list(card);
863 return 0;
864}
865
866void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
867 const u8 *addr)
868{
869 struct qeth_ipaddr *ipaddr;
870
871 ipaddr = qeth_l3_get_addr_buffer(proto);
872 if (ipaddr) {
873 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200874 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100875 memcpy(&ipaddr->u.a4.addr, addr, 4);
876 ipaddr->u.a4.mask = 0;
877 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200878 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100879 memcpy(&ipaddr->u.a6.addr, addr, 16);
880 ipaddr->u.a6.pfxlen = 0;
881 }
882 ipaddr->type = QETH_IP_TYPE_RXIP;
883 } else
884 return;
885 if (!qeth_l3_delete_ip(card, ipaddr))
886 kfree(ipaddr);
887 qeth_l3_set_ip_addr_list(card);
888}
889
890static int qeth_l3_register_addr_entry(struct qeth_card *card,
891 struct qeth_ipaddr *addr)
892{
893 char buf[50];
894 int rc = 0;
895 int cnt = 3;
896
897 if (addr->proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200898 QETH_DBF_TEXT(TRACE, 2, "setaddr4");
899 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100900 } else if (addr->proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200901 QETH_DBF_TEXT(TRACE, 2, "setaddr6");
902 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
903 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904 } else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200905 QETH_DBF_TEXT(TRACE, 2, "setaddr?");
906 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 }
908 do {
909 if (addr->is_multicast)
910 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
911 else
912 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
913 addr->set_flags);
914 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200915 QETH_DBF_TEXT(TRACE, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 } while ((--cnt > 0) && rc);
917 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200918 QETH_DBF_TEXT(TRACE, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
920 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
921 buf, rc, rc);
922 }
923 return rc;
924}
925
926static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
927 struct qeth_ipaddr *addr)
928{
929 int rc = 0;
930
931 if (addr->proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200932 QETH_DBF_TEXT(TRACE, 2, "deladdr4");
933 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100934 } else if (addr->proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200935 QETH_DBF_TEXT(TRACE, 2, "deladdr6");
936 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
937 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 } else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200939 QETH_DBF_TEXT(TRACE, 2, "deladdr?");
940 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941 }
942 if (addr->is_multicast)
943 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
944 else
945 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
946 addr->del_flags);
947 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200948 QETH_DBF_TEXT(TRACE, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949 /* TODO: re-activate this warning as soon as we have a
950 * clean mirco code
951 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
952 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
953 buf, rc);
954 */
955 }
956
957 return rc;
958}
959
960static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
961{
962 if (cast_type == RTN_MULTICAST)
963 return QETH_CAST_MULTICAST;
964 if (cast_type == RTN_BROADCAST)
965 return QETH_CAST_BROADCAST;
966 return QETH_CAST_UNICAST;
967}
968
969static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
970{
971 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
972 if (cast_type == RTN_MULTICAST)
973 return ct | QETH_CAST_MULTICAST;
974 if (cast_type == RTN_ANYCAST)
975 return ct | QETH_CAST_ANYCAST;
976 if (cast_type == RTN_BROADCAST)
977 return ct | QETH_CAST_BROADCAST;
978 return ct | QETH_CAST_UNICAST;
979}
980
981static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
982 __u32 mode)
983{
984 int rc;
985 struct qeth_cmd_buffer *iob;
986 struct qeth_ipa_cmd *cmd;
987
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200988 QETH_DBF_TEXT(TRACE, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989
990 iob = qeth_get_adapter_cmd(card, command,
991 sizeof(struct qeth_ipacmd_setadpparms));
992 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
993 cmd->data.setadapterparms.data.mode = mode;
994 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
995 NULL);
996 return rc;
997}
998
999static int qeth_l3_setadapter_hstr(struct qeth_card *card)
1000{
1001 int rc;
1002
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001003 QETH_DBF_TEXT(TRACE, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001004
1005 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1006 rc = qeth_l3_send_setadp_mode(card,
1007 IPA_SETADP_SET_BROADCAST_MODE,
1008 card->options.broadcast_mode);
1009 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001010 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011 "device %s: x%x\n",
1012 CARD_BUS_ID(card), rc);
1013 rc = qeth_l3_send_setadp_mode(card,
1014 IPA_SETADP_ALTER_MAC_ADDRESS,
1015 card->options.macaddr_mode);
1016 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001017 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1019 return rc;
1020 }
1021 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001022 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023 "to set broadcast mode, using ALLRINGS "
1024 "on device %s:\n", CARD_BUS_ID(card));
1025 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001026 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001027 "to set macaddr mode, using NONCANONICAL "
1028 "on device %s:\n", CARD_BUS_ID(card));
1029 return 0;
1030}
1031
1032static int qeth_l3_setadapter_parms(struct qeth_card *card)
1033{
1034 int rc;
1035
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001036 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001037
1038 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
1039 PRINT_WARN("set adapter parameters not supported "
1040 "on device %s.\n",
1041 CARD_BUS_ID(card));
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001042 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043 return 0;
1044 }
1045 rc = qeth_query_setadapterparms(card);
1046 if (rc) {
1047 PRINT_WARN("couldn't set adapter parameters on device %s: "
1048 "x%x\n", CARD_BUS_ID(card), rc);
1049 return rc;
1050 }
1051 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1052 rc = qeth_setadpparms_change_macaddr(card);
1053 if (rc)
1054 PRINT_WARN("couldn't get MAC address on "
1055 "device %s: x%x\n",
1056 CARD_BUS_ID(card), rc);
1057 }
1058
1059 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1060 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1061 rc = qeth_l3_setadapter_hstr(card);
1062
1063 return rc;
1064}
1065
1066static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1067 struct qeth_reply *reply, unsigned long data)
1068{
1069 struct qeth_ipa_cmd *cmd;
1070
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001071 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001072
1073 cmd = (struct qeth_ipa_cmd *) data;
1074 if (cmd->hdr.return_code == 0) {
1075 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1076 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1077 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1078 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1079 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1080 }
1081 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1082 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1083 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001084 QETH_DBF_TEXT_(TRACE, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001085 }
1086 return 0;
1087}
1088
1089static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1090 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1091 __u16 len, enum qeth_prot_versions prot)
1092{
1093 struct qeth_cmd_buffer *iob;
1094 struct qeth_ipa_cmd *cmd;
1095
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001096 QETH_DBF_TEXT(TRACE, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001097 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1098
1099 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1100 cmd->data.setassparms.hdr.assist_no = ipa_func;
1101 cmd->data.setassparms.hdr.length = 8 + len;
1102 cmd->data.setassparms.hdr.command_code = cmd_code;
1103 cmd->data.setassparms.hdr.return_code = 0;
1104 cmd->data.setassparms.hdr.seq_no = 0;
1105
1106 return iob;
1107}
1108
1109static int qeth_l3_send_setassparms(struct qeth_card *card,
1110 struct qeth_cmd_buffer *iob, __u16 len, long data,
1111 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1112 unsigned long),
1113 void *reply_param)
1114{
1115 int rc;
1116 struct qeth_ipa_cmd *cmd;
1117
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001118 QETH_DBF_TEXT(TRACE, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001119
1120 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1121 if (len <= sizeof(__u32))
1122 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1123 else /* (len > sizeof(__u32)) */
1124 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1125
1126 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1127 return rc;
1128}
1129
1130#ifdef CONFIG_QETH_IPV6
1131static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1132 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1133{
1134 int rc;
1135 struct qeth_cmd_buffer *iob;
1136
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001137 QETH_DBF_TEXT(TRACE, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001138 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1139 0, QETH_PROT_IPV6);
1140 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1141 qeth_l3_default_setassparms_cb, NULL);
1142 return rc;
1143}
1144#endif
1145
1146static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1147 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1148{
1149 int rc;
1150 int length = 0;
1151 struct qeth_cmd_buffer *iob;
1152
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001153 QETH_DBF_TEXT(TRACE, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154 if (data)
1155 length = sizeof(__u32);
1156 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1157 length, QETH_PROT_IPV4);
1158 rc = qeth_l3_send_setassparms(card, iob, length, data,
1159 qeth_l3_default_setassparms_cb, NULL);
1160 return rc;
1161}
1162
1163static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1164{
1165 int rc;
1166
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001167 QETH_DBF_TEXT(TRACE, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001168
1169 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
1170 PRINT_WARN("ARP processing not supported "
1171 "on %s!\n", QETH_CARD_IFNAME(card));
1172 return 0;
1173 }
1174 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1175 IPA_CMD_ASS_START, 0);
1176 if (rc) {
1177 PRINT_WARN("Could not start ARP processing "
1178 "assist on %s: 0x%x\n",
1179 QETH_CARD_IFNAME(card), rc);
1180 }
1181 return rc;
1182}
1183
1184static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1185{
1186 int rc;
1187
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001188 QETH_DBF_TEXT(TRACE, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001189
1190 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
1191 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
1192 QETH_CARD_IFNAME(card));
1193 return -EOPNOTSUPP;
1194 }
1195
1196 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1197 IPA_CMD_ASS_START, 0);
1198 if (rc) {
1199 PRINT_WARN("Could not start Hardware IP fragmentation "
1200 "assist on %s: 0x%x\n",
1201 QETH_CARD_IFNAME(card), rc);
1202 } else
1203 PRINT_INFO("Hardware IP fragmentation enabled \n");
1204 return rc;
1205}
1206
1207static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1208{
1209 int rc;
1210
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001211 QETH_DBF_TEXT(TRACE, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001212
1213 if (!card->options.fake_ll)
1214 return -EOPNOTSUPP;
1215
1216 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
1217 PRINT_INFO("Inbound source address not "
1218 "supported on %s\n", QETH_CARD_IFNAME(card));
1219 return -EOPNOTSUPP;
1220 }
1221
1222 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1223 IPA_CMD_ASS_START, 0);
1224 if (rc)
1225 PRINT_WARN("Could not start inbound source "
1226 "assist on %s: 0x%x\n",
1227 QETH_CARD_IFNAME(card), rc);
1228 return rc;
1229}
1230
1231static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1232{
1233 int rc = 0;
1234
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001235 QETH_DBF_TEXT(TRACE, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001236
1237 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
1238 PRINT_WARN("VLAN not supported on %s\n",
1239 QETH_CARD_IFNAME(card));
1240 return -EOPNOTSUPP;
1241 }
1242
1243 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1244 IPA_CMD_ASS_START, 0);
1245 if (rc) {
1246 PRINT_WARN("Could not start vlan "
1247 "assist on %s: 0x%x\n",
1248 QETH_CARD_IFNAME(card), rc);
1249 } else {
1250 PRINT_INFO("VLAN enabled \n");
1251 }
1252 return rc;
1253}
1254
1255static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1256{
1257 int rc;
1258
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001259 QETH_DBF_TEXT(TRACE, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001260
1261 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
1262 PRINT_WARN("Multicast not supported on %s\n",
1263 QETH_CARD_IFNAME(card));
1264 return -EOPNOTSUPP;
1265 }
1266
1267 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1268 IPA_CMD_ASS_START, 0);
1269 if (rc) {
1270 PRINT_WARN("Could not start multicast "
1271 "assist on %s: rc=%i\n",
1272 QETH_CARD_IFNAME(card), rc);
1273 } else {
1274 PRINT_INFO("Multicast enabled\n");
1275 card->dev->flags |= IFF_MULTICAST;
1276 }
1277 return rc;
1278}
1279
1280static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1281 struct qeth_reply *reply, unsigned long data)
1282{
1283 struct qeth_ipa_cmd *cmd;
1284
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001285 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001286
1287 cmd = (struct qeth_ipa_cmd *) data;
1288 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1289 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1290 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1291 } else {
1292 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1293 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1294 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001295 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1296 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1297 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001298 return 0;
1299}
1300
1301static int qeth_l3_query_ipassists(struct qeth_card *card,
1302 enum qeth_prot_versions prot)
1303{
1304 int rc;
1305 struct qeth_cmd_buffer *iob;
1306
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001307 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001308 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1309 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1310 return rc;
1311}
1312
1313#ifdef CONFIG_QETH_IPV6
1314static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1315{
1316 int rc;
1317
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001318 QETH_DBF_TEXT(TRACE, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319
1320 if (card->info.type == QETH_CARD_TYPE_IQD)
1321 goto out;
1322
1323 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1324 if (rc) {
1325 PRINT_ERR("IPv6 query ipassist failed on %s\n",
1326 QETH_CARD_IFNAME(card));
1327 return rc;
1328 }
1329 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1330 IPA_CMD_ASS_START, 3);
1331 if (rc) {
1332 PRINT_WARN("IPv6 start assist (version 4) failed "
1333 "on %s: 0x%x\n",
1334 QETH_CARD_IFNAME(card), rc);
1335 return rc;
1336 }
1337 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1338 IPA_CMD_ASS_START);
1339 if (rc) {
1340 PRINT_WARN("IPV6 start assist (version 6) failed "
1341 "on %s: 0x%x\n",
1342 QETH_CARD_IFNAME(card), rc);
1343 return rc;
1344 }
1345 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1346 IPA_CMD_ASS_START);
1347 if (rc) {
1348 PRINT_WARN("Could not enable passthrough "
1349 "on %s: 0x%x\n",
1350 QETH_CARD_IFNAME(card), rc);
1351 return rc;
1352 }
1353out:
1354 PRINT_INFO("IPV6 enabled \n");
1355 return 0;
1356}
1357#endif
1358
1359static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1360{
1361 int rc = 0;
1362
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001363 QETH_DBF_TEXT(TRACE, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001364
1365 if (!qeth_is_supported(card, IPA_IPV6)) {
1366 PRINT_WARN("IPv6 not supported on %s\n",
1367 QETH_CARD_IFNAME(card));
1368 return 0;
1369 }
1370#ifdef CONFIG_QETH_IPV6
1371 rc = qeth_l3_softsetup_ipv6(card);
1372#endif
1373 return rc ;
1374}
1375
1376static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1377{
1378 int rc;
1379
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001380 QETH_DBF_TEXT(TRACE, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001381 card->info.broadcast_capable = 0;
1382 if (!qeth_is_supported(card, IPA_FILTERING)) {
1383 PRINT_WARN("Broadcast not supported on %s\n",
1384 QETH_CARD_IFNAME(card));
1385 rc = -EOPNOTSUPP;
1386 goto out;
1387 }
1388 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1389 IPA_CMD_ASS_START, 0);
1390 if (rc) {
1391 PRINT_WARN("Could not enable broadcasting filtering "
1392 "on %s: 0x%x\n",
1393 QETH_CARD_IFNAME(card), rc);
1394 goto out;
1395 }
1396
1397 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1398 IPA_CMD_ASS_CONFIGURE, 1);
1399 if (rc) {
1400 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
1401 QETH_CARD_IFNAME(card), rc);
1402 goto out;
1403 }
1404 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
1405 PRINT_INFO("Broadcast enabled \n");
1406 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1407 IPA_CMD_ASS_ENABLE, 1);
1408 if (rc) {
1409 PRINT_WARN("Could not set up broadcast echo filtering on "
1410 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
1411 goto out;
1412 }
1413 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1414out:
1415 if (card->info.broadcast_capable)
1416 card->dev->flags |= IFF_BROADCAST;
1417 else
1418 card->dev->flags &= ~IFF_BROADCAST;
1419 return rc;
1420}
1421
1422static int qeth_l3_send_checksum_command(struct qeth_card *card)
1423{
1424 int rc;
1425
1426 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1427 IPA_CMD_ASS_START, 0);
1428 if (rc) {
1429 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
1430 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
1431 QETH_CARD_IFNAME(card), rc);
1432 return rc;
1433 }
1434 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1435 IPA_CMD_ASS_ENABLE,
1436 card->info.csum_mask);
1437 if (rc) {
1438 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
1439 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
1440 QETH_CARD_IFNAME(card), rc);
1441 return rc;
1442 }
1443 return 0;
1444}
1445
1446static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1447{
1448 int rc = 0;
1449
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001450 QETH_DBF_TEXT(TRACE, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001451
1452 if (card->options.checksum_type == NO_CHECKSUMMING) {
1453 PRINT_WARN("Using no checksumming on %s.\n",
1454 QETH_CARD_IFNAME(card));
1455 return 0;
1456 }
1457 if (card->options.checksum_type == SW_CHECKSUMMING) {
1458 PRINT_WARN("Using SW checksumming on %s.\n",
1459 QETH_CARD_IFNAME(card));
1460 return 0;
1461 }
1462 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
1463 PRINT_WARN("Inbound HW Checksumming not "
1464 "supported on %s,\ncontinuing "
1465 "using Inbound SW Checksumming\n",
1466 QETH_CARD_IFNAME(card));
1467 card->options.checksum_type = SW_CHECKSUMMING;
1468 return 0;
1469 }
1470 rc = qeth_l3_send_checksum_command(card);
1471 if (!rc)
1472 PRINT_INFO("HW Checksumming (inbound) enabled \n");
1473
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)) {
1484 PRINT_WARN("Outbound TSO not supported on %s\n",
1485 QETH_CARD_IFNAME(card));
1486 rc = -EOPNOTSUPP;
1487 } else {
1488 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1489 IPA_CMD_ASS_START, 0);
1490 if (rc)
1491 PRINT_WARN("Could not start outbound TSO "
1492 "assist on %s: rc=%i\n",
1493 QETH_CARD_IFNAME(card), rc);
1494 else
1495 PRINT_INFO("Outbound TSO enabled\n");
1496 }
1497 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1498 card->options.large_send = QETH_LARGE_SEND_NO;
1499 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1500 }
1501 return rc;
1502}
1503
1504static int qeth_l3_start_ipassists(struct qeth_card *card)
1505{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001506 QETH_DBF_TEXT(TRACE, 3, "strtipas");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001507 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1508 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1509 qeth_l3_start_ipa_source_mac(card); /* go on*/
1510 qeth_l3_start_ipa_vlan(card); /* go on*/
1511 qeth_l3_start_ipa_multicast(card); /* go on*/
1512 qeth_l3_start_ipa_ipv6(card); /* go on*/
1513 qeth_l3_start_ipa_broadcast(card); /* go on*/
1514 qeth_l3_start_ipa_checksum(card); /* go on*/
1515 qeth_l3_start_ipa_tso(card); /* go on*/
1516 return 0;
1517}
1518
1519static int qeth_l3_put_unique_id(struct qeth_card *card)
1520{
1521
1522 int rc = 0;
1523 struct qeth_cmd_buffer *iob;
1524 struct qeth_ipa_cmd *cmd;
1525
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001526 QETH_DBF_TEXT(TRACE, 2, "puniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001527
1528 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1529 UNIQUE_ID_NOT_BY_CARD)
1530 return -1;
1531 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1532 QETH_PROT_IPV6);
1533 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1534 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1535 card->info.unique_id;
1536 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1537 card->dev->dev_addr, OSA_ADDR_LEN);
1538 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1539 return rc;
1540}
1541
1542static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1543 struct qeth_reply *reply, unsigned long data)
1544{
1545 struct qeth_ipa_cmd *cmd;
1546
1547 cmd = (struct qeth_ipa_cmd *) data;
1548 if (cmd->hdr.return_code == 0)
1549 memcpy(card->dev->dev_addr,
1550 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1551 else
1552 random_ether_addr(card->dev->dev_addr);
1553
1554 return 0;
1555}
1556
1557static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1558{
1559 int rc = 0;
1560 struct qeth_cmd_buffer *iob;
1561 struct qeth_ipa_cmd *cmd;
1562
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001563 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001564
1565 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1566 QETH_PROT_IPV6);
1567 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1568 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1569 card->info.unique_id;
1570
1571 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1572 NULL);
1573 return rc;
1574}
1575
1576static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1577 struct qeth_reply *reply, unsigned long data)
1578{
1579 struct qeth_ipa_cmd *cmd;
1580
1581 cmd = (struct qeth_ipa_cmd *) data;
1582 if (cmd->hdr.return_code == 0)
1583 card->info.unique_id = *((__u16 *)
1584 &cmd->data.create_destroy_addr.unique_id[6]);
1585 else {
1586 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1587 UNIQUE_ID_NOT_BY_CARD;
1588 PRINT_WARN("couldn't get a unique id from the card on device "
1589 "%s (result=x%x), using default id. ipv6 "
1590 "autoconfig on other lpars may lead to duplicate "
1591 "ip addresses. please use manually "
1592 "configured ones.\n",
1593 CARD_BUS_ID(card), cmd->hdr.return_code);
1594 }
1595 return 0;
1596}
1597
1598static int qeth_l3_get_unique_id(struct qeth_card *card)
1599{
1600 int rc = 0;
1601 struct qeth_cmd_buffer *iob;
1602 struct qeth_ipa_cmd *cmd;
1603
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001604 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001605
1606 if (!qeth_is_supported(card, IPA_IPV6)) {
1607 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1608 UNIQUE_ID_NOT_BY_CARD;
1609 return 0;
1610 }
1611
1612 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1613 QETH_PROT_IPV6);
1614 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1615 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1616 card->info.unique_id;
1617
1618 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1619 return rc;
1620}
1621
1622static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1623 struct net_device *dev)
1624{
1625 if (dev->type == ARPHRD_IEEE802_TR)
1626 ip_tr_mc_map(ipm, mac);
1627 else
1628 ip_eth_mc_map(ipm, mac);
1629}
1630
1631static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1632{
1633 struct qeth_ipaddr *ipm;
1634 struct ip_mc_list *im4;
1635 char buf[MAX_ADDR_LEN];
1636
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001637 QETH_DBF_TEXT(TRACE, 4, "addmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001638 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1639 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1640 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1641 if (!ipm)
1642 continue;
1643 ipm->u.a4.addr = im4->multiaddr;
1644 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1645 ipm->is_multicast = 1;
1646 if (!qeth_l3_add_ip(card, ipm))
1647 kfree(ipm);
1648 }
1649}
1650
1651static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1652{
1653 struct in_device *in_dev;
1654 struct vlan_group *vg;
1655 int i;
1656
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001657 QETH_DBF_TEXT(TRACE, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001658 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1659 return;
1660
1661 vg = card->vlangrp;
1662 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1663 struct net_device *netdev = vlan_group_get_device(vg, i);
1664 if (netdev == NULL ||
1665 !(netdev->flags & IFF_UP))
1666 continue;
1667 in_dev = in_dev_get(netdev);
1668 if (!in_dev)
1669 continue;
1670 read_lock(&in_dev->mc_list_lock);
1671 qeth_l3_add_mc(card, in_dev);
1672 read_unlock(&in_dev->mc_list_lock);
1673 in_dev_put(in_dev);
1674 }
1675}
1676
1677static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1678{
1679 struct in_device *in4_dev;
1680
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001681 QETH_DBF_TEXT(TRACE, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001682 in4_dev = in_dev_get(card->dev);
1683 if (in4_dev == NULL)
1684 return;
1685 read_lock(&in4_dev->mc_list_lock);
1686 qeth_l3_add_mc(card, in4_dev);
1687 qeth_l3_add_vlan_mc(card);
1688 read_unlock(&in4_dev->mc_list_lock);
1689 in_dev_put(in4_dev);
1690}
1691
1692#ifdef CONFIG_QETH_IPV6
1693static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1694{
1695 struct qeth_ipaddr *ipm;
1696 struct ifmcaddr6 *im6;
1697 char buf[MAX_ADDR_LEN];
1698
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001699 QETH_DBF_TEXT(TRACE, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001700 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1701 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1702 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1703 if (!ipm)
1704 continue;
1705 ipm->is_multicast = 1;
1706 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1707 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1708 sizeof(struct in6_addr));
1709 if (!qeth_l3_add_ip(card, ipm))
1710 kfree(ipm);
1711 }
1712}
1713
1714static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1715{
1716 struct inet6_dev *in_dev;
1717 struct vlan_group *vg;
1718 int i;
1719
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001720 QETH_DBF_TEXT(TRACE, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001721 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1722 return;
1723
1724 vg = card->vlangrp;
1725 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1726 struct net_device *netdev = vlan_group_get_device(vg, i);
1727 if (netdev == NULL ||
1728 !(netdev->flags & IFF_UP))
1729 continue;
1730 in_dev = in6_dev_get(netdev);
1731 if (!in_dev)
1732 continue;
1733 read_lock_bh(&in_dev->lock);
1734 qeth_l3_add_mc6(card, in_dev);
1735 read_unlock_bh(&in_dev->lock);
1736 in6_dev_put(in_dev);
1737 }
1738}
1739
1740static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1741{
1742 struct inet6_dev *in6_dev;
1743
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001744 QETH_DBF_TEXT(TRACE, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001745 if (!qeth_is_supported(card, IPA_IPV6))
1746 return ;
1747 in6_dev = in6_dev_get(card->dev);
1748 if (in6_dev == NULL)
1749 return;
1750 read_lock_bh(&in6_dev->lock);
1751 qeth_l3_add_mc6(card, in6_dev);
1752 qeth_l3_add_vlan_mc6(card);
1753 read_unlock_bh(&in6_dev->lock);
1754 in6_dev_put(in6_dev);
1755}
1756#endif /* CONFIG_QETH_IPV6 */
1757
1758static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1759 unsigned short vid)
1760{
1761 struct in_device *in_dev;
1762 struct in_ifaddr *ifa;
1763 struct qeth_ipaddr *addr;
1764
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001765 QETH_DBF_TEXT(TRACE, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001766
1767 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1768 if (!in_dev)
1769 return;
1770 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1771 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1772 if (addr) {
1773 addr->u.a4.addr = ifa->ifa_address;
1774 addr->u.a4.mask = ifa->ifa_mask;
1775 addr->type = QETH_IP_TYPE_NORMAL;
1776 if (!qeth_l3_delete_ip(card, addr))
1777 kfree(addr);
1778 }
1779 }
1780 in_dev_put(in_dev);
1781}
1782
1783static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1784 unsigned short vid)
1785{
1786#ifdef CONFIG_QETH_IPV6
1787 struct inet6_dev *in6_dev;
1788 struct inet6_ifaddr *ifa;
1789 struct qeth_ipaddr *addr;
1790
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001791 QETH_DBF_TEXT(TRACE, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001792
1793 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1794 if (!in6_dev)
1795 return;
1796 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) {
1797 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1798 if (addr) {
1799 memcpy(&addr->u.a6.addr, &ifa->addr,
1800 sizeof(struct in6_addr));
1801 addr->u.a6.pfxlen = ifa->prefix_len;
1802 addr->type = QETH_IP_TYPE_NORMAL;
1803 if (!qeth_l3_delete_ip(card, addr))
1804 kfree(addr);
1805 }
1806 }
1807 in6_dev_put(in6_dev);
1808#endif /* CONFIG_QETH_IPV6 */
1809}
1810
1811static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1812 unsigned short vid)
1813{
1814 if (!card->vlangrp)
1815 return;
1816 qeth_l3_free_vlan_addresses4(card, vid);
1817 qeth_l3_free_vlan_addresses6(card, vid);
1818}
1819
1820static void qeth_l3_vlan_rx_register(struct net_device *dev,
1821 struct vlan_group *grp)
1822{
1823 struct qeth_card *card = netdev_priv(dev);
1824 unsigned long flags;
1825
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001826 QETH_DBF_TEXT(TRACE, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001827 spin_lock_irqsave(&card->vlanlock, flags);
1828 card->vlangrp = grp;
1829 spin_unlock_irqrestore(&card->vlanlock, flags);
1830}
1831
1832static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1833{
1834 struct net_device *vlandev;
1835 struct qeth_card *card = (struct qeth_card *) dev->priv;
1836 struct in_device *in_dev;
1837
1838 if (card->info.type == QETH_CARD_TYPE_IQD)
1839 return;
1840
1841 vlandev = vlan_group_get_device(card->vlangrp, vid);
1842 vlandev->neigh_setup = qeth_l3_neigh_setup;
1843
1844 in_dev = in_dev_get(vlandev);
1845#ifdef CONFIG_SYSCTL
1846 neigh_sysctl_unregister(in_dev->arp_parms);
1847#endif
1848 neigh_parms_release(&arp_tbl, in_dev->arp_parms);
1849
1850 in_dev->arp_parms = neigh_parms_alloc(vlandev, &arp_tbl);
1851#ifdef CONFIG_SYSCTL
1852 neigh_sysctl_register(vlandev, in_dev->arp_parms, NET_IPV4,
1853 NET_IPV4_NEIGH, "ipv4", NULL, NULL);
1854#endif
1855 in_dev_put(in_dev);
1856 return;
1857}
1858
1859static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1860{
1861 struct qeth_card *card = netdev_priv(dev);
1862 unsigned long flags;
1863
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001864 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001865 spin_lock_irqsave(&card->vlanlock, flags);
1866 /* unregister IP addresses of vlan device */
1867 qeth_l3_free_vlan_addresses(card, vid);
1868 vlan_group_set_device(card->vlangrp, vid, NULL);
1869 spin_unlock_irqrestore(&card->vlanlock, flags);
1870 qeth_l3_set_multicast_list(card->dev);
1871}
1872
1873static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card,
1874 struct sk_buff *skb, struct qeth_hdr *hdr)
1875{
1876 unsigned short vlan_id = 0;
1877 __be16 prot;
1878 struct iphdr *ip_hdr;
1879 unsigned char tg_addr[MAX_ADDR_LEN];
1880
1881 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1882 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1883 ETH_P_IP);
1884 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1885 case QETH_CAST_MULTICAST:
1886 switch (prot) {
1887#ifdef CONFIG_QETH_IPV6
1888 case __constant_htons(ETH_P_IPV6):
1889 ndisc_mc_map((struct in6_addr *)
1890 skb->data + 24,
1891 tg_addr, card->dev, 0);
1892 break;
1893#endif
1894 case __constant_htons(ETH_P_IP):
1895 ip_hdr = (struct iphdr *)skb->data;
1896 (card->dev->type == ARPHRD_IEEE802_TR) ?
1897 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1898 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1899 break;
1900 default:
1901 memcpy(tg_addr, card->dev->broadcast,
1902 card->dev->addr_len);
1903 }
1904 card->stats.multicast++;
1905 skb->pkt_type = PACKET_MULTICAST;
1906 break;
1907 case QETH_CAST_BROADCAST:
1908 memcpy(tg_addr, card->dev->broadcast,
1909 card->dev->addr_len);
1910 card->stats.multicast++;
1911 skb->pkt_type = PACKET_BROADCAST;
1912 break;
1913 case QETH_CAST_UNICAST:
1914 case QETH_CAST_ANYCAST:
1915 case QETH_CAST_NOCAST:
1916 default:
1917 skb->pkt_type = PACKET_HOST;
1918 memcpy(tg_addr, card->dev->dev_addr,
1919 card->dev->addr_len);
1920 }
1921 card->dev->header_ops->create(skb, card->dev, prot, tg_addr,
1922 "FAKELL", card->dev->addr_len);
1923 }
1924
1925#ifdef CONFIG_TR
1926 if (card->dev->type == ARPHRD_IEEE802_TR)
1927 skb->protocol = tr_type_trans(skb, card->dev);
1928 else
1929#endif
1930 skb->protocol = eth_type_trans(skb, card->dev);
1931
1932 if (hdr->hdr.l3.ext_flags &
1933 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
1934 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
1935 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
1936 }
1937
1938 skb->ip_summed = card->options.checksum_type;
1939 if (card->options.checksum_type == HW_CHECKSUMMING) {
1940 if ((hdr->hdr.l3.ext_flags &
1941 (QETH_HDR_EXT_CSUM_HDR_REQ |
1942 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1943 (QETH_HDR_EXT_CSUM_HDR_REQ |
1944 QETH_HDR_EXT_CSUM_TRANSP_REQ))
1945 skb->ip_summed = CHECKSUM_UNNECESSARY;
1946 else
1947 skb->ip_summed = SW_CHECKSUMMING;
1948 }
1949
1950 return vlan_id;
1951}
1952
1953static void qeth_l3_process_inbound_buffer(struct qeth_card *card,
1954 struct qeth_qdio_buffer *buf, int index)
1955{
1956 struct qdio_buffer_element *element;
1957 struct sk_buff *skb;
1958 struct qeth_hdr *hdr;
1959 int offset;
1960 __u16 vlan_tag = 0;
1961 unsigned int len;
1962
1963 /* get first element of current buffer */
1964 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
1965 offset = 0;
1966 if (card->options.performance_stats)
1967 card->perf_stats.bufs_rec++;
1968 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
1969 &offset, &hdr))) {
1970 skb->dev = card->dev;
1971 /* is device UP ? */
1972 if (!(card->dev->flags & IFF_UP)) {
1973 dev_kfree_skb_any(skb);
1974 continue;
1975 }
1976
1977 switch (hdr->hdr.l3.id) {
1978 case QETH_HEADER_TYPE_LAYER3:
1979 vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr);
1980 len = skb->len;
1981 if (vlan_tag)
1982 if (card->vlangrp)
1983 vlan_hwaccel_rx(skb, card->vlangrp,
1984 vlan_tag);
1985 else {
1986 dev_kfree_skb_any(skb);
1987 continue;
1988 }
1989 else
1990 netif_rx(skb);
1991 break;
1992 default:
1993 dev_kfree_skb_any(skb);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001994 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
1995 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001996 continue;
1997 }
1998
1999 card->dev->last_rx = jiffies;
2000 card->stats.rx_packets++;
2001 card->stats.rx_bytes += len;
2002 }
2003}
2004
2005static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2006 struct qeth_card *card)
2007{
2008 int rc = 0;
2009 struct vlan_group *vg;
2010 int i;
2011
2012 vg = card->vlangrp;
2013 if (!vg)
2014 return rc;
2015
2016 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
2017 if (vlan_group_get_device(vg, i) == dev) {
2018 rc = QETH_VLAN_CARD;
2019 break;
2020 }
2021 }
2022
2023 if (rc && !(netdev_priv(vlan_dev_info(dev)->real_dev) == (void *)card))
2024 return 0;
2025
2026 return rc;
2027}
2028
2029static int qeth_l3_verify_dev(struct net_device *dev)
2030{
2031 struct qeth_card *card;
2032 unsigned long flags;
2033 int rc = 0;
2034
2035 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2036 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2037 if (card->dev == dev) {
2038 rc = QETH_REAL_CARD;
2039 break;
2040 }
2041 rc = qeth_l3_verify_vlan_dev(dev, card);
2042 if (rc)
2043 break;
2044 }
2045 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2046
2047 return rc;
2048}
2049
2050static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2051{
2052 struct qeth_card *card = NULL;
2053 int rc;
2054
2055 rc = qeth_l3_verify_dev(dev);
2056 if (rc == QETH_REAL_CARD)
2057 card = netdev_priv(dev);
2058 else if (rc == QETH_VLAN_CARD)
2059 card = netdev_priv(vlan_dev_info(dev)->real_dev);
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002060 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002061 card = NULL;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002062 QETH_DBF_TEXT_(TRACE, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002063 return card ;
2064}
2065
2066static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2067{
2068 int rc = 0;
2069
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002070 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2071 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002072
2073 qeth_set_allowed_threads(card, 0, 1);
2074 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
2075 return -ERESTARTSYS;
2076 if (card->read.state == CH_STATE_UP &&
2077 card->write.state == CH_STATE_UP &&
2078 (card->state == CARD_STATE_UP)) {
2079 if (recovery_mode)
2080 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002081 else {
2082 rtnl_lock();
2083 dev_close(card->dev);
2084 rtnl_unlock();
2085 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002086 if (!card->use_hard_stop) {
2087 rc = qeth_send_stoplan(card);
2088 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002089 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002090 }
2091 card->state = CARD_STATE_SOFTSETUP;
2092 }
2093 if (card->state == CARD_STATE_SOFTSETUP) {
2094 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2095 qeth_clear_ipacmd_list(card);
2096 card->state = CARD_STATE_HARDSETUP;
2097 }
2098 if (card->state == CARD_STATE_HARDSETUP) {
2099 if (!card->use_hard_stop &&
2100 (card->info.type != QETH_CARD_TYPE_IQD)) {
2101 rc = qeth_l3_put_unique_id(card);
2102 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002103 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002104 }
2105 qeth_qdio_clear_card(card, 0);
2106 qeth_clear_qdio_buffers(card);
2107 qeth_clear_working_pool_list(card);
2108 card->state = CARD_STATE_DOWN;
2109 }
2110 if (card->state == CARD_STATE_DOWN) {
2111 qeth_clear_cmd_buffers(&card->read);
2112 qeth_clear_cmd_buffers(&card->write);
2113 }
2114 card->use_hard_stop = 0;
2115 return rc;
2116}
2117
2118static void qeth_l3_set_multicast_list(struct net_device *dev)
2119{
2120 struct qeth_card *card = netdev_priv(dev);
2121
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002122 QETH_DBF_TEXT(TRACE, 3, "setmulti");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002123 qeth_l3_delete_mc_addresses(card);
2124 qeth_l3_add_multicast_ipv4(card);
2125#ifdef CONFIG_QETH_IPV6
2126 qeth_l3_add_multicast_ipv6(card);
2127#endif
2128 qeth_l3_set_ip_addr_list(card);
2129 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2130 return;
2131 qeth_setadp_promisc_mode(card);
2132}
2133
2134static const char *qeth_l3_arp_get_error_cause(int *rc)
2135{
2136 switch (*rc) {
2137 case QETH_IPA_ARP_RC_FAILED:
2138 *rc = -EIO;
2139 return "operation failed";
2140 case QETH_IPA_ARP_RC_NOTSUPP:
2141 *rc = -EOPNOTSUPP;
2142 return "operation not supported";
2143 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2144 *rc = -EINVAL;
2145 return "argument out of range";
2146 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2147 *rc = -EOPNOTSUPP;
2148 return "query operation not supported";
2149 case QETH_IPA_ARP_RC_Q_NO_DATA:
2150 *rc = -ENOENT;
2151 return "no query data available";
2152 default:
2153 return "unknown error";
2154 }
2155}
2156
2157static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2158{
2159 int tmp;
2160 int rc;
2161
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002162 QETH_DBF_TEXT(TRACE, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002163
2164 /*
2165 * currently GuestLAN only supports the ARP assist function
2166 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2167 * thus we say EOPNOTSUPP for this ARP function
2168 */
2169 if (card->info.guestlan)
2170 return -EOPNOTSUPP;
2171 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002172 return -EOPNOTSUPP;
2173 }
2174 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2175 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2176 no_entries);
2177 if (rc) {
2178 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002179 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2180 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002181 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2182 }
2183 return rc;
2184}
2185
2186static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2187 struct qeth_arp_query_data *qdata, int entry_size,
2188 int uentry_size)
2189{
2190 char *entry_ptr;
2191 char *uentry_ptr;
2192 int i;
2193
2194 entry_ptr = (char *)&qdata->data;
2195 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2196 for (i = 0; i < qdata->no_entries; ++i) {
2197 /* strip off 32 bytes "media specific information" */
2198 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2199 entry_ptr += entry_size;
2200 uentry_ptr += uentry_size;
2201 }
2202}
2203
2204static int qeth_l3_arp_query_cb(struct qeth_card *card,
2205 struct qeth_reply *reply, unsigned long data)
2206{
2207 struct qeth_ipa_cmd *cmd;
2208 struct qeth_arp_query_data *qdata;
2209 struct qeth_arp_query_info *qinfo;
2210 int entry_size;
2211 int uentry_size;
2212 int i;
2213
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002214 QETH_DBF_TEXT(TRACE, 4, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002215
2216 qinfo = (struct qeth_arp_query_info *) reply->param;
2217 cmd = (struct qeth_ipa_cmd *) data;
2218 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002219 QETH_DBF_TEXT_(TRACE, 4, "qaer1%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002220 return 0;
2221 }
2222 if (cmd->data.setassparms.hdr.return_code) {
2223 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002224 QETH_DBF_TEXT_(TRACE, 4, "qaer2%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002225 return 0;
2226 }
2227 qdata = &cmd->data.setassparms.data.query_arp;
2228 switch (qdata->reply_bits) {
2229 case 5:
2230 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2231 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2232 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2233 break;
2234 case 7:
2235 /* fall through to default */
2236 default:
2237 /* tr is the same as eth -> entry7 */
2238 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2239 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2240 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2241 break;
2242 }
2243 /* check if there is enough room in userspace */
2244 if ((qinfo->udata_len - qinfo->udata_offset) <
2245 qdata->no_entries * uentry_size){
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002246 QETH_DBF_TEXT_(TRACE, 4, "qaer3%i", -ENOMEM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002247 cmd->hdr.return_code = -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002248 goto out_error;
2249 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002250 QETH_DBF_TEXT_(TRACE, 4, "anore%i",
Frank Blaschka4a71df52008-02-15 09:19:42 +01002251 cmd->data.setassparms.hdr.number_of_replies);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002252 QETH_DBF_TEXT_(TRACE, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2253 QETH_DBF_TEXT_(TRACE, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002254
2255 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2256 /* strip off "media specific information" */
2257 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2258 uentry_size);
2259 } else
2260 /*copy entries to user buffer*/
2261 memcpy(qinfo->udata + qinfo->udata_offset,
2262 (char *)&qdata->data, qdata->no_entries*uentry_size);
2263
2264 qinfo->no_entries += qdata->no_entries;
2265 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2266 /* check if all replies received ... */
2267 if (cmd->data.setassparms.hdr.seq_no <
2268 cmd->data.setassparms.hdr.number_of_replies)
2269 return 1;
2270 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2271 /* keep STRIP_ENTRIES flag so the user program can distinguish
2272 * stripped entries from normal ones */
2273 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2274 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2275 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2276 return 0;
2277out_error:
2278 i = 0;
2279 memcpy(qinfo->udata, &i, 4);
2280 return 0;
2281}
2282
2283static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2284 struct qeth_cmd_buffer *iob, int len,
2285 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2286 unsigned long),
2287 void *reply_param)
2288{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002289 QETH_DBF_TEXT(TRACE, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002290
2291 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2292 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2293 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2294 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2295 reply_cb, reply_param);
2296}
2297
2298static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2299{
2300 struct qeth_cmd_buffer *iob;
2301 struct qeth_arp_query_info qinfo = {0, };
2302 int tmp;
2303 int rc;
2304
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002305 QETH_DBF_TEXT(TRACE, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002306
2307 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2308 IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002309 return -EOPNOTSUPP;
2310 }
2311 /* get size of userspace buffer and mask_bits -> 6 bytes */
2312 if (copy_from_user(&qinfo, udata, 6))
2313 return -EFAULT;
2314 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2315 if (!qinfo.udata)
2316 return -ENOMEM;
2317 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2318 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2319 IPA_CMD_ASS_ARP_QUERY_INFO,
2320 sizeof(int), QETH_PROT_IPV4);
2321
2322 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2323 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2324 qeth_l3_arp_query_cb, (void *)&qinfo);
2325 if (rc) {
2326 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002327 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
Frank Blaschka4a71df52008-02-15 09:19:42 +01002328 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2329 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2330 if (copy_to_user(udata, qinfo.udata, 4))
2331 rc = -EFAULT;
2332 } else {
2333 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2334 rc = -EFAULT;
2335 }
2336 kfree(qinfo.udata);
2337 return rc;
2338}
2339
2340static int qeth_l3_arp_add_entry(struct qeth_card *card,
2341 struct qeth_arp_cache_entry *entry)
2342{
2343 struct qeth_cmd_buffer *iob;
2344 char buf[16];
2345 int tmp;
2346 int rc;
2347
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002348 QETH_DBF_TEXT(TRACE, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002349
2350 /*
2351 * currently GuestLAN only supports the ARP assist function
2352 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2353 * thus we say EOPNOTSUPP for this ARP function
2354 */
2355 if (card->info.guestlan)
2356 return -EOPNOTSUPP;
2357 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002358 return -EOPNOTSUPP;
2359 }
2360
2361 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2362 IPA_CMD_ASS_ARP_ADD_ENTRY,
2363 sizeof(struct qeth_arp_cache_entry),
2364 QETH_PROT_IPV4);
2365 rc = qeth_l3_send_setassparms(card, iob,
2366 sizeof(struct qeth_arp_cache_entry),
2367 (unsigned long) entry,
2368 qeth_l3_default_setassparms_cb, NULL);
2369 if (rc) {
2370 tmp = rc;
2371 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002372 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2373 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2374 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002375 }
2376 return rc;
2377}
2378
2379static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2380 struct qeth_arp_cache_entry *entry)
2381{
2382 struct qeth_cmd_buffer *iob;
2383 char buf[16] = {0, };
2384 int tmp;
2385 int rc;
2386
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002387 QETH_DBF_TEXT(TRACE, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002388
2389 /*
2390 * currently GuestLAN only supports the ARP assist function
2391 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2392 * thus we say EOPNOTSUPP for this ARP function
2393 */
2394 if (card->info.guestlan)
2395 return -EOPNOTSUPP;
2396 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002397 return -EOPNOTSUPP;
2398 }
2399 memcpy(buf, entry, 12);
2400 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2401 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2402 12,
2403 QETH_PROT_IPV4);
2404 rc = qeth_l3_send_setassparms(card, iob,
2405 12, (unsigned long)buf,
2406 qeth_l3_default_setassparms_cb, NULL);
2407 if (rc) {
2408 tmp = rc;
2409 memset(buf, 0, 16);
2410 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002411 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2412 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2413 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002414 }
2415 return rc;
2416}
2417
2418static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2419{
2420 int rc;
2421 int tmp;
2422
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002423 QETH_DBF_TEXT(TRACE, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002424
2425 /*
2426 * currently GuestLAN only supports the ARP assist function
2427 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2428 * thus we say EOPNOTSUPP for this ARP function
2429 */
2430 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2431 return -EOPNOTSUPP;
2432 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002433 return -EOPNOTSUPP;
2434 }
2435 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2436 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2437 if (rc) {
2438 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002439 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2440 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002441 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2442 }
2443 return rc;
2444}
2445
2446static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2447{
2448 struct qeth_card *card = netdev_priv(dev);
2449 struct qeth_arp_cache_entry arp_entry;
2450 struct mii_ioctl_data *mii_data;
2451 int rc = 0;
2452
2453 if (!card)
2454 return -ENODEV;
2455
2456 if ((card->state != CARD_STATE_UP) &&
2457 (card->state != CARD_STATE_SOFTSETUP))
2458 return -ENODEV;
2459
2460 switch (cmd) {
2461 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2462 if (!capable(CAP_NET_ADMIN)) {
2463 rc = -EPERM;
2464 break;
2465 }
2466 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2467 break;
2468 case SIOC_QETH_ARP_QUERY_INFO:
2469 if (!capable(CAP_NET_ADMIN)) {
2470 rc = -EPERM;
2471 break;
2472 }
2473 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2474 break;
2475 case SIOC_QETH_ARP_ADD_ENTRY:
2476 if (!capable(CAP_NET_ADMIN)) {
2477 rc = -EPERM;
2478 break;
2479 }
2480 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2481 sizeof(struct qeth_arp_cache_entry)))
2482 rc = -EFAULT;
2483 else
2484 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2485 break;
2486 case SIOC_QETH_ARP_REMOVE_ENTRY:
2487 if (!capable(CAP_NET_ADMIN)) {
2488 rc = -EPERM;
2489 break;
2490 }
2491 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2492 sizeof(struct qeth_arp_cache_entry)))
2493 rc = -EFAULT;
2494 else
2495 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2496 break;
2497 case SIOC_QETH_ARP_FLUSH_CACHE:
2498 if (!capable(CAP_NET_ADMIN)) {
2499 rc = -EPERM;
2500 break;
2501 }
2502 rc = qeth_l3_arp_flush_cache(card);
2503 break;
2504 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2505 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2506 break;
2507 case SIOC_QETH_GET_CARD_TYPE:
2508 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
2509 !card->info.guestlan)
2510 return 1;
2511 return 0;
2512 break;
2513 case SIOCGMIIPHY:
2514 mii_data = if_mii(rq);
2515 mii_data->phy_id = 0;
2516 break;
2517 case SIOCGMIIREG:
2518 mii_data = if_mii(rq);
2519 if (mii_data->phy_id != 0)
2520 rc = -EINVAL;
2521 else
2522 mii_data->val_out = qeth_mdio_read(dev,
2523 mii_data->phy_id,
2524 mii_data->reg_num);
2525 break;
2526 default:
2527 rc = -EOPNOTSUPP;
2528 }
2529 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002530 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002531 return rc;
2532}
2533
2534static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2535 struct sk_buff *skb, int ipv, int cast_type)
2536{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002537 memset(hdr, 0, sizeof(struct qeth_hdr));
2538 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2539 hdr->hdr.l3.ext_flags = 0;
2540
2541 /*
2542 * before we're going to overwrite this location with next hop ip.
2543 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2544 */
2545 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002546 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2547 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2548 else
2549 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002550 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2551 }
2552
2553 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2554 if (ipv == 4) {
2555 /* IPv4 */
2556 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2557 memset(hdr->hdr.l3.dest_addr, 0, 12);
2558 if ((skb->dst) && (skb->dst->neighbour)) {
2559 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2560 *((u32 *) skb->dst->neighbour->primary_key);
2561 } else {
2562 /* fill in destination address used in ip header */
2563 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2564 ip_hdr(skb)->daddr;
2565 }
2566 } else if (ipv == 6) {
2567 /* IPv6 */
2568 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2569 if (card->info.type == QETH_CARD_TYPE_IQD)
2570 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
2571 if ((skb->dst) && (skb->dst->neighbour)) {
2572 memcpy(hdr->hdr.l3.dest_addr,
2573 skb->dst->neighbour->primary_key, 16);
2574 } else {
2575 /* fill in destination address used in ip header */
2576 memcpy(hdr->hdr.l3.dest_addr,
2577 &ipv6_hdr(skb)->daddr, 16);
2578 }
2579 } else {
2580 /* passthrough */
2581 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2582 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2583 sizeof(__u16), skb->dev->broadcast, 6)) {
2584 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2585 QETH_HDR_PASSTHRU;
2586 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2587 skb->dev->broadcast, 6)) {
2588 /* broadcast? */
2589 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2590 QETH_HDR_PASSTHRU;
2591 } else {
2592 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2593 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2594 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2595 }
2596 }
2597}
2598
2599static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2600{
2601 int rc;
2602 u16 *tag;
2603 struct qeth_hdr *hdr = NULL;
2604 int elements_needed = 0;
2605 struct qeth_card *card = netdev_priv(dev);
2606 struct sk_buff *new_skb = NULL;
2607 int ipv = qeth_get_ip_version(skb);
2608 int cast_type = qeth_get_cast_type(card, skb);
2609 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2610 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2611 int tx_bytes = skb->len;
2612 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
2613 struct qeth_eddp_context *ctx = NULL;
2614
Frank Blaschka4a71df52008-02-15 09:19:42 +01002615 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2616 (skb->protocol != htons(ETH_P_IPV6)) &&
2617 (skb->protocol != htons(ETH_P_IP)))
2618 goto tx_drop;
2619
2620 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2621 card->stats.tx_carrier_errors++;
2622 goto tx_drop;
2623 }
2624
2625 if ((cast_type == RTN_BROADCAST) &&
2626 (card->info.broadcast_capable == 0))
2627 goto tx_drop;
2628
2629 if (card->options.performance_stats) {
2630 card->perf_stats.outbound_cnt++;
2631 card->perf_stats.outbound_start_time = qeth_get_micros();
2632 }
2633
2634 /* create a clone with writeable headroom */
2635 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso) +
2636 VLAN_HLEN);
2637 if (!new_skb)
2638 goto tx_drop;
2639
2640 if (card->info.type == QETH_CARD_TYPE_IQD) {
2641 skb_pull(new_skb, ETH_HLEN);
2642 } else {
2643 if (new_skb->protocol == htons(ETH_P_IP)) {
2644 if (card->dev->type == ARPHRD_IEEE802_TR)
2645 skb_pull(new_skb, TR_HLEN);
2646 else
2647 skb_pull(new_skb, ETH_HLEN);
2648 }
2649
2650 if (new_skb->protocol == ETH_P_IPV6 && card->vlangrp &&
2651 vlan_tx_tag_present(new_skb)) {
2652 skb_push(new_skb, VLAN_HLEN);
2653 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2654 skb_copy_to_linear_data_offset(new_skb, 4,
2655 new_skb->data + 8, 4);
2656 skb_copy_to_linear_data_offset(new_skb, 8,
2657 new_skb->data + 12, 4);
2658 tag = (u16 *)(new_skb->data + 12);
2659 *tag = __constant_htons(ETH_P_8021Q);
2660 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
2661 VLAN_TX_SKB_CB(new_skb)->magic = 0;
2662 }
2663 }
2664
2665 netif_stop_queue(dev);
2666
2667 if (skb_is_gso(new_skb))
2668 large_send = card->options.large_send;
2669
2670 /* fix hardware limitation: as long as we do not have sbal
2671 * chaining we can not send long frag lists so we temporary
2672 * switch to EDDP
2673 */
2674 if ((large_send == QETH_LARGE_SEND_TSO) &&
2675 ((skb_shinfo(new_skb)->nr_frags + 2) > 16))
2676 large_send = QETH_LARGE_SEND_EDDP;
2677
2678 if ((large_send == QETH_LARGE_SEND_TSO) &&
2679 (cast_type == RTN_UNSPEC)) {
2680 hdr = (struct qeth_hdr *)skb_push(new_skb,
2681 sizeof(struct qeth_hdr_tso));
2682 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2683 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2684 qeth_tso_fill_header(card, hdr, new_skb);
2685 elements_needed++;
2686 } else {
2687 hdr = (struct qeth_hdr *)skb_push(new_skb,
2688 sizeof(struct qeth_hdr));
2689 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2690 }
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);
2705 if (!elems)
2706 goto tx_drop;
2707 elements_needed += elems;
2708 }
2709
2710 if ((large_send == QETH_LARGE_SEND_NO) &&
2711 (new_skb->ip_summed == CHECKSUM_PARTIAL))
2712 qeth_tx_csum(new_skb);
2713
2714 if (card->info.type != QETH_CARD_TYPE_IQD)
2715 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
2716 elements_needed, ctx);
2717 else
2718 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
2719 elements_needed, ctx);
2720
2721 if (!rc) {
2722 card->stats.tx_packets++;
2723 card->stats.tx_bytes += tx_bytes;
2724 if (new_skb != skb)
2725 dev_kfree_skb_any(skb);
2726 if (card->options.performance_stats) {
2727 if (large_send != QETH_LARGE_SEND_NO) {
2728 card->perf_stats.large_send_bytes += tx_bytes;
2729 card->perf_stats.large_send_cnt++;
2730 }
2731 if (skb_shinfo(new_skb)->nr_frags > 0) {
2732 card->perf_stats.sg_skbs_sent++;
2733 /* nr_frags + skb->data */
2734 card->perf_stats.sg_frags_sent +=
2735 skb_shinfo(new_skb)->nr_frags + 1;
2736 }
2737 }
2738
2739 if (ctx != NULL) {
2740 qeth_eddp_put_context(ctx);
2741 dev_kfree_skb_any(new_skb);
2742 }
2743 } else {
2744 if (ctx != NULL)
2745 qeth_eddp_put_context(ctx);
2746
2747 if (rc == -EBUSY) {
2748 if (new_skb != skb)
2749 dev_kfree_skb_any(new_skb);
2750 return NETDEV_TX_BUSY;
2751 } else
2752 goto tx_drop;
2753 }
2754
2755 netif_wake_queue(dev);
2756 if (card->options.performance_stats)
2757 card->perf_stats.outbound_time += qeth_get_micros() -
2758 card->perf_stats.outbound_start_time;
2759 return rc;
2760
2761tx_drop:
2762 card->stats.tx_dropped++;
2763 card->stats.tx_errors++;
2764 if ((new_skb != skb) && new_skb)
2765 dev_kfree_skb_any(new_skb);
2766 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002767 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002768 return NETDEV_TX_OK;
2769}
2770
2771static int qeth_l3_open(struct net_device *dev)
2772{
2773 struct qeth_card *card = netdev_priv(dev);
2774
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002775 QETH_DBF_TEXT(TRACE, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002776 if (card->state != CARD_STATE_SOFTSETUP)
2777 return -ENODEV;
2778 card->data.state = CH_STATE_UP;
2779 card->state = CARD_STATE_UP;
2780 card->dev->flags |= IFF_UP;
2781 netif_start_queue(dev);
2782
2783 if (!card->lan_online && netif_carrier_ok(dev))
2784 netif_carrier_off(dev);
2785 return 0;
2786}
2787
2788static int qeth_l3_stop(struct net_device *dev)
2789{
2790 struct qeth_card *card = netdev_priv(dev);
2791
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002792 QETH_DBF_TEXT(TRACE, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002793 netif_tx_disable(dev);
2794 card->dev->flags &= ~IFF_UP;
2795 if (card->state == CARD_STATE_UP)
2796 card->state = CARD_STATE_SOFTSETUP;
2797 return 0;
2798}
2799
2800static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
2801{
2802 struct qeth_card *card = netdev_priv(dev);
2803
2804 return (card->options.checksum_type == HW_CHECKSUMMING);
2805}
2806
2807static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
2808{
2809 struct qeth_card *card = netdev_priv(dev);
2810 enum qeth_card_states old_state;
2811 enum qeth_checksum_types csum_type;
2812
2813 if ((card->state != CARD_STATE_UP) &&
2814 (card->state != CARD_STATE_DOWN))
2815 return -EPERM;
2816
2817 if (data)
2818 csum_type = HW_CHECKSUMMING;
2819 else
2820 csum_type = SW_CHECKSUMMING;
2821
2822 if (card->options.checksum_type != csum_type) {
2823 old_state = card->state;
2824 if (card->state == CARD_STATE_UP)
2825 __qeth_l3_set_offline(card->gdev, 1);
2826 card->options.checksum_type = csum_type;
2827 if (old_state == CARD_STATE_UP)
2828 __qeth_l3_set_online(card->gdev, 1);
2829 }
2830 return 0;
2831}
2832
2833static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
2834{
2835 struct qeth_card *card = netdev_priv(dev);
2836
2837 if (data) {
2838 if (card->options.large_send == QETH_LARGE_SEND_NO) {
2839 if (card->info.type == QETH_CARD_TYPE_IQD)
2840 card->options.large_send = QETH_LARGE_SEND_EDDP;
2841 else
2842 card->options.large_send = QETH_LARGE_SEND_TSO;
2843 dev->features |= NETIF_F_TSO;
2844 }
2845 } else {
2846 dev->features &= ~NETIF_F_TSO;
2847 card->options.large_send = QETH_LARGE_SEND_NO;
2848 }
2849 return 0;
2850}
2851
2852static struct ethtool_ops qeth_l3_ethtool_ops = {
2853 .get_link = ethtool_op_get_link,
2854 .get_tx_csum = ethtool_op_get_tx_csum,
2855 .set_tx_csum = ethtool_op_set_tx_hw_csum,
2856 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
2857 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
2858 .get_sg = ethtool_op_get_sg,
2859 .set_sg = ethtool_op_set_sg,
2860 .get_tso = ethtool_op_get_tso,
2861 .set_tso = qeth_l3_ethtool_set_tso,
2862 .get_strings = qeth_core_get_strings,
2863 .get_ethtool_stats = qeth_core_get_ethtool_stats,
2864 .get_stats_count = qeth_core_get_stats_count,
2865 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02002866 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002867};
2868
2869/*
2870 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2871 * NOARP on the netdevice is no option because it also turns off neighbor
2872 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2873 * arp resolution but we want the hard header (packet socket will work
2874 * e.g. tcpdump)
2875 */
2876static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2877{
2878 n->nud_state = NUD_NOARP;
2879 memcpy(n->ha, "FAKELL", 6);
2880 n->output = n->ops->connected_output;
2881 return 0;
2882}
2883
2884static int
2885qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2886{
2887 if (np->tbl->family == AF_INET)
2888 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2889
2890 return 0;
2891}
2892
2893static int qeth_l3_setup_netdev(struct qeth_card *card)
2894{
2895 if (card->info.type == QETH_CARD_TYPE_OSAE) {
2896 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2897 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
2898#ifdef CONFIG_TR
2899 card->dev = alloc_trdev(0);
2900#endif
2901 if (!card->dev)
2902 return -ENODEV;
2903 } else {
2904 card->dev = alloc_etherdev(0);
2905 if (!card->dev)
2906 return -ENODEV;
2907 card->dev->neigh_setup = qeth_l3_neigh_setup;
2908
2909 /*IPv6 address autoconfiguration stuff*/
2910 qeth_l3_get_unique_id(card);
2911 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2912 card->dev->dev_id = card->info.unique_id &
2913 0xffff;
2914 }
2915 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
2916 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
2917 if (!card->dev)
2918 return -ENODEV;
2919 card->dev->flags |= IFF_NOARP;
2920 qeth_l3_iqd_read_initial_mac(card);
2921 } else
2922 return -ENODEV;
2923
2924 card->dev->hard_start_xmit = qeth_l3_hard_start_xmit;
2925 card->dev->priv = card;
2926 card->dev->tx_timeout = &qeth_tx_timeout;
2927 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
2928 card->dev->open = qeth_l3_open;
2929 card->dev->stop = qeth_l3_stop;
2930 card->dev->do_ioctl = qeth_l3_do_ioctl;
2931 card->dev->get_stats = qeth_get_stats;
2932 card->dev->change_mtu = qeth_change_mtu;
2933 card->dev->set_multicast_list = qeth_l3_set_multicast_list;
2934 card->dev->vlan_rx_register = qeth_l3_vlan_rx_register;
2935 card->dev->vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid;
2936 card->dev->vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid;
2937 card->dev->mtu = card->info.initial_mtu;
Frank Blaschkab7624ec2008-04-01 10:26:57 +02002938 card->dev->set_mac_address = NULL;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002939 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
2940 card->dev->features |= NETIF_F_HW_VLAN_TX |
2941 NETIF_F_HW_VLAN_RX |
2942 NETIF_F_HW_VLAN_FILTER;
2943
2944 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
2945 return register_netdev(card->dev);
2946}
2947
2948static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
2949 unsigned int status, unsigned int qdio_err,
2950 unsigned int siga_err, unsigned int queue, int first_element,
2951 int count, unsigned long card_ptr)
2952{
2953 struct net_device *net_dev;
2954 struct qeth_card *card;
2955 struct qeth_qdio_buffer *buffer;
2956 int index;
2957 int i;
2958
Frank Blaschka4a71df52008-02-15 09:19:42 +01002959 card = (struct qeth_card *) card_ptr;
2960 net_dev = card->dev;
2961 if (card->options.performance_stats) {
2962 card->perf_stats.inbound_cnt++;
2963 card->perf_stats.inbound_start_time = qeth_get_micros();
2964 }
2965 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2966 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002967 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
2968 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2969 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X",
Frank Blaschka4a71df52008-02-15 09:19:42 +01002970 first_element, count);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002971 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", queue, status);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002972 qeth_schedule_recovery(card);
2973 return;
2974 }
2975 }
2976 for (i = first_element; i < (first_element + count); ++i) {
2977 index = i % QDIO_MAX_BUFFERS_PER_Q;
2978 buffer = &card->qdio.in_q->bufs[index];
2979 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
2980 qeth_check_qdio_errors(buffer->buffer,
2981 qdio_err, siga_err, "qinerr")))
2982 qeth_l3_process_inbound_buffer(card, buffer, index);
2983 /* clear buffer and give back to hardware */
2984 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2985 qeth_queue_input_buffer(card, index);
2986 }
2987 if (card->options.performance_stats)
2988 card->perf_stats.inbound_time += qeth_get_micros() -
2989 card->perf_stats.inbound_start_time;
2990}
2991
2992static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2993{
2994 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2995
2996 qeth_l3_create_device_attributes(&gdev->dev);
2997 card->options.layer2 = 0;
2998 card->discipline.input_handler = (qdio_handler_t *)
2999 qeth_l3_qdio_input_handler;
3000 card->discipline.output_handler = (qdio_handler_t *)
3001 qeth_qdio_output_handler;
3002 card->discipline.recover = qeth_l3_recover;
3003 return 0;
3004}
3005
3006static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3007{
3008 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3009
3010 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3011
3012 if (cgdev->state == CCWGROUP_ONLINE) {
3013 card->use_hard_stop = 1;
3014 qeth_l3_set_offline(cgdev);
3015 }
3016
3017 if (card->dev) {
3018 unregister_netdev(card->dev);
3019 card->dev = NULL;
3020 }
3021
3022 qeth_l3_remove_device_attributes(&cgdev->dev);
3023 qeth_l3_clear_ip_list(card, 0, 0);
3024 qeth_l3_clear_ipato_list(card);
3025 return;
3026}
3027
3028static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3029{
3030 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3031 int rc = 0;
3032 enum qeth_card_states recover_flag;
3033
3034 BUG_ON(!card);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003035 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3036 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003037
3038 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
3039 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)) {
3040 PRINT_WARN("set_online of card %s interrupted by user!\n",
3041 CARD_BUS_ID(card));
3042 return -ERESTARTSYS;
3043 }
3044
3045 recover_flag = card->state;
3046 rc = ccw_device_set_online(CARD_RDEV(card));
3047 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003048 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003049 return -EIO;
3050 }
3051 rc = ccw_device_set_online(CARD_WDEV(card));
3052 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003053 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003054 return -EIO;
3055 }
3056 rc = ccw_device_set_online(CARD_DDEV(card));
3057 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003058 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003059 return -EIO;
3060 }
3061
3062 rc = qeth_core_hardsetup_card(card);
3063 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003064 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003065 goto out_remove;
3066 }
3067
3068 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3069
3070 if (!card->dev && qeth_l3_setup_netdev(card))
3071 goto out_remove;
3072
3073 card->state = CARD_STATE_HARDSETUP;
3074 qeth_print_status_message(card);
3075
3076 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003077 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003078
3079 rc = qeth_send_startlan(card);
3080 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003081 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003082 if (rc == 0xe080) {
3083 PRINT_WARN("LAN on card %s if offline! "
3084 "Waiting for STARTLAN from card.\n",
3085 CARD_BUS_ID(card));
3086 card->lan_online = 0;
3087 }
3088 return rc;
3089 } else
3090 card->lan_online = 1;
3091 qeth_set_large_send(card, card->options.large_send);
3092
3093 rc = qeth_l3_setadapter_parms(card);
3094 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003095 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003096 rc = qeth_l3_start_ipassists(card);
3097 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003098 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003099 rc = qeth_l3_setrouting_v4(card);
3100 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003101 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003102 rc = qeth_l3_setrouting_v6(card);
3103 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003104 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003105 netif_tx_disable(card->dev);
3106
3107 rc = qeth_init_qdio_queues(card);
3108 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003109 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003110 goto out_remove;
3111 }
3112 card->state = CARD_STATE_SOFTSETUP;
3113 netif_carrier_on(card->dev);
3114
3115 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003116 if (recover_flag == CARD_STATE_RECOVER) {
3117 if (recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003118 qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003119 else {
3120 rtnl_lock();
3121 dev_open(card->dev);
3122 rtnl_unlock();
3123 }
3124 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003125 }
3126 /* let user_space know that device is online */
3127 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3128 return 0;
3129out_remove:
3130 card->use_hard_stop = 1;
3131 qeth_l3_stop_card(card, 0);
3132 ccw_device_set_offline(CARD_DDEV(card));
3133 ccw_device_set_offline(CARD_WDEV(card));
3134 ccw_device_set_offline(CARD_RDEV(card));
3135 if (recover_flag == CARD_STATE_RECOVER)
3136 card->state = CARD_STATE_RECOVER;
3137 else
3138 card->state = CARD_STATE_DOWN;
3139 return -ENODEV;
3140}
3141
3142static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3143{
3144 return __qeth_l3_set_online(gdev, 0);
3145}
3146
3147static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3148 int recovery_mode)
3149{
3150 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3151 int rc = 0, rc2 = 0, rc3 = 0;
3152 enum qeth_card_states recover_flag;
3153
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003154 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3155 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003156
3157 if (card->dev && netif_carrier_ok(card->dev))
3158 netif_carrier_off(card->dev);
3159 recover_flag = card->state;
3160 if (qeth_l3_stop_card(card, recovery_mode) == -ERESTARTSYS) {
3161 PRINT_WARN("Stopping card %s interrupted by user!\n",
3162 CARD_BUS_ID(card));
3163 return -ERESTARTSYS;
3164 }
3165 rc = ccw_device_set_offline(CARD_DDEV(card));
3166 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3167 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3168 if (!rc)
3169 rc = (rc2) ? rc2 : rc3;
3170 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003171 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003172 if (recover_flag == CARD_STATE_UP)
3173 card->state = CARD_STATE_RECOVER;
3174 /* let user_space know that device is offline */
3175 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3176 return 0;
3177}
3178
3179static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3180{
3181 return __qeth_l3_set_offline(cgdev, 0);
3182}
3183
3184static int qeth_l3_recover(void *ptr)
3185{
3186 struct qeth_card *card;
3187 int rc = 0;
3188
3189 card = (struct qeth_card *) ptr;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003190 QETH_DBF_TEXT(TRACE, 2, "recover1");
3191 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003192 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3193 return 0;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003194 QETH_DBF_TEXT(TRACE, 2, "recover2");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003195 PRINT_WARN("Recovery of device %s started ...\n",
3196 CARD_BUS_ID(card));
3197 card->use_hard_stop = 1;
3198 __qeth_l3_set_offline(card->gdev, 1);
3199 rc = __qeth_l3_set_online(card->gdev, 1);
3200 /* don't run another scheduled recovery */
3201 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3202 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3203 if (!rc)
3204 PRINT_INFO("Device %s successfully recovered!\n",
3205 CARD_BUS_ID(card));
3206 else
3207 PRINT_INFO("Device %s could not be recovered!\n",
3208 CARD_BUS_ID(card));
3209 return 0;
3210}
3211
3212static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3213{
3214 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3215 qeth_l3_clear_ip_list(card, 0, 0);
3216 qeth_qdio_clear_card(card, 0);
3217 qeth_clear_qdio_buffers(card);
3218}
3219
3220struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3221 .probe = qeth_l3_probe_device,
3222 .remove = qeth_l3_remove_device,
3223 .set_online = qeth_l3_set_online,
3224 .set_offline = qeth_l3_set_offline,
3225 .shutdown = qeth_l3_shutdown,
3226};
3227EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3228
3229static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003230 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003231{
3232 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3233 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3234 struct qeth_ipaddr *addr;
3235 struct qeth_card *card;
3236
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003237 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003238 return NOTIFY_DONE;
3239
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003240 QETH_DBF_TEXT(TRACE, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003241 card = qeth_l3_get_card_from_dev(dev);
3242 if (!card)
3243 return NOTIFY_DONE;
3244
3245 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3246 if (addr != NULL) {
3247 addr->u.a4.addr = ifa->ifa_address;
3248 addr->u.a4.mask = ifa->ifa_mask;
3249 addr->type = QETH_IP_TYPE_NORMAL;
3250 } else
3251 goto out;
3252
3253 switch (event) {
3254 case NETDEV_UP:
3255 if (!qeth_l3_add_ip(card, addr))
3256 kfree(addr);
3257 break;
3258 case NETDEV_DOWN:
3259 if (!qeth_l3_delete_ip(card, addr))
3260 kfree(addr);
3261 break;
3262 default:
3263 break;
3264 }
3265 qeth_l3_set_ip_addr_list(card);
3266out:
3267 return NOTIFY_DONE;
3268}
3269
3270static struct notifier_block qeth_l3_ip_notifier = {
3271 qeth_l3_ip_event,
3272 NULL,
3273};
3274
3275#ifdef CONFIG_QETH_IPV6
3276/**
3277 * IPv6 event handler
3278 */
3279static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003280 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003281{
3282 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3283 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3284 struct qeth_ipaddr *addr;
3285 struct qeth_card *card;
3286
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003287 QETH_DBF_TEXT(TRACE, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003288
3289 card = qeth_l3_get_card_from_dev(dev);
3290 if (!card)
3291 return NOTIFY_DONE;
3292 if (!qeth_is_supported(card, IPA_IPV6))
3293 return NOTIFY_DONE;
3294
3295 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3296 if (addr != NULL) {
3297 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3298 addr->u.a6.pfxlen = ifa->prefix_len;
3299 addr->type = QETH_IP_TYPE_NORMAL;
3300 } else
3301 goto out;
3302
3303 switch (event) {
3304 case NETDEV_UP:
3305 if (!qeth_l3_add_ip(card, addr))
3306 kfree(addr);
3307 break;
3308 case NETDEV_DOWN:
3309 if (!qeth_l3_delete_ip(card, addr))
3310 kfree(addr);
3311 break;
3312 default:
3313 break;
3314 }
3315 qeth_l3_set_ip_addr_list(card);
3316out:
3317 return NOTIFY_DONE;
3318}
3319
3320static struct notifier_block qeth_l3_ip6_notifier = {
3321 qeth_l3_ip6_event,
3322 NULL,
3323};
3324#endif
3325
3326static int qeth_l3_register_notifiers(void)
3327{
3328 int rc;
3329
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003330 QETH_DBF_TEXT(TRACE, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003331 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3332 if (rc)
3333 return rc;
3334#ifdef CONFIG_QETH_IPV6
3335 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3336 if (rc) {
3337 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3338 return rc;
3339 }
3340#else
3341 PRINT_WARN("layer 3 discipline no IPv6 support\n");
3342#endif
3343 return 0;
3344}
3345
3346static void qeth_l3_unregister_notifiers(void)
3347{
3348
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003349 QETH_DBF_TEXT(TRACE, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003350 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3351#ifdef CONFIG_QETH_IPV6
3352 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3353#endif /* QETH_IPV6 */
3354}
3355
3356static int __init qeth_l3_init(void)
3357{
3358 int rc = 0;
3359
3360 PRINT_INFO("register layer 3 discipline\n");
3361 rc = qeth_l3_register_notifiers();
3362 return rc;
3363}
3364
3365static void __exit qeth_l3_exit(void)
3366{
3367 qeth_l3_unregister_notifiers();
3368 PRINT_INFO("unregister layer 3 discipline\n");
3369}
3370
3371module_init(qeth_l3_init);
3372module_exit(qeth_l3_exit);
3373MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3374MODULE_DESCRIPTION("qeth layer 3 discipline");
3375MODULE_LICENSE("GPL");