blob: 70eb2f61bb9269221f4c389838b67bf90fc071ba [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
Eugene Crosserc3521252015-01-16 14:05:47 +0100435 if (!qeth_card_hw_is_reachable(card) || card->options.sniffer)
Ursula Braun76b11f82010-01-11 02:50:50 +0000436 return;
Einar Lueckf154b792010-12-08 02:57:59 +0000437
Frank Blaschka4a71df52008-02-15 09:19:42 +0100438 spin_lock_irqsave(&card->ip_lock, flags);
439 tbd_list = card->ip_tbd_list;
Frank Blaschkab3332932011-08-08 01:33:59 +0000440 card->ip_tbd_list = kzalloc(sizeof(struct list_head), GFP_ATOMIC);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 if (!card->ip_tbd_list) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000442 QETH_CARD_TEXT(card, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443 card->ip_tbd_list = tbd_list;
444 spin_unlock_irqrestore(&card->ip_lock, flags);
445 return;
446 } else
447 INIT_LIST_HEAD(card->ip_tbd_list);
448
449 while (!list_empty(tbd_list)) {
450 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
451 list_del(&todo->entry);
452 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
453 __qeth_l3_delete_all_mc(card, &flags);
454 kfree(todo);
455 continue;
456 }
457 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
458 if (rc == 0) {
459 /* nothing to be done; only adjusted refcount */
460 kfree(todo);
461 } else if (rc == 1) {
462 /* new entry to be added to on-card list */
463 spin_unlock_irqrestore(&card->ip_lock, flags);
464 rc = qeth_l3_register_addr_entry(card, todo);
465 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200466 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100467 list_add_tail(&todo->entry, &card->ip_list);
468 else
469 kfree(todo);
470 } else if (rc == -1) {
471 /* on-card entry to be removed */
472 list_del_init(&addr->entry);
473 spin_unlock_irqrestore(&card->ip_lock, flags);
474 rc = qeth_l3_deregister_addr_entry(card, addr);
475 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun76b11f82010-01-11 02:50:50 +0000476 if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100477 kfree(addr);
478 else
479 list_add_tail(&addr->entry, &card->ip_list);
480 kfree(todo);
481 }
482 }
483 spin_unlock_irqrestore(&card->ip_lock, flags);
484 kfree(tbd_list);
485}
486
Ursula Braun70919e22011-02-26 22:41:36 -0800487static void qeth_l3_clear_ip_list(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100488{
489 struct qeth_ipaddr *addr, *tmp;
490 unsigned long flags;
491
Carsten Otte847a50f2010-06-21 22:57:05 +0000492 QETH_CARD_TEXT(card, 4, "clearip");
Ursula Braun76b11f82010-01-11 02:50:50 +0000493 if (recover && card->options.sniffer)
494 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100495 spin_lock_irqsave(&card->ip_lock, flags);
496 /* clear todo list */
497 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
498 list_del(&addr->entry);
499 kfree(addr);
500 }
501
502 while (!list_empty(&card->ip_list)) {
503 addr = list_entry(card->ip_list.next,
504 struct qeth_ipaddr, entry);
505 list_del_init(&addr->entry);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100506 if (!recover || addr->is_multicast) {
507 kfree(addr);
508 continue;
509 }
510 list_add_tail(&addr->entry, card->ip_tbd_list);
511 }
512 spin_unlock_irqrestore(&card->ip_lock, flags);
513}
514
515static int qeth_l3_address_exists_in_list(struct list_head *list,
516 struct qeth_ipaddr *addr, int same_type)
517{
518 struct qeth_ipaddr *tmp;
519
520 list_for_each_entry(tmp, list, entry) {
521 if ((tmp->proto == QETH_PROT_IPV4) &&
522 (addr->proto == QETH_PROT_IPV4) &&
523 ((same_type && (tmp->type == addr->type)) ||
524 (!same_type && (tmp->type != addr->type))) &&
525 (tmp->u.a4.addr == addr->u.a4.addr))
526 return 1;
527
528 if ((tmp->proto == QETH_PROT_IPV6) &&
529 (addr->proto == QETH_PROT_IPV6) &&
530 ((same_type && (tmp->type == addr->type)) ||
531 (!same_type && (tmp->type != addr->type))) &&
532 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
533 sizeof(struct in6_addr)) == 0))
534 return 1;
535
536 }
537 return 0;
538}
539
540static int qeth_l3_send_setdelmc(struct qeth_card *card,
541 struct qeth_ipaddr *addr, int ipacmd)
542{
543 int rc;
544 struct qeth_cmd_buffer *iob;
545 struct qeth_ipa_cmd *cmd;
546
Carsten Otte847a50f2010-06-21 22:57:05 +0000547 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100548
549 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100550 if (!iob)
551 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100552 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
553 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
554 if (addr->proto == QETH_PROT_IPV6)
555 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
556 sizeof(struct in6_addr));
557 else
558 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
559
560 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
561
562 return rc;
563}
564
565static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
566{
567 int i, j;
568 for (i = 0; i < 16; i++) {
569 j = (len) - (i * 8);
570 if (j >= 8)
571 netmask[i] = 0xff;
572 else if (j > 0)
573 netmask[i] = (u8)(0xFF00 >> j);
574 else
575 netmask[i] = 0;
576 }
577}
578
579static int qeth_l3_send_setdelip(struct qeth_card *card,
580 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
581{
582 int rc;
583 struct qeth_cmd_buffer *iob;
584 struct qeth_ipa_cmd *cmd;
585 __u8 netmask[16];
586
Carsten Otte847a50f2010-06-21 22:57:05 +0000587 QETH_CARD_TEXT(card, 4, "setdelip");
588 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100589
590 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100591 if (!iob)
592 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100593 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
594 if (addr->proto == QETH_PROT_IPV6) {
595 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
596 sizeof(struct in6_addr));
597 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
598 memcpy(cmd->data.setdelip6.mask, netmask,
599 sizeof(struct in6_addr));
600 cmd->data.setdelip6.flags = flags;
601 } else {
602 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
603 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
604 cmd->data.setdelip4.flags = flags;
605 }
606
607 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
608
609 return rc;
610}
611
612static int qeth_l3_send_setrouting(struct qeth_card *card,
613 enum qeth_routing_types type, enum qeth_prot_versions prot)
614{
615 int rc;
616 struct qeth_ipa_cmd *cmd;
617 struct qeth_cmd_buffer *iob;
618
Carsten Otte847a50f2010-06-21 22:57:05 +0000619 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100620 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100621 if (!iob)
622 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100623 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
624 cmd->data.setrtg.type = (type);
625 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
626
627 return rc;
628}
629
Stefan Raspl82e2e782013-03-18 20:04:43 +0000630static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100631 enum qeth_routing_types *type, enum qeth_prot_versions prot)
632{
633 if (card->info.type == QETH_CARD_TYPE_IQD) {
634 switch (*type) {
635 case NO_ROUTER:
636 case PRIMARY_CONNECTOR:
637 case SECONDARY_CONNECTOR:
638 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000639 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640 default:
641 goto out_inval;
642 }
643 } else {
644 switch (*type) {
645 case NO_ROUTER:
646 case PRIMARY_ROUTER:
647 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000648 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100649 case MULTICAST_ROUTER:
650 if (qeth_is_ipafunc_supported(card, prot,
651 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000652 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100653 default:
654 goto out_inval;
655 }
656 }
657out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100658 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000659 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100660}
661
662int qeth_l3_setrouting_v4(struct qeth_card *card)
663{
664 int rc;
665
Carsten Otte847a50f2010-06-21 22:57:05 +0000666 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100667
Stefan Raspl82e2e782013-03-18 20:04:43 +0000668 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100669 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000670 if (rc)
671 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100672
673 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
674 QETH_PROT_IPV4);
675 if (rc) {
676 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200677 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
678 " on %s. Type set to 'no router'.\n", rc,
679 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100680 }
681 return rc;
682}
683
684int qeth_l3_setrouting_v6(struct qeth_card *card)
685{
686 int rc = 0;
687
Carsten Otte847a50f2010-06-21 22:57:05 +0000688 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100689#ifdef CONFIG_QETH_IPV6
690
691 if (!qeth_is_supported(card, IPA_IPV6))
692 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000693 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100694 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000695 if (rc)
696 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100697
698 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
699 QETH_PROT_IPV6);
700 if (rc) {
701 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200702 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
703 " on %s. Type set to 'no router'.\n", rc,
704 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100705 }
706#endif
707 return rc;
708}
709
710/*
711 * IP address takeover related functions
712 */
713static void qeth_l3_clear_ipato_list(struct qeth_card *card)
714{
715
716 struct qeth_ipato_entry *ipatoe, *tmp;
717 unsigned long flags;
718
719 spin_lock_irqsave(&card->ip_lock, flags);
720 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
721 list_del(&ipatoe->entry);
722 kfree(ipatoe);
723 }
724 spin_unlock_irqrestore(&card->ip_lock, flags);
725}
726
727int qeth_l3_add_ipato_entry(struct qeth_card *card,
728 struct qeth_ipato_entry *new)
729{
730 struct qeth_ipato_entry *ipatoe;
731 unsigned long flags;
732 int rc = 0;
733
Carsten Otte847a50f2010-06-21 22:57:05 +0000734 QETH_CARD_TEXT(card, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100735 spin_lock_irqsave(&card->ip_lock, flags);
736 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
737 if (ipatoe->proto != new->proto)
738 continue;
739 if (!memcmp(ipatoe->addr, new->addr,
740 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
741 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100742 rc = -EEXIST;
743 break;
744 }
745 }
746 if (!rc)
747 list_add_tail(&new->entry, &card->ipato.entries);
748
749 spin_unlock_irqrestore(&card->ip_lock, flags);
750 return rc;
751}
752
753void qeth_l3_del_ipato_entry(struct qeth_card *card,
754 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
755{
756 struct qeth_ipato_entry *ipatoe, *tmp;
757 unsigned long flags;
758
Carsten Otte847a50f2010-06-21 22:57:05 +0000759 QETH_CARD_TEXT(card, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100760 spin_lock_irqsave(&card->ip_lock, flags);
761 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
762 if (ipatoe->proto != proto)
763 continue;
764 if (!memcmp(ipatoe->addr, addr,
765 (proto == QETH_PROT_IPV4)? 4:16) &&
766 (ipatoe->mask_bits == mask_bits)) {
767 list_del(&ipatoe->entry);
768 kfree(ipatoe);
769 }
770 }
771 spin_unlock_irqrestore(&card->ip_lock, flags);
772}
773
774/*
775 * VIPA related functions
776 */
777int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
778 const u8 *addr)
779{
780 struct qeth_ipaddr *ipaddr;
781 unsigned long flags;
782 int rc = 0;
783
784 ipaddr = qeth_l3_get_addr_buffer(proto);
785 if (ipaddr) {
786 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000787 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 memcpy(&ipaddr->u.a4.addr, addr, 4);
789 ipaddr->u.a4.mask = 0;
790 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000791 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100792 memcpy(&ipaddr->u.a6.addr, addr, 16);
793 ipaddr->u.a6.pfxlen = 0;
794 }
795 ipaddr->type = QETH_IP_TYPE_VIPA;
796 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
797 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
798 } else
799 return -ENOMEM;
800 spin_lock_irqsave(&card->ip_lock, flags);
801 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
802 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
803 rc = -EEXIST;
804 spin_unlock_irqrestore(&card->ip_lock, flags);
805 if (rc) {
Wei Yongjunf68bd072012-09-24 04:24:25 +0000806 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100807 return rc;
808 }
809 if (!qeth_l3_add_ip(card, ipaddr))
810 kfree(ipaddr);
811 qeth_l3_set_ip_addr_list(card);
812 return rc;
813}
814
815void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
816 const u8 *addr)
817{
818 struct qeth_ipaddr *ipaddr;
819
820 ipaddr = qeth_l3_get_addr_buffer(proto);
821 if (ipaddr) {
822 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000823 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100824 memcpy(&ipaddr->u.a4.addr, addr, 4);
825 ipaddr->u.a4.mask = 0;
826 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000827 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100828 memcpy(&ipaddr->u.a6.addr, addr, 16);
829 ipaddr->u.a6.pfxlen = 0;
830 }
831 ipaddr->type = QETH_IP_TYPE_VIPA;
832 } else
833 return;
834 if (!qeth_l3_delete_ip(card, ipaddr))
835 kfree(ipaddr);
836 qeth_l3_set_ip_addr_list(card);
837}
838
839/*
840 * proxy ARP related functions
841 */
842int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
843 const u8 *addr)
844{
845 struct qeth_ipaddr *ipaddr;
846 unsigned long flags;
847 int rc = 0;
848
849 ipaddr = qeth_l3_get_addr_buffer(proto);
850 if (ipaddr) {
851 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000852 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853 memcpy(&ipaddr->u.a4.addr, addr, 4);
854 ipaddr->u.a4.mask = 0;
855 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000856 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100857 memcpy(&ipaddr->u.a6.addr, addr, 16);
858 ipaddr->u.a6.pfxlen = 0;
859 }
860 ipaddr->type = QETH_IP_TYPE_RXIP;
861 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
862 ipaddr->del_flags = 0;
863 } else
864 return -ENOMEM;
865 spin_lock_irqsave(&card->ip_lock, flags);
866 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
867 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
868 rc = -EEXIST;
869 spin_unlock_irqrestore(&card->ip_lock, flags);
870 if (rc) {
Wei Yongjunf68bd072012-09-24 04:24:25 +0000871 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872 return rc;
873 }
874 if (!qeth_l3_add_ip(card, ipaddr))
875 kfree(ipaddr);
876 qeth_l3_set_ip_addr_list(card);
877 return 0;
878}
879
880void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
881 const u8 *addr)
882{
883 struct qeth_ipaddr *ipaddr;
884
885 ipaddr = qeth_l3_get_addr_buffer(proto);
886 if (ipaddr) {
887 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000888 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100889 memcpy(&ipaddr->u.a4.addr, addr, 4);
890 ipaddr->u.a4.mask = 0;
891 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000892 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100893 memcpy(&ipaddr->u.a6.addr, addr, 16);
894 ipaddr->u.a6.pfxlen = 0;
895 }
896 ipaddr->type = QETH_IP_TYPE_RXIP;
897 } else
898 return;
899 if (!qeth_l3_delete_ip(card, ipaddr))
900 kfree(ipaddr);
901 qeth_l3_set_ip_addr_list(card);
902}
903
904static int qeth_l3_register_addr_entry(struct qeth_card *card,
905 struct qeth_ipaddr *addr)
906{
907 char buf[50];
908 int rc = 0;
909 int cnt = 3;
910
911 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000912 QETH_CARD_TEXT(card, 2, "setaddr4");
913 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100914 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000915 QETH_CARD_TEXT(card, 2, "setaddr6");
916 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
917 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100918 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000919 QETH_CARD_TEXT(card, 2, "setaddr?");
920 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100921 }
922 do {
923 if (addr->is_multicast)
924 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
925 else
926 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
927 addr->set_flags);
928 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000929 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100930 } while ((--cnt > 0) && rc);
931 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000932 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100934 dev_warn(&card->gdev->dev,
935 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100936 }
937 return rc;
938}
939
940static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
941 struct qeth_ipaddr *addr)
942{
943 int rc = 0;
944
945 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000946 QETH_CARD_TEXT(card, 2, "deladdr4");
947 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100948 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000949 QETH_CARD_TEXT(card, 2, "deladdr6");
950 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
951 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000953 QETH_CARD_TEXT(card, 2, "deladdr?");
954 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 }
956 if (addr->is_multicast)
957 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
958 else
959 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
960 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200961 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000962 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963
964 return rc;
965}
966
967static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
968{
969 if (cast_type == RTN_MULTICAST)
970 return QETH_CAST_MULTICAST;
971 if (cast_type == RTN_BROADCAST)
972 return QETH_CAST_BROADCAST;
973 return QETH_CAST_UNICAST;
974}
975
976static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
977{
978 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
979 if (cast_type == RTN_MULTICAST)
980 return ct | QETH_CAST_MULTICAST;
981 if (cast_type == RTN_ANYCAST)
982 return ct | QETH_CAST_ANYCAST;
983 if (cast_type == RTN_BROADCAST)
984 return ct | QETH_CAST_BROADCAST;
985 return ct | QETH_CAST_UNICAST;
986}
987
Frank Blaschka4a71df52008-02-15 09:19:42 +0100988static int qeth_l3_setadapter_parms(struct qeth_card *card)
989{
990 int rc;
991
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200992 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100993
994 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100995 dev_info(&card->gdev->dev,
996 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200997 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100998 return 0;
999 }
1000 rc = qeth_query_setadapterparms(card);
1001 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001002 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +00001003 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001004 return rc;
1005 }
1006 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1007 rc = qeth_setadpparms_change_macaddr(card);
1008 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001009 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001010 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011 }
1012
Frank Blaschka4a71df52008-02-15 09:19:42 +01001013 return rc;
1014}
1015
1016static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1017 struct qeth_reply *reply, unsigned long data)
1018{
1019 struct qeth_ipa_cmd *cmd;
1020
Carsten Otte847a50f2010-06-21 22:57:05 +00001021 QETH_CARD_TEXT(card, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001022
1023 cmd = (struct qeth_ipa_cmd *) data;
1024 if (cmd->hdr.return_code == 0) {
1025 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1026 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1027 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1028 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1029 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1030 }
1031 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1032 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1033 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001034 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001035 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001036 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1037 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1038 card->info.tx_csum_mask =
1039 cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001040 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001041 }
1042
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043 return 0;
1044}
1045
1046static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1047 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1048 __u16 len, enum qeth_prot_versions prot)
1049{
1050 struct qeth_cmd_buffer *iob;
1051 struct qeth_ipa_cmd *cmd;
1052
Carsten Otte847a50f2010-06-21 22:57:05 +00001053 QETH_CARD_TEXT(card, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001054 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1055
Thomas Richter1aec42b2015-01-21 13:39:10 +01001056 if (iob) {
1057 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1058 cmd->data.setassparms.hdr.assist_no = ipa_func;
1059 cmd->data.setassparms.hdr.length = 8 + len;
1060 cmd->data.setassparms.hdr.command_code = cmd_code;
1061 cmd->data.setassparms.hdr.return_code = 0;
1062 cmd->data.setassparms.hdr.seq_no = 0;
1063 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001064
1065 return iob;
1066}
1067
1068static int qeth_l3_send_setassparms(struct qeth_card *card,
1069 struct qeth_cmd_buffer *iob, __u16 len, long data,
1070 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1071 unsigned long),
1072 void *reply_param)
1073{
1074 int rc;
1075 struct qeth_ipa_cmd *cmd;
1076
Carsten Otte847a50f2010-06-21 22:57:05 +00001077 QETH_CARD_TEXT(card, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001078
1079 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1080 if (len <= sizeof(__u32))
1081 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1082 else /* (len > sizeof(__u32)) */
1083 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1084
1085 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1086 return rc;
1087}
1088
1089#ifdef CONFIG_QETH_IPV6
1090static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1091 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1092{
1093 int rc;
1094 struct qeth_cmd_buffer *iob;
1095
Carsten Otte847a50f2010-06-21 22:57:05 +00001096 QETH_CARD_TEXT(card, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001097 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1098 0, QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001099 if (!iob)
1100 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001101 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1102 qeth_l3_default_setassparms_cb, NULL);
1103 return rc;
1104}
1105#endif
1106
1107static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1108 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1109{
1110 int rc;
1111 int length = 0;
1112 struct qeth_cmd_buffer *iob;
1113
Carsten Otte847a50f2010-06-21 22:57:05 +00001114 QETH_CARD_TEXT(card, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001115 if (data)
1116 length = sizeof(__u32);
1117 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1118 length, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001119 if (!iob)
1120 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001121 rc = qeth_l3_send_setassparms(card, iob, length, data,
1122 qeth_l3_default_setassparms_cb, NULL);
1123 return rc;
1124}
1125
1126static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1127{
1128 int rc;
1129
Carsten Otte847a50f2010-06-21 22:57:05 +00001130 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001131
1132 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001133 dev_info(&card->gdev->dev,
1134 "ARP processing not supported on %s!\n",
1135 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001136 return 0;
1137 }
1138 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1139 IPA_CMD_ASS_START, 0);
1140 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001141 dev_warn(&card->gdev->dev,
1142 "Starting ARP processing support for %s failed\n",
1143 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001144 }
1145 return rc;
1146}
1147
1148static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1149{
1150 int rc;
1151
Carsten Otte847a50f2010-06-21 22:57:05 +00001152 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001153
1154 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001155 dev_info(&card->gdev->dev,
1156 "Hardware IP fragmentation not supported on %s\n",
1157 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001158 return -EOPNOTSUPP;
1159 }
1160
1161 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1162 IPA_CMD_ASS_START, 0);
1163 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001164 dev_warn(&card->gdev->dev,
1165 "Starting IP fragmentation support for %s failed\n",
1166 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001167 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001168 dev_info(&card->gdev->dev,
1169 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001170 return rc;
1171}
1172
1173static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1174{
1175 int rc;
1176
Carsten Otte847a50f2010-06-21 22:57:05 +00001177 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178
Frank Blaschka4a71df52008-02-15 09:19:42 +01001179 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001180 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001181 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001182 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001183 return -EOPNOTSUPP;
1184 }
1185
1186 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1187 IPA_CMD_ASS_START, 0);
1188 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001189 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001190 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001191 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001192 return rc;
1193}
1194
1195static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1196{
1197 int rc = 0;
1198
Carsten Otte847a50f2010-06-21 22:57:05 +00001199 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001200
1201 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001202 dev_info(&card->gdev->dev,
1203 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001204 return -EOPNOTSUPP;
1205 }
1206
1207 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1208 IPA_CMD_ASS_START, 0);
1209 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001210 dev_warn(&card->gdev->dev,
1211 "Starting VLAN support for %s failed\n",
1212 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001213 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001214 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001215 }
1216 return rc;
1217}
1218
1219static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1220{
1221 int rc;
1222
Carsten Otte847a50f2010-06-21 22:57:05 +00001223 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001224
1225 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001226 dev_info(&card->gdev->dev,
1227 "Multicast not supported on %s\n",
1228 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001229 return -EOPNOTSUPP;
1230 }
1231
1232 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1233 IPA_CMD_ASS_START, 0);
1234 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001235 dev_warn(&card->gdev->dev,
1236 "Starting multicast support for %s failed\n",
1237 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001238 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001239 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001240 card->dev->flags |= IFF_MULTICAST;
1241 }
1242 return rc;
1243}
1244
Frank Blaschka4a71df52008-02-15 09:19:42 +01001245#ifdef CONFIG_QETH_IPV6
1246static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1247{
1248 int rc;
1249
Carsten Otte847a50f2010-06-21 22:57:05 +00001250 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001251
1252 if (card->info.type == QETH_CARD_TYPE_IQD)
1253 goto out;
1254
Frank Blaschka1da74b12011-05-12 18:45:02 +00001255 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001257 dev_err(&card->gdev->dev,
1258 "Activating IPv6 support for %s failed\n",
1259 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001260 return rc;
1261 }
1262 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1263 IPA_CMD_ASS_START, 3);
1264 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001265 dev_err(&card->gdev->dev,
1266 "Activating IPv6 support for %s failed\n",
1267 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001268 return rc;
1269 }
1270 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1271 IPA_CMD_ASS_START);
1272 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001273 dev_err(&card->gdev->dev,
1274 "Activating IPv6 support for %s failed\n",
1275 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001276 return rc;
1277 }
1278 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1279 IPA_CMD_ASS_START);
1280 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001281 dev_warn(&card->gdev->dev,
1282 "Enabling the passthrough mode for %s failed\n",
1283 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001284 return rc;
1285 }
1286out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001287 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001288 return 0;
1289}
1290#endif
1291
1292static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1293{
1294 int rc = 0;
1295
Carsten Otte847a50f2010-06-21 22:57:05 +00001296 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001297
1298 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001299 dev_info(&card->gdev->dev,
1300 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001301 return 0;
1302 }
1303#ifdef CONFIG_QETH_IPV6
1304 rc = qeth_l3_softsetup_ipv6(card);
1305#endif
1306 return rc ;
1307}
1308
1309static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1310{
1311 int rc;
1312
Carsten Otte847a50f2010-06-21 22:57:05 +00001313 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001314 card->info.broadcast_capable = 0;
1315 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001316 dev_info(&card->gdev->dev,
1317 "Broadcast not supported on %s\n",
1318 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319 rc = -EOPNOTSUPP;
1320 goto out;
1321 }
1322 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1323 IPA_CMD_ASS_START, 0);
1324 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001325 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1326 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001327 goto out;
1328 }
1329
1330 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1331 IPA_CMD_ASS_CONFIGURE, 1);
1332 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001333 dev_warn(&card->gdev->dev,
1334 "Setting up broadcast filtering for %s failed\n",
1335 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001336 goto out;
1337 }
1338 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001339 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001340 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1341 IPA_CMD_ASS_ENABLE, 1);
1342 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001343 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1344 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001345 goto out;
1346 }
1347 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1348out:
1349 if (card->info.broadcast_capable)
1350 card->dev->flags |= IFF_BROADCAST;
1351 else
1352 card->dev->flags &= ~IFF_BROADCAST;
1353 return rc;
1354}
1355
1356static int qeth_l3_send_checksum_command(struct qeth_card *card)
1357{
1358 int rc;
1359
1360 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1361 IPA_CMD_ASS_START, 0);
1362 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001363 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1364 "failed, using SW checksumming\n",
1365 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001366 return rc;
1367 }
1368 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1369 IPA_CMD_ASS_ENABLE,
1370 card->info.csum_mask);
1371 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001372 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1373 "failed, using SW checksumming\n",
1374 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001375 return rc;
1376 }
1377 return 0;
1378}
1379
Martin Schwidefskyc4736d92011-10-30 15:17:11 +01001380static int qeth_l3_set_rx_csum(struct qeth_card *card, int on)
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001381{
1382 int rc = 0;
1383
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001384 if (on) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001385 rc = qeth_l3_send_checksum_command(card);
1386 if (rc)
1387 return -EIO;
1388 dev_info(&card->gdev->dev,
1389 "HW Checksumming (inbound) enabled\n");
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001390 } else {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001391 rc = qeth_l3_send_simple_setassparms(card,
1392 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1393 if (rc)
1394 return -EIO;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001395 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001396
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001397 return 0;
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001398}
1399
Frank Blaschka4a71df52008-02-15 09:19:42 +01001400static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1401{
Carsten Otte847a50f2010-06-21 22:57:05 +00001402 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001403
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001404 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka60a34277d52011-05-18 03:28:35 +00001405 rtnl_lock();
1406 /* force set_features call */
1407 card->dev->features &= ~NETIF_F_RXCSUM;
1408 netdev_update_features(card->dev);
1409 rtnl_unlock();
1410 }
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001411 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001412}
1413
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001414static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1415{
1416 int rc = 0;
1417
1418 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1419 return rc;
1420 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1421 IPA_CMD_ASS_START, 0);
1422 if (rc)
1423 goto err_out;
1424 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1425 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1426 if (rc)
1427 goto err_out;
1428 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1429 return rc;
1430err_out:
1431 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1432 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1433 return rc;
1434}
1435
Frank Blaschka4a71df52008-02-15 09:19:42 +01001436static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1437{
1438 int rc;
1439
Carsten Otte847a50f2010-06-21 22:57:05 +00001440 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001441
1442 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001443 dev_info(&card->gdev->dev,
1444 "Outbound TSO not supported on %s\n",
1445 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001446 rc = -EOPNOTSUPP;
1447 } else {
1448 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1449 IPA_CMD_ASS_START, 0);
1450 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001451 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1452 "segmentation offload for %s failed\n",
1453 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001454 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001455 dev_info(&card->gdev->dev,
1456 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001457 }
Michał Mirosław6204b472011-04-19 00:43:20 +00001458 if (rc)
1459 card->dev->features &= ~NETIF_F_TSO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001460 return rc;
1461}
1462
1463static int qeth_l3_start_ipassists(struct qeth_card *card)
1464{
Carsten Otte847a50f2010-06-21 22:57:05 +00001465 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001466
Stefan Raspl0f547612013-01-21 02:30:20 +00001467 if (qeth_set_access_ctrl_online(card, 0))
1468 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001469 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1470 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1471 qeth_l3_start_ipa_source_mac(card); /* go on*/
1472 qeth_l3_start_ipa_vlan(card); /* go on*/
1473 qeth_l3_start_ipa_multicast(card); /* go on*/
1474 qeth_l3_start_ipa_ipv6(card); /* go on*/
1475 qeth_l3_start_ipa_broadcast(card); /* go on*/
1476 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001477 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001478 qeth_l3_start_ipa_tso(card); /* go on*/
1479 return 0;
1480}
1481
Frank Blaschka4a71df52008-02-15 09:19:42 +01001482static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1483 struct qeth_reply *reply, unsigned long data)
1484{
1485 struct qeth_ipa_cmd *cmd;
1486
1487 cmd = (struct qeth_ipa_cmd *) data;
1488 if (cmd->hdr.return_code == 0)
1489 memcpy(card->dev->dev_addr,
1490 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1491 else
Joe Perches18336112012-07-12 22:33:10 -07001492 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001493
1494 return 0;
1495}
1496
1497static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1498{
1499 int rc = 0;
1500 struct qeth_cmd_buffer *iob;
1501 struct qeth_ipa_cmd *cmd;
1502
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001503 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001504
1505 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1506 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001507 if (!iob)
1508 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001509 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1510 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1511 card->info.unique_id;
1512
1513 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1514 NULL);
1515 return rc;
1516}
1517
1518static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1519 struct qeth_reply *reply, unsigned long data)
1520{
1521 struct qeth_ipa_cmd *cmd;
1522
1523 cmd = (struct qeth_ipa_cmd *) data;
1524 if (cmd->hdr.return_code == 0)
1525 card->info.unique_id = *((__u16 *)
1526 &cmd->data.create_destroy_addr.unique_id[6]);
1527 else {
1528 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1529 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001530 dev_warn(&card->gdev->dev, "The network adapter failed to "
1531 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001532 }
1533 return 0;
1534}
1535
1536static int qeth_l3_get_unique_id(struct qeth_card *card)
1537{
1538 int rc = 0;
1539 struct qeth_cmd_buffer *iob;
1540 struct qeth_ipa_cmd *cmd;
1541
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001542 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001543
1544 if (!qeth_is_supported(card, IPA_IPV6)) {
1545 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1546 UNIQUE_ID_NOT_BY_CARD;
1547 return 0;
1548 }
1549
1550 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1551 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001552 if (!iob)
1553 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001554 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1555 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1556 card->info.unique_id;
1557
1558 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1559 return rc;
1560}
1561
Ursula Braun76b11f82010-01-11 02:50:50 +00001562static int
1563qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1564 unsigned long data)
1565{
1566 struct qeth_ipa_cmd *cmd;
1567 __u16 rc;
1568
1569 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1570
1571 cmd = (struct qeth_ipa_cmd *)data;
1572 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001573 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001574 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001575 switch (cmd->data.diagass.action) {
1576 case QETH_DIAGS_CMD_TRACE_QUERY:
1577 break;
1578 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001579 switch (rc) {
1580 case 0:
1581 case IPA_RC_INVALID_SUBCMD:
1582 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1583 dev_info(&card->gdev->dev, "The HiperSockets network "
1584 "traffic analyzer is deactivated\n");
1585 break;
1586 default:
1587 break;
1588 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001589 break;
1590 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001591 switch (rc) {
1592 case 0:
1593 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1594 dev_info(&card->gdev->dev, "The HiperSockets network "
1595 "traffic analyzer is activated\n");
1596 break;
1597 case IPA_RC_HARDWARE_AUTH_ERROR:
1598 dev_warn(&card->gdev->dev, "The device is not "
1599 "authorized to run as a HiperSockets network "
1600 "traffic analyzer\n");
1601 break;
1602 case IPA_RC_TRACE_ALREADY_ACTIVE:
1603 dev_warn(&card->gdev->dev, "A HiperSockets "
1604 "network traffic analyzer is already "
1605 "active in the HiperSockets LAN\n");
1606 break;
1607 default:
1608 break;
1609 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001610 break;
1611 default:
1612 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1613 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1614 }
1615
1616 return 0;
1617}
1618
1619static int
1620qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1621{
1622 struct qeth_cmd_buffer *iob;
1623 struct qeth_ipa_cmd *cmd;
1624
1625 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1626
1627 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001628 if (!iob)
1629 return -ENOMEM;
Ursula Braun76b11f82010-01-11 02:50:50 +00001630 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1631 cmd->data.diagass.subcmd_len = 16;
1632 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1633 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1634 cmd->data.diagass.action = diags_cmd;
1635 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1636}
1637
Frank Blaschka4a71df52008-02-15 09:19:42 +01001638static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1639 struct net_device *dev)
1640{
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001641 ip_eth_mc_map(ipm, mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001642}
1643
1644static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1645{
1646 struct qeth_ipaddr *ipm;
1647 struct ip_mc_list *im4;
1648 char buf[MAX_ADDR_LEN];
1649
Carsten Otte847a50f2010-06-21 22:57:05 +00001650 QETH_CARD_TEXT(card, 4, "addmc");
Sachin Santf3aa3132010-11-26 02:41:17 +00001651 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1652 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001653 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1654 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1655 if (!ipm)
1656 continue;
1657 ipm->u.a4.addr = im4->multiaddr;
1658 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1659 ipm->is_multicast = 1;
1660 if (!qeth_l3_add_ip(card, ipm))
1661 kfree(ipm);
1662 }
1663}
1664
Jiri Pirko0347af52013-01-03 22:48:58 +00001665/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001666static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1667{
1668 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001669 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001670
Carsten Otte847a50f2010-06-21 22:57:05 +00001671 QETH_CARD_TEXT(card, 4, "addmcvl");
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001672 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001673 return;
1674
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001675 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1676 struct net_device *netdev;
1677
dingtianhongf06c7f92014-05-09 14:58:05 +08001678 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001679 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001680 if (netdev == NULL ||
1681 !(netdev->flags & IFF_UP))
1682 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001683 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001684 if (!in_dev)
1685 continue;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001686 qeth_l3_add_mc(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001687 }
1688}
1689
1690static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1691{
1692 struct in_device *in4_dev;
1693
Carsten Otte847a50f2010-06-21 22:57:05 +00001694 QETH_CARD_TEXT(card, 4, "chkmcv4");
Sachin Santf3aa3132010-11-26 02:41:17 +00001695 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001696 in4_dev = __in_dev_get_rcu(card->dev);
1697 if (in4_dev == NULL)
1698 goto unlock;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001699 qeth_l3_add_mc(card, in4_dev);
1700 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001701unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001702 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001703}
1704
1705#ifdef CONFIG_QETH_IPV6
1706static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1707{
1708 struct qeth_ipaddr *ipm;
1709 struct ifmcaddr6 *im6;
1710 char buf[MAX_ADDR_LEN];
1711
Carsten Otte847a50f2010-06-21 22:57:05 +00001712 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001713 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1714 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1715 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1716 if (!ipm)
1717 continue;
1718 ipm->is_multicast = 1;
1719 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1720 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1721 sizeof(struct in6_addr));
1722 if (!qeth_l3_add_ip(card, ipm))
1723 kfree(ipm);
1724 }
1725}
1726
Jiri Pirko0347af52013-01-03 22:48:58 +00001727/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001728static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1729{
1730 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001731 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001732
Carsten Otte847a50f2010-06-21 22:57:05 +00001733 QETH_CARD_TEXT(card, 4, "admc6vl");
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001734 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001735 return;
1736
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001737 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1738 struct net_device *netdev;
1739
dingtianhongf06c7f92014-05-09 14:58:05 +08001740 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001741 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001742 if (netdev == NULL ||
1743 !(netdev->flags & IFF_UP))
1744 continue;
1745 in_dev = in6_dev_get(netdev);
1746 if (!in_dev)
1747 continue;
1748 read_lock_bh(&in_dev->lock);
1749 qeth_l3_add_mc6(card, in_dev);
1750 read_unlock_bh(&in_dev->lock);
1751 in6_dev_put(in_dev);
1752 }
1753}
1754
1755static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1756{
1757 struct inet6_dev *in6_dev;
1758
Carsten Otte847a50f2010-06-21 22:57:05 +00001759 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001760 if (!qeth_is_supported(card, IPA_IPV6))
1761 return ;
1762 in6_dev = in6_dev_get(card->dev);
1763 if (in6_dev == NULL)
1764 return;
Jiri Pirko0347af52013-01-03 22:48:58 +00001765 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001766 read_lock_bh(&in6_dev->lock);
1767 qeth_l3_add_mc6(card, in6_dev);
1768 qeth_l3_add_vlan_mc6(card);
1769 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001770 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001771 in6_dev_put(in6_dev);
1772}
1773#endif /* CONFIG_QETH_IPV6 */
1774
1775static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1776 unsigned short vid)
1777{
1778 struct in_device *in_dev;
1779 struct in_ifaddr *ifa;
1780 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001781 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001782
Carsten Otte847a50f2010-06-21 22:57:05 +00001783 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001784
dingtianhongf06c7f92014-05-09 14:58:05 +08001785 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001786 if (!netdev)
1787 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001788 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001789 if (!in_dev)
1790 return;
1791 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1792 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1793 if (addr) {
1794 addr->u.a4.addr = ifa->ifa_address;
1795 addr->u.a4.mask = ifa->ifa_mask;
1796 addr->type = QETH_IP_TYPE_NORMAL;
1797 if (!qeth_l3_delete_ip(card, addr))
1798 kfree(addr);
1799 }
1800 }
1801 in_dev_put(in_dev);
1802}
1803
1804static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1805 unsigned short vid)
1806{
1807#ifdef CONFIG_QETH_IPV6
1808 struct inet6_dev *in6_dev;
1809 struct inet6_ifaddr *ifa;
1810 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001811 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001812
Carsten Otte847a50f2010-06-21 22:57:05 +00001813 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001814
dingtianhongf06c7f92014-05-09 14:58:05 +08001815 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001816 if (!netdev)
1817 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001818 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001819 if (!in6_dev)
1820 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001821 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001822 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1823 if (addr) {
1824 memcpy(&addr->u.a6.addr, &ifa->addr,
1825 sizeof(struct in6_addr));
1826 addr->u.a6.pfxlen = ifa->prefix_len;
1827 addr->type = QETH_IP_TYPE_NORMAL;
1828 if (!qeth_l3_delete_ip(card, addr))
1829 kfree(addr);
1830 }
1831 }
1832 in6_dev_put(in6_dev);
1833#endif /* CONFIG_QETH_IPV6 */
1834}
1835
1836static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1837 unsigned short vid)
1838{
Jiri Pirko0347af52013-01-03 22:48:58 +00001839 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001840 qeth_l3_free_vlan_addresses4(card, vid);
1841 qeth_l3_free_vlan_addresses6(card, vid);
Jiri Pirko0347af52013-01-03 22:48:58 +00001842 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001843}
1844
Patrick McHardy80d5c362013-04-19 02:04:28 +00001845static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1846 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001847{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001848 struct qeth_card *card = dev->ml_priv;
1849
1850 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001851 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001852}
1853
Patrick McHardy80d5c362013-04-19 02:04:28 +00001854static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1855 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001856{
Heiko Carstens509e2562008-07-26 02:24:10 -07001857 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001858 unsigned long flags;
1859
Carsten Otte847a50f2010-06-21 22:57:05 +00001860 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00001861 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001862 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001863 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001864 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001865 spin_lock_irqsave(&card->vlanlock, flags);
1866 /* unregister IP addresses of vlan device */
1867 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001868 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001869 spin_unlock_irqrestore(&card->vlanlock, flags);
1870 qeth_l3_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001871 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001872}
1873
Ursula Braun10651db2010-10-01 02:51:13 +00001874static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1875 struct sk_buff *skb, struct qeth_hdr *hdr,
1876 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001877{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001878 __be16 prot;
1879 struct iphdr *ip_hdr;
1880 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001881 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001882
1883 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1884 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1885 ETH_P_IP);
1886 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1887 case QETH_CAST_MULTICAST:
1888 switch (prot) {
1889#ifdef CONFIG_QETH_IPV6
1890 case __constant_htons(ETH_P_IPV6):
1891 ndisc_mc_map((struct in6_addr *)
1892 skb->data + 24,
1893 tg_addr, card->dev, 0);
1894 break;
1895#endif
1896 case __constant_htons(ETH_P_IP):
1897 ip_hdr = (struct iphdr *)skb->data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001898 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1899 break;
1900 default:
1901 memcpy(tg_addr, card->dev->broadcast,
1902 card->dev->addr_len);
1903 }
1904 card->stats.multicast++;
1905 skb->pkt_type = PACKET_MULTICAST;
1906 break;
1907 case QETH_CAST_BROADCAST:
1908 memcpy(tg_addr, card->dev->broadcast,
1909 card->dev->addr_len);
1910 card->stats.multicast++;
1911 skb->pkt_type = PACKET_BROADCAST;
1912 break;
1913 case QETH_CAST_UNICAST:
1914 case QETH_CAST_ANYCAST:
1915 case QETH_CAST_NOCAST:
1916 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001917 if (card->options.sniffer)
1918 skb->pkt_type = PACKET_OTHERHOST;
1919 else
1920 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001921 memcpy(tg_addr, card->dev->dev_addr,
1922 card->dev->addr_len);
1923 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001924 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1925 card->dev->header_ops->create(skb, card->dev, prot,
1926 tg_addr, &hdr->hdr.l3.dest_addr[2],
1927 card->dev->addr_len);
1928 else
1929 card->dev->header_ops->create(skb, card->dev, prot,
1930 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001931 }
1932
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001933 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001934
1935 if (hdr->hdr.l3.ext_flags &
1936 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001937 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001938 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001939 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001940 }
1941
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001942 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001943 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001944 (QETH_HDR_EXT_CSUM_HDR_REQ |
1945 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1946 (QETH_HDR_EXT_CSUM_HDR_REQ |
1947 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001948 skb->ip_summed = CHECKSUM_UNNECESSARY;
1949 else
Ursula Braunb9139802009-05-19 21:38:40 +00001950 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001951 } else
1952 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001953
Ursula Braun10651db2010-10-01 02:51:13 +00001954 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001955}
1956
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001957static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1958 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001959{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001960 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001961 struct sk_buff *skb;
1962 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001963 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001964 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001965 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001966 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001967
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001968 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001969 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001970 while (budget) {
1971 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001972 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001973 &card->rx.b_element, &card->rx.e_offset, &hdr);
1974 if (!skb) {
1975 *done = 1;
1976 break;
1977 }
1978 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001979 switch (hdr->hdr.l3.id) {
1980 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001981 magic = *(__u16 *)skb->data;
1982 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1983 (magic == ETH_P_AF_IUCV)) {
1984 skb->protocol = ETH_P_AF_IUCV;
1985 skb->pkt_type = PACKET_HOST;
1986 skb->mac_header = NET_SKB_PAD;
1987 skb->dev = card->dev;
1988 len = skb->len;
1989 card->dev->header_ops->create(skb, card->dev, 0,
1990 card->dev->dev_addr, "FAKELL",
1991 card->dev->addr_len);
1992 netif_receive_skb(skb);
1993 } else {
1994 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
Ursula Braun10651db2010-10-01 02:51:13 +00001995 &vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001996 len = skb->len;
1997 if (is_vlan && !card->options.sniffer)
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001998 __vlan_hwaccel_put_tag(skb,
1999 htons(ETH_P_8021Q), vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00002000 napi_gro_receive(&card->napi, skb);
2001 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002002 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002003 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2004 skb->pkt_type = PACKET_HOST;
2005 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002006 len = skb->len;
2007 netif_receive_skb(skb);
2008 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002009 default:
2010 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002011 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002012 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002013 continue;
2014 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002015 work_done++;
2016 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002017 card->stats.rx_packets++;
2018 card->stats.rx_bytes += len;
2019 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002020 return work_done;
2021}
2022
2023static int qeth_l3_poll(struct napi_struct *napi, int budget)
2024{
2025 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2026 int work_done = 0;
2027 struct qeth_qdio_buffer *buffer;
2028 int done;
2029 int new_budget = budget;
2030
2031 if (card->options.performance_stats) {
2032 card->perf_stats.inbound_cnt++;
2033 card->perf_stats.inbound_start_time = qeth_get_micros();
2034 }
2035
2036 while (1) {
2037 if (!card->rx.b_count) {
2038 card->rx.qdio_err = 0;
2039 card->rx.b_count = qdio_get_next_buffers(
2040 card->data.ccwdev, 0, &card->rx.b_index,
2041 &card->rx.qdio_err);
2042 if (card->rx.b_count <= 0) {
2043 card->rx.b_count = 0;
2044 break;
2045 }
2046 card->rx.b_element =
2047 &card->qdio.in_q->bufs[card->rx.b_index]
2048 .buffer->element[0];
2049 card->rx.e_offset = 0;
2050 }
2051
2052 while (card->rx.b_count) {
2053 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2054 if (!(card->rx.qdio_err &&
2055 qeth_check_qdio_errors(card, buffer->buffer,
2056 card->rx.qdio_err, "qinerr")))
2057 work_done += qeth_l3_process_inbound_buffer(
2058 card, new_budget, &done);
2059 else
2060 done = 1;
2061
2062 if (done) {
2063 if (card->options.performance_stats)
2064 card->perf_stats.bufs_rec++;
2065 qeth_put_buffer_pool_entry(card,
2066 buffer->pool_entry);
2067 qeth_queue_input_buffer(card, card->rx.b_index);
2068 card->rx.b_count--;
2069 if (card->rx.b_count) {
2070 card->rx.b_index =
2071 (card->rx.b_index + 1) %
2072 QDIO_MAX_BUFFERS_PER_Q;
2073 card->rx.b_element =
2074 &card->qdio.in_q
2075 ->bufs[card->rx.b_index]
2076 .buffer->element[0];
2077 card->rx.e_offset = 0;
2078 }
2079 }
2080
2081 if (work_done >= budget)
2082 goto out;
2083 else
2084 new_budget = budget - work_done;
2085 }
2086 }
2087
2088 napi_complete(napi);
2089 if (qdio_start_irq(card->data.ccwdev, 0))
2090 napi_schedule(&card->napi);
2091out:
2092 if (card->options.performance_stats)
2093 card->perf_stats.inbound_time += qeth_get_micros() -
2094 card->perf_stats.inbound_start_time;
2095 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002096}
2097
2098static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2099 struct qeth_card *card)
2100{
2101 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002102 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002103
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002104 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
2105 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002106
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002107 rcu_read_lock();
dingtianhongf06c7f92014-05-09 14:58:05 +08002108 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00002109 vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002110 rcu_read_unlock();
2111 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002112 rc = QETH_VLAN_CARD;
2113 break;
2114 }
2115 }
2116
Heiko Carstens509e2562008-07-26 02:24:10 -07002117 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002118 return 0;
2119
2120 return rc;
2121}
2122
2123static int qeth_l3_verify_dev(struct net_device *dev)
2124{
2125 struct qeth_card *card;
2126 unsigned long flags;
2127 int rc = 0;
2128
2129 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2130 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2131 if (card->dev == dev) {
2132 rc = QETH_REAL_CARD;
2133 break;
2134 }
2135 rc = qeth_l3_verify_vlan_dev(dev, card);
2136 if (rc)
2137 break;
2138 }
2139 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2140
2141 return rc;
2142}
2143
2144static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2145{
2146 struct qeth_card *card = NULL;
2147 int rc;
2148
2149 rc = qeth_l3_verify_dev(dev);
2150 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002151 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002152 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002153 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002154 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002155 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002156 if (card)
2157 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002158 return card ;
2159}
2160
2161static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2162{
2163 int rc = 0;
2164
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002165 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2166 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002167
2168 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002169 if (card->options.sniffer &&
2170 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2171 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002172 if (card->read.state == CH_STATE_UP &&
2173 card->write.state == CH_STATE_UP &&
2174 (card->state == CARD_STATE_UP)) {
2175 if (recovery_mode)
2176 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002177 else {
Ursula Braun869da902010-03-08 20:36:56 +00002178 rtnl_lock();
2179 dev_close(card->dev);
2180 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002181 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002182 card->state = CARD_STATE_SOFTSETUP;
2183 }
2184 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -08002185 qeth_l3_clear_ip_list(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002186 qeth_clear_ipacmd_list(card);
2187 card->state = CARD_STATE_HARDSETUP;
2188 }
2189 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002190 qeth_qdio_clear_card(card, 0);
2191 qeth_clear_qdio_buffers(card);
2192 qeth_clear_working_pool_list(card);
2193 card->state = CARD_STATE_DOWN;
2194 }
2195 if (card->state == CARD_STATE_DOWN) {
2196 qeth_clear_cmd_buffers(&card->read);
2197 qeth_clear_cmd_buffers(&card->write);
2198 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002199 return rc;
2200}
2201
Ursula Braun76b11f82010-01-11 02:50:50 +00002202/*
2203 * test for and Switch promiscuous mode (on or off)
2204 * either for guestlan or HiperSocket Sniffer
2205 */
2206static void
2207qeth_l3_handle_promisc_mode(struct qeth_card *card)
2208{
2209 struct net_device *dev = card->dev;
2210
2211 if (((dev->flags & IFF_PROMISC) &&
2212 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2213 (!(dev->flags & IFF_PROMISC) &&
2214 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2215 return;
2216
2217 if (card->info.guestlan) { /* Guestlan trace */
2218 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2219 qeth_setadp_promisc_mode(card);
2220 } else if (card->options.sniffer && /* HiperSockets trace */
2221 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2222 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002223 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002224 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2225 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002226 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002227 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2228 }
2229 }
2230}
2231
Frank Blaschka4a71df52008-02-15 09:19:42 +01002232static void qeth_l3_set_multicast_list(struct net_device *dev)
2233{
Heiko Carstens509e2562008-07-26 02:24:10 -07002234 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002235
Carsten Otte847a50f2010-06-21 22:57:05 +00002236 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002237 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2238 (card->state != CARD_STATE_UP))
2239 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002240 if (!card->options.sniffer) {
2241 qeth_l3_delete_mc_addresses(card);
2242 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002243#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002244 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002245#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002246 qeth_l3_set_ip_addr_list(card);
2247 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2248 return;
2249 }
2250 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002251}
2252
2253static const char *qeth_l3_arp_get_error_cause(int *rc)
2254{
2255 switch (*rc) {
2256 case QETH_IPA_ARP_RC_FAILED:
2257 *rc = -EIO;
2258 return "operation failed";
2259 case QETH_IPA_ARP_RC_NOTSUPP:
2260 *rc = -EOPNOTSUPP;
2261 return "operation not supported";
2262 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2263 *rc = -EINVAL;
2264 return "argument out of range";
2265 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2266 *rc = -EOPNOTSUPP;
2267 return "query operation not supported";
2268 case QETH_IPA_ARP_RC_Q_NO_DATA:
2269 *rc = -ENOENT;
2270 return "no query data available";
2271 default:
2272 return "unknown error";
2273 }
2274}
2275
2276static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2277{
2278 int tmp;
2279 int rc;
2280
Carsten Otte847a50f2010-06-21 22:57:05 +00002281 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002282
2283 /*
2284 * currently GuestLAN only supports the ARP assist function
2285 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2286 * thus we say EOPNOTSUPP for this ARP function
2287 */
2288 if (card->info.guestlan)
2289 return -EOPNOTSUPP;
2290 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002291 return -EOPNOTSUPP;
2292 }
2293 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2294 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2295 no_entries);
2296 if (rc) {
2297 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002298 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2299 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002300 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2301 }
2302 return rc;
2303}
2304
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002305static __u32 get_arp_entry_size(struct qeth_card *card,
2306 struct qeth_arp_query_data *qdata,
2307 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002308{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002309 __u32 rc;
2310 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002311
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002312 is_hsi = qdata->reply_bits == 5;
2313 if (type->ip == QETHARP_IP_ADDR_V4) {
2314 QETH_CARD_TEXT(card, 4, "arpev4");
2315 if (strip_entries) {
2316 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2317 sizeof(struct qeth_arp_qi_entry7_short);
2318 } else {
2319 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2320 sizeof(struct qeth_arp_qi_entry7);
2321 }
2322 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2323 QETH_CARD_TEXT(card, 4, "arpev6");
2324 if (strip_entries) {
2325 rc = is_hsi ?
2326 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2327 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2328 } else {
2329 rc = is_hsi ?
2330 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2331 sizeof(struct qeth_arp_qi_entry7_ipv6);
2332 }
2333 } else {
2334 QETH_CARD_TEXT(card, 4, "arpinv");
2335 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002336 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002337
2338 return rc;
2339}
2340
2341static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2342{
2343 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2344 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002345}
2346
2347static int qeth_l3_arp_query_cb(struct qeth_card *card,
2348 struct qeth_reply *reply, unsigned long data)
2349{
2350 struct qeth_ipa_cmd *cmd;
2351 struct qeth_arp_query_data *qdata;
2352 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002353 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002354 int e;
2355 int entrybytes_done;
2356 int stripped_bytes;
2357 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002358
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002359 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002360
2361 qinfo = (struct qeth_arp_query_info *) reply->param;
2362 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002363 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002364 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002365 QETH_CARD_TEXT(card, 4, "arpcberr");
2366 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002367 return 0;
2368 }
2369 if (cmd->data.setassparms.hdr.return_code) {
2370 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002371 QETH_CARD_TEXT(card, 4, "setaperr");
2372 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002373 return 0;
2374 }
2375 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002376 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002377
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002378 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2379 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2380 entrybytes_done = 0;
2381 for (e = 0; e < qdata->no_entries; ++e) {
2382 char *cur_entry;
2383 __u32 esize;
2384 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002385
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002386 cur_entry = &qdata->data + entrybytes_done;
2387 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2388 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2389 QETH_CARD_TEXT(card, 4, "pmis");
2390 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2391 break;
2392 }
2393 esize = get_arp_entry_size(card, qdata, etype,
2394 do_strip_entries);
2395 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2396 if (!esize)
2397 break;
2398
2399 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2400 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00002401 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002402 goto out_error;
2403 }
2404
2405 memcpy(qinfo->udata + qinfo->udata_offset,
2406 &qdata->data + entrybytes_done + stripped_bytes,
2407 esize);
2408 entrybytes_done += esize + stripped_bytes;
2409 qinfo->udata_offset += esize;
2410 ++qinfo->no_entries;
2411 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002412 /* check if all replies received ... */
2413 if (cmd->data.setassparms.hdr.seq_no <
2414 cmd->data.setassparms.hdr.number_of_replies)
2415 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002416 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002417 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2418 /* keep STRIP_ENTRIES flag so the user program can distinguish
2419 * stripped entries from normal ones */
2420 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2421 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2422 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002423 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002424 return 0;
2425out_error:
2426 i = 0;
2427 memcpy(qinfo->udata, &i, 4);
2428 return 0;
2429}
2430
2431static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2432 struct qeth_cmd_buffer *iob, int len,
2433 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2434 unsigned long),
2435 void *reply_param)
2436{
Carsten Otte847a50f2010-06-21 22:57:05 +00002437 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002438
2439 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2440 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2441 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2442 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2443 reply_cb, reply_param);
2444}
2445
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002446static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2447 enum qeth_prot_versions prot,
2448 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002449{
2450 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002451 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002452 int tmp;
2453 int rc;
2454
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002455 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2456
2457 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2458 IPA_CMD_ASS_ARP_QUERY_INFO,
2459 sizeof(struct qeth_arp_query_data) - sizeof(char),
2460 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002461 if (!iob)
2462 return -ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002463 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2464 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2465 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2466 cmd->data.setassparms.data.query_arp.no_entries = 0;
2467 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2468 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2469 qeth_l3_arp_query_cb, (void *)qinfo);
2470 if (rc) {
2471 tmp = rc;
2472 QETH_DBF_MESSAGE(2,
2473 "Error while querying ARP cache on %s: %s "
2474 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2475 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2476 }
2477
2478 return rc;
2479}
2480
2481static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2482{
2483 struct qeth_arp_query_info qinfo = {0, };
2484 int rc;
2485
Carsten Otte847a50f2010-06-21 22:57:05 +00002486 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002487
2488 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2489 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002490 QETH_CARD_TEXT(card, 3, "arpqnsup");
2491 rc = -EOPNOTSUPP;
2492 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002493 }
2494 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002495 if (copy_from_user(&qinfo, udata, 6)) {
2496 rc = -EFAULT;
2497 goto out;
2498 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002499 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002500 if (!qinfo.udata) {
2501 rc = -ENOMEM;
2502 goto out;
2503 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002504 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002505 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002506 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002507 if (copy_to_user(udata, qinfo.udata, 4))
2508 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002509 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002510 } else {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002511#ifdef CONFIG_QETH_IPV6
2512 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2513 /* fails in case of GuestLAN QDIO mode */
2514 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2515 &qinfo);
2516 }
2517#endif
2518 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2519 QETH_CARD_TEXT(card, 4, "qactf");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002520 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002521 goto free_and_out;
2522 }
Thomas Richter8a593142014-10-22 12:18:03 +02002523 QETH_CARD_TEXT(card, 4, "qacts");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002524 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002525free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002526 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002527out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002528 return rc;
2529}
2530
2531static int qeth_l3_arp_add_entry(struct qeth_card *card,
2532 struct qeth_arp_cache_entry *entry)
2533{
2534 struct qeth_cmd_buffer *iob;
2535 char buf[16];
2536 int tmp;
2537 int rc;
2538
Carsten Otte847a50f2010-06-21 22:57:05 +00002539 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002540
2541 /*
2542 * currently GuestLAN only supports the ARP assist function
2543 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2544 * thus we say EOPNOTSUPP for this ARP function
2545 */
2546 if (card->info.guestlan)
2547 return -EOPNOTSUPP;
2548 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002549 return -EOPNOTSUPP;
2550 }
2551
2552 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2553 IPA_CMD_ASS_ARP_ADD_ENTRY,
2554 sizeof(struct qeth_arp_cache_entry),
2555 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002556 if (!iob)
2557 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002558 rc = qeth_l3_send_setassparms(card, iob,
2559 sizeof(struct qeth_arp_cache_entry),
2560 (unsigned long) entry,
2561 qeth_l3_default_setassparms_cb, NULL);
2562 if (rc) {
2563 tmp = rc;
2564 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002565 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2566 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2567 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002568 }
2569 return rc;
2570}
2571
2572static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2573 struct qeth_arp_cache_entry *entry)
2574{
2575 struct qeth_cmd_buffer *iob;
2576 char buf[16] = {0, };
2577 int tmp;
2578 int rc;
2579
Carsten Otte847a50f2010-06-21 22:57:05 +00002580 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002581
2582 /*
2583 * currently GuestLAN only supports the ARP assist function
2584 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2585 * thus we say EOPNOTSUPP for this ARP function
2586 */
2587 if (card->info.guestlan)
2588 return -EOPNOTSUPP;
2589 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002590 return -EOPNOTSUPP;
2591 }
2592 memcpy(buf, entry, 12);
2593 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2594 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2595 12,
2596 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002597 if (!iob)
2598 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002599 rc = qeth_l3_send_setassparms(card, iob,
2600 12, (unsigned long)buf,
2601 qeth_l3_default_setassparms_cb, NULL);
2602 if (rc) {
2603 tmp = rc;
2604 memset(buf, 0, 16);
2605 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002606 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2607 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2608 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002609 }
2610 return rc;
2611}
2612
2613static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2614{
2615 int rc;
2616 int tmp;
2617
Carsten Otte847a50f2010-06-21 22:57:05 +00002618 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002619
2620 /*
2621 * currently GuestLAN only supports the ARP assist function
2622 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2623 * thus we say EOPNOTSUPP for this ARP function
2624 */
2625 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2626 return -EOPNOTSUPP;
2627 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002628 return -EOPNOTSUPP;
2629 }
2630 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2631 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2632 if (rc) {
2633 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002634 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2635 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002636 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2637 }
2638 return rc;
2639}
2640
2641static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2642{
Heiko Carstens509e2562008-07-26 02:24:10 -07002643 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002644 struct qeth_arp_cache_entry arp_entry;
2645 struct mii_ioctl_data *mii_data;
2646 int rc = 0;
2647
2648 if (!card)
2649 return -ENODEV;
2650
Eugene Crosserc3521252015-01-16 14:05:47 +01002651 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002652 return -ENODEV;
2653
2654 switch (cmd) {
2655 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2656 if (!capable(CAP_NET_ADMIN)) {
2657 rc = -EPERM;
2658 break;
2659 }
2660 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2661 break;
2662 case SIOC_QETH_ARP_QUERY_INFO:
2663 if (!capable(CAP_NET_ADMIN)) {
2664 rc = -EPERM;
2665 break;
2666 }
2667 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2668 break;
2669 case SIOC_QETH_ARP_ADD_ENTRY:
2670 if (!capable(CAP_NET_ADMIN)) {
2671 rc = -EPERM;
2672 break;
2673 }
2674 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2675 sizeof(struct qeth_arp_cache_entry)))
2676 rc = -EFAULT;
2677 else
2678 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2679 break;
2680 case SIOC_QETH_ARP_REMOVE_ENTRY:
2681 if (!capable(CAP_NET_ADMIN)) {
2682 rc = -EPERM;
2683 break;
2684 }
2685 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2686 sizeof(struct qeth_arp_cache_entry)))
2687 rc = -EFAULT;
2688 else
2689 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2690 break;
2691 case SIOC_QETH_ARP_FLUSH_CACHE:
2692 if (!capable(CAP_NET_ADMIN)) {
2693 rc = -EPERM;
2694 break;
2695 }
2696 rc = qeth_l3_arp_flush_cache(card);
2697 break;
2698 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2699 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2700 break;
2701 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002702 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2703 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002704 !card->info.guestlan)
2705 return 1;
2706 return 0;
2707 break;
2708 case SIOCGMIIPHY:
2709 mii_data = if_mii(rq);
2710 mii_data->phy_id = 0;
2711 break;
2712 case SIOCGMIIREG:
2713 mii_data = if_mii(rq);
2714 if (mii_data->phy_id != 0)
2715 rc = -EINVAL;
2716 else
2717 mii_data->val_out = qeth_mdio_read(dev,
2718 mii_data->phy_id,
2719 mii_data->reg_num);
2720 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +00002721 case SIOC_QETH_QUERY_OAT:
2722 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
2723 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002724 default:
2725 rc = -EOPNOTSUPP;
2726 }
2727 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002728 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002729 return rc;
2730}
2731
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002732int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2733{
2734 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002735 struct neighbour *n = NULL;
2736 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002737
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002738 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002739 dst = skb_dst(skb);
2740 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002741 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002742 if (n) {
2743 cast_type = n->type;
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002744 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002745 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002746 if ((cast_type == RTN_BROADCAST) ||
2747 (cast_type == RTN_MULTICAST) ||
2748 (cast_type == RTN_ANYCAST))
2749 return cast_type;
2750 else
2751 return RTN_UNSPEC;
2752 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002753 rcu_read_unlock();
2754
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002755 /* try something else */
2756 if (skb->protocol == ETH_P_IPV6)
2757 return (skb_network_header(skb)[24] == 0xff) ?
2758 RTN_MULTICAST : 0;
2759 else if (skb->protocol == ETH_P_IP)
2760 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2761 RTN_MULTICAST : 0;
2762 /* ... */
2763 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2764 return RTN_BROADCAST;
2765 else {
2766 u16 hdr_mac;
2767
2768 hdr_mac = *((u16 *)skb->data);
2769 /* tr multicast? */
2770 switch (card->info.link_type) {
2771 case QETH_LINK_TYPE_HSTR:
2772 case QETH_LINK_TYPE_LANE_TR:
2773 if ((hdr_mac == QETH_TR_MAC_NC) ||
2774 (hdr_mac == QETH_TR_MAC_C))
2775 return RTN_MULTICAST;
2776 break;
2777 /* eth or so multicast? */
2778 default:
2779 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2780 (hdr_mac == QETH_ETH_MAC_V6))
2781 return RTN_MULTICAST;
2782 }
2783 }
2784 return cast_type;
2785}
2786
Frank Blaschkab3332932011-08-08 01:33:59 +00002787static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2788 struct qeth_hdr *hdr, struct sk_buff *skb)
2789{
2790 char daddr[16];
2791 struct af_iucv_trans_hdr *iucv_hdr;
2792
2793 skb_pull(skb, 14);
2794 card->dev->header_ops->create(skb, card->dev, 0,
2795 card->dev->dev_addr, card->dev->dev_addr,
2796 card->dev->addr_len);
2797 skb_pull(skb, 14);
2798 iucv_hdr = (struct af_iucv_trans_hdr *)skb->data;
2799 memset(hdr, 0, sizeof(struct qeth_hdr));
2800 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2801 hdr->hdr.l3.ext_flags = 0;
2802 hdr->hdr.l3.length = skb->len;
2803 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
2804 memset(daddr, 0, sizeof(daddr));
2805 daddr[0] = 0xfe;
2806 daddr[1] = 0x80;
2807 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2808 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2809}
2810
Frank Blaschka4a71df52008-02-15 09:19:42 +01002811static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2812 struct sk_buff *skb, int ipv, int cast_type)
2813{
David S. Miller69cce1d2011-07-17 23:09:49 -07002814 struct dst_entry *dst;
2815
Frank Blaschka4a71df52008-02-15 09:19:42 +01002816 memset(hdr, 0, sizeof(struct qeth_hdr));
2817 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2818 hdr->hdr.l3.ext_flags = 0;
2819
2820 /*
2821 * before we're going to overwrite this location with next hop ip.
2822 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2823 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002824 if (skb_vlan_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002825 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2826 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2827 else
2828 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002829 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002830 }
2831
2832 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002833
2834 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002835 dst = skb_dst(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002836 if (ipv == 4) {
David Miller87e75972012-02-01 10:49:17 +00002837 struct rtable *rt = (struct rtable *) dst;
2838 __be32 *pkey = &ip_hdr(skb)->daddr;
2839
2840 if (rt->rt_gateway)
2841 pkey = &rt->rt_gateway;
2842
Frank Blaschka4a71df52008-02-15 09:19:42 +01002843 /* IPv4 */
2844 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2845 memset(hdr->hdr.l3.dest_addr, 0, 12);
David Miller87e75972012-02-01 10:49:17 +00002846 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002847 } else if (ipv == 6) {
David Miller87e75972012-02-01 10:49:17 +00002848 struct rt6_info *rt = (struct rt6_info *) dst;
2849 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2850
2851 if (!ipv6_addr_any(&rt->rt6i_gateway))
2852 pkey = &rt->rt6i_gateway;
2853
Frank Blaschka4a71df52008-02-15 09:19:42 +01002854 /* IPv6 */
2855 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2856 if (card->info.type == QETH_CARD_TYPE_IQD)
2857 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David Miller87e75972012-02-01 10:49:17 +00002858 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002859 } else {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002860 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002861 skb->dev->broadcast, 6)) {
2862 /* broadcast? */
2863 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2864 QETH_HDR_PASSTHRU;
2865 } else {
2866 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2867 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2868 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2869 }
2870 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002871 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002872}
2873
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002874static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2875 struct qeth_hdr *hdr, struct sk_buff *skb)
2876{
2877 struct iphdr *iph = ip_hdr(skb);
2878
2879 /* tcph->check contains already the pseudo hdr checksum
2880 * so just set the header flags
2881 */
2882 if (iph->protocol == IPPROTO_UDP)
2883 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002884 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2885 QETH_HDR_EXT_CSUM_HDR_REQ;
2886 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002887 if (card->options.performance_stats)
2888 card->perf_stats.tx_csum++;
2889}
2890
Frank Blaschka64ef8952009-03-24 20:57:16 +00002891static void qeth_tso_fill_header(struct qeth_card *card,
2892 struct qeth_hdr *qhdr, struct sk_buff *skb)
2893{
2894 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2895 struct tcphdr *tcph = tcp_hdr(skb);
2896 struct iphdr *iph = ip_hdr(skb);
2897 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2898
2899 /*fix header to TSO values ...*/
2900 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002901 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002902 /*set values which are fix for the first approach ...*/
2903 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2904 hdr->ext.imb_hdr_no = 1;
2905 hdr->ext.hdr_type = 1;
2906 hdr->ext.hdr_version = 1;
2907 hdr->ext.hdr_len = 28;
2908 /*insert non-fix values */
2909 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2910 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2911 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2912 sizeof(struct qeth_hdr_tso));
2913 tcph->check = 0;
2914 if (skb->protocol == ETH_P_IPV6) {
2915 ip6h->payload_len = 0;
2916 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2917 0, IPPROTO_TCP, 0);
2918 } else {
2919 /*OSA want us to set these values ...*/
2920 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2921 0, IPPROTO_TCP, 0);
2922 iph->tot_len = 0;
2923 iph->check = 0;
2924 }
2925}
2926
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002927static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2928{
2929 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2930 tcp_hdr(skb)->doff * 4;
2931 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002932 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschka271648b2013-03-18 20:04:44 +00002933
2934 elements += qeth_get_elements_for_frags(skb);
2935
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002936 return elements;
2937}
2938
Frank Blaschka4a71df52008-02-15 09:19:42 +01002939static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2940{
2941 int rc;
2942 u16 *tag;
2943 struct qeth_hdr *hdr = NULL;
2944 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002945 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002946 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002947 struct sk_buff *new_skb = NULL;
2948 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002949 int cast_type = qeth_l3_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002950 struct qeth_qdio_out_q *queue =
2951 card->qdio.out_qs[card->qdio.do_prio_queueing
2952 || (cast_type && card->info.is_multicast_different) ?
2953 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2954 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002955 int tx_bytes = skb->len;
Michał Mirosław6204b472011-04-19 00:43:20 +00002956 bool large_send;
Frank Blaschka683d7182008-08-01 16:39:13 +02002957 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002958 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002959
Frank Blaschkab3332932011-08-08 01:33:59 +00002960 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2961 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2962 ((card->options.cq == QETH_CQ_ENABLED) &&
2963 (skb->protocol != ETH_P_AF_IUCV)))) ||
2964 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002965 goto tx_drop;
2966
2967 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2968 card->stats.tx_carrier_errors++;
2969 goto tx_drop;
2970 }
2971
2972 if ((cast_type == RTN_BROADCAST) &&
2973 (card->info.broadcast_capable == 0))
2974 goto tx_drop;
2975
2976 if (card->options.performance_stats) {
2977 card->perf_stats.outbound_cnt++;
2978 card->perf_stats.outbound_start_time = qeth_get_micros();
2979 }
2980
Michał Mirosław6204b472011-04-19 00:43:20 +00002981 large_send = skb_is_gso(skb);
Frank Blaschka683d7182008-08-01 16:39:13 +02002982
2983 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2984 (skb_shinfo(skb)->nr_frags == 0)) {
2985 new_skb = skb;
Frank Blaschkab3332932011-08-08 01:33:59 +00002986 if (new_skb->protocol == ETH_P_AF_IUCV)
2987 data_offset = 0;
2988 else
2989 data_offset = ETH_HLEN;
Frank Blaschka683d7182008-08-01 16:39:13 +02002990 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2991 if (!hdr)
2992 goto tx_drop;
2993 elements_needed++;
2994 } else {
2995 /* create a clone with writeable headroom */
2996 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2997 + VLAN_HLEN);
2998 if (!new_skb)
2999 goto tx_drop;
3000 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003001
3002 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02003003 if (data_offset < 0)
3004 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003005 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00003006 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04003007 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003008 }
3009
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01003010 if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003011 skb_push(new_skb, VLAN_HLEN);
3012 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
3013 skb_copy_to_linear_data_offset(new_skb, 4,
3014 new_skb->data + 8, 4);
3015 skb_copy_to_linear_data_offset(new_skb, 8,
3016 new_skb->data + 12, 4);
3017 tag = (u16 *)(new_skb->data + 12);
3018 *tag = __constant_htons(ETH_P_8021Q);
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01003019 *(tag + 1) = htons(skb_vlan_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003020 }
3021 }
3022
3023 netif_stop_queue(dev);
3024
Frank Blaschka4a71df52008-02-15 09:19:42 +01003025 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003026 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003027 */
Michał Mirosław6204b472011-04-19 00:43:20 +00003028 if (large_send) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003029 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3030 if (skb_linearize(new_skb))
3031 goto tx_drop;
3032 if (card->options.performance_stats)
3033 card->perf_stats.tx_lin++;
3034 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003035 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003036
Michał Mirosław6204b472011-04-19 00:43:20 +00003037 if (large_send && (cast_type == RTN_UNSPEC)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003038 hdr = (struct qeth_hdr *)skb_push(new_skb,
3039 sizeof(struct qeth_hdr_tso));
3040 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3041 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3042 qeth_tso_fill_header(card, hdr, new_skb);
3043 elements_needed++;
3044 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003045 if (data_offset < 0) {
3046 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003047 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003048 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3049 cast_type);
3050 } else {
Frank Blaschkab3332932011-08-08 01:33:59 +00003051 if (new_skb->protocol == ETH_P_AF_IUCV)
3052 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
3053 else {
3054 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3055 cast_type);
3056 hdr->hdr.l3.length = new_skb->len - data_offset;
3057 }
Frank Blaschka683d7182008-08-01 16:39:13 +02003058 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003059
3060 if (skb->ip_summed == CHECKSUM_PARTIAL)
3061 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003062 }
3063
Stefan Raspl065cc782013-04-22 01:12:28 +00003064 elems = qeth_get_elements_no(card, new_skb, elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003065 if (!elems) {
3066 if (data_offset >= 0)
3067 kmem_cache_free(qeth_core_header_cache, hdr);
3068 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003069 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003070 elements_needed += elems;
3071 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003072
Frank Blaschka51aa1652010-06-21 22:57:10 +00003073 if (card->info.type != QETH_CARD_TYPE_IQD) {
3074 int len;
Michał Mirosław6204b472011-04-19 00:43:20 +00003075 if (large_send)
Frank Blaschka51aa1652010-06-21 22:57:10 +00003076 len = ((unsigned long)tcp_hdr(new_skb) +
3077 tcp_hdr(new_skb)->doff * 4) -
3078 (unsigned long)new_skb->data;
3079 else
3080 len = sizeof(struct qeth_hdr_layer3);
3081
Stefan Raspld4ae1f52013-04-22 01:12:29 +00003082 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00003083 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003084 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003085 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003086 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003087 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003088 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003089
3090 if (!rc) {
3091 card->stats.tx_packets++;
3092 card->stats.tx_bytes += tx_bytes;
3093 if (new_skb != skb)
3094 dev_kfree_skb_any(skb);
3095 if (card->options.performance_stats) {
Michał Mirosław6204b472011-04-19 00:43:20 +00003096 if (large_send) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003097 card->perf_stats.large_send_bytes += tx_bytes;
3098 card->perf_stats.large_send_cnt++;
3099 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003100 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003101 card->perf_stats.sg_skbs_sent++;
3102 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003103 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003104 }
3105 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003106 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003107 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003108 if (data_offset >= 0)
3109 kmem_cache_free(qeth_core_header_cache, hdr);
3110
Frank Blaschka4a71df52008-02-15 09:19:42 +01003111 if (rc == -EBUSY) {
3112 if (new_skb != skb)
3113 dev_kfree_skb_any(new_skb);
3114 return NETDEV_TX_BUSY;
3115 } else
3116 goto tx_drop;
3117 }
3118
3119 netif_wake_queue(dev);
3120 if (card->options.performance_stats)
3121 card->perf_stats.outbound_time += qeth_get_micros() -
3122 card->perf_stats.outbound_start_time;
3123 return rc;
3124
3125tx_drop:
3126 card->stats.tx_dropped++;
3127 card->stats.tx_errors++;
3128 if ((new_skb != skb) && new_skb)
3129 dev_kfree_skb_any(new_skb);
3130 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003131 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003132 return NETDEV_TX_OK;
3133}
3134
Ursula Braun39423442011-01-12 20:42:24 +00003135static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003136{
Heiko Carstens509e2562008-07-26 02:24:10 -07003137 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003138 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003139
Carsten Otte847a50f2010-06-21 22:57:05 +00003140 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00003141 if (card->state == CARD_STATE_UP)
3142 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003143 if (card->state != CARD_STATE_SOFTSETUP)
3144 return -ENODEV;
3145 card->data.state = CH_STATE_UP;
3146 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003147 netif_start_queue(dev);
3148
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003149 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3150 napi_enable(&card->napi);
3151 napi_schedule(&card->napi);
3152 } else
3153 rc = -EIO;
3154 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003155}
3156
Ursula Braun39423442011-01-12 20:42:24 +00003157static int qeth_l3_open(struct net_device *dev)
3158{
3159 struct qeth_card *card = dev->ml_priv;
3160
3161 QETH_CARD_TEXT(card, 5, "qethope_");
3162 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3163 QETH_CARD_TEXT(card, 3, "openREC");
3164 return -ERESTARTSYS;
3165 }
3166 return __qeth_l3_open(dev);
3167}
3168
Frank Blaschka4a71df52008-02-15 09:19:42 +01003169static int qeth_l3_stop(struct net_device *dev)
3170{
Heiko Carstens509e2562008-07-26 02:24:10 -07003171 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003172
Carsten Otte847a50f2010-06-21 22:57:05 +00003173 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003174 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003175 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003176 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003177 napi_disable(&card->napi);
3178 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003179 return 0;
3180}
3181
Michał Mirosławc8f44af2011-11-15 15:29:55 +00003182static netdev_features_t qeth_l3_fix_features(struct net_device *dev,
3183 netdev_features_t features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003184{
Heiko Carstens509e2562008-07-26 02:24:10 -07003185 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003186
Michał Mirosław6204b472011-04-19 00:43:20 +00003187 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3188 features &= ~NETIF_F_IP_CSUM;
3189 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
3190 features &= ~NETIF_F_TSO;
3191 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
3192 features &= ~NETIF_F_RXCSUM;
3193
3194 return features;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003195}
3196
Michał Mirosławc8f44af2011-11-15 15:29:55 +00003197static int qeth_l3_set_features(struct net_device *dev,
3198 netdev_features_t features)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003199{
Michał Mirosław6204b472011-04-19 00:43:20 +00003200 struct qeth_card *card = dev->ml_priv;
Thomas Richterc7258d82015-05-18 14:27:52 +02003201 netdev_features_t changed = dev->features ^ features;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003202
Michał Mirosław6204b472011-04-19 00:43:20 +00003203 if (!(changed & NETIF_F_RXCSUM))
3204 return 0;
3205
Frank Blaschka60a34277d52011-05-18 03:28:35 +00003206 if (card->state == CARD_STATE_DOWN ||
3207 card->state == CARD_STATE_RECOVER)
3208 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003209
Thomas Richterc7258d82015-05-18 14:27:52 +02003210 return qeth_l3_set_rx_csum(card, features & NETIF_F_RXCSUM ? 1 : 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003211}
3212
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003213static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003214 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003215 .get_strings = qeth_core_get_strings,
3216 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003217 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003218 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003219 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003220};
3221
3222/*
3223 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3224 * NOARP on the netdevice is no option because it also turns off neighbor
3225 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3226 * arp resolution but we want the hard header (packet socket will work
3227 * e.g. tcpdump)
3228 */
3229static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3230{
3231 n->nud_state = NUD_NOARP;
3232 memcpy(n->ha, "FAKELL", 6);
3233 n->output = n->ops->connected_output;
3234 return 0;
3235}
3236
3237static int
3238qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3239{
3240 if (np->tbl->family == AF_INET)
3241 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3242
3243 return 0;
3244}
3245
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003246static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003247 .ndo_open = qeth_l3_open,
3248 .ndo_stop = qeth_l3_stop,
3249 .ndo_get_stats = qeth_get_stats,
3250 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3251 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003252 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003253 .ndo_do_ioctl = qeth_l3_do_ioctl,
3254 .ndo_change_mtu = qeth_change_mtu,
3255 .ndo_fix_features = qeth_l3_fix_features,
3256 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003257 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3258 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003259 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08003260};
3261
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003262static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3263 .ndo_open = qeth_l3_open,
3264 .ndo_stop = qeth_l3_stop,
3265 .ndo_get_stats = qeth_get_stats,
3266 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3267 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003268 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003269 .ndo_do_ioctl = qeth_l3_do_ioctl,
3270 .ndo_change_mtu = qeth_change_mtu,
3271 .ndo_fix_features = qeth_l3_fix_features,
3272 .ndo_set_features = qeth_l3_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003273 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3274 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003275 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003276 .ndo_neigh_setup = qeth_l3_neigh_setup,
3277};
3278
Frank Blaschka4a71df52008-02-15 09:19:42 +01003279static int qeth_l3_setup_netdev(struct qeth_card *card)
3280{
Thomas Richter1aec42b2015-01-21 13:39:10 +01003281 int rc;
3282
Ursula Braun5113fec2010-05-16 21:15:14 +00003283 if (card->info.type == QETH_CARD_TYPE_OSD ||
3284 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003285 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3286 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04003287 pr_info("qeth_l3: ignoring TR device\n");
3288 return -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003289 } else {
3290 card->dev = alloc_etherdev(0);
3291 if (!card->dev)
3292 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003293 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003294
3295 /*IPv6 address autoconfiguration stuff*/
3296 qeth_l3_get_unique_id(card);
3297 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3298 card->dev->dev_id = card->info.unique_id &
3299 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003300 if (!card->info.guestlan) {
3301 card->dev->hw_features = NETIF_F_SG |
3302 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3303 NETIF_F_TSO;
3304 card->dev->features = NETIF_F_RXCSUM;
3305 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003306 }
3307 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02003308 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
3309 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003310 if (!card->dev)
3311 return -ENODEV;
3312 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003313 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01003314 rc = qeth_l3_iqd_read_initial_mac(card);
3315 if (rc)
3316 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00003317 if (card->options.hsuid[0])
3318 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003319 } else
3320 return -ENODEV;
3321
Heiko Carstens509e2562008-07-26 02:24:10 -07003322 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003323 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003324 card->dev->mtu = card->info.initial_mtu;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003325 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00003326 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
3327 NETIF_F_HW_VLAN_CTAG_RX |
3328 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07003329 netif_keep_dst(card->dev);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003330 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003331
3332 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003333 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003334 return register_netdev(card->dev);
3335}
3336
Frank Blaschka4a71df52008-02-15 09:19:42 +01003337static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3338{
3339 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3340
3341 qeth_l3_create_device_attributes(&gdev->dev);
3342 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003343 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003344 return 0;
3345}
3346
3347static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3348{
3349 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3350
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003351 qeth_l3_remove_device_attributes(&cgdev->dev);
3352
Ursula Braunf2148562009-05-19 21:38:37 +00003353 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003354 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3355
Ursula Braun70919e22011-02-26 22:41:36 -08003356 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003357 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003358
3359 if (card->dev) {
3360 unregister_netdev(card->dev);
3361 card->dev = NULL;
3362 }
3363
Ursula Braun70919e22011-02-26 22:41:36 -08003364 qeth_l3_clear_ip_list(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003365 qeth_l3_clear_ipato_list(card);
3366 return;
3367}
3368
3369static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3370{
3371 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3372 int rc = 0;
3373 enum qeth_card_states recover_flag;
3374
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003375 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003376 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003377 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3378 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003379
Frank Blaschka4a71df52008-02-15 09:19:42 +01003380 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003381 rc = qeth_core_hardsetup_card(card);
3382 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01003383 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003384 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003385 goto out_remove;
3386 }
3387
Ursula Braunaa909222009-11-12 00:11:43 +00003388 if (!card->dev && qeth_l3_setup_netdev(card)) {
3389 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003390 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003391 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003392
Frank Blaschka1da74b12011-05-12 18:45:02 +00003393 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3394 if (card->info.hwtrap &&
3395 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3396 card->info.hwtrap = 0;
3397 } else
3398 card->info.hwtrap = 0;
3399
Frank Blaschka4a71df52008-02-15 09:19:42 +01003400 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003401 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003402 qeth_print_status_message(card);
3403
3404 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003405 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003406
3407 rc = qeth_send_startlan(card);
3408 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003409 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003410 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003411 dev_warn(&card->gdev->dev,
3412 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003413 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003414 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003415 }
Ursula Braunaa909222009-11-12 00:11:43 +00003416 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003417 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003418 } else
3419 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003420
Ursula Braun2b6203b2010-11-26 02:41:19 +00003421contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003422 rc = qeth_l3_setadapter_parms(card);
3423 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003424 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003425 if (!card->options.sniffer) {
3426 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00003427 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00003428 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00003429 goto out_remove;
3430 }
Ursula Braun76b11f82010-01-11 02:50:50 +00003431 rc = qeth_l3_setrouting_v4(card);
3432 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003433 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003434 rc = qeth_l3_setrouting_v6(card);
3435 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003436 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003437 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003438 netif_tx_disable(card->dev);
3439
3440 rc = qeth_init_qdio_queues(card);
3441 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003442 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003443 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003444 goto out_remove;
3445 }
3446 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003447
3448 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003449 qeth_l3_set_ip_addr_list(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003450 if (card->lan_online)
3451 netif_carrier_on(card->dev);
3452 else
3453 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003454 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00003455 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003456 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003457 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003458 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003459 dev_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003460 qeth_l3_set_multicast_list(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003461 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003462 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00003463 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003464 /* let user_space know that device is online */
3465 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003466 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003467 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003468 return 0;
3469out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003470 qeth_l3_stop_card(card, 0);
3471 ccw_device_set_offline(CARD_DDEV(card));
3472 ccw_device_set_offline(CARD_WDEV(card));
3473 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01003474 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003475 if (recover_flag == CARD_STATE_RECOVER)
3476 card->state = CARD_STATE_RECOVER;
3477 else
3478 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003479 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003480 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003481 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003482}
3483
3484static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3485{
3486 return __qeth_l3_set_online(gdev, 0);
3487}
3488
3489static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3490 int recovery_mode)
3491{
3492 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3493 int rc = 0, rc2 = 0, rc3 = 0;
3494 enum qeth_card_states recover_flag;
3495
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003496 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003497 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003498 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3499 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003500
3501 if (card->dev && netif_carrier_ok(card->dev))
3502 netif_carrier_off(card->dev);
3503 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003504 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3505 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3506 card->info.hwtrap = 1;
3507 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003508 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00003509 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3510 rtnl_lock();
3511 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3512 rtnl_unlock();
3513 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003514 rc = ccw_device_set_offline(CARD_DDEV(card));
3515 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3516 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3517 if (!rc)
3518 rc = (rc2) ? rc2 : rc3;
3519 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003520 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01003521 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003522 if (recover_flag == CARD_STATE_UP)
3523 card->state = CARD_STATE_RECOVER;
3524 /* let user_space know that device is offline */
3525 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003526 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003527 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003528 return 0;
3529}
3530
3531static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3532{
3533 return __qeth_l3_set_offline(cgdev, 0);
3534}
3535
3536static int qeth_l3_recover(void *ptr)
3537{
3538 struct qeth_card *card;
3539 int rc = 0;
3540
3541 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003542 QETH_CARD_TEXT(card, 2, "recover1");
3543 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003544 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3545 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003546 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003547 dev_warn(&card->gdev->dev,
3548 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00003549 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003550 __qeth_l3_set_offline(card->gdev, 1);
3551 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003552 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003553 dev_info(&card->gdev->dev,
3554 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003555 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00003556 qeth_close_dev(card);
3557 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00003558 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003559 }
Stefan Raspl65d80132013-04-07 22:19:27 +00003560 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003561 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3562 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003563 return 0;
3564}
3565
3566static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3567{
3568 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00003569 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00003570 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3571 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003572 qeth_qdio_clear_card(card, 0);
3573 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01003574 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003575}
3576
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003577static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3578{
3579 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3580
3581 if (card->dev)
3582 netif_device_detach(card->dev);
3583 qeth_set_allowed_threads(card, 0, 1);
3584 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3585 if (gdev->state == CCWGROUP_OFFLINE)
3586 return 0;
3587 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003588 if (card->info.hwtrap)
3589 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003590 __qeth_l3_set_offline(card->gdev, 1);
3591 } else
3592 __qeth_l3_set_offline(card->gdev, 0);
3593 return 0;
3594}
3595
3596static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3597{
3598 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3599 int rc = 0;
3600
3601 if (gdev->state == CCWGROUP_OFFLINE)
3602 goto out;
3603
3604 if (card->state == CARD_STATE_RECOVER) {
3605 rc = __qeth_l3_set_online(card->gdev, 1);
3606 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003607 rtnl_lock();
3608 dev_close(card->dev);
3609 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003610 }
3611 } else
3612 rc = __qeth_l3_set_online(card->gdev, 0);
3613out:
3614 qeth_set_allowed_threads(card, 0xffffffff, 0);
3615 if (card->dev)
3616 netif_device_attach(card->dev);
3617 if (rc)
3618 dev_warn(&card->gdev->dev, "The qeth device driver "
3619 "failed to recover an error on the device\n");
3620 return rc;
3621}
3622
Eugene Crosserc044dc22014-01-29 09:23:48 +01003623/* Returns zero if the command is successfully "consumed" */
3624static int qeth_l3_control_event(struct qeth_card *card,
3625 struct qeth_ipa_cmd *cmd)
3626{
3627 return 1;
3628}
3629
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003630struct qeth_discipline qeth_l3_discipline = {
3631 .start_poll = qeth_qdio_start_poll,
3632 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3633 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
3634 .recover = qeth_l3_recover,
3635 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003636 .remove = qeth_l3_remove_device,
3637 .set_online = qeth_l3_set_online,
3638 .set_offline = qeth_l3_set_offline,
3639 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003640 .freeze = qeth_l3_pm_suspend,
3641 .thaw = qeth_l3_pm_resume,
3642 .restore = qeth_l3_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01003643 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003644};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003645EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003646
3647static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003648 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003649{
3650 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3651 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3652 struct qeth_ipaddr *addr;
3653 struct qeth_card *card;
3654
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003655 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003656 return NOTIFY_DONE;
3657
Frank Blaschka4a71df52008-02-15 09:19:42 +01003658 card = qeth_l3_get_card_from_dev(dev);
3659 if (!card)
3660 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00003661 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003662
3663 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3664 if (addr != NULL) {
3665 addr->u.a4.addr = ifa->ifa_address;
3666 addr->u.a4.mask = ifa->ifa_mask;
3667 addr->type = QETH_IP_TYPE_NORMAL;
3668 } else
3669 goto out;
3670
3671 switch (event) {
3672 case NETDEV_UP:
3673 if (!qeth_l3_add_ip(card, addr))
3674 kfree(addr);
3675 break;
3676 case NETDEV_DOWN:
3677 if (!qeth_l3_delete_ip(card, addr))
3678 kfree(addr);
3679 break;
3680 default:
3681 break;
3682 }
3683 qeth_l3_set_ip_addr_list(card);
3684out:
3685 return NOTIFY_DONE;
3686}
3687
3688static struct notifier_block qeth_l3_ip_notifier = {
3689 qeth_l3_ip_event,
3690 NULL,
3691};
3692
3693#ifdef CONFIG_QETH_IPV6
3694/**
3695 * IPv6 event handler
3696 */
3697static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003698 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003699{
3700 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3701 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3702 struct qeth_ipaddr *addr;
3703 struct qeth_card *card;
3704
Frank Blaschka4a71df52008-02-15 09:19:42 +01003705 card = qeth_l3_get_card_from_dev(dev);
3706 if (!card)
3707 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003708 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003709 if (!qeth_is_supported(card, IPA_IPV6))
3710 return NOTIFY_DONE;
3711
3712 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3713 if (addr != NULL) {
3714 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3715 addr->u.a6.pfxlen = ifa->prefix_len;
3716 addr->type = QETH_IP_TYPE_NORMAL;
3717 } else
3718 goto out;
3719
3720 switch (event) {
3721 case NETDEV_UP:
3722 if (!qeth_l3_add_ip(card, addr))
3723 kfree(addr);
3724 break;
3725 case NETDEV_DOWN:
3726 if (!qeth_l3_delete_ip(card, addr))
3727 kfree(addr);
3728 break;
3729 default:
3730 break;
3731 }
3732 qeth_l3_set_ip_addr_list(card);
3733out:
3734 return NOTIFY_DONE;
3735}
3736
3737static struct notifier_block qeth_l3_ip6_notifier = {
3738 qeth_l3_ip6_event,
3739 NULL,
3740};
3741#endif
3742
3743static int qeth_l3_register_notifiers(void)
3744{
3745 int rc;
3746
Carsten Otte847a50f2010-06-21 22:57:05 +00003747 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003748 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3749 if (rc)
3750 return rc;
3751#ifdef CONFIG_QETH_IPV6
3752 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3753 if (rc) {
3754 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3755 return rc;
3756 }
3757#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003758 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003759#endif
3760 return 0;
3761}
3762
3763static void qeth_l3_unregister_notifiers(void)
3764{
3765
Carsten Otte847a50f2010-06-21 22:57:05 +00003766 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00003767 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003768#ifdef CONFIG_QETH_IPV6
Stefan Raspl18af5c12012-11-19 02:46:50 +00003769 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003770#endif /* QETH_IPV6 */
3771}
3772
3773static int __init qeth_l3_init(void)
3774{
3775 int rc = 0;
3776
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003777 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003778 rc = qeth_l3_register_notifiers();
3779 return rc;
3780}
3781
3782static void __exit qeth_l3_exit(void)
3783{
3784 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003785 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003786}
3787
3788module_init(qeth_l3_init);
3789module_exit(qeth_l3_exit);
3790MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3791MODULE_DESCRIPTION("qeth layer 3 discipline");
3792MODULE_LICENSE("GPL");