blob: e4c1176ee25b2fd9942cfad447826611bbc7037f [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>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000016#include <linux/bitops.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010017#include <linux/string.h>
18#include <linux/errno.h>
19#include <linux/kernel.h>
20#include <linux/etherdevice.h>
21#include <linux/mii.h>
22#include <linux/ip.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000023#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010024#include <linux/inetdevice.h>
25#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000027#include <linux/if_vlan.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010028
29#include <net/ip.h>
30#include <net/arp.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000031#include <net/ip6_checksum.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000032#include <net/iucv/af_iucv.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010033
Frank Blaschka4a71df52008-02-15 09:19:42 +010034#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010035
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000036
Frank Blaschka4a71df52008-02-15 09:19:42 +010037static int qeth_l3_set_offline(struct ccwgroup_device *);
38static int qeth_l3_recover(void *);
39static int qeth_l3_stop(struct net_device *);
40static void qeth_l3_set_multicast_list(struct net_device *);
41static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
42static int qeth_l3_register_addr_entry(struct qeth_card *,
43 struct qeth_ipaddr *);
44static int qeth_l3_deregister_addr_entry(struct qeth_card *,
45 struct qeth_ipaddr *);
46static int __qeth_l3_set_online(struct ccwgroup_device *, int);
47static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
48
Frank Blaschka4a71df52008-02-15 09:19:42 +010049static int qeth_l3_isxdigit(char *buf)
50{
51 while (*buf) {
52 if (!isxdigit(*buf++))
53 return 0;
54 }
55 return 1;
56}
57
58void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
59{
60 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
61}
62
63int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
64{
65 int count = 0, rc = 0;
66 int in[4];
67 char c;
68
69 rc = sscanf(buf, "%u.%u.%u.%u%c",
70 &in[0], &in[1], &in[2], &in[3], &c);
71 if (rc != 4 && (rc != 5 || c != '\n'))
72 return -EINVAL;
73 for (count = 0; count < 4; count++) {
74 if (in[count] > 255)
75 return -EINVAL;
76 addr[count] = in[count];
77 }
78 return 0;
79}
80
81void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
82{
Joe Perches963a9fd2010-09-07 21:14:40 +000083 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010084}
85
86int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
87{
88 const char *end, *end_tmp, *start;
89 __u16 *in;
90 char num[5];
91 int num2, cnt, out, found, save_cnt;
92 unsigned short in_tmp[8] = {0, };
93
94 cnt = out = found = save_cnt = num2 = 0;
95 end = start = buf;
96 in = (__u16 *) addr;
97 memset(in, 0, 16);
98 while (*end) {
99 end = strchr(start, ':');
100 if (end == NULL) {
101 end = buf + strlen(buf);
102 end_tmp = strchr(start, '\n');
103 if (end_tmp != NULL)
104 end = end_tmp;
105 out = 1;
106 }
107 if ((end - start)) {
108 memset(num, 0, 5);
109 if ((end - start) > 4)
110 return -EINVAL;
111 memcpy(num, start, end - start);
112 if (!qeth_l3_isxdigit(num))
113 return -EINVAL;
114 sscanf(start, "%x", &num2);
115 if (found)
116 in_tmp[save_cnt++] = num2;
117 else
118 in[cnt++] = num2;
119 if (out)
120 break;
121 } else {
122 if (found)
123 return -EINVAL;
124 found = 1;
125 }
126 start = ++end;
127 }
128 if (cnt + save_cnt > 8)
129 return -EINVAL;
130 cnt = 7;
131 while (save_cnt)
132 in[cnt--] = in_tmp[--save_cnt];
133 return 0;
134}
135
136void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
137 char *buf)
138{
139 if (proto == QETH_PROT_IPV4)
140 qeth_l3_ipaddr4_to_string(addr, buf);
141 else if (proto == QETH_PROT_IPV6)
142 qeth_l3_ipaddr6_to_string(addr, buf);
143}
144
145int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
146 __u8 *addr)
147{
148 if (proto == QETH_PROT_IPV4)
149 return qeth_l3_string_to_ipaddr4(buf, addr);
150 else if (proto == QETH_PROT_IPV6)
151 return qeth_l3_string_to_ipaddr6(buf, addr);
152 else
153 return -EINVAL;
154}
155
156static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
157{
158 int i, j;
159 u8 octet;
160
161 for (i = 0; i < len; ++i) {
162 octet = addr[i];
163 for (j = 7; j >= 0; --j) {
164 bits[i*8 + j] = octet & 1;
165 octet >>= 1;
166 }
167 }
168}
169
Klaus-Dieter Wacker62982632010-07-22 23:15:03 +0000170int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100171 struct qeth_ipaddr *addr)
172{
173 struct qeth_ipato_entry *ipatoe;
174 u8 addr_bits[128] = {0, };
175 u8 ipatoe_bits[128] = {0, };
176 int rc = 0;
177
178 if (!card->ipato.enabled)
179 return 0;
180
181 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
182 (addr->proto == QETH_PROT_IPV4)? 4:16);
183 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
184 if (addr->proto != ipatoe->proto)
185 continue;
186 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
187 (ipatoe->proto == QETH_PROT_IPV4) ?
188 4 : 16);
189 if (addr->proto == QETH_PROT_IPV4)
190 rc = !memcmp(addr_bits, ipatoe_bits,
191 min(32, ipatoe->mask_bits));
192 else
193 rc = !memcmp(addr_bits, ipatoe_bits,
194 min(128, ipatoe->mask_bits));
195 if (rc)
196 break;
197 }
198 /* invert? */
199 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
200 rc = !rc;
201 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
202 rc = !rc;
203
204 return rc;
205}
206
207/*
208 * Add IP to be added to todo list. If there is already an "add todo"
209 * in this list we just incremenent the reference count.
210 * Returns 0 if we just incremented reference count.
211 */
212static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
213 struct qeth_ipaddr *addr, int add)
214{
215 struct qeth_ipaddr *tmp, *t;
216 int found = 0;
217
Ursula Braun76b11f82010-01-11 02:50:50 +0000218 if (card->options.sniffer)
219 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100220 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
221 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
222 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
223 return 0;
224 if ((tmp->proto == QETH_PROT_IPV4) &&
225 (addr->proto == QETH_PROT_IPV4) &&
226 (tmp->type == addr->type) &&
227 (tmp->is_multicast == addr->is_multicast) &&
228 (tmp->u.a4.addr == addr->u.a4.addr) &&
229 (tmp->u.a4.mask == addr->u.a4.mask)) {
230 found = 1;
231 break;
232 }
233 if ((tmp->proto == QETH_PROT_IPV6) &&
234 (addr->proto == QETH_PROT_IPV6) &&
235 (tmp->type == addr->type) &&
236 (tmp->is_multicast == addr->is_multicast) &&
237 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
238 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
239 sizeof(struct in6_addr)) == 0)) {
240 found = 1;
241 break;
242 }
243 }
244 if (found) {
245 if (addr->users != 0)
246 tmp->users += addr->users;
247 else
248 tmp->users += add ? 1 : -1;
249 if (tmp->users == 0) {
250 list_del(&tmp->entry);
251 kfree(tmp);
252 }
253 return 0;
254 } else {
255 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
256 list_add(&addr->entry, card->ip_tbd_list);
257 else {
258 if (addr->users == 0)
259 addr->users += add ? 1 : -1;
260 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
261 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000262 QETH_CARD_TEXT(card, 2, "tkovaddr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100263 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
264 }
265 list_add_tail(&addr->entry, card->ip_tbd_list);
266 }
267 return 1;
268 }
269}
270
Frank Blaschkab3332932011-08-08 01:33:59 +0000271int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100272{
273 unsigned long flags;
274 int rc = 0;
275
Carsten Otte847a50f2010-06-21 22:57:05 +0000276 QETH_CARD_TEXT(card, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277
278 if (addr->proto == QETH_PROT_IPV4)
Carsten Otte847a50f2010-06-21 22:57:05 +0000279 QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100280 else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000281 QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
282 QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100283 }
284 spin_lock_irqsave(&card->ip_lock, flags);
285 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
286 spin_unlock_irqrestore(&card->ip_lock, flags);
287 return rc;
288}
289
Frank Blaschkab3332932011-08-08 01:33:59 +0000290int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100291{
292 unsigned long flags;
293 int rc = 0;
294
Carsten Otte847a50f2010-06-21 22:57:05 +0000295 QETH_CARD_TEXT(card, 4, "addip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100296 if (addr->proto == QETH_PROT_IPV4)
Carsten Otte847a50f2010-06-21 22:57:05 +0000297 QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100298 else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000299 QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
300 QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301 }
302 spin_lock_irqsave(&card->ip_lock, flags);
303 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
304 spin_unlock_irqrestore(&card->ip_lock, flags);
305 return rc;
306}
307
308
Frank Blaschkab3332932011-08-08 01:33:59 +0000309struct qeth_ipaddr *qeth_l3_get_addr_buffer(
Frank Blaschka4a71df52008-02-15 09:19:42 +0100310 enum qeth_prot_versions prot)
311{
312 struct qeth_ipaddr *addr;
313
314 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
315 if (addr == NULL) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100316 return NULL;
317 }
318 addr->type = QETH_IP_TYPE_NORMAL;
319 addr->proto = prot;
320 return addr;
321}
322
323static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
324{
325 struct qeth_ipaddr *iptodo;
326 unsigned long flags;
327
Carsten Otte847a50f2010-06-21 22:57:05 +0000328 QETH_CARD_TEXT(card, 4, "delmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
330 if (!iptodo) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000331 QETH_CARD_TEXT(card, 2, "dmcnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100332 return;
333 }
334 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
335 spin_lock_irqsave(&card->ip_lock, flags);
336 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
337 kfree(iptodo);
338 spin_unlock_irqrestore(&card->ip_lock, flags);
339}
340
341/*
342 * Add/remove address to/from card's ip list, i.e. try to add or remove
343 * reference to/from an IP address that is already registered on the card.
344 * Returns:
345 * 0 address was on card and its reference count has been adjusted,
346 * but is still > 0, so nothing has to be done
347 * also returns 0 if card was not on card and the todo was to delete
348 * the address -> there is also nothing to be done
349 * 1 address was not on card and the todo is to add it to the card's ip
350 * list
351 * -1 address was on card and its reference count has been decremented
352 * to <= 0 by the todo -> address must be removed from card
353 */
354static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
355 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
356{
357 struct qeth_ipaddr *addr;
358 int found = 0;
359
360 list_for_each_entry(addr, &card->ip_list, entry) {
361 if ((addr->proto == QETH_PROT_IPV4) &&
362 (todo->proto == QETH_PROT_IPV4) &&
363 (addr->type == todo->type) &&
364 (addr->u.a4.addr == todo->u.a4.addr) &&
365 (addr->u.a4.mask == todo->u.a4.mask)) {
366 found = 1;
367 break;
368 }
369 if ((addr->proto == QETH_PROT_IPV6) &&
370 (todo->proto == QETH_PROT_IPV6) &&
371 (addr->type == todo->type) &&
372 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
373 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
374 sizeof(struct in6_addr)) == 0)) {
375 found = 1;
376 break;
377 }
378 }
379 if (found) {
380 addr->users += todo->users;
381 if (addr->users <= 0) {
382 *__addr = addr;
383 return -1;
384 } else {
385 /* for VIPA and RXIP limit refcount to 1 */
386 if (addr->type != QETH_IP_TYPE_NORMAL)
387 addr->users = 1;
388 return 0;
389 }
390 }
391 if (todo->users > 0) {
392 /* for VIPA and RXIP limit refcount to 1 */
393 if (todo->type != QETH_IP_TYPE_NORMAL)
394 todo->users = 1;
395 return 1;
396 } else
397 return 0;
398}
399
400static void __qeth_l3_delete_all_mc(struct qeth_card *card,
401 unsigned long *flags)
402{
Ursula Braun2d921c32008-04-01 10:26:53 +0200403 struct list_head fail_list;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100404 struct qeth_ipaddr *addr, *tmp;
405 int rc;
Ursula Braun2d921c32008-04-01 10:26:53 +0200406
407 INIT_LIST_HEAD(&fail_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100408again:
409 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
410 if (addr->is_multicast) {
411 list_del(&addr->entry);
412 spin_unlock_irqrestore(&card->ip_lock, *flags);
413 rc = qeth_l3_deregister_addr_entry(card, addr);
414 spin_lock_irqsave(&card->ip_lock, *flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200415 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100416 kfree(addr);
Ursula Braun2d921c32008-04-01 10:26:53 +0200417 else
418 list_add_tail(&addr->entry, &fail_list);
419 goto again;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100420 }
421 }
Ursula Braun2d921c32008-04-01 10:26:53 +0200422 list_splice(&fail_list, &card->ip_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100423}
424
Frank Blaschkab3332932011-08-08 01:33:59 +0000425void qeth_l3_set_ip_addr_list(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100426{
427 struct list_head *tbd_list;
428 struct qeth_ipaddr *todo, *addr;
429 unsigned long flags;
430 int rc;
431
Carsten Otte847a50f2010-06-21 22:57:05 +0000432 QETH_CARD_TEXT(card, 2, "sdiplist");
433 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100434
Einar Lueckf154b792010-12-08 02:57:59 +0000435 if ((card->state != CARD_STATE_UP &&
436 card->state != CARD_STATE_SOFTSETUP) || card->options.sniffer) {
Ursula Braun76b11f82010-01-11 02:50:50 +0000437 return;
Einar Lueckf154b792010-12-08 02:57:59 +0000438 }
439
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 spin_lock_irqsave(&card->ip_lock, flags);
441 tbd_list = card->ip_tbd_list;
Frank Blaschkab3332932011-08-08 01:33:59 +0000442 card->ip_tbd_list = kzalloc(sizeof(struct list_head), GFP_ATOMIC);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443 if (!card->ip_tbd_list) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000444 QETH_CARD_TEXT(card, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100445 card->ip_tbd_list = tbd_list;
446 spin_unlock_irqrestore(&card->ip_lock, flags);
447 return;
448 } else
449 INIT_LIST_HEAD(card->ip_tbd_list);
450
451 while (!list_empty(tbd_list)) {
452 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
453 list_del(&todo->entry);
454 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
455 __qeth_l3_delete_all_mc(card, &flags);
456 kfree(todo);
457 continue;
458 }
459 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
460 if (rc == 0) {
461 /* nothing to be done; only adjusted refcount */
462 kfree(todo);
463 } else if (rc == 1) {
464 /* new entry to be added to on-card list */
465 spin_unlock_irqrestore(&card->ip_lock, flags);
466 rc = qeth_l3_register_addr_entry(card, todo);
467 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200468 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100469 list_add_tail(&todo->entry, &card->ip_list);
470 else
471 kfree(todo);
472 } else if (rc == -1) {
473 /* on-card entry to be removed */
474 list_del_init(&addr->entry);
475 spin_unlock_irqrestore(&card->ip_lock, flags);
476 rc = qeth_l3_deregister_addr_entry(card, addr);
477 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun76b11f82010-01-11 02:50:50 +0000478 if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100479 kfree(addr);
480 else
481 list_add_tail(&addr->entry, &card->ip_list);
482 kfree(todo);
483 }
484 }
485 spin_unlock_irqrestore(&card->ip_lock, flags);
486 kfree(tbd_list);
487}
488
Ursula Braun70919e22011-02-26 22:41:36 -0800489static void qeth_l3_clear_ip_list(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100490{
491 struct qeth_ipaddr *addr, *tmp;
492 unsigned long flags;
493
Carsten Otte847a50f2010-06-21 22:57:05 +0000494 QETH_CARD_TEXT(card, 4, "clearip");
Ursula Braun76b11f82010-01-11 02:50:50 +0000495 if (recover && card->options.sniffer)
496 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100497 spin_lock_irqsave(&card->ip_lock, flags);
498 /* clear todo list */
499 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
500 list_del(&addr->entry);
501 kfree(addr);
502 }
503
504 while (!list_empty(&card->ip_list)) {
505 addr = list_entry(card->ip_list.next,
506 struct qeth_ipaddr, entry);
507 list_del_init(&addr->entry);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100508 if (!recover || addr->is_multicast) {
509 kfree(addr);
510 continue;
511 }
512 list_add_tail(&addr->entry, card->ip_tbd_list);
513 }
514 spin_unlock_irqrestore(&card->ip_lock, flags);
515}
516
517static int qeth_l3_address_exists_in_list(struct list_head *list,
518 struct qeth_ipaddr *addr, int same_type)
519{
520 struct qeth_ipaddr *tmp;
521
522 list_for_each_entry(tmp, list, entry) {
523 if ((tmp->proto == QETH_PROT_IPV4) &&
524 (addr->proto == QETH_PROT_IPV4) &&
525 ((same_type && (tmp->type == addr->type)) ||
526 (!same_type && (tmp->type != addr->type))) &&
527 (tmp->u.a4.addr == addr->u.a4.addr))
528 return 1;
529
530 if ((tmp->proto == QETH_PROT_IPV6) &&
531 (addr->proto == QETH_PROT_IPV6) &&
532 ((same_type && (tmp->type == addr->type)) ||
533 (!same_type && (tmp->type != addr->type))) &&
534 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
535 sizeof(struct in6_addr)) == 0))
536 return 1;
537
538 }
539 return 0;
540}
541
542static int qeth_l3_send_setdelmc(struct qeth_card *card,
543 struct qeth_ipaddr *addr, int ipacmd)
544{
545 int rc;
546 struct qeth_cmd_buffer *iob;
547 struct qeth_ipa_cmd *cmd;
548
Carsten Otte847a50f2010-06-21 22:57:05 +0000549 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100550
551 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
552 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
553 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
554 if (addr->proto == QETH_PROT_IPV6)
555 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
556 sizeof(struct in6_addr));
557 else
558 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
559
560 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
561
562 return rc;
563}
564
565static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
566{
567 int i, j;
568 for (i = 0; i < 16; i++) {
569 j = (len) - (i * 8);
570 if (j >= 8)
571 netmask[i] = 0xff;
572 else if (j > 0)
573 netmask[i] = (u8)(0xFF00 >> j);
574 else
575 netmask[i] = 0;
576 }
577}
578
579static int qeth_l3_send_setdelip(struct qeth_card *card,
580 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
581{
582 int rc;
583 struct qeth_cmd_buffer *iob;
584 struct qeth_ipa_cmd *cmd;
585 __u8 netmask[16];
586
Carsten Otte847a50f2010-06-21 22:57:05 +0000587 QETH_CARD_TEXT(card, 4, "setdelip");
588 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100589
590 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
591 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
592 if (addr->proto == QETH_PROT_IPV6) {
593 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
594 sizeof(struct in6_addr));
595 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
596 memcpy(cmd->data.setdelip6.mask, netmask,
597 sizeof(struct in6_addr));
598 cmd->data.setdelip6.flags = flags;
599 } else {
600 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
601 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
602 cmd->data.setdelip4.flags = flags;
603 }
604
605 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
606
607 return rc;
608}
609
610static int qeth_l3_send_setrouting(struct qeth_card *card,
611 enum qeth_routing_types type, enum qeth_prot_versions prot)
612{
613 int rc;
614 struct qeth_ipa_cmd *cmd;
615 struct qeth_cmd_buffer *iob;
616
Carsten Otte847a50f2010-06-21 22:57:05 +0000617 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100618 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
619 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
620 cmd->data.setrtg.type = (type);
621 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
622
623 return rc;
624}
625
626static void qeth_l3_correct_routing_type(struct qeth_card *card,
627 enum qeth_routing_types *type, enum qeth_prot_versions prot)
628{
629 if (card->info.type == QETH_CARD_TYPE_IQD) {
630 switch (*type) {
631 case NO_ROUTER:
632 case PRIMARY_CONNECTOR:
633 case SECONDARY_CONNECTOR:
634 case MULTICAST_ROUTER:
635 return;
636 default:
637 goto out_inval;
638 }
639 } else {
640 switch (*type) {
641 case NO_ROUTER:
642 case PRIMARY_ROUTER:
643 case SECONDARY_ROUTER:
644 return;
645 case MULTICAST_ROUTER:
646 if (qeth_is_ipafunc_supported(card, prot,
647 IPA_OSA_MC_ROUTER))
648 return;
649 default:
650 goto out_inval;
651 }
652 }
653out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654 *type = NO_ROUTER;
655}
656
657int qeth_l3_setrouting_v4(struct qeth_card *card)
658{
659 int rc;
660
Carsten Otte847a50f2010-06-21 22:57:05 +0000661 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100662
663 qeth_l3_correct_routing_type(card, &card->options.route4.type,
664 QETH_PROT_IPV4);
665
666 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
667 QETH_PROT_IPV4);
668 if (rc) {
669 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200670 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
671 " on %s. Type set to 'no router'.\n", rc,
672 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100673 }
674 return rc;
675}
676
677int qeth_l3_setrouting_v6(struct qeth_card *card)
678{
679 int rc = 0;
680
Carsten Otte847a50f2010-06-21 22:57:05 +0000681 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682#ifdef CONFIG_QETH_IPV6
683
684 if (!qeth_is_supported(card, IPA_IPV6))
685 return 0;
686 qeth_l3_correct_routing_type(card, &card->options.route6.type,
687 QETH_PROT_IPV6);
688
689 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
690 QETH_PROT_IPV6);
691 if (rc) {
692 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200693 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
694 " on %s. Type set to 'no router'.\n", rc,
695 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100696 }
697#endif
698 return rc;
699}
700
701/*
702 * IP address takeover related functions
703 */
704static void qeth_l3_clear_ipato_list(struct qeth_card *card)
705{
706
707 struct qeth_ipato_entry *ipatoe, *tmp;
708 unsigned long flags;
709
710 spin_lock_irqsave(&card->ip_lock, flags);
711 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
712 list_del(&ipatoe->entry);
713 kfree(ipatoe);
714 }
715 spin_unlock_irqrestore(&card->ip_lock, flags);
716}
717
718int qeth_l3_add_ipato_entry(struct qeth_card *card,
719 struct qeth_ipato_entry *new)
720{
721 struct qeth_ipato_entry *ipatoe;
722 unsigned long flags;
723 int rc = 0;
724
Carsten Otte847a50f2010-06-21 22:57:05 +0000725 QETH_CARD_TEXT(card, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100726 spin_lock_irqsave(&card->ip_lock, flags);
727 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
728 if (ipatoe->proto != new->proto)
729 continue;
730 if (!memcmp(ipatoe->addr, new->addr,
731 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
732 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100733 rc = -EEXIST;
734 break;
735 }
736 }
737 if (!rc)
738 list_add_tail(&new->entry, &card->ipato.entries);
739
740 spin_unlock_irqrestore(&card->ip_lock, flags);
741 return rc;
742}
743
744void qeth_l3_del_ipato_entry(struct qeth_card *card,
745 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
746{
747 struct qeth_ipato_entry *ipatoe, *tmp;
748 unsigned long flags;
749
Carsten Otte847a50f2010-06-21 22:57:05 +0000750 QETH_CARD_TEXT(card, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 spin_lock_irqsave(&card->ip_lock, flags);
752 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
753 if (ipatoe->proto != proto)
754 continue;
755 if (!memcmp(ipatoe->addr, addr,
756 (proto == QETH_PROT_IPV4)? 4:16) &&
757 (ipatoe->mask_bits == mask_bits)) {
758 list_del(&ipatoe->entry);
759 kfree(ipatoe);
760 }
761 }
762 spin_unlock_irqrestore(&card->ip_lock, flags);
763}
764
765/*
766 * VIPA related functions
767 */
768int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
769 const u8 *addr)
770{
771 struct qeth_ipaddr *ipaddr;
772 unsigned long flags;
773 int rc = 0;
774
775 ipaddr = qeth_l3_get_addr_buffer(proto);
776 if (ipaddr) {
777 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000778 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779 memcpy(&ipaddr->u.a4.addr, addr, 4);
780 ipaddr->u.a4.mask = 0;
781 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000782 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100783 memcpy(&ipaddr->u.a6.addr, addr, 16);
784 ipaddr->u.a6.pfxlen = 0;
785 }
786 ipaddr->type = QETH_IP_TYPE_VIPA;
787 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
788 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
789 } else
790 return -ENOMEM;
791 spin_lock_irqsave(&card->ip_lock, flags);
792 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
793 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
794 rc = -EEXIST;
795 spin_unlock_irqrestore(&card->ip_lock, flags);
796 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100797 return rc;
798 }
799 if (!qeth_l3_add_ip(card, ipaddr))
800 kfree(ipaddr);
801 qeth_l3_set_ip_addr_list(card);
802 return rc;
803}
804
805void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
806 const u8 *addr)
807{
808 struct qeth_ipaddr *ipaddr;
809
810 ipaddr = qeth_l3_get_addr_buffer(proto);
811 if (ipaddr) {
812 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000813 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100814 memcpy(&ipaddr->u.a4.addr, addr, 4);
815 ipaddr->u.a4.mask = 0;
816 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000817 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100818 memcpy(&ipaddr->u.a6.addr, addr, 16);
819 ipaddr->u.a6.pfxlen = 0;
820 }
821 ipaddr->type = QETH_IP_TYPE_VIPA;
822 } else
823 return;
824 if (!qeth_l3_delete_ip(card, ipaddr))
825 kfree(ipaddr);
826 qeth_l3_set_ip_addr_list(card);
827}
828
829/*
830 * proxy ARP related functions
831 */
832int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
833 const u8 *addr)
834{
835 struct qeth_ipaddr *ipaddr;
836 unsigned long flags;
837 int rc = 0;
838
839 ipaddr = qeth_l3_get_addr_buffer(proto);
840 if (ipaddr) {
841 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000842 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 memcpy(&ipaddr->u.a4.addr, addr, 4);
844 ipaddr->u.a4.mask = 0;
845 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000846 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100847 memcpy(&ipaddr->u.a6.addr, addr, 16);
848 ipaddr->u.a6.pfxlen = 0;
849 }
850 ipaddr->type = QETH_IP_TYPE_RXIP;
851 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
852 ipaddr->del_flags = 0;
853 } else
854 return -ENOMEM;
855 spin_lock_irqsave(&card->ip_lock, flags);
856 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
857 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
858 rc = -EEXIST;
859 spin_unlock_irqrestore(&card->ip_lock, flags);
860 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100861 return rc;
862 }
863 if (!qeth_l3_add_ip(card, ipaddr))
864 kfree(ipaddr);
865 qeth_l3_set_ip_addr_list(card);
866 return 0;
867}
868
869void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
870 const u8 *addr)
871{
872 struct qeth_ipaddr *ipaddr;
873
874 ipaddr = qeth_l3_get_addr_buffer(proto);
875 if (ipaddr) {
876 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000877 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100878 memcpy(&ipaddr->u.a4.addr, addr, 4);
879 ipaddr->u.a4.mask = 0;
880 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000881 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100882 memcpy(&ipaddr->u.a6.addr, addr, 16);
883 ipaddr->u.a6.pfxlen = 0;
884 }
885 ipaddr->type = QETH_IP_TYPE_RXIP;
886 } else
887 return;
888 if (!qeth_l3_delete_ip(card, ipaddr))
889 kfree(ipaddr);
890 qeth_l3_set_ip_addr_list(card);
891}
892
893static int qeth_l3_register_addr_entry(struct qeth_card *card,
894 struct qeth_ipaddr *addr)
895{
896 char buf[50];
897 int rc = 0;
898 int cnt = 3;
899
900 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000901 QETH_CARD_TEXT(card, 2, "setaddr4");
902 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100903 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000904 QETH_CARD_TEXT(card, 2, "setaddr6");
905 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
906 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000908 QETH_CARD_TEXT(card, 2, "setaddr?");
909 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 }
911 do {
912 if (addr->is_multicast)
913 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
914 else
915 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
916 addr->set_flags);
917 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000918 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 } while ((--cnt > 0) && rc);
920 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000921 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100922 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100923 dev_warn(&card->gdev->dev,
924 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100925 }
926 return rc;
927}
928
929static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
930 struct qeth_ipaddr *addr)
931{
932 int rc = 0;
933
934 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000935 QETH_CARD_TEXT(card, 2, "deladdr4");
936 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000938 QETH_CARD_TEXT(card, 2, "deladdr6");
939 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
940 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000942 QETH_CARD_TEXT(card, 2, "deladdr?");
943 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944 }
945 if (addr->is_multicast)
946 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
947 else
948 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
949 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200950 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000951 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952
953 return rc;
954}
955
956static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
957{
958 if (cast_type == RTN_MULTICAST)
959 return QETH_CAST_MULTICAST;
960 if (cast_type == RTN_BROADCAST)
961 return QETH_CAST_BROADCAST;
962 return QETH_CAST_UNICAST;
963}
964
965static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
966{
967 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
968 if (cast_type == RTN_MULTICAST)
969 return ct | QETH_CAST_MULTICAST;
970 if (cast_type == RTN_ANYCAST)
971 return ct | QETH_CAST_ANYCAST;
972 if (cast_type == RTN_BROADCAST)
973 return ct | QETH_CAST_BROADCAST;
974 return ct | QETH_CAST_UNICAST;
975}
976
977static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
978 __u32 mode)
979{
980 int rc;
981 struct qeth_cmd_buffer *iob;
982 struct qeth_ipa_cmd *cmd;
983
Carsten Otte847a50f2010-06-21 22:57:05 +0000984 QETH_CARD_TEXT(card, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100985
986 iob = qeth_get_adapter_cmd(card, command,
987 sizeof(struct qeth_ipacmd_setadpparms));
988 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
989 cmd->data.setadapterparms.data.mode = mode;
990 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
991 NULL);
992 return rc;
993}
994
995static int qeth_l3_setadapter_hstr(struct qeth_card *card)
996{
997 int rc;
998
Carsten Otte847a50f2010-06-21 22:57:05 +0000999 QETH_CARD_TEXT(card, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000
1001 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1002 rc = qeth_l3_send_setadp_mode(card,
1003 IPA_SETADP_SET_BROADCAST_MODE,
1004 card->options.broadcast_mode);
1005 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001006 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007 "device %s: x%x\n",
1008 CARD_BUS_ID(card), rc);
1009 rc = qeth_l3_send_setadp_mode(card,
1010 IPA_SETADP_ALTER_MAC_ADDRESS,
1011 card->options.macaddr_mode);
1012 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001013 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001014 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1015 return rc;
1016 }
1017 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001018 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001019 "to set broadcast mode, using ALLRINGS "
1020 "on device %s:\n", CARD_BUS_ID(card));
1021 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001022 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023 "to set macaddr mode, using NONCANONICAL "
1024 "on device %s:\n", CARD_BUS_ID(card));
1025 return 0;
1026}
1027
1028static int qeth_l3_setadapter_parms(struct qeth_card *card)
1029{
1030 int rc;
1031
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001032 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001033
1034 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001035 dev_info(&card->gdev->dev,
1036 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001037 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001038 return 0;
1039 }
1040 rc = qeth_query_setadapterparms(card);
1041 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001042 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +00001043 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044 return rc;
1045 }
1046 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1047 rc = qeth_setadpparms_change_macaddr(card);
1048 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001049 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001050 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001051 }
1052
1053 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1054 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1055 rc = qeth_l3_setadapter_hstr(card);
1056
1057 return rc;
1058}
1059
1060static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1061 struct qeth_reply *reply, unsigned long data)
1062{
1063 struct qeth_ipa_cmd *cmd;
1064
Carsten Otte847a50f2010-06-21 22:57:05 +00001065 QETH_CARD_TEXT(card, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001066
1067 cmd = (struct qeth_ipa_cmd *) data;
1068 if (cmd->hdr.return_code == 0) {
1069 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1070 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1071 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1072 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1073 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1074 }
1075 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1076 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1077 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001078 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001079 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001080 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1081 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1082 card->info.tx_csum_mask =
1083 cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001084 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001085 }
1086
Frank Blaschka4a71df52008-02-15 09:19:42 +01001087 return 0;
1088}
1089
1090static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1091 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1092 __u16 len, enum qeth_prot_versions prot)
1093{
1094 struct qeth_cmd_buffer *iob;
1095 struct qeth_ipa_cmd *cmd;
1096
Carsten Otte847a50f2010-06-21 22:57:05 +00001097 QETH_CARD_TEXT(card, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001098 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1099
1100 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1101 cmd->data.setassparms.hdr.assist_no = ipa_func;
1102 cmd->data.setassparms.hdr.length = 8 + len;
1103 cmd->data.setassparms.hdr.command_code = cmd_code;
1104 cmd->data.setassparms.hdr.return_code = 0;
1105 cmd->data.setassparms.hdr.seq_no = 0;
1106
1107 return iob;
1108}
1109
1110static int qeth_l3_send_setassparms(struct qeth_card *card,
1111 struct qeth_cmd_buffer *iob, __u16 len, long data,
1112 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1113 unsigned long),
1114 void *reply_param)
1115{
1116 int rc;
1117 struct qeth_ipa_cmd *cmd;
1118
Carsten Otte847a50f2010-06-21 22:57:05 +00001119 QETH_CARD_TEXT(card, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001120
1121 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1122 if (len <= sizeof(__u32))
1123 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1124 else /* (len > sizeof(__u32)) */
1125 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1126
1127 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1128 return rc;
1129}
1130
1131#ifdef CONFIG_QETH_IPV6
1132static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1133 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1134{
1135 int rc;
1136 struct qeth_cmd_buffer *iob;
1137
Carsten Otte847a50f2010-06-21 22:57:05 +00001138 QETH_CARD_TEXT(card, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1140 0, QETH_PROT_IPV6);
1141 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1142 qeth_l3_default_setassparms_cb, NULL);
1143 return rc;
1144}
1145#endif
1146
1147static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1148 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1149{
1150 int rc;
1151 int length = 0;
1152 struct qeth_cmd_buffer *iob;
1153
Carsten Otte847a50f2010-06-21 22:57:05 +00001154 QETH_CARD_TEXT(card, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001155 if (data)
1156 length = sizeof(__u32);
1157 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1158 length, QETH_PROT_IPV4);
1159 rc = qeth_l3_send_setassparms(card, iob, length, data,
1160 qeth_l3_default_setassparms_cb, NULL);
1161 return rc;
1162}
1163
1164static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1165{
1166 int rc;
1167
Carsten Otte847a50f2010-06-21 22:57:05 +00001168 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001169
1170 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001171 dev_info(&card->gdev->dev,
1172 "ARP processing not supported on %s!\n",
1173 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001174 return 0;
1175 }
1176 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1177 IPA_CMD_ASS_START, 0);
1178 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001179 dev_warn(&card->gdev->dev,
1180 "Starting ARP processing support for %s failed\n",
1181 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001182 }
1183 return rc;
1184}
1185
1186static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1187{
1188 int rc;
1189
Carsten Otte847a50f2010-06-21 22:57:05 +00001190 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001191
1192 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001193 dev_info(&card->gdev->dev,
1194 "Hardware IP fragmentation not supported on %s\n",
1195 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001196 return -EOPNOTSUPP;
1197 }
1198
1199 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1200 IPA_CMD_ASS_START, 0);
1201 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001202 dev_warn(&card->gdev->dev,
1203 "Starting IP fragmentation support for %s failed\n",
1204 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001205 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001206 dev_info(&card->gdev->dev,
1207 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001208 return rc;
1209}
1210
1211static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1212{
1213 int rc;
1214
Carsten Otte847a50f2010-06-21 22:57:05 +00001215 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001216
Frank Blaschka4a71df52008-02-15 09:19:42 +01001217 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001218 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001219 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001220 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001221 return -EOPNOTSUPP;
1222 }
1223
1224 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1225 IPA_CMD_ASS_START, 0);
1226 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001227 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001228 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001229 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230 return rc;
1231}
1232
1233static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1234{
1235 int rc = 0;
1236
Carsten Otte847a50f2010-06-21 22:57:05 +00001237 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001238
1239 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001240 dev_info(&card->gdev->dev,
1241 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001242 return -EOPNOTSUPP;
1243 }
1244
1245 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1246 IPA_CMD_ASS_START, 0);
1247 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001248 dev_warn(&card->gdev->dev,
1249 "Starting VLAN support for %s failed\n",
1250 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001251 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001252 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001253 }
1254 return rc;
1255}
1256
1257static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1258{
1259 int rc;
1260
Carsten Otte847a50f2010-06-21 22:57:05 +00001261 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262
1263 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001264 dev_info(&card->gdev->dev,
1265 "Multicast not supported on %s\n",
1266 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001267 return -EOPNOTSUPP;
1268 }
1269
1270 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1271 IPA_CMD_ASS_START, 0);
1272 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001273 dev_warn(&card->gdev->dev,
1274 "Starting multicast support for %s failed\n",
1275 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001276 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001277 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001278 card->dev->flags |= IFF_MULTICAST;
1279 }
1280 return rc;
1281}
1282
Frank Blaschka4a71df52008-02-15 09:19:42 +01001283#ifdef CONFIG_QETH_IPV6
1284static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1285{
1286 int rc;
1287
Carsten Otte847a50f2010-06-21 22:57:05 +00001288 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001289
1290 if (card->info.type == QETH_CARD_TYPE_IQD)
1291 goto out;
1292
Frank Blaschka1da74b12011-05-12 18:45:02 +00001293 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001294 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001295 dev_err(&card->gdev->dev,
1296 "Activating IPv6 support for %s failed\n",
1297 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001298 return rc;
1299 }
1300 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1301 IPA_CMD_ASS_START, 3);
1302 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001303 dev_err(&card->gdev->dev,
1304 "Activating IPv6 support for %s failed\n",
1305 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001306 return rc;
1307 }
1308 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1309 IPA_CMD_ASS_START);
1310 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001311 dev_err(&card->gdev->dev,
1312 "Activating IPv6 support for %s failed\n",
1313 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001314 return rc;
1315 }
1316 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1317 IPA_CMD_ASS_START);
1318 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001319 dev_warn(&card->gdev->dev,
1320 "Enabling the passthrough mode for %s failed\n",
1321 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001322 return rc;
1323 }
1324out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001325 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001326 return 0;
1327}
1328#endif
1329
1330static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1331{
1332 int rc = 0;
1333
Carsten Otte847a50f2010-06-21 22:57:05 +00001334 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335
1336 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001337 dev_info(&card->gdev->dev,
1338 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001339 return 0;
1340 }
1341#ifdef CONFIG_QETH_IPV6
1342 rc = qeth_l3_softsetup_ipv6(card);
1343#endif
1344 return rc ;
1345}
1346
1347static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1348{
1349 int rc;
1350
Carsten Otte847a50f2010-06-21 22:57:05 +00001351 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001352 card->info.broadcast_capable = 0;
1353 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001354 dev_info(&card->gdev->dev,
1355 "Broadcast not supported on %s\n",
1356 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001357 rc = -EOPNOTSUPP;
1358 goto out;
1359 }
1360 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1361 IPA_CMD_ASS_START, 0);
1362 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001363 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1364 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365 goto out;
1366 }
1367
1368 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1369 IPA_CMD_ASS_CONFIGURE, 1);
1370 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001371 dev_warn(&card->gdev->dev,
1372 "Setting up broadcast filtering for %s failed\n",
1373 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001374 goto out;
1375 }
1376 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001377 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001378 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1379 IPA_CMD_ASS_ENABLE, 1);
1380 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001381 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1382 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001383 goto out;
1384 }
1385 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1386out:
1387 if (card->info.broadcast_capable)
1388 card->dev->flags |= IFF_BROADCAST;
1389 else
1390 card->dev->flags &= ~IFF_BROADCAST;
1391 return rc;
1392}
1393
1394static int qeth_l3_send_checksum_command(struct qeth_card *card)
1395{
1396 int rc;
1397
1398 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1399 IPA_CMD_ASS_START, 0);
1400 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001401 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1402 "failed, using SW checksumming\n",
1403 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001404 return rc;
1405 }
1406 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1407 IPA_CMD_ASS_ENABLE,
1408 card->info.csum_mask);
1409 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001410 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1411 "failed, using SW checksumming\n",
1412 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001413 return rc;
1414 }
1415 return 0;
1416}
1417
Martin Schwidefskyc4736d92011-10-30 15:17:11 +01001418static int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001419{
1420 int rc = 0;
1421
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001422 if (on) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001423 rc = qeth_l3_send_checksum_command(card);
1424 if (rc)
1425 return -EIO;
1426 dev_info(&card->gdev->dev,
1427 "HW Checksumming (inbound) enabled\n");
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001428 } else {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001429 rc = qeth_l3_send_simple_setassparms(card,
1430 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1431 if (rc)
1432 return -EIO;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001433 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001434
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001435 return 0;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001436}
1437
Frank Blaschka4a71df52008-02-15 09:19:42 +01001438static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1439{
Carsten Otte847a50f2010-06-21 22:57:05 +00001440 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001441
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001442 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001443 rtnl_lock();
1444 /* force set_features call */
1445 card->dev->features &= ~NETIF_F_RXCSUM;
1446 netdev_update_features(card->dev);
1447 rtnl_unlock();
1448 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001449 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001450}
1451
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001452static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1453{
1454 int rc = 0;
1455
1456 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1457 return rc;
1458 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1459 IPA_CMD_ASS_START, 0);
1460 if (rc)
1461 goto err_out;
1462 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1463 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1464 if (rc)
1465 goto err_out;
1466 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1467 return rc;
1468err_out:
1469 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1470 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1471 return rc;
1472}
1473
Frank Blaschka4a71df52008-02-15 09:19:42 +01001474static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1475{
1476 int rc;
1477
Carsten Otte847a50f2010-06-21 22:57:05 +00001478 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001479
1480 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001481 dev_info(&card->gdev->dev,
1482 "Outbound TSO not supported on %s\n",
1483 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001484 rc = -EOPNOTSUPP;
1485 } else {
1486 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1487 IPA_CMD_ASS_START, 0);
1488 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001489 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1490 "segmentation offload for %s failed\n",
1491 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001492 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001493 dev_info(&card->gdev->dev,
1494 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001495 }
Michał Mirosław6204b472011-04-19 00:43:20 +00001496 if (rc)
1497 card->dev->features &= ~NETIF_F_TSO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001498 return rc;
1499}
1500
1501static int qeth_l3_start_ipassists(struct qeth_card *card)
1502{
Carsten Otte847a50f2010-06-21 22:57:05 +00001503 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001504
1505 qeth_set_access_ctrl_online(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001506 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1507 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1508 qeth_l3_start_ipa_source_mac(card); /* go on*/
1509 qeth_l3_start_ipa_vlan(card); /* go on*/
1510 qeth_l3_start_ipa_multicast(card); /* go on*/
1511 qeth_l3_start_ipa_ipv6(card); /* go on*/
1512 qeth_l3_start_ipa_broadcast(card); /* go on*/
1513 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001514 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001515 qeth_l3_start_ipa_tso(card); /* go on*/
1516 return 0;
1517}
1518
Frank Blaschka4a71df52008-02-15 09:19:42 +01001519static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1520 struct qeth_reply *reply, unsigned long data)
1521{
1522 struct qeth_ipa_cmd *cmd;
1523
1524 cmd = (struct qeth_ipa_cmd *) data;
1525 if (cmd->hdr.return_code == 0)
1526 memcpy(card->dev->dev_addr,
1527 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1528 else
1529 random_ether_addr(card->dev->dev_addr);
1530
1531 return 0;
1532}
1533
1534static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1535{
1536 int rc = 0;
1537 struct qeth_cmd_buffer *iob;
1538 struct qeth_ipa_cmd *cmd;
1539
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001540 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001541
1542 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1543 QETH_PROT_IPV6);
1544 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1545 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1546 card->info.unique_id;
1547
1548 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1549 NULL);
1550 return rc;
1551}
1552
1553static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1554 struct qeth_reply *reply, unsigned long data)
1555{
1556 struct qeth_ipa_cmd *cmd;
1557
1558 cmd = (struct qeth_ipa_cmd *) data;
1559 if (cmd->hdr.return_code == 0)
1560 card->info.unique_id = *((__u16 *)
1561 &cmd->data.create_destroy_addr.unique_id[6]);
1562 else {
1563 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1564 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001565 dev_warn(&card->gdev->dev, "The network adapter failed to "
1566 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001567 }
1568 return 0;
1569}
1570
1571static int qeth_l3_get_unique_id(struct qeth_card *card)
1572{
1573 int rc = 0;
1574 struct qeth_cmd_buffer *iob;
1575 struct qeth_ipa_cmd *cmd;
1576
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001577 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001578
1579 if (!qeth_is_supported(card, IPA_IPV6)) {
1580 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1581 UNIQUE_ID_NOT_BY_CARD;
1582 return 0;
1583 }
1584
1585 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1586 QETH_PROT_IPV6);
1587 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1588 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1589 card->info.unique_id;
1590
1591 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1592 return rc;
1593}
1594
Ursula Braun76b11f82010-01-11 02:50:50 +00001595static int
1596qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1597 unsigned long data)
1598{
1599 struct qeth_ipa_cmd *cmd;
1600 __u16 rc;
1601
1602 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1603
1604 cmd = (struct qeth_ipa_cmd *)data;
1605 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001606 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001607 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001608 switch (cmd->data.diagass.action) {
1609 case QETH_DIAGS_CMD_TRACE_QUERY:
1610 break;
1611 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001612 switch (rc) {
1613 case 0:
1614 case IPA_RC_INVALID_SUBCMD:
1615 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1616 dev_info(&card->gdev->dev, "The HiperSockets network "
1617 "traffic analyzer is deactivated\n");
1618 break;
1619 default:
1620 break;
1621 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001622 break;
1623 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001624 switch (rc) {
1625 case 0:
1626 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1627 dev_info(&card->gdev->dev, "The HiperSockets network "
1628 "traffic analyzer is activated\n");
1629 break;
1630 case IPA_RC_HARDWARE_AUTH_ERROR:
1631 dev_warn(&card->gdev->dev, "The device is not "
1632 "authorized to run as a HiperSockets network "
1633 "traffic analyzer\n");
1634 break;
1635 case IPA_RC_TRACE_ALREADY_ACTIVE:
1636 dev_warn(&card->gdev->dev, "A HiperSockets "
1637 "network traffic analyzer is already "
1638 "active in the HiperSockets LAN\n");
1639 break;
1640 default:
1641 break;
1642 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001643 break;
1644 default:
1645 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1646 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1647 }
1648
1649 return 0;
1650}
1651
1652static int
1653qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1654{
1655 struct qeth_cmd_buffer *iob;
1656 struct qeth_ipa_cmd *cmd;
1657
1658 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1659
1660 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1661 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1662 cmd->data.diagass.subcmd_len = 16;
1663 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1664 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1665 cmd->data.diagass.action = diags_cmd;
1666 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1667}
1668
Frank Blaschka4a71df52008-02-15 09:19:42 +01001669static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1670 struct net_device *dev)
1671{
1672 if (dev->type == ARPHRD_IEEE802_TR)
1673 ip_tr_mc_map(ipm, mac);
1674 else
1675 ip_eth_mc_map(ipm, mac);
1676}
1677
1678static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1679{
1680 struct qeth_ipaddr *ipm;
1681 struct ip_mc_list *im4;
1682 char buf[MAX_ADDR_LEN];
1683
Carsten Otte847a50f2010-06-21 22:57:05 +00001684 QETH_CARD_TEXT(card, 4, "addmc");
Sachin Santf3aa31362010-11-26 02:41:17 +00001685 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1686 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001687 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1688 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1689 if (!ipm)
1690 continue;
1691 ipm->u.a4.addr = im4->multiaddr;
1692 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1693 ipm->is_multicast = 1;
1694 if (!qeth_l3_add_ip(card, ipm))
1695 kfree(ipm);
1696 }
1697}
1698
1699static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1700{
1701 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001702 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001703
Carsten Otte847a50f2010-06-21 22:57:05 +00001704 QETH_CARD_TEXT(card, 4, "addmcvl");
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001705 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001706 return;
1707
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001708 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1709 struct net_device *netdev;
1710
1711 rcu_read_lock();
1712 netdev = __vlan_find_dev_deep(card->dev, vid);
1713 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001714 if (netdev == NULL ||
1715 !(netdev->flags & IFF_UP))
1716 continue;
1717 in_dev = in_dev_get(netdev);
1718 if (!in_dev)
1719 continue;
Sachin Santf3aa31362010-11-26 02:41:17 +00001720 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001721 qeth_l3_add_mc(card, in_dev);
Sachin Santf3aa31362010-11-26 02:41:17 +00001722 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001723 in_dev_put(in_dev);
1724 }
1725}
1726
1727static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1728{
1729 struct in_device *in4_dev;
1730
Carsten Otte847a50f2010-06-21 22:57:05 +00001731 QETH_CARD_TEXT(card, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001732 in4_dev = in_dev_get(card->dev);
1733 if (in4_dev == NULL)
1734 return;
Sachin Santf3aa31362010-11-26 02:41:17 +00001735 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001736 qeth_l3_add_mc(card, in4_dev);
1737 qeth_l3_add_vlan_mc(card);
Sachin Santf3aa31362010-11-26 02:41:17 +00001738 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001739 in_dev_put(in4_dev);
1740}
1741
1742#ifdef CONFIG_QETH_IPV6
1743static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1744{
1745 struct qeth_ipaddr *ipm;
1746 struct ifmcaddr6 *im6;
1747 char buf[MAX_ADDR_LEN];
1748
Carsten Otte847a50f2010-06-21 22:57:05 +00001749 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001750 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1751 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1752 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1753 if (!ipm)
1754 continue;
1755 ipm->is_multicast = 1;
1756 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1757 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1758 sizeof(struct in6_addr));
1759 if (!qeth_l3_add_ip(card, ipm))
1760 kfree(ipm);
1761 }
1762}
1763
1764static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1765{
1766 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001767 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001768
Carsten Otte847a50f2010-06-21 22:57:05 +00001769 QETH_CARD_TEXT(card, 4, "admc6vl");
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001770 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001771 return;
1772
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001773 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1774 struct net_device *netdev;
1775
1776 netdev = __vlan_find_dev_deep(card->dev, vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001777 if (netdev == NULL ||
1778 !(netdev->flags & IFF_UP))
1779 continue;
1780 in_dev = in6_dev_get(netdev);
1781 if (!in_dev)
1782 continue;
1783 read_lock_bh(&in_dev->lock);
1784 qeth_l3_add_mc6(card, in_dev);
1785 read_unlock_bh(&in_dev->lock);
1786 in6_dev_put(in_dev);
1787 }
1788}
1789
1790static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1791{
1792 struct inet6_dev *in6_dev;
1793
Carsten Otte847a50f2010-06-21 22:57:05 +00001794 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001795 if (!qeth_is_supported(card, IPA_IPV6))
1796 return ;
1797 in6_dev = in6_dev_get(card->dev);
1798 if (in6_dev == NULL)
1799 return;
1800 read_lock_bh(&in6_dev->lock);
1801 qeth_l3_add_mc6(card, in6_dev);
1802 qeth_l3_add_vlan_mc6(card);
1803 read_unlock_bh(&in6_dev->lock);
1804 in6_dev_put(in6_dev);
1805}
1806#endif /* CONFIG_QETH_IPV6 */
1807
1808static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1809 unsigned short vid)
1810{
1811 struct in_device *in_dev;
1812 struct in_ifaddr *ifa;
1813 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001814 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001815
Carsten Otte847a50f2010-06-21 22:57:05 +00001816 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001817
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001818 netdev = __vlan_find_dev_deep(card->dev, vid);
1819 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001820 if (!in_dev)
1821 return;
1822 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1823 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1824 if (addr) {
1825 addr->u.a4.addr = ifa->ifa_address;
1826 addr->u.a4.mask = ifa->ifa_mask;
1827 addr->type = QETH_IP_TYPE_NORMAL;
1828 if (!qeth_l3_delete_ip(card, addr))
1829 kfree(addr);
1830 }
1831 }
1832 in_dev_put(in_dev);
1833}
1834
1835static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1836 unsigned short vid)
1837{
1838#ifdef CONFIG_QETH_IPV6
1839 struct inet6_dev *in6_dev;
1840 struct inet6_ifaddr *ifa;
1841 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001842 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001843
Carsten Otte847a50f2010-06-21 22:57:05 +00001844 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001845
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001846 netdev = __vlan_find_dev_deep(card->dev, vid);
1847 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001848 if (!in6_dev)
1849 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001850 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001851 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1852 if (addr) {
1853 memcpy(&addr->u.a6.addr, &ifa->addr,
1854 sizeof(struct in6_addr));
1855 addr->u.a6.pfxlen = ifa->prefix_len;
1856 addr->type = QETH_IP_TYPE_NORMAL;
1857 if (!qeth_l3_delete_ip(card, addr))
1858 kfree(addr);
1859 }
1860 }
1861 in6_dev_put(in6_dev);
1862#endif /* CONFIG_QETH_IPV6 */
1863}
1864
1865static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1866 unsigned short vid)
1867{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001868 qeth_l3_free_vlan_addresses4(card, vid);
1869 qeth_l3_free_vlan_addresses6(card, vid);
1870}
1871
Frank Blaschka4a71df52008-02-15 09:19:42 +01001872static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1873{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001874 struct qeth_card *card = dev->ml_priv;
1875
1876 set_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001877 return;
1878}
1879
1880static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1881{
Heiko Carstens509e2562008-07-26 02:24:10 -07001882 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001883 unsigned long flags;
1884
Carsten Otte847a50f2010-06-21 22:57:05 +00001885 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00001886 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001887 QETH_CARD_TEXT(card, 3, "kidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001888 return;
1889 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001890 spin_lock_irqsave(&card->vlanlock, flags);
1891 /* unregister IP addresses of vlan device */
1892 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001893 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001894 spin_unlock_irqrestore(&card->vlanlock, flags);
1895 qeth_l3_set_multicast_list(card->dev);
1896}
1897
Ursula Braun10651db2010-10-01 02:51:13 +00001898static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1899 struct sk_buff *skb, struct qeth_hdr *hdr,
1900 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001901{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001902 __be16 prot;
1903 struct iphdr *ip_hdr;
1904 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001905 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001906
1907 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1908 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1909 ETH_P_IP);
1910 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1911 case QETH_CAST_MULTICAST:
1912 switch (prot) {
1913#ifdef CONFIG_QETH_IPV6
1914 case __constant_htons(ETH_P_IPV6):
1915 ndisc_mc_map((struct in6_addr *)
1916 skb->data + 24,
1917 tg_addr, card->dev, 0);
1918 break;
1919#endif
1920 case __constant_htons(ETH_P_IP):
1921 ip_hdr = (struct iphdr *)skb->data;
1922 (card->dev->type == ARPHRD_IEEE802_TR) ?
1923 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1924 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1925 break;
1926 default:
1927 memcpy(tg_addr, card->dev->broadcast,
1928 card->dev->addr_len);
1929 }
1930 card->stats.multicast++;
1931 skb->pkt_type = PACKET_MULTICAST;
1932 break;
1933 case QETH_CAST_BROADCAST:
1934 memcpy(tg_addr, card->dev->broadcast,
1935 card->dev->addr_len);
1936 card->stats.multicast++;
1937 skb->pkt_type = PACKET_BROADCAST;
1938 break;
1939 case QETH_CAST_UNICAST:
1940 case QETH_CAST_ANYCAST:
1941 case QETH_CAST_NOCAST:
1942 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001943 if (card->options.sniffer)
1944 skb->pkt_type = PACKET_OTHERHOST;
1945 else
1946 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001947 memcpy(tg_addr, card->dev->dev_addr,
1948 card->dev->addr_len);
1949 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001950 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1951 card->dev->header_ops->create(skb, card->dev, prot,
1952 tg_addr, &hdr->hdr.l3.dest_addr[2],
1953 card->dev->addr_len);
1954 else
1955 card->dev->header_ops->create(skb, card->dev, prot,
1956 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001957 }
1958
1959#ifdef CONFIG_TR
1960 if (card->dev->type == ARPHRD_IEEE802_TR)
1961 skb->protocol = tr_type_trans(skb, card->dev);
1962 else
1963#endif
1964 skb->protocol = eth_type_trans(skb, card->dev);
1965
1966 if (hdr->hdr.l3.ext_flags &
1967 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001968 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001969 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001970 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001971 }
1972
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001973 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001974 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001975 (QETH_HDR_EXT_CSUM_HDR_REQ |
1976 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1977 (QETH_HDR_EXT_CSUM_HDR_REQ |
1978 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001979 skb->ip_summed = CHECKSUM_UNNECESSARY;
1980 else
Ursula Braunb9139802009-05-19 21:38:40 +00001981 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001982 } else
1983 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001984
Ursula Braun10651db2010-10-01 02:51:13 +00001985 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001986}
1987
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001988static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1989 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001990{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001991 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001992 struct sk_buff *skb;
1993 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001994 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001995 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001996 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001997 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001998
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001999 *done = 0;
2000 BUG_ON(!budget);
2001 while (budget) {
2002 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00002003 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002004 &card->rx.b_element, &card->rx.e_offset, &hdr);
2005 if (!skb) {
2006 *done = 1;
2007 break;
2008 }
2009 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002010 switch (hdr->hdr.l3.id) {
2011 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00002012 magic = *(__u16 *)skb->data;
2013 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2014 (magic == ETH_P_AF_IUCV)) {
2015 skb->protocol = ETH_P_AF_IUCV;
2016 skb->pkt_type = PACKET_HOST;
2017 skb->mac_header = NET_SKB_PAD;
2018 skb->dev = card->dev;
2019 len = skb->len;
2020 card->dev->header_ops->create(skb, card->dev, 0,
2021 card->dev->dev_addr, "FAKELL",
2022 card->dev->addr_len);
2023 netif_receive_skb(skb);
2024 } else {
2025 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
Ursula Braun10651db2010-10-01 02:51:13 +00002026 &vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00002027 len = skb->len;
2028 if (is_vlan && !card->options.sniffer)
2029 __vlan_hwaccel_put_tag(skb, vlan_tag);
2030 napi_gro_receive(&card->napi, skb);
2031 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002032 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002033 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2034 skb->pkt_type = PACKET_HOST;
2035 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002036 len = skb->len;
2037 netif_receive_skb(skb);
2038 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002039 default:
2040 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002041 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002042 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002043 continue;
2044 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002045 work_done++;
2046 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002047 card->stats.rx_packets++;
2048 card->stats.rx_bytes += len;
2049 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002050 return work_done;
2051}
2052
2053static int qeth_l3_poll(struct napi_struct *napi, int budget)
2054{
2055 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2056 int work_done = 0;
2057 struct qeth_qdio_buffer *buffer;
2058 int done;
2059 int new_budget = budget;
2060
2061 if (card->options.performance_stats) {
2062 card->perf_stats.inbound_cnt++;
2063 card->perf_stats.inbound_start_time = qeth_get_micros();
2064 }
2065
2066 while (1) {
2067 if (!card->rx.b_count) {
2068 card->rx.qdio_err = 0;
2069 card->rx.b_count = qdio_get_next_buffers(
2070 card->data.ccwdev, 0, &card->rx.b_index,
2071 &card->rx.qdio_err);
2072 if (card->rx.b_count <= 0) {
2073 card->rx.b_count = 0;
2074 break;
2075 }
2076 card->rx.b_element =
2077 &card->qdio.in_q->bufs[card->rx.b_index]
2078 .buffer->element[0];
2079 card->rx.e_offset = 0;
2080 }
2081
2082 while (card->rx.b_count) {
2083 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2084 if (!(card->rx.qdio_err &&
2085 qeth_check_qdio_errors(card, buffer->buffer,
2086 card->rx.qdio_err, "qinerr")))
2087 work_done += qeth_l3_process_inbound_buffer(
2088 card, new_budget, &done);
2089 else
2090 done = 1;
2091
2092 if (done) {
2093 if (card->options.performance_stats)
2094 card->perf_stats.bufs_rec++;
2095 qeth_put_buffer_pool_entry(card,
2096 buffer->pool_entry);
2097 qeth_queue_input_buffer(card, card->rx.b_index);
2098 card->rx.b_count--;
2099 if (card->rx.b_count) {
2100 card->rx.b_index =
2101 (card->rx.b_index + 1) %
2102 QDIO_MAX_BUFFERS_PER_Q;
2103 card->rx.b_element =
2104 &card->qdio.in_q
2105 ->bufs[card->rx.b_index]
2106 .buffer->element[0];
2107 card->rx.e_offset = 0;
2108 }
2109 }
2110
2111 if (work_done >= budget)
2112 goto out;
2113 else
2114 new_budget = budget - work_done;
2115 }
2116 }
2117
2118 napi_complete(napi);
2119 if (qdio_start_irq(card->data.ccwdev, 0))
2120 napi_schedule(&card->napi);
2121out:
2122 if (card->options.performance_stats)
2123 card->perf_stats.inbound_time += qeth_get_micros() -
2124 card->perf_stats.inbound_start_time;
2125 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002126}
2127
2128static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2129 struct qeth_card *card)
2130{
2131 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002132 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002133
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002134 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
2135 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002136
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002137 rcu_read_lock();
2138 netdev = __vlan_find_dev_deep(dev, vid);
2139 rcu_read_unlock();
2140 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002141 rc = QETH_VLAN_CARD;
2142 break;
2143 }
2144 }
2145
Heiko Carstens509e2562008-07-26 02:24:10 -07002146 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002147 return 0;
2148
2149 return rc;
2150}
2151
2152static int qeth_l3_verify_dev(struct net_device *dev)
2153{
2154 struct qeth_card *card;
2155 unsigned long flags;
2156 int rc = 0;
2157
2158 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2159 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2160 if (card->dev == dev) {
2161 rc = QETH_REAL_CARD;
2162 break;
2163 }
2164 rc = qeth_l3_verify_vlan_dev(dev, card);
2165 if (rc)
2166 break;
2167 }
2168 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2169
2170 return rc;
2171}
2172
2173static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2174{
2175 struct qeth_card *card = NULL;
2176 int rc;
2177
2178 rc = qeth_l3_verify_dev(dev);
2179 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002180 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002181 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002182 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002183 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002184 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002185 if (card)
2186 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002187 return card ;
2188}
2189
2190static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2191{
2192 int rc = 0;
2193
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002194 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2195 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002196
2197 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002198 if (card->options.sniffer &&
2199 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2200 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002201 if (card->read.state == CH_STATE_UP &&
2202 card->write.state == CH_STATE_UP &&
2203 (card->state == CARD_STATE_UP)) {
2204 if (recovery_mode)
2205 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002206 else {
Ursula Braun869da902010-03-08 20:36:56 +00002207 rtnl_lock();
2208 dev_close(card->dev);
2209 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002210 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002211 card->state = CARD_STATE_SOFTSETUP;
2212 }
2213 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -08002214 qeth_l3_clear_ip_list(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002215 qeth_clear_ipacmd_list(card);
2216 card->state = CARD_STATE_HARDSETUP;
2217 }
2218 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002219 qeth_qdio_clear_card(card, 0);
2220 qeth_clear_qdio_buffers(card);
2221 qeth_clear_working_pool_list(card);
2222 card->state = CARD_STATE_DOWN;
2223 }
2224 if (card->state == CARD_STATE_DOWN) {
2225 qeth_clear_cmd_buffers(&card->read);
2226 qeth_clear_cmd_buffers(&card->write);
2227 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002228 return rc;
2229}
2230
Ursula Braun76b11f82010-01-11 02:50:50 +00002231/*
2232 * test for and Switch promiscuous mode (on or off)
2233 * either for guestlan or HiperSocket Sniffer
2234 */
2235static void
2236qeth_l3_handle_promisc_mode(struct qeth_card *card)
2237{
2238 struct net_device *dev = card->dev;
2239
2240 if (((dev->flags & IFF_PROMISC) &&
2241 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2242 (!(dev->flags & IFF_PROMISC) &&
2243 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2244 return;
2245
2246 if (card->info.guestlan) { /* Guestlan trace */
2247 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2248 qeth_setadp_promisc_mode(card);
2249 } else if (card->options.sniffer && /* HiperSockets trace */
2250 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2251 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002252 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002253 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2254 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002255 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002256 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2257 }
2258 }
2259}
2260
Frank Blaschka4a71df52008-02-15 09:19:42 +01002261static void qeth_l3_set_multicast_list(struct net_device *dev)
2262{
Heiko Carstens509e2562008-07-26 02:24:10 -07002263 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002264
Carsten Otte847a50f2010-06-21 22:57:05 +00002265 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002266 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2267 (card->state != CARD_STATE_UP))
2268 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002269 if (!card->options.sniffer) {
2270 qeth_l3_delete_mc_addresses(card);
2271 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002272#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002273 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002274#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002275 qeth_l3_set_ip_addr_list(card);
2276 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2277 return;
2278 }
2279 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002280}
2281
2282static const char *qeth_l3_arp_get_error_cause(int *rc)
2283{
2284 switch (*rc) {
2285 case QETH_IPA_ARP_RC_FAILED:
2286 *rc = -EIO;
2287 return "operation failed";
2288 case QETH_IPA_ARP_RC_NOTSUPP:
2289 *rc = -EOPNOTSUPP;
2290 return "operation not supported";
2291 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2292 *rc = -EINVAL;
2293 return "argument out of range";
2294 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2295 *rc = -EOPNOTSUPP;
2296 return "query operation not supported";
2297 case QETH_IPA_ARP_RC_Q_NO_DATA:
2298 *rc = -ENOENT;
2299 return "no query data available";
2300 default:
2301 return "unknown error";
2302 }
2303}
2304
2305static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2306{
2307 int tmp;
2308 int rc;
2309
Carsten Otte847a50f2010-06-21 22:57:05 +00002310 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002311
2312 /*
2313 * currently GuestLAN only supports the ARP assist function
2314 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2315 * thus we say EOPNOTSUPP for this ARP function
2316 */
2317 if (card->info.guestlan)
2318 return -EOPNOTSUPP;
2319 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002320 return -EOPNOTSUPP;
2321 }
2322 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2323 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2324 no_entries);
2325 if (rc) {
2326 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002327 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2328 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002329 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2330 }
2331 return rc;
2332}
2333
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002334static __u32 get_arp_entry_size(struct qeth_card *card,
2335 struct qeth_arp_query_data *qdata,
2336 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002337{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002338 __u32 rc;
2339 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002340
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002341 is_hsi = qdata->reply_bits == 5;
2342 if (type->ip == QETHARP_IP_ADDR_V4) {
2343 QETH_CARD_TEXT(card, 4, "arpev4");
2344 if (strip_entries) {
2345 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2346 sizeof(struct qeth_arp_qi_entry7_short);
2347 } else {
2348 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2349 sizeof(struct qeth_arp_qi_entry7);
2350 }
2351 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2352 QETH_CARD_TEXT(card, 4, "arpev6");
2353 if (strip_entries) {
2354 rc = is_hsi ?
2355 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2356 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2357 } else {
2358 rc = is_hsi ?
2359 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2360 sizeof(struct qeth_arp_qi_entry7_ipv6);
2361 }
2362 } else {
2363 QETH_CARD_TEXT(card, 4, "arpinv");
2364 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002365 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002366
2367 return rc;
2368}
2369
2370static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2371{
2372 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2373 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002374}
2375
2376static int qeth_l3_arp_query_cb(struct qeth_card *card,
2377 struct qeth_reply *reply, unsigned long data)
2378{
2379 struct qeth_ipa_cmd *cmd;
2380 struct qeth_arp_query_data *qdata;
2381 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002382 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002383 int e;
2384 int entrybytes_done;
2385 int stripped_bytes;
2386 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002387
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002388 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002389
2390 qinfo = (struct qeth_arp_query_info *) reply->param;
2391 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002392 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002393 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002394 QETH_CARD_TEXT(card, 4, "arpcberr");
2395 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002396 return 0;
2397 }
2398 if (cmd->data.setassparms.hdr.return_code) {
2399 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002400 QETH_CARD_TEXT(card, 4, "setaperr");
2401 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002402 return 0;
2403 }
2404 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002405 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002406
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002407 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2408 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2409 entrybytes_done = 0;
2410 for (e = 0; e < qdata->no_entries; ++e) {
2411 char *cur_entry;
2412 __u32 esize;
2413 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002414
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002415 cur_entry = &qdata->data + entrybytes_done;
2416 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2417 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2418 QETH_CARD_TEXT(card, 4, "pmis");
2419 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2420 break;
2421 }
2422 esize = get_arp_entry_size(card, qdata, etype,
2423 do_strip_entries);
2424 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2425 if (!esize)
2426 break;
2427
2428 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2429 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
2430 cmd->hdr.return_code = -ENOMEM;
2431 goto out_error;
2432 }
2433
2434 memcpy(qinfo->udata + qinfo->udata_offset,
2435 &qdata->data + entrybytes_done + stripped_bytes,
2436 esize);
2437 entrybytes_done += esize + stripped_bytes;
2438 qinfo->udata_offset += esize;
2439 ++qinfo->no_entries;
2440 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002441 /* check if all replies received ... */
2442 if (cmd->data.setassparms.hdr.seq_no <
2443 cmd->data.setassparms.hdr.number_of_replies)
2444 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002445 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002446 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2447 /* keep STRIP_ENTRIES flag so the user program can distinguish
2448 * stripped entries from normal ones */
2449 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2450 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2451 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002452 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002453 return 0;
2454out_error:
2455 i = 0;
2456 memcpy(qinfo->udata, &i, 4);
2457 return 0;
2458}
2459
2460static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2461 struct qeth_cmd_buffer *iob, int len,
2462 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2463 unsigned long),
2464 void *reply_param)
2465{
Carsten Otte847a50f2010-06-21 22:57:05 +00002466 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002467
2468 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2469 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2470 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2471 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2472 reply_cb, reply_param);
2473}
2474
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002475static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2476 enum qeth_prot_versions prot,
2477 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002478{
2479 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002480 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002481 int tmp;
2482 int rc;
2483
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002484 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2485
2486 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2487 IPA_CMD_ASS_ARP_QUERY_INFO,
2488 sizeof(struct qeth_arp_query_data) - sizeof(char),
2489 prot);
2490 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2491 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2492 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2493 cmd->data.setassparms.data.query_arp.no_entries = 0;
2494 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2495 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2496 qeth_l3_arp_query_cb, (void *)qinfo);
2497 if (rc) {
2498 tmp = rc;
2499 QETH_DBF_MESSAGE(2,
2500 "Error while querying ARP cache on %s: %s "
2501 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2502 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2503 }
2504
2505 return rc;
2506}
2507
2508static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2509{
2510 struct qeth_arp_query_info qinfo = {0, };
2511 int rc;
2512
Carsten Otte847a50f2010-06-21 22:57:05 +00002513 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002514
2515 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2516 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002517 QETH_CARD_TEXT(card, 3, "arpqnsup");
2518 rc = -EOPNOTSUPP;
2519 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002520 }
2521 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002522 if (copy_from_user(&qinfo, udata, 6)) {
2523 rc = -EFAULT;
2524 goto out;
2525 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002526 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002527 if (!qinfo.udata) {
2528 rc = -ENOMEM;
2529 goto out;
2530 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002531 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002532 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002533 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002534 if (copy_to_user(udata, qinfo.udata, 4))
2535 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002536 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002537 } else {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002538#ifdef CONFIG_QETH_IPV6
2539 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2540 /* fails in case of GuestLAN QDIO mode */
2541 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2542 &qinfo);
2543 }
2544#endif
2545 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2546 QETH_CARD_TEXT(card, 4, "qactf");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002547 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002548 goto free_and_out;
2549 }
2550 QETH_CARD_TEXT_(card, 4, "qacts");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002551 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002552free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002553 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002554out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002555 return rc;
2556}
2557
2558static int qeth_l3_arp_add_entry(struct qeth_card *card,
2559 struct qeth_arp_cache_entry *entry)
2560{
2561 struct qeth_cmd_buffer *iob;
2562 char buf[16];
2563 int tmp;
2564 int rc;
2565
Carsten Otte847a50f2010-06-21 22:57:05 +00002566 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002567
2568 /*
2569 * currently GuestLAN only supports the ARP assist function
2570 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2571 * thus we say EOPNOTSUPP for this ARP function
2572 */
2573 if (card->info.guestlan)
2574 return -EOPNOTSUPP;
2575 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002576 return -EOPNOTSUPP;
2577 }
2578
2579 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2580 IPA_CMD_ASS_ARP_ADD_ENTRY,
2581 sizeof(struct qeth_arp_cache_entry),
2582 QETH_PROT_IPV4);
2583 rc = qeth_l3_send_setassparms(card, iob,
2584 sizeof(struct qeth_arp_cache_entry),
2585 (unsigned long) entry,
2586 qeth_l3_default_setassparms_cb, NULL);
2587 if (rc) {
2588 tmp = rc;
2589 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002590 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2591 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2592 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002593 }
2594 return rc;
2595}
2596
2597static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2598 struct qeth_arp_cache_entry *entry)
2599{
2600 struct qeth_cmd_buffer *iob;
2601 char buf[16] = {0, };
2602 int tmp;
2603 int rc;
2604
Carsten Otte847a50f2010-06-21 22:57:05 +00002605 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002606
2607 /*
2608 * currently GuestLAN only supports the ARP assist function
2609 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2610 * thus we say EOPNOTSUPP for this ARP function
2611 */
2612 if (card->info.guestlan)
2613 return -EOPNOTSUPP;
2614 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002615 return -EOPNOTSUPP;
2616 }
2617 memcpy(buf, entry, 12);
2618 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2619 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2620 12,
2621 QETH_PROT_IPV4);
2622 rc = qeth_l3_send_setassparms(card, iob,
2623 12, (unsigned long)buf,
2624 qeth_l3_default_setassparms_cb, NULL);
2625 if (rc) {
2626 tmp = rc;
2627 memset(buf, 0, 16);
2628 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002629 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2630 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2631 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002632 }
2633 return rc;
2634}
2635
2636static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2637{
2638 int rc;
2639 int tmp;
2640
Carsten Otte847a50f2010-06-21 22:57:05 +00002641 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002642
2643 /*
2644 * currently GuestLAN only supports the ARP assist function
2645 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2646 * thus we say EOPNOTSUPP for this ARP function
2647 */
2648 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2649 return -EOPNOTSUPP;
2650 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002651 return -EOPNOTSUPP;
2652 }
2653 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2654 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2655 if (rc) {
2656 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002657 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2658 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002659 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2660 }
2661 return rc;
2662}
2663
2664static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2665{
Heiko Carstens509e2562008-07-26 02:24:10 -07002666 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002667 struct qeth_arp_cache_entry arp_entry;
2668 struct mii_ioctl_data *mii_data;
2669 int rc = 0;
2670
2671 if (!card)
2672 return -ENODEV;
2673
2674 if ((card->state != CARD_STATE_UP) &&
2675 (card->state != CARD_STATE_SOFTSETUP))
2676 return -ENODEV;
2677
2678 switch (cmd) {
2679 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2680 if (!capable(CAP_NET_ADMIN)) {
2681 rc = -EPERM;
2682 break;
2683 }
2684 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2685 break;
2686 case SIOC_QETH_ARP_QUERY_INFO:
2687 if (!capable(CAP_NET_ADMIN)) {
2688 rc = -EPERM;
2689 break;
2690 }
2691 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2692 break;
2693 case SIOC_QETH_ARP_ADD_ENTRY:
2694 if (!capable(CAP_NET_ADMIN)) {
2695 rc = -EPERM;
2696 break;
2697 }
2698 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2699 sizeof(struct qeth_arp_cache_entry)))
2700 rc = -EFAULT;
2701 else
2702 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2703 break;
2704 case SIOC_QETH_ARP_REMOVE_ENTRY:
2705 if (!capable(CAP_NET_ADMIN)) {
2706 rc = -EPERM;
2707 break;
2708 }
2709 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2710 sizeof(struct qeth_arp_cache_entry)))
2711 rc = -EFAULT;
2712 else
2713 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2714 break;
2715 case SIOC_QETH_ARP_FLUSH_CACHE:
2716 if (!capable(CAP_NET_ADMIN)) {
2717 rc = -EPERM;
2718 break;
2719 }
2720 rc = qeth_l3_arp_flush_cache(card);
2721 break;
2722 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2723 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2724 break;
2725 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002726 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2727 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002728 !card->info.guestlan)
2729 return 1;
2730 return 0;
2731 break;
2732 case SIOCGMIIPHY:
2733 mii_data = if_mii(rq);
2734 mii_data->phy_id = 0;
2735 break;
2736 case SIOCGMIIREG:
2737 mii_data = if_mii(rq);
2738 if (mii_data->phy_id != 0)
2739 rc = -EINVAL;
2740 else
2741 mii_data->val_out = qeth_mdio_read(dev,
2742 mii_data->phy_id,
2743 mii_data->reg_num);
2744 break;
2745 default:
2746 rc = -EOPNOTSUPP;
2747 }
2748 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002749 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002750 return rc;
2751}
2752
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002753int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2754{
2755 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002756 struct neighbour *n = NULL;
2757 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002758
David S. Miller69cce1d2011-07-17 23:09:49 -07002759 dst = skb_dst(skb);
2760 if (dst)
2761 n = dst_get_neighbour(dst);
2762 if (n) {
2763 cast_type = n->type;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002764 if ((cast_type == RTN_BROADCAST) ||
2765 (cast_type == RTN_MULTICAST) ||
2766 (cast_type == RTN_ANYCAST))
2767 return cast_type;
2768 else
2769 return RTN_UNSPEC;
2770 }
2771 /* try something else */
2772 if (skb->protocol == ETH_P_IPV6)
2773 return (skb_network_header(skb)[24] == 0xff) ?
2774 RTN_MULTICAST : 0;
2775 else if (skb->protocol == ETH_P_IP)
2776 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2777 RTN_MULTICAST : 0;
2778 /* ... */
2779 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2780 return RTN_BROADCAST;
2781 else {
2782 u16 hdr_mac;
2783
2784 hdr_mac = *((u16 *)skb->data);
2785 /* tr multicast? */
2786 switch (card->info.link_type) {
2787 case QETH_LINK_TYPE_HSTR:
2788 case QETH_LINK_TYPE_LANE_TR:
2789 if ((hdr_mac == QETH_TR_MAC_NC) ||
2790 (hdr_mac == QETH_TR_MAC_C))
2791 return RTN_MULTICAST;
2792 break;
2793 /* eth or so multicast? */
2794 default:
2795 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2796 (hdr_mac == QETH_ETH_MAC_V6))
2797 return RTN_MULTICAST;
2798 }
2799 }
2800 return cast_type;
2801}
2802
Frank Blaschkab3332932011-08-08 01:33:59 +00002803static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2804 struct qeth_hdr *hdr, struct sk_buff *skb)
2805{
2806 char daddr[16];
2807 struct af_iucv_trans_hdr *iucv_hdr;
2808
2809 skb_pull(skb, 14);
2810 card->dev->header_ops->create(skb, card->dev, 0,
2811 card->dev->dev_addr, card->dev->dev_addr,
2812 card->dev->addr_len);
2813 skb_pull(skb, 14);
2814 iucv_hdr = (struct af_iucv_trans_hdr *)skb->data;
2815 memset(hdr, 0, sizeof(struct qeth_hdr));
2816 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2817 hdr->hdr.l3.ext_flags = 0;
2818 hdr->hdr.l3.length = skb->len;
2819 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
2820 memset(daddr, 0, sizeof(daddr));
2821 daddr[0] = 0xfe;
2822 daddr[1] = 0x80;
2823 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2824 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2825}
2826
Frank Blaschka4a71df52008-02-15 09:19:42 +01002827static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2828 struct sk_buff *skb, int ipv, int cast_type)
2829{
David S. Miller69cce1d2011-07-17 23:09:49 -07002830 struct neighbour *n = NULL;
2831 struct dst_entry *dst;
2832
Frank Blaschka4a71df52008-02-15 09:19:42 +01002833 memset(hdr, 0, sizeof(struct qeth_hdr));
2834 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2835 hdr->hdr.l3.ext_flags = 0;
2836
2837 /*
2838 * before we're going to overwrite this location with next hop ip.
2839 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2840 */
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002841 if (vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002842 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2843 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2844 else
2845 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002846 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2847 }
2848
2849 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
David S. Miller69cce1d2011-07-17 23:09:49 -07002850 dst = skb_dst(skb);
2851 if (dst)
2852 n = dst_get_neighbour(dst);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002853 if (ipv == 4) {
2854 /* IPv4 */
2855 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2856 memset(hdr->hdr.l3.dest_addr, 0, 12);
David S. Miller69cce1d2011-07-17 23:09:49 -07002857 if (n) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002858 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
David S. Miller69cce1d2011-07-17 23:09:49 -07002859 *((u32 *) n->primary_key);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002860 } else {
2861 /* fill in destination address used in ip header */
2862 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2863 ip_hdr(skb)->daddr;
2864 }
2865 } else if (ipv == 6) {
2866 /* IPv6 */
2867 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2868 if (card->info.type == QETH_CARD_TYPE_IQD)
2869 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David S. Miller69cce1d2011-07-17 23:09:49 -07002870 if (n) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002871 memcpy(hdr->hdr.l3.dest_addr,
David S. Miller69cce1d2011-07-17 23:09:49 -07002872 n->primary_key, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002873 } else {
2874 /* fill in destination address used in ip header */
2875 memcpy(hdr->hdr.l3.dest_addr,
2876 &ipv6_hdr(skb)->daddr, 16);
2877 }
2878 } else {
2879 /* passthrough */
2880 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2881 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2882 sizeof(__u16), skb->dev->broadcast, 6)) {
2883 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2884 QETH_HDR_PASSTHRU;
2885 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2886 skb->dev->broadcast, 6)) {
2887 /* broadcast? */
2888 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2889 QETH_HDR_PASSTHRU;
2890 } else {
2891 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2892 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2893 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2894 }
2895 }
2896}
2897
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002898static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2899 struct qeth_hdr *hdr, struct sk_buff *skb)
2900{
2901 struct iphdr *iph = ip_hdr(skb);
2902
2903 /* tcph->check contains already the pseudo hdr checksum
2904 * so just set the header flags
2905 */
2906 if (iph->protocol == IPPROTO_UDP)
2907 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002908 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2909 QETH_HDR_EXT_CSUM_HDR_REQ;
2910 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002911 if (card->options.performance_stats)
2912 card->perf_stats.tx_csum++;
2913}
2914
Frank Blaschka64ef8952009-03-24 20:57:16 +00002915static void qeth_tso_fill_header(struct qeth_card *card,
2916 struct qeth_hdr *qhdr, struct sk_buff *skb)
2917{
2918 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2919 struct tcphdr *tcph = tcp_hdr(skb);
2920 struct iphdr *iph = ip_hdr(skb);
2921 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2922
2923 /*fix header to TSO values ...*/
2924 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002925 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002926 /*set values which are fix for the first approach ...*/
2927 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2928 hdr->ext.imb_hdr_no = 1;
2929 hdr->ext.hdr_type = 1;
2930 hdr->ext.hdr_version = 1;
2931 hdr->ext.hdr_len = 28;
2932 /*insert non-fix values */
2933 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2934 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2935 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2936 sizeof(struct qeth_hdr_tso));
2937 tcph->check = 0;
2938 if (skb->protocol == ETH_P_IPV6) {
2939 ip6h->payload_len = 0;
2940 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2941 0, IPPROTO_TCP, 0);
2942 } else {
2943 /*OSA want us to set these values ...*/
2944 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2945 0, IPPROTO_TCP, 0);
2946 iph->tot_len = 0;
2947 iph->check = 0;
2948 }
2949}
2950
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002951static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2952{
2953 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2954 tcp_hdr(skb)->doff * 4;
2955 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002956 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002957 elements += skb_shinfo(skb)->nr_frags;
2958 return elements;
2959}
2960
Frank Blaschka4a71df52008-02-15 09:19:42 +01002961static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2962{
2963 int rc;
2964 u16 *tag;
2965 struct qeth_hdr *hdr = NULL;
2966 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002967 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002968 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002969 struct sk_buff *new_skb = NULL;
2970 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002971 int cast_type = qeth_l3_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002972 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2973 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2974 int tx_bytes = skb->len;
Michał Mirosław6204b472011-04-19 00:43:20 +00002975 bool large_send;
Frank Blaschka683d7182008-08-01 16:39:13 +02002976 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002977 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002978
Frank Blaschkab3332932011-08-08 01:33:59 +00002979 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2980 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2981 ((card->options.cq == QETH_CQ_ENABLED) &&
2982 (skb->protocol != ETH_P_AF_IUCV)))) ||
2983 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002984 goto tx_drop;
2985
2986 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2987 card->stats.tx_carrier_errors++;
2988 goto tx_drop;
2989 }
2990
2991 if ((cast_type == RTN_BROADCAST) &&
2992 (card->info.broadcast_capable == 0))
2993 goto tx_drop;
2994
2995 if (card->options.performance_stats) {
2996 card->perf_stats.outbound_cnt++;
2997 card->perf_stats.outbound_start_time = qeth_get_micros();
2998 }
2999
Michał Mirosław6204b472011-04-19 00:43:20 +00003000 large_send = skb_is_gso(skb);
Frank Blaschka683d7182008-08-01 16:39:13 +02003001
3002 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
3003 (skb_shinfo(skb)->nr_frags == 0)) {
3004 new_skb = skb;
Frank Blaschkab3332932011-08-08 01:33:59 +00003005 if (new_skb->protocol == ETH_P_AF_IUCV)
3006 data_offset = 0;
3007 else
3008 data_offset = ETH_HLEN;
Frank Blaschka683d7182008-08-01 16:39:13 +02003009 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
3010 if (!hdr)
3011 goto tx_drop;
3012 elements_needed++;
3013 } else {
3014 /* create a clone with writeable headroom */
3015 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
3016 + VLAN_HLEN);
3017 if (!new_skb)
3018 goto tx_drop;
3019 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003020
3021 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02003022 if (data_offset < 0)
3023 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003024 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00003025 if (ipv == 4) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003026 if (card->dev->type == ARPHRD_IEEE802_TR)
3027 skb_pull(new_skb, TR_HLEN);
3028 else
3029 skb_pull(new_skb, ETH_HLEN);
3030 }
3031
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003032 if (ipv != 4 && vlan_tx_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003033 skb_push(new_skb, VLAN_HLEN);
3034 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
3035 skb_copy_to_linear_data_offset(new_skb, 4,
3036 new_skb->data + 8, 4);
3037 skb_copy_to_linear_data_offset(new_skb, 8,
3038 new_skb->data + 12, 4);
3039 tag = (u16 *)(new_skb->data + 12);
3040 *tag = __constant_htons(ETH_P_8021Q);
3041 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003042 }
3043 }
3044
3045 netif_stop_queue(dev);
3046
Frank Blaschka4a71df52008-02-15 09:19:42 +01003047 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003048 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003049 */
Michał Mirosław6204b472011-04-19 00:43:20 +00003050 if (large_send) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003051 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3052 if (skb_linearize(new_skb))
3053 goto tx_drop;
3054 if (card->options.performance_stats)
3055 card->perf_stats.tx_lin++;
3056 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003057 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003058
Michał Mirosław6204b472011-04-19 00:43:20 +00003059 if (large_send && (cast_type == RTN_UNSPEC)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003060 hdr = (struct qeth_hdr *)skb_push(new_skb,
3061 sizeof(struct qeth_hdr_tso));
3062 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3063 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3064 qeth_tso_fill_header(card, hdr, new_skb);
3065 elements_needed++;
3066 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003067 if (data_offset < 0) {
3068 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003069 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003070 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3071 cast_type);
3072 } else {
Frank Blaschkab3332932011-08-08 01:33:59 +00003073 if (new_skb->protocol == ETH_P_AF_IUCV)
3074 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
3075 else {
3076 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3077 cast_type);
3078 hdr->hdr.l3.length = new_skb->len - data_offset;
3079 }
Frank Blaschka683d7182008-08-01 16:39:13 +02003080 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003081
3082 if (skb->ip_summed == CHECKSUM_PARTIAL)
3083 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003084 }
3085
Frank Blaschka64ef8952009-03-24 20:57:16 +00003086 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003087 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003088 if (!elems) {
3089 if (data_offset >= 0)
3090 kmem_cache_free(qeth_core_header_cache, hdr);
3091 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003092 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003093 elements_needed += elems;
3094 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003095
Frank Blaschka51aa1652010-06-21 22:57:10 +00003096 if (card->info.type != QETH_CARD_TYPE_IQD) {
3097 int len;
Michał Mirosław6204b472011-04-19 00:43:20 +00003098 if (large_send)
Frank Blaschka51aa1652010-06-21 22:57:10 +00003099 len = ((unsigned long)tcp_hdr(new_skb) +
3100 tcp_hdr(new_skb)->doff * 4) -
3101 (unsigned long)new_skb->data;
3102 else
3103 len = sizeof(struct qeth_hdr_layer3);
3104
3105 if (qeth_hdr_chk_and_bounce(new_skb, len))
3106 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003107 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003108 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003109 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003110 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003111 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003112
3113 if (!rc) {
3114 card->stats.tx_packets++;
3115 card->stats.tx_bytes += tx_bytes;
3116 if (new_skb != skb)
3117 dev_kfree_skb_any(skb);
3118 if (card->options.performance_stats) {
Michał Mirosław6204b472011-04-19 00:43:20 +00003119 if (large_send) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003120 card->perf_stats.large_send_bytes += tx_bytes;
3121 card->perf_stats.large_send_cnt++;
3122 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003123 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003124 card->perf_stats.sg_skbs_sent++;
3125 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003126 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003127 }
3128 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003129 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003130 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003131 if (data_offset >= 0)
3132 kmem_cache_free(qeth_core_header_cache, hdr);
3133
Frank Blaschka4a71df52008-02-15 09:19:42 +01003134 if (rc == -EBUSY) {
3135 if (new_skb != skb)
3136 dev_kfree_skb_any(new_skb);
3137 return NETDEV_TX_BUSY;
3138 } else
3139 goto tx_drop;
3140 }
3141
3142 netif_wake_queue(dev);
3143 if (card->options.performance_stats)
3144 card->perf_stats.outbound_time += qeth_get_micros() -
3145 card->perf_stats.outbound_start_time;
3146 return rc;
3147
3148tx_drop:
3149 card->stats.tx_dropped++;
3150 card->stats.tx_errors++;
3151 if ((new_skb != skb) && new_skb)
3152 dev_kfree_skb_any(new_skb);
3153 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003154 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003155 return NETDEV_TX_OK;
3156}
3157
Ursula Braun39423442011-01-12 20:42:24 +00003158static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003159{
Heiko Carstens509e2562008-07-26 02:24:10 -07003160 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003161 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003162
Carsten Otte847a50f2010-06-21 22:57:05 +00003163 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00003164 if (card->state == CARD_STATE_UP)
3165 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003166 if (card->state != CARD_STATE_SOFTSETUP)
3167 return -ENODEV;
3168 card->data.state = CH_STATE_UP;
3169 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003170 netif_start_queue(dev);
3171
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003172 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3173 napi_enable(&card->napi);
3174 napi_schedule(&card->napi);
3175 } else
3176 rc = -EIO;
3177 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003178}
3179
Ursula Braun39423442011-01-12 20:42:24 +00003180static int qeth_l3_open(struct net_device *dev)
3181{
3182 struct qeth_card *card = dev->ml_priv;
3183
3184 QETH_CARD_TEXT(card, 5, "qethope_");
3185 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3186 QETH_CARD_TEXT(card, 3, "openREC");
3187 return -ERESTARTSYS;
3188 }
3189 return __qeth_l3_open(dev);
3190}
3191
Frank Blaschka4a71df52008-02-15 09:19:42 +01003192static int qeth_l3_stop(struct net_device *dev)
3193{
Heiko Carstens509e2562008-07-26 02:24:10 -07003194 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003195
Carsten Otte847a50f2010-06-21 22:57:05 +00003196 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003197 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003198 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003199 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003200 napi_disable(&card->napi);
3201 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003202 return 0;
3203}
3204
Michał Mirosław6204b472011-04-19 00:43:20 +00003205static u32 qeth_l3_fix_features(struct net_device *dev, u32 features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003206{
Heiko Carstens509e2562008-07-26 02:24:10 -07003207 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003208
Michał Mirosław6204b472011-04-19 00:43:20 +00003209 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3210 features &= ~NETIF_F_IP_CSUM;
3211 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
3212 features &= ~NETIF_F_TSO;
3213 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
3214 features &= ~NETIF_F_RXCSUM;
3215
3216 return features;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003217}
3218
Michał Mirosław6204b472011-04-19 00:43:20 +00003219static int qeth_l3_set_features(struct net_device *dev, u32 features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003220{
Michał Mirosław6204b472011-04-19 00:43:20 +00003221 struct qeth_card *card = dev->ml_priv;
3222 u32 changed = dev->features ^ features;
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003223 int err;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003224
Michał Mirosław6204b472011-04-19 00:43:20 +00003225 if (!(changed & NETIF_F_RXCSUM))
3226 return 0;
3227
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003228 if (card->state == CARD_STATE_DOWN ||
3229 card->state == CARD_STATE_RECOVER)
3230 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003231
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003232 err = qeth_l3_set_rx_csum(card, features & NETIF_F_RXCSUM);
3233 if (err)
3234 dev->features = features ^ NETIF_F_RXCSUM;
3235
3236 return err;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003237}
3238
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003239static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003240 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003241 .get_strings = qeth_core_get_strings,
3242 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003243 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003244 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003245 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003246};
3247
3248/*
3249 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3250 * NOARP on the netdevice is no option because it also turns off neighbor
3251 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3252 * arp resolution but we want the hard header (packet socket will work
3253 * e.g. tcpdump)
3254 */
3255static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3256{
3257 n->nud_state = NUD_NOARP;
3258 memcpy(n->ha, "FAKELL", 6);
3259 n->output = n->ops->connected_output;
3260 return 0;
3261}
3262
3263static int
3264qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3265{
3266 if (np->tbl->family == AF_INET)
3267 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3268
3269 return 0;
3270}
3271
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003272static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003273 .ndo_open = qeth_l3_open,
3274 .ndo_stop = qeth_l3_stop,
3275 .ndo_get_stats = qeth_get_stats,
3276 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3277 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003278 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003279 .ndo_do_ioctl = qeth_l3_do_ioctl,
3280 .ndo_change_mtu = qeth_change_mtu,
3281 .ndo_fix_features = qeth_l3_fix_features,
3282 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003283 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3284 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003285 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08003286};
3287
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003288static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3289 .ndo_open = qeth_l3_open,
3290 .ndo_stop = qeth_l3_stop,
3291 .ndo_get_stats = qeth_get_stats,
3292 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3293 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003294 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003295 .ndo_do_ioctl = qeth_l3_do_ioctl,
3296 .ndo_change_mtu = qeth_change_mtu,
3297 .ndo_fix_features = qeth_l3_fix_features,
3298 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003299 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3300 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003301 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003302 .ndo_neigh_setup = qeth_l3_neigh_setup,
3303};
3304
Frank Blaschka4a71df52008-02-15 09:19:42 +01003305static int qeth_l3_setup_netdev(struct qeth_card *card)
3306{
Ursula Braun5113fec2010-05-16 21:15:14 +00003307 if (card->info.type == QETH_CARD_TYPE_OSD ||
3308 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003309 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3310 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3311#ifdef CONFIG_TR
3312 card->dev = alloc_trdev(0);
3313#endif
3314 if (!card->dev)
3315 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003316 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003317 } else {
3318 card->dev = alloc_etherdev(0);
3319 if (!card->dev)
3320 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003321 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003322
3323 /*IPv6 address autoconfiguration stuff*/
3324 qeth_l3_get_unique_id(card);
3325 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3326 card->dev->dev_id = card->info.unique_id &
3327 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003328 if (!card->info.guestlan) {
3329 card->dev->hw_features = NETIF_F_SG |
3330 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3331 NETIF_F_TSO;
3332 card->dev->features = NETIF_F_RXCSUM;
3333 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003334 }
3335 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3336 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3337 if (!card->dev)
3338 return -ENODEV;
3339 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003340 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003341 qeth_l3_iqd_read_initial_mac(card);
Frank Blaschkab3332932011-08-08 01:33:59 +00003342 if (card->options.hsuid[0])
3343 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003344 } else
3345 return -ENODEV;
3346
Heiko Carstens509e2562008-07-26 02:24:10 -07003347 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003348 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003349 card->dev->mtu = card->info.initial_mtu;
3350 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3351 card->dev->features |= NETIF_F_HW_VLAN_TX |
3352 NETIF_F_HW_VLAN_RX |
3353 NETIF_F_HW_VLAN_FILTER;
Eric Dumazet86d15cd2009-05-30 23:04:46 -07003354 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003355 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003356
3357 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003358 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003359 return register_netdev(card->dev);
3360}
3361
Frank Blaschka4a71df52008-02-15 09:19:42 +01003362static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3363{
3364 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3365
3366 qeth_l3_create_device_attributes(&gdev->dev);
3367 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003368 card->info.hwtrap = 0;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003369 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003370 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003371 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003372 card->discipline.output_handler = (qdio_handler_t *)
3373 qeth_qdio_output_handler;
3374 card->discipline.recover = qeth_l3_recover;
3375 return 0;
3376}
3377
3378static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3379{
3380 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3381
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003382 qeth_l3_remove_device_attributes(&cgdev->dev);
3383
Ursula Braunf2148562009-05-19 21:38:37 +00003384 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003385 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3386
Ursula Braun70919e22011-02-26 22:41:36 -08003387 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003388 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003389
3390 if (card->dev) {
3391 unregister_netdev(card->dev);
3392 card->dev = NULL;
3393 }
3394
Ursula Braun70919e22011-02-26 22:41:36 -08003395 qeth_l3_clear_ip_list(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003396 qeth_l3_clear_ipato_list(card);
3397 return;
3398}
3399
3400static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3401{
3402 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3403 int rc = 0;
3404 enum qeth_card_states recover_flag;
3405
3406 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003407 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003408 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003409 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3410 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003411
Frank Blaschka4a71df52008-02-15 09:19:42 +01003412 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003413 rc = qeth_core_hardsetup_card(card);
3414 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003415 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003416 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003417 goto out_remove;
3418 }
3419
Ursula Braunaa909222009-11-12 00:11:43 +00003420 if (!card->dev && qeth_l3_setup_netdev(card)) {
3421 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003422 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003423 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003424
Frank Blaschka1da74b12011-05-12 18:45:02 +00003425 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3426 if (card->info.hwtrap &&
3427 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3428 card->info.hwtrap = 0;
3429 } else
3430 card->info.hwtrap = 0;
3431
Frank Blaschka4a71df52008-02-15 09:19:42 +01003432 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;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003533 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3534 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3535 card->info.hwtrap = 1;
3536 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003537 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003538 rc = ccw_device_set_offline(CARD_DDEV(card));
3539 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3540 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3541 if (!rc)
3542 rc = (rc2) ? rc2 : rc3;
3543 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003544 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003545 if (recover_flag == CARD_STATE_UP)
3546 card->state = CARD_STATE_RECOVER;
3547 /* let user_space know that device is offline */
3548 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003549 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003550 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003551 return 0;
3552}
3553
3554static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3555{
3556 return __qeth_l3_set_offline(cgdev, 0);
3557}
3558
3559static int qeth_l3_recover(void *ptr)
3560{
3561 struct qeth_card *card;
3562 int rc = 0;
3563
3564 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003565 QETH_CARD_TEXT(card, 2, "recover1");
3566 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003567 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3568 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003569 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003570 dev_warn(&card->gdev->dev,
3571 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003572 __qeth_l3_set_offline(card->gdev, 1);
3573 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003574 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003575 dev_info(&card->gdev->dev,
3576 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003577 else {
3578 rtnl_lock();
3579 dev_close(card->dev);
3580 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003581 dev_warn(&card->gdev->dev, "The qeth device driver "
3582 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003583 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003584 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3585 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003586 return 0;
3587}
3588
3589static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3590{
3591 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Frank Blaschka1da74b12011-05-12 18:45:02 +00003592 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3593 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003594 qeth_qdio_clear_card(card, 0);
3595 qeth_clear_qdio_buffers(card);
3596}
3597
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003598static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3599{
3600 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3601
3602 if (card->dev)
3603 netif_device_detach(card->dev);
3604 qeth_set_allowed_threads(card, 0, 1);
3605 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3606 if (gdev->state == CCWGROUP_OFFLINE)
3607 return 0;
3608 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003609 if (card->info.hwtrap)
3610 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003611 __qeth_l3_set_offline(card->gdev, 1);
3612 } else
3613 __qeth_l3_set_offline(card->gdev, 0);
3614 return 0;
3615}
3616
3617static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3618{
3619 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3620 int rc = 0;
3621
3622 if (gdev->state == CCWGROUP_OFFLINE)
3623 goto out;
3624
3625 if (card->state == CARD_STATE_RECOVER) {
3626 rc = __qeth_l3_set_online(card->gdev, 1);
3627 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003628 rtnl_lock();
3629 dev_close(card->dev);
3630 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003631 }
3632 } else
3633 rc = __qeth_l3_set_online(card->gdev, 0);
3634out:
3635 qeth_set_allowed_threads(card, 0xffffffff, 0);
3636 if (card->dev)
3637 netif_device_attach(card->dev);
3638 if (rc)
3639 dev_warn(&card->gdev->dev, "The qeth device driver "
3640 "failed to recover an error on the device\n");
3641 return rc;
3642}
3643
Frank Blaschka4a71df52008-02-15 09:19:42 +01003644struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3645 .probe = qeth_l3_probe_device,
3646 .remove = qeth_l3_remove_device,
3647 .set_online = qeth_l3_set_online,
3648 .set_offline = qeth_l3_set_offline,
3649 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003650 .freeze = qeth_l3_pm_suspend,
3651 .thaw = qeth_l3_pm_resume,
3652 .restore = qeth_l3_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003653};
3654EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3655
3656static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003657 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003658{
3659 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3660 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3661 struct qeth_ipaddr *addr;
3662 struct qeth_card *card;
3663
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003664 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003665 return NOTIFY_DONE;
3666
Frank Blaschka4a71df52008-02-15 09:19:42 +01003667 card = qeth_l3_get_card_from_dev(dev);
Carsten Otte847a50f2010-06-21 22:57:05 +00003668 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003669 if (!card)
3670 return NOTIFY_DONE;
3671
3672 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3673 if (addr != NULL) {
3674 addr->u.a4.addr = ifa->ifa_address;
3675 addr->u.a4.mask = ifa->ifa_mask;
3676 addr->type = QETH_IP_TYPE_NORMAL;
3677 } else
3678 goto out;
3679
3680 switch (event) {
3681 case NETDEV_UP:
3682 if (!qeth_l3_add_ip(card, addr))
3683 kfree(addr);
3684 break;
3685 case NETDEV_DOWN:
3686 if (!qeth_l3_delete_ip(card, addr))
3687 kfree(addr);
3688 break;
3689 default:
3690 break;
3691 }
3692 qeth_l3_set_ip_addr_list(card);
3693out:
3694 return NOTIFY_DONE;
3695}
3696
3697static struct notifier_block qeth_l3_ip_notifier = {
3698 qeth_l3_ip_event,
3699 NULL,
3700};
3701
3702#ifdef CONFIG_QETH_IPV6
3703/**
3704 * IPv6 event handler
3705 */
3706static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003707 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003708{
3709 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3710 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3711 struct qeth_ipaddr *addr;
3712 struct qeth_card *card;
3713
Frank Blaschka4a71df52008-02-15 09:19:42 +01003714 card = qeth_l3_get_card_from_dev(dev);
3715 if (!card)
3716 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003717 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003718 if (!qeth_is_supported(card, IPA_IPV6))
3719 return NOTIFY_DONE;
3720
3721 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3722 if (addr != NULL) {
3723 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3724 addr->u.a6.pfxlen = ifa->prefix_len;
3725 addr->type = QETH_IP_TYPE_NORMAL;
3726 } else
3727 goto out;
3728
3729 switch (event) {
3730 case NETDEV_UP:
3731 if (!qeth_l3_add_ip(card, addr))
3732 kfree(addr);
3733 break;
3734 case NETDEV_DOWN:
3735 if (!qeth_l3_delete_ip(card, addr))
3736 kfree(addr);
3737 break;
3738 default:
3739 break;
3740 }
3741 qeth_l3_set_ip_addr_list(card);
3742out:
3743 return NOTIFY_DONE;
3744}
3745
3746static struct notifier_block qeth_l3_ip6_notifier = {
3747 qeth_l3_ip6_event,
3748 NULL,
3749};
3750#endif
3751
3752static int qeth_l3_register_notifiers(void)
3753{
3754 int rc;
3755
Carsten Otte847a50f2010-06-21 22:57:05 +00003756 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003757 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3758 if (rc)
3759 return rc;
3760#ifdef CONFIG_QETH_IPV6
3761 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3762 if (rc) {
3763 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3764 return rc;
3765 }
3766#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003767 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003768#endif
3769 return 0;
3770}
3771
3772static void qeth_l3_unregister_notifiers(void)
3773{
3774
Carsten Otte847a50f2010-06-21 22:57:05 +00003775 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003776 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3777#ifdef CONFIG_QETH_IPV6
3778 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3779#endif /* QETH_IPV6 */
3780}
3781
3782static int __init qeth_l3_init(void)
3783{
3784 int rc = 0;
3785
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003786 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003787 rc = qeth_l3_register_notifiers();
3788 return rc;
3789}
3790
3791static void __exit qeth_l3_exit(void)
3792{
3793 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003794 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003795}
3796
3797module_init(qeth_l3_init);
3798module_exit(qeth_l3_exit);
3799MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3800MODULE_DESCRIPTION("qeth layer 3 discipline");
3801MODULE_LICENSE("GPL");