blob: fd69da3fa6b44d0afe34e550f027680b9f8da6b0 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
2 * drivers/s390/net/qeth_l3_main.c
3 *
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02004 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01005 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
10
Frank Blaschka74eacdb2008-12-25 13:39:49 +010011#define KMSG_COMPONENT "qeth"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Frank Blaschka4a71df52008-02-15 09:19:42 +010014#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/etherdevice.h>
20#include <linux/mii.h>
21#include <linux/ip.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000022#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010023#include <linux/inetdevice.h>
24#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
27#include <net/ip.h>
28#include <net/arp.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000029#include <net/ip6_checksum.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010030
Frank Blaschka4a71df52008-02-15 09:19:42 +010031#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010032
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000033
Frank Blaschka4a71df52008-02-15 09:19:42 +010034static int qeth_l3_set_offline(struct ccwgroup_device *);
35static int qeth_l3_recover(void *);
36static int qeth_l3_stop(struct net_device *);
37static void qeth_l3_set_multicast_list(struct net_device *);
38static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
39static int qeth_l3_register_addr_entry(struct qeth_card *,
40 struct qeth_ipaddr *);
41static int qeth_l3_deregister_addr_entry(struct qeth_card *,
42 struct qeth_ipaddr *);
43static int __qeth_l3_set_online(struct ccwgroup_device *, int);
44static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
45
Frank Blaschka4a71df52008-02-15 09:19:42 +010046static int qeth_l3_isxdigit(char *buf)
47{
48 while (*buf) {
49 if (!isxdigit(*buf++))
50 return 0;
51 }
52 return 1;
53}
54
55void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
56{
57 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
58}
59
60int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
61{
62 int count = 0, rc = 0;
63 int in[4];
64 char c;
65
66 rc = sscanf(buf, "%u.%u.%u.%u%c",
67 &in[0], &in[1], &in[2], &in[3], &c);
68 if (rc != 4 && (rc != 5 || c != '\n'))
69 return -EINVAL;
70 for (count = 0; count < 4; count++) {
71 if (in[count] > 255)
72 return -EINVAL;
73 addr[count] = in[count];
74 }
75 return 0;
76}
77
78void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
79{
Joe Perches963a9fd2010-09-07 21:14:40 +000080 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010081}
82
83int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
84{
85 const char *end, *end_tmp, *start;
86 __u16 *in;
87 char num[5];
88 int num2, cnt, out, found, save_cnt;
89 unsigned short in_tmp[8] = {0, };
90
91 cnt = out = found = save_cnt = num2 = 0;
92 end = start = buf;
93 in = (__u16 *) addr;
94 memset(in, 0, 16);
95 while (*end) {
96 end = strchr(start, ':');
97 if (end == NULL) {
98 end = buf + strlen(buf);
99 end_tmp = strchr(start, '\n');
100 if (end_tmp != NULL)
101 end = end_tmp;
102 out = 1;
103 }
104 if ((end - start)) {
105 memset(num, 0, 5);
106 if ((end - start) > 4)
107 return -EINVAL;
108 memcpy(num, start, end - start);
109 if (!qeth_l3_isxdigit(num))
110 return -EINVAL;
111 sscanf(start, "%x", &num2);
112 if (found)
113 in_tmp[save_cnt++] = num2;
114 else
115 in[cnt++] = num2;
116 if (out)
117 break;
118 } else {
119 if (found)
120 return -EINVAL;
121 found = 1;
122 }
123 start = ++end;
124 }
125 if (cnt + save_cnt > 8)
126 return -EINVAL;
127 cnt = 7;
128 while (save_cnt)
129 in[cnt--] = in_tmp[--save_cnt];
130 return 0;
131}
132
133void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
134 char *buf)
135{
136 if (proto == QETH_PROT_IPV4)
137 qeth_l3_ipaddr4_to_string(addr, buf);
138 else if (proto == QETH_PROT_IPV6)
139 qeth_l3_ipaddr6_to_string(addr, buf);
140}
141
142int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
143 __u8 *addr)
144{
145 if (proto == QETH_PROT_IPV4)
146 return qeth_l3_string_to_ipaddr4(buf, addr);
147 else if (proto == QETH_PROT_IPV6)
148 return qeth_l3_string_to_ipaddr6(buf, addr);
149 else
150 return -EINVAL;
151}
152
153static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
154{
155 int i, j;
156 u8 octet;
157
158 for (i = 0; i < len; ++i) {
159 octet = addr[i];
160 for (j = 7; j >= 0; --j) {
161 bits[i*8 + j] = octet & 1;
162 octet >>= 1;
163 }
164 }
165}
166
Klaus-Dieter Wacker62982632010-07-22 23:15:03 +0000167int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100168 struct qeth_ipaddr *addr)
169{
170 struct qeth_ipato_entry *ipatoe;
171 u8 addr_bits[128] = {0, };
172 u8 ipatoe_bits[128] = {0, };
173 int rc = 0;
174
175 if (!card->ipato.enabled)
176 return 0;
177
178 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
179 (addr->proto == QETH_PROT_IPV4)? 4:16);
180 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
181 if (addr->proto != ipatoe->proto)
182 continue;
183 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
184 (ipatoe->proto == QETH_PROT_IPV4) ?
185 4 : 16);
186 if (addr->proto == QETH_PROT_IPV4)
187 rc = !memcmp(addr_bits, ipatoe_bits,
188 min(32, ipatoe->mask_bits));
189 else
190 rc = !memcmp(addr_bits, ipatoe_bits,
191 min(128, ipatoe->mask_bits));
192 if (rc)
193 break;
194 }
195 /* invert? */
196 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
197 rc = !rc;
198 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
199 rc = !rc;
200
201 return rc;
202}
203
204/*
205 * Add IP to be added to todo list. If there is already an "add todo"
206 * in this list we just incremenent the reference count.
207 * Returns 0 if we just incremented reference count.
208 */
209static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
210 struct qeth_ipaddr *addr, int add)
211{
212 struct qeth_ipaddr *tmp, *t;
213 int found = 0;
214
Ursula Braun76b11f82010-01-11 02:50:50 +0000215 if (card->options.sniffer)
216 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100217 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
218 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
219 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
220 return 0;
221 if ((tmp->proto == QETH_PROT_IPV4) &&
222 (addr->proto == QETH_PROT_IPV4) &&
223 (tmp->type == addr->type) &&
224 (tmp->is_multicast == addr->is_multicast) &&
225 (tmp->u.a4.addr == addr->u.a4.addr) &&
226 (tmp->u.a4.mask == addr->u.a4.mask)) {
227 found = 1;
228 break;
229 }
230 if ((tmp->proto == QETH_PROT_IPV6) &&
231 (addr->proto == QETH_PROT_IPV6) &&
232 (tmp->type == addr->type) &&
233 (tmp->is_multicast == addr->is_multicast) &&
234 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
235 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
236 sizeof(struct in6_addr)) == 0)) {
237 found = 1;
238 break;
239 }
240 }
241 if (found) {
242 if (addr->users != 0)
243 tmp->users += addr->users;
244 else
245 tmp->users += add ? 1 : -1;
246 if (tmp->users == 0) {
247 list_del(&tmp->entry);
248 kfree(tmp);
249 }
250 return 0;
251 } else {
252 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
253 list_add(&addr->entry, card->ip_tbd_list);
254 else {
255 if (addr->users == 0)
256 addr->users += add ? 1 : -1;
257 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
258 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000259 QETH_CARD_TEXT(card, 2, "tkovaddr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100260 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
261 }
262 list_add_tail(&addr->entry, card->ip_tbd_list);
263 }
264 return 1;
265 }
266}
267
268static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
269{
270 unsigned long flags;
271 int rc = 0;
272
Carsten Otte847a50f2010-06-21 22:57:05 +0000273 QETH_CARD_TEXT(card, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274
275 if (addr->proto == QETH_PROT_IPV4)
Carsten Otte847a50f2010-06-21 22:57:05 +0000276 QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277 else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000278 QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
279 QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100280 }
281 spin_lock_irqsave(&card->ip_lock, flags);
282 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
283 spin_unlock_irqrestore(&card->ip_lock, flags);
284 return rc;
285}
286
287static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
288{
289 unsigned long flags;
290 int rc = 0;
291
Carsten Otte847a50f2010-06-21 22:57:05 +0000292 QETH_CARD_TEXT(card, 4, "addip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100293 if (addr->proto == QETH_PROT_IPV4)
Carsten Otte847a50f2010-06-21 22:57:05 +0000294 QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100295 else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000296 QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
297 QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100298 }
299 spin_lock_irqsave(&card->ip_lock, flags);
300 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
301 spin_unlock_irqrestore(&card->ip_lock, flags);
302 return rc;
303}
304
305
306static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
307 enum qeth_prot_versions prot)
308{
309 struct qeth_ipaddr *addr;
310
311 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
312 if (addr == NULL) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100313 return NULL;
314 }
315 addr->type = QETH_IP_TYPE_NORMAL;
316 addr->proto = prot;
317 return addr;
318}
319
320static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
321{
322 struct qeth_ipaddr *iptodo;
323 unsigned long flags;
324
Carsten Otte847a50f2010-06-21 22:57:05 +0000325 QETH_CARD_TEXT(card, 4, "delmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100326 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
327 if (!iptodo) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000328 QETH_CARD_TEXT(card, 2, "dmcnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329 return;
330 }
331 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
332 spin_lock_irqsave(&card->ip_lock, flags);
333 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
334 kfree(iptodo);
335 spin_unlock_irqrestore(&card->ip_lock, flags);
336}
337
338/*
339 * Add/remove address to/from card's ip list, i.e. try to add or remove
340 * reference to/from an IP address that is already registered on the card.
341 * Returns:
342 * 0 address was on card and its reference count has been adjusted,
343 * but is still > 0, so nothing has to be done
344 * also returns 0 if card was not on card and the todo was to delete
345 * the address -> there is also nothing to be done
346 * 1 address was not on card and the todo is to add it to the card's ip
347 * list
348 * -1 address was on card and its reference count has been decremented
349 * to <= 0 by the todo -> address must be removed from card
350 */
351static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
352 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
353{
354 struct qeth_ipaddr *addr;
355 int found = 0;
356
357 list_for_each_entry(addr, &card->ip_list, entry) {
358 if ((addr->proto == QETH_PROT_IPV4) &&
359 (todo->proto == QETH_PROT_IPV4) &&
360 (addr->type == todo->type) &&
361 (addr->u.a4.addr == todo->u.a4.addr) &&
362 (addr->u.a4.mask == todo->u.a4.mask)) {
363 found = 1;
364 break;
365 }
366 if ((addr->proto == QETH_PROT_IPV6) &&
367 (todo->proto == QETH_PROT_IPV6) &&
368 (addr->type == todo->type) &&
369 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
370 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
371 sizeof(struct in6_addr)) == 0)) {
372 found = 1;
373 break;
374 }
375 }
376 if (found) {
377 addr->users += todo->users;
378 if (addr->users <= 0) {
379 *__addr = addr;
380 return -1;
381 } else {
382 /* for VIPA and RXIP limit refcount to 1 */
383 if (addr->type != QETH_IP_TYPE_NORMAL)
384 addr->users = 1;
385 return 0;
386 }
387 }
388 if (todo->users > 0) {
389 /* for VIPA and RXIP limit refcount to 1 */
390 if (todo->type != QETH_IP_TYPE_NORMAL)
391 todo->users = 1;
392 return 1;
393 } else
394 return 0;
395}
396
397static void __qeth_l3_delete_all_mc(struct qeth_card *card,
398 unsigned long *flags)
399{
Ursula Braun2d921c32008-04-01 10:26:53 +0200400 struct list_head fail_list;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401 struct qeth_ipaddr *addr, *tmp;
402 int rc;
Ursula Braun2d921c32008-04-01 10:26:53 +0200403
404 INIT_LIST_HEAD(&fail_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100405again:
406 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
407 if (addr->is_multicast) {
408 list_del(&addr->entry);
409 spin_unlock_irqrestore(&card->ip_lock, *flags);
410 rc = qeth_l3_deregister_addr_entry(card, addr);
411 spin_lock_irqsave(&card->ip_lock, *flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200412 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100413 kfree(addr);
Ursula Braun2d921c32008-04-01 10:26:53 +0200414 else
415 list_add_tail(&addr->entry, &fail_list);
416 goto again;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100417 }
418 }
Ursula Braun2d921c32008-04-01 10:26:53 +0200419 list_splice(&fail_list, &card->ip_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100420}
421
422static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
423{
424 struct list_head *tbd_list;
425 struct qeth_ipaddr *todo, *addr;
426 unsigned long flags;
427 int rc;
428
Carsten Otte847a50f2010-06-21 22:57:05 +0000429 QETH_CARD_TEXT(card, 2, "sdiplist");
430 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431
Einar Lueckf154b792010-12-08 02:57:59 +0000432 if ((card->state != CARD_STATE_UP &&
433 card->state != CARD_STATE_SOFTSETUP) || card->options.sniffer) {
Ursula Braun76b11f82010-01-11 02:50:50 +0000434 return;
Einar Lueckf154b792010-12-08 02:57:59 +0000435 }
436
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437 spin_lock_irqsave(&card->ip_lock, flags);
438 tbd_list = card->ip_tbd_list;
439 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
440 if (!card->ip_tbd_list) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000441 QETH_CARD_TEXT(card, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100442 card->ip_tbd_list = tbd_list;
443 spin_unlock_irqrestore(&card->ip_lock, flags);
444 return;
445 } else
446 INIT_LIST_HEAD(card->ip_tbd_list);
447
448 while (!list_empty(tbd_list)) {
449 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
450 list_del(&todo->entry);
451 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
452 __qeth_l3_delete_all_mc(card, &flags);
453 kfree(todo);
454 continue;
455 }
456 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
457 if (rc == 0) {
458 /* nothing to be done; only adjusted refcount */
459 kfree(todo);
460 } else if (rc == 1) {
461 /* new entry to be added to on-card list */
462 spin_unlock_irqrestore(&card->ip_lock, flags);
463 rc = qeth_l3_register_addr_entry(card, todo);
464 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200465 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100466 list_add_tail(&todo->entry, &card->ip_list);
467 else
468 kfree(todo);
469 } else if (rc == -1) {
470 /* on-card entry to be removed */
471 list_del_init(&addr->entry);
472 spin_unlock_irqrestore(&card->ip_lock, flags);
473 rc = qeth_l3_deregister_addr_entry(card, addr);
474 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun76b11f82010-01-11 02:50:50 +0000475 if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100476 kfree(addr);
477 else
478 list_add_tail(&addr->entry, &card->ip_list);
479 kfree(todo);
480 }
481 }
482 spin_unlock_irqrestore(&card->ip_lock, flags);
483 kfree(tbd_list);
484}
485
Ursula Braun70919e22011-02-26 22:41:36 -0800486static void qeth_l3_clear_ip_list(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100487{
488 struct qeth_ipaddr *addr, *tmp;
489 unsigned long flags;
490
Carsten Otte847a50f2010-06-21 22:57:05 +0000491 QETH_CARD_TEXT(card, 4, "clearip");
Ursula Braun76b11f82010-01-11 02:50:50 +0000492 if (recover && card->options.sniffer)
493 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100494 spin_lock_irqsave(&card->ip_lock, flags);
495 /* clear todo list */
496 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
497 list_del(&addr->entry);
498 kfree(addr);
499 }
500
501 while (!list_empty(&card->ip_list)) {
502 addr = list_entry(card->ip_list.next,
503 struct qeth_ipaddr, entry);
504 list_del_init(&addr->entry);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100505 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
Carsten Otte847a50f2010-06-21 22:57:05 +0000546 QETH_CARD_TEXT(card, 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
Carsten Otte847a50f2010-06-21 22:57:05 +0000584 QETH_CARD_TEXT(card, 4, "setdelip");
585 QETH_CARD_TEXT_(card, 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
Carsten Otte847a50f2010-06-21 22:57:05 +0000614 QETH_CARD_TEXT(card, 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
Carsten Otte847a50f2010-06-21 22:57:05 +0000658 QETH_CARD_TEXT(card, 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
Carsten Otte847a50f2010-06-21 22:57:05 +0000678 QETH_CARD_TEXT(card, 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
Carsten Otte847a50f2010-06-21 22:57:05 +0000722 QETH_CARD_TEXT(card, 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
Carsten Otte847a50f2010-06-21 22:57:05 +0000747 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000775 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000779 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000810 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000814 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000839 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000843 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000874 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000878 QETH_CARD_TEXT(card, 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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000898 QETH_CARD_TEXT(card, 2, "setaddr4");
899 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100900 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000901 QETH_CARD_TEXT(card, 2, "setaddr6");
902 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
903 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000905 QETH_CARD_TEXT(card, 2, "setaddr?");
906 QETH_CARD_HEX(card, 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)
Carsten Otte847a50f2010-06-21 22:57:05 +0000915 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 } while ((--cnt > 0) && rc);
917 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000918 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100920 dev_warn(&card->gdev->dev,
921 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100922 }
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) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000932 QETH_CARD_TEXT(card, 2, "deladdr4");
933 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100934 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000935 QETH_CARD_TEXT(card, 2, "deladdr6");
936 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
937 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000939 QETH_CARD_TEXT(card, 2, "deladdr?");
940 QETH_CARD_HEX(card, 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);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200947 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000948 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949
950 return rc;
951}
952
953static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
954{
955 if (cast_type == RTN_MULTICAST)
956 return QETH_CAST_MULTICAST;
957 if (cast_type == RTN_BROADCAST)
958 return QETH_CAST_BROADCAST;
959 return QETH_CAST_UNICAST;
960}
961
962static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
963{
964 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
965 if (cast_type == RTN_MULTICAST)
966 return ct | QETH_CAST_MULTICAST;
967 if (cast_type == RTN_ANYCAST)
968 return ct | QETH_CAST_ANYCAST;
969 if (cast_type == RTN_BROADCAST)
970 return ct | QETH_CAST_BROADCAST;
971 return ct | QETH_CAST_UNICAST;
972}
973
974static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
975 __u32 mode)
976{
977 int rc;
978 struct qeth_cmd_buffer *iob;
979 struct qeth_ipa_cmd *cmd;
980
Carsten Otte847a50f2010-06-21 22:57:05 +0000981 QETH_CARD_TEXT(card, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100982
983 iob = qeth_get_adapter_cmd(card, command,
984 sizeof(struct qeth_ipacmd_setadpparms));
985 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
986 cmd->data.setadapterparms.data.mode = mode;
987 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
988 NULL);
989 return rc;
990}
991
992static int qeth_l3_setadapter_hstr(struct qeth_card *card)
993{
994 int rc;
995
Carsten Otte847a50f2010-06-21 22:57:05 +0000996 QETH_CARD_TEXT(card, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100997
998 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
999 rc = qeth_l3_send_setadp_mode(card,
1000 IPA_SETADP_SET_BROADCAST_MODE,
1001 card->options.broadcast_mode);
1002 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001003 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001004 "device %s: x%x\n",
1005 CARD_BUS_ID(card), rc);
1006 rc = qeth_l3_send_setadp_mode(card,
1007 IPA_SETADP_ALTER_MAC_ADDRESS,
1008 card->options.macaddr_mode);
1009 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001010 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1012 return rc;
1013 }
1014 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001015 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001016 "to set broadcast mode, using ALLRINGS "
1017 "on device %s:\n", CARD_BUS_ID(card));
1018 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001019 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001020 "to set macaddr mode, using NONCANONICAL "
1021 "on device %s:\n", CARD_BUS_ID(card));
1022 return 0;
1023}
1024
1025static int qeth_l3_setadapter_parms(struct qeth_card *card)
1026{
1027 int rc;
1028
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001029 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001030
1031 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001032 dev_info(&card->gdev->dev,
1033 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001034 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001035 return 0;
1036 }
1037 rc = qeth_query_setadapterparms(card);
1038 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001039 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +00001040 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001041 return rc;
1042 }
1043 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1044 rc = qeth_setadpparms_change_macaddr(card);
1045 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001046 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001047 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001048 }
1049
1050 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1051 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1052 rc = qeth_l3_setadapter_hstr(card);
1053
1054 return rc;
1055}
1056
1057static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1058 struct qeth_reply *reply, unsigned long data)
1059{
1060 struct qeth_ipa_cmd *cmd;
1061
Carsten Otte847a50f2010-06-21 22:57:05 +00001062 QETH_CARD_TEXT(card, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001063
1064 cmd = (struct qeth_ipa_cmd *) data;
1065 if (cmd->hdr.return_code == 0) {
1066 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1067 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1068 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1069 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1070 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1071 }
1072 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1073 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1074 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001075 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001076 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001077 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1078 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1079 card->info.tx_csum_mask =
1080 cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001081 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001082 }
1083
Frank Blaschka4a71df52008-02-15 09:19:42 +01001084 return 0;
1085}
1086
1087static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1088 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1089 __u16 len, enum qeth_prot_versions prot)
1090{
1091 struct qeth_cmd_buffer *iob;
1092 struct qeth_ipa_cmd *cmd;
1093
Carsten Otte847a50f2010-06-21 22:57:05 +00001094 QETH_CARD_TEXT(card, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001095 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1096
1097 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1098 cmd->data.setassparms.hdr.assist_no = ipa_func;
1099 cmd->data.setassparms.hdr.length = 8 + len;
1100 cmd->data.setassparms.hdr.command_code = cmd_code;
1101 cmd->data.setassparms.hdr.return_code = 0;
1102 cmd->data.setassparms.hdr.seq_no = 0;
1103
1104 return iob;
1105}
1106
1107static int qeth_l3_send_setassparms(struct qeth_card *card,
1108 struct qeth_cmd_buffer *iob, __u16 len, long data,
1109 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1110 unsigned long),
1111 void *reply_param)
1112{
1113 int rc;
1114 struct qeth_ipa_cmd *cmd;
1115
Carsten Otte847a50f2010-06-21 22:57:05 +00001116 QETH_CARD_TEXT(card, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001117
1118 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1119 if (len <= sizeof(__u32))
1120 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1121 else /* (len > sizeof(__u32)) */
1122 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1123
1124 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1125 return rc;
1126}
1127
1128#ifdef CONFIG_QETH_IPV6
1129static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1130 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1131{
1132 int rc;
1133 struct qeth_cmd_buffer *iob;
1134
Carsten Otte847a50f2010-06-21 22:57:05 +00001135 QETH_CARD_TEXT(card, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001136 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1137 0, QETH_PROT_IPV6);
1138 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1139 qeth_l3_default_setassparms_cb, NULL);
1140 return rc;
1141}
1142#endif
1143
1144static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1145 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1146{
1147 int rc;
1148 int length = 0;
1149 struct qeth_cmd_buffer *iob;
1150
Carsten Otte847a50f2010-06-21 22:57:05 +00001151 QETH_CARD_TEXT(card, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001152 if (data)
1153 length = sizeof(__u32);
1154 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1155 length, QETH_PROT_IPV4);
1156 rc = qeth_l3_send_setassparms(card, iob, length, data,
1157 qeth_l3_default_setassparms_cb, NULL);
1158 return rc;
1159}
1160
1161static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1162{
1163 int rc;
1164
Carsten Otte847a50f2010-06-21 22:57:05 +00001165 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001166
1167 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001168 dev_info(&card->gdev->dev,
1169 "ARP processing not supported on %s!\n",
1170 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001171 return 0;
1172 }
1173 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1174 IPA_CMD_ASS_START, 0);
1175 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001176 dev_warn(&card->gdev->dev,
1177 "Starting ARP processing support for %s failed\n",
1178 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001179 }
1180 return rc;
1181}
1182
1183static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1184{
1185 int rc;
1186
Carsten Otte847a50f2010-06-21 22:57:05 +00001187 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001188
1189 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001190 dev_info(&card->gdev->dev,
1191 "Hardware IP fragmentation not supported on %s\n",
1192 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001193 return -EOPNOTSUPP;
1194 }
1195
1196 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1197 IPA_CMD_ASS_START, 0);
1198 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001199 dev_warn(&card->gdev->dev,
1200 "Starting IP fragmentation support for %s failed\n",
1201 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001203 dev_info(&card->gdev->dev,
1204 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001205 return rc;
1206}
1207
1208static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1209{
1210 int rc;
1211
Carsten Otte847a50f2010-06-21 22:57:05 +00001212 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001213
Frank Blaschka4a71df52008-02-15 09:19:42 +01001214 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001215 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001216 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001217 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001218 return -EOPNOTSUPP;
1219 }
1220
1221 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1222 IPA_CMD_ASS_START, 0);
1223 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001224 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001225 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001226 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001227 return rc;
1228}
1229
1230static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1231{
1232 int rc = 0;
1233
Carsten Otte847a50f2010-06-21 22:57:05 +00001234 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235
1236 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001237 dev_info(&card->gdev->dev,
1238 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001239 return -EOPNOTSUPP;
1240 }
1241
1242 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1243 IPA_CMD_ASS_START, 0);
1244 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001245 dev_warn(&card->gdev->dev,
1246 "Starting VLAN support for %s failed\n",
1247 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001248 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001249 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001250 }
1251 return rc;
1252}
1253
1254static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1255{
1256 int rc;
1257
Carsten Otte847a50f2010-06-21 22:57:05 +00001258 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001259
1260 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001261 dev_info(&card->gdev->dev,
1262 "Multicast not supported on %s\n",
1263 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001264 return -EOPNOTSUPP;
1265 }
1266
1267 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1268 IPA_CMD_ASS_START, 0);
1269 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001270 dev_warn(&card->gdev->dev,
1271 "Starting multicast support for %s failed\n",
1272 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001273 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001274 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275 card->dev->flags |= IFF_MULTICAST;
1276 }
1277 return rc;
1278}
1279
Frank Blaschka4a71df52008-02-15 09:19:42 +01001280#ifdef CONFIG_QETH_IPV6
1281static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1282{
1283 int rc;
1284
Carsten Otte847a50f2010-06-21 22:57:05 +00001285 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001286
1287 if (card->info.type == QETH_CARD_TYPE_IQD)
1288 goto out;
1289
Frank Blaschka1da74b12011-05-12 18:45:02 +00001290 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001291 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001292 dev_err(&card->gdev->dev,
1293 "Activating IPv6 support for %s failed\n",
1294 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295 return rc;
1296 }
1297 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1298 IPA_CMD_ASS_START, 3);
1299 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001300 dev_err(&card->gdev->dev,
1301 "Activating IPv6 support for %s failed\n",
1302 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001303 return rc;
1304 }
1305 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1306 IPA_CMD_ASS_START);
1307 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001308 dev_err(&card->gdev->dev,
1309 "Activating IPv6 support for %s failed\n",
1310 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001311 return rc;
1312 }
1313 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1314 IPA_CMD_ASS_START);
1315 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001316 dev_warn(&card->gdev->dev,
1317 "Enabling the passthrough mode for %s failed\n",
1318 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319 return rc;
1320 }
1321out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001322 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323 return 0;
1324}
1325#endif
1326
1327static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1328{
1329 int rc = 0;
1330
Carsten Otte847a50f2010-06-21 22:57:05 +00001331 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001332
1333 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001334 dev_info(&card->gdev->dev,
1335 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001336 return 0;
1337 }
1338#ifdef CONFIG_QETH_IPV6
1339 rc = qeth_l3_softsetup_ipv6(card);
1340#endif
1341 return rc ;
1342}
1343
1344static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1345{
1346 int rc;
1347
Carsten Otte847a50f2010-06-21 22:57:05 +00001348 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001349 card->info.broadcast_capable = 0;
1350 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001351 dev_info(&card->gdev->dev,
1352 "Broadcast not supported on %s\n",
1353 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001354 rc = -EOPNOTSUPP;
1355 goto out;
1356 }
1357 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1358 IPA_CMD_ASS_START, 0);
1359 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001360 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1361 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001362 goto out;
1363 }
1364
1365 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1366 IPA_CMD_ASS_CONFIGURE, 1);
1367 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001368 dev_warn(&card->gdev->dev,
1369 "Setting up broadcast filtering for %s failed\n",
1370 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001371 goto out;
1372 }
1373 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001374 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001375 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1376 IPA_CMD_ASS_ENABLE, 1);
1377 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001378 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1379 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001380 goto out;
1381 }
1382 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1383out:
1384 if (card->info.broadcast_capable)
1385 card->dev->flags |= IFF_BROADCAST;
1386 else
1387 card->dev->flags &= ~IFF_BROADCAST;
1388 return rc;
1389}
1390
1391static int qeth_l3_send_checksum_command(struct qeth_card *card)
1392{
1393 int rc;
1394
1395 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1396 IPA_CMD_ASS_START, 0);
1397 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001398 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1399 "failed, using SW checksumming\n",
1400 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001401 return rc;
1402 }
1403 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1404 IPA_CMD_ASS_ENABLE,
1405 card->info.csum_mask);
1406 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001407 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1408 "failed, using SW checksumming\n",
1409 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001410 return rc;
1411 }
1412 return 0;
1413}
1414
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001415int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001416{
1417 int rc = 0;
1418
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001419 if (on) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001420 rc = qeth_l3_send_checksum_command(card);
1421 if (rc)
1422 return -EIO;
1423 dev_info(&card->gdev->dev,
1424 "HW Checksumming (inbound) enabled\n");
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001425 } else {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001426 rc = qeth_l3_send_simple_setassparms(card,
1427 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1428 if (rc)
1429 return -EIO;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001430 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001431
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001432 return 0;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001433}
1434
Frank Blaschka4a71df52008-02-15 09:19:42 +01001435static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1436{
Carsten Otte847a50f2010-06-21 22:57:05 +00001437 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001438
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001439 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001440 rtnl_lock();
1441 /* force set_features call */
1442 card->dev->features &= ~NETIF_F_RXCSUM;
1443 netdev_update_features(card->dev);
1444 rtnl_unlock();
1445 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001446 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001447}
1448
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001449static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1450{
1451 int rc = 0;
1452
1453 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1454 return rc;
1455 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1456 IPA_CMD_ASS_START, 0);
1457 if (rc)
1458 goto err_out;
1459 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1460 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1461 if (rc)
1462 goto err_out;
1463 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1464 return rc;
1465err_out:
1466 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1467 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1468 return rc;
1469}
1470
Frank Blaschka4a71df52008-02-15 09:19:42 +01001471static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1472{
1473 int rc;
1474
Carsten Otte847a50f2010-06-21 22:57:05 +00001475 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001476
1477 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001478 dev_info(&card->gdev->dev,
1479 "Outbound TSO not supported on %s\n",
1480 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001481 rc = -EOPNOTSUPP;
1482 } else {
1483 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1484 IPA_CMD_ASS_START, 0);
1485 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001486 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1487 "segmentation offload for %s failed\n",
1488 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001489 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001490 dev_info(&card->gdev->dev,
1491 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001492 }
Michał Mirosław6204b472011-04-19 00:43:20 +00001493 if (rc)
1494 card->dev->features &= ~NETIF_F_TSO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001495 return rc;
1496}
1497
1498static int qeth_l3_start_ipassists(struct qeth_card *card)
1499{
Carsten Otte847a50f2010-06-21 22:57:05 +00001500 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001501
1502 qeth_set_access_ctrl_online(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001503 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1504 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1505 qeth_l3_start_ipa_source_mac(card); /* go on*/
1506 qeth_l3_start_ipa_vlan(card); /* go on*/
1507 qeth_l3_start_ipa_multicast(card); /* go on*/
1508 qeth_l3_start_ipa_ipv6(card); /* go on*/
1509 qeth_l3_start_ipa_broadcast(card); /* go on*/
1510 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001511 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001512 qeth_l3_start_ipa_tso(card); /* go on*/
1513 return 0;
1514}
1515
Frank Blaschka4a71df52008-02-15 09:19:42 +01001516static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1517 struct qeth_reply *reply, unsigned long data)
1518{
1519 struct qeth_ipa_cmd *cmd;
1520
1521 cmd = (struct qeth_ipa_cmd *) data;
1522 if (cmd->hdr.return_code == 0)
1523 memcpy(card->dev->dev_addr,
1524 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1525 else
1526 random_ether_addr(card->dev->dev_addr);
1527
1528 return 0;
1529}
1530
1531static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1532{
1533 int rc = 0;
1534 struct qeth_cmd_buffer *iob;
1535 struct qeth_ipa_cmd *cmd;
1536
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001537 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001538
1539 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1540 QETH_PROT_IPV6);
1541 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1542 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1543 card->info.unique_id;
1544
1545 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1546 NULL);
1547 return rc;
1548}
1549
1550static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1551 struct qeth_reply *reply, unsigned long data)
1552{
1553 struct qeth_ipa_cmd *cmd;
1554
1555 cmd = (struct qeth_ipa_cmd *) data;
1556 if (cmd->hdr.return_code == 0)
1557 card->info.unique_id = *((__u16 *)
1558 &cmd->data.create_destroy_addr.unique_id[6]);
1559 else {
1560 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1561 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001562 dev_warn(&card->gdev->dev, "The network adapter failed to "
1563 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001564 }
1565 return 0;
1566}
1567
1568static int qeth_l3_get_unique_id(struct qeth_card *card)
1569{
1570 int rc = 0;
1571 struct qeth_cmd_buffer *iob;
1572 struct qeth_ipa_cmd *cmd;
1573
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001574 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001575
1576 if (!qeth_is_supported(card, IPA_IPV6)) {
1577 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1578 UNIQUE_ID_NOT_BY_CARD;
1579 return 0;
1580 }
1581
1582 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1583 QETH_PROT_IPV6);
1584 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1585 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1586 card->info.unique_id;
1587
1588 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1589 return rc;
1590}
1591
Ursula Braun76b11f82010-01-11 02:50:50 +00001592static int
1593qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1594 unsigned long data)
1595{
1596 struct qeth_ipa_cmd *cmd;
1597 __u16 rc;
1598
1599 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1600
1601 cmd = (struct qeth_ipa_cmd *)data;
1602 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001603 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001604 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001605 switch (cmd->data.diagass.action) {
1606 case QETH_DIAGS_CMD_TRACE_QUERY:
1607 break;
1608 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001609 switch (rc) {
1610 case 0:
1611 case IPA_RC_INVALID_SUBCMD:
1612 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1613 dev_info(&card->gdev->dev, "The HiperSockets network "
1614 "traffic analyzer is deactivated\n");
1615 break;
1616 default:
1617 break;
1618 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001619 break;
1620 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001621 switch (rc) {
1622 case 0:
1623 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1624 dev_info(&card->gdev->dev, "The HiperSockets network "
1625 "traffic analyzer is activated\n");
1626 break;
1627 case IPA_RC_HARDWARE_AUTH_ERROR:
1628 dev_warn(&card->gdev->dev, "The device is not "
1629 "authorized to run as a HiperSockets network "
1630 "traffic analyzer\n");
1631 break;
1632 case IPA_RC_TRACE_ALREADY_ACTIVE:
1633 dev_warn(&card->gdev->dev, "A HiperSockets "
1634 "network traffic analyzer is already "
1635 "active in the HiperSockets LAN\n");
1636 break;
1637 default:
1638 break;
1639 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001640 break;
1641 default:
1642 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1643 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1644 }
1645
1646 return 0;
1647}
1648
1649static int
1650qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1651{
1652 struct qeth_cmd_buffer *iob;
1653 struct qeth_ipa_cmd *cmd;
1654
1655 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1656
1657 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1658 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1659 cmd->data.diagass.subcmd_len = 16;
1660 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1661 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1662 cmd->data.diagass.action = diags_cmd;
1663 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1664}
1665
Frank Blaschka4a71df52008-02-15 09:19:42 +01001666static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1667 struct net_device *dev)
1668{
1669 if (dev->type == ARPHRD_IEEE802_TR)
1670 ip_tr_mc_map(ipm, mac);
1671 else
1672 ip_eth_mc_map(ipm, mac);
1673}
1674
1675static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1676{
1677 struct qeth_ipaddr *ipm;
1678 struct ip_mc_list *im4;
1679 char buf[MAX_ADDR_LEN];
1680
Carsten Otte847a50f2010-06-21 22:57:05 +00001681 QETH_CARD_TEXT(card, 4, "addmc");
Sachin Santf3aa31362010-11-26 02:41:17 +00001682 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1683 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001684 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1685 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1686 if (!ipm)
1687 continue;
1688 ipm->u.a4.addr = im4->multiaddr;
1689 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1690 ipm->is_multicast = 1;
1691 if (!qeth_l3_add_ip(card, ipm))
1692 kfree(ipm);
1693 }
1694}
1695
1696static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1697{
1698 struct in_device *in_dev;
1699 struct vlan_group *vg;
1700 int i;
1701
Carsten Otte847a50f2010-06-21 22:57:05 +00001702 QETH_CARD_TEXT(card, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001703 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1704 return;
1705
1706 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001707 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001708 struct net_device *netdev = vlan_group_get_device(vg, i);
1709 if (netdev == NULL ||
1710 !(netdev->flags & IFF_UP))
1711 continue;
1712 in_dev = in_dev_get(netdev);
1713 if (!in_dev)
1714 continue;
Sachin Santf3aa31362010-11-26 02:41:17 +00001715 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001716 qeth_l3_add_mc(card, in_dev);
Sachin Santf3aa31362010-11-26 02:41:17 +00001717 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001718 in_dev_put(in_dev);
1719 }
1720}
1721
1722static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1723{
1724 struct in_device *in4_dev;
1725
Carsten Otte847a50f2010-06-21 22:57:05 +00001726 QETH_CARD_TEXT(card, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001727 in4_dev = in_dev_get(card->dev);
1728 if (in4_dev == NULL)
1729 return;
Sachin Santf3aa31362010-11-26 02:41:17 +00001730 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001731 qeth_l3_add_mc(card, in4_dev);
1732 qeth_l3_add_vlan_mc(card);
Sachin Santf3aa31362010-11-26 02:41:17 +00001733 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001734 in_dev_put(in4_dev);
1735}
1736
1737#ifdef CONFIG_QETH_IPV6
1738static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1739{
1740 struct qeth_ipaddr *ipm;
1741 struct ifmcaddr6 *im6;
1742 char buf[MAX_ADDR_LEN];
1743
Carsten Otte847a50f2010-06-21 22:57:05 +00001744 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001745 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1746 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1747 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1748 if (!ipm)
1749 continue;
1750 ipm->is_multicast = 1;
1751 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1752 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1753 sizeof(struct in6_addr));
1754 if (!qeth_l3_add_ip(card, ipm))
1755 kfree(ipm);
1756 }
1757}
1758
1759static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1760{
1761 struct inet6_dev *in_dev;
1762 struct vlan_group *vg;
1763 int i;
1764
Carsten Otte847a50f2010-06-21 22:57:05 +00001765 QETH_CARD_TEXT(card, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001766 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1767 return;
1768
1769 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001770 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001771 struct net_device *netdev = vlan_group_get_device(vg, i);
1772 if (netdev == NULL ||
1773 !(netdev->flags & IFF_UP))
1774 continue;
1775 in_dev = in6_dev_get(netdev);
1776 if (!in_dev)
1777 continue;
1778 read_lock_bh(&in_dev->lock);
1779 qeth_l3_add_mc6(card, in_dev);
1780 read_unlock_bh(&in_dev->lock);
1781 in6_dev_put(in_dev);
1782 }
1783}
1784
1785static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1786{
1787 struct inet6_dev *in6_dev;
1788
Carsten Otte847a50f2010-06-21 22:57:05 +00001789 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001790 if (!qeth_is_supported(card, IPA_IPV6))
1791 return ;
1792 in6_dev = in6_dev_get(card->dev);
1793 if (in6_dev == NULL)
1794 return;
1795 read_lock_bh(&in6_dev->lock);
1796 qeth_l3_add_mc6(card, in6_dev);
1797 qeth_l3_add_vlan_mc6(card);
1798 read_unlock_bh(&in6_dev->lock);
1799 in6_dev_put(in6_dev);
1800}
1801#endif /* CONFIG_QETH_IPV6 */
1802
1803static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1804 unsigned short vid)
1805{
1806 struct in_device *in_dev;
1807 struct in_ifaddr *ifa;
1808 struct qeth_ipaddr *addr;
1809
Carsten Otte847a50f2010-06-21 22:57:05 +00001810 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001811
1812 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1813 if (!in_dev)
1814 return;
1815 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1816 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1817 if (addr) {
1818 addr->u.a4.addr = ifa->ifa_address;
1819 addr->u.a4.mask = ifa->ifa_mask;
1820 addr->type = QETH_IP_TYPE_NORMAL;
1821 if (!qeth_l3_delete_ip(card, addr))
1822 kfree(addr);
1823 }
1824 }
1825 in_dev_put(in_dev);
1826}
1827
1828static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1829 unsigned short vid)
1830{
1831#ifdef CONFIG_QETH_IPV6
1832 struct inet6_dev *in6_dev;
1833 struct inet6_ifaddr *ifa;
1834 struct qeth_ipaddr *addr;
1835
Carsten Otte847a50f2010-06-21 22:57:05 +00001836 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001837
1838 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1839 if (!in6_dev)
1840 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001841 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001842 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1843 if (addr) {
1844 memcpy(&addr->u.a6.addr, &ifa->addr,
1845 sizeof(struct in6_addr));
1846 addr->u.a6.pfxlen = ifa->prefix_len;
1847 addr->type = QETH_IP_TYPE_NORMAL;
1848 if (!qeth_l3_delete_ip(card, addr))
1849 kfree(addr);
1850 }
1851 }
1852 in6_dev_put(in6_dev);
1853#endif /* CONFIG_QETH_IPV6 */
1854}
1855
1856static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1857 unsigned short vid)
1858{
1859 if (!card->vlangrp)
1860 return;
1861 qeth_l3_free_vlan_addresses4(card, vid);
1862 qeth_l3_free_vlan_addresses6(card, vid);
1863}
1864
1865static void qeth_l3_vlan_rx_register(struct net_device *dev,
1866 struct vlan_group *grp)
1867{
Heiko Carstens509e2562008-07-26 02:24:10 -07001868 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001869 unsigned long flags;
1870
Carsten Otte847a50f2010-06-21 22:57:05 +00001871 QETH_CARD_TEXT(card, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001872 spin_lock_irqsave(&card->vlanlock, flags);
1873 card->vlangrp = grp;
1874 spin_unlock_irqrestore(&card->vlanlock, flags);
1875}
1876
1877static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1878{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001879 return;
1880}
1881
1882static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1883{
Heiko Carstens509e2562008-07-26 02:24:10 -07001884 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001885 unsigned long flags;
1886
Carsten Otte847a50f2010-06-21 22:57:05 +00001887 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00001888 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001889 QETH_CARD_TEXT(card, 3, "kidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001890 return;
1891 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001892 spin_lock_irqsave(&card->vlanlock, flags);
1893 /* unregister IP addresses of vlan device */
1894 qeth_l3_free_vlan_addresses(card, vid);
1895 vlan_group_set_device(card->vlangrp, vid, NULL);
1896 spin_unlock_irqrestore(&card->vlanlock, flags);
1897 qeth_l3_set_multicast_list(card->dev);
1898}
1899
Ursula Braun10651db2010-10-01 02:51:13 +00001900static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1901 struct sk_buff *skb, struct qeth_hdr *hdr,
1902 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001903{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001904 __be16 prot;
1905 struct iphdr *ip_hdr;
1906 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001907 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001908
1909 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1910 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1911 ETH_P_IP);
1912 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1913 case QETH_CAST_MULTICAST:
1914 switch (prot) {
1915#ifdef CONFIG_QETH_IPV6
1916 case __constant_htons(ETH_P_IPV6):
1917 ndisc_mc_map((struct in6_addr *)
1918 skb->data + 24,
1919 tg_addr, card->dev, 0);
1920 break;
1921#endif
1922 case __constant_htons(ETH_P_IP):
1923 ip_hdr = (struct iphdr *)skb->data;
1924 (card->dev->type == ARPHRD_IEEE802_TR) ?
1925 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1926 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1927 break;
1928 default:
1929 memcpy(tg_addr, card->dev->broadcast,
1930 card->dev->addr_len);
1931 }
1932 card->stats.multicast++;
1933 skb->pkt_type = PACKET_MULTICAST;
1934 break;
1935 case QETH_CAST_BROADCAST:
1936 memcpy(tg_addr, card->dev->broadcast,
1937 card->dev->addr_len);
1938 card->stats.multicast++;
1939 skb->pkt_type = PACKET_BROADCAST;
1940 break;
1941 case QETH_CAST_UNICAST:
1942 case QETH_CAST_ANYCAST:
1943 case QETH_CAST_NOCAST:
1944 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001945 if (card->options.sniffer)
1946 skb->pkt_type = PACKET_OTHERHOST;
1947 else
1948 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001949 memcpy(tg_addr, card->dev->dev_addr,
1950 card->dev->addr_len);
1951 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001952 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1953 card->dev->header_ops->create(skb, card->dev, prot,
1954 tg_addr, &hdr->hdr.l3.dest_addr[2],
1955 card->dev->addr_len);
1956 else
1957 card->dev->header_ops->create(skb, card->dev, prot,
1958 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001959 }
1960
1961#ifdef CONFIG_TR
1962 if (card->dev->type == ARPHRD_IEEE802_TR)
1963 skb->protocol = tr_type_trans(skb, card->dev);
1964 else
1965#endif
1966 skb->protocol = eth_type_trans(skb, card->dev);
1967
1968 if (hdr->hdr.l3.ext_flags &
1969 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001970 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001971 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001972 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001973 }
1974
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001975 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001976 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001977 (QETH_HDR_EXT_CSUM_HDR_REQ |
1978 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1979 (QETH_HDR_EXT_CSUM_HDR_REQ |
1980 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001981 skb->ip_summed = CHECKSUM_UNNECESSARY;
1982 else
Ursula Braunb9139802009-05-19 21:38:40 +00001983 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001984 } else
1985 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001986
Ursula Braun10651db2010-10-01 02:51:13 +00001987 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001988}
1989
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001990static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1991 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001992{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001993 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001994 struct sk_buff *skb;
1995 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001996 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001997 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001998 unsigned int len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001999
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002000 *done = 0;
2001 BUG_ON(!budget);
2002 while (budget) {
2003 skb = qeth_core_get_next_skb(card,
2004 card->qdio.in_q->bufs[card->rx.b_index].buffer,
2005 &card->rx.b_element, &card->rx.e_offset, &hdr);
2006 if (!skb) {
2007 *done = 1;
2008 break;
2009 }
2010 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002011 switch (hdr->hdr.l3.id) {
2012 case QETH_HEADER_TYPE_LAYER3:
Ursula Braun10651db2010-10-01 02:51:13 +00002013 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
2014 &vlan_tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002015 len = skb->len;
Ursula Braun10651db2010-10-01 02:51:13 +00002016 if (is_vlan && !card->options.sniffer)
2017 vlan_gro_receive(&card->napi, card->vlangrp,
2018 vlan_tag, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002019 else
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002020 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002021 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002022 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2023 skb->pkt_type = PACKET_HOST;
2024 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002025 len = skb->len;
2026 netif_receive_skb(skb);
2027 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002028 default:
2029 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002030 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002031 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002032 continue;
2033 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002034 work_done++;
2035 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002036 card->stats.rx_packets++;
2037 card->stats.rx_bytes += len;
2038 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002039 return work_done;
2040}
2041
2042static int qeth_l3_poll(struct napi_struct *napi, int budget)
2043{
2044 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2045 int work_done = 0;
2046 struct qeth_qdio_buffer *buffer;
2047 int done;
2048 int new_budget = budget;
2049
2050 if (card->options.performance_stats) {
2051 card->perf_stats.inbound_cnt++;
2052 card->perf_stats.inbound_start_time = qeth_get_micros();
2053 }
2054
2055 while (1) {
2056 if (!card->rx.b_count) {
2057 card->rx.qdio_err = 0;
2058 card->rx.b_count = qdio_get_next_buffers(
2059 card->data.ccwdev, 0, &card->rx.b_index,
2060 &card->rx.qdio_err);
2061 if (card->rx.b_count <= 0) {
2062 card->rx.b_count = 0;
2063 break;
2064 }
2065 card->rx.b_element =
2066 &card->qdio.in_q->bufs[card->rx.b_index]
2067 .buffer->element[0];
2068 card->rx.e_offset = 0;
2069 }
2070
2071 while (card->rx.b_count) {
2072 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2073 if (!(card->rx.qdio_err &&
2074 qeth_check_qdio_errors(card, buffer->buffer,
2075 card->rx.qdio_err, "qinerr")))
2076 work_done += qeth_l3_process_inbound_buffer(
2077 card, new_budget, &done);
2078 else
2079 done = 1;
2080
2081 if (done) {
2082 if (card->options.performance_stats)
2083 card->perf_stats.bufs_rec++;
2084 qeth_put_buffer_pool_entry(card,
2085 buffer->pool_entry);
2086 qeth_queue_input_buffer(card, card->rx.b_index);
2087 card->rx.b_count--;
2088 if (card->rx.b_count) {
2089 card->rx.b_index =
2090 (card->rx.b_index + 1) %
2091 QDIO_MAX_BUFFERS_PER_Q;
2092 card->rx.b_element =
2093 &card->qdio.in_q
2094 ->bufs[card->rx.b_index]
2095 .buffer->element[0];
2096 card->rx.e_offset = 0;
2097 }
2098 }
2099
2100 if (work_done >= budget)
2101 goto out;
2102 else
2103 new_budget = budget - work_done;
2104 }
2105 }
2106
2107 napi_complete(napi);
2108 if (qdio_start_irq(card->data.ccwdev, 0))
2109 napi_schedule(&card->napi);
2110out:
2111 if (card->options.performance_stats)
2112 card->perf_stats.inbound_time += qeth_get_micros() -
2113 card->perf_stats.inbound_start_time;
2114 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002115}
2116
2117static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2118 struct qeth_card *card)
2119{
2120 int rc = 0;
2121 struct vlan_group *vg;
2122 int i;
2123
2124 vg = card->vlangrp;
2125 if (!vg)
2126 return rc;
2127
Jesse Grossb7381272010-10-20 13:56:02 +00002128 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002129 if (vlan_group_get_device(vg, i) == dev) {
2130 rc = QETH_VLAN_CARD;
2131 break;
2132 }
2133 }
2134
Heiko Carstens509e2562008-07-26 02:24:10 -07002135 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002136 return 0;
2137
2138 return rc;
2139}
2140
2141static int qeth_l3_verify_dev(struct net_device *dev)
2142{
2143 struct qeth_card *card;
2144 unsigned long flags;
2145 int rc = 0;
2146
2147 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2148 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2149 if (card->dev == dev) {
2150 rc = QETH_REAL_CARD;
2151 break;
2152 }
2153 rc = qeth_l3_verify_vlan_dev(dev, card);
2154 if (rc)
2155 break;
2156 }
2157 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2158
2159 return rc;
2160}
2161
2162static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2163{
2164 struct qeth_card *card = NULL;
2165 int rc;
2166
2167 rc = qeth_l3_verify_dev(dev);
2168 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002169 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002170 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002171 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002172 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002173 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002174 if (card)
2175 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002176 return card ;
2177}
2178
2179static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2180{
2181 int rc = 0;
2182
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002183 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2184 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002185
2186 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002187 if (card->options.sniffer &&
2188 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2189 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002190 if (card->read.state == CH_STATE_UP &&
2191 card->write.state == CH_STATE_UP &&
2192 (card->state == CARD_STATE_UP)) {
2193 if (recovery_mode)
2194 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002195 else {
Ursula Braun869da902010-03-08 20:36:56 +00002196 rtnl_lock();
2197 dev_close(card->dev);
2198 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002199 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002200 card->state = CARD_STATE_SOFTSETUP;
2201 }
2202 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -08002203 qeth_l3_clear_ip_list(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002204 qeth_clear_ipacmd_list(card);
2205 card->state = CARD_STATE_HARDSETUP;
2206 }
2207 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002208 qeth_qdio_clear_card(card, 0);
2209 qeth_clear_qdio_buffers(card);
2210 qeth_clear_working_pool_list(card);
2211 card->state = CARD_STATE_DOWN;
2212 }
2213 if (card->state == CARD_STATE_DOWN) {
2214 qeth_clear_cmd_buffers(&card->read);
2215 qeth_clear_cmd_buffers(&card->write);
2216 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002217 return rc;
2218}
2219
Ursula Braun76b11f82010-01-11 02:50:50 +00002220/*
2221 * test for and Switch promiscuous mode (on or off)
2222 * either for guestlan or HiperSocket Sniffer
2223 */
2224static void
2225qeth_l3_handle_promisc_mode(struct qeth_card *card)
2226{
2227 struct net_device *dev = card->dev;
2228
2229 if (((dev->flags & IFF_PROMISC) &&
2230 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2231 (!(dev->flags & IFF_PROMISC) &&
2232 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2233 return;
2234
2235 if (card->info.guestlan) { /* Guestlan trace */
2236 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2237 qeth_setadp_promisc_mode(card);
2238 } else if (card->options.sniffer && /* HiperSockets trace */
2239 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2240 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002241 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002242 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2243 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002244 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002245 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2246 }
2247 }
2248}
2249
Frank Blaschka4a71df52008-02-15 09:19:42 +01002250static void qeth_l3_set_multicast_list(struct net_device *dev)
2251{
Heiko Carstens509e2562008-07-26 02:24:10 -07002252 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002253
Carsten Otte847a50f2010-06-21 22:57:05 +00002254 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002255 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2256 (card->state != CARD_STATE_UP))
2257 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002258 if (!card->options.sniffer) {
2259 qeth_l3_delete_mc_addresses(card);
2260 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002261#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002262 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002263#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002264 qeth_l3_set_ip_addr_list(card);
2265 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2266 return;
2267 }
2268 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002269}
2270
2271static const char *qeth_l3_arp_get_error_cause(int *rc)
2272{
2273 switch (*rc) {
2274 case QETH_IPA_ARP_RC_FAILED:
2275 *rc = -EIO;
2276 return "operation failed";
2277 case QETH_IPA_ARP_RC_NOTSUPP:
2278 *rc = -EOPNOTSUPP;
2279 return "operation not supported";
2280 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2281 *rc = -EINVAL;
2282 return "argument out of range";
2283 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2284 *rc = -EOPNOTSUPP;
2285 return "query operation not supported";
2286 case QETH_IPA_ARP_RC_Q_NO_DATA:
2287 *rc = -ENOENT;
2288 return "no query data available";
2289 default:
2290 return "unknown error";
2291 }
2292}
2293
2294static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2295{
2296 int tmp;
2297 int rc;
2298
Carsten Otte847a50f2010-06-21 22:57:05 +00002299 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002300
2301 /*
2302 * currently GuestLAN only supports the ARP assist function
2303 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2304 * thus we say EOPNOTSUPP for this ARP function
2305 */
2306 if (card->info.guestlan)
2307 return -EOPNOTSUPP;
2308 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002309 return -EOPNOTSUPP;
2310 }
2311 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2312 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2313 no_entries);
2314 if (rc) {
2315 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002316 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2317 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002318 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2319 }
2320 return rc;
2321}
2322
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002323static __u32 get_arp_entry_size(struct qeth_card *card,
2324 struct qeth_arp_query_data *qdata,
2325 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002326{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002327 __u32 rc;
2328 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002329
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002330 is_hsi = qdata->reply_bits == 5;
2331 if (type->ip == QETHARP_IP_ADDR_V4) {
2332 QETH_CARD_TEXT(card, 4, "arpev4");
2333 if (strip_entries) {
2334 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2335 sizeof(struct qeth_arp_qi_entry7_short);
2336 } else {
2337 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2338 sizeof(struct qeth_arp_qi_entry7);
2339 }
2340 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2341 QETH_CARD_TEXT(card, 4, "arpev6");
2342 if (strip_entries) {
2343 rc = is_hsi ?
2344 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2345 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2346 } else {
2347 rc = is_hsi ?
2348 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2349 sizeof(struct qeth_arp_qi_entry7_ipv6);
2350 }
2351 } else {
2352 QETH_CARD_TEXT(card, 4, "arpinv");
2353 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002354 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002355
2356 return rc;
2357}
2358
2359static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2360{
2361 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2362 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002363}
2364
2365static int qeth_l3_arp_query_cb(struct qeth_card *card,
2366 struct qeth_reply *reply, unsigned long data)
2367{
2368 struct qeth_ipa_cmd *cmd;
2369 struct qeth_arp_query_data *qdata;
2370 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002371 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002372 int e;
2373 int entrybytes_done;
2374 int stripped_bytes;
2375 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002376
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002377 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002378
2379 qinfo = (struct qeth_arp_query_info *) reply->param;
2380 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002381 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002382 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002383 QETH_CARD_TEXT(card, 4, "arpcberr");
2384 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002385 return 0;
2386 }
2387 if (cmd->data.setassparms.hdr.return_code) {
2388 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002389 QETH_CARD_TEXT(card, 4, "setaperr");
2390 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002391 return 0;
2392 }
2393 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002394 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002395
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002396 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2397 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2398 entrybytes_done = 0;
2399 for (e = 0; e < qdata->no_entries; ++e) {
2400 char *cur_entry;
2401 __u32 esize;
2402 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002403
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002404 cur_entry = &qdata->data + entrybytes_done;
2405 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2406 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2407 QETH_CARD_TEXT(card, 4, "pmis");
2408 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2409 break;
2410 }
2411 esize = get_arp_entry_size(card, qdata, etype,
2412 do_strip_entries);
2413 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2414 if (!esize)
2415 break;
2416
2417 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2418 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
2419 cmd->hdr.return_code = -ENOMEM;
2420 goto out_error;
2421 }
2422
2423 memcpy(qinfo->udata + qinfo->udata_offset,
2424 &qdata->data + entrybytes_done + stripped_bytes,
2425 esize);
2426 entrybytes_done += esize + stripped_bytes;
2427 qinfo->udata_offset += esize;
2428 ++qinfo->no_entries;
2429 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002430 /* check if all replies received ... */
2431 if (cmd->data.setassparms.hdr.seq_no <
2432 cmd->data.setassparms.hdr.number_of_replies)
2433 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002434 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002435 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2436 /* keep STRIP_ENTRIES flag so the user program can distinguish
2437 * stripped entries from normal ones */
2438 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2439 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2440 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002441 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002442 return 0;
2443out_error:
2444 i = 0;
2445 memcpy(qinfo->udata, &i, 4);
2446 return 0;
2447}
2448
2449static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2450 struct qeth_cmd_buffer *iob, int len,
2451 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2452 unsigned long),
2453 void *reply_param)
2454{
Carsten Otte847a50f2010-06-21 22:57:05 +00002455 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002456
2457 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2458 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2459 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2460 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2461 reply_cb, reply_param);
2462}
2463
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002464static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2465 enum qeth_prot_versions prot,
2466 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002467{
2468 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002469 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002470 int tmp;
2471 int rc;
2472
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002473 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2474
2475 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2476 IPA_CMD_ASS_ARP_QUERY_INFO,
2477 sizeof(struct qeth_arp_query_data) - sizeof(char),
2478 prot);
2479 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2480 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2481 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2482 cmd->data.setassparms.data.query_arp.no_entries = 0;
2483 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2484 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2485 qeth_l3_arp_query_cb, (void *)qinfo);
2486 if (rc) {
2487 tmp = rc;
2488 QETH_DBF_MESSAGE(2,
2489 "Error while querying ARP cache on %s: %s "
2490 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2491 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2492 }
2493
2494 return rc;
2495}
2496
2497static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2498{
2499 struct qeth_arp_query_info qinfo = {0, };
2500 int rc;
2501
Carsten Otte847a50f2010-06-21 22:57:05 +00002502 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002503
2504 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2505 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002506 QETH_CARD_TEXT(card, 3, "arpqnsup");
2507 rc = -EOPNOTSUPP;
2508 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002509 }
2510 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002511 if (copy_from_user(&qinfo, udata, 6)) {
2512 rc = -EFAULT;
2513 goto out;
2514 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002515 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002516 if (!qinfo.udata) {
2517 rc = -ENOMEM;
2518 goto out;
2519 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002520 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002521 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002522 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002523 if (copy_to_user(udata, qinfo.udata, 4))
2524 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002525 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002526 } else {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002527#ifdef CONFIG_QETH_IPV6
2528 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2529 /* fails in case of GuestLAN QDIO mode */
2530 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2531 &qinfo);
2532 }
2533#endif
2534 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2535 QETH_CARD_TEXT(card, 4, "qactf");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002536 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002537 goto free_and_out;
2538 }
2539 QETH_CARD_TEXT_(card, 4, "qacts");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002540 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002541free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002542 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002543out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002544 return rc;
2545}
2546
2547static int qeth_l3_arp_add_entry(struct qeth_card *card,
2548 struct qeth_arp_cache_entry *entry)
2549{
2550 struct qeth_cmd_buffer *iob;
2551 char buf[16];
2552 int tmp;
2553 int rc;
2554
Carsten Otte847a50f2010-06-21 22:57:05 +00002555 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002556
2557 /*
2558 * currently GuestLAN only supports the ARP assist function
2559 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2560 * thus we say EOPNOTSUPP for this ARP function
2561 */
2562 if (card->info.guestlan)
2563 return -EOPNOTSUPP;
2564 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002565 return -EOPNOTSUPP;
2566 }
2567
2568 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2569 IPA_CMD_ASS_ARP_ADD_ENTRY,
2570 sizeof(struct qeth_arp_cache_entry),
2571 QETH_PROT_IPV4);
2572 rc = qeth_l3_send_setassparms(card, iob,
2573 sizeof(struct qeth_arp_cache_entry),
2574 (unsigned long) entry,
2575 qeth_l3_default_setassparms_cb, NULL);
2576 if (rc) {
2577 tmp = rc;
2578 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002579 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2580 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2581 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002582 }
2583 return rc;
2584}
2585
2586static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2587 struct qeth_arp_cache_entry *entry)
2588{
2589 struct qeth_cmd_buffer *iob;
2590 char buf[16] = {0, };
2591 int tmp;
2592 int rc;
2593
Carsten Otte847a50f2010-06-21 22:57:05 +00002594 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002595
2596 /*
2597 * currently GuestLAN only supports the ARP assist function
2598 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2599 * thus we say EOPNOTSUPP for this ARP function
2600 */
2601 if (card->info.guestlan)
2602 return -EOPNOTSUPP;
2603 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002604 return -EOPNOTSUPP;
2605 }
2606 memcpy(buf, entry, 12);
2607 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2608 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2609 12,
2610 QETH_PROT_IPV4);
2611 rc = qeth_l3_send_setassparms(card, iob,
2612 12, (unsigned long)buf,
2613 qeth_l3_default_setassparms_cb, NULL);
2614 if (rc) {
2615 tmp = rc;
2616 memset(buf, 0, 16);
2617 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002618 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2619 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2620 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002621 }
2622 return rc;
2623}
2624
2625static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2626{
2627 int rc;
2628 int tmp;
2629
Carsten Otte847a50f2010-06-21 22:57:05 +00002630 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002631
2632 /*
2633 * currently GuestLAN only supports the ARP assist function
2634 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2635 * thus we say EOPNOTSUPP for this ARP function
2636 */
2637 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2638 return -EOPNOTSUPP;
2639 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002640 return -EOPNOTSUPP;
2641 }
2642 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2643 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2644 if (rc) {
2645 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002646 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2647 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002648 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2649 }
2650 return rc;
2651}
2652
2653static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2654{
Heiko Carstens509e2562008-07-26 02:24:10 -07002655 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002656 struct qeth_arp_cache_entry arp_entry;
2657 struct mii_ioctl_data *mii_data;
2658 int rc = 0;
2659
2660 if (!card)
2661 return -ENODEV;
2662
2663 if ((card->state != CARD_STATE_UP) &&
2664 (card->state != CARD_STATE_SOFTSETUP))
2665 return -ENODEV;
2666
2667 switch (cmd) {
2668 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2669 if (!capable(CAP_NET_ADMIN)) {
2670 rc = -EPERM;
2671 break;
2672 }
2673 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2674 break;
2675 case SIOC_QETH_ARP_QUERY_INFO:
2676 if (!capable(CAP_NET_ADMIN)) {
2677 rc = -EPERM;
2678 break;
2679 }
2680 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2681 break;
2682 case SIOC_QETH_ARP_ADD_ENTRY:
2683 if (!capable(CAP_NET_ADMIN)) {
2684 rc = -EPERM;
2685 break;
2686 }
2687 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2688 sizeof(struct qeth_arp_cache_entry)))
2689 rc = -EFAULT;
2690 else
2691 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2692 break;
2693 case SIOC_QETH_ARP_REMOVE_ENTRY:
2694 if (!capable(CAP_NET_ADMIN)) {
2695 rc = -EPERM;
2696 break;
2697 }
2698 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2699 sizeof(struct qeth_arp_cache_entry)))
2700 rc = -EFAULT;
2701 else
2702 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2703 break;
2704 case SIOC_QETH_ARP_FLUSH_CACHE:
2705 if (!capable(CAP_NET_ADMIN)) {
2706 rc = -EPERM;
2707 break;
2708 }
2709 rc = qeth_l3_arp_flush_cache(card);
2710 break;
2711 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2712 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2713 break;
2714 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002715 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2716 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002717 !card->info.guestlan)
2718 return 1;
2719 return 0;
2720 break;
2721 case SIOCGMIIPHY:
2722 mii_data = if_mii(rq);
2723 mii_data->phy_id = 0;
2724 break;
2725 case SIOCGMIIREG:
2726 mii_data = if_mii(rq);
2727 if (mii_data->phy_id != 0)
2728 rc = -EINVAL;
2729 else
2730 mii_data->val_out = qeth_mdio_read(dev,
2731 mii_data->phy_id,
2732 mii_data->reg_num);
2733 break;
2734 default:
2735 rc = -EOPNOTSUPP;
2736 }
2737 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002738 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002739 return rc;
2740}
2741
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002742int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2743{
2744 int cast_type = RTN_UNSPEC;
2745
2746 if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2747 cast_type = skb_dst(skb)->neighbour->type;
2748 if ((cast_type == RTN_BROADCAST) ||
2749 (cast_type == RTN_MULTICAST) ||
2750 (cast_type == RTN_ANYCAST))
2751 return cast_type;
2752 else
2753 return RTN_UNSPEC;
2754 }
2755 /* try something else */
2756 if (skb->protocol == ETH_P_IPV6)
2757 return (skb_network_header(skb)[24] == 0xff) ?
2758 RTN_MULTICAST : 0;
2759 else if (skb->protocol == ETH_P_IP)
2760 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2761 RTN_MULTICAST : 0;
2762 /* ... */
2763 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2764 return RTN_BROADCAST;
2765 else {
2766 u16 hdr_mac;
2767
2768 hdr_mac = *((u16 *)skb->data);
2769 /* tr multicast? */
2770 switch (card->info.link_type) {
2771 case QETH_LINK_TYPE_HSTR:
2772 case QETH_LINK_TYPE_LANE_TR:
2773 if ((hdr_mac == QETH_TR_MAC_NC) ||
2774 (hdr_mac == QETH_TR_MAC_C))
2775 return RTN_MULTICAST;
2776 break;
2777 /* eth or so multicast? */
2778 default:
2779 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2780 (hdr_mac == QETH_ETH_MAC_V6))
2781 return RTN_MULTICAST;
2782 }
2783 }
2784 return cast_type;
2785}
2786
Frank Blaschka4a71df52008-02-15 09:19:42 +01002787static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2788 struct sk_buff *skb, int ipv, int cast_type)
2789{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002790 memset(hdr, 0, sizeof(struct qeth_hdr));
2791 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2792 hdr->hdr.l3.ext_flags = 0;
2793
2794 /*
2795 * before we're going to overwrite this location with next hop ip.
2796 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2797 */
2798 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002799 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2800 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2801 else
2802 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002803 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2804 }
2805
2806 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2807 if (ipv == 4) {
2808 /* IPv4 */
2809 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2810 memset(hdr->hdr.l3.dest_addr, 0, 12);
Eric Dumazetadf30902009-06-02 05:19:30 +00002811 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002812 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
Eric Dumazetadf30902009-06-02 05:19:30 +00002813 *((u32 *) skb_dst(skb)->neighbour->primary_key);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002814 } else {
2815 /* fill in destination address used in ip header */
2816 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2817 ip_hdr(skb)->daddr;
2818 }
2819 } else if (ipv == 6) {
2820 /* IPv6 */
2821 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2822 if (card->info.type == QETH_CARD_TYPE_IQD)
2823 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
Eric Dumazetadf30902009-06-02 05:19:30 +00002824 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002825 memcpy(hdr->hdr.l3.dest_addr,
Eric Dumazetadf30902009-06-02 05:19:30 +00002826 skb_dst(skb)->neighbour->primary_key, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002827 } else {
2828 /* fill in destination address used in ip header */
2829 memcpy(hdr->hdr.l3.dest_addr,
2830 &ipv6_hdr(skb)->daddr, 16);
2831 }
2832 } else {
2833 /* passthrough */
2834 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2835 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2836 sizeof(__u16), skb->dev->broadcast, 6)) {
2837 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2838 QETH_HDR_PASSTHRU;
2839 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2840 skb->dev->broadcast, 6)) {
2841 /* broadcast? */
2842 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2843 QETH_HDR_PASSTHRU;
2844 } else {
2845 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2846 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2847 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2848 }
2849 }
2850}
2851
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002852static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2853 struct qeth_hdr *hdr, struct sk_buff *skb)
2854{
2855 struct iphdr *iph = ip_hdr(skb);
2856
2857 /* tcph->check contains already the pseudo hdr checksum
2858 * so just set the header flags
2859 */
2860 if (iph->protocol == IPPROTO_UDP)
2861 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002862 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2863 QETH_HDR_EXT_CSUM_HDR_REQ;
2864 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002865 if (card->options.performance_stats)
2866 card->perf_stats.tx_csum++;
2867}
2868
Frank Blaschka64ef8952009-03-24 20:57:16 +00002869static void qeth_tso_fill_header(struct qeth_card *card,
2870 struct qeth_hdr *qhdr, struct sk_buff *skb)
2871{
2872 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2873 struct tcphdr *tcph = tcp_hdr(skb);
2874 struct iphdr *iph = ip_hdr(skb);
2875 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2876
2877 /*fix header to TSO values ...*/
2878 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002879 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002880 /*set values which are fix for the first approach ...*/
2881 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2882 hdr->ext.imb_hdr_no = 1;
2883 hdr->ext.hdr_type = 1;
2884 hdr->ext.hdr_version = 1;
2885 hdr->ext.hdr_len = 28;
2886 /*insert non-fix values */
2887 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2888 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2889 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2890 sizeof(struct qeth_hdr_tso));
2891 tcph->check = 0;
2892 if (skb->protocol == ETH_P_IPV6) {
2893 ip6h->payload_len = 0;
2894 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2895 0, IPPROTO_TCP, 0);
2896 } else {
2897 /*OSA want us to set these values ...*/
2898 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2899 0, IPPROTO_TCP, 0);
2900 iph->tot_len = 0;
2901 iph->check = 0;
2902 }
2903}
2904
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002905static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2906{
2907 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2908 tcp_hdr(skb)->doff * 4;
2909 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002910 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002911 elements += skb_shinfo(skb)->nr_frags;
2912 return elements;
2913}
2914
Frank Blaschka4a71df52008-02-15 09:19:42 +01002915static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2916{
2917 int rc;
2918 u16 *tag;
2919 struct qeth_hdr *hdr = NULL;
2920 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002921 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002922 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002923 struct sk_buff *new_skb = NULL;
2924 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002925 int cast_type = qeth_l3_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002926 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2927 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2928 int tx_bytes = skb->len;
Michał Mirosław6204b472011-04-19 00:43:20 +00002929 bool large_send;
Frank Blaschka683d7182008-08-01 16:39:13 +02002930 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002931 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002932
Frank Blaschka21fde742010-03-08 20:36:54 +00002933 if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
2934 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002935 goto tx_drop;
2936
2937 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2938 card->stats.tx_carrier_errors++;
2939 goto tx_drop;
2940 }
2941
2942 if ((cast_type == RTN_BROADCAST) &&
2943 (card->info.broadcast_capable == 0))
2944 goto tx_drop;
2945
2946 if (card->options.performance_stats) {
2947 card->perf_stats.outbound_cnt++;
2948 card->perf_stats.outbound_start_time = qeth_get_micros();
2949 }
2950
Michał Mirosław6204b472011-04-19 00:43:20 +00002951 large_send = skb_is_gso(skb);
Frank Blaschka683d7182008-08-01 16:39:13 +02002952
2953 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2954 (skb_shinfo(skb)->nr_frags == 0)) {
2955 new_skb = skb;
2956 data_offset = ETH_HLEN;
2957 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2958 if (!hdr)
2959 goto tx_drop;
2960 elements_needed++;
2961 } else {
2962 /* create a clone with writeable headroom */
2963 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2964 + VLAN_HLEN);
2965 if (!new_skb)
2966 goto tx_drop;
2967 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002968
2969 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002970 if (data_offset < 0)
2971 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002972 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00002973 if (ipv == 4) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002974 if (card->dev->type == ARPHRD_IEEE802_TR)
2975 skb_pull(new_skb, TR_HLEN);
2976 else
2977 skb_pull(new_skb, ETH_HLEN);
2978 }
2979
Frank Blaschka91d45762010-12-08 02:58:00 +00002980 if (ipv != 4 && card->vlangrp &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002981 vlan_tx_tag_present(new_skb)) {
2982 skb_push(new_skb, VLAN_HLEN);
2983 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2984 skb_copy_to_linear_data_offset(new_skb, 4,
2985 new_skb->data + 8, 4);
2986 skb_copy_to_linear_data_offset(new_skb, 8,
2987 new_skb->data + 12, 4);
2988 tag = (u16 *)(new_skb->data + 12);
2989 *tag = __constant_htons(ETH_P_8021Q);
2990 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02002991 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002992 }
2993 }
2994
2995 netif_stop_queue(dev);
2996
Frank Blaschka4a71df52008-02-15 09:19:42 +01002997 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002998 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002999 */
Michał Mirosław6204b472011-04-19 00:43:20 +00003000 if (large_send) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003001 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3002 if (skb_linearize(new_skb))
3003 goto tx_drop;
3004 if (card->options.performance_stats)
3005 card->perf_stats.tx_lin++;
3006 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003007 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003008
Michał Mirosław6204b472011-04-19 00:43:20 +00003009 if (large_send && (cast_type == RTN_UNSPEC)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003010 hdr = (struct qeth_hdr *)skb_push(new_skb,
3011 sizeof(struct qeth_hdr_tso));
3012 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3013 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3014 qeth_tso_fill_header(card, hdr, new_skb);
3015 elements_needed++;
3016 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003017 if (data_offset < 0) {
3018 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003019 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003020 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3021 cast_type);
3022 } else {
3023 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3024 cast_type);
3025 hdr->hdr.l3.length = new_skb->len - data_offset;
3026 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003027
3028 if (skb->ip_summed == CHECKSUM_PARTIAL)
3029 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003030 }
3031
Frank Blaschka64ef8952009-03-24 20:57:16 +00003032 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003033 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003034 if (!elems) {
3035 if (data_offset >= 0)
3036 kmem_cache_free(qeth_core_header_cache, hdr);
3037 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003038 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003039 elements_needed += elems;
3040 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003041
Frank Blaschka51aa1652010-06-21 22:57:10 +00003042 if (card->info.type != QETH_CARD_TYPE_IQD) {
3043 int len;
Michał Mirosław6204b472011-04-19 00:43:20 +00003044 if (large_send)
Frank Blaschka51aa1652010-06-21 22:57:10 +00003045 len = ((unsigned long)tcp_hdr(new_skb) +
3046 tcp_hdr(new_skb)->doff * 4) -
3047 (unsigned long)new_skb->data;
3048 else
3049 len = sizeof(struct qeth_hdr_layer3);
3050
3051 if (qeth_hdr_chk_and_bounce(new_skb, len))
3052 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003053 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003054 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003055 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003056 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003057 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003058
3059 if (!rc) {
3060 card->stats.tx_packets++;
3061 card->stats.tx_bytes += tx_bytes;
3062 if (new_skb != skb)
3063 dev_kfree_skb_any(skb);
3064 if (card->options.performance_stats) {
Michał Mirosław6204b472011-04-19 00:43:20 +00003065 if (large_send) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003066 card->perf_stats.large_send_bytes += tx_bytes;
3067 card->perf_stats.large_send_cnt++;
3068 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003069 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003070 card->perf_stats.sg_skbs_sent++;
3071 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003072 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003073 }
3074 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003075 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003076 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003077 if (data_offset >= 0)
3078 kmem_cache_free(qeth_core_header_cache, hdr);
3079
Frank Blaschka4a71df52008-02-15 09:19:42 +01003080 if (rc == -EBUSY) {
3081 if (new_skb != skb)
3082 dev_kfree_skb_any(new_skb);
3083 return NETDEV_TX_BUSY;
3084 } else
3085 goto tx_drop;
3086 }
3087
3088 netif_wake_queue(dev);
3089 if (card->options.performance_stats)
3090 card->perf_stats.outbound_time += qeth_get_micros() -
3091 card->perf_stats.outbound_start_time;
3092 return rc;
3093
3094tx_drop:
3095 card->stats.tx_dropped++;
3096 card->stats.tx_errors++;
3097 if ((new_skb != skb) && new_skb)
3098 dev_kfree_skb_any(new_skb);
3099 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003100 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003101 return NETDEV_TX_OK;
3102}
3103
Ursula Braun39423442011-01-12 20:42:24 +00003104static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003105{
Heiko Carstens509e2562008-07-26 02:24:10 -07003106 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003107 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003108
Carsten Otte847a50f2010-06-21 22:57:05 +00003109 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00003110 if (card->state == CARD_STATE_UP)
3111 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003112 if (card->state != CARD_STATE_SOFTSETUP)
3113 return -ENODEV;
3114 card->data.state = CH_STATE_UP;
3115 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003116 netif_start_queue(dev);
3117
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003118 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3119 napi_enable(&card->napi);
3120 napi_schedule(&card->napi);
3121 } else
3122 rc = -EIO;
3123 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003124}
3125
Ursula Braun39423442011-01-12 20:42:24 +00003126static int qeth_l3_open(struct net_device *dev)
3127{
3128 struct qeth_card *card = dev->ml_priv;
3129
3130 QETH_CARD_TEXT(card, 5, "qethope_");
3131 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3132 QETH_CARD_TEXT(card, 3, "openREC");
3133 return -ERESTARTSYS;
3134 }
3135 return __qeth_l3_open(dev);
3136}
3137
Frank Blaschka4a71df52008-02-15 09:19:42 +01003138static int qeth_l3_stop(struct net_device *dev)
3139{
Heiko Carstens509e2562008-07-26 02:24:10 -07003140 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003141
Carsten Otte847a50f2010-06-21 22:57:05 +00003142 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003143 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003144 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003145 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003146 napi_disable(&card->napi);
3147 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003148 return 0;
3149}
3150
Michał Mirosław6204b472011-04-19 00:43:20 +00003151static u32 qeth_l3_fix_features(struct net_device *dev, u32 features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003152{
Heiko Carstens509e2562008-07-26 02:24:10 -07003153 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003154
Michał Mirosław6204b472011-04-19 00:43:20 +00003155 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3156 features &= ~NETIF_F_IP_CSUM;
3157 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
3158 features &= ~NETIF_F_TSO;
3159 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
3160 features &= ~NETIF_F_RXCSUM;
3161
3162 return features;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003163}
3164
Michał Mirosław6204b472011-04-19 00:43:20 +00003165static int qeth_l3_set_features(struct net_device *dev, u32 features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003166{
Michał Mirosław6204b472011-04-19 00:43:20 +00003167 struct qeth_card *card = dev->ml_priv;
3168 u32 changed = dev->features ^ features;
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003169 int err;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003170
Michał Mirosław6204b472011-04-19 00:43:20 +00003171 if (!(changed & NETIF_F_RXCSUM))
3172 return 0;
3173
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003174 if (card->state == CARD_STATE_DOWN ||
3175 card->state == CARD_STATE_RECOVER)
3176 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003177
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003178 err = qeth_l3_set_rx_csum(card, features & NETIF_F_RXCSUM);
3179 if (err)
3180 dev->features = features ^ NETIF_F_RXCSUM;
3181
3182 return err;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003183}
3184
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003185static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003186 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003187 .get_strings = qeth_core_get_strings,
3188 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003189 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003190 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003191 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003192};
3193
3194/*
3195 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3196 * NOARP on the netdevice is no option because it also turns off neighbor
3197 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3198 * arp resolution but we want the hard header (packet socket will work
3199 * e.g. tcpdump)
3200 */
3201static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3202{
3203 n->nud_state = NUD_NOARP;
3204 memcpy(n->ha, "FAKELL", 6);
3205 n->output = n->ops->connected_output;
3206 return 0;
3207}
3208
3209static int
3210qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3211{
3212 if (np->tbl->family == AF_INET)
3213 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3214
3215 return 0;
3216}
3217
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003218static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003219 .ndo_open = qeth_l3_open,
3220 .ndo_stop = qeth_l3_stop,
3221 .ndo_get_stats = qeth_get_stats,
3222 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3223 .ndo_validate_addr = eth_validate_addr,
3224 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3225 .ndo_do_ioctl = qeth_l3_do_ioctl,
3226 .ndo_change_mtu = qeth_change_mtu,
Michał Mirosław6204b472011-04-19 00:43:20 +00003227 .ndo_fix_features = qeth_l3_fix_features,
3228 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003229 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3230 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3231 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3232 .ndo_tx_timeout = qeth_tx_timeout,
3233};
3234
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003235static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3236 .ndo_open = qeth_l3_open,
3237 .ndo_stop = qeth_l3_stop,
3238 .ndo_get_stats = qeth_get_stats,
3239 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3240 .ndo_validate_addr = eth_validate_addr,
3241 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3242 .ndo_do_ioctl = qeth_l3_do_ioctl,
3243 .ndo_change_mtu = qeth_change_mtu,
Michał Mirosław6204b472011-04-19 00:43:20 +00003244 .ndo_fix_features = qeth_l3_fix_features,
3245 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003246 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3247 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3248 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3249 .ndo_tx_timeout = qeth_tx_timeout,
3250 .ndo_neigh_setup = qeth_l3_neigh_setup,
3251};
3252
Frank Blaschka4a71df52008-02-15 09:19:42 +01003253static int qeth_l3_setup_netdev(struct qeth_card *card)
3254{
Ursula Braun5113fec2010-05-16 21:15:14 +00003255 if (card->info.type == QETH_CARD_TYPE_OSD ||
3256 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003257 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3258 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3259#ifdef CONFIG_TR
3260 card->dev = alloc_trdev(0);
3261#endif
3262 if (!card->dev)
3263 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003264 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003265 } else {
3266 card->dev = alloc_etherdev(0);
3267 if (!card->dev)
3268 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003269 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003270
3271 /*IPv6 address autoconfiguration stuff*/
3272 qeth_l3_get_unique_id(card);
3273 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3274 card->dev->dev_id = card->info.unique_id &
3275 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003276 if (!card->info.guestlan) {
3277 card->dev->hw_features = NETIF_F_SG |
3278 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3279 NETIF_F_TSO;
3280 card->dev->features = NETIF_F_RXCSUM;
3281 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003282 }
3283 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3284 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3285 if (!card->dev)
3286 return -ENODEV;
3287 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003288 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003289 qeth_l3_iqd_read_initial_mac(card);
3290 } else
3291 return -ENODEV;
3292
Heiko Carstens509e2562008-07-26 02:24:10 -07003293 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003294 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003295 card->dev->mtu = card->info.initial_mtu;
3296 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3297 card->dev->features |= NETIF_F_HW_VLAN_TX |
3298 NETIF_F_HW_VLAN_RX |
3299 NETIF_F_HW_VLAN_FILTER;
Eric Dumazet86d15cd2009-05-30 23:04:46 -07003300 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003301 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003302
3303 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003304 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003305 return register_netdev(card->dev);
3306}
3307
Frank Blaschka4a71df52008-02-15 09:19:42 +01003308static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3309{
3310 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3311
3312 qeth_l3_create_device_attributes(&gdev->dev);
3313 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003314 card->info.hwtrap = 0;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003315 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003316 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003317 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003318 card->discipline.output_handler = (qdio_handler_t *)
3319 qeth_qdio_output_handler;
3320 card->discipline.recover = qeth_l3_recover;
3321 return 0;
3322}
3323
3324static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3325{
3326 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3327
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003328 qeth_l3_remove_device_attributes(&cgdev->dev);
3329
Ursula Braunf2148562009-05-19 21:38:37 +00003330 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003331 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3332
Ursula Braun70919e22011-02-26 22:41:36 -08003333 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003334 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003335
3336 if (card->dev) {
3337 unregister_netdev(card->dev);
3338 card->dev = NULL;
3339 }
3340
Ursula Braun70919e22011-02-26 22:41:36 -08003341 qeth_l3_clear_ip_list(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003342 qeth_l3_clear_ipato_list(card);
3343 return;
3344}
3345
3346static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3347{
3348 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3349 int rc = 0;
3350 enum qeth_card_states recover_flag;
3351
3352 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003353 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003354 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003355 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3356 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003357
Frank Blaschka4a71df52008-02-15 09:19:42 +01003358 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003359 rc = qeth_core_hardsetup_card(card);
3360 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003361 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003362 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003363 goto out_remove;
3364 }
3365
Ursula Braunaa909222009-11-12 00:11:43 +00003366 if (!card->dev && qeth_l3_setup_netdev(card)) {
3367 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003368 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003369 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003370
Frank Blaschka1da74b12011-05-12 18:45:02 +00003371 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3372 if (card->info.hwtrap &&
3373 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3374 card->info.hwtrap = 0;
3375 } else
3376 card->info.hwtrap = 0;
3377
Frank Blaschka4a71df52008-02-15 09:19:42 +01003378 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003379 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003380 qeth_print_status_message(card);
3381
3382 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003383 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003384
3385 rc = qeth_send_startlan(card);
3386 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003387 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003388 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003389 dev_warn(&card->gdev->dev,
3390 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003391 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003392 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003393 }
Ursula Braunaa909222009-11-12 00:11:43 +00003394 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003395 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003396 } else
3397 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003398
Ursula Braun2b6203b2010-11-26 02:41:19 +00003399contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003400 rc = qeth_l3_setadapter_parms(card);
3401 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003402 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003403 if (!card->options.sniffer) {
3404 rc = qeth_l3_start_ipassists(card);
3405 if (rc)
3406 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003407 rc = qeth_l3_setrouting_v4(card);
3408 if (rc)
3409 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3410 rc = qeth_l3_setrouting_v6(card);
3411 if (rc)
3412 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3413 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003414 netif_tx_disable(card->dev);
3415
3416 rc = qeth_init_qdio_queues(card);
3417 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003418 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003419 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003420 goto out_remove;
3421 }
3422 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003423
3424 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003425 qeth_l3_set_ip_addr_list(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003426 if (card->lan_online)
3427 netif_carrier_on(card->dev);
3428 else
3429 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003430 if (recover_flag == CARD_STATE_RECOVER) {
3431 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003432 __qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003433 else {
3434 rtnl_lock();
3435 dev_open(card->dev);
3436 rtnl_unlock();
3437 }
3438 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003439 }
3440 /* let user_space know that device is online */
3441 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003442 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003443 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003444 return 0;
3445out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003446 qeth_l3_stop_card(card, 0);
3447 ccw_device_set_offline(CARD_DDEV(card));
3448 ccw_device_set_offline(CARD_WDEV(card));
3449 ccw_device_set_offline(CARD_RDEV(card));
3450 if (recover_flag == CARD_STATE_RECOVER)
3451 card->state = CARD_STATE_RECOVER;
3452 else
3453 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003454 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003455 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003456 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003457}
3458
3459static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3460{
3461 return __qeth_l3_set_online(gdev, 0);
3462}
3463
3464static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3465 int recovery_mode)
3466{
3467 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3468 int rc = 0, rc2 = 0, rc3 = 0;
3469 enum qeth_card_states recover_flag;
3470
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003471 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003472 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003473 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3474 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003475
3476 if (card->dev && netif_carrier_ok(card->dev))
3477 netif_carrier_off(card->dev);
3478 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003479 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3480 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3481 card->info.hwtrap = 1;
3482 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003483 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003484 rc = ccw_device_set_offline(CARD_DDEV(card));
3485 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3486 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3487 if (!rc)
3488 rc = (rc2) ? rc2 : rc3;
3489 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003490 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003491 if (recover_flag == CARD_STATE_UP)
3492 card->state = CARD_STATE_RECOVER;
3493 /* let user_space know that device is offline */
3494 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003495 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003496 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003497 return 0;
3498}
3499
3500static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3501{
3502 return __qeth_l3_set_offline(cgdev, 0);
3503}
3504
3505static int qeth_l3_recover(void *ptr)
3506{
3507 struct qeth_card *card;
3508 int rc = 0;
3509
3510 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003511 QETH_CARD_TEXT(card, 2, "recover1");
3512 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003513 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3514 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003515 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003516 dev_warn(&card->gdev->dev,
3517 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003518 __qeth_l3_set_offline(card->gdev, 1);
3519 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003520 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003521 dev_info(&card->gdev->dev,
3522 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003523 else {
3524 rtnl_lock();
3525 dev_close(card->dev);
3526 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003527 dev_warn(&card->gdev->dev, "The qeth device driver "
3528 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003529 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003530 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3531 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003532 return 0;
3533}
3534
3535static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3536{
3537 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Frank Blaschka1da74b12011-05-12 18:45:02 +00003538 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3539 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003540 qeth_qdio_clear_card(card, 0);
3541 qeth_clear_qdio_buffers(card);
3542}
3543
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003544static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3545{
3546 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3547
3548 if (card->dev)
3549 netif_device_detach(card->dev);
3550 qeth_set_allowed_threads(card, 0, 1);
3551 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3552 if (gdev->state == CCWGROUP_OFFLINE)
3553 return 0;
3554 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003555 if (card->info.hwtrap)
3556 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003557 __qeth_l3_set_offline(card->gdev, 1);
3558 } else
3559 __qeth_l3_set_offline(card->gdev, 0);
3560 return 0;
3561}
3562
3563static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3564{
3565 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3566 int rc = 0;
3567
3568 if (gdev->state == CCWGROUP_OFFLINE)
3569 goto out;
3570
3571 if (card->state == CARD_STATE_RECOVER) {
3572 rc = __qeth_l3_set_online(card->gdev, 1);
3573 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003574 rtnl_lock();
3575 dev_close(card->dev);
3576 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003577 }
3578 } else
3579 rc = __qeth_l3_set_online(card->gdev, 0);
3580out:
3581 qeth_set_allowed_threads(card, 0xffffffff, 0);
3582 if (card->dev)
3583 netif_device_attach(card->dev);
3584 if (rc)
3585 dev_warn(&card->gdev->dev, "The qeth device driver "
3586 "failed to recover an error on the device\n");
3587 return rc;
3588}
3589
Frank Blaschka4a71df52008-02-15 09:19:42 +01003590struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3591 .probe = qeth_l3_probe_device,
3592 .remove = qeth_l3_remove_device,
3593 .set_online = qeth_l3_set_online,
3594 .set_offline = qeth_l3_set_offline,
3595 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003596 .freeze = qeth_l3_pm_suspend,
3597 .thaw = qeth_l3_pm_resume,
3598 .restore = qeth_l3_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003599};
3600EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3601
3602static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003603 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003604{
3605 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3606 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3607 struct qeth_ipaddr *addr;
3608 struct qeth_card *card;
3609
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003610 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003611 return NOTIFY_DONE;
3612
Frank Blaschka4a71df52008-02-15 09:19:42 +01003613 card = qeth_l3_get_card_from_dev(dev);
Carsten Otte847a50f2010-06-21 22:57:05 +00003614 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003615 if (!card)
3616 return NOTIFY_DONE;
3617
3618 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3619 if (addr != NULL) {
3620 addr->u.a4.addr = ifa->ifa_address;
3621 addr->u.a4.mask = ifa->ifa_mask;
3622 addr->type = QETH_IP_TYPE_NORMAL;
3623 } else
3624 goto out;
3625
3626 switch (event) {
3627 case NETDEV_UP:
3628 if (!qeth_l3_add_ip(card, addr))
3629 kfree(addr);
3630 break;
3631 case NETDEV_DOWN:
3632 if (!qeth_l3_delete_ip(card, addr))
3633 kfree(addr);
3634 break;
3635 default:
3636 break;
3637 }
3638 qeth_l3_set_ip_addr_list(card);
3639out:
3640 return NOTIFY_DONE;
3641}
3642
3643static struct notifier_block qeth_l3_ip_notifier = {
3644 qeth_l3_ip_event,
3645 NULL,
3646};
3647
3648#ifdef CONFIG_QETH_IPV6
3649/**
3650 * IPv6 event handler
3651 */
3652static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003653 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003654{
3655 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3656 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3657 struct qeth_ipaddr *addr;
3658 struct qeth_card *card;
3659
Frank Blaschka4a71df52008-02-15 09:19:42 +01003660
3661 card = qeth_l3_get_card_from_dev(dev);
3662 if (!card)
3663 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003664 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003665 if (!qeth_is_supported(card, IPA_IPV6))
3666 return NOTIFY_DONE;
3667
3668 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3669 if (addr != NULL) {
3670 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3671 addr->u.a6.pfxlen = ifa->prefix_len;
3672 addr->type = QETH_IP_TYPE_NORMAL;
3673 } else
3674 goto out;
3675
3676 switch (event) {
3677 case NETDEV_UP:
3678 if (!qeth_l3_add_ip(card, addr))
3679 kfree(addr);
3680 break;
3681 case NETDEV_DOWN:
3682 if (!qeth_l3_delete_ip(card, addr))
3683 kfree(addr);
3684 break;
3685 default:
3686 break;
3687 }
3688 qeth_l3_set_ip_addr_list(card);
3689out:
3690 return NOTIFY_DONE;
3691}
3692
3693static struct notifier_block qeth_l3_ip6_notifier = {
3694 qeth_l3_ip6_event,
3695 NULL,
3696};
3697#endif
3698
3699static int qeth_l3_register_notifiers(void)
3700{
3701 int rc;
3702
Carsten Otte847a50f2010-06-21 22:57:05 +00003703 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003704 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3705 if (rc)
3706 return rc;
3707#ifdef CONFIG_QETH_IPV6
3708 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3709 if (rc) {
3710 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3711 return rc;
3712 }
3713#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003714 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003715#endif
3716 return 0;
3717}
3718
3719static void qeth_l3_unregister_notifiers(void)
3720{
3721
Carsten Otte847a50f2010-06-21 22:57:05 +00003722 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003723 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3724#ifdef CONFIG_QETH_IPV6
3725 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3726#endif /* QETH_IPV6 */
3727}
3728
3729static int __init qeth_l3_init(void)
3730{
3731 int rc = 0;
3732
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003733 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003734 rc = qeth_l3_register_notifiers();
3735 return rc;
3736}
3737
3738static void __exit qeth_l3_exit(void)
3739{
3740 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003741 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003742}
3743
3744module_init(qeth_l3_init);
3745module_exit(qeth_l3_exit);
3746MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3747MODULE_DESCRIPTION("qeth layer 3 discipline");
3748MODULE_LICENSE("GPL");