blob: 625227ad16ee91cd2b4ca1aaa8a9541408e2a838 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01003 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
8
Frank Blaschka74eacdb2008-12-25 13:39:49 +01009#define KMSG_COMPONENT "qeth"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Frank Blaschka4a71df52008-02-15 09:19:42 +010012#include <linux/module.h>
13#include <linux/moduleparam.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000014#include <linux/bitops.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010015#include <linux/string.h>
16#include <linux/errno.h>
17#include <linux/kernel.h>
18#include <linux/etherdevice.h>
19#include <linux/mii.h>
20#include <linux/ip.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000021#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010022#include <linux/inetdevice.h>
23#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000025#include <linux/if_vlan.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
27#include <net/ip.h>
28#include <net/arp.h>
David Miller87e75972012-02-01 10:49:17 +000029#include <net/route.h>
30#include <net/ip6_fib.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
Thomas Richter56530d62014-10-22 12:18:04 +020058static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010059{
60 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
61}
62
Thomas Richter56530d62014-10-22 12:18:04 +020063static int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +010064{
65 int count = 0, rc = 0;
Ursula Brauna68be012014-05-28 10:22:31 +020066 unsigned int in[4];
Frank Blaschka4a71df52008-02-15 09:19:42 +010067 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
Thomas Richter56530d62014-10-22 12:18:04 +020081static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010082{
Joe Perches963a9fd2010-09-07 21:14:40 +000083 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010084}
85
Thomas Richter56530d62014-10-22 12:18:04 +020086static int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +010087{
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
Stefan Raspl82e2e782013-03-18 20:04:43 +0000626static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100627 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:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000635 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100636 default:
637 goto out_inval;
638 }
639 } else {
640 switch (*type) {
641 case NO_ROUTER:
642 case PRIMARY_ROUTER:
643 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000644 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645 case MULTICAST_ROUTER:
646 if (qeth_is_ipafunc_supported(card, prot,
647 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000648 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100649 default:
650 goto out_inval;
651 }
652 }
653out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000655 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100656}
657
658int qeth_l3_setrouting_v4(struct qeth_card *card)
659{
660 int rc;
661
Carsten Otte847a50f2010-06-21 22:57:05 +0000662 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100663
Stefan Raspl82e2e782013-03-18 20:04:43 +0000664 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100665 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000666 if (rc)
667 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100668
669 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
670 QETH_PROT_IPV4);
671 if (rc) {
672 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200673 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
674 " on %s. Type set to 'no router'.\n", rc,
675 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100676 }
677 return rc;
678}
679
680int qeth_l3_setrouting_v6(struct qeth_card *card)
681{
682 int rc = 0;
683
Carsten Otte847a50f2010-06-21 22:57:05 +0000684 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100685#ifdef CONFIG_QETH_IPV6
686
687 if (!qeth_is_supported(card, IPA_IPV6))
688 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000689 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100690 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000691 if (rc)
692 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100693
694 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
695 QETH_PROT_IPV6);
696 if (rc) {
697 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200698 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
699 " on %s. Type set to 'no router'.\n", rc,
700 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100701 }
702#endif
703 return rc;
704}
705
706/*
707 * IP address takeover related functions
708 */
709static void qeth_l3_clear_ipato_list(struct qeth_card *card)
710{
711
712 struct qeth_ipato_entry *ipatoe, *tmp;
713 unsigned long flags;
714
715 spin_lock_irqsave(&card->ip_lock, flags);
716 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
717 list_del(&ipatoe->entry);
718 kfree(ipatoe);
719 }
720 spin_unlock_irqrestore(&card->ip_lock, flags);
721}
722
723int qeth_l3_add_ipato_entry(struct qeth_card *card,
724 struct qeth_ipato_entry *new)
725{
726 struct qeth_ipato_entry *ipatoe;
727 unsigned long flags;
728 int rc = 0;
729
Carsten Otte847a50f2010-06-21 22:57:05 +0000730 QETH_CARD_TEXT(card, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731 spin_lock_irqsave(&card->ip_lock, flags);
732 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
733 if (ipatoe->proto != new->proto)
734 continue;
735 if (!memcmp(ipatoe->addr, new->addr,
736 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
737 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100738 rc = -EEXIST;
739 break;
740 }
741 }
742 if (!rc)
743 list_add_tail(&new->entry, &card->ipato.entries);
744
745 spin_unlock_irqrestore(&card->ip_lock, flags);
746 return rc;
747}
748
749void qeth_l3_del_ipato_entry(struct qeth_card *card,
750 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
751{
752 struct qeth_ipato_entry *ipatoe, *tmp;
753 unsigned long flags;
754
Carsten Otte847a50f2010-06-21 22:57:05 +0000755 QETH_CARD_TEXT(card, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756 spin_lock_irqsave(&card->ip_lock, flags);
757 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
758 if (ipatoe->proto != proto)
759 continue;
760 if (!memcmp(ipatoe->addr, addr,
761 (proto == QETH_PROT_IPV4)? 4:16) &&
762 (ipatoe->mask_bits == mask_bits)) {
763 list_del(&ipatoe->entry);
764 kfree(ipatoe);
765 }
766 }
767 spin_unlock_irqrestore(&card->ip_lock, flags);
768}
769
770/*
771 * VIPA related functions
772 */
773int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
774 const u8 *addr)
775{
776 struct qeth_ipaddr *ipaddr;
777 unsigned long flags;
778 int rc = 0;
779
780 ipaddr = qeth_l3_get_addr_buffer(proto);
781 if (ipaddr) {
782 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000783 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100784 memcpy(&ipaddr->u.a4.addr, addr, 4);
785 ipaddr->u.a4.mask = 0;
786 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000787 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 memcpy(&ipaddr->u.a6.addr, addr, 16);
789 ipaddr->u.a6.pfxlen = 0;
790 }
791 ipaddr->type = QETH_IP_TYPE_VIPA;
792 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
793 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
794 } else
795 return -ENOMEM;
796 spin_lock_irqsave(&card->ip_lock, flags);
797 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
798 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
799 rc = -EEXIST;
800 spin_unlock_irqrestore(&card->ip_lock, flags);
801 if (rc) {
Wei Yongjunf68bd072012-09-24 04:24:25 +0000802 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100803 return rc;
804 }
805 if (!qeth_l3_add_ip(card, ipaddr))
806 kfree(ipaddr);
807 qeth_l3_set_ip_addr_list(card);
808 return rc;
809}
810
811void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
812 const u8 *addr)
813{
814 struct qeth_ipaddr *ipaddr;
815
816 ipaddr = qeth_l3_get_addr_buffer(proto);
817 if (ipaddr) {
818 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000819 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100820 memcpy(&ipaddr->u.a4.addr, addr, 4);
821 ipaddr->u.a4.mask = 0;
822 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000823 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100824 memcpy(&ipaddr->u.a6.addr, addr, 16);
825 ipaddr->u.a6.pfxlen = 0;
826 }
827 ipaddr->type = QETH_IP_TYPE_VIPA;
828 } else
829 return;
830 if (!qeth_l3_delete_ip(card, ipaddr))
831 kfree(ipaddr);
832 qeth_l3_set_ip_addr_list(card);
833}
834
835/*
836 * proxy ARP related functions
837 */
838int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
839 const u8 *addr)
840{
841 struct qeth_ipaddr *ipaddr;
842 unsigned long flags;
843 int rc = 0;
844
845 ipaddr = qeth_l3_get_addr_buffer(proto);
846 if (ipaddr) {
847 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000848 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100849 memcpy(&ipaddr->u.a4.addr, addr, 4);
850 ipaddr->u.a4.mask = 0;
851 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000852 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853 memcpy(&ipaddr->u.a6.addr, addr, 16);
854 ipaddr->u.a6.pfxlen = 0;
855 }
856 ipaddr->type = QETH_IP_TYPE_RXIP;
857 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
858 ipaddr->del_flags = 0;
859 } else
860 return -ENOMEM;
861 spin_lock_irqsave(&card->ip_lock, flags);
862 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
863 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
864 rc = -EEXIST;
865 spin_unlock_irqrestore(&card->ip_lock, flags);
866 if (rc) {
Wei Yongjunf68bd072012-09-24 04:24:25 +0000867 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100868 return rc;
869 }
870 if (!qeth_l3_add_ip(card, ipaddr))
871 kfree(ipaddr);
872 qeth_l3_set_ip_addr_list(card);
873 return 0;
874}
875
876void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
877 const u8 *addr)
878{
879 struct qeth_ipaddr *ipaddr;
880
881 ipaddr = qeth_l3_get_addr_buffer(proto);
882 if (ipaddr) {
883 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000884 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100885 memcpy(&ipaddr->u.a4.addr, addr, 4);
886 ipaddr->u.a4.mask = 0;
887 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000888 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100889 memcpy(&ipaddr->u.a6.addr, addr, 16);
890 ipaddr->u.a6.pfxlen = 0;
891 }
892 ipaddr->type = QETH_IP_TYPE_RXIP;
893 } else
894 return;
895 if (!qeth_l3_delete_ip(card, ipaddr))
896 kfree(ipaddr);
897 qeth_l3_set_ip_addr_list(card);
898}
899
900static int qeth_l3_register_addr_entry(struct qeth_card *card,
901 struct qeth_ipaddr *addr)
902{
903 char buf[50];
904 int rc = 0;
905 int cnt = 3;
906
907 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000908 QETH_CARD_TEXT(card, 2, "setaddr4");
909 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000911 QETH_CARD_TEXT(card, 2, "setaddr6");
912 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
913 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100914 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000915 QETH_CARD_TEXT(card, 2, "setaddr?");
916 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100917 }
918 do {
919 if (addr->is_multicast)
920 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
921 else
922 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
923 addr->set_flags);
924 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000925 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100926 } while ((--cnt > 0) && rc);
927 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000928 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100930 dev_warn(&card->gdev->dev,
931 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932 }
933 return rc;
934}
935
936static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
937 struct qeth_ipaddr *addr)
938{
939 int rc = 0;
940
941 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000942 QETH_CARD_TEXT(card, 2, "deladdr4");
943 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000945 QETH_CARD_TEXT(card, 2, "deladdr6");
946 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
947 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100948 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000949 QETH_CARD_TEXT(card, 2, "deladdr?");
950 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100951 }
952 if (addr->is_multicast)
953 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
954 else
955 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
956 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200957 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000958 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959
960 return rc;
961}
962
963static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
964{
965 if (cast_type == RTN_MULTICAST)
966 return QETH_CAST_MULTICAST;
967 if (cast_type == RTN_BROADCAST)
968 return QETH_CAST_BROADCAST;
969 return QETH_CAST_UNICAST;
970}
971
972static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
973{
974 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
975 if (cast_type == RTN_MULTICAST)
976 return ct | QETH_CAST_MULTICAST;
977 if (cast_type == RTN_ANYCAST)
978 return ct | QETH_CAST_ANYCAST;
979 if (cast_type == RTN_BROADCAST)
980 return ct | QETH_CAST_BROADCAST;
981 return ct | QETH_CAST_UNICAST;
982}
983
Frank Blaschka4a71df52008-02-15 09:19:42 +0100984static int qeth_l3_setadapter_parms(struct qeth_card *card)
985{
986 int rc;
987
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200988 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989
990 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100991 dev_info(&card->gdev->dev,
992 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200993 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994 return 0;
995 }
996 rc = qeth_query_setadapterparms(card);
997 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100998 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +0000999 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000 return rc;
1001 }
1002 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1003 rc = qeth_setadpparms_change_macaddr(card);
1004 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001005 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001006 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007 }
1008
Frank Blaschka4a71df52008-02-15 09:19:42 +01001009 return rc;
1010}
1011
1012static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1013 struct qeth_reply *reply, unsigned long data)
1014{
1015 struct qeth_ipa_cmd *cmd;
1016
Carsten Otte847a50f2010-06-21 22:57:05 +00001017 QETH_CARD_TEXT(card, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018
1019 cmd = (struct qeth_ipa_cmd *) data;
1020 if (cmd->hdr.return_code == 0) {
1021 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1022 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1023 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1024 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1025 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1026 }
1027 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1028 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1029 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001030 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001031 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001032 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1033 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1034 card->info.tx_csum_mask =
1035 cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001036 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001037 }
1038
Frank Blaschka4a71df52008-02-15 09:19:42 +01001039 return 0;
1040}
1041
1042static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1043 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1044 __u16 len, enum qeth_prot_versions prot)
1045{
1046 struct qeth_cmd_buffer *iob;
1047 struct qeth_ipa_cmd *cmd;
1048
Carsten Otte847a50f2010-06-21 22:57:05 +00001049 QETH_CARD_TEXT(card, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001050 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1051
1052 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1053 cmd->data.setassparms.hdr.assist_no = ipa_func;
1054 cmd->data.setassparms.hdr.length = 8 + len;
1055 cmd->data.setassparms.hdr.command_code = cmd_code;
1056 cmd->data.setassparms.hdr.return_code = 0;
1057 cmd->data.setassparms.hdr.seq_no = 0;
1058
1059 return iob;
1060}
1061
1062static int qeth_l3_send_setassparms(struct qeth_card *card,
1063 struct qeth_cmd_buffer *iob, __u16 len, long data,
1064 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1065 unsigned long),
1066 void *reply_param)
1067{
1068 int rc;
1069 struct qeth_ipa_cmd *cmd;
1070
Carsten Otte847a50f2010-06-21 22:57:05 +00001071 QETH_CARD_TEXT(card, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001072
1073 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1074 if (len <= sizeof(__u32))
1075 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1076 else /* (len > sizeof(__u32)) */
1077 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1078
1079 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1080 return rc;
1081}
1082
1083#ifdef CONFIG_QETH_IPV6
1084static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1085 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1086{
1087 int rc;
1088 struct qeth_cmd_buffer *iob;
1089
Carsten Otte847a50f2010-06-21 22:57:05 +00001090 QETH_CARD_TEXT(card, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1092 0, QETH_PROT_IPV6);
1093 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1094 qeth_l3_default_setassparms_cb, NULL);
1095 return rc;
1096}
1097#endif
1098
1099static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1100 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1101{
1102 int rc;
1103 int length = 0;
1104 struct qeth_cmd_buffer *iob;
1105
Carsten Otte847a50f2010-06-21 22:57:05 +00001106 QETH_CARD_TEXT(card, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001107 if (data)
1108 length = sizeof(__u32);
1109 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1110 length, QETH_PROT_IPV4);
1111 rc = qeth_l3_send_setassparms(card, iob, length, data,
1112 qeth_l3_default_setassparms_cb, NULL);
1113 return rc;
1114}
1115
1116static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1117{
1118 int rc;
1119
Carsten Otte847a50f2010-06-21 22:57:05 +00001120 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001121
1122 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001123 dev_info(&card->gdev->dev,
1124 "ARP processing not supported on %s!\n",
1125 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001126 return 0;
1127 }
1128 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1129 IPA_CMD_ASS_START, 0);
1130 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001131 dev_warn(&card->gdev->dev,
1132 "Starting ARP processing support for %s failed\n",
1133 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001134 }
1135 return rc;
1136}
1137
1138static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1139{
1140 int rc;
1141
Carsten Otte847a50f2010-06-21 22:57:05 +00001142 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143
1144 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001145 dev_info(&card->gdev->dev,
1146 "Hardware IP fragmentation not supported on %s\n",
1147 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001148 return -EOPNOTSUPP;
1149 }
1150
1151 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1152 IPA_CMD_ASS_START, 0);
1153 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001154 dev_warn(&card->gdev->dev,
1155 "Starting IP fragmentation support for %s failed\n",
1156 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001157 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001158 dev_info(&card->gdev->dev,
1159 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160 return rc;
1161}
1162
1163static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1164{
1165 int rc;
1166
Carsten Otte847a50f2010-06-21 22:57:05 +00001167 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001168
Frank Blaschka4a71df52008-02-15 09:19:42 +01001169 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001170 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001171 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001172 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001173 return -EOPNOTSUPP;
1174 }
1175
1176 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1177 IPA_CMD_ASS_START, 0);
1178 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001179 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001180 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001181 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001182 return rc;
1183}
1184
1185static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1186{
1187 int rc = 0;
1188
Carsten Otte847a50f2010-06-21 22:57:05 +00001189 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001190
1191 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001192 dev_info(&card->gdev->dev,
1193 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001194 return -EOPNOTSUPP;
1195 }
1196
1197 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1198 IPA_CMD_ASS_START, 0);
1199 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001200 dev_warn(&card->gdev->dev,
1201 "Starting VLAN support for %s failed\n",
1202 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001203 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001204 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001205 }
1206 return rc;
1207}
1208
1209static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1210{
1211 int rc;
1212
Carsten Otte847a50f2010-06-21 22:57:05 +00001213 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001214
1215 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001216 dev_info(&card->gdev->dev,
1217 "Multicast not supported on %s\n",
1218 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001219 return -EOPNOTSUPP;
1220 }
1221
1222 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1223 IPA_CMD_ASS_START, 0);
1224 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001225 dev_warn(&card->gdev->dev,
1226 "Starting multicast support for %s failed\n",
1227 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001229 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230 card->dev->flags |= IFF_MULTICAST;
1231 }
1232 return rc;
1233}
1234
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235#ifdef CONFIG_QETH_IPV6
1236static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1237{
1238 int rc;
1239
Carsten Otte847a50f2010-06-21 22:57:05 +00001240 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241
1242 if (card->info.type == QETH_CARD_TYPE_IQD)
1243 goto out;
1244
Frank Blaschka1da74b12011-05-12 18:45:02 +00001245 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001246 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001247 dev_err(&card->gdev->dev,
1248 "Activating IPv6 support for %s failed\n",
1249 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001250 return rc;
1251 }
1252 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1253 IPA_CMD_ASS_START, 3);
1254 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001255 dev_err(&card->gdev->dev,
1256 "Activating IPv6 support for %s failed\n",
1257 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001258 return rc;
1259 }
1260 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1261 IPA_CMD_ASS_START);
1262 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001263 dev_err(&card->gdev->dev,
1264 "Activating IPv6 support for %s failed\n",
1265 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001266 return rc;
1267 }
1268 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1269 IPA_CMD_ASS_START);
1270 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001271 dev_warn(&card->gdev->dev,
1272 "Enabling the passthrough mode for %s failed\n",
1273 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001274 return rc;
1275 }
1276out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001277 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001278 return 0;
1279}
1280#endif
1281
1282static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1283{
1284 int rc = 0;
1285
Carsten Otte847a50f2010-06-21 22:57:05 +00001286 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001287
1288 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001289 dev_info(&card->gdev->dev,
1290 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001291 return 0;
1292 }
1293#ifdef CONFIG_QETH_IPV6
1294 rc = qeth_l3_softsetup_ipv6(card);
1295#endif
1296 return rc ;
1297}
1298
1299static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1300{
1301 int rc;
1302
Carsten Otte847a50f2010-06-21 22:57:05 +00001303 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001304 card->info.broadcast_capable = 0;
1305 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001306 dev_info(&card->gdev->dev,
1307 "Broadcast not supported on %s\n",
1308 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001309 rc = -EOPNOTSUPP;
1310 goto out;
1311 }
1312 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1313 IPA_CMD_ASS_START, 0);
1314 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001315 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1316 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001317 goto out;
1318 }
1319
1320 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1321 IPA_CMD_ASS_CONFIGURE, 1);
1322 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001323 dev_warn(&card->gdev->dev,
1324 "Setting up broadcast filtering for %s failed\n",
1325 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001326 goto out;
1327 }
1328 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001329 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001330 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1331 IPA_CMD_ASS_ENABLE, 1);
1332 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001333 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1334 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335 goto out;
1336 }
1337 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1338out:
1339 if (card->info.broadcast_capable)
1340 card->dev->flags |= IFF_BROADCAST;
1341 else
1342 card->dev->flags &= ~IFF_BROADCAST;
1343 return rc;
1344}
1345
1346static int qeth_l3_send_checksum_command(struct qeth_card *card)
1347{
1348 int rc;
1349
1350 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1351 IPA_CMD_ASS_START, 0);
1352 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001353 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1354 "failed, using SW checksumming\n",
1355 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001356 return rc;
1357 }
1358 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1359 IPA_CMD_ASS_ENABLE,
1360 card->info.csum_mask);
1361 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001362 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1363 "failed, using SW checksumming\n",
1364 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365 return rc;
1366 }
1367 return 0;
1368}
1369
Martin Schwidefskyc4736d92011-10-30 15:17:11 +01001370static int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001371{
1372 int rc = 0;
1373
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001374 if (on) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001375 rc = qeth_l3_send_checksum_command(card);
1376 if (rc)
1377 return -EIO;
1378 dev_info(&card->gdev->dev,
1379 "HW Checksumming (inbound) enabled\n");
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001380 } else {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001381 rc = qeth_l3_send_simple_setassparms(card,
1382 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1383 if (rc)
1384 return -EIO;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001385 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001386
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001387 return 0;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001388}
1389
Frank Blaschka4a71df52008-02-15 09:19:42 +01001390static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1391{
Carsten Otte847a50f2010-06-21 22:57:05 +00001392 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001393
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001394 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001395 rtnl_lock();
1396 /* force set_features call */
1397 card->dev->features &= ~NETIF_F_RXCSUM;
1398 netdev_update_features(card->dev);
1399 rtnl_unlock();
1400 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001401 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001402}
1403
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001404static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1405{
1406 int rc = 0;
1407
1408 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1409 return rc;
1410 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1411 IPA_CMD_ASS_START, 0);
1412 if (rc)
1413 goto err_out;
1414 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1415 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1416 if (rc)
1417 goto err_out;
1418 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1419 return rc;
1420err_out:
1421 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1422 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1423 return rc;
1424}
1425
Frank Blaschka4a71df52008-02-15 09:19:42 +01001426static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1427{
1428 int rc;
1429
Carsten Otte847a50f2010-06-21 22:57:05 +00001430 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001431
1432 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001433 dev_info(&card->gdev->dev,
1434 "Outbound TSO not supported on %s\n",
1435 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001436 rc = -EOPNOTSUPP;
1437 } else {
1438 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1439 IPA_CMD_ASS_START, 0);
1440 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001441 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1442 "segmentation offload for %s failed\n",
1443 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001444 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001445 dev_info(&card->gdev->dev,
1446 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001447 }
Michał Mirosław6204b472011-04-19 00:43:20 +00001448 if (rc)
1449 card->dev->features &= ~NETIF_F_TSO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001450 return rc;
1451}
1452
1453static int qeth_l3_start_ipassists(struct qeth_card *card)
1454{
Carsten Otte847a50f2010-06-21 22:57:05 +00001455 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001456
Stefan Raspl0f547612013-01-21 02:30:20 +00001457 if (qeth_set_access_ctrl_online(card, 0))
1458 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001459 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1460 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1461 qeth_l3_start_ipa_source_mac(card); /* go on*/
1462 qeth_l3_start_ipa_vlan(card); /* go on*/
1463 qeth_l3_start_ipa_multicast(card); /* go on*/
1464 qeth_l3_start_ipa_ipv6(card); /* go on*/
1465 qeth_l3_start_ipa_broadcast(card); /* go on*/
1466 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001467 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001468 qeth_l3_start_ipa_tso(card); /* go on*/
1469 return 0;
1470}
1471
Frank Blaschka4a71df52008-02-15 09:19:42 +01001472static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1473 struct qeth_reply *reply, unsigned long data)
1474{
1475 struct qeth_ipa_cmd *cmd;
1476
1477 cmd = (struct qeth_ipa_cmd *) data;
1478 if (cmd->hdr.return_code == 0)
1479 memcpy(card->dev->dev_addr,
1480 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1481 else
Joe Perches18336112012-07-12 22:33:10 -07001482 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001483
1484 return 0;
1485}
1486
1487static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1488{
1489 int rc = 0;
1490 struct qeth_cmd_buffer *iob;
1491 struct qeth_ipa_cmd *cmd;
1492
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001493 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001494
1495 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1496 QETH_PROT_IPV6);
1497 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1498 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1499 card->info.unique_id;
1500
1501 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1502 NULL);
1503 return rc;
1504}
1505
1506static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1507 struct qeth_reply *reply, unsigned long data)
1508{
1509 struct qeth_ipa_cmd *cmd;
1510
1511 cmd = (struct qeth_ipa_cmd *) data;
1512 if (cmd->hdr.return_code == 0)
1513 card->info.unique_id = *((__u16 *)
1514 &cmd->data.create_destroy_addr.unique_id[6]);
1515 else {
1516 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1517 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001518 dev_warn(&card->gdev->dev, "The network adapter failed to "
1519 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001520 }
1521 return 0;
1522}
1523
1524static int qeth_l3_get_unique_id(struct qeth_card *card)
1525{
1526 int rc = 0;
1527 struct qeth_cmd_buffer *iob;
1528 struct qeth_ipa_cmd *cmd;
1529
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001530 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001531
1532 if (!qeth_is_supported(card, IPA_IPV6)) {
1533 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1534 UNIQUE_ID_NOT_BY_CARD;
1535 return 0;
1536 }
1537
1538 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1539 QETH_PROT_IPV6);
1540 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1541 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1542 card->info.unique_id;
1543
1544 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1545 return rc;
1546}
1547
Ursula Braun76b11f82010-01-11 02:50:50 +00001548static int
1549qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1550 unsigned long data)
1551{
1552 struct qeth_ipa_cmd *cmd;
1553 __u16 rc;
1554
1555 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1556
1557 cmd = (struct qeth_ipa_cmd *)data;
1558 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001559 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001560 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001561 switch (cmd->data.diagass.action) {
1562 case QETH_DIAGS_CMD_TRACE_QUERY:
1563 break;
1564 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001565 switch (rc) {
1566 case 0:
1567 case IPA_RC_INVALID_SUBCMD:
1568 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1569 dev_info(&card->gdev->dev, "The HiperSockets network "
1570 "traffic analyzer is deactivated\n");
1571 break;
1572 default:
1573 break;
1574 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001575 break;
1576 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001577 switch (rc) {
1578 case 0:
1579 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1580 dev_info(&card->gdev->dev, "The HiperSockets network "
1581 "traffic analyzer is activated\n");
1582 break;
1583 case IPA_RC_HARDWARE_AUTH_ERROR:
1584 dev_warn(&card->gdev->dev, "The device is not "
1585 "authorized to run as a HiperSockets network "
1586 "traffic analyzer\n");
1587 break;
1588 case IPA_RC_TRACE_ALREADY_ACTIVE:
1589 dev_warn(&card->gdev->dev, "A HiperSockets "
1590 "network traffic analyzer is already "
1591 "active in the HiperSockets LAN\n");
1592 break;
1593 default:
1594 break;
1595 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001596 break;
1597 default:
1598 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1599 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1600 }
1601
1602 return 0;
1603}
1604
1605static int
1606qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1607{
1608 struct qeth_cmd_buffer *iob;
1609 struct qeth_ipa_cmd *cmd;
1610
1611 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1612
1613 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1614 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1615 cmd->data.diagass.subcmd_len = 16;
1616 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1617 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1618 cmd->data.diagass.action = diags_cmd;
1619 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1620}
1621
Frank Blaschka4a71df52008-02-15 09:19:42 +01001622static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1623 struct net_device *dev)
1624{
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001625 ip_eth_mc_map(ipm, mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001626}
1627
1628static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1629{
1630 struct qeth_ipaddr *ipm;
1631 struct ip_mc_list *im4;
1632 char buf[MAX_ADDR_LEN];
1633
Carsten Otte847a50f2010-06-21 22:57:05 +00001634 QETH_CARD_TEXT(card, 4, "addmc");
Sachin Santf3aa3132010-11-26 02:41:17 +00001635 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1636 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001637 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1638 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1639 if (!ipm)
1640 continue;
1641 ipm->u.a4.addr = im4->multiaddr;
1642 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1643 ipm->is_multicast = 1;
1644 if (!qeth_l3_add_ip(card, ipm))
1645 kfree(ipm);
1646 }
1647}
1648
Jiri Pirko0347af52013-01-03 22:48:58 +00001649/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001650static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1651{
1652 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001653 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001654
Carsten Otte847a50f2010-06-21 22:57:05 +00001655 QETH_CARD_TEXT(card, 4, "addmcvl");
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001656 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001657 return;
1658
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001659 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1660 struct net_device *netdev;
1661
dingtianhongf06c7f92014-05-09 14:58:05 +08001662 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001663 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001664 if (netdev == NULL ||
1665 !(netdev->flags & IFF_UP))
1666 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001667 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001668 if (!in_dev)
1669 continue;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001670 qeth_l3_add_mc(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001671 }
1672}
1673
1674static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1675{
1676 struct in_device *in4_dev;
1677
Carsten Otte847a50f2010-06-21 22:57:05 +00001678 QETH_CARD_TEXT(card, 4, "chkmcv4");
Sachin Santf3aa3132010-11-26 02:41:17 +00001679 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001680 in4_dev = __in_dev_get_rcu(card->dev);
1681 if (in4_dev == NULL)
1682 goto unlock;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001683 qeth_l3_add_mc(card, in4_dev);
1684 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001685unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001686 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001687}
1688
1689#ifdef CONFIG_QETH_IPV6
1690static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1691{
1692 struct qeth_ipaddr *ipm;
1693 struct ifmcaddr6 *im6;
1694 char buf[MAX_ADDR_LEN];
1695
Carsten Otte847a50f2010-06-21 22:57:05 +00001696 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001697 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1698 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1699 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1700 if (!ipm)
1701 continue;
1702 ipm->is_multicast = 1;
1703 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1704 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1705 sizeof(struct in6_addr));
1706 if (!qeth_l3_add_ip(card, ipm))
1707 kfree(ipm);
1708 }
1709}
1710
Jiri Pirko0347af52013-01-03 22:48:58 +00001711/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001712static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1713{
1714 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001715 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001716
Carsten Otte847a50f2010-06-21 22:57:05 +00001717 QETH_CARD_TEXT(card, 4, "admc6vl");
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001718 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001719 return;
1720
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001721 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1722 struct net_device *netdev;
1723
dingtianhongf06c7f92014-05-09 14:58:05 +08001724 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001725 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001726 if (netdev == NULL ||
1727 !(netdev->flags & IFF_UP))
1728 continue;
1729 in_dev = in6_dev_get(netdev);
1730 if (!in_dev)
1731 continue;
1732 read_lock_bh(&in_dev->lock);
1733 qeth_l3_add_mc6(card, in_dev);
1734 read_unlock_bh(&in_dev->lock);
1735 in6_dev_put(in_dev);
1736 }
1737}
1738
1739static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1740{
1741 struct inet6_dev *in6_dev;
1742
Carsten Otte847a50f2010-06-21 22:57:05 +00001743 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001744 if (!qeth_is_supported(card, IPA_IPV6))
1745 return ;
1746 in6_dev = in6_dev_get(card->dev);
1747 if (in6_dev == NULL)
1748 return;
Jiri Pirko0347af52013-01-03 22:48:58 +00001749 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001750 read_lock_bh(&in6_dev->lock);
1751 qeth_l3_add_mc6(card, in6_dev);
1752 qeth_l3_add_vlan_mc6(card);
1753 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001754 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001755 in6_dev_put(in6_dev);
1756}
1757#endif /* CONFIG_QETH_IPV6 */
1758
1759static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1760 unsigned short vid)
1761{
1762 struct in_device *in_dev;
1763 struct in_ifaddr *ifa;
1764 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001765 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001766
Carsten Otte847a50f2010-06-21 22:57:05 +00001767 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001768
dingtianhongf06c7f92014-05-09 14:58:05 +08001769 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001770 if (!netdev)
1771 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001772 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001773 if (!in_dev)
1774 return;
1775 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1776 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1777 if (addr) {
1778 addr->u.a4.addr = ifa->ifa_address;
1779 addr->u.a4.mask = ifa->ifa_mask;
1780 addr->type = QETH_IP_TYPE_NORMAL;
1781 if (!qeth_l3_delete_ip(card, addr))
1782 kfree(addr);
1783 }
1784 }
1785 in_dev_put(in_dev);
1786}
1787
1788static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1789 unsigned short vid)
1790{
1791#ifdef CONFIG_QETH_IPV6
1792 struct inet6_dev *in6_dev;
1793 struct inet6_ifaddr *ifa;
1794 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001795 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001796
Carsten Otte847a50f2010-06-21 22:57:05 +00001797 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001798
dingtianhongf06c7f92014-05-09 14:58:05 +08001799 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001800 if (!netdev)
1801 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001802 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001803 if (!in6_dev)
1804 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001805 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001806 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1807 if (addr) {
1808 memcpy(&addr->u.a6.addr, &ifa->addr,
1809 sizeof(struct in6_addr));
1810 addr->u.a6.pfxlen = ifa->prefix_len;
1811 addr->type = QETH_IP_TYPE_NORMAL;
1812 if (!qeth_l3_delete_ip(card, addr))
1813 kfree(addr);
1814 }
1815 }
1816 in6_dev_put(in6_dev);
1817#endif /* CONFIG_QETH_IPV6 */
1818}
1819
1820static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1821 unsigned short vid)
1822{
Jiri Pirko0347af52013-01-03 22:48:58 +00001823 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001824 qeth_l3_free_vlan_addresses4(card, vid);
1825 qeth_l3_free_vlan_addresses6(card, vid);
Jiri Pirko0347af52013-01-03 22:48:58 +00001826 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001827}
1828
Patrick McHardy80d5c362013-04-19 02:04:28 +00001829static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1830 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001831{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001832 struct qeth_card *card = dev->ml_priv;
1833
1834 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001835 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001836}
1837
Patrick McHardy80d5c362013-04-19 02:04:28 +00001838static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1839 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001840{
Heiko Carstens509e2562008-07-26 02:24:10 -07001841 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001842 unsigned long flags;
1843
Carsten Otte847a50f2010-06-21 22:57:05 +00001844 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00001845 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001846 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001847 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001848 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001849 spin_lock_irqsave(&card->vlanlock, flags);
1850 /* unregister IP addresses of vlan device */
1851 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001852 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001853 spin_unlock_irqrestore(&card->vlanlock, flags);
1854 qeth_l3_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001855 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001856}
1857
Ursula Braun10651db2010-10-01 02:51:13 +00001858static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1859 struct sk_buff *skb, struct qeth_hdr *hdr,
1860 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001861{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001862 __be16 prot;
1863 struct iphdr *ip_hdr;
1864 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001865 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001866
1867 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1868 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1869 ETH_P_IP);
1870 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1871 case QETH_CAST_MULTICAST:
1872 switch (prot) {
1873#ifdef CONFIG_QETH_IPV6
1874 case __constant_htons(ETH_P_IPV6):
1875 ndisc_mc_map((struct in6_addr *)
1876 skb->data + 24,
1877 tg_addr, card->dev, 0);
1878 break;
1879#endif
1880 case __constant_htons(ETH_P_IP):
1881 ip_hdr = (struct iphdr *)skb->data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001882 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1883 break;
1884 default:
1885 memcpy(tg_addr, card->dev->broadcast,
1886 card->dev->addr_len);
1887 }
1888 card->stats.multicast++;
1889 skb->pkt_type = PACKET_MULTICAST;
1890 break;
1891 case QETH_CAST_BROADCAST:
1892 memcpy(tg_addr, card->dev->broadcast,
1893 card->dev->addr_len);
1894 card->stats.multicast++;
1895 skb->pkt_type = PACKET_BROADCAST;
1896 break;
1897 case QETH_CAST_UNICAST:
1898 case QETH_CAST_ANYCAST:
1899 case QETH_CAST_NOCAST:
1900 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001901 if (card->options.sniffer)
1902 skb->pkt_type = PACKET_OTHERHOST;
1903 else
1904 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001905 memcpy(tg_addr, card->dev->dev_addr,
1906 card->dev->addr_len);
1907 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001908 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1909 card->dev->header_ops->create(skb, card->dev, prot,
1910 tg_addr, &hdr->hdr.l3.dest_addr[2],
1911 card->dev->addr_len);
1912 else
1913 card->dev->header_ops->create(skb, card->dev, prot,
1914 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001915 }
1916
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001917 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001918
1919 if (hdr->hdr.l3.ext_flags &
1920 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001921 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001922 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001923 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001924 }
1925
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001926 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001927 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001928 (QETH_HDR_EXT_CSUM_HDR_REQ |
1929 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1930 (QETH_HDR_EXT_CSUM_HDR_REQ |
1931 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001932 skb->ip_summed = CHECKSUM_UNNECESSARY;
1933 else
Ursula Braunb9139802009-05-19 21:38:40 +00001934 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001935 } else
1936 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001937
Ursula Braun10651db2010-10-01 02:51:13 +00001938 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001939}
1940
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001941static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1942 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001943{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001944 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001945 struct sk_buff *skb;
1946 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001947 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001948 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001949 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001950 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001951
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001952 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001953 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001954 while (budget) {
1955 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001956 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001957 &card->rx.b_element, &card->rx.e_offset, &hdr);
1958 if (!skb) {
1959 *done = 1;
1960 break;
1961 }
1962 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001963 switch (hdr->hdr.l3.id) {
1964 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001965 magic = *(__u16 *)skb->data;
1966 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1967 (magic == ETH_P_AF_IUCV)) {
1968 skb->protocol = ETH_P_AF_IUCV;
1969 skb->pkt_type = PACKET_HOST;
1970 skb->mac_header = NET_SKB_PAD;
1971 skb->dev = card->dev;
1972 len = skb->len;
1973 card->dev->header_ops->create(skb, card->dev, 0,
1974 card->dev->dev_addr, "FAKELL",
1975 card->dev->addr_len);
1976 netif_receive_skb(skb);
1977 } else {
1978 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
Ursula Braun10651db2010-10-01 02:51:13 +00001979 &vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001980 len = skb->len;
1981 if (is_vlan && !card->options.sniffer)
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001982 __vlan_hwaccel_put_tag(skb,
1983 htons(ETH_P_8021Q), vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001984 napi_gro_receive(&card->napi, skb);
1985 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001986 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001987 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
1988 skb->pkt_type = PACKET_HOST;
1989 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001990 len = skb->len;
1991 netif_receive_skb(skb);
1992 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001993 default:
1994 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001995 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001996 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001997 continue;
1998 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001999 work_done++;
2000 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002001 card->stats.rx_packets++;
2002 card->stats.rx_bytes += len;
2003 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002004 return work_done;
2005}
2006
2007static int qeth_l3_poll(struct napi_struct *napi, int budget)
2008{
2009 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2010 int work_done = 0;
2011 struct qeth_qdio_buffer *buffer;
2012 int done;
2013 int new_budget = budget;
2014
2015 if (card->options.performance_stats) {
2016 card->perf_stats.inbound_cnt++;
2017 card->perf_stats.inbound_start_time = qeth_get_micros();
2018 }
2019
2020 while (1) {
2021 if (!card->rx.b_count) {
2022 card->rx.qdio_err = 0;
2023 card->rx.b_count = qdio_get_next_buffers(
2024 card->data.ccwdev, 0, &card->rx.b_index,
2025 &card->rx.qdio_err);
2026 if (card->rx.b_count <= 0) {
2027 card->rx.b_count = 0;
2028 break;
2029 }
2030 card->rx.b_element =
2031 &card->qdio.in_q->bufs[card->rx.b_index]
2032 .buffer->element[0];
2033 card->rx.e_offset = 0;
2034 }
2035
2036 while (card->rx.b_count) {
2037 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2038 if (!(card->rx.qdio_err &&
2039 qeth_check_qdio_errors(card, buffer->buffer,
2040 card->rx.qdio_err, "qinerr")))
2041 work_done += qeth_l3_process_inbound_buffer(
2042 card, new_budget, &done);
2043 else
2044 done = 1;
2045
2046 if (done) {
2047 if (card->options.performance_stats)
2048 card->perf_stats.bufs_rec++;
2049 qeth_put_buffer_pool_entry(card,
2050 buffer->pool_entry);
2051 qeth_queue_input_buffer(card, card->rx.b_index);
2052 card->rx.b_count--;
2053 if (card->rx.b_count) {
2054 card->rx.b_index =
2055 (card->rx.b_index + 1) %
2056 QDIO_MAX_BUFFERS_PER_Q;
2057 card->rx.b_element =
2058 &card->qdio.in_q
2059 ->bufs[card->rx.b_index]
2060 .buffer->element[0];
2061 card->rx.e_offset = 0;
2062 }
2063 }
2064
2065 if (work_done >= budget)
2066 goto out;
2067 else
2068 new_budget = budget - work_done;
2069 }
2070 }
2071
2072 napi_complete(napi);
2073 if (qdio_start_irq(card->data.ccwdev, 0))
2074 napi_schedule(&card->napi);
2075out:
2076 if (card->options.performance_stats)
2077 card->perf_stats.inbound_time += qeth_get_micros() -
2078 card->perf_stats.inbound_start_time;
2079 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002080}
2081
2082static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2083 struct qeth_card *card)
2084{
2085 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002086 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002087
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002088 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
2089 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002090
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002091 rcu_read_lock();
dingtianhongf06c7f92014-05-09 14:58:05 +08002092 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00002093 vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002094 rcu_read_unlock();
2095 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002096 rc = QETH_VLAN_CARD;
2097 break;
2098 }
2099 }
2100
Heiko Carstens509e2562008-07-26 02:24:10 -07002101 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002102 return 0;
2103
2104 return rc;
2105}
2106
2107static int qeth_l3_verify_dev(struct net_device *dev)
2108{
2109 struct qeth_card *card;
2110 unsigned long flags;
2111 int rc = 0;
2112
2113 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2114 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2115 if (card->dev == dev) {
2116 rc = QETH_REAL_CARD;
2117 break;
2118 }
2119 rc = qeth_l3_verify_vlan_dev(dev, card);
2120 if (rc)
2121 break;
2122 }
2123 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2124
2125 return rc;
2126}
2127
2128static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2129{
2130 struct qeth_card *card = NULL;
2131 int rc;
2132
2133 rc = qeth_l3_verify_dev(dev);
2134 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002135 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002136 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002137 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002138 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002139 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002140 if (card)
2141 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002142 return card ;
2143}
2144
2145static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2146{
2147 int rc = 0;
2148
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002149 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2150 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002151
2152 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002153 if (card->options.sniffer &&
2154 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2155 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002156 if (card->read.state == CH_STATE_UP &&
2157 card->write.state == CH_STATE_UP &&
2158 (card->state == CARD_STATE_UP)) {
2159 if (recovery_mode)
2160 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002161 else {
Ursula Braun869da902010-03-08 20:36:56 +00002162 rtnl_lock();
2163 dev_close(card->dev);
2164 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002165 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002166 card->state = CARD_STATE_SOFTSETUP;
2167 }
2168 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -08002169 qeth_l3_clear_ip_list(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002170 qeth_clear_ipacmd_list(card);
2171 card->state = CARD_STATE_HARDSETUP;
2172 }
2173 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002174 qeth_qdio_clear_card(card, 0);
2175 qeth_clear_qdio_buffers(card);
2176 qeth_clear_working_pool_list(card);
2177 card->state = CARD_STATE_DOWN;
2178 }
2179 if (card->state == CARD_STATE_DOWN) {
2180 qeth_clear_cmd_buffers(&card->read);
2181 qeth_clear_cmd_buffers(&card->write);
2182 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002183 return rc;
2184}
2185
Ursula Braun76b11f82010-01-11 02:50:50 +00002186/*
2187 * test for and Switch promiscuous mode (on or off)
2188 * either for guestlan or HiperSocket Sniffer
2189 */
2190static void
2191qeth_l3_handle_promisc_mode(struct qeth_card *card)
2192{
2193 struct net_device *dev = card->dev;
2194
2195 if (((dev->flags & IFF_PROMISC) &&
2196 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2197 (!(dev->flags & IFF_PROMISC) &&
2198 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2199 return;
2200
2201 if (card->info.guestlan) { /* Guestlan trace */
2202 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2203 qeth_setadp_promisc_mode(card);
2204 } else if (card->options.sniffer && /* HiperSockets trace */
2205 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2206 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002207 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002208 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2209 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002210 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002211 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2212 }
2213 }
2214}
2215
Frank Blaschka4a71df52008-02-15 09:19:42 +01002216static void qeth_l3_set_multicast_list(struct net_device *dev)
2217{
Heiko Carstens509e2562008-07-26 02:24:10 -07002218 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002219
Carsten Otte847a50f2010-06-21 22:57:05 +00002220 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002221 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2222 (card->state != CARD_STATE_UP))
2223 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002224 if (!card->options.sniffer) {
2225 qeth_l3_delete_mc_addresses(card);
2226 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002227#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002228 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002229#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002230 qeth_l3_set_ip_addr_list(card);
2231 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2232 return;
2233 }
2234 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002235}
2236
2237static const char *qeth_l3_arp_get_error_cause(int *rc)
2238{
2239 switch (*rc) {
2240 case QETH_IPA_ARP_RC_FAILED:
2241 *rc = -EIO;
2242 return "operation failed";
2243 case QETH_IPA_ARP_RC_NOTSUPP:
2244 *rc = -EOPNOTSUPP;
2245 return "operation not supported";
2246 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2247 *rc = -EINVAL;
2248 return "argument out of range";
2249 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2250 *rc = -EOPNOTSUPP;
2251 return "query operation not supported";
2252 case QETH_IPA_ARP_RC_Q_NO_DATA:
2253 *rc = -ENOENT;
2254 return "no query data available";
2255 default:
2256 return "unknown error";
2257 }
2258}
2259
2260static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2261{
2262 int tmp;
2263 int rc;
2264
Carsten Otte847a50f2010-06-21 22:57:05 +00002265 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002266
2267 /*
2268 * currently GuestLAN only supports the ARP assist function
2269 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2270 * thus we say EOPNOTSUPP for this ARP function
2271 */
2272 if (card->info.guestlan)
2273 return -EOPNOTSUPP;
2274 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002275 return -EOPNOTSUPP;
2276 }
2277 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2278 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2279 no_entries);
2280 if (rc) {
2281 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002282 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2283 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002284 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2285 }
2286 return rc;
2287}
2288
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002289static __u32 get_arp_entry_size(struct qeth_card *card,
2290 struct qeth_arp_query_data *qdata,
2291 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002292{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002293 __u32 rc;
2294 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002295
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002296 is_hsi = qdata->reply_bits == 5;
2297 if (type->ip == QETHARP_IP_ADDR_V4) {
2298 QETH_CARD_TEXT(card, 4, "arpev4");
2299 if (strip_entries) {
2300 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2301 sizeof(struct qeth_arp_qi_entry7_short);
2302 } else {
2303 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2304 sizeof(struct qeth_arp_qi_entry7);
2305 }
2306 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2307 QETH_CARD_TEXT(card, 4, "arpev6");
2308 if (strip_entries) {
2309 rc = is_hsi ?
2310 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2311 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2312 } else {
2313 rc = is_hsi ?
2314 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2315 sizeof(struct qeth_arp_qi_entry7_ipv6);
2316 }
2317 } else {
2318 QETH_CARD_TEXT(card, 4, "arpinv");
2319 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002320 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002321
2322 return rc;
2323}
2324
2325static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2326{
2327 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2328 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002329}
2330
2331static int qeth_l3_arp_query_cb(struct qeth_card *card,
2332 struct qeth_reply *reply, unsigned long data)
2333{
2334 struct qeth_ipa_cmd *cmd;
2335 struct qeth_arp_query_data *qdata;
2336 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002337 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002338 int e;
2339 int entrybytes_done;
2340 int stripped_bytes;
2341 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002342
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002343 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002344
2345 qinfo = (struct qeth_arp_query_info *) reply->param;
2346 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002347 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002348 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002349 QETH_CARD_TEXT(card, 4, "arpcberr");
2350 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002351 return 0;
2352 }
2353 if (cmd->data.setassparms.hdr.return_code) {
2354 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002355 QETH_CARD_TEXT(card, 4, "setaperr");
2356 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002357 return 0;
2358 }
2359 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002360 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002361
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002362 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2363 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2364 entrybytes_done = 0;
2365 for (e = 0; e < qdata->no_entries; ++e) {
2366 char *cur_entry;
2367 __u32 esize;
2368 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002369
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002370 cur_entry = &qdata->data + entrybytes_done;
2371 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2372 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2373 QETH_CARD_TEXT(card, 4, "pmis");
2374 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2375 break;
2376 }
2377 esize = get_arp_entry_size(card, qdata, etype,
2378 do_strip_entries);
2379 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2380 if (!esize)
2381 break;
2382
2383 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2384 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00002385 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002386 goto out_error;
2387 }
2388
2389 memcpy(qinfo->udata + qinfo->udata_offset,
2390 &qdata->data + entrybytes_done + stripped_bytes,
2391 esize);
2392 entrybytes_done += esize + stripped_bytes;
2393 qinfo->udata_offset += esize;
2394 ++qinfo->no_entries;
2395 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002396 /* check if all replies received ... */
2397 if (cmd->data.setassparms.hdr.seq_no <
2398 cmd->data.setassparms.hdr.number_of_replies)
2399 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002400 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002401 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2402 /* keep STRIP_ENTRIES flag so the user program can distinguish
2403 * stripped entries from normal ones */
2404 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2405 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2406 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002407 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002408 return 0;
2409out_error:
2410 i = 0;
2411 memcpy(qinfo->udata, &i, 4);
2412 return 0;
2413}
2414
2415static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2416 struct qeth_cmd_buffer *iob, int len,
2417 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2418 unsigned long),
2419 void *reply_param)
2420{
Carsten Otte847a50f2010-06-21 22:57:05 +00002421 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002422
2423 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2424 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2425 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2426 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2427 reply_cb, reply_param);
2428}
2429
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002430static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2431 enum qeth_prot_versions prot,
2432 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002433{
2434 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002435 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002436 int tmp;
2437 int rc;
2438
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002439 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2440
2441 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2442 IPA_CMD_ASS_ARP_QUERY_INFO,
2443 sizeof(struct qeth_arp_query_data) - sizeof(char),
2444 prot);
2445 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2446 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2447 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2448 cmd->data.setassparms.data.query_arp.no_entries = 0;
2449 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2450 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2451 qeth_l3_arp_query_cb, (void *)qinfo);
2452 if (rc) {
2453 tmp = rc;
2454 QETH_DBF_MESSAGE(2,
2455 "Error while querying ARP cache on %s: %s "
2456 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2457 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2458 }
2459
2460 return rc;
2461}
2462
2463static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2464{
2465 struct qeth_arp_query_info qinfo = {0, };
2466 int rc;
2467
Carsten Otte847a50f2010-06-21 22:57:05 +00002468 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002469
2470 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2471 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002472 QETH_CARD_TEXT(card, 3, "arpqnsup");
2473 rc = -EOPNOTSUPP;
2474 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002475 }
2476 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002477 if (copy_from_user(&qinfo, udata, 6)) {
2478 rc = -EFAULT;
2479 goto out;
2480 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002481 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002482 if (!qinfo.udata) {
2483 rc = -ENOMEM;
2484 goto out;
2485 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002486 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002487 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002488 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002489 if (copy_to_user(udata, qinfo.udata, 4))
2490 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002491 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002492 } else {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002493#ifdef CONFIG_QETH_IPV6
2494 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2495 /* fails in case of GuestLAN QDIO mode */
2496 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2497 &qinfo);
2498 }
2499#endif
2500 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2501 QETH_CARD_TEXT(card, 4, "qactf");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002502 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002503 goto free_and_out;
2504 }
Thomas Richter8a593142014-10-22 12:18:03 +02002505 QETH_CARD_TEXT(card, 4, "qacts");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002506 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002507free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002508 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002509out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002510 return rc;
2511}
2512
2513static int qeth_l3_arp_add_entry(struct qeth_card *card,
2514 struct qeth_arp_cache_entry *entry)
2515{
2516 struct qeth_cmd_buffer *iob;
2517 char buf[16];
2518 int tmp;
2519 int rc;
2520
Carsten Otte847a50f2010-06-21 22:57:05 +00002521 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002522
2523 /*
2524 * currently GuestLAN only supports the ARP assist function
2525 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2526 * thus we say EOPNOTSUPP for this ARP function
2527 */
2528 if (card->info.guestlan)
2529 return -EOPNOTSUPP;
2530 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002531 return -EOPNOTSUPP;
2532 }
2533
2534 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2535 IPA_CMD_ASS_ARP_ADD_ENTRY,
2536 sizeof(struct qeth_arp_cache_entry),
2537 QETH_PROT_IPV4);
2538 rc = qeth_l3_send_setassparms(card, iob,
2539 sizeof(struct qeth_arp_cache_entry),
2540 (unsigned long) entry,
2541 qeth_l3_default_setassparms_cb, NULL);
2542 if (rc) {
2543 tmp = rc;
2544 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002545 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2546 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2547 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002548 }
2549 return rc;
2550}
2551
2552static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2553 struct qeth_arp_cache_entry *entry)
2554{
2555 struct qeth_cmd_buffer *iob;
2556 char buf[16] = {0, };
2557 int tmp;
2558 int rc;
2559
Carsten Otte847a50f2010-06-21 22:57:05 +00002560 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002561
2562 /*
2563 * currently GuestLAN only supports the ARP assist function
2564 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2565 * thus we say EOPNOTSUPP for this ARP function
2566 */
2567 if (card->info.guestlan)
2568 return -EOPNOTSUPP;
2569 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002570 return -EOPNOTSUPP;
2571 }
2572 memcpy(buf, entry, 12);
2573 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2574 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2575 12,
2576 QETH_PROT_IPV4);
2577 rc = qeth_l3_send_setassparms(card, iob,
2578 12, (unsigned long)buf,
2579 qeth_l3_default_setassparms_cb, NULL);
2580 if (rc) {
2581 tmp = rc;
2582 memset(buf, 0, 16);
2583 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002584 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2585 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2586 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002587 }
2588 return rc;
2589}
2590
2591static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2592{
2593 int rc;
2594 int tmp;
2595
Carsten Otte847a50f2010-06-21 22:57:05 +00002596 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002597
2598 /*
2599 * currently GuestLAN only supports the ARP assist function
2600 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2601 * thus we say EOPNOTSUPP for this ARP function
2602 */
2603 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2604 return -EOPNOTSUPP;
2605 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002606 return -EOPNOTSUPP;
2607 }
2608 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2609 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2610 if (rc) {
2611 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002612 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2613 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002614 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2615 }
2616 return rc;
2617}
2618
2619static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2620{
Heiko Carstens509e2562008-07-26 02:24:10 -07002621 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002622 struct qeth_arp_cache_entry arp_entry;
2623 struct mii_ioctl_data *mii_data;
2624 int rc = 0;
2625
2626 if (!card)
2627 return -ENODEV;
2628
2629 if ((card->state != CARD_STATE_UP) &&
2630 (card->state != CARD_STATE_SOFTSETUP))
2631 return -ENODEV;
2632
2633 switch (cmd) {
2634 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2635 if (!capable(CAP_NET_ADMIN)) {
2636 rc = -EPERM;
2637 break;
2638 }
2639 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2640 break;
2641 case SIOC_QETH_ARP_QUERY_INFO:
2642 if (!capable(CAP_NET_ADMIN)) {
2643 rc = -EPERM;
2644 break;
2645 }
2646 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2647 break;
2648 case SIOC_QETH_ARP_ADD_ENTRY:
2649 if (!capable(CAP_NET_ADMIN)) {
2650 rc = -EPERM;
2651 break;
2652 }
2653 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2654 sizeof(struct qeth_arp_cache_entry)))
2655 rc = -EFAULT;
2656 else
2657 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2658 break;
2659 case SIOC_QETH_ARP_REMOVE_ENTRY:
2660 if (!capable(CAP_NET_ADMIN)) {
2661 rc = -EPERM;
2662 break;
2663 }
2664 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2665 sizeof(struct qeth_arp_cache_entry)))
2666 rc = -EFAULT;
2667 else
2668 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2669 break;
2670 case SIOC_QETH_ARP_FLUSH_CACHE:
2671 if (!capable(CAP_NET_ADMIN)) {
2672 rc = -EPERM;
2673 break;
2674 }
2675 rc = qeth_l3_arp_flush_cache(card);
2676 break;
2677 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2678 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2679 break;
2680 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002681 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2682 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002683 !card->info.guestlan)
2684 return 1;
2685 return 0;
2686 break;
2687 case SIOCGMIIPHY:
2688 mii_data = if_mii(rq);
2689 mii_data->phy_id = 0;
2690 break;
2691 case SIOCGMIIREG:
2692 mii_data = if_mii(rq);
2693 if (mii_data->phy_id != 0)
2694 rc = -EINVAL;
2695 else
2696 mii_data->val_out = qeth_mdio_read(dev,
2697 mii_data->phy_id,
2698 mii_data->reg_num);
2699 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +00002700 case SIOC_QETH_QUERY_OAT:
2701 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
2702 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002703 default:
2704 rc = -EOPNOTSUPP;
2705 }
2706 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002707 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002708 return rc;
2709}
2710
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002711int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2712{
2713 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002714 struct neighbour *n = NULL;
2715 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002716
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002717 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002718 dst = skb_dst(skb);
2719 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002720 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002721 if (n) {
2722 cast_type = n->type;
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002723 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002724 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002725 if ((cast_type == RTN_BROADCAST) ||
2726 (cast_type == RTN_MULTICAST) ||
2727 (cast_type == RTN_ANYCAST))
2728 return cast_type;
2729 else
2730 return RTN_UNSPEC;
2731 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002732 rcu_read_unlock();
2733
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002734 /* try something else */
2735 if (skb->protocol == ETH_P_IPV6)
2736 return (skb_network_header(skb)[24] == 0xff) ?
2737 RTN_MULTICAST : 0;
2738 else if (skb->protocol == ETH_P_IP)
2739 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2740 RTN_MULTICAST : 0;
2741 /* ... */
2742 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2743 return RTN_BROADCAST;
2744 else {
2745 u16 hdr_mac;
2746
2747 hdr_mac = *((u16 *)skb->data);
2748 /* tr multicast? */
2749 switch (card->info.link_type) {
2750 case QETH_LINK_TYPE_HSTR:
2751 case QETH_LINK_TYPE_LANE_TR:
2752 if ((hdr_mac == QETH_TR_MAC_NC) ||
2753 (hdr_mac == QETH_TR_MAC_C))
2754 return RTN_MULTICAST;
2755 break;
2756 /* eth or so multicast? */
2757 default:
2758 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2759 (hdr_mac == QETH_ETH_MAC_V6))
2760 return RTN_MULTICAST;
2761 }
2762 }
2763 return cast_type;
2764}
2765
Frank Blaschkab3332932011-08-08 01:33:59 +00002766static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2767 struct qeth_hdr *hdr, struct sk_buff *skb)
2768{
2769 char daddr[16];
2770 struct af_iucv_trans_hdr *iucv_hdr;
2771
2772 skb_pull(skb, 14);
2773 card->dev->header_ops->create(skb, card->dev, 0,
2774 card->dev->dev_addr, card->dev->dev_addr,
2775 card->dev->addr_len);
2776 skb_pull(skb, 14);
2777 iucv_hdr = (struct af_iucv_trans_hdr *)skb->data;
2778 memset(hdr, 0, sizeof(struct qeth_hdr));
2779 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2780 hdr->hdr.l3.ext_flags = 0;
2781 hdr->hdr.l3.length = skb->len;
2782 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
2783 memset(daddr, 0, sizeof(daddr));
2784 daddr[0] = 0xfe;
2785 daddr[1] = 0x80;
2786 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2787 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2788}
2789
Frank Blaschka4a71df52008-02-15 09:19:42 +01002790static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2791 struct sk_buff *skb, int ipv, int cast_type)
2792{
David S. Miller69cce1d2011-07-17 23:09:49 -07002793 struct dst_entry *dst;
2794
Frank Blaschka4a71df52008-02-15 09:19:42 +01002795 memset(hdr, 0, sizeof(struct qeth_hdr));
2796 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2797 hdr->hdr.l3.ext_flags = 0;
2798
2799 /*
2800 * before we're going to overwrite this location with next hop ip.
2801 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2802 */
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002803 if (vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002804 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2805 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2806 else
2807 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002808 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2809 }
2810
2811 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002812
2813 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002814 dst = skb_dst(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002815 if (ipv == 4) {
David Miller87e75972012-02-01 10:49:17 +00002816 struct rtable *rt = (struct rtable *) dst;
2817 __be32 *pkey = &ip_hdr(skb)->daddr;
2818
2819 if (rt->rt_gateway)
2820 pkey = &rt->rt_gateway;
2821
Frank Blaschka4a71df52008-02-15 09:19:42 +01002822 /* IPv4 */
2823 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2824 memset(hdr->hdr.l3.dest_addr, 0, 12);
David Miller87e75972012-02-01 10:49:17 +00002825 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002826 } else if (ipv == 6) {
David Miller87e75972012-02-01 10:49:17 +00002827 struct rt6_info *rt = (struct rt6_info *) dst;
2828 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2829
2830 if (!ipv6_addr_any(&rt->rt6i_gateway))
2831 pkey = &rt->rt6i_gateway;
2832
Frank Blaschka4a71df52008-02-15 09:19:42 +01002833 /* IPv6 */
2834 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2835 if (card->info.type == QETH_CARD_TYPE_IQD)
2836 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David Miller87e75972012-02-01 10:49:17 +00002837 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002838 } else {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002839 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002840 skb->dev->broadcast, 6)) {
2841 /* broadcast? */
2842 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2843 QETH_HDR_PASSTHRU;
2844 } else {
2845 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2846 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2847 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2848 }
2849 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002850 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002851}
2852
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002853static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2854 struct qeth_hdr *hdr, struct sk_buff *skb)
2855{
2856 struct iphdr *iph = ip_hdr(skb);
2857
2858 /* tcph->check contains already the pseudo hdr checksum
2859 * so just set the header flags
2860 */
2861 if (iph->protocol == IPPROTO_UDP)
2862 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002863 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2864 QETH_HDR_EXT_CSUM_HDR_REQ;
2865 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002866 if (card->options.performance_stats)
2867 card->perf_stats.tx_csum++;
2868}
2869
Frank Blaschka64ef8952009-03-24 20:57:16 +00002870static void qeth_tso_fill_header(struct qeth_card *card,
2871 struct qeth_hdr *qhdr, struct sk_buff *skb)
2872{
2873 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2874 struct tcphdr *tcph = tcp_hdr(skb);
2875 struct iphdr *iph = ip_hdr(skb);
2876 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2877
2878 /*fix header to TSO values ...*/
2879 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002880 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002881 /*set values which are fix for the first approach ...*/
2882 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2883 hdr->ext.imb_hdr_no = 1;
2884 hdr->ext.hdr_type = 1;
2885 hdr->ext.hdr_version = 1;
2886 hdr->ext.hdr_len = 28;
2887 /*insert non-fix values */
2888 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2889 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2890 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2891 sizeof(struct qeth_hdr_tso));
2892 tcph->check = 0;
2893 if (skb->protocol == ETH_P_IPV6) {
2894 ip6h->payload_len = 0;
2895 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2896 0, IPPROTO_TCP, 0);
2897 } else {
2898 /*OSA want us to set these values ...*/
2899 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2900 0, IPPROTO_TCP, 0);
2901 iph->tot_len = 0;
2902 iph->check = 0;
2903 }
2904}
2905
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002906static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2907{
2908 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2909 tcp_hdr(skb)->doff * 4;
2910 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002911 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschka271648b2013-03-18 20:04:44 +00002912
2913 elements += qeth_get_elements_for_frags(skb);
2914
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002915 return elements;
2916}
2917
Frank Blaschka4a71df52008-02-15 09:19:42 +01002918static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2919{
2920 int rc;
2921 u16 *tag;
2922 struct qeth_hdr *hdr = NULL;
2923 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002924 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002925 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002926 struct sk_buff *new_skb = NULL;
2927 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002928 int cast_type = qeth_l3_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002929 struct qeth_qdio_out_q *queue =
2930 card->qdio.out_qs[card->qdio.do_prio_queueing
2931 || (cast_type && card->info.is_multicast_different) ?
2932 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2933 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002934 int tx_bytes = skb->len;
Michał Mirosław6204b472011-04-19 00:43:20 +00002935 bool large_send;
Frank Blaschka683d7182008-08-01 16:39:13 +02002936 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002937 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002938
Frank Blaschkab3332932011-08-08 01:33:59 +00002939 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2940 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2941 ((card->options.cq == QETH_CQ_ENABLED) &&
2942 (skb->protocol != ETH_P_AF_IUCV)))) ||
2943 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002944 goto tx_drop;
2945
2946 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2947 card->stats.tx_carrier_errors++;
2948 goto tx_drop;
2949 }
2950
2951 if ((cast_type == RTN_BROADCAST) &&
2952 (card->info.broadcast_capable == 0))
2953 goto tx_drop;
2954
2955 if (card->options.performance_stats) {
2956 card->perf_stats.outbound_cnt++;
2957 card->perf_stats.outbound_start_time = qeth_get_micros();
2958 }
2959
Michał Mirosław6204b472011-04-19 00:43:20 +00002960 large_send = skb_is_gso(skb);
Frank Blaschka683d7182008-08-01 16:39:13 +02002961
2962 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2963 (skb_shinfo(skb)->nr_frags == 0)) {
2964 new_skb = skb;
Frank Blaschkab3332932011-08-08 01:33:59 +00002965 if (new_skb->protocol == ETH_P_AF_IUCV)
2966 data_offset = 0;
2967 else
2968 data_offset = ETH_HLEN;
Frank Blaschka683d7182008-08-01 16:39:13 +02002969 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2970 if (!hdr)
2971 goto tx_drop;
2972 elements_needed++;
2973 } else {
2974 /* create a clone with writeable headroom */
2975 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2976 + VLAN_HLEN);
2977 if (!new_skb)
2978 goto tx_drop;
2979 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002980
2981 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002982 if (data_offset < 0)
2983 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002984 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00002985 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002986 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002987 }
2988
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002989 if (ipv != 4 && vlan_tx_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002990 skb_push(new_skb, VLAN_HLEN);
2991 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2992 skb_copy_to_linear_data_offset(new_skb, 4,
2993 new_skb->data + 8, 4);
2994 skb_copy_to_linear_data_offset(new_skb, 8,
2995 new_skb->data + 12, 4);
2996 tag = (u16 *)(new_skb->data + 12);
2997 *tag = __constant_htons(ETH_P_8021Q);
2998 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002999 }
3000 }
3001
3002 netif_stop_queue(dev);
3003
Frank Blaschka4a71df52008-02-15 09:19:42 +01003004 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003005 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003006 */
Michał Mirosław6204b472011-04-19 00:43:20 +00003007 if (large_send) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003008 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3009 if (skb_linearize(new_skb))
3010 goto tx_drop;
3011 if (card->options.performance_stats)
3012 card->perf_stats.tx_lin++;
3013 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003014 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003015
Michał Mirosław6204b472011-04-19 00:43:20 +00003016 if (large_send && (cast_type == RTN_UNSPEC)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003017 hdr = (struct qeth_hdr *)skb_push(new_skb,
3018 sizeof(struct qeth_hdr_tso));
3019 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3020 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3021 qeth_tso_fill_header(card, hdr, new_skb);
3022 elements_needed++;
3023 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003024 if (data_offset < 0) {
3025 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003026 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003027 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3028 cast_type);
3029 } else {
Frank Blaschkab3332932011-08-08 01:33:59 +00003030 if (new_skb->protocol == ETH_P_AF_IUCV)
3031 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
3032 else {
3033 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3034 cast_type);
3035 hdr->hdr.l3.length = new_skb->len - data_offset;
3036 }
Frank Blaschka683d7182008-08-01 16:39:13 +02003037 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003038
3039 if (skb->ip_summed == CHECKSUM_PARTIAL)
3040 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003041 }
3042
Stefan Raspl065cc782013-04-22 01:12:28 +00003043 elems = qeth_get_elements_no(card, new_skb, elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003044 if (!elems) {
3045 if (data_offset >= 0)
3046 kmem_cache_free(qeth_core_header_cache, hdr);
3047 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003048 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003049 elements_needed += elems;
3050 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003051
Frank Blaschka51aa1652010-06-21 22:57:10 +00003052 if (card->info.type != QETH_CARD_TYPE_IQD) {
3053 int len;
Michał Mirosław6204b472011-04-19 00:43:20 +00003054 if (large_send)
Frank Blaschka51aa1652010-06-21 22:57:10 +00003055 len = ((unsigned long)tcp_hdr(new_skb) +
3056 tcp_hdr(new_skb)->doff * 4) -
3057 (unsigned long)new_skb->data;
3058 else
3059 len = sizeof(struct qeth_hdr_layer3);
3060
Stefan Raspld4ae1f52013-04-22 01:12:29 +00003061 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00003062 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003063 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003064 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003065 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003066 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003067 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003068
3069 if (!rc) {
3070 card->stats.tx_packets++;
3071 card->stats.tx_bytes += tx_bytes;
3072 if (new_skb != skb)
3073 dev_kfree_skb_any(skb);
3074 if (card->options.performance_stats) {
Michał Mirosław6204b472011-04-19 00:43:20 +00003075 if (large_send) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003076 card->perf_stats.large_send_bytes += tx_bytes;
3077 card->perf_stats.large_send_cnt++;
3078 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003079 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003080 card->perf_stats.sg_skbs_sent++;
3081 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003082 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003083 }
3084 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003085 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003086 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003087 if (data_offset >= 0)
3088 kmem_cache_free(qeth_core_header_cache, hdr);
3089
Frank Blaschka4a71df52008-02-15 09:19:42 +01003090 if (rc == -EBUSY) {
3091 if (new_skb != skb)
3092 dev_kfree_skb_any(new_skb);
3093 return NETDEV_TX_BUSY;
3094 } else
3095 goto tx_drop;
3096 }
3097
3098 netif_wake_queue(dev);
3099 if (card->options.performance_stats)
3100 card->perf_stats.outbound_time += qeth_get_micros() -
3101 card->perf_stats.outbound_start_time;
3102 return rc;
3103
3104tx_drop:
3105 card->stats.tx_dropped++;
3106 card->stats.tx_errors++;
3107 if ((new_skb != skb) && new_skb)
3108 dev_kfree_skb_any(new_skb);
3109 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003110 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003111 return NETDEV_TX_OK;
3112}
3113
Ursula Braun39423442011-01-12 20:42:24 +00003114static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003115{
Heiko Carstens509e2562008-07-26 02:24:10 -07003116 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003117 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003118
Carsten Otte847a50f2010-06-21 22:57:05 +00003119 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00003120 if (card->state == CARD_STATE_UP)
3121 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003122 if (card->state != CARD_STATE_SOFTSETUP)
3123 return -ENODEV;
3124 card->data.state = CH_STATE_UP;
3125 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003126 netif_start_queue(dev);
3127
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003128 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3129 napi_enable(&card->napi);
3130 napi_schedule(&card->napi);
3131 } else
3132 rc = -EIO;
3133 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003134}
3135
Ursula Braun39423442011-01-12 20:42:24 +00003136static int qeth_l3_open(struct net_device *dev)
3137{
3138 struct qeth_card *card = dev->ml_priv;
3139
3140 QETH_CARD_TEXT(card, 5, "qethope_");
3141 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3142 QETH_CARD_TEXT(card, 3, "openREC");
3143 return -ERESTARTSYS;
3144 }
3145 return __qeth_l3_open(dev);
3146}
3147
Frank Blaschka4a71df52008-02-15 09:19:42 +01003148static int qeth_l3_stop(struct net_device *dev)
3149{
Heiko Carstens509e2562008-07-26 02:24:10 -07003150 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003151
Carsten Otte847a50f2010-06-21 22:57:05 +00003152 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003153 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003154 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003155 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003156 napi_disable(&card->napi);
3157 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003158 return 0;
3159}
3160
Michał Mirosławc8f44af2011-11-15 15:29:55 +00003161static netdev_features_t qeth_l3_fix_features(struct net_device *dev,
3162 netdev_features_t features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003163{
Heiko Carstens509e2562008-07-26 02:24:10 -07003164 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003165
Michał Mirosław6204b472011-04-19 00:43:20 +00003166 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3167 features &= ~NETIF_F_IP_CSUM;
3168 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
3169 features &= ~NETIF_F_TSO;
3170 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
3171 features &= ~NETIF_F_RXCSUM;
3172
3173 return features;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003174}
3175
Michał Mirosławc8f44af2011-11-15 15:29:55 +00003176static int qeth_l3_set_features(struct net_device *dev,
3177 netdev_features_t features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003178{
Michał Mirosław6204b472011-04-19 00:43:20 +00003179 struct qeth_card *card = dev->ml_priv;
3180 u32 changed = dev->features ^ features;
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003181 int err;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003182
Michał Mirosław6204b472011-04-19 00:43:20 +00003183 if (!(changed & NETIF_F_RXCSUM))
3184 return 0;
3185
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003186 if (card->state == CARD_STATE_DOWN ||
3187 card->state == CARD_STATE_RECOVER)
3188 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003189
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003190 err = qeth_l3_set_rx_csum(card, features & NETIF_F_RXCSUM);
3191 if (err)
3192 dev->features = features ^ NETIF_F_RXCSUM;
3193
3194 return err;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003195}
3196
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003197static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003198 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003199 .get_strings = qeth_core_get_strings,
3200 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003201 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003202 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003203 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003204};
3205
3206/*
3207 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3208 * NOARP on the netdevice is no option because it also turns off neighbor
3209 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3210 * arp resolution but we want the hard header (packet socket will work
3211 * e.g. tcpdump)
3212 */
3213static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3214{
3215 n->nud_state = NUD_NOARP;
3216 memcpy(n->ha, "FAKELL", 6);
3217 n->output = n->ops->connected_output;
3218 return 0;
3219}
3220
3221static int
3222qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3223{
3224 if (np->tbl->family == AF_INET)
3225 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3226
3227 return 0;
3228}
3229
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003230static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003231 .ndo_open = qeth_l3_open,
3232 .ndo_stop = qeth_l3_stop,
3233 .ndo_get_stats = qeth_get_stats,
3234 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3235 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003236 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003237 .ndo_do_ioctl = qeth_l3_do_ioctl,
3238 .ndo_change_mtu = qeth_change_mtu,
3239 .ndo_fix_features = qeth_l3_fix_features,
3240 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003241 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3242 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003243 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08003244};
3245
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003246static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3247 .ndo_open = qeth_l3_open,
3248 .ndo_stop = qeth_l3_stop,
3249 .ndo_get_stats = qeth_get_stats,
3250 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3251 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003252 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003253 .ndo_do_ioctl = qeth_l3_do_ioctl,
3254 .ndo_change_mtu = qeth_change_mtu,
3255 .ndo_fix_features = qeth_l3_fix_features,
3256 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003257 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3258 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003259 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003260 .ndo_neigh_setup = qeth_l3_neigh_setup,
3261};
3262
Frank Blaschka4a71df52008-02-15 09:19:42 +01003263static int qeth_l3_setup_netdev(struct qeth_card *card)
3264{
Ursula Braun5113fec2010-05-16 21:15:14 +00003265 if (card->info.type == QETH_CARD_TYPE_OSD ||
3266 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003267 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3268 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04003269 pr_info("qeth_l3: ignoring TR device\n");
3270 return -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003271 } else {
3272 card->dev = alloc_etherdev(0);
3273 if (!card->dev)
3274 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003275 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003276
3277 /*IPv6 address autoconfiguration stuff*/
3278 qeth_l3_get_unique_id(card);
3279 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3280 card->dev->dev_id = card->info.unique_id &
3281 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003282 if (!card->info.guestlan) {
3283 card->dev->hw_features = NETIF_F_SG |
3284 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3285 NETIF_F_TSO;
3286 card->dev->features = NETIF_F_RXCSUM;
3287 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003288 }
3289 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02003290 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
3291 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003292 if (!card->dev)
3293 return -ENODEV;
3294 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003295 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003296 qeth_l3_iqd_read_initial_mac(card);
Frank Blaschkab3332932011-08-08 01:33:59 +00003297 if (card->options.hsuid[0])
3298 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003299 } else
3300 return -ENODEV;
3301
Heiko Carstens509e2562008-07-26 02:24:10 -07003302 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003303 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003304 card->dev->mtu = card->info.initial_mtu;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003305 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00003306 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
3307 NETIF_F_HW_VLAN_CTAG_RX |
3308 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07003309 netif_keep_dst(card->dev);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003310 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003311
3312 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003313 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003314 return register_netdev(card->dev);
3315}
3316
Frank Blaschka4a71df52008-02-15 09:19:42 +01003317static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3318{
3319 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3320
3321 qeth_l3_create_device_attributes(&gdev->dev);
3322 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003323 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003324 return 0;
3325}
3326
3327static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3328{
3329 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3330
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003331 qeth_l3_remove_device_attributes(&cgdev->dev);
3332
Ursula Braunf2148562009-05-19 21:38:37 +00003333 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003334 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3335
Ursula Braun70919e22011-02-26 22:41:36 -08003336 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003337 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003338
3339 if (card->dev) {
3340 unregister_netdev(card->dev);
3341 card->dev = NULL;
3342 }
3343
Ursula Braun70919e22011-02-26 22:41:36 -08003344 qeth_l3_clear_ip_list(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003345 qeth_l3_clear_ipato_list(card);
3346 return;
3347}
3348
3349static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3350{
3351 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3352 int rc = 0;
3353 enum qeth_card_states recover_flag;
3354
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003355 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003356 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003357 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3358 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003359
Frank Blaschka4a71df52008-02-15 09:19:42 +01003360 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003361 rc = qeth_core_hardsetup_card(card);
3362 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003363 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003364 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003365 goto out_remove;
3366 }
3367
Ursula Braunaa909222009-11-12 00:11:43 +00003368 if (!card->dev && qeth_l3_setup_netdev(card)) {
3369 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003370 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003371 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003372
Frank Blaschka1da74b12011-05-12 18:45:02 +00003373 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3374 if (card->info.hwtrap &&
3375 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3376 card->info.hwtrap = 0;
3377 } else
3378 card->info.hwtrap = 0;
3379
Frank Blaschka4a71df52008-02-15 09:19:42 +01003380 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003381 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003382 qeth_print_status_message(card);
3383
3384 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003385 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003386
3387 rc = qeth_send_startlan(card);
3388 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003389 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003390 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003391 dev_warn(&card->gdev->dev,
3392 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003393 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003394 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003395 }
Ursula Braunaa909222009-11-12 00:11:43 +00003396 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003397 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003398 } else
3399 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003400
Ursula Braun2b6203b2010-11-26 02:41:19 +00003401contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003402 rc = qeth_l3_setadapter_parms(card);
3403 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003404 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003405 if (!card->options.sniffer) {
3406 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00003407 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00003408 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00003409 goto out_remove;
3410 }
Ursula Braun76b11f82010-01-11 02:50:50 +00003411 rc = qeth_l3_setrouting_v4(card);
3412 if (rc)
3413 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3414 rc = qeth_l3_setrouting_v6(card);
3415 if (rc)
3416 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3417 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003418 netif_tx_disable(card->dev);
3419
3420 rc = qeth_init_qdio_queues(card);
3421 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003422 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003423 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003424 goto out_remove;
3425 }
3426 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003427
3428 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003429 qeth_l3_set_ip_addr_list(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003430 if (card->lan_online)
3431 netif_carrier_on(card->dev);
3432 else
3433 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003434 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00003435 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003436 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003437 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003438 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003439 dev_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003440 qeth_l3_set_multicast_list(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003441 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003442 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00003443 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003444 /* let user_space know that device is online */
3445 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003446 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003447 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003448 return 0;
3449out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003450 qeth_l3_stop_card(card, 0);
3451 ccw_device_set_offline(CARD_DDEV(card));
3452 ccw_device_set_offline(CARD_WDEV(card));
3453 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01003454 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003455 if (recover_flag == CARD_STATE_RECOVER)
3456 card->state = CARD_STATE_RECOVER;
3457 else
3458 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003459 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003460 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003461 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003462}
3463
3464static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3465{
3466 return __qeth_l3_set_online(gdev, 0);
3467}
3468
3469static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3470 int recovery_mode)
3471{
3472 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3473 int rc = 0, rc2 = 0, rc3 = 0;
3474 enum qeth_card_states recover_flag;
3475
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003476 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003477 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003478 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3479 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003480
3481 if (card->dev && netif_carrier_ok(card->dev))
3482 netif_carrier_off(card->dev);
3483 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003484 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3485 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3486 card->info.hwtrap = 1;
3487 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003488 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00003489 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3490 rtnl_lock();
3491 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3492 rtnl_unlock();
3493 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003494 rc = ccw_device_set_offline(CARD_DDEV(card));
3495 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3496 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3497 if (!rc)
3498 rc = (rc2) ? rc2 : rc3;
3499 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003500 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01003501 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003502 if (recover_flag == CARD_STATE_UP)
3503 card->state = CARD_STATE_RECOVER;
3504 /* let user_space know that device is offline */
3505 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003506 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003507 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003508 return 0;
3509}
3510
3511static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3512{
3513 return __qeth_l3_set_offline(cgdev, 0);
3514}
3515
3516static int qeth_l3_recover(void *ptr)
3517{
3518 struct qeth_card *card;
3519 int rc = 0;
3520
3521 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003522 QETH_CARD_TEXT(card, 2, "recover1");
3523 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003524 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3525 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003526 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003527 dev_warn(&card->gdev->dev,
3528 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00003529 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003530 __qeth_l3_set_offline(card->gdev, 1);
3531 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003532 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003533 dev_info(&card->gdev->dev,
3534 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003535 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00003536 qeth_close_dev(card);
3537 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00003538 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003539 }
Stefan Raspl65d80132013-04-07 22:19:27 +00003540 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003541 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3542 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003543 return 0;
3544}
3545
3546static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3547{
3548 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00003549 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00003550 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3551 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003552 qeth_qdio_clear_card(card, 0);
3553 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01003554 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003555}
3556
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003557static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3558{
3559 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3560
3561 if (card->dev)
3562 netif_device_detach(card->dev);
3563 qeth_set_allowed_threads(card, 0, 1);
3564 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3565 if (gdev->state == CCWGROUP_OFFLINE)
3566 return 0;
3567 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003568 if (card->info.hwtrap)
3569 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003570 __qeth_l3_set_offline(card->gdev, 1);
3571 } else
3572 __qeth_l3_set_offline(card->gdev, 0);
3573 return 0;
3574}
3575
3576static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3577{
3578 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3579 int rc = 0;
3580
3581 if (gdev->state == CCWGROUP_OFFLINE)
3582 goto out;
3583
3584 if (card->state == CARD_STATE_RECOVER) {
3585 rc = __qeth_l3_set_online(card->gdev, 1);
3586 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003587 rtnl_lock();
3588 dev_close(card->dev);
3589 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003590 }
3591 } else
3592 rc = __qeth_l3_set_online(card->gdev, 0);
3593out:
3594 qeth_set_allowed_threads(card, 0xffffffff, 0);
3595 if (card->dev)
3596 netif_device_attach(card->dev);
3597 if (rc)
3598 dev_warn(&card->gdev->dev, "The qeth device driver "
3599 "failed to recover an error on the device\n");
3600 return rc;
3601}
3602
Eugene Crosserc044dc22014-01-29 09:23:48 +01003603/* Returns zero if the command is successfully "consumed" */
3604static int qeth_l3_control_event(struct qeth_card *card,
3605 struct qeth_ipa_cmd *cmd)
3606{
3607 return 1;
3608}
3609
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003610struct qeth_discipline qeth_l3_discipline = {
3611 .start_poll = qeth_qdio_start_poll,
3612 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3613 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
3614 .recover = qeth_l3_recover,
3615 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003616 .remove = qeth_l3_remove_device,
3617 .set_online = qeth_l3_set_online,
3618 .set_offline = qeth_l3_set_offline,
3619 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003620 .freeze = qeth_l3_pm_suspend,
3621 .thaw = qeth_l3_pm_resume,
3622 .restore = qeth_l3_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01003623 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003624};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003625EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003626
3627static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003628 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003629{
3630 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3631 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3632 struct qeth_ipaddr *addr;
3633 struct qeth_card *card;
3634
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003635 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003636 return NOTIFY_DONE;
3637
Frank Blaschka4a71df52008-02-15 09:19:42 +01003638 card = qeth_l3_get_card_from_dev(dev);
3639 if (!card)
3640 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00003641 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003642
3643 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3644 if (addr != NULL) {
3645 addr->u.a4.addr = ifa->ifa_address;
3646 addr->u.a4.mask = ifa->ifa_mask;
3647 addr->type = QETH_IP_TYPE_NORMAL;
3648 } else
3649 goto out;
3650
3651 switch (event) {
3652 case NETDEV_UP:
3653 if (!qeth_l3_add_ip(card, addr))
3654 kfree(addr);
3655 break;
3656 case NETDEV_DOWN:
3657 if (!qeth_l3_delete_ip(card, addr))
3658 kfree(addr);
3659 break;
3660 default:
3661 break;
3662 }
3663 qeth_l3_set_ip_addr_list(card);
3664out:
3665 return NOTIFY_DONE;
3666}
3667
3668static struct notifier_block qeth_l3_ip_notifier = {
3669 qeth_l3_ip_event,
3670 NULL,
3671};
3672
3673#ifdef CONFIG_QETH_IPV6
3674/**
3675 * IPv6 event handler
3676 */
3677static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003678 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003679{
3680 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3681 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3682 struct qeth_ipaddr *addr;
3683 struct qeth_card *card;
3684
Frank Blaschka4a71df52008-02-15 09:19:42 +01003685 card = qeth_l3_get_card_from_dev(dev);
3686 if (!card)
3687 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003688 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003689 if (!qeth_is_supported(card, IPA_IPV6))
3690 return NOTIFY_DONE;
3691
3692 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3693 if (addr != NULL) {
3694 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3695 addr->u.a6.pfxlen = ifa->prefix_len;
3696 addr->type = QETH_IP_TYPE_NORMAL;
3697 } else
3698 goto out;
3699
3700 switch (event) {
3701 case NETDEV_UP:
3702 if (!qeth_l3_add_ip(card, addr))
3703 kfree(addr);
3704 break;
3705 case NETDEV_DOWN:
3706 if (!qeth_l3_delete_ip(card, addr))
3707 kfree(addr);
3708 break;
3709 default:
3710 break;
3711 }
3712 qeth_l3_set_ip_addr_list(card);
3713out:
3714 return NOTIFY_DONE;
3715}
3716
3717static struct notifier_block qeth_l3_ip6_notifier = {
3718 qeth_l3_ip6_event,
3719 NULL,
3720};
3721#endif
3722
3723static int qeth_l3_register_notifiers(void)
3724{
3725 int rc;
3726
Carsten Otte847a50f2010-06-21 22:57:05 +00003727 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003728 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3729 if (rc)
3730 return rc;
3731#ifdef CONFIG_QETH_IPV6
3732 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3733 if (rc) {
3734 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3735 return rc;
3736 }
3737#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003738 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003739#endif
3740 return 0;
3741}
3742
3743static void qeth_l3_unregister_notifiers(void)
3744{
3745
Carsten Otte847a50f2010-06-21 22:57:05 +00003746 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00003747 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003748#ifdef CONFIG_QETH_IPV6
Stefan Raspl18af5c12012-11-19 02:46:50 +00003749 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003750#endif /* QETH_IPV6 */
3751}
3752
3753static int __init qeth_l3_init(void)
3754{
3755 int rc = 0;
3756
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003757 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003758 rc = qeth_l3_register_notifiers();
3759 return rc;
3760}
3761
3762static void __exit qeth_l3_exit(void)
3763{
3764 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003765 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003766}
3767
3768module_init(qeth_l3_init);
3769module_exit(qeth_l3_exit);
3770MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3771MODULE_DESCRIPTION("qeth layer 3 discipline");
3772MODULE_LICENSE("GPL");