blob: e2a0ee845399d64d48a5dfdb813161feeb9e58e2 [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);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100552 if (!iob)
553 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100554 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
555 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
556 if (addr->proto == QETH_PROT_IPV6)
557 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
558 sizeof(struct in6_addr));
559 else
560 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
561
562 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
563
564 return rc;
565}
566
567static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
568{
569 int i, j;
570 for (i = 0; i < 16; i++) {
571 j = (len) - (i * 8);
572 if (j >= 8)
573 netmask[i] = 0xff;
574 else if (j > 0)
575 netmask[i] = (u8)(0xFF00 >> j);
576 else
577 netmask[i] = 0;
578 }
579}
580
581static int qeth_l3_send_setdelip(struct qeth_card *card,
582 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
583{
584 int rc;
585 struct qeth_cmd_buffer *iob;
586 struct qeth_ipa_cmd *cmd;
587 __u8 netmask[16];
588
Carsten Otte847a50f2010-06-21 22:57:05 +0000589 QETH_CARD_TEXT(card, 4, "setdelip");
590 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100591
592 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100593 if (!iob)
594 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100595 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
596 if (addr->proto == QETH_PROT_IPV6) {
597 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
598 sizeof(struct in6_addr));
599 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
600 memcpy(cmd->data.setdelip6.mask, netmask,
601 sizeof(struct in6_addr));
602 cmd->data.setdelip6.flags = flags;
603 } else {
604 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
605 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
606 cmd->data.setdelip4.flags = flags;
607 }
608
609 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
610
611 return rc;
612}
613
614static int qeth_l3_send_setrouting(struct qeth_card *card,
615 enum qeth_routing_types type, enum qeth_prot_versions prot)
616{
617 int rc;
618 struct qeth_ipa_cmd *cmd;
619 struct qeth_cmd_buffer *iob;
620
Carsten Otte847a50f2010-06-21 22:57:05 +0000621 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100622 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100623 if (!iob)
624 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100625 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
626 cmd->data.setrtg.type = (type);
627 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
628
629 return rc;
630}
631
Stefan Raspl82e2e782013-03-18 20:04:43 +0000632static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100633 enum qeth_routing_types *type, enum qeth_prot_versions prot)
634{
635 if (card->info.type == QETH_CARD_TYPE_IQD) {
636 switch (*type) {
637 case NO_ROUTER:
638 case PRIMARY_CONNECTOR:
639 case SECONDARY_CONNECTOR:
640 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000641 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100642 default:
643 goto out_inval;
644 }
645 } else {
646 switch (*type) {
647 case NO_ROUTER:
648 case PRIMARY_ROUTER:
649 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000650 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100651 case MULTICAST_ROUTER:
652 if (qeth_is_ipafunc_supported(card, prot,
653 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000654 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100655 default:
656 goto out_inval;
657 }
658 }
659out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100660 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000661 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100662}
663
664int qeth_l3_setrouting_v4(struct qeth_card *card)
665{
666 int rc;
667
Carsten Otte847a50f2010-06-21 22:57:05 +0000668 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100669
Stefan Raspl82e2e782013-03-18 20:04:43 +0000670 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000672 if (rc)
673 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674
675 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
676 QETH_PROT_IPV4);
677 if (rc) {
678 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200679 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
680 " on %s. Type set to 'no router'.\n", rc,
681 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682 }
683 return rc;
684}
685
686int qeth_l3_setrouting_v6(struct qeth_card *card)
687{
688 int rc = 0;
689
Carsten Otte847a50f2010-06-21 22:57:05 +0000690 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100691#ifdef CONFIG_QETH_IPV6
692
693 if (!qeth_is_supported(card, IPA_IPV6))
694 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000695 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100696 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000697 if (rc)
698 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699
700 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
701 QETH_PROT_IPV6);
702 if (rc) {
703 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200704 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
705 " on %s. Type set to 'no router'.\n", rc,
706 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100707 }
708#endif
709 return rc;
710}
711
712/*
713 * IP address takeover related functions
714 */
715static void qeth_l3_clear_ipato_list(struct qeth_card *card)
716{
717
718 struct qeth_ipato_entry *ipatoe, *tmp;
719 unsigned long flags;
720
721 spin_lock_irqsave(&card->ip_lock, flags);
722 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
723 list_del(&ipatoe->entry);
724 kfree(ipatoe);
725 }
726 spin_unlock_irqrestore(&card->ip_lock, flags);
727}
728
729int qeth_l3_add_ipato_entry(struct qeth_card *card,
730 struct qeth_ipato_entry *new)
731{
732 struct qeth_ipato_entry *ipatoe;
733 unsigned long flags;
734 int rc = 0;
735
Carsten Otte847a50f2010-06-21 22:57:05 +0000736 QETH_CARD_TEXT(card, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100737 spin_lock_irqsave(&card->ip_lock, flags);
738 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
739 if (ipatoe->proto != new->proto)
740 continue;
741 if (!memcmp(ipatoe->addr, new->addr,
742 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
743 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100744 rc = -EEXIST;
745 break;
746 }
747 }
748 if (!rc)
749 list_add_tail(&new->entry, &card->ipato.entries);
750
751 spin_unlock_irqrestore(&card->ip_lock, flags);
752 return rc;
753}
754
755void qeth_l3_del_ipato_entry(struct qeth_card *card,
756 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
757{
758 struct qeth_ipato_entry *ipatoe, *tmp;
759 unsigned long flags;
760
Carsten Otte847a50f2010-06-21 22:57:05 +0000761 QETH_CARD_TEXT(card, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100762 spin_lock_irqsave(&card->ip_lock, flags);
763 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
764 if (ipatoe->proto != proto)
765 continue;
766 if (!memcmp(ipatoe->addr, addr,
767 (proto == QETH_PROT_IPV4)? 4:16) &&
768 (ipatoe->mask_bits == mask_bits)) {
769 list_del(&ipatoe->entry);
770 kfree(ipatoe);
771 }
772 }
773 spin_unlock_irqrestore(&card->ip_lock, flags);
774}
775
776/*
777 * VIPA related functions
778 */
779int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
780 const u8 *addr)
781{
782 struct qeth_ipaddr *ipaddr;
783 unsigned long flags;
784 int rc = 0;
785
786 ipaddr = qeth_l3_get_addr_buffer(proto);
787 if (ipaddr) {
788 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000789 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 memcpy(&ipaddr->u.a4.addr, addr, 4);
791 ipaddr->u.a4.mask = 0;
792 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000793 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100794 memcpy(&ipaddr->u.a6.addr, addr, 16);
795 ipaddr->u.a6.pfxlen = 0;
796 }
797 ipaddr->type = QETH_IP_TYPE_VIPA;
798 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
799 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
800 } else
801 return -ENOMEM;
802 spin_lock_irqsave(&card->ip_lock, flags);
803 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
804 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
805 rc = -EEXIST;
806 spin_unlock_irqrestore(&card->ip_lock, flags);
807 if (rc) {
Wei Yongjunf68bd072012-09-24 04:24:25 +0000808 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100809 return rc;
810 }
811 if (!qeth_l3_add_ip(card, ipaddr))
812 kfree(ipaddr);
813 qeth_l3_set_ip_addr_list(card);
814 return rc;
815}
816
817void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
818 const u8 *addr)
819{
820 struct qeth_ipaddr *ipaddr;
821
822 ipaddr = qeth_l3_get_addr_buffer(proto);
823 if (ipaddr) {
824 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000825 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826 memcpy(&ipaddr->u.a4.addr, addr, 4);
827 ipaddr->u.a4.mask = 0;
828 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000829 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100830 memcpy(&ipaddr->u.a6.addr, addr, 16);
831 ipaddr->u.a6.pfxlen = 0;
832 }
833 ipaddr->type = QETH_IP_TYPE_VIPA;
834 } else
835 return;
836 if (!qeth_l3_delete_ip(card, ipaddr))
837 kfree(ipaddr);
838 qeth_l3_set_ip_addr_list(card);
839}
840
841/*
842 * proxy ARP related functions
843 */
844int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
845 const u8 *addr)
846{
847 struct qeth_ipaddr *ipaddr;
848 unsigned long flags;
849 int rc = 0;
850
851 ipaddr = qeth_l3_get_addr_buffer(proto);
852 if (ipaddr) {
853 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000854 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855 memcpy(&ipaddr->u.a4.addr, addr, 4);
856 ipaddr->u.a4.mask = 0;
857 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000858 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859 memcpy(&ipaddr->u.a6.addr, addr, 16);
860 ipaddr->u.a6.pfxlen = 0;
861 }
862 ipaddr->type = QETH_IP_TYPE_RXIP;
863 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
864 ipaddr->del_flags = 0;
865 } else
866 return -ENOMEM;
867 spin_lock_irqsave(&card->ip_lock, flags);
868 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
869 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
870 rc = -EEXIST;
871 spin_unlock_irqrestore(&card->ip_lock, flags);
872 if (rc) {
Wei Yongjunf68bd072012-09-24 04:24:25 +0000873 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100874 return rc;
875 }
876 if (!qeth_l3_add_ip(card, ipaddr))
877 kfree(ipaddr);
878 qeth_l3_set_ip_addr_list(card);
879 return 0;
880}
881
882void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
883 const u8 *addr)
884{
885 struct qeth_ipaddr *ipaddr;
886
887 ipaddr = qeth_l3_get_addr_buffer(proto);
888 if (ipaddr) {
889 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000890 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100891 memcpy(&ipaddr->u.a4.addr, addr, 4);
892 ipaddr->u.a4.mask = 0;
893 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000894 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100895 memcpy(&ipaddr->u.a6.addr, addr, 16);
896 ipaddr->u.a6.pfxlen = 0;
897 }
898 ipaddr->type = QETH_IP_TYPE_RXIP;
899 } else
900 return;
901 if (!qeth_l3_delete_ip(card, ipaddr))
902 kfree(ipaddr);
903 qeth_l3_set_ip_addr_list(card);
904}
905
906static int qeth_l3_register_addr_entry(struct qeth_card *card,
907 struct qeth_ipaddr *addr)
908{
909 char buf[50];
910 int rc = 0;
911 int cnt = 3;
912
913 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000914 QETH_CARD_TEXT(card, 2, "setaddr4");
915 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000917 QETH_CARD_TEXT(card, 2, "setaddr6");
918 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
919 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000921 QETH_CARD_TEXT(card, 2, "setaddr?");
922 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100923 }
924 do {
925 if (addr->is_multicast)
926 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
927 else
928 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
929 addr->set_flags);
930 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000931 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932 } while ((--cnt > 0) && rc);
933 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000934 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100935 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100936 dev_warn(&card->gdev->dev,
937 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 }
939 return rc;
940}
941
942static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
943 struct qeth_ipaddr *addr)
944{
945 int rc = 0;
946
947 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000948 QETH_CARD_TEXT(card, 2, "deladdr4");
949 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000951 QETH_CARD_TEXT(card, 2, "deladdr6");
952 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
953 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100954 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000955 QETH_CARD_TEXT(card, 2, "deladdr?");
956 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957 }
958 if (addr->is_multicast)
959 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
960 else
961 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
962 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200963 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000964 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100965
966 return rc;
967}
968
969static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
970{
971 if (cast_type == RTN_MULTICAST)
972 return QETH_CAST_MULTICAST;
973 if (cast_type == RTN_BROADCAST)
974 return QETH_CAST_BROADCAST;
975 return QETH_CAST_UNICAST;
976}
977
978static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
979{
980 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
981 if (cast_type == RTN_MULTICAST)
982 return ct | QETH_CAST_MULTICAST;
983 if (cast_type == RTN_ANYCAST)
984 return ct | QETH_CAST_ANYCAST;
985 if (cast_type == RTN_BROADCAST)
986 return ct | QETH_CAST_BROADCAST;
987 return ct | QETH_CAST_UNICAST;
988}
989
Frank Blaschka4a71df52008-02-15 09:19:42 +0100990static int qeth_l3_setadapter_parms(struct qeth_card *card)
991{
992 int rc;
993
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200994 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100995
996 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100997 dev_info(&card->gdev->dev,
998 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200999 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000 return 0;
1001 }
1002 rc = qeth_query_setadapterparms(card);
1003 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001004 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +00001005 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001006 return rc;
1007 }
1008 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1009 rc = qeth_setadpparms_change_macaddr(card);
1010 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001011 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001012 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001013 }
1014
Frank Blaschka4a71df52008-02-15 09:19:42 +01001015 return rc;
1016}
1017
1018static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1019 struct qeth_reply *reply, unsigned long data)
1020{
1021 struct qeth_ipa_cmd *cmd;
1022
Carsten Otte847a50f2010-06-21 22:57:05 +00001023 QETH_CARD_TEXT(card, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001024
1025 cmd = (struct qeth_ipa_cmd *) data;
1026 if (cmd->hdr.return_code == 0) {
1027 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1028 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1029 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1030 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1031 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1032 }
1033 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1034 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1035 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001036 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001037 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001038 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1039 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1040 card->info.tx_csum_mask =
1041 cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001042 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001043 }
1044
Frank Blaschka4a71df52008-02-15 09:19:42 +01001045 return 0;
1046}
1047
1048static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1049 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1050 __u16 len, enum qeth_prot_versions prot)
1051{
1052 struct qeth_cmd_buffer *iob;
1053 struct qeth_ipa_cmd *cmd;
1054
Carsten Otte847a50f2010-06-21 22:57:05 +00001055 QETH_CARD_TEXT(card, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001056 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1057
Thomas Richter1aec42b2015-01-21 13:39:10 +01001058 if (iob) {
1059 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1060 cmd->data.setassparms.hdr.assist_no = ipa_func;
1061 cmd->data.setassparms.hdr.length = 8 + len;
1062 cmd->data.setassparms.hdr.command_code = cmd_code;
1063 cmd->data.setassparms.hdr.return_code = 0;
1064 cmd->data.setassparms.hdr.seq_no = 0;
1065 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001066
1067 return iob;
1068}
1069
1070static int qeth_l3_send_setassparms(struct qeth_card *card,
1071 struct qeth_cmd_buffer *iob, __u16 len, long data,
1072 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1073 unsigned long),
1074 void *reply_param)
1075{
1076 int rc;
1077 struct qeth_ipa_cmd *cmd;
1078
Carsten Otte847a50f2010-06-21 22:57:05 +00001079 QETH_CARD_TEXT(card, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001080
1081 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1082 if (len <= sizeof(__u32))
1083 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1084 else /* (len > sizeof(__u32)) */
1085 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1086
1087 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1088 return rc;
1089}
1090
1091#ifdef CONFIG_QETH_IPV6
1092static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1093 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1094{
1095 int rc;
1096 struct qeth_cmd_buffer *iob;
1097
Carsten Otte847a50f2010-06-21 22:57:05 +00001098 QETH_CARD_TEXT(card, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001099 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1100 0, QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001101 if (!iob)
1102 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001103 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1104 qeth_l3_default_setassparms_cb, NULL);
1105 return rc;
1106}
1107#endif
1108
1109static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1110 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1111{
1112 int rc;
1113 int length = 0;
1114 struct qeth_cmd_buffer *iob;
1115
Carsten Otte847a50f2010-06-21 22:57:05 +00001116 QETH_CARD_TEXT(card, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001117 if (data)
1118 length = sizeof(__u32);
1119 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1120 length, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001121 if (!iob)
1122 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001123 rc = qeth_l3_send_setassparms(card, iob, length, data,
1124 qeth_l3_default_setassparms_cb, NULL);
1125 return rc;
1126}
1127
1128static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1129{
1130 int rc;
1131
Carsten Otte847a50f2010-06-21 22:57:05 +00001132 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001133
1134 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001135 dev_info(&card->gdev->dev,
1136 "ARP processing not supported on %s!\n",
1137 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001138 return 0;
1139 }
1140 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1141 IPA_CMD_ASS_START, 0);
1142 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001143 dev_warn(&card->gdev->dev,
1144 "Starting ARP processing support for %s failed\n",
1145 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001146 }
1147 return rc;
1148}
1149
1150static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1151{
1152 int rc;
1153
Carsten Otte847a50f2010-06-21 22:57:05 +00001154 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001155
1156 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001157 dev_info(&card->gdev->dev,
1158 "Hardware IP fragmentation not supported on %s\n",
1159 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160 return -EOPNOTSUPP;
1161 }
1162
1163 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1164 IPA_CMD_ASS_START, 0);
1165 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001166 dev_warn(&card->gdev->dev,
1167 "Starting IP fragmentation support for %s failed\n",
1168 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001169 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001170 dev_info(&card->gdev->dev,
1171 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001172 return rc;
1173}
1174
1175static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1176{
1177 int rc;
1178
Carsten Otte847a50f2010-06-21 22:57:05 +00001179 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001180
Frank Blaschka4a71df52008-02-15 09:19:42 +01001181 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001182 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001183 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001184 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185 return -EOPNOTSUPP;
1186 }
1187
1188 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1189 IPA_CMD_ASS_START, 0);
1190 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001191 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001192 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001193 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001194 return rc;
1195}
1196
1197static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1198{
1199 int rc = 0;
1200
Carsten Otte847a50f2010-06-21 22:57:05 +00001201 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202
1203 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001204 dev_info(&card->gdev->dev,
1205 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001206 return -EOPNOTSUPP;
1207 }
1208
1209 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1210 IPA_CMD_ASS_START, 0);
1211 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001212 dev_warn(&card->gdev->dev,
1213 "Starting VLAN support for %s failed\n",
1214 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001215 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001216 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001217 }
1218 return rc;
1219}
1220
1221static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1222{
1223 int rc;
1224
Carsten Otte847a50f2010-06-21 22:57:05 +00001225 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001226
1227 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001228 dev_info(&card->gdev->dev,
1229 "Multicast not supported on %s\n",
1230 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231 return -EOPNOTSUPP;
1232 }
1233
1234 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1235 IPA_CMD_ASS_START, 0);
1236 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001237 dev_warn(&card->gdev->dev,
1238 "Starting multicast support for %s failed\n",
1239 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001240 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001241 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001242 card->dev->flags |= IFF_MULTICAST;
1243 }
1244 return rc;
1245}
1246
Frank Blaschka4a71df52008-02-15 09:19:42 +01001247#ifdef CONFIG_QETH_IPV6
1248static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1249{
1250 int rc;
1251
Carsten Otte847a50f2010-06-21 22:57:05 +00001252 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001253
1254 if (card->info.type == QETH_CARD_TYPE_IQD)
1255 goto out;
1256
Frank Blaschka1da74b12011-05-12 18:45:02 +00001257 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001258 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001259 dev_err(&card->gdev->dev,
1260 "Activating IPv6 support for %s failed\n",
1261 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262 return rc;
1263 }
1264 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1265 IPA_CMD_ASS_START, 3);
1266 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001267 dev_err(&card->gdev->dev,
1268 "Activating IPv6 support for %s failed\n",
1269 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001270 return rc;
1271 }
1272 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1273 IPA_CMD_ASS_START);
1274 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001275 dev_err(&card->gdev->dev,
1276 "Activating IPv6 support for %s failed\n",
1277 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001278 return rc;
1279 }
1280 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1281 IPA_CMD_ASS_START);
1282 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001283 dev_warn(&card->gdev->dev,
1284 "Enabling the passthrough mode for %s failed\n",
1285 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001286 return rc;
1287 }
1288out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001289 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001290 return 0;
1291}
1292#endif
1293
1294static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1295{
1296 int rc = 0;
1297
Carsten Otte847a50f2010-06-21 22:57:05 +00001298 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001299
1300 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001301 dev_info(&card->gdev->dev,
1302 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001303 return 0;
1304 }
1305#ifdef CONFIG_QETH_IPV6
1306 rc = qeth_l3_softsetup_ipv6(card);
1307#endif
1308 return rc ;
1309}
1310
1311static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1312{
1313 int rc;
1314
Carsten Otte847a50f2010-06-21 22:57:05 +00001315 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001316 card->info.broadcast_capable = 0;
1317 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001318 dev_info(&card->gdev->dev,
1319 "Broadcast not supported on %s\n",
1320 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001321 rc = -EOPNOTSUPP;
1322 goto out;
1323 }
1324 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1325 IPA_CMD_ASS_START, 0);
1326 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001327 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1328 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001329 goto out;
1330 }
1331
1332 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1333 IPA_CMD_ASS_CONFIGURE, 1);
1334 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001335 dev_warn(&card->gdev->dev,
1336 "Setting up broadcast filtering for %s failed\n",
1337 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001338 goto out;
1339 }
1340 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001341 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001342 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1343 IPA_CMD_ASS_ENABLE, 1);
1344 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001345 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1346 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001347 goto out;
1348 }
1349 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1350out:
1351 if (card->info.broadcast_capable)
1352 card->dev->flags |= IFF_BROADCAST;
1353 else
1354 card->dev->flags &= ~IFF_BROADCAST;
1355 return rc;
1356}
1357
1358static int qeth_l3_send_checksum_command(struct qeth_card *card)
1359{
1360 int rc;
1361
1362 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1363 IPA_CMD_ASS_START, 0);
1364 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001365 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1366 "failed, using SW checksumming\n",
1367 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001368 return rc;
1369 }
1370 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1371 IPA_CMD_ASS_ENABLE,
1372 card->info.csum_mask);
1373 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001374 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1375 "failed, using SW checksumming\n",
1376 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001377 return rc;
1378 }
1379 return 0;
1380}
1381
Martin Schwidefskyc4736d92011-10-30 15:17:11 +01001382static int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001383{
1384 int rc = 0;
1385
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001386 if (on) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001387 rc = qeth_l3_send_checksum_command(card);
1388 if (rc)
1389 return -EIO;
1390 dev_info(&card->gdev->dev,
1391 "HW Checksumming (inbound) enabled\n");
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001392 } else {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001393 rc = qeth_l3_send_simple_setassparms(card,
1394 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1395 if (rc)
1396 return -EIO;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001397 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001398
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001399 return 0;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001400}
1401
Frank Blaschka4a71df52008-02-15 09:19:42 +01001402static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1403{
Carsten Otte847a50f2010-06-21 22:57:05 +00001404 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001405
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001406 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001407 rtnl_lock();
1408 /* force set_features call */
1409 card->dev->features &= ~NETIF_F_RXCSUM;
1410 netdev_update_features(card->dev);
1411 rtnl_unlock();
1412 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001413 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001414}
1415
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001416static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1417{
1418 int rc = 0;
1419
1420 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1421 return rc;
1422 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1423 IPA_CMD_ASS_START, 0);
1424 if (rc)
1425 goto err_out;
1426 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1427 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1428 if (rc)
1429 goto err_out;
1430 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1431 return rc;
1432err_out:
1433 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1434 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1435 return rc;
1436}
1437
Frank Blaschka4a71df52008-02-15 09:19:42 +01001438static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1439{
1440 int rc;
1441
Carsten Otte847a50f2010-06-21 22:57:05 +00001442 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001443
1444 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001445 dev_info(&card->gdev->dev,
1446 "Outbound TSO not supported on %s\n",
1447 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001448 rc = -EOPNOTSUPP;
1449 } else {
1450 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1451 IPA_CMD_ASS_START, 0);
1452 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001453 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1454 "segmentation offload for %s failed\n",
1455 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001456 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001457 dev_info(&card->gdev->dev,
1458 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001459 }
Michał Mirosław6204b472011-04-19 00:43:20 +00001460 if (rc)
1461 card->dev->features &= ~NETIF_F_TSO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001462 return rc;
1463}
1464
1465static int qeth_l3_start_ipassists(struct qeth_card *card)
1466{
Carsten Otte847a50f2010-06-21 22:57:05 +00001467 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001468
Stefan Raspl0f547612013-01-21 02:30:20 +00001469 if (qeth_set_access_ctrl_online(card, 0))
1470 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001471 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1472 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1473 qeth_l3_start_ipa_source_mac(card); /* go on*/
1474 qeth_l3_start_ipa_vlan(card); /* go on*/
1475 qeth_l3_start_ipa_multicast(card); /* go on*/
1476 qeth_l3_start_ipa_ipv6(card); /* go on*/
1477 qeth_l3_start_ipa_broadcast(card); /* go on*/
1478 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001479 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001480 qeth_l3_start_ipa_tso(card); /* go on*/
1481 return 0;
1482}
1483
Frank Blaschka4a71df52008-02-15 09:19:42 +01001484static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1485 struct qeth_reply *reply, unsigned long data)
1486{
1487 struct qeth_ipa_cmd *cmd;
1488
1489 cmd = (struct qeth_ipa_cmd *) data;
1490 if (cmd->hdr.return_code == 0)
1491 memcpy(card->dev->dev_addr,
1492 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1493 else
Joe Perches18336112012-07-12 22:33:10 -07001494 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001495
1496 return 0;
1497}
1498
1499static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1500{
1501 int rc = 0;
1502 struct qeth_cmd_buffer *iob;
1503 struct qeth_ipa_cmd *cmd;
1504
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001505 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001506
1507 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1508 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001509 if (!iob)
1510 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001511 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1512 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1513 card->info.unique_id;
1514
1515 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1516 NULL);
1517 return rc;
1518}
1519
1520static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1521 struct qeth_reply *reply, unsigned long data)
1522{
1523 struct qeth_ipa_cmd *cmd;
1524
1525 cmd = (struct qeth_ipa_cmd *) data;
1526 if (cmd->hdr.return_code == 0)
1527 card->info.unique_id = *((__u16 *)
1528 &cmd->data.create_destroy_addr.unique_id[6]);
1529 else {
1530 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1531 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001532 dev_warn(&card->gdev->dev, "The network adapter failed to "
1533 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001534 }
1535 return 0;
1536}
1537
1538static int qeth_l3_get_unique_id(struct qeth_card *card)
1539{
1540 int rc = 0;
1541 struct qeth_cmd_buffer *iob;
1542 struct qeth_ipa_cmd *cmd;
1543
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001544 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001545
1546 if (!qeth_is_supported(card, IPA_IPV6)) {
1547 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1548 UNIQUE_ID_NOT_BY_CARD;
1549 return 0;
1550 }
1551
1552 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1553 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001554 if (!iob)
1555 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001556 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1557 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1558 card->info.unique_id;
1559
1560 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1561 return rc;
1562}
1563
Ursula Braun76b11f82010-01-11 02:50:50 +00001564static int
1565qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1566 unsigned long data)
1567{
1568 struct qeth_ipa_cmd *cmd;
1569 __u16 rc;
1570
1571 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1572
1573 cmd = (struct qeth_ipa_cmd *)data;
1574 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001575 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001576 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001577 switch (cmd->data.diagass.action) {
1578 case QETH_DIAGS_CMD_TRACE_QUERY:
1579 break;
1580 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001581 switch (rc) {
1582 case 0:
1583 case IPA_RC_INVALID_SUBCMD:
1584 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1585 dev_info(&card->gdev->dev, "The HiperSockets network "
1586 "traffic analyzer is deactivated\n");
1587 break;
1588 default:
1589 break;
1590 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001591 break;
1592 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001593 switch (rc) {
1594 case 0:
1595 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1596 dev_info(&card->gdev->dev, "The HiperSockets network "
1597 "traffic analyzer is activated\n");
1598 break;
1599 case IPA_RC_HARDWARE_AUTH_ERROR:
1600 dev_warn(&card->gdev->dev, "The device is not "
1601 "authorized to run as a HiperSockets network "
1602 "traffic analyzer\n");
1603 break;
1604 case IPA_RC_TRACE_ALREADY_ACTIVE:
1605 dev_warn(&card->gdev->dev, "A HiperSockets "
1606 "network traffic analyzer is already "
1607 "active in the HiperSockets LAN\n");
1608 break;
1609 default:
1610 break;
1611 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001612 break;
1613 default:
1614 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1615 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1616 }
1617
1618 return 0;
1619}
1620
1621static int
1622qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1623{
1624 struct qeth_cmd_buffer *iob;
1625 struct qeth_ipa_cmd *cmd;
1626
1627 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1628
1629 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001630 if (!iob)
1631 return -ENOMEM;
Ursula Braun76b11f82010-01-11 02:50:50 +00001632 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1633 cmd->data.diagass.subcmd_len = 16;
1634 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1635 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1636 cmd->data.diagass.action = diags_cmd;
1637 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1638}
1639
Frank Blaschka4a71df52008-02-15 09:19:42 +01001640static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1641 struct net_device *dev)
1642{
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001643 ip_eth_mc_map(ipm, mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001644}
1645
1646static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1647{
1648 struct qeth_ipaddr *ipm;
1649 struct ip_mc_list *im4;
1650 char buf[MAX_ADDR_LEN];
1651
Carsten Otte847a50f2010-06-21 22:57:05 +00001652 QETH_CARD_TEXT(card, 4, "addmc");
Sachin Santf3aa3132010-11-26 02:41:17 +00001653 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1654 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001655 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1656 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1657 if (!ipm)
1658 continue;
1659 ipm->u.a4.addr = im4->multiaddr;
1660 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1661 ipm->is_multicast = 1;
1662 if (!qeth_l3_add_ip(card, ipm))
1663 kfree(ipm);
1664 }
1665}
1666
Jiri Pirko0347af52013-01-03 22:48:58 +00001667/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001668static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1669{
1670 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001671 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001672
Carsten Otte847a50f2010-06-21 22:57:05 +00001673 QETH_CARD_TEXT(card, 4, "addmcvl");
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001674 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001675 return;
1676
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001677 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1678 struct net_device *netdev;
1679
dingtianhongf06c7f92014-05-09 14:58:05 +08001680 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001681 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001682 if (netdev == NULL ||
1683 !(netdev->flags & IFF_UP))
1684 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001685 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001686 if (!in_dev)
1687 continue;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001688 qeth_l3_add_mc(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001689 }
1690}
1691
1692static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1693{
1694 struct in_device *in4_dev;
1695
Carsten Otte847a50f2010-06-21 22:57:05 +00001696 QETH_CARD_TEXT(card, 4, "chkmcv4");
Sachin Santf3aa3132010-11-26 02:41:17 +00001697 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001698 in4_dev = __in_dev_get_rcu(card->dev);
1699 if (in4_dev == NULL)
1700 goto unlock;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001701 qeth_l3_add_mc(card, in4_dev);
1702 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001703unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001704 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001705}
1706
1707#ifdef CONFIG_QETH_IPV6
1708static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1709{
1710 struct qeth_ipaddr *ipm;
1711 struct ifmcaddr6 *im6;
1712 char buf[MAX_ADDR_LEN];
1713
Carsten Otte847a50f2010-06-21 22:57:05 +00001714 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001715 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1716 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1717 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1718 if (!ipm)
1719 continue;
1720 ipm->is_multicast = 1;
1721 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1722 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1723 sizeof(struct in6_addr));
1724 if (!qeth_l3_add_ip(card, ipm))
1725 kfree(ipm);
1726 }
1727}
1728
Jiri Pirko0347af52013-01-03 22:48:58 +00001729/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001730static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1731{
1732 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001733 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001734
Carsten Otte847a50f2010-06-21 22:57:05 +00001735 QETH_CARD_TEXT(card, 4, "admc6vl");
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001736 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001737 return;
1738
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001739 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1740 struct net_device *netdev;
1741
dingtianhongf06c7f92014-05-09 14:58:05 +08001742 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001743 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001744 if (netdev == NULL ||
1745 !(netdev->flags & IFF_UP))
1746 continue;
1747 in_dev = in6_dev_get(netdev);
1748 if (!in_dev)
1749 continue;
1750 read_lock_bh(&in_dev->lock);
1751 qeth_l3_add_mc6(card, in_dev);
1752 read_unlock_bh(&in_dev->lock);
1753 in6_dev_put(in_dev);
1754 }
1755}
1756
1757static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1758{
1759 struct inet6_dev *in6_dev;
1760
Carsten Otte847a50f2010-06-21 22:57:05 +00001761 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001762 if (!qeth_is_supported(card, IPA_IPV6))
1763 return ;
1764 in6_dev = in6_dev_get(card->dev);
1765 if (in6_dev == NULL)
1766 return;
Jiri Pirko0347af52013-01-03 22:48:58 +00001767 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001768 read_lock_bh(&in6_dev->lock);
1769 qeth_l3_add_mc6(card, in6_dev);
1770 qeth_l3_add_vlan_mc6(card);
1771 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001772 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001773 in6_dev_put(in6_dev);
1774}
1775#endif /* CONFIG_QETH_IPV6 */
1776
1777static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1778 unsigned short vid)
1779{
1780 struct in_device *in_dev;
1781 struct in_ifaddr *ifa;
1782 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001783 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001784
Carsten Otte847a50f2010-06-21 22:57:05 +00001785 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001786
dingtianhongf06c7f92014-05-09 14:58:05 +08001787 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001788 if (!netdev)
1789 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001790 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001791 if (!in_dev)
1792 return;
1793 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1794 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1795 if (addr) {
1796 addr->u.a4.addr = ifa->ifa_address;
1797 addr->u.a4.mask = ifa->ifa_mask;
1798 addr->type = QETH_IP_TYPE_NORMAL;
1799 if (!qeth_l3_delete_ip(card, addr))
1800 kfree(addr);
1801 }
1802 }
1803 in_dev_put(in_dev);
1804}
1805
1806static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1807 unsigned short vid)
1808{
1809#ifdef CONFIG_QETH_IPV6
1810 struct inet6_dev *in6_dev;
1811 struct inet6_ifaddr *ifa;
1812 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001813 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001814
Carsten Otte847a50f2010-06-21 22:57:05 +00001815 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001816
dingtianhongf06c7f92014-05-09 14:58:05 +08001817 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001818 if (!netdev)
1819 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001820 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001821 if (!in6_dev)
1822 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001823 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001824 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1825 if (addr) {
1826 memcpy(&addr->u.a6.addr, &ifa->addr,
1827 sizeof(struct in6_addr));
1828 addr->u.a6.pfxlen = ifa->prefix_len;
1829 addr->type = QETH_IP_TYPE_NORMAL;
1830 if (!qeth_l3_delete_ip(card, addr))
1831 kfree(addr);
1832 }
1833 }
1834 in6_dev_put(in6_dev);
1835#endif /* CONFIG_QETH_IPV6 */
1836}
1837
1838static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1839 unsigned short vid)
1840{
Jiri Pirko0347af52013-01-03 22:48:58 +00001841 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001842 qeth_l3_free_vlan_addresses4(card, vid);
1843 qeth_l3_free_vlan_addresses6(card, vid);
Jiri Pirko0347af52013-01-03 22:48:58 +00001844 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001845}
1846
Patrick McHardy80d5c362013-04-19 02:04:28 +00001847static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1848 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001849{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001850 struct qeth_card *card = dev->ml_priv;
1851
1852 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001853 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001854}
1855
Patrick McHardy80d5c362013-04-19 02:04:28 +00001856static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1857 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001858{
Heiko Carstens509e2562008-07-26 02:24:10 -07001859 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001860 unsigned long flags;
1861
Carsten Otte847a50f2010-06-21 22:57:05 +00001862 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00001863 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001864 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001865 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001866 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001867 spin_lock_irqsave(&card->vlanlock, flags);
1868 /* unregister IP addresses of vlan device */
1869 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001870 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001871 spin_unlock_irqrestore(&card->vlanlock, flags);
1872 qeth_l3_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001873 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001874}
1875
Ursula Braun10651db2010-10-01 02:51:13 +00001876static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1877 struct sk_buff *skb, struct qeth_hdr *hdr,
1878 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001879{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001880 __be16 prot;
1881 struct iphdr *ip_hdr;
1882 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001883 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001884
1885 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1886 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1887 ETH_P_IP);
1888 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1889 case QETH_CAST_MULTICAST:
1890 switch (prot) {
1891#ifdef CONFIG_QETH_IPV6
1892 case __constant_htons(ETH_P_IPV6):
1893 ndisc_mc_map((struct in6_addr *)
1894 skb->data + 24,
1895 tg_addr, card->dev, 0);
1896 break;
1897#endif
1898 case __constant_htons(ETH_P_IP):
1899 ip_hdr = (struct iphdr *)skb->data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001900 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1901 break;
1902 default:
1903 memcpy(tg_addr, card->dev->broadcast,
1904 card->dev->addr_len);
1905 }
1906 card->stats.multicast++;
1907 skb->pkt_type = PACKET_MULTICAST;
1908 break;
1909 case QETH_CAST_BROADCAST:
1910 memcpy(tg_addr, card->dev->broadcast,
1911 card->dev->addr_len);
1912 card->stats.multicast++;
1913 skb->pkt_type = PACKET_BROADCAST;
1914 break;
1915 case QETH_CAST_UNICAST:
1916 case QETH_CAST_ANYCAST:
1917 case QETH_CAST_NOCAST:
1918 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001919 if (card->options.sniffer)
1920 skb->pkt_type = PACKET_OTHERHOST;
1921 else
1922 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001923 memcpy(tg_addr, card->dev->dev_addr,
1924 card->dev->addr_len);
1925 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001926 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1927 card->dev->header_ops->create(skb, card->dev, prot,
1928 tg_addr, &hdr->hdr.l3.dest_addr[2],
1929 card->dev->addr_len);
1930 else
1931 card->dev->header_ops->create(skb, card->dev, prot,
1932 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001933 }
1934
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001935 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001936
1937 if (hdr->hdr.l3.ext_flags &
1938 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001939 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001940 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001941 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001942 }
1943
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001944 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001945 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001946 (QETH_HDR_EXT_CSUM_HDR_REQ |
1947 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1948 (QETH_HDR_EXT_CSUM_HDR_REQ |
1949 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001950 skb->ip_summed = CHECKSUM_UNNECESSARY;
1951 else
Ursula Braunb9139802009-05-19 21:38:40 +00001952 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001953 } else
1954 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001955
Ursula Braun10651db2010-10-01 02:51:13 +00001956 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001957}
1958
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001959static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1960 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001961{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001962 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001963 struct sk_buff *skb;
1964 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001965 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001966 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001967 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001968 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001969
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001970 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001971 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001972 while (budget) {
1973 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001974 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001975 &card->rx.b_element, &card->rx.e_offset, &hdr);
1976 if (!skb) {
1977 *done = 1;
1978 break;
1979 }
1980 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001981 switch (hdr->hdr.l3.id) {
1982 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001983 magic = *(__u16 *)skb->data;
1984 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1985 (magic == ETH_P_AF_IUCV)) {
1986 skb->protocol = ETH_P_AF_IUCV;
1987 skb->pkt_type = PACKET_HOST;
1988 skb->mac_header = NET_SKB_PAD;
1989 skb->dev = card->dev;
1990 len = skb->len;
1991 card->dev->header_ops->create(skb, card->dev, 0,
1992 card->dev->dev_addr, "FAKELL",
1993 card->dev->addr_len);
1994 netif_receive_skb(skb);
1995 } else {
1996 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
Ursula Braun10651db2010-10-01 02:51:13 +00001997 &vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001998 len = skb->len;
1999 if (is_vlan && !card->options.sniffer)
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00002000 __vlan_hwaccel_put_tag(skb,
2001 htons(ETH_P_8021Q), vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00002002 napi_gro_receive(&card->napi, skb);
2003 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002004 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002005 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2006 skb->pkt_type = PACKET_HOST;
2007 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002008 len = skb->len;
2009 netif_receive_skb(skb);
2010 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002011 default:
2012 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002013 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002014 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002015 continue;
2016 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002017 work_done++;
2018 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002019 card->stats.rx_packets++;
2020 card->stats.rx_bytes += len;
2021 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002022 return work_done;
2023}
2024
2025static int qeth_l3_poll(struct napi_struct *napi, int budget)
2026{
2027 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2028 int work_done = 0;
2029 struct qeth_qdio_buffer *buffer;
2030 int done;
2031 int new_budget = budget;
2032
2033 if (card->options.performance_stats) {
2034 card->perf_stats.inbound_cnt++;
2035 card->perf_stats.inbound_start_time = qeth_get_micros();
2036 }
2037
2038 while (1) {
2039 if (!card->rx.b_count) {
2040 card->rx.qdio_err = 0;
2041 card->rx.b_count = qdio_get_next_buffers(
2042 card->data.ccwdev, 0, &card->rx.b_index,
2043 &card->rx.qdio_err);
2044 if (card->rx.b_count <= 0) {
2045 card->rx.b_count = 0;
2046 break;
2047 }
2048 card->rx.b_element =
2049 &card->qdio.in_q->bufs[card->rx.b_index]
2050 .buffer->element[0];
2051 card->rx.e_offset = 0;
2052 }
2053
2054 while (card->rx.b_count) {
2055 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2056 if (!(card->rx.qdio_err &&
2057 qeth_check_qdio_errors(card, buffer->buffer,
2058 card->rx.qdio_err, "qinerr")))
2059 work_done += qeth_l3_process_inbound_buffer(
2060 card, new_budget, &done);
2061 else
2062 done = 1;
2063
2064 if (done) {
2065 if (card->options.performance_stats)
2066 card->perf_stats.bufs_rec++;
2067 qeth_put_buffer_pool_entry(card,
2068 buffer->pool_entry);
2069 qeth_queue_input_buffer(card, card->rx.b_index);
2070 card->rx.b_count--;
2071 if (card->rx.b_count) {
2072 card->rx.b_index =
2073 (card->rx.b_index + 1) %
2074 QDIO_MAX_BUFFERS_PER_Q;
2075 card->rx.b_element =
2076 &card->qdio.in_q
2077 ->bufs[card->rx.b_index]
2078 .buffer->element[0];
2079 card->rx.e_offset = 0;
2080 }
2081 }
2082
2083 if (work_done >= budget)
2084 goto out;
2085 else
2086 new_budget = budget - work_done;
2087 }
2088 }
2089
2090 napi_complete(napi);
2091 if (qdio_start_irq(card->data.ccwdev, 0))
2092 napi_schedule(&card->napi);
2093out:
2094 if (card->options.performance_stats)
2095 card->perf_stats.inbound_time += qeth_get_micros() -
2096 card->perf_stats.inbound_start_time;
2097 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002098}
2099
2100static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2101 struct qeth_card *card)
2102{
2103 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002104 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002105
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002106 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
2107 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002108
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002109 rcu_read_lock();
dingtianhongf06c7f92014-05-09 14:58:05 +08002110 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00002111 vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002112 rcu_read_unlock();
2113 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002114 rc = QETH_VLAN_CARD;
2115 break;
2116 }
2117 }
2118
Heiko Carstens509e2562008-07-26 02:24:10 -07002119 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002120 return 0;
2121
2122 return rc;
2123}
2124
2125static int qeth_l3_verify_dev(struct net_device *dev)
2126{
2127 struct qeth_card *card;
2128 unsigned long flags;
2129 int rc = 0;
2130
2131 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2132 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2133 if (card->dev == dev) {
2134 rc = QETH_REAL_CARD;
2135 break;
2136 }
2137 rc = qeth_l3_verify_vlan_dev(dev, card);
2138 if (rc)
2139 break;
2140 }
2141 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2142
2143 return rc;
2144}
2145
2146static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2147{
2148 struct qeth_card *card = NULL;
2149 int rc;
2150
2151 rc = qeth_l3_verify_dev(dev);
2152 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002153 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002154 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002155 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002156 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002157 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002158 if (card)
2159 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002160 return card ;
2161}
2162
2163static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2164{
2165 int rc = 0;
2166
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002167 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2168 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002169
2170 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002171 if (card->options.sniffer &&
2172 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2173 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002174 if (card->read.state == CH_STATE_UP &&
2175 card->write.state == CH_STATE_UP &&
2176 (card->state == CARD_STATE_UP)) {
2177 if (recovery_mode)
2178 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002179 else {
Ursula Braun869da902010-03-08 20:36:56 +00002180 rtnl_lock();
2181 dev_close(card->dev);
2182 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002183 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002184 card->state = CARD_STATE_SOFTSETUP;
2185 }
2186 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -08002187 qeth_l3_clear_ip_list(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002188 qeth_clear_ipacmd_list(card);
2189 card->state = CARD_STATE_HARDSETUP;
2190 }
2191 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002192 qeth_qdio_clear_card(card, 0);
2193 qeth_clear_qdio_buffers(card);
2194 qeth_clear_working_pool_list(card);
2195 card->state = CARD_STATE_DOWN;
2196 }
2197 if (card->state == CARD_STATE_DOWN) {
2198 qeth_clear_cmd_buffers(&card->read);
2199 qeth_clear_cmd_buffers(&card->write);
2200 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002201 return rc;
2202}
2203
Ursula Braun76b11f82010-01-11 02:50:50 +00002204/*
2205 * test for and Switch promiscuous mode (on or off)
2206 * either for guestlan or HiperSocket Sniffer
2207 */
2208static void
2209qeth_l3_handle_promisc_mode(struct qeth_card *card)
2210{
2211 struct net_device *dev = card->dev;
2212
2213 if (((dev->flags & IFF_PROMISC) &&
2214 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2215 (!(dev->flags & IFF_PROMISC) &&
2216 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2217 return;
2218
2219 if (card->info.guestlan) { /* Guestlan trace */
2220 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2221 qeth_setadp_promisc_mode(card);
2222 } else if (card->options.sniffer && /* HiperSockets trace */
2223 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2224 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002225 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002226 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2227 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002228 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002229 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2230 }
2231 }
2232}
2233
Frank Blaschka4a71df52008-02-15 09:19:42 +01002234static void qeth_l3_set_multicast_list(struct net_device *dev)
2235{
Heiko Carstens509e2562008-07-26 02:24:10 -07002236 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002237
Carsten Otte847a50f2010-06-21 22:57:05 +00002238 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002239 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2240 (card->state != CARD_STATE_UP))
2241 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002242 if (!card->options.sniffer) {
2243 qeth_l3_delete_mc_addresses(card);
2244 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002245#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002246 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002247#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002248 qeth_l3_set_ip_addr_list(card);
2249 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2250 return;
2251 }
2252 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002253}
2254
2255static const char *qeth_l3_arp_get_error_cause(int *rc)
2256{
2257 switch (*rc) {
2258 case QETH_IPA_ARP_RC_FAILED:
2259 *rc = -EIO;
2260 return "operation failed";
2261 case QETH_IPA_ARP_RC_NOTSUPP:
2262 *rc = -EOPNOTSUPP;
2263 return "operation not supported";
2264 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2265 *rc = -EINVAL;
2266 return "argument out of range";
2267 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2268 *rc = -EOPNOTSUPP;
2269 return "query operation not supported";
2270 case QETH_IPA_ARP_RC_Q_NO_DATA:
2271 *rc = -ENOENT;
2272 return "no query data available";
2273 default:
2274 return "unknown error";
2275 }
2276}
2277
2278static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2279{
2280 int tmp;
2281 int rc;
2282
Carsten Otte847a50f2010-06-21 22:57:05 +00002283 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002284
2285 /*
2286 * currently GuestLAN only supports the ARP assist function
2287 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2288 * thus we say EOPNOTSUPP for this ARP function
2289 */
2290 if (card->info.guestlan)
2291 return -EOPNOTSUPP;
2292 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002293 return -EOPNOTSUPP;
2294 }
2295 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2296 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2297 no_entries);
2298 if (rc) {
2299 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002300 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2301 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002302 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2303 }
2304 return rc;
2305}
2306
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002307static __u32 get_arp_entry_size(struct qeth_card *card,
2308 struct qeth_arp_query_data *qdata,
2309 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002310{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002311 __u32 rc;
2312 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002313
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002314 is_hsi = qdata->reply_bits == 5;
2315 if (type->ip == QETHARP_IP_ADDR_V4) {
2316 QETH_CARD_TEXT(card, 4, "arpev4");
2317 if (strip_entries) {
2318 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2319 sizeof(struct qeth_arp_qi_entry7_short);
2320 } else {
2321 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2322 sizeof(struct qeth_arp_qi_entry7);
2323 }
2324 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2325 QETH_CARD_TEXT(card, 4, "arpev6");
2326 if (strip_entries) {
2327 rc = is_hsi ?
2328 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2329 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2330 } else {
2331 rc = is_hsi ?
2332 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2333 sizeof(struct qeth_arp_qi_entry7_ipv6);
2334 }
2335 } else {
2336 QETH_CARD_TEXT(card, 4, "arpinv");
2337 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002338 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002339
2340 return rc;
2341}
2342
2343static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2344{
2345 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2346 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002347}
2348
2349static int qeth_l3_arp_query_cb(struct qeth_card *card,
2350 struct qeth_reply *reply, unsigned long data)
2351{
2352 struct qeth_ipa_cmd *cmd;
2353 struct qeth_arp_query_data *qdata;
2354 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002355 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002356 int e;
2357 int entrybytes_done;
2358 int stripped_bytes;
2359 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002360
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002361 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002362
2363 qinfo = (struct qeth_arp_query_info *) reply->param;
2364 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002365 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002366 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002367 QETH_CARD_TEXT(card, 4, "arpcberr");
2368 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002369 return 0;
2370 }
2371 if (cmd->data.setassparms.hdr.return_code) {
2372 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002373 QETH_CARD_TEXT(card, 4, "setaperr");
2374 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002375 return 0;
2376 }
2377 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002378 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002379
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002380 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2381 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2382 entrybytes_done = 0;
2383 for (e = 0; e < qdata->no_entries; ++e) {
2384 char *cur_entry;
2385 __u32 esize;
2386 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002387
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002388 cur_entry = &qdata->data + entrybytes_done;
2389 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2390 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2391 QETH_CARD_TEXT(card, 4, "pmis");
2392 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2393 break;
2394 }
2395 esize = get_arp_entry_size(card, qdata, etype,
2396 do_strip_entries);
2397 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2398 if (!esize)
2399 break;
2400
2401 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2402 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00002403 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002404 goto out_error;
2405 }
2406
2407 memcpy(qinfo->udata + qinfo->udata_offset,
2408 &qdata->data + entrybytes_done + stripped_bytes,
2409 esize);
2410 entrybytes_done += esize + stripped_bytes;
2411 qinfo->udata_offset += esize;
2412 ++qinfo->no_entries;
2413 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002414 /* check if all replies received ... */
2415 if (cmd->data.setassparms.hdr.seq_no <
2416 cmd->data.setassparms.hdr.number_of_replies)
2417 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002418 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002419 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2420 /* keep STRIP_ENTRIES flag so the user program can distinguish
2421 * stripped entries from normal ones */
2422 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2423 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2424 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002425 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002426 return 0;
2427out_error:
2428 i = 0;
2429 memcpy(qinfo->udata, &i, 4);
2430 return 0;
2431}
2432
2433static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2434 struct qeth_cmd_buffer *iob, int len,
2435 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2436 unsigned long),
2437 void *reply_param)
2438{
Carsten Otte847a50f2010-06-21 22:57:05 +00002439 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002440
2441 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2442 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2443 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2444 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2445 reply_cb, reply_param);
2446}
2447
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002448static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2449 enum qeth_prot_versions prot,
2450 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002451{
2452 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002453 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002454 int tmp;
2455 int rc;
2456
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002457 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2458
2459 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2460 IPA_CMD_ASS_ARP_QUERY_INFO,
2461 sizeof(struct qeth_arp_query_data) - sizeof(char),
2462 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002463 if (!iob)
2464 return -ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002465 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2466 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2467 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2468 cmd->data.setassparms.data.query_arp.no_entries = 0;
2469 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2470 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2471 qeth_l3_arp_query_cb, (void *)qinfo);
2472 if (rc) {
2473 tmp = rc;
2474 QETH_DBF_MESSAGE(2,
2475 "Error while querying ARP cache on %s: %s "
2476 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2477 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2478 }
2479
2480 return rc;
2481}
2482
2483static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2484{
2485 struct qeth_arp_query_info qinfo = {0, };
2486 int rc;
2487
Carsten Otte847a50f2010-06-21 22:57:05 +00002488 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002489
2490 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2491 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002492 QETH_CARD_TEXT(card, 3, "arpqnsup");
2493 rc = -EOPNOTSUPP;
2494 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002495 }
2496 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002497 if (copy_from_user(&qinfo, udata, 6)) {
2498 rc = -EFAULT;
2499 goto out;
2500 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002501 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002502 if (!qinfo.udata) {
2503 rc = -ENOMEM;
2504 goto out;
2505 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002506 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002507 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002508 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002509 if (copy_to_user(udata, qinfo.udata, 4))
2510 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002511 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002512 } else {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002513#ifdef CONFIG_QETH_IPV6
2514 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2515 /* fails in case of GuestLAN QDIO mode */
2516 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2517 &qinfo);
2518 }
2519#endif
2520 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2521 QETH_CARD_TEXT(card, 4, "qactf");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002522 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002523 goto free_and_out;
2524 }
Thomas Richter8a593142014-10-22 12:18:03 +02002525 QETH_CARD_TEXT(card, 4, "qacts");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002526 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002527free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002528 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002529out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002530 return rc;
2531}
2532
2533static int qeth_l3_arp_add_entry(struct qeth_card *card,
2534 struct qeth_arp_cache_entry *entry)
2535{
2536 struct qeth_cmd_buffer *iob;
2537 char buf[16];
2538 int tmp;
2539 int rc;
2540
Carsten Otte847a50f2010-06-21 22:57:05 +00002541 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002542
2543 /*
2544 * currently GuestLAN only supports the ARP assist function
2545 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2546 * thus we say EOPNOTSUPP for this ARP function
2547 */
2548 if (card->info.guestlan)
2549 return -EOPNOTSUPP;
2550 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002551 return -EOPNOTSUPP;
2552 }
2553
2554 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2555 IPA_CMD_ASS_ARP_ADD_ENTRY,
2556 sizeof(struct qeth_arp_cache_entry),
2557 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002558 if (!iob)
2559 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002560 rc = qeth_l3_send_setassparms(card, iob,
2561 sizeof(struct qeth_arp_cache_entry),
2562 (unsigned long) entry,
2563 qeth_l3_default_setassparms_cb, NULL);
2564 if (rc) {
2565 tmp = rc;
2566 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002567 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2568 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2569 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002570 }
2571 return rc;
2572}
2573
2574static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2575 struct qeth_arp_cache_entry *entry)
2576{
2577 struct qeth_cmd_buffer *iob;
2578 char buf[16] = {0, };
2579 int tmp;
2580 int rc;
2581
Carsten Otte847a50f2010-06-21 22:57:05 +00002582 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002583
2584 /*
2585 * currently GuestLAN only supports the ARP assist function
2586 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2587 * thus we say EOPNOTSUPP for this ARP function
2588 */
2589 if (card->info.guestlan)
2590 return -EOPNOTSUPP;
2591 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002592 return -EOPNOTSUPP;
2593 }
2594 memcpy(buf, entry, 12);
2595 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2596 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2597 12,
2598 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002599 if (!iob)
2600 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002601 rc = qeth_l3_send_setassparms(card, iob,
2602 12, (unsigned long)buf,
2603 qeth_l3_default_setassparms_cb, NULL);
2604 if (rc) {
2605 tmp = rc;
2606 memset(buf, 0, 16);
2607 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002608 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2609 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2610 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002611 }
2612 return rc;
2613}
2614
2615static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2616{
2617 int rc;
2618 int tmp;
2619
Carsten Otte847a50f2010-06-21 22:57:05 +00002620 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002621
2622 /*
2623 * currently GuestLAN only supports the ARP assist function
2624 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2625 * thus we say EOPNOTSUPP for this ARP function
2626 */
2627 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2628 return -EOPNOTSUPP;
2629 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002630 return -EOPNOTSUPP;
2631 }
2632 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2633 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2634 if (rc) {
2635 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002636 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2637 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002638 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2639 }
2640 return rc;
2641}
2642
2643static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2644{
Heiko Carstens509e2562008-07-26 02:24:10 -07002645 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002646 struct qeth_arp_cache_entry arp_entry;
2647 struct mii_ioctl_data *mii_data;
2648 int rc = 0;
2649
2650 if (!card)
2651 return -ENODEV;
2652
2653 if ((card->state != CARD_STATE_UP) &&
2654 (card->state != CARD_STATE_SOFTSETUP))
2655 return -ENODEV;
2656
2657 switch (cmd) {
2658 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2659 if (!capable(CAP_NET_ADMIN)) {
2660 rc = -EPERM;
2661 break;
2662 }
2663 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2664 break;
2665 case SIOC_QETH_ARP_QUERY_INFO:
2666 if (!capable(CAP_NET_ADMIN)) {
2667 rc = -EPERM;
2668 break;
2669 }
2670 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2671 break;
2672 case SIOC_QETH_ARP_ADD_ENTRY:
2673 if (!capable(CAP_NET_ADMIN)) {
2674 rc = -EPERM;
2675 break;
2676 }
2677 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2678 sizeof(struct qeth_arp_cache_entry)))
2679 rc = -EFAULT;
2680 else
2681 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2682 break;
2683 case SIOC_QETH_ARP_REMOVE_ENTRY:
2684 if (!capable(CAP_NET_ADMIN)) {
2685 rc = -EPERM;
2686 break;
2687 }
2688 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2689 sizeof(struct qeth_arp_cache_entry)))
2690 rc = -EFAULT;
2691 else
2692 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2693 break;
2694 case SIOC_QETH_ARP_FLUSH_CACHE:
2695 if (!capable(CAP_NET_ADMIN)) {
2696 rc = -EPERM;
2697 break;
2698 }
2699 rc = qeth_l3_arp_flush_cache(card);
2700 break;
2701 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2702 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2703 break;
2704 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002705 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2706 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002707 !card->info.guestlan)
2708 return 1;
2709 return 0;
2710 break;
2711 case SIOCGMIIPHY:
2712 mii_data = if_mii(rq);
2713 mii_data->phy_id = 0;
2714 break;
2715 case SIOCGMIIREG:
2716 mii_data = if_mii(rq);
2717 if (mii_data->phy_id != 0)
2718 rc = -EINVAL;
2719 else
2720 mii_data->val_out = qeth_mdio_read(dev,
2721 mii_data->phy_id,
2722 mii_data->reg_num);
2723 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +00002724 case SIOC_QETH_QUERY_OAT:
2725 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
2726 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002727 default:
2728 rc = -EOPNOTSUPP;
2729 }
2730 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002731 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002732 return rc;
2733}
2734
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002735int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2736{
2737 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002738 struct neighbour *n = NULL;
2739 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002740
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002741 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002742 dst = skb_dst(skb);
2743 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002744 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002745 if (n) {
2746 cast_type = n->type;
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002747 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002748 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002749 if ((cast_type == RTN_BROADCAST) ||
2750 (cast_type == RTN_MULTICAST) ||
2751 (cast_type == RTN_ANYCAST))
2752 return cast_type;
2753 else
2754 return RTN_UNSPEC;
2755 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002756 rcu_read_unlock();
2757
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002758 /* try something else */
2759 if (skb->protocol == ETH_P_IPV6)
2760 return (skb_network_header(skb)[24] == 0xff) ?
2761 RTN_MULTICAST : 0;
2762 else if (skb->protocol == ETH_P_IP)
2763 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2764 RTN_MULTICAST : 0;
2765 /* ... */
2766 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2767 return RTN_BROADCAST;
2768 else {
2769 u16 hdr_mac;
2770
2771 hdr_mac = *((u16 *)skb->data);
2772 /* tr multicast? */
2773 switch (card->info.link_type) {
2774 case QETH_LINK_TYPE_HSTR:
2775 case QETH_LINK_TYPE_LANE_TR:
2776 if ((hdr_mac == QETH_TR_MAC_NC) ||
2777 (hdr_mac == QETH_TR_MAC_C))
2778 return RTN_MULTICAST;
2779 break;
2780 /* eth or so multicast? */
2781 default:
2782 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2783 (hdr_mac == QETH_ETH_MAC_V6))
2784 return RTN_MULTICAST;
2785 }
2786 }
2787 return cast_type;
2788}
2789
Frank Blaschkab3332932011-08-08 01:33:59 +00002790static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2791 struct qeth_hdr *hdr, struct sk_buff *skb)
2792{
2793 char daddr[16];
2794 struct af_iucv_trans_hdr *iucv_hdr;
2795
2796 skb_pull(skb, 14);
2797 card->dev->header_ops->create(skb, card->dev, 0,
2798 card->dev->dev_addr, card->dev->dev_addr,
2799 card->dev->addr_len);
2800 skb_pull(skb, 14);
2801 iucv_hdr = (struct af_iucv_trans_hdr *)skb->data;
2802 memset(hdr, 0, sizeof(struct qeth_hdr));
2803 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2804 hdr->hdr.l3.ext_flags = 0;
2805 hdr->hdr.l3.length = skb->len;
2806 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
2807 memset(daddr, 0, sizeof(daddr));
2808 daddr[0] = 0xfe;
2809 daddr[1] = 0x80;
2810 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2811 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2812}
2813
Frank Blaschka4a71df52008-02-15 09:19:42 +01002814static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2815 struct sk_buff *skb, int ipv, int cast_type)
2816{
David S. Miller69cce1d2011-07-17 23:09:49 -07002817 struct dst_entry *dst;
2818
Frank Blaschka4a71df52008-02-15 09:19:42 +01002819 memset(hdr, 0, sizeof(struct qeth_hdr));
2820 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2821 hdr->hdr.l3.ext_flags = 0;
2822
2823 /*
2824 * before we're going to overwrite this location with next hop ip.
2825 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2826 */
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002827 if (vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002828 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2829 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2830 else
2831 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002832 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2833 }
2834
2835 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002836
2837 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002838 dst = skb_dst(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002839 if (ipv == 4) {
David Miller87e75972012-02-01 10:49:17 +00002840 struct rtable *rt = (struct rtable *) dst;
2841 __be32 *pkey = &ip_hdr(skb)->daddr;
2842
2843 if (rt->rt_gateway)
2844 pkey = &rt->rt_gateway;
2845
Frank Blaschka4a71df52008-02-15 09:19:42 +01002846 /* IPv4 */
2847 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2848 memset(hdr->hdr.l3.dest_addr, 0, 12);
David Miller87e75972012-02-01 10:49:17 +00002849 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002850 } else if (ipv == 6) {
David Miller87e75972012-02-01 10:49:17 +00002851 struct rt6_info *rt = (struct rt6_info *) dst;
2852 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2853
2854 if (!ipv6_addr_any(&rt->rt6i_gateway))
2855 pkey = &rt->rt6i_gateway;
2856
Frank Blaschka4a71df52008-02-15 09:19:42 +01002857 /* IPv6 */
2858 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2859 if (card->info.type == QETH_CARD_TYPE_IQD)
2860 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David Miller87e75972012-02-01 10:49:17 +00002861 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002862 } else {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002863 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002864 skb->dev->broadcast, 6)) {
2865 /* broadcast? */
2866 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2867 QETH_HDR_PASSTHRU;
2868 } else {
2869 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2870 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2871 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2872 }
2873 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002874 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002875}
2876
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002877static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2878 struct qeth_hdr *hdr, struct sk_buff *skb)
2879{
2880 struct iphdr *iph = ip_hdr(skb);
2881
2882 /* tcph->check contains already the pseudo hdr checksum
2883 * so just set the header flags
2884 */
2885 if (iph->protocol == IPPROTO_UDP)
2886 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002887 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2888 QETH_HDR_EXT_CSUM_HDR_REQ;
2889 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002890 if (card->options.performance_stats)
2891 card->perf_stats.tx_csum++;
2892}
2893
Frank Blaschka64ef8952009-03-24 20:57:16 +00002894static void qeth_tso_fill_header(struct qeth_card *card,
2895 struct qeth_hdr *qhdr, struct sk_buff *skb)
2896{
2897 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2898 struct tcphdr *tcph = tcp_hdr(skb);
2899 struct iphdr *iph = ip_hdr(skb);
2900 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2901
2902 /*fix header to TSO values ...*/
2903 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002904 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002905 /*set values which are fix for the first approach ...*/
2906 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2907 hdr->ext.imb_hdr_no = 1;
2908 hdr->ext.hdr_type = 1;
2909 hdr->ext.hdr_version = 1;
2910 hdr->ext.hdr_len = 28;
2911 /*insert non-fix values */
2912 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2913 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2914 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2915 sizeof(struct qeth_hdr_tso));
2916 tcph->check = 0;
2917 if (skb->protocol == ETH_P_IPV6) {
2918 ip6h->payload_len = 0;
2919 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2920 0, IPPROTO_TCP, 0);
2921 } else {
2922 /*OSA want us to set these values ...*/
2923 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2924 0, IPPROTO_TCP, 0);
2925 iph->tot_len = 0;
2926 iph->check = 0;
2927 }
2928}
2929
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002930static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2931{
2932 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2933 tcp_hdr(skb)->doff * 4;
2934 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002935 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschka271648b2013-03-18 20:04:44 +00002936
2937 elements += qeth_get_elements_for_frags(skb);
2938
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002939 return elements;
2940}
2941
Frank Blaschka4a71df52008-02-15 09:19:42 +01002942static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2943{
2944 int rc;
2945 u16 *tag;
2946 struct qeth_hdr *hdr = NULL;
2947 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002948 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002949 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002950 struct sk_buff *new_skb = NULL;
2951 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002952 int cast_type = qeth_l3_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002953 struct qeth_qdio_out_q *queue =
2954 card->qdio.out_qs[card->qdio.do_prio_queueing
2955 || (cast_type && card->info.is_multicast_different) ?
2956 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2957 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002958 int tx_bytes = skb->len;
Michał Mirosław6204b472011-04-19 00:43:20 +00002959 bool large_send;
Frank Blaschka683d7182008-08-01 16:39:13 +02002960 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002961 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002962
Frank Blaschkab3332932011-08-08 01:33:59 +00002963 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2964 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2965 ((card->options.cq == QETH_CQ_ENABLED) &&
2966 (skb->protocol != ETH_P_AF_IUCV)))) ||
2967 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002968 goto tx_drop;
2969
2970 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2971 card->stats.tx_carrier_errors++;
2972 goto tx_drop;
2973 }
2974
2975 if ((cast_type == RTN_BROADCAST) &&
2976 (card->info.broadcast_capable == 0))
2977 goto tx_drop;
2978
2979 if (card->options.performance_stats) {
2980 card->perf_stats.outbound_cnt++;
2981 card->perf_stats.outbound_start_time = qeth_get_micros();
2982 }
2983
Michał Mirosław6204b472011-04-19 00:43:20 +00002984 large_send = skb_is_gso(skb);
Frank Blaschka683d7182008-08-01 16:39:13 +02002985
2986 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2987 (skb_shinfo(skb)->nr_frags == 0)) {
2988 new_skb = skb;
Frank Blaschkab3332932011-08-08 01:33:59 +00002989 if (new_skb->protocol == ETH_P_AF_IUCV)
2990 data_offset = 0;
2991 else
2992 data_offset = ETH_HLEN;
Frank Blaschka683d7182008-08-01 16:39:13 +02002993 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2994 if (!hdr)
2995 goto tx_drop;
2996 elements_needed++;
2997 } else {
2998 /* create a clone with writeable headroom */
2999 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
3000 + VLAN_HLEN);
3001 if (!new_skb)
3002 goto tx_drop;
3003 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003004
3005 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02003006 if (data_offset < 0)
3007 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003008 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00003009 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04003010 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003011 }
3012
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003013 if (ipv != 4 && vlan_tx_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003014 skb_push(new_skb, VLAN_HLEN);
3015 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
3016 skb_copy_to_linear_data_offset(new_skb, 4,
3017 new_skb->data + 8, 4);
3018 skb_copy_to_linear_data_offset(new_skb, 8,
3019 new_skb->data + 12, 4);
3020 tag = (u16 *)(new_skb->data + 12);
3021 *tag = __constant_htons(ETH_P_8021Q);
3022 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003023 }
3024 }
3025
3026 netif_stop_queue(dev);
3027
Frank Blaschka4a71df52008-02-15 09:19:42 +01003028 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003029 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003030 */
Michał Mirosław6204b472011-04-19 00:43:20 +00003031 if (large_send) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003032 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3033 if (skb_linearize(new_skb))
3034 goto tx_drop;
3035 if (card->options.performance_stats)
3036 card->perf_stats.tx_lin++;
3037 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003038 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003039
Michał Mirosław6204b472011-04-19 00:43:20 +00003040 if (large_send && (cast_type == RTN_UNSPEC)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003041 hdr = (struct qeth_hdr *)skb_push(new_skb,
3042 sizeof(struct qeth_hdr_tso));
3043 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3044 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3045 qeth_tso_fill_header(card, hdr, new_skb);
3046 elements_needed++;
3047 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003048 if (data_offset < 0) {
3049 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003050 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003051 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3052 cast_type);
3053 } else {
Frank Blaschkab3332932011-08-08 01:33:59 +00003054 if (new_skb->protocol == ETH_P_AF_IUCV)
3055 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
3056 else {
3057 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3058 cast_type);
3059 hdr->hdr.l3.length = new_skb->len - data_offset;
3060 }
Frank Blaschka683d7182008-08-01 16:39:13 +02003061 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003062
3063 if (skb->ip_summed == CHECKSUM_PARTIAL)
3064 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003065 }
3066
Stefan Raspl065cc782013-04-22 01:12:28 +00003067 elems = qeth_get_elements_no(card, new_skb, elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003068 if (!elems) {
3069 if (data_offset >= 0)
3070 kmem_cache_free(qeth_core_header_cache, hdr);
3071 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003072 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003073 elements_needed += elems;
3074 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003075
Frank Blaschka51aa1652010-06-21 22:57:10 +00003076 if (card->info.type != QETH_CARD_TYPE_IQD) {
3077 int len;
Michał Mirosław6204b472011-04-19 00:43:20 +00003078 if (large_send)
Frank Blaschka51aa1652010-06-21 22:57:10 +00003079 len = ((unsigned long)tcp_hdr(new_skb) +
3080 tcp_hdr(new_skb)->doff * 4) -
3081 (unsigned long)new_skb->data;
3082 else
3083 len = sizeof(struct qeth_hdr_layer3);
3084
Stefan Raspld4ae1f52013-04-22 01:12:29 +00003085 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00003086 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003087 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003088 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003089 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003090 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003091 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003092
3093 if (!rc) {
3094 card->stats.tx_packets++;
3095 card->stats.tx_bytes += tx_bytes;
3096 if (new_skb != skb)
3097 dev_kfree_skb_any(skb);
3098 if (card->options.performance_stats) {
Michał Mirosław6204b472011-04-19 00:43:20 +00003099 if (large_send) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003100 card->perf_stats.large_send_bytes += tx_bytes;
3101 card->perf_stats.large_send_cnt++;
3102 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003103 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003104 card->perf_stats.sg_skbs_sent++;
3105 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003106 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003107 }
3108 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003109 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003110 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003111 if (data_offset >= 0)
3112 kmem_cache_free(qeth_core_header_cache, hdr);
3113
Frank Blaschka4a71df52008-02-15 09:19:42 +01003114 if (rc == -EBUSY) {
3115 if (new_skb != skb)
3116 dev_kfree_skb_any(new_skb);
3117 return NETDEV_TX_BUSY;
3118 } else
3119 goto tx_drop;
3120 }
3121
3122 netif_wake_queue(dev);
3123 if (card->options.performance_stats)
3124 card->perf_stats.outbound_time += qeth_get_micros() -
3125 card->perf_stats.outbound_start_time;
3126 return rc;
3127
3128tx_drop:
3129 card->stats.tx_dropped++;
3130 card->stats.tx_errors++;
3131 if ((new_skb != skb) && new_skb)
3132 dev_kfree_skb_any(new_skb);
3133 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003134 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003135 return NETDEV_TX_OK;
3136}
3137
Ursula Braun39423442011-01-12 20:42:24 +00003138static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003139{
Heiko Carstens509e2562008-07-26 02:24:10 -07003140 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003141 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003142
Carsten Otte847a50f2010-06-21 22:57:05 +00003143 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00003144 if (card->state == CARD_STATE_UP)
3145 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003146 if (card->state != CARD_STATE_SOFTSETUP)
3147 return -ENODEV;
3148 card->data.state = CH_STATE_UP;
3149 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003150 netif_start_queue(dev);
3151
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003152 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3153 napi_enable(&card->napi);
3154 napi_schedule(&card->napi);
3155 } else
3156 rc = -EIO;
3157 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003158}
3159
Ursula Braun39423442011-01-12 20:42:24 +00003160static int qeth_l3_open(struct net_device *dev)
3161{
3162 struct qeth_card *card = dev->ml_priv;
3163
3164 QETH_CARD_TEXT(card, 5, "qethope_");
3165 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3166 QETH_CARD_TEXT(card, 3, "openREC");
3167 return -ERESTARTSYS;
3168 }
3169 return __qeth_l3_open(dev);
3170}
3171
Frank Blaschka4a71df52008-02-15 09:19:42 +01003172static int qeth_l3_stop(struct net_device *dev)
3173{
Heiko Carstens509e2562008-07-26 02:24:10 -07003174 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003175
Carsten Otte847a50f2010-06-21 22:57:05 +00003176 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003177 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003178 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003179 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003180 napi_disable(&card->napi);
3181 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003182 return 0;
3183}
3184
Michał Mirosławc8f44af2011-11-15 15:29:55 +00003185static netdev_features_t qeth_l3_fix_features(struct net_device *dev,
3186 netdev_features_t features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003187{
Heiko Carstens509e2562008-07-26 02:24:10 -07003188 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003189
Michał Mirosław6204b472011-04-19 00:43:20 +00003190 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3191 features &= ~NETIF_F_IP_CSUM;
3192 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
3193 features &= ~NETIF_F_TSO;
3194 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
3195 features &= ~NETIF_F_RXCSUM;
3196
3197 return features;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003198}
3199
Michał Mirosławc8f44af2011-11-15 15:29:55 +00003200static int qeth_l3_set_features(struct net_device *dev,
3201 netdev_features_t features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003202{
Michał Mirosław6204b472011-04-19 00:43:20 +00003203 struct qeth_card *card = dev->ml_priv;
3204 u32 changed = dev->features ^ features;
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003205 int err;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003206
Michał Mirosław6204b472011-04-19 00:43:20 +00003207 if (!(changed & NETIF_F_RXCSUM))
3208 return 0;
3209
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003210 if (card->state == CARD_STATE_DOWN ||
3211 card->state == CARD_STATE_RECOVER)
3212 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003213
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003214 err = qeth_l3_set_rx_csum(card, features & NETIF_F_RXCSUM);
3215 if (err)
3216 dev->features = features ^ NETIF_F_RXCSUM;
3217
3218 return err;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003219}
3220
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003221static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003222 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003223 .get_strings = qeth_core_get_strings,
3224 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003225 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003226 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003227 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003228};
3229
3230/*
3231 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3232 * NOARP on the netdevice is no option because it also turns off neighbor
3233 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3234 * arp resolution but we want the hard header (packet socket will work
3235 * e.g. tcpdump)
3236 */
3237static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3238{
3239 n->nud_state = NUD_NOARP;
3240 memcpy(n->ha, "FAKELL", 6);
3241 n->output = n->ops->connected_output;
3242 return 0;
3243}
3244
3245static int
3246qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3247{
3248 if (np->tbl->family == AF_INET)
3249 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3250
3251 return 0;
3252}
3253
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003254static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003255 .ndo_open = qeth_l3_open,
3256 .ndo_stop = qeth_l3_stop,
3257 .ndo_get_stats = qeth_get_stats,
3258 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3259 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003260 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003261 .ndo_do_ioctl = qeth_l3_do_ioctl,
3262 .ndo_change_mtu = qeth_change_mtu,
3263 .ndo_fix_features = qeth_l3_fix_features,
3264 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003265 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3266 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003267 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08003268};
3269
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003270static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3271 .ndo_open = qeth_l3_open,
3272 .ndo_stop = qeth_l3_stop,
3273 .ndo_get_stats = qeth_get_stats,
3274 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3275 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003276 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003277 .ndo_do_ioctl = qeth_l3_do_ioctl,
3278 .ndo_change_mtu = qeth_change_mtu,
3279 .ndo_fix_features = qeth_l3_fix_features,
3280 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003281 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3282 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003283 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003284 .ndo_neigh_setup = qeth_l3_neigh_setup,
3285};
3286
Frank Blaschka4a71df52008-02-15 09:19:42 +01003287static int qeth_l3_setup_netdev(struct qeth_card *card)
3288{
Thomas Richter1aec42b2015-01-21 13:39:10 +01003289 int rc;
3290
Ursula Braun5113fec2010-05-16 21:15:14 +00003291 if (card->info.type == QETH_CARD_TYPE_OSD ||
3292 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003293 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3294 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04003295 pr_info("qeth_l3: ignoring TR device\n");
3296 return -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003297 } else {
3298 card->dev = alloc_etherdev(0);
3299 if (!card->dev)
3300 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003301 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003302
3303 /*IPv6 address autoconfiguration stuff*/
3304 qeth_l3_get_unique_id(card);
3305 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3306 card->dev->dev_id = card->info.unique_id &
3307 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003308 if (!card->info.guestlan) {
3309 card->dev->hw_features = NETIF_F_SG |
3310 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3311 NETIF_F_TSO;
3312 card->dev->features = NETIF_F_RXCSUM;
3313 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003314 }
3315 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02003316 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
3317 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003318 if (!card->dev)
3319 return -ENODEV;
3320 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003321 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01003322 rc = qeth_l3_iqd_read_initial_mac(card);
3323 if (rc)
3324 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00003325 if (card->options.hsuid[0])
3326 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003327 } else
3328 return -ENODEV;
3329
Heiko Carstens509e2562008-07-26 02:24:10 -07003330 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003331 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003332 card->dev->mtu = card->info.initial_mtu;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003333 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00003334 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
3335 NETIF_F_HW_VLAN_CTAG_RX |
3336 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07003337 netif_keep_dst(card->dev);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003338 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003339
3340 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003341 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003342 return register_netdev(card->dev);
3343}
3344
Frank Blaschka4a71df52008-02-15 09:19:42 +01003345static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3346{
3347 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3348
3349 qeth_l3_create_device_attributes(&gdev->dev);
3350 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003351 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003352 return 0;
3353}
3354
3355static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3356{
3357 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3358
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003359 qeth_l3_remove_device_attributes(&cgdev->dev);
3360
Ursula Braunf2148562009-05-19 21:38:37 +00003361 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003362 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3363
Ursula Braun70919e22011-02-26 22:41:36 -08003364 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003365 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003366
3367 if (card->dev) {
3368 unregister_netdev(card->dev);
3369 card->dev = NULL;
3370 }
3371
Ursula Braun70919e22011-02-26 22:41:36 -08003372 qeth_l3_clear_ip_list(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003373 qeth_l3_clear_ipato_list(card);
3374 return;
3375}
3376
3377static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3378{
3379 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3380 int rc = 0;
3381 enum qeth_card_states recover_flag;
3382
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003383 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003384 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003385 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3386 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003387
Frank Blaschka4a71df52008-02-15 09:19:42 +01003388 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003389 rc = qeth_core_hardsetup_card(card);
3390 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01003391 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003392 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003393 goto out_remove;
3394 }
3395
Ursula Braunaa909222009-11-12 00:11:43 +00003396 if (!card->dev && qeth_l3_setup_netdev(card)) {
3397 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003398 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003399 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003400
Frank Blaschka1da74b12011-05-12 18:45:02 +00003401 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3402 if (card->info.hwtrap &&
3403 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3404 card->info.hwtrap = 0;
3405 } else
3406 card->info.hwtrap = 0;
3407
Frank Blaschka4a71df52008-02-15 09:19:42 +01003408 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003409 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003410 qeth_print_status_message(card);
3411
3412 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003413 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003414
3415 rc = qeth_send_startlan(card);
3416 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003417 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003418 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003419 dev_warn(&card->gdev->dev,
3420 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003421 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003422 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003423 }
Ursula Braunaa909222009-11-12 00:11:43 +00003424 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003425 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003426 } else
3427 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003428
Ursula Braun2b6203b2010-11-26 02:41:19 +00003429contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003430 rc = qeth_l3_setadapter_parms(card);
3431 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003432 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003433 if (!card->options.sniffer) {
3434 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00003435 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00003436 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00003437 goto out_remove;
3438 }
Ursula Braun76b11f82010-01-11 02:50:50 +00003439 rc = qeth_l3_setrouting_v4(card);
3440 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003441 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003442 rc = qeth_l3_setrouting_v6(card);
3443 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003444 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003445 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003446 netif_tx_disable(card->dev);
3447
3448 rc = qeth_init_qdio_queues(card);
3449 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003450 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003451 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003452 goto out_remove;
3453 }
3454 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003455
3456 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003457 qeth_l3_set_ip_addr_list(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003458 if (card->lan_online)
3459 netif_carrier_on(card->dev);
3460 else
3461 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003462 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00003463 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003464 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003465 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003466 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003467 dev_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003468 qeth_l3_set_multicast_list(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003469 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003470 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00003471 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003472 /* let user_space know that device is online */
3473 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003474 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003475 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003476 return 0;
3477out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003478 qeth_l3_stop_card(card, 0);
3479 ccw_device_set_offline(CARD_DDEV(card));
3480 ccw_device_set_offline(CARD_WDEV(card));
3481 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01003482 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003483 if (recover_flag == CARD_STATE_RECOVER)
3484 card->state = CARD_STATE_RECOVER;
3485 else
3486 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003487 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003488 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003489 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003490}
3491
3492static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3493{
3494 return __qeth_l3_set_online(gdev, 0);
3495}
3496
3497static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3498 int recovery_mode)
3499{
3500 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3501 int rc = 0, rc2 = 0, rc3 = 0;
3502 enum qeth_card_states recover_flag;
3503
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003504 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003505 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003506 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3507 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003508
3509 if (card->dev && netif_carrier_ok(card->dev))
3510 netif_carrier_off(card->dev);
3511 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003512 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3513 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3514 card->info.hwtrap = 1;
3515 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003516 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00003517 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3518 rtnl_lock();
3519 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3520 rtnl_unlock();
3521 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003522 rc = ccw_device_set_offline(CARD_DDEV(card));
3523 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3524 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3525 if (!rc)
3526 rc = (rc2) ? rc2 : rc3;
3527 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003528 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01003529 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003530 if (recover_flag == CARD_STATE_UP)
3531 card->state = CARD_STATE_RECOVER;
3532 /* let user_space know that device is offline */
3533 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003534 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003535 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003536 return 0;
3537}
3538
3539static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3540{
3541 return __qeth_l3_set_offline(cgdev, 0);
3542}
3543
3544static int qeth_l3_recover(void *ptr)
3545{
3546 struct qeth_card *card;
3547 int rc = 0;
3548
3549 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003550 QETH_CARD_TEXT(card, 2, "recover1");
3551 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003552 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3553 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003554 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003555 dev_warn(&card->gdev->dev,
3556 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00003557 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003558 __qeth_l3_set_offline(card->gdev, 1);
3559 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003560 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003561 dev_info(&card->gdev->dev,
3562 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003563 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00003564 qeth_close_dev(card);
3565 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00003566 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003567 }
Stefan Raspl65d80132013-04-07 22:19:27 +00003568 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003569 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3570 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003571 return 0;
3572}
3573
3574static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3575{
3576 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00003577 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00003578 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3579 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003580 qeth_qdio_clear_card(card, 0);
3581 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01003582 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003583}
3584
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003585static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3586{
3587 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3588
3589 if (card->dev)
3590 netif_device_detach(card->dev);
3591 qeth_set_allowed_threads(card, 0, 1);
3592 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3593 if (gdev->state == CCWGROUP_OFFLINE)
3594 return 0;
3595 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003596 if (card->info.hwtrap)
3597 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003598 __qeth_l3_set_offline(card->gdev, 1);
3599 } else
3600 __qeth_l3_set_offline(card->gdev, 0);
3601 return 0;
3602}
3603
3604static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3605{
3606 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3607 int rc = 0;
3608
3609 if (gdev->state == CCWGROUP_OFFLINE)
3610 goto out;
3611
3612 if (card->state == CARD_STATE_RECOVER) {
3613 rc = __qeth_l3_set_online(card->gdev, 1);
3614 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003615 rtnl_lock();
3616 dev_close(card->dev);
3617 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003618 }
3619 } else
3620 rc = __qeth_l3_set_online(card->gdev, 0);
3621out:
3622 qeth_set_allowed_threads(card, 0xffffffff, 0);
3623 if (card->dev)
3624 netif_device_attach(card->dev);
3625 if (rc)
3626 dev_warn(&card->gdev->dev, "The qeth device driver "
3627 "failed to recover an error on the device\n");
3628 return rc;
3629}
3630
Eugene Crosserc044dc22014-01-29 09:23:48 +01003631/* Returns zero if the command is successfully "consumed" */
3632static int qeth_l3_control_event(struct qeth_card *card,
3633 struct qeth_ipa_cmd *cmd)
3634{
3635 return 1;
3636}
3637
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003638struct qeth_discipline qeth_l3_discipline = {
3639 .start_poll = qeth_qdio_start_poll,
3640 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3641 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
3642 .recover = qeth_l3_recover,
3643 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003644 .remove = qeth_l3_remove_device,
3645 .set_online = qeth_l3_set_online,
3646 .set_offline = qeth_l3_set_offline,
3647 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003648 .freeze = qeth_l3_pm_suspend,
3649 .thaw = qeth_l3_pm_resume,
3650 .restore = qeth_l3_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01003651 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003652};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003653EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003654
3655static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003656 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003657{
3658 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3659 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3660 struct qeth_ipaddr *addr;
3661 struct qeth_card *card;
3662
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003663 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003664 return NOTIFY_DONE;
3665
Frank Blaschka4a71df52008-02-15 09:19:42 +01003666 card = qeth_l3_get_card_from_dev(dev);
3667 if (!card)
3668 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00003669 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003670
3671 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3672 if (addr != NULL) {
3673 addr->u.a4.addr = ifa->ifa_address;
3674 addr->u.a4.mask = ifa->ifa_mask;
3675 addr->type = QETH_IP_TYPE_NORMAL;
3676 } else
3677 goto out;
3678
3679 switch (event) {
3680 case NETDEV_UP:
3681 if (!qeth_l3_add_ip(card, addr))
3682 kfree(addr);
3683 break;
3684 case NETDEV_DOWN:
3685 if (!qeth_l3_delete_ip(card, addr))
3686 kfree(addr);
3687 break;
3688 default:
3689 break;
3690 }
3691 qeth_l3_set_ip_addr_list(card);
3692out:
3693 return NOTIFY_DONE;
3694}
3695
3696static struct notifier_block qeth_l3_ip_notifier = {
3697 qeth_l3_ip_event,
3698 NULL,
3699};
3700
3701#ifdef CONFIG_QETH_IPV6
3702/**
3703 * IPv6 event handler
3704 */
3705static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003706 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003707{
3708 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3709 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3710 struct qeth_ipaddr *addr;
3711 struct qeth_card *card;
3712
Frank Blaschka4a71df52008-02-15 09:19:42 +01003713 card = qeth_l3_get_card_from_dev(dev);
3714 if (!card)
3715 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003716 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003717 if (!qeth_is_supported(card, IPA_IPV6))
3718 return NOTIFY_DONE;
3719
3720 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3721 if (addr != NULL) {
3722 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3723 addr->u.a6.pfxlen = ifa->prefix_len;
3724 addr->type = QETH_IP_TYPE_NORMAL;
3725 } else
3726 goto out;
3727
3728 switch (event) {
3729 case NETDEV_UP:
3730 if (!qeth_l3_add_ip(card, addr))
3731 kfree(addr);
3732 break;
3733 case NETDEV_DOWN:
3734 if (!qeth_l3_delete_ip(card, addr))
3735 kfree(addr);
3736 break;
3737 default:
3738 break;
3739 }
3740 qeth_l3_set_ip_addr_list(card);
3741out:
3742 return NOTIFY_DONE;
3743}
3744
3745static struct notifier_block qeth_l3_ip6_notifier = {
3746 qeth_l3_ip6_event,
3747 NULL,
3748};
3749#endif
3750
3751static int qeth_l3_register_notifiers(void)
3752{
3753 int rc;
3754
Carsten Otte847a50f2010-06-21 22:57:05 +00003755 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003756 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3757 if (rc)
3758 return rc;
3759#ifdef CONFIG_QETH_IPV6
3760 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3761 if (rc) {
3762 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3763 return rc;
3764 }
3765#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003766 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003767#endif
3768 return 0;
3769}
3770
3771static void qeth_l3_unregister_notifiers(void)
3772{
3773
Carsten Otte847a50f2010-06-21 22:57:05 +00003774 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00003775 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003776#ifdef CONFIG_QETH_IPV6
Stefan Raspl18af5c12012-11-19 02:46:50 +00003777 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003778#endif /* QETH_IPV6 */
3779}
3780
3781static int __init qeth_l3_init(void)
3782{
3783 int rc = 0;
3784
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003785 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003786 rc = qeth_l3_register_notifiers();
3787 return rc;
3788}
3789
3790static void __exit qeth_l3_exit(void)
3791{
3792 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003793 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003794}
3795
3796module_init(qeth_l3_init);
3797module_exit(qeth_l3_exit);
3798MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3799MODULE_DESCRIPTION("qeth layer 3 discipline");
3800MODULE_LICENSE("GPL");