blob: 18484b586a3eb2eae66c209bcbdabd8199c92688 [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
1280static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1281 struct qeth_reply *reply, unsigned long data)
1282{
1283 struct qeth_ipa_cmd *cmd;
1284
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001285 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001286
1287 cmd = (struct qeth_ipa_cmd *) data;
1288 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1289 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1290 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1291 } else {
1292 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1293 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1294 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001295 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1296 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1297 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001298 return 0;
1299}
1300
1301static int qeth_l3_query_ipassists(struct qeth_card *card,
1302 enum qeth_prot_versions prot)
1303{
1304 int rc;
1305 struct qeth_cmd_buffer *iob;
1306
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001307 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001308 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1309 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1310 return rc;
1311}
1312
1313#ifdef CONFIG_QETH_IPV6
1314static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1315{
1316 int rc;
1317
Carsten Otte847a50f2010-06-21 22:57:05 +00001318 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319
1320 if (card->info.type == QETH_CARD_TYPE_IQD)
1321 goto out;
1322
1323 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1324 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001325 dev_err(&card->gdev->dev,
1326 "Activating IPv6 support for %s failed\n",
1327 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001328 return rc;
1329 }
1330 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1331 IPA_CMD_ASS_START, 3);
1332 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001333 dev_err(&card->gdev->dev,
1334 "Activating IPv6 support for %s failed\n",
1335 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001336 return rc;
1337 }
1338 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1339 IPA_CMD_ASS_START);
1340 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001341 dev_err(&card->gdev->dev,
1342 "Activating IPv6 support for %s failed\n",
1343 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001344 return rc;
1345 }
1346 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1347 IPA_CMD_ASS_START);
1348 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001349 dev_warn(&card->gdev->dev,
1350 "Enabling the passthrough mode for %s failed\n",
1351 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001352 return rc;
1353 }
1354out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001355 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001356 return 0;
1357}
1358#endif
1359
1360static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1361{
1362 int rc = 0;
1363
Carsten Otte847a50f2010-06-21 22:57:05 +00001364 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365
1366 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001367 dev_info(&card->gdev->dev,
1368 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001369 return 0;
1370 }
1371#ifdef CONFIG_QETH_IPV6
1372 rc = qeth_l3_softsetup_ipv6(card);
1373#endif
1374 return rc ;
1375}
1376
1377static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1378{
1379 int rc;
1380
Carsten Otte847a50f2010-06-21 22:57:05 +00001381 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001382 card->info.broadcast_capable = 0;
1383 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001384 dev_info(&card->gdev->dev,
1385 "Broadcast not supported on %s\n",
1386 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001387 rc = -EOPNOTSUPP;
1388 goto out;
1389 }
1390 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1391 IPA_CMD_ASS_START, 0);
1392 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001393 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1394 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001395 goto out;
1396 }
1397
1398 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1399 IPA_CMD_ASS_CONFIGURE, 1);
1400 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001401 dev_warn(&card->gdev->dev,
1402 "Setting up broadcast filtering for %s failed\n",
1403 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001404 goto out;
1405 }
1406 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001407 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001408 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1409 IPA_CMD_ASS_ENABLE, 1);
1410 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001411 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1412 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001413 goto out;
1414 }
1415 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1416out:
1417 if (card->info.broadcast_capable)
1418 card->dev->flags |= IFF_BROADCAST;
1419 else
1420 card->dev->flags &= ~IFF_BROADCAST;
1421 return rc;
1422}
1423
1424static int qeth_l3_send_checksum_command(struct qeth_card *card)
1425{
1426 int rc;
1427
1428 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1429 IPA_CMD_ASS_START, 0);
1430 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001431 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1432 "failed, using SW checksumming\n",
1433 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001434 return rc;
1435 }
1436 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1437 IPA_CMD_ASS_ENABLE,
1438 card->info.csum_mask);
1439 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001440 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1441 "failed, using SW checksumming\n",
1442 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001443 return rc;
1444 }
1445 return 0;
1446}
1447
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001448int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001449{
1450 int rc = 0;
1451
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001452 if (on) {
1453 if (card->state != CARD_STATE_DOWN) {
1454 if (!qeth_is_supported(card,
1455 IPA_INBOUND_CHECKSUM))
1456 return -EPERM;
1457 rc = qeth_l3_send_checksum_command(card);
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001458 if (rc)
1459 return -EIO;
1460 }
Michał Mirosław6204b472011-04-19 00:43:20 +00001461 card->dev->features |= NETIF_F_RXCSUM;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001462 } else {
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001463 if (card->state != CARD_STATE_DOWN) {
1464 rc = qeth_l3_send_simple_setassparms(card,
1465 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1466 if (rc)
1467 return -EIO;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001468 }
Michał Mirosław6204b472011-04-19 00:43:20 +00001469 card->dev->features &= ~NETIF_F_RXCSUM;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001470 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001471
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001472 return rc;
1473}
1474
Frank Blaschka4a71df52008-02-15 09:19:42 +01001475static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1476{
1477 int rc = 0;
1478
Carsten Otte847a50f2010-06-21 22:57:05 +00001479 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001480
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001481 if (card->dev->features & NETIF_F_RXCSUM) {
1482 /* hw may have changed during offline or recovery */
1483 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
1484 dev_info(&card->gdev->dev,
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001485 "Inbound HW Checksumming not "
1486 "supported on %s,\ncontinuing "
1487 "using Inbound SW Checksumming\n",
1488 QETH_CARD_IFNAME(card));
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001489 goto update_feature;
1490 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001491
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001492 rc = qeth_l3_send_checksum_command(card);
1493 if (!rc)
1494 dev_info(&card->gdev->dev,
1495 "HW Checksumming (inbound) enabled\n");
1496 else
1497 goto update_feature;
1498 } else
1499 dev_info(&card->gdev->dev,
1500 "Using SW checksumming on %s.\n",
1501 QETH_CARD_IFNAME(card));
1502 return 0;
1503
1504update_feature:
1505 rtnl_lock();
1506 card->dev->features &= ~NETIF_F_RXCSUM;
1507 netdev_update_features(card->dev);
1508 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001509 return rc;
1510}
1511
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001512static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1513{
1514 int rc = 0;
1515
1516 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1517 return rc;
1518 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1519 IPA_CMD_ASS_START, 0);
1520 if (rc)
1521 goto err_out;
1522 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1523 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1524 if (rc)
1525 goto err_out;
1526 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1527 return rc;
1528err_out:
1529 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1530 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1531 return rc;
1532}
1533
Frank Blaschka4a71df52008-02-15 09:19:42 +01001534static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1535{
1536 int rc;
1537
Carsten Otte847a50f2010-06-21 22:57:05 +00001538 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001539
1540 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001541 dev_info(&card->gdev->dev,
1542 "Outbound TSO not supported on %s\n",
1543 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001544 rc = -EOPNOTSUPP;
1545 } else {
1546 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1547 IPA_CMD_ASS_START, 0);
1548 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001549 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1550 "segmentation offload for %s failed\n",
1551 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001552 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001553 dev_info(&card->gdev->dev,
1554 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001555 }
Michał Mirosław6204b472011-04-19 00:43:20 +00001556 if (rc)
1557 card->dev->features &= ~NETIF_F_TSO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001558 return rc;
1559}
1560
1561static int qeth_l3_start_ipassists(struct qeth_card *card)
1562{
Carsten Otte847a50f2010-06-21 22:57:05 +00001563 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001564
1565 qeth_set_access_ctrl_online(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001566 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1567 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1568 qeth_l3_start_ipa_source_mac(card); /* go on*/
1569 qeth_l3_start_ipa_vlan(card); /* go on*/
1570 qeth_l3_start_ipa_multicast(card); /* go on*/
1571 qeth_l3_start_ipa_ipv6(card); /* go on*/
1572 qeth_l3_start_ipa_broadcast(card); /* go on*/
1573 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001574 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001575 qeth_l3_start_ipa_tso(card); /* go on*/
1576 return 0;
1577}
1578
Frank Blaschka4a71df52008-02-15 09:19:42 +01001579static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1580 struct qeth_reply *reply, unsigned long data)
1581{
1582 struct qeth_ipa_cmd *cmd;
1583
1584 cmd = (struct qeth_ipa_cmd *) data;
1585 if (cmd->hdr.return_code == 0)
1586 memcpy(card->dev->dev_addr,
1587 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1588 else
1589 random_ether_addr(card->dev->dev_addr);
1590
1591 return 0;
1592}
1593
1594static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1595{
1596 int rc = 0;
1597 struct qeth_cmd_buffer *iob;
1598 struct qeth_ipa_cmd *cmd;
1599
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001600 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001601
1602 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1603 QETH_PROT_IPV6);
1604 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1605 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1606 card->info.unique_id;
1607
1608 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1609 NULL);
1610 return rc;
1611}
1612
1613static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1614 struct qeth_reply *reply, unsigned long data)
1615{
1616 struct qeth_ipa_cmd *cmd;
1617
1618 cmd = (struct qeth_ipa_cmd *) data;
1619 if (cmd->hdr.return_code == 0)
1620 card->info.unique_id = *((__u16 *)
1621 &cmd->data.create_destroy_addr.unique_id[6]);
1622 else {
1623 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1624 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001625 dev_warn(&card->gdev->dev, "The network adapter failed to "
1626 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001627 }
1628 return 0;
1629}
1630
1631static int qeth_l3_get_unique_id(struct qeth_card *card)
1632{
1633 int rc = 0;
1634 struct qeth_cmd_buffer *iob;
1635 struct qeth_ipa_cmd *cmd;
1636
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001637 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001638
1639 if (!qeth_is_supported(card, IPA_IPV6)) {
1640 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1641 UNIQUE_ID_NOT_BY_CARD;
1642 return 0;
1643 }
1644
1645 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1646 QETH_PROT_IPV6);
1647 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1648 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1649 card->info.unique_id;
1650
1651 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1652 return rc;
1653}
1654
Ursula Braun76b11f82010-01-11 02:50:50 +00001655static int
1656qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1657 unsigned long data)
1658{
1659 struct qeth_ipa_cmd *cmd;
1660 __u16 rc;
1661
1662 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1663
1664 cmd = (struct qeth_ipa_cmd *)data;
1665 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001666 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001667 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001668 switch (cmd->data.diagass.action) {
1669 case QETH_DIAGS_CMD_TRACE_QUERY:
1670 break;
1671 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001672 switch (rc) {
1673 case 0:
1674 case IPA_RC_INVALID_SUBCMD:
1675 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1676 dev_info(&card->gdev->dev, "The HiperSockets network "
1677 "traffic analyzer is deactivated\n");
1678 break;
1679 default:
1680 break;
1681 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001682 break;
1683 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001684 switch (rc) {
1685 case 0:
1686 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1687 dev_info(&card->gdev->dev, "The HiperSockets network "
1688 "traffic analyzer is activated\n");
1689 break;
1690 case IPA_RC_HARDWARE_AUTH_ERROR:
1691 dev_warn(&card->gdev->dev, "The device is not "
1692 "authorized to run as a HiperSockets network "
1693 "traffic analyzer\n");
1694 break;
1695 case IPA_RC_TRACE_ALREADY_ACTIVE:
1696 dev_warn(&card->gdev->dev, "A HiperSockets "
1697 "network traffic analyzer is already "
1698 "active in the HiperSockets LAN\n");
1699 break;
1700 default:
1701 break;
1702 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001703 break;
1704 default:
1705 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1706 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1707 }
1708
1709 return 0;
1710}
1711
1712static int
1713qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1714{
1715 struct qeth_cmd_buffer *iob;
1716 struct qeth_ipa_cmd *cmd;
1717
1718 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1719
1720 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1721 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1722 cmd->data.diagass.subcmd_len = 16;
1723 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1724 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1725 cmd->data.diagass.action = diags_cmd;
1726 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1727}
1728
Frank Blaschka4a71df52008-02-15 09:19:42 +01001729static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1730 struct net_device *dev)
1731{
1732 if (dev->type == ARPHRD_IEEE802_TR)
1733 ip_tr_mc_map(ipm, mac);
1734 else
1735 ip_eth_mc_map(ipm, mac);
1736}
1737
1738static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1739{
1740 struct qeth_ipaddr *ipm;
1741 struct ip_mc_list *im4;
1742 char buf[MAX_ADDR_LEN];
1743
Carsten Otte847a50f2010-06-21 22:57:05 +00001744 QETH_CARD_TEXT(card, 4, "addmc");
Sachin Santf3aa31362010-11-26 02:41:17 +00001745 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1746 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001747 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1748 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1749 if (!ipm)
1750 continue;
1751 ipm->u.a4.addr = im4->multiaddr;
1752 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1753 ipm->is_multicast = 1;
1754 if (!qeth_l3_add_ip(card, ipm))
1755 kfree(ipm);
1756 }
1757}
1758
1759static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1760{
1761 struct in_device *in_dev;
1762 struct vlan_group *vg;
1763 int i;
1764
Carsten Otte847a50f2010-06-21 22:57:05 +00001765 QETH_CARD_TEXT(card, 4, "addmcvl");
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 = in_dev_get(netdev);
1776 if (!in_dev)
1777 continue;
Sachin Santf3aa31362010-11-26 02:41:17 +00001778 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001779 qeth_l3_add_mc(card, in_dev);
Sachin Santf3aa31362010-11-26 02:41:17 +00001780 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001781 in_dev_put(in_dev);
1782 }
1783}
1784
1785static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1786{
1787 struct in_device *in4_dev;
1788
Carsten Otte847a50f2010-06-21 22:57:05 +00001789 QETH_CARD_TEXT(card, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001790 in4_dev = in_dev_get(card->dev);
1791 if (in4_dev == NULL)
1792 return;
Sachin Santf3aa31362010-11-26 02:41:17 +00001793 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001794 qeth_l3_add_mc(card, in4_dev);
1795 qeth_l3_add_vlan_mc(card);
Sachin Santf3aa31362010-11-26 02:41:17 +00001796 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001797 in_dev_put(in4_dev);
1798}
1799
1800#ifdef CONFIG_QETH_IPV6
1801static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1802{
1803 struct qeth_ipaddr *ipm;
1804 struct ifmcaddr6 *im6;
1805 char buf[MAX_ADDR_LEN];
1806
Carsten Otte847a50f2010-06-21 22:57:05 +00001807 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001808 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1809 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1810 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1811 if (!ipm)
1812 continue;
1813 ipm->is_multicast = 1;
1814 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1815 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1816 sizeof(struct in6_addr));
1817 if (!qeth_l3_add_ip(card, ipm))
1818 kfree(ipm);
1819 }
1820}
1821
1822static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1823{
1824 struct inet6_dev *in_dev;
1825 struct vlan_group *vg;
1826 int i;
1827
Carsten Otte847a50f2010-06-21 22:57:05 +00001828 QETH_CARD_TEXT(card, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001829 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1830 return;
1831
1832 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001833 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001834 struct net_device *netdev = vlan_group_get_device(vg, i);
1835 if (netdev == NULL ||
1836 !(netdev->flags & IFF_UP))
1837 continue;
1838 in_dev = in6_dev_get(netdev);
1839 if (!in_dev)
1840 continue;
1841 read_lock_bh(&in_dev->lock);
1842 qeth_l3_add_mc6(card, in_dev);
1843 read_unlock_bh(&in_dev->lock);
1844 in6_dev_put(in_dev);
1845 }
1846}
1847
1848static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1849{
1850 struct inet6_dev *in6_dev;
1851
Carsten Otte847a50f2010-06-21 22:57:05 +00001852 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001853 if (!qeth_is_supported(card, IPA_IPV6))
1854 return ;
1855 in6_dev = in6_dev_get(card->dev);
1856 if (in6_dev == NULL)
1857 return;
1858 read_lock_bh(&in6_dev->lock);
1859 qeth_l3_add_mc6(card, in6_dev);
1860 qeth_l3_add_vlan_mc6(card);
1861 read_unlock_bh(&in6_dev->lock);
1862 in6_dev_put(in6_dev);
1863}
1864#endif /* CONFIG_QETH_IPV6 */
1865
1866static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1867 unsigned short vid)
1868{
1869 struct in_device *in_dev;
1870 struct in_ifaddr *ifa;
1871 struct qeth_ipaddr *addr;
1872
Carsten Otte847a50f2010-06-21 22:57:05 +00001873 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001874
1875 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1876 if (!in_dev)
1877 return;
1878 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1879 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1880 if (addr) {
1881 addr->u.a4.addr = ifa->ifa_address;
1882 addr->u.a4.mask = ifa->ifa_mask;
1883 addr->type = QETH_IP_TYPE_NORMAL;
1884 if (!qeth_l3_delete_ip(card, addr))
1885 kfree(addr);
1886 }
1887 }
1888 in_dev_put(in_dev);
1889}
1890
1891static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1892 unsigned short vid)
1893{
1894#ifdef CONFIG_QETH_IPV6
1895 struct inet6_dev *in6_dev;
1896 struct inet6_ifaddr *ifa;
1897 struct qeth_ipaddr *addr;
1898
Carsten Otte847a50f2010-06-21 22:57:05 +00001899 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001900
1901 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1902 if (!in6_dev)
1903 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001904 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001905 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1906 if (addr) {
1907 memcpy(&addr->u.a6.addr, &ifa->addr,
1908 sizeof(struct in6_addr));
1909 addr->u.a6.pfxlen = ifa->prefix_len;
1910 addr->type = QETH_IP_TYPE_NORMAL;
1911 if (!qeth_l3_delete_ip(card, addr))
1912 kfree(addr);
1913 }
1914 }
1915 in6_dev_put(in6_dev);
1916#endif /* CONFIG_QETH_IPV6 */
1917}
1918
1919static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1920 unsigned short vid)
1921{
1922 if (!card->vlangrp)
1923 return;
1924 qeth_l3_free_vlan_addresses4(card, vid);
1925 qeth_l3_free_vlan_addresses6(card, vid);
1926}
1927
1928static void qeth_l3_vlan_rx_register(struct net_device *dev,
1929 struct vlan_group *grp)
1930{
Heiko Carstens509e2562008-07-26 02:24:10 -07001931 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001932 unsigned long flags;
1933
Carsten Otte847a50f2010-06-21 22:57:05 +00001934 QETH_CARD_TEXT(card, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001935 spin_lock_irqsave(&card->vlanlock, flags);
1936 card->vlangrp = grp;
1937 spin_unlock_irqrestore(&card->vlanlock, flags);
1938}
1939
1940static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1941{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001942 return;
1943}
1944
1945static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1946{
Heiko Carstens509e2562008-07-26 02:24:10 -07001947 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001948 unsigned long flags;
1949
Carsten Otte847a50f2010-06-21 22:57:05 +00001950 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00001951 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001952 QETH_CARD_TEXT(card, 3, "kidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001953 return;
1954 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001955 spin_lock_irqsave(&card->vlanlock, flags);
1956 /* unregister IP addresses of vlan device */
1957 qeth_l3_free_vlan_addresses(card, vid);
1958 vlan_group_set_device(card->vlangrp, vid, NULL);
1959 spin_unlock_irqrestore(&card->vlanlock, flags);
1960 qeth_l3_set_multicast_list(card->dev);
1961}
1962
Ursula Braun10651db2010-10-01 02:51:13 +00001963static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1964 struct sk_buff *skb, struct qeth_hdr *hdr,
1965 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001966{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001967 __be16 prot;
1968 struct iphdr *ip_hdr;
1969 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001970 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001971
1972 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1973 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1974 ETH_P_IP);
1975 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1976 case QETH_CAST_MULTICAST:
1977 switch (prot) {
1978#ifdef CONFIG_QETH_IPV6
1979 case __constant_htons(ETH_P_IPV6):
1980 ndisc_mc_map((struct in6_addr *)
1981 skb->data + 24,
1982 tg_addr, card->dev, 0);
1983 break;
1984#endif
1985 case __constant_htons(ETH_P_IP):
1986 ip_hdr = (struct iphdr *)skb->data;
1987 (card->dev->type == ARPHRD_IEEE802_TR) ?
1988 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1989 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1990 break;
1991 default:
1992 memcpy(tg_addr, card->dev->broadcast,
1993 card->dev->addr_len);
1994 }
1995 card->stats.multicast++;
1996 skb->pkt_type = PACKET_MULTICAST;
1997 break;
1998 case QETH_CAST_BROADCAST:
1999 memcpy(tg_addr, card->dev->broadcast,
2000 card->dev->addr_len);
2001 card->stats.multicast++;
2002 skb->pkt_type = PACKET_BROADCAST;
2003 break;
2004 case QETH_CAST_UNICAST:
2005 case QETH_CAST_ANYCAST:
2006 case QETH_CAST_NOCAST:
2007 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00002008 if (card->options.sniffer)
2009 skb->pkt_type = PACKET_OTHERHOST;
2010 else
2011 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002012 memcpy(tg_addr, card->dev->dev_addr,
2013 card->dev->addr_len);
2014 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08002015 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2016 card->dev->header_ops->create(skb, card->dev, prot,
2017 tg_addr, &hdr->hdr.l3.dest_addr[2],
2018 card->dev->addr_len);
2019 else
2020 card->dev->header_ops->create(skb, card->dev, prot,
2021 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002022 }
2023
2024#ifdef CONFIG_TR
2025 if (card->dev->type == ARPHRD_IEEE802_TR)
2026 skb->protocol = tr_type_trans(skb, card->dev);
2027 else
2028#endif
2029 skb->protocol = eth_type_trans(skb, card->dev);
2030
2031 if (hdr->hdr.l3.ext_flags &
2032 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00002033 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01002034 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00002035 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002036 }
2037
Frank Blaschkac5e631a2011-05-12 18:45:01 +00002038 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002039 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00002040 (QETH_HDR_EXT_CSUM_HDR_REQ |
2041 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2042 (QETH_HDR_EXT_CSUM_HDR_REQ |
2043 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002044 skb->ip_summed = CHECKSUM_UNNECESSARY;
2045 else
Ursula Braunb9139802009-05-19 21:38:40 +00002046 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00002047 } else
2048 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002049
Ursula Braun10651db2010-10-01 02:51:13 +00002050 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002051}
2052
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002053static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
2054 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002055{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002056 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002057 struct sk_buff *skb;
2058 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002059 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00002060 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002061 unsigned int len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002062
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002063 *done = 0;
2064 BUG_ON(!budget);
2065 while (budget) {
2066 skb = qeth_core_get_next_skb(card,
2067 card->qdio.in_q->bufs[card->rx.b_index].buffer,
2068 &card->rx.b_element, &card->rx.e_offset, &hdr);
2069 if (!skb) {
2070 *done = 1;
2071 break;
2072 }
2073 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002074 switch (hdr->hdr.l3.id) {
2075 case QETH_HEADER_TYPE_LAYER3:
Ursula Braun10651db2010-10-01 02:51:13 +00002076 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
2077 &vlan_tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002078 len = skb->len;
Ursula Braun10651db2010-10-01 02:51:13 +00002079 if (is_vlan && !card->options.sniffer)
2080 vlan_gro_receive(&card->napi, card->vlangrp,
2081 vlan_tag, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002082 else
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002083 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002084 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002085 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2086 skb->pkt_type = PACKET_HOST;
2087 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002088 len = skb->len;
2089 netif_receive_skb(skb);
2090 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002091 default:
2092 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002093 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002094 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002095 continue;
2096 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002097 work_done++;
2098 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002099 card->stats.rx_packets++;
2100 card->stats.rx_bytes += len;
2101 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002102 return work_done;
2103}
2104
2105static int qeth_l3_poll(struct napi_struct *napi, int budget)
2106{
2107 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2108 int work_done = 0;
2109 struct qeth_qdio_buffer *buffer;
2110 int done;
2111 int new_budget = budget;
2112
2113 if (card->options.performance_stats) {
2114 card->perf_stats.inbound_cnt++;
2115 card->perf_stats.inbound_start_time = qeth_get_micros();
2116 }
2117
2118 while (1) {
2119 if (!card->rx.b_count) {
2120 card->rx.qdio_err = 0;
2121 card->rx.b_count = qdio_get_next_buffers(
2122 card->data.ccwdev, 0, &card->rx.b_index,
2123 &card->rx.qdio_err);
2124 if (card->rx.b_count <= 0) {
2125 card->rx.b_count = 0;
2126 break;
2127 }
2128 card->rx.b_element =
2129 &card->qdio.in_q->bufs[card->rx.b_index]
2130 .buffer->element[0];
2131 card->rx.e_offset = 0;
2132 }
2133
2134 while (card->rx.b_count) {
2135 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2136 if (!(card->rx.qdio_err &&
2137 qeth_check_qdio_errors(card, buffer->buffer,
2138 card->rx.qdio_err, "qinerr")))
2139 work_done += qeth_l3_process_inbound_buffer(
2140 card, new_budget, &done);
2141 else
2142 done = 1;
2143
2144 if (done) {
2145 if (card->options.performance_stats)
2146 card->perf_stats.bufs_rec++;
2147 qeth_put_buffer_pool_entry(card,
2148 buffer->pool_entry);
2149 qeth_queue_input_buffer(card, card->rx.b_index);
2150 card->rx.b_count--;
2151 if (card->rx.b_count) {
2152 card->rx.b_index =
2153 (card->rx.b_index + 1) %
2154 QDIO_MAX_BUFFERS_PER_Q;
2155 card->rx.b_element =
2156 &card->qdio.in_q
2157 ->bufs[card->rx.b_index]
2158 .buffer->element[0];
2159 card->rx.e_offset = 0;
2160 }
2161 }
2162
2163 if (work_done >= budget)
2164 goto out;
2165 else
2166 new_budget = budget - work_done;
2167 }
2168 }
2169
2170 napi_complete(napi);
2171 if (qdio_start_irq(card->data.ccwdev, 0))
2172 napi_schedule(&card->napi);
2173out:
2174 if (card->options.performance_stats)
2175 card->perf_stats.inbound_time += qeth_get_micros() -
2176 card->perf_stats.inbound_start_time;
2177 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002178}
2179
2180static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2181 struct qeth_card *card)
2182{
2183 int rc = 0;
2184 struct vlan_group *vg;
2185 int i;
2186
2187 vg = card->vlangrp;
2188 if (!vg)
2189 return rc;
2190
Jesse Grossb7381272010-10-20 13:56:02 +00002191 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002192 if (vlan_group_get_device(vg, i) == dev) {
2193 rc = QETH_VLAN_CARD;
2194 break;
2195 }
2196 }
2197
Heiko Carstens509e2562008-07-26 02:24:10 -07002198 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002199 return 0;
2200
2201 return rc;
2202}
2203
2204static int qeth_l3_verify_dev(struct net_device *dev)
2205{
2206 struct qeth_card *card;
2207 unsigned long flags;
2208 int rc = 0;
2209
2210 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2211 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2212 if (card->dev == dev) {
2213 rc = QETH_REAL_CARD;
2214 break;
2215 }
2216 rc = qeth_l3_verify_vlan_dev(dev, card);
2217 if (rc)
2218 break;
2219 }
2220 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2221
2222 return rc;
2223}
2224
2225static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2226{
2227 struct qeth_card *card = NULL;
2228 int rc;
2229
2230 rc = qeth_l3_verify_dev(dev);
2231 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002232 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002233 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002234 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002235 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002236 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002237 if (card)
2238 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002239 return card ;
2240}
2241
2242static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2243{
2244 int rc = 0;
2245
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002246 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2247 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002248
2249 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002250 if (card->options.sniffer &&
2251 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2252 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002253 if (card->read.state == CH_STATE_UP &&
2254 card->write.state == CH_STATE_UP &&
2255 (card->state == CARD_STATE_UP)) {
2256 if (recovery_mode)
2257 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002258 else {
Ursula Braun869da902010-03-08 20:36:56 +00002259 rtnl_lock();
2260 dev_close(card->dev);
2261 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002262 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002263 card->state = CARD_STATE_SOFTSETUP;
2264 }
2265 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -08002266 qeth_l3_clear_ip_list(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002267 qeth_clear_ipacmd_list(card);
2268 card->state = CARD_STATE_HARDSETUP;
2269 }
2270 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002271 qeth_qdio_clear_card(card, 0);
2272 qeth_clear_qdio_buffers(card);
2273 qeth_clear_working_pool_list(card);
2274 card->state = CARD_STATE_DOWN;
2275 }
2276 if (card->state == CARD_STATE_DOWN) {
2277 qeth_clear_cmd_buffers(&card->read);
2278 qeth_clear_cmd_buffers(&card->write);
2279 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002280 return rc;
2281}
2282
Ursula Braun76b11f82010-01-11 02:50:50 +00002283/*
2284 * test for and Switch promiscuous mode (on or off)
2285 * either for guestlan or HiperSocket Sniffer
2286 */
2287static void
2288qeth_l3_handle_promisc_mode(struct qeth_card *card)
2289{
2290 struct net_device *dev = card->dev;
2291
2292 if (((dev->flags & IFF_PROMISC) &&
2293 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2294 (!(dev->flags & IFF_PROMISC) &&
2295 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2296 return;
2297
2298 if (card->info.guestlan) { /* Guestlan trace */
2299 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2300 qeth_setadp_promisc_mode(card);
2301 } else if (card->options.sniffer && /* HiperSockets trace */
2302 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2303 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002304 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002305 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2306 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002307 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002308 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2309 }
2310 }
2311}
2312
Frank Blaschka4a71df52008-02-15 09:19:42 +01002313static void qeth_l3_set_multicast_list(struct net_device *dev)
2314{
Heiko Carstens509e2562008-07-26 02:24:10 -07002315 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002316
Carsten Otte847a50f2010-06-21 22:57:05 +00002317 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002318 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2319 (card->state != CARD_STATE_UP))
2320 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002321 if (!card->options.sniffer) {
2322 qeth_l3_delete_mc_addresses(card);
2323 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002324#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002325 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002326#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002327 qeth_l3_set_ip_addr_list(card);
2328 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2329 return;
2330 }
2331 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002332}
2333
2334static const char *qeth_l3_arp_get_error_cause(int *rc)
2335{
2336 switch (*rc) {
2337 case QETH_IPA_ARP_RC_FAILED:
2338 *rc = -EIO;
2339 return "operation failed";
2340 case QETH_IPA_ARP_RC_NOTSUPP:
2341 *rc = -EOPNOTSUPP;
2342 return "operation not supported";
2343 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2344 *rc = -EINVAL;
2345 return "argument out of range";
2346 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2347 *rc = -EOPNOTSUPP;
2348 return "query operation not supported";
2349 case QETH_IPA_ARP_RC_Q_NO_DATA:
2350 *rc = -ENOENT;
2351 return "no query data available";
2352 default:
2353 return "unknown error";
2354 }
2355}
2356
2357static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2358{
2359 int tmp;
2360 int rc;
2361
Carsten Otte847a50f2010-06-21 22:57:05 +00002362 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002363
2364 /*
2365 * currently GuestLAN only supports the ARP assist function
2366 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2367 * thus we say EOPNOTSUPP for this ARP function
2368 */
2369 if (card->info.guestlan)
2370 return -EOPNOTSUPP;
2371 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002372 return -EOPNOTSUPP;
2373 }
2374 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2375 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2376 no_entries);
2377 if (rc) {
2378 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002379 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2380 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002381 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2382 }
2383 return rc;
2384}
2385
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002386static __u32 get_arp_entry_size(struct qeth_card *card,
2387 struct qeth_arp_query_data *qdata,
2388 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002389{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002390 __u32 rc;
2391 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002392
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002393 is_hsi = qdata->reply_bits == 5;
2394 if (type->ip == QETHARP_IP_ADDR_V4) {
2395 QETH_CARD_TEXT(card, 4, "arpev4");
2396 if (strip_entries) {
2397 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2398 sizeof(struct qeth_arp_qi_entry7_short);
2399 } else {
2400 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2401 sizeof(struct qeth_arp_qi_entry7);
2402 }
2403 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2404 QETH_CARD_TEXT(card, 4, "arpev6");
2405 if (strip_entries) {
2406 rc = is_hsi ?
2407 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2408 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2409 } else {
2410 rc = is_hsi ?
2411 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2412 sizeof(struct qeth_arp_qi_entry7_ipv6);
2413 }
2414 } else {
2415 QETH_CARD_TEXT(card, 4, "arpinv");
2416 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002417 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002418
2419 return rc;
2420}
2421
2422static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2423{
2424 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2425 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002426}
2427
2428static int qeth_l3_arp_query_cb(struct qeth_card *card,
2429 struct qeth_reply *reply, unsigned long data)
2430{
2431 struct qeth_ipa_cmd *cmd;
2432 struct qeth_arp_query_data *qdata;
2433 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002434 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002435 int e;
2436 int entrybytes_done;
2437 int stripped_bytes;
2438 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002439
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002440 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002441
2442 qinfo = (struct qeth_arp_query_info *) reply->param;
2443 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002444 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002445 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002446 QETH_CARD_TEXT(card, 4, "arpcberr");
2447 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002448 return 0;
2449 }
2450 if (cmd->data.setassparms.hdr.return_code) {
2451 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002452 QETH_CARD_TEXT(card, 4, "setaperr");
2453 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002454 return 0;
2455 }
2456 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002457 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002458
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002459 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2460 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2461 entrybytes_done = 0;
2462 for (e = 0; e < qdata->no_entries; ++e) {
2463 char *cur_entry;
2464 __u32 esize;
2465 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002466
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002467 cur_entry = &qdata->data + entrybytes_done;
2468 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2469 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2470 QETH_CARD_TEXT(card, 4, "pmis");
2471 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2472 break;
2473 }
2474 esize = get_arp_entry_size(card, qdata, etype,
2475 do_strip_entries);
2476 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2477 if (!esize)
2478 break;
2479
2480 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2481 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
2482 cmd->hdr.return_code = -ENOMEM;
2483 goto out_error;
2484 }
2485
2486 memcpy(qinfo->udata + qinfo->udata_offset,
2487 &qdata->data + entrybytes_done + stripped_bytes,
2488 esize);
2489 entrybytes_done += esize + stripped_bytes;
2490 qinfo->udata_offset += esize;
2491 ++qinfo->no_entries;
2492 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002493 /* check if all replies received ... */
2494 if (cmd->data.setassparms.hdr.seq_no <
2495 cmd->data.setassparms.hdr.number_of_replies)
2496 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002497 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002498 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2499 /* keep STRIP_ENTRIES flag so the user program can distinguish
2500 * stripped entries from normal ones */
2501 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2502 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2503 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002504 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002505 return 0;
2506out_error:
2507 i = 0;
2508 memcpy(qinfo->udata, &i, 4);
2509 return 0;
2510}
2511
2512static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2513 struct qeth_cmd_buffer *iob, int len,
2514 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2515 unsigned long),
2516 void *reply_param)
2517{
Carsten Otte847a50f2010-06-21 22:57:05 +00002518 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002519
2520 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2521 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2522 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2523 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2524 reply_cb, reply_param);
2525}
2526
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002527static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2528 enum qeth_prot_versions prot,
2529 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002530{
2531 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002532 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002533 int tmp;
2534 int rc;
2535
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002536 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2537
2538 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2539 IPA_CMD_ASS_ARP_QUERY_INFO,
2540 sizeof(struct qeth_arp_query_data) - sizeof(char),
2541 prot);
2542 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2543 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2544 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2545 cmd->data.setassparms.data.query_arp.no_entries = 0;
2546 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2547 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2548 qeth_l3_arp_query_cb, (void *)qinfo);
2549 if (rc) {
2550 tmp = rc;
2551 QETH_DBF_MESSAGE(2,
2552 "Error while querying ARP cache on %s: %s "
2553 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2554 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2555 }
2556
2557 return rc;
2558}
2559
2560static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2561{
2562 struct qeth_arp_query_info qinfo = {0, };
2563 int rc;
2564
Carsten Otte847a50f2010-06-21 22:57:05 +00002565 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002566
2567 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2568 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002569 QETH_CARD_TEXT(card, 3, "arpqnsup");
2570 rc = -EOPNOTSUPP;
2571 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002572 }
2573 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002574 if (copy_from_user(&qinfo, udata, 6)) {
2575 rc = -EFAULT;
2576 goto out;
2577 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002578 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002579 if (!qinfo.udata) {
2580 rc = -ENOMEM;
2581 goto out;
2582 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002583 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002584 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002585 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002586 if (copy_to_user(udata, qinfo.udata, 4))
2587 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002588 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002589 } else {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002590#ifdef CONFIG_QETH_IPV6
2591 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2592 /* fails in case of GuestLAN QDIO mode */
2593 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2594 &qinfo);
2595 }
2596#endif
2597 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2598 QETH_CARD_TEXT(card, 4, "qactf");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002599 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002600 goto free_and_out;
2601 }
2602 QETH_CARD_TEXT_(card, 4, "qacts");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002603 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002604free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002605 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002606out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002607 return rc;
2608}
2609
2610static int qeth_l3_arp_add_entry(struct qeth_card *card,
2611 struct qeth_arp_cache_entry *entry)
2612{
2613 struct qeth_cmd_buffer *iob;
2614 char buf[16];
2615 int tmp;
2616 int rc;
2617
Carsten Otte847a50f2010-06-21 22:57:05 +00002618 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002619
2620 /*
2621 * currently GuestLAN only supports the ARP assist function
2622 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2623 * thus we say EOPNOTSUPP for this ARP function
2624 */
2625 if (card->info.guestlan)
2626 return -EOPNOTSUPP;
2627 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002628 return -EOPNOTSUPP;
2629 }
2630
2631 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2632 IPA_CMD_ASS_ARP_ADD_ENTRY,
2633 sizeof(struct qeth_arp_cache_entry),
2634 QETH_PROT_IPV4);
2635 rc = qeth_l3_send_setassparms(card, iob,
2636 sizeof(struct qeth_arp_cache_entry),
2637 (unsigned long) entry,
2638 qeth_l3_default_setassparms_cb, NULL);
2639 if (rc) {
2640 tmp = rc;
2641 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002642 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2643 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2644 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002645 }
2646 return rc;
2647}
2648
2649static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2650 struct qeth_arp_cache_entry *entry)
2651{
2652 struct qeth_cmd_buffer *iob;
2653 char buf[16] = {0, };
2654 int tmp;
2655 int rc;
2656
Carsten Otte847a50f2010-06-21 22:57:05 +00002657 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002658
2659 /*
2660 * currently GuestLAN only supports the ARP assist function
2661 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2662 * thus we say EOPNOTSUPP for this ARP function
2663 */
2664 if (card->info.guestlan)
2665 return -EOPNOTSUPP;
2666 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002667 return -EOPNOTSUPP;
2668 }
2669 memcpy(buf, entry, 12);
2670 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2671 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2672 12,
2673 QETH_PROT_IPV4);
2674 rc = qeth_l3_send_setassparms(card, iob,
2675 12, (unsigned long)buf,
2676 qeth_l3_default_setassparms_cb, NULL);
2677 if (rc) {
2678 tmp = rc;
2679 memset(buf, 0, 16);
2680 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002681 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2682 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2683 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002684 }
2685 return rc;
2686}
2687
2688static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2689{
2690 int rc;
2691 int tmp;
2692
Carsten Otte847a50f2010-06-21 22:57:05 +00002693 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002694
2695 /*
2696 * currently GuestLAN only supports the ARP assist function
2697 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2698 * thus we say EOPNOTSUPP for this ARP function
2699 */
2700 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2701 return -EOPNOTSUPP;
2702 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002703 return -EOPNOTSUPP;
2704 }
2705 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2706 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2707 if (rc) {
2708 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002709 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2710 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002711 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2712 }
2713 return rc;
2714}
2715
2716static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2717{
Heiko Carstens509e2562008-07-26 02:24:10 -07002718 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002719 struct qeth_arp_cache_entry arp_entry;
2720 struct mii_ioctl_data *mii_data;
2721 int rc = 0;
2722
2723 if (!card)
2724 return -ENODEV;
2725
2726 if ((card->state != CARD_STATE_UP) &&
2727 (card->state != CARD_STATE_SOFTSETUP))
2728 return -ENODEV;
2729
2730 switch (cmd) {
2731 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2732 if (!capable(CAP_NET_ADMIN)) {
2733 rc = -EPERM;
2734 break;
2735 }
2736 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2737 break;
2738 case SIOC_QETH_ARP_QUERY_INFO:
2739 if (!capable(CAP_NET_ADMIN)) {
2740 rc = -EPERM;
2741 break;
2742 }
2743 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2744 break;
2745 case SIOC_QETH_ARP_ADD_ENTRY:
2746 if (!capable(CAP_NET_ADMIN)) {
2747 rc = -EPERM;
2748 break;
2749 }
2750 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2751 sizeof(struct qeth_arp_cache_entry)))
2752 rc = -EFAULT;
2753 else
2754 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2755 break;
2756 case SIOC_QETH_ARP_REMOVE_ENTRY:
2757 if (!capable(CAP_NET_ADMIN)) {
2758 rc = -EPERM;
2759 break;
2760 }
2761 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2762 sizeof(struct qeth_arp_cache_entry)))
2763 rc = -EFAULT;
2764 else
2765 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2766 break;
2767 case SIOC_QETH_ARP_FLUSH_CACHE:
2768 if (!capable(CAP_NET_ADMIN)) {
2769 rc = -EPERM;
2770 break;
2771 }
2772 rc = qeth_l3_arp_flush_cache(card);
2773 break;
2774 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2775 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2776 break;
2777 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002778 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2779 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002780 !card->info.guestlan)
2781 return 1;
2782 return 0;
2783 break;
2784 case SIOCGMIIPHY:
2785 mii_data = if_mii(rq);
2786 mii_data->phy_id = 0;
2787 break;
2788 case SIOCGMIIREG:
2789 mii_data = if_mii(rq);
2790 if (mii_data->phy_id != 0)
2791 rc = -EINVAL;
2792 else
2793 mii_data->val_out = qeth_mdio_read(dev,
2794 mii_data->phy_id,
2795 mii_data->reg_num);
2796 break;
2797 default:
2798 rc = -EOPNOTSUPP;
2799 }
2800 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002801 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002802 return rc;
2803}
2804
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002805int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2806{
2807 int cast_type = RTN_UNSPEC;
2808
2809 if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2810 cast_type = skb_dst(skb)->neighbour->type;
2811 if ((cast_type == RTN_BROADCAST) ||
2812 (cast_type == RTN_MULTICAST) ||
2813 (cast_type == RTN_ANYCAST))
2814 return cast_type;
2815 else
2816 return RTN_UNSPEC;
2817 }
2818 /* try something else */
2819 if (skb->protocol == ETH_P_IPV6)
2820 return (skb_network_header(skb)[24] == 0xff) ?
2821 RTN_MULTICAST : 0;
2822 else if (skb->protocol == ETH_P_IP)
2823 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2824 RTN_MULTICAST : 0;
2825 /* ... */
2826 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2827 return RTN_BROADCAST;
2828 else {
2829 u16 hdr_mac;
2830
2831 hdr_mac = *((u16 *)skb->data);
2832 /* tr multicast? */
2833 switch (card->info.link_type) {
2834 case QETH_LINK_TYPE_HSTR:
2835 case QETH_LINK_TYPE_LANE_TR:
2836 if ((hdr_mac == QETH_TR_MAC_NC) ||
2837 (hdr_mac == QETH_TR_MAC_C))
2838 return RTN_MULTICAST;
2839 break;
2840 /* eth or so multicast? */
2841 default:
2842 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2843 (hdr_mac == QETH_ETH_MAC_V6))
2844 return RTN_MULTICAST;
2845 }
2846 }
2847 return cast_type;
2848}
2849
Frank Blaschka4a71df52008-02-15 09:19:42 +01002850static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2851 struct sk_buff *skb, int ipv, int cast_type)
2852{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002853 memset(hdr, 0, sizeof(struct qeth_hdr));
2854 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2855 hdr->hdr.l3.ext_flags = 0;
2856
2857 /*
2858 * before we're going to overwrite this location with next hop ip.
2859 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2860 */
2861 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002862 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2863 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2864 else
2865 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002866 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2867 }
2868
2869 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2870 if (ipv == 4) {
2871 /* IPv4 */
2872 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2873 memset(hdr->hdr.l3.dest_addr, 0, 12);
Eric Dumazetadf30902009-06-02 05:19:30 +00002874 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002875 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
Eric Dumazetadf30902009-06-02 05:19:30 +00002876 *((u32 *) skb_dst(skb)->neighbour->primary_key);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002877 } else {
2878 /* fill in destination address used in ip header */
2879 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2880 ip_hdr(skb)->daddr;
2881 }
2882 } else if (ipv == 6) {
2883 /* IPv6 */
2884 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2885 if (card->info.type == QETH_CARD_TYPE_IQD)
2886 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
Eric Dumazetadf30902009-06-02 05:19:30 +00002887 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002888 memcpy(hdr->hdr.l3.dest_addr,
Eric Dumazetadf30902009-06-02 05:19:30 +00002889 skb_dst(skb)->neighbour->primary_key, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002890 } else {
2891 /* fill in destination address used in ip header */
2892 memcpy(hdr->hdr.l3.dest_addr,
2893 &ipv6_hdr(skb)->daddr, 16);
2894 }
2895 } else {
2896 /* passthrough */
2897 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2898 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2899 sizeof(__u16), skb->dev->broadcast, 6)) {
2900 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2901 QETH_HDR_PASSTHRU;
2902 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2903 skb->dev->broadcast, 6)) {
2904 /* broadcast? */
2905 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2906 QETH_HDR_PASSTHRU;
2907 } else {
2908 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2909 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2910 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2911 }
2912 }
2913}
2914
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002915static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2916 struct qeth_hdr *hdr, struct sk_buff *skb)
2917{
2918 struct iphdr *iph = ip_hdr(skb);
2919
2920 /* tcph->check contains already the pseudo hdr checksum
2921 * so just set the header flags
2922 */
2923 if (iph->protocol == IPPROTO_UDP)
2924 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002925 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2926 QETH_HDR_EXT_CSUM_HDR_REQ;
2927 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002928 if (card->options.performance_stats)
2929 card->perf_stats.tx_csum++;
2930}
2931
Frank Blaschka64ef8952009-03-24 20:57:16 +00002932static void qeth_tso_fill_header(struct qeth_card *card,
2933 struct qeth_hdr *qhdr, struct sk_buff *skb)
2934{
2935 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2936 struct tcphdr *tcph = tcp_hdr(skb);
2937 struct iphdr *iph = ip_hdr(skb);
2938 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2939
2940 /*fix header to TSO values ...*/
2941 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002942 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002943 /*set values which are fix for the first approach ...*/
2944 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2945 hdr->ext.imb_hdr_no = 1;
2946 hdr->ext.hdr_type = 1;
2947 hdr->ext.hdr_version = 1;
2948 hdr->ext.hdr_len = 28;
2949 /*insert non-fix values */
2950 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2951 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2952 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2953 sizeof(struct qeth_hdr_tso));
2954 tcph->check = 0;
2955 if (skb->protocol == ETH_P_IPV6) {
2956 ip6h->payload_len = 0;
2957 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2958 0, IPPROTO_TCP, 0);
2959 } else {
2960 /*OSA want us to set these values ...*/
2961 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2962 0, IPPROTO_TCP, 0);
2963 iph->tot_len = 0;
2964 iph->check = 0;
2965 }
2966}
2967
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002968static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2969{
2970 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2971 tcp_hdr(skb)->doff * 4;
2972 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002973 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002974 elements += skb_shinfo(skb)->nr_frags;
2975 return elements;
2976}
2977
Frank Blaschka4a71df52008-02-15 09:19:42 +01002978static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2979{
2980 int rc;
2981 u16 *tag;
2982 struct qeth_hdr *hdr = NULL;
2983 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002984 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002985 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002986 struct sk_buff *new_skb = NULL;
2987 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002988 int cast_type = qeth_l3_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002989 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2990 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2991 int tx_bytes = skb->len;
Michał Mirosław6204b472011-04-19 00:43:20 +00002992 bool large_send;
Frank Blaschka683d7182008-08-01 16:39:13 +02002993 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002994 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002995
Frank Blaschka21fde742010-03-08 20:36:54 +00002996 if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
2997 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002998 goto tx_drop;
2999
3000 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3001 card->stats.tx_carrier_errors++;
3002 goto tx_drop;
3003 }
3004
3005 if ((cast_type == RTN_BROADCAST) &&
3006 (card->info.broadcast_capable == 0))
3007 goto tx_drop;
3008
3009 if (card->options.performance_stats) {
3010 card->perf_stats.outbound_cnt++;
3011 card->perf_stats.outbound_start_time = qeth_get_micros();
3012 }
3013
Michał Mirosław6204b472011-04-19 00:43:20 +00003014 large_send = skb_is_gso(skb);
Frank Blaschka683d7182008-08-01 16:39:13 +02003015
3016 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
3017 (skb_shinfo(skb)->nr_frags == 0)) {
3018 new_skb = skb;
3019 data_offset = ETH_HLEN;
3020 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
3021 if (!hdr)
3022 goto tx_drop;
3023 elements_needed++;
3024 } else {
3025 /* create a clone with writeable headroom */
3026 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
3027 + VLAN_HLEN);
3028 if (!new_skb)
3029 goto tx_drop;
3030 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003031
3032 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02003033 if (data_offset < 0)
3034 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003035 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00003036 if (ipv == 4) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003037 if (card->dev->type == ARPHRD_IEEE802_TR)
3038 skb_pull(new_skb, TR_HLEN);
3039 else
3040 skb_pull(new_skb, ETH_HLEN);
3041 }
3042
Frank Blaschka91d45762010-12-08 02:58:00 +00003043 if (ipv != 4 && card->vlangrp &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01003044 vlan_tx_tag_present(new_skb)) {
3045 skb_push(new_skb, VLAN_HLEN);
3046 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
3047 skb_copy_to_linear_data_offset(new_skb, 4,
3048 new_skb->data + 8, 4);
3049 skb_copy_to_linear_data_offset(new_skb, 8,
3050 new_skb->data + 12, 4);
3051 tag = (u16 *)(new_skb->data + 12);
3052 *tag = __constant_htons(ETH_P_8021Q);
3053 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02003054 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003055 }
3056 }
3057
3058 netif_stop_queue(dev);
3059
Frank Blaschka4a71df52008-02-15 09:19:42 +01003060 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003061 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003062 */
Michał Mirosław6204b472011-04-19 00:43:20 +00003063 if (large_send) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003064 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3065 if (skb_linearize(new_skb))
3066 goto tx_drop;
3067 if (card->options.performance_stats)
3068 card->perf_stats.tx_lin++;
3069 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003070 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003071
Michał Mirosław6204b472011-04-19 00:43:20 +00003072 if (large_send && (cast_type == RTN_UNSPEC)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003073 hdr = (struct qeth_hdr *)skb_push(new_skb,
3074 sizeof(struct qeth_hdr_tso));
3075 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3076 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3077 qeth_tso_fill_header(card, hdr, new_skb);
3078 elements_needed++;
3079 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003080 if (data_offset < 0) {
3081 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003082 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003083 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3084 cast_type);
3085 } else {
3086 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3087 cast_type);
3088 hdr->hdr.l3.length = new_skb->len - data_offset;
3089 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003090
3091 if (skb->ip_summed == CHECKSUM_PARTIAL)
3092 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003093 }
3094
Frank Blaschka64ef8952009-03-24 20:57:16 +00003095 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003096 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003097 if (!elems) {
3098 if (data_offset >= 0)
3099 kmem_cache_free(qeth_core_header_cache, hdr);
3100 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003101 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003102 elements_needed += elems;
3103 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003104
Frank Blaschka51aa1652010-06-21 22:57:10 +00003105 if (card->info.type != QETH_CARD_TYPE_IQD) {
3106 int len;
Michał Mirosław6204b472011-04-19 00:43:20 +00003107 if (large_send)
Frank Blaschka51aa1652010-06-21 22:57:10 +00003108 len = ((unsigned long)tcp_hdr(new_skb) +
3109 tcp_hdr(new_skb)->doff * 4) -
3110 (unsigned long)new_skb->data;
3111 else
3112 len = sizeof(struct qeth_hdr_layer3);
3113
3114 if (qeth_hdr_chk_and_bounce(new_skb, len))
3115 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003116 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003117 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003118 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003119 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003120 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003121
3122 if (!rc) {
3123 card->stats.tx_packets++;
3124 card->stats.tx_bytes += tx_bytes;
3125 if (new_skb != skb)
3126 dev_kfree_skb_any(skb);
3127 if (card->options.performance_stats) {
Michał Mirosław6204b472011-04-19 00:43:20 +00003128 if (large_send) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003129 card->perf_stats.large_send_bytes += tx_bytes;
3130 card->perf_stats.large_send_cnt++;
3131 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003132 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003133 card->perf_stats.sg_skbs_sent++;
3134 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003135 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003136 }
3137 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003138 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003139 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003140 if (data_offset >= 0)
3141 kmem_cache_free(qeth_core_header_cache, hdr);
3142
Frank Blaschka4a71df52008-02-15 09:19:42 +01003143 if (rc == -EBUSY) {
3144 if (new_skb != skb)
3145 dev_kfree_skb_any(new_skb);
3146 return NETDEV_TX_BUSY;
3147 } else
3148 goto tx_drop;
3149 }
3150
3151 netif_wake_queue(dev);
3152 if (card->options.performance_stats)
3153 card->perf_stats.outbound_time += qeth_get_micros() -
3154 card->perf_stats.outbound_start_time;
3155 return rc;
3156
3157tx_drop:
3158 card->stats.tx_dropped++;
3159 card->stats.tx_errors++;
3160 if ((new_skb != skb) && new_skb)
3161 dev_kfree_skb_any(new_skb);
3162 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003163 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003164 return NETDEV_TX_OK;
3165}
3166
Ursula Braun39423442011-01-12 20:42:24 +00003167static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003168{
Heiko Carstens509e2562008-07-26 02:24:10 -07003169 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003170 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003171
Carsten Otte847a50f2010-06-21 22:57:05 +00003172 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00003173 if (card->state == CARD_STATE_UP)
3174 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003175 if (card->state != CARD_STATE_SOFTSETUP)
3176 return -ENODEV;
3177 card->data.state = CH_STATE_UP;
3178 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003179 netif_start_queue(dev);
3180
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003181 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3182 napi_enable(&card->napi);
3183 napi_schedule(&card->napi);
3184 } else
3185 rc = -EIO;
3186 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003187}
3188
Ursula Braun39423442011-01-12 20:42:24 +00003189static int qeth_l3_open(struct net_device *dev)
3190{
3191 struct qeth_card *card = dev->ml_priv;
3192
3193 QETH_CARD_TEXT(card, 5, "qethope_");
3194 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3195 QETH_CARD_TEXT(card, 3, "openREC");
3196 return -ERESTARTSYS;
3197 }
3198 return __qeth_l3_open(dev);
3199}
3200
Frank Blaschka4a71df52008-02-15 09:19:42 +01003201static int qeth_l3_stop(struct net_device *dev)
3202{
Heiko Carstens509e2562008-07-26 02:24:10 -07003203 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003204
Carsten Otte847a50f2010-06-21 22:57:05 +00003205 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003206 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003207 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003208 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003209 napi_disable(&card->napi);
3210 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003211 return 0;
3212}
3213
Michał Mirosław6204b472011-04-19 00:43:20 +00003214static u32 qeth_l3_fix_features(struct net_device *dev, u32 features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003215{
Heiko Carstens509e2562008-07-26 02:24:10 -07003216 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003217
Michał Mirosław6204b472011-04-19 00:43:20 +00003218 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3219 features &= ~NETIF_F_IP_CSUM;
3220 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
3221 features &= ~NETIF_F_TSO;
3222 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
3223 features &= ~NETIF_F_RXCSUM;
3224
3225 return features;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003226}
3227
Michał Mirosław6204b472011-04-19 00:43:20 +00003228static int qeth_l3_set_features(struct net_device *dev, u32 features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003229{
Michał Mirosław6204b472011-04-19 00:43:20 +00003230 struct qeth_card *card = dev->ml_priv;
3231 u32 changed = dev->features ^ features;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003232 int on;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003233
Michał Mirosław6204b472011-04-19 00:43:20 +00003234 if (!(changed & NETIF_F_RXCSUM))
3235 return 0;
3236
3237 if (features & NETIF_F_RXCSUM)
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003238 on = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003239 else
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003240 on = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003241
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003242 return qeth_l3_set_rx_csum(card, on);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003243}
3244
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003245static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003246 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003247 .get_strings = qeth_core_get_strings,
3248 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003249 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003250 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003251 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003252};
3253
3254/*
3255 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3256 * NOARP on the netdevice is no option because it also turns off neighbor
3257 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3258 * arp resolution but we want the hard header (packet socket will work
3259 * e.g. tcpdump)
3260 */
3261static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3262{
3263 n->nud_state = NUD_NOARP;
3264 memcpy(n->ha, "FAKELL", 6);
3265 n->output = n->ops->connected_output;
3266 return 0;
3267}
3268
3269static int
3270qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3271{
3272 if (np->tbl->family == AF_INET)
3273 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3274
3275 return 0;
3276}
3277
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003278static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003279 .ndo_open = qeth_l3_open,
3280 .ndo_stop = qeth_l3_stop,
3281 .ndo_get_stats = qeth_get_stats,
3282 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3283 .ndo_validate_addr = eth_validate_addr,
3284 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3285 .ndo_do_ioctl = qeth_l3_do_ioctl,
3286 .ndo_change_mtu = qeth_change_mtu,
Michał Mirosław6204b472011-04-19 00:43:20 +00003287 .ndo_fix_features = qeth_l3_fix_features,
3288 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003289 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3290 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3291 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3292 .ndo_tx_timeout = qeth_tx_timeout,
3293};
3294
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003295static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3296 .ndo_open = qeth_l3_open,
3297 .ndo_stop = qeth_l3_stop,
3298 .ndo_get_stats = qeth_get_stats,
3299 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3300 .ndo_validate_addr = eth_validate_addr,
3301 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3302 .ndo_do_ioctl = qeth_l3_do_ioctl,
3303 .ndo_change_mtu = qeth_change_mtu,
Michał Mirosław6204b472011-04-19 00:43:20 +00003304 .ndo_fix_features = qeth_l3_fix_features,
3305 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003306 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3307 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3308 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3309 .ndo_tx_timeout = qeth_tx_timeout,
3310 .ndo_neigh_setup = qeth_l3_neigh_setup,
3311};
3312
Frank Blaschka4a71df52008-02-15 09:19:42 +01003313static int qeth_l3_setup_netdev(struct qeth_card *card)
3314{
Ursula Braun5113fec2010-05-16 21:15:14 +00003315 if (card->info.type == QETH_CARD_TYPE_OSD ||
3316 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003317 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3318 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3319#ifdef CONFIG_TR
3320 card->dev = alloc_trdev(0);
3321#endif
3322 if (!card->dev)
3323 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003324 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003325 } else {
3326 card->dev = alloc_etherdev(0);
3327 if (!card->dev)
3328 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003329 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003330
3331 /*IPv6 address autoconfiguration stuff*/
3332 qeth_l3_get_unique_id(card);
3333 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3334 card->dev->dev_id = card->info.unique_id &
3335 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003336 if (!card->info.guestlan) {
3337 card->dev->hw_features = NETIF_F_SG |
3338 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3339 NETIF_F_TSO;
3340 card->dev->features = NETIF_F_RXCSUM;
3341 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003342 }
3343 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3344 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3345 if (!card->dev)
3346 return -ENODEV;
3347 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003348 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003349 qeth_l3_iqd_read_initial_mac(card);
3350 } else
3351 return -ENODEV;
3352
Heiko Carstens509e2562008-07-26 02:24:10 -07003353 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003354 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003355 card->dev->mtu = card->info.initial_mtu;
3356 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3357 card->dev->features |= NETIF_F_HW_VLAN_TX |
3358 NETIF_F_HW_VLAN_RX |
3359 NETIF_F_HW_VLAN_FILTER;
Eric Dumazet86d15cd2009-05-30 23:04:46 -07003360 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003361 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003362
3363 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003364 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003365 return register_netdev(card->dev);
3366}
3367
Frank Blaschka4a71df52008-02-15 09:19:42 +01003368static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3369{
3370 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3371
3372 qeth_l3_create_device_attributes(&gdev->dev);
3373 card->options.layer2 = 0;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003374 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003375 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003376 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003377 card->discipline.output_handler = (qdio_handler_t *)
3378 qeth_qdio_output_handler;
3379 card->discipline.recover = qeth_l3_recover;
3380 return 0;
3381}
3382
3383static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3384{
3385 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3386
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003387 qeth_l3_remove_device_attributes(&cgdev->dev);
3388
Ursula Braunf2148562009-05-19 21:38:37 +00003389 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003390 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3391
Ursula Braun70919e22011-02-26 22:41:36 -08003392 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003393 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003394
3395 if (card->dev) {
3396 unregister_netdev(card->dev);
3397 card->dev = NULL;
3398 }
3399
Ursula Braun70919e22011-02-26 22:41:36 -08003400 qeth_l3_clear_ip_list(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003401 qeth_l3_clear_ipato_list(card);
3402 return;
3403}
3404
3405static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3406{
3407 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3408 int rc = 0;
3409 enum qeth_card_states recover_flag;
3410
3411 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003412 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003413 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003414 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3415 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003416
Frank Blaschka4a71df52008-02-15 09:19:42 +01003417 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003418 rc = qeth_core_hardsetup_card(card);
3419 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003420 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003421 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003422 goto out_remove;
3423 }
3424
3425 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3426
Ursula Braunaa909222009-11-12 00:11:43 +00003427 if (!card->dev && qeth_l3_setup_netdev(card)) {
3428 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003429 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003430 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003431
3432 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003433 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003434 qeth_print_status_message(card);
3435
3436 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003437 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003438
3439 rc = qeth_send_startlan(card);
3440 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003441 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003442 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003443 dev_warn(&card->gdev->dev,
3444 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003445 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003446 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003447 }
Ursula Braunaa909222009-11-12 00:11:43 +00003448 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003449 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003450 } else
3451 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003452
Ursula Braun2b6203b2010-11-26 02:41:19 +00003453contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003454 rc = qeth_l3_setadapter_parms(card);
3455 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003456 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003457 if (!card->options.sniffer) {
3458 rc = qeth_l3_start_ipassists(card);
3459 if (rc)
3460 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003461 rc = qeth_l3_setrouting_v4(card);
3462 if (rc)
3463 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3464 rc = qeth_l3_setrouting_v6(card);
3465 if (rc)
3466 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3467 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003468 netif_tx_disable(card->dev);
3469
3470 rc = qeth_init_qdio_queues(card);
3471 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003472 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003473 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003474 goto out_remove;
3475 }
3476 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003477
3478 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003479 qeth_l3_set_ip_addr_list(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003480 if (card->lan_online)
3481 netif_carrier_on(card->dev);
3482 else
3483 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003484 if (recover_flag == CARD_STATE_RECOVER) {
3485 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003486 __qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003487 else {
3488 rtnl_lock();
3489 dev_open(card->dev);
3490 rtnl_unlock();
3491 }
3492 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003493 }
3494 /* let user_space know that device is online */
3495 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003496 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003497 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003498 return 0;
3499out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003500 qeth_l3_stop_card(card, 0);
3501 ccw_device_set_offline(CARD_DDEV(card));
3502 ccw_device_set_offline(CARD_WDEV(card));
3503 ccw_device_set_offline(CARD_RDEV(card));
3504 if (recover_flag == CARD_STATE_RECOVER)
3505 card->state = CARD_STATE_RECOVER;
3506 else
3507 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003508 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003509 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003510 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003511}
3512
3513static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3514{
3515 return __qeth_l3_set_online(gdev, 0);
3516}
3517
3518static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3519 int recovery_mode)
3520{
3521 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3522 int rc = 0, rc2 = 0, rc3 = 0;
3523 enum qeth_card_states recover_flag;
3524
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003525 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003526 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003527 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3528 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003529
3530 if (card->dev && netif_carrier_ok(card->dev))
3531 netif_carrier_off(card->dev);
3532 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02003533 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003534 rc = ccw_device_set_offline(CARD_DDEV(card));
3535 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3536 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3537 if (!rc)
3538 rc = (rc2) ? rc2 : rc3;
3539 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003540 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003541 if (recover_flag == CARD_STATE_UP)
3542 card->state = CARD_STATE_RECOVER;
3543 /* let user_space know that device is offline */
3544 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003545 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003546 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003547 return 0;
3548}
3549
3550static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3551{
3552 return __qeth_l3_set_offline(cgdev, 0);
3553}
3554
3555static int qeth_l3_recover(void *ptr)
3556{
3557 struct qeth_card *card;
3558 int rc = 0;
3559
3560 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003561 QETH_CARD_TEXT(card, 2, "recover1");
3562 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003563 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3564 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003565 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003566 dev_warn(&card->gdev->dev,
3567 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003568 __qeth_l3_set_offline(card->gdev, 1);
3569 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003570 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003571 dev_info(&card->gdev->dev,
3572 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003573 else {
3574 rtnl_lock();
3575 dev_close(card->dev);
3576 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003577 dev_warn(&card->gdev->dev, "The qeth device driver "
3578 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003579 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003580 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3581 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003582 return 0;
3583}
3584
3585static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3586{
3587 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003588 qeth_qdio_clear_card(card, 0);
3589 qeth_clear_qdio_buffers(card);
3590}
3591
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003592static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3593{
3594 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3595
3596 if (card->dev)
3597 netif_device_detach(card->dev);
3598 qeth_set_allowed_threads(card, 0, 1);
3599 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3600 if (gdev->state == CCWGROUP_OFFLINE)
3601 return 0;
3602 if (card->state == CARD_STATE_UP) {
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003603 __qeth_l3_set_offline(card->gdev, 1);
3604 } else
3605 __qeth_l3_set_offline(card->gdev, 0);
3606 return 0;
3607}
3608
3609static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3610{
3611 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3612 int rc = 0;
3613
3614 if (gdev->state == CCWGROUP_OFFLINE)
3615 goto out;
3616
3617 if (card->state == CARD_STATE_RECOVER) {
3618 rc = __qeth_l3_set_online(card->gdev, 1);
3619 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003620 rtnl_lock();
3621 dev_close(card->dev);
3622 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003623 }
3624 } else
3625 rc = __qeth_l3_set_online(card->gdev, 0);
3626out:
3627 qeth_set_allowed_threads(card, 0xffffffff, 0);
3628 if (card->dev)
3629 netif_device_attach(card->dev);
3630 if (rc)
3631 dev_warn(&card->gdev->dev, "The qeth device driver "
3632 "failed to recover an error on the device\n");
3633 return rc;
3634}
3635
Frank Blaschka4a71df52008-02-15 09:19:42 +01003636struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3637 .probe = qeth_l3_probe_device,
3638 .remove = qeth_l3_remove_device,
3639 .set_online = qeth_l3_set_online,
3640 .set_offline = qeth_l3_set_offline,
3641 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003642 .freeze = qeth_l3_pm_suspend,
3643 .thaw = qeth_l3_pm_resume,
3644 .restore = qeth_l3_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003645};
3646EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3647
3648static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003649 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003650{
3651 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3652 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3653 struct qeth_ipaddr *addr;
3654 struct qeth_card *card;
3655
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003656 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003657 return NOTIFY_DONE;
3658
Frank Blaschka4a71df52008-02-15 09:19:42 +01003659 card = qeth_l3_get_card_from_dev(dev);
Carsten Otte847a50f2010-06-21 22:57:05 +00003660 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003661 if (!card)
3662 return NOTIFY_DONE;
3663
3664 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3665 if (addr != NULL) {
3666 addr->u.a4.addr = ifa->ifa_address;
3667 addr->u.a4.mask = ifa->ifa_mask;
3668 addr->type = QETH_IP_TYPE_NORMAL;
3669 } else
3670 goto out;
3671
3672 switch (event) {
3673 case NETDEV_UP:
3674 if (!qeth_l3_add_ip(card, addr))
3675 kfree(addr);
3676 break;
3677 case NETDEV_DOWN:
3678 if (!qeth_l3_delete_ip(card, addr))
3679 kfree(addr);
3680 break;
3681 default:
3682 break;
3683 }
3684 qeth_l3_set_ip_addr_list(card);
3685out:
3686 return NOTIFY_DONE;
3687}
3688
3689static struct notifier_block qeth_l3_ip_notifier = {
3690 qeth_l3_ip_event,
3691 NULL,
3692};
3693
3694#ifdef CONFIG_QETH_IPV6
3695/**
3696 * IPv6 event handler
3697 */
3698static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003699 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003700{
3701 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3702 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3703 struct qeth_ipaddr *addr;
3704 struct qeth_card *card;
3705
Frank Blaschka4a71df52008-02-15 09:19:42 +01003706
3707 card = qeth_l3_get_card_from_dev(dev);
3708 if (!card)
3709 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003710 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003711 if (!qeth_is_supported(card, IPA_IPV6))
3712 return NOTIFY_DONE;
3713
3714 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3715 if (addr != NULL) {
3716 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3717 addr->u.a6.pfxlen = ifa->prefix_len;
3718 addr->type = QETH_IP_TYPE_NORMAL;
3719 } else
3720 goto out;
3721
3722 switch (event) {
3723 case NETDEV_UP:
3724 if (!qeth_l3_add_ip(card, addr))
3725 kfree(addr);
3726 break;
3727 case NETDEV_DOWN:
3728 if (!qeth_l3_delete_ip(card, addr))
3729 kfree(addr);
3730 break;
3731 default:
3732 break;
3733 }
3734 qeth_l3_set_ip_addr_list(card);
3735out:
3736 return NOTIFY_DONE;
3737}
3738
3739static struct notifier_block qeth_l3_ip6_notifier = {
3740 qeth_l3_ip6_event,
3741 NULL,
3742};
3743#endif
3744
3745static int qeth_l3_register_notifiers(void)
3746{
3747 int rc;
3748
Carsten Otte847a50f2010-06-21 22:57:05 +00003749 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003750 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3751 if (rc)
3752 return rc;
3753#ifdef CONFIG_QETH_IPV6
3754 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3755 if (rc) {
3756 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3757 return rc;
3758 }
3759#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003760 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003761#endif
3762 return 0;
3763}
3764
3765static void qeth_l3_unregister_notifiers(void)
3766{
3767
Carsten Otte847a50f2010-06-21 22:57:05 +00003768 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003769 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3770#ifdef CONFIG_QETH_IPV6
3771 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3772#endif /* QETH_IPV6 */
3773}
3774
3775static int __init qeth_l3_init(void)
3776{
3777 int rc = 0;
3778
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003779 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003780 rc = qeth_l3_register_notifiers();
3781 return rc;
3782}
3783
3784static void __exit qeth_l3_exit(void)
3785{
3786 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003787 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003788}
3789
3790module_init(qeth_l3_init);
3791module_exit(qeth_l3_exit);
3792MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3793MODULE_DESCRIPTION("qeth layer 3 discipline");
3794MODULE_LICENSE("GPL");