blob: d5e40c3e4bc37be5bc273083b942bacdf555f8f4 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
2 * drivers/s390/net/qeth_l3_main.c
3 *
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02004 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01005 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
10
Frank Blaschka74eacdb2008-12-25 13:39:49 +010011#define KMSG_COMPONENT "qeth"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Frank Blaschka4a71df52008-02-15 09:19:42 +010014#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/etherdevice.h>
20#include <linux/mii.h>
21#include <linux/ip.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000022#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010023#include <linux/inetdevice.h>
24#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
27#include <net/ip.h>
28#include <net/arp.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000029#include <net/ip6_checksum.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010030
Frank Blaschka4a71df52008-02-15 09:19:42 +010031#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010032
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000033
Frank Blaschka4a71df52008-02-15 09:19:42 +010034static int qeth_l3_set_offline(struct ccwgroup_device *);
35static int qeth_l3_recover(void *);
36static int qeth_l3_stop(struct net_device *);
37static void qeth_l3_set_multicast_list(struct net_device *);
38static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
39static int qeth_l3_register_addr_entry(struct qeth_card *,
40 struct qeth_ipaddr *);
41static int qeth_l3_deregister_addr_entry(struct qeth_card *,
42 struct qeth_ipaddr *);
43static int __qeth_l3_set_online(struct ccwgroup_device *, int);
44static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
45
Frank Blaschkac3b4a742009-11-12 00:11:44 +000046int qeth_l3_set_large_send(struct qeth_card *card,
47 enum qeth_large_send_types type)
48{
49 int rc = 0;
50
51 card->options.large_send = type;
52 if (card->dev == NULL)
53 return 0;
54
55 if (card->options.large_send == QETH_LARGE_SEND_TSO) {
56 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
57 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
Frank Blaschkaf6b85b62010-05-11 19:34:45 +000058 NETIF_F_IP_CSUM;
Frank Blaschkac3b4a742009-11-12 00:11:44 +000059 } else {
60 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
Frank Blaschkaf6b85b62010-05-11 19:34:45 +000061 NETIF_F_IP_CSUM);
Frank Blaschkac3b4a742009-11-12 00:11:44 +000062 card->options.large_send = QETH_LARGE_SEND_NO;
63 rc = -EOPNOTSUPP;
64 }
65 } else {
66 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
Frank Blaschkaf6b85b62010-05-11 19:34:45 +000067 NETIF_F_IP_CSUM);
Frank Blaschkac3b4a742009-11-12 00:11:44 +000068 card->options.large_send = QETH_LARGE_SEND_NO;
69 }
70 return rc;
71}
Frank Blaschka4a71df52008-02-15 09:19:42 +010072
73static int qeth_l3_isxdigit(char *buf)
74{
75 while (*buf) {
76 if (!isxdigit(*buf++))
77 return 0;
78 }
79 return 1;
80}
81
82void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
83{
84 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
85}
86
87int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
88{
89 int count = 0, rc = 0;
90 int in[4];
91 char c;
92
93 rc = sscanf(buf, "%u.%u.%u.%u%c",
94 &in[0], &in[1], &in[2], &in[3], &c);
95 if (rc != 4 && (rc != 5 || c != '\n'))
96 return -EINVAL;
97 for (count = 0; count < 4; count++) {
98 if (in[count] > 255)
99 return -EINVAL;
100 addr[count] = in[count];
101 }
102 return 0;
103}
104
105void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
106{
Joe Perches963a9fd2010-09-07 21:14:40 +0000107 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100108}
109
110int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
111{
112 const char *end, *end_tmp, *start;
113 __u16 *in;
114 char num[5];
115 int num2, cnt, out, found, save_cnt;
116 unsigned short in_tmp[8] = {0, };
117
118 cnt = out = found = save_cnt = num2 = 0;
119 end = start = buf;
120 in = (__u16 *) addr;
121 memset(in, 0, 16);
122 while (*end) {
123 end = strchr(start, ':');
124 if (end == NULL) {
125 end = buf + strlen(buf);
126 end_tmp = strchr(start, '\n');
127 if (end_tmp != NULL)
128 end = end_tmp;
129 out = 1;
130 }
131 if ((end - start)) {
132 memset(num, 0, 5);
133 if ((end - start) > 4)
134 return -EINVAL;
135 memcpy(num, start, end - start);
136 if (!qeth_l3_isxdigit(num))
137 return -EINVAL;
138 sscanf(start, "%x", &num2);
139 if (found)
140 in_tmp[save_cnt++] = num2;
141 else
142 in[cnt++] = num2;
143 if (out)
144 break;
145 } else {
146 if (found)
147 return -EINVAL;
148 found = 1;
149 }
150 start = ++end;
151 }
152 if (cnt + save_cnt > 8)
153 return -EINVAL;
154 cnt = 7;
155 while (save_cnt)
156 in[cnt--] = in_tmp[--save_cnt];
157 return 0;
158}
159
160void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
161 char *buf)
162{
163 if (proto == QETH_PROT_IPV4)
164 qeth_l3_ipaddr4_to_string(addr, buf);
165 else if (proto == QETH_PROT_IPV6)
166 qeth_l3_ipaddr6_to_string(addr, buf);
167}
168
169int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
170 __u8 *addr)
171{
172 if (proto == QETH_PROT_IPV4)
173 return qeth_l3_string_to_ipaddr4(buf, addr);
174 else if (proto == QETH_PROT_IPV6)
175 return qeth_l3_string_to_ipaddr6(buf, addr);
176 else
177 return -EINVAL;
178}
179
180static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
181{
182 int i, j;
183 u8 octet;
184
185 for (i = 0; i < len; ++i) {
186 octet = addr[i];
187 for (j = 7; j >= 0; --j) {
188 bits[i*8 + j] = octet & 1;
189 octet >>= 1;
190 }
191 }
192}
193
Klaus-Dieter Wacker62982632010-07-22 23:15:03 +0000194int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100195 struct qeth_ipaddr *addr)
196{
197 struct qeth_ipato_entry *ipatoe;
198 u8 addr_bits[128] = {0, };
199 u8 ipatoe_bits[128] = {0, };
200 int rc = 0;
201
202 if (!card->ipato.enabled)
203 return 0;
204
205 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
206 (addr->proto == QETH_PROT_IPV4)? 4:16);
207 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
208 if (addr->proto != ipatoe->proto)
209 continue;
210 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
211 (ipatoe->proto == QETH_PROT_IPV4) ?
212 4 : 16);
213 if (addr->proto == QETH_PROT_IPV4)
214 rc = !memcmp(addr_bits, ipatoe_bits,
215 min(32, ipatoe->mask_bits));
216 else
217 rc = !memcmp(addr_bits, ipatoe_bits,
218 min(128, ipatoe->mask_bits));
219 if (rc)
220 break;
221 }
222 /* invert? */
223 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
224 rc = !rc;
225 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
226 rc = !rc;
227
228 return rc;
229}
230
231/*
232 * Add IP to be added to todo list. If there is already an "add todo"
233 * in this list we just incremenent the reference count.
234 * Returns 0 if we just incremented reference count.
235 */
236static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
237 struct qeth_ipaddr *addr, int add)
238{
239 struct qeth_ipaddr *tmp, *t;
240 int found = 0;
241
Ursula Braun76b11f82010-01-11 02:50:50 +0000242 if (card->options.sniffer)
243 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100244 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
245 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
246 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
247 return 0;
248 if ((tmp->proto == QETH_PROT_IPV4) &&
249 (addr->proto == QETH_PROT_IPV4) &&
250 (tmp->type == addr->type) &&
251 (tmp->is_multicast == addr->is_multicast) &&
252 (tmp->u.a4.addr == addr->u.a4.addr) &&
253 (tmp->u.a4.mask == addr->u.a4.mask)) {
254 found = 1;
255 break;
256 }
257 if ((tmp->proto == QETH_PROT_IPV6) &&
258 (addr->proto == QETH_PROT_IPV6) &&
259 (tmp->type == addr->type) &&
260 (tmp->is_multicast == addr->is_multicast) &&
261 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
262 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
263 sizeof(struct in6_addr)) == 0)) {
264 found = 1;
265 break;
266 }
267 }
268 if (found) {
269 if (addr->users != 0)
270 tmp->users += addr->users;
271 else
272 tmp->users += add ? 1 : -1;
273 if (tmp->users == 0) {
274 list_del(&tmp->entry);
275 kfree(tmp);
276 }
277 return 0;
278 } else {
279 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
280 list_add(&addr->entry, card->ip_tbd_list);
281 else {
282 if (addr->users == 0)
283 addr->users += add ? 1 : -1;
284 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
285 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000286 QETH_CARD_TEXT(card, 2, "tkovaddr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100287 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
288 }
289 list_add_tail(&addr->entry, card->ip_tbd_list);
290 }
291 return 1;
292 }
293}
294
295static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
296{
297 unsigned long flags;
298 int rc = 0;
299
Carsten Otte847a50f2010-06-21 22:57:05 +0000300 QETH_CARD_TEXT(card, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301
302 if (addr->proto == QETH_PROT_IPV4)
Carsten Otte847a50f2010-06-21 22:57:05 +0000303 QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304 else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000305 QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
306 QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100307 }
308 spin_lock_irqsave(&card->ip_lock, flags);
309 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
310 spin_unlock_irqrestore(&card->ip_lock, flags);
311 return rc;
312}
313
314static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
315{
316 unsigned long flags;
317 int rc = 0;
318
Carsten Otte847a50f2010-06-21 22:57:05 +0000319 QETH_CARD_TEXT(card, 4, "addip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100320 if (addr->proto == QETH_PROT_IPV4)
Carsten Otte847a50f2010-06-21 22:57:05 +0000321 QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100322 else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000323 QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
324 QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100325 }
326 spin_lock_irqsave(&card->ip_lock, flags);
327 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
328 spin_unlock_irqrestore(&card->ip_lock, flags);
329 return rc;
330}
331
332
333static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
334 enum qeth_prot_versions prot)
335{
336 struct qeth_ipaddr *addr;
337
338 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
339 if (addr == NULL) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100340 return NULL;
341 }
342 addr->type = QETH_IP_TYPE_NORMAL;
343 addr->proto = prot;
344 return addr;
345}
346
347static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
348{
349 struct qeth_ipaddr *iptodo;
350 unsigned long flags;
351
Carsten Otte847a50f2010-06-21 22:57:05 +0000352 QETH_CARD_TEXT(card, 4, "delmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100353 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
354 if (!iptodo) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000355 QETH_CARD_TEXT(card, 2, "dmcnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100356 return;
357 }
358 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
359 spin_lock_irqsave(&card->ip_lock, flags);
360 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
361 kfree(iptodo);
362 spin_unlock_irqrestore(&card->ip_lock, flags);
363}
364
365/*
366 * Add/remove address to/from card's ip list, i.e. try to add or remove
367 * reference to/from an IP address that is already registered on the card.
368 * Returns:
369 * 0 address was on card and its reference count has been adjusted,
370 * but is still > 0, so nothing has to be done
371 * also returns 0 if card was not on card and the todo was to delete
372 * the address -> there is also nothing to be done
373 * 1 address was not on card and the todo is to add it to the card's ip
374 * list
375 * -1 address was on card and its reference count has been decremented
376 * to <= 0 by the todo -> address must be removed from card
377 */
378static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
379 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
380{
381 struct qeth_ipaddr *addr;
382 int found = 0;
383
384 list_for_each_entry(addr, &card->ip_list, entry) {
385 if ((addr->proto == QETH_PROT_IPV4) &&
386 (todo->proto == QETH_PROT_IPV4) &&
387 (addr->type == todo->type) &&
388 (addr->u.a4.addr == todo->u.a4.addr) &&
389 (addr->u.a4.mask == todo->u.a4.mask)) {
390 found = 1;
391 break;
392 }
393 if ((addr->proto == QETH_PROT_IPV6) &&
394 (todo->proto == QETH_PROT_IPV6) &&
395 (addr->type == todo->type) &&
396 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
397 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
398 sizeof(struct in6_addr)) == 0)) {
399 found = 1;
400 break;
401 }
402 }
403 if (found) {
404 addr->users += todo->users;
405 if (addr->users <= 0) {
406 *__addr = addr;
407 return -1;
408 } else {
409 /* for VIPA and RXIP limit refcount to 1 */
410 if (addr->type != QETH_IP_TYPE_NORMAL)
411 addr->users = 1;
412 return 0;
413 }
414 }
415 if (todo->users > 0) {
416 /* for VIPA and RXIP limit refcount to 1 */
417 if (todo->type != QETH_IP_TYPE_NORMAL)
418 todo->users = 1;
419 return 1;
420 } else
421 return 0;
422}
423
424static void __qeth_l3_delete_all_mc(struct qeth_card *card,
425 unsigned long *flags)
426{
Ursula Braun2d921c32008-04-01 10:26:53 +0200427 struct list_head fail_list;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100428 struct qeth_ipaddr *addr, *tmp;
429 int rc;
Ursula Braun2d921c32008-04-01 10:26:53 +0200430
431 INIT_LIST_HEAD(&fail_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100432again:
433 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
434 if (addr->is_multicast) {
435 list_del(&addr->entry);
436 spin_unlock_irqrestore(&card->ip_lock, *flags);
437 rc = qeth_l3_deregister_addr_entry(card, addr);
438 spin_lock_irqsave(&card->ip_lock, *flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200439 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 kfree(addr);
Ursula Braun2d921c32008-04-01 10:26:53 +0200441 else
442 list_add_tail(&addr->entry, &fail_list);
443 goto again;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100444 }
445 }
Ursula Braun2d921c32008-04-01 10:26:53 +0200446 list_splice(&fail_list, &card->ip_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100447}
448
449static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
450{
451 struct list_head *tbd_list;
452 struct qeth_ipaddr *todo, *addr;
453 unsigned long flags;
454 int rc;
455
Carsten Otte847a50f2010-06-21 22:57:05 +0000456 QETH_CARD_TEXT(card, 2, "sdiplist");
457 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100458
Einar Lueckf154b792010-12-08 02:57:59 +0000459 if ((card->state != CARD_STATE_UP &&
460 card->state != CARD_STATE_SOFTSETUP) || card->options.sniffer) {
Ursula Braun76b11f82010-01-11 02:50:50 +0000461 return;
Einar Lueckf154b792010-12-08 02:57:59 +0000462 }
463
Frank Blaschka4a71df52008-02-15 09:19:42 +0100464 spin_lock_irqsave(&card->ip_lock, flags);
465 tbd_list = card->ip_tbd_list;
466 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
467 if (!card->ip_tbd_list) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000468 QETH_CARD_TEXT(card, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100469 card->ip_tbd_list = tbd_list;
470 spin_unlock_irqrestore(&card->ip_lock, flags);
471 return;
472 } else
473 INIT_LIST_HEAD(card->ip_tbd_list);
474
475 while (!list_empty(tbd_list)) {
476 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
477 list_del(&todo->entry);
478 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
479 __qeth_l3_delete_all_mc(card, &flags);
480 kfree(todo);
481 continue;
482 }
483 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
484 if (rc == 0) {
485 /* nothing to be done; only adjusted refcount */
486 kfree(todo);
487 } else if (rc == 1) {
488 /* new entry to be added to on-card list */
489 spin_unlock_irqrestore(&card->ip_lock, flags);
490 rc = qeth_l3_register_addr_entry(card, todo);
491 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200492 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493 list_add_tail(&todo->entry, &card->ip_list);
494 else
495 kfree(todo);
496 } else if (rc == -1) {
497 /* on-card entry to be removed */
498 list_del_init(&addr->entry);
499 spin_unlock_irqrestore(&card->ip_lock, flags);
500 rc = qeth_l3_deregister_addr_entry(card, addr);
501 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun76b11f82010-01-11 02:50:50 +0000502 if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100503 kfree(addr);
504 else
505 list_add_tail(&addr->entry, &card->ip_list);
506 kfree(todo);
507 }
508 }
509 spin_unlock_irqrestore(&card->ip_lock, flags);
510 kfree(tbd_list);
511}
512
513static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
514 int recover)
515{
516 struct qeth_ipaddr *addr, *tmp;
517 unsigned long flags;
518
Carsten Otte847a50f2010-06-21 22:57:05 +0000519 QETH_CARD_TEXT(card, 4, "clearip");
Ursula Braun76b11f82010-01-11 02:50:50 +0000520 if (recover && card->options.sniffer)
521 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100522 spin_lock_irqsave(&card->ip_lock, flags);
523 /* clear todo list */
524 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
525 list_del(&addr->entry);
526 kfree(addr);
527 }
528
529 while (!list_empty(&card->ip_list)) {
530 addr = list_entry(card->ip_list.next,
531 struct qeth_ipaddr, entry);
532 list_del_init(&addr->entry);
533 if (clean) {
534 spin_unlock_irqrestore(&card->ip_lock, flags);
535 qeth_l3_deregister_addr_entry(card, addr);
536 spin_lock_irqsave(&card->ip_lock, flags);
537 }
538 if (!recover || addr->is_multicast) {
539 kfree(addr);
540 continue;
541 }
542 list_add_tail(&addr->entry, card->ip_tbd_list);
543 }
544 spin_unlock_irqrestore(&card->ip_lock, flags);
545}
546
547static int qeth_l3_address_exists_in_list(struct list_head *list,
548 struct qeth_ipaddr *addr, int same_type)
549{
550 struct qeth_ipaddr *tmp;
551
552 list_for_each_entry(tmp, list, entry) {
553 if ((tmp->proto == QETH_PROT_IPV4) &&
554 (addr->proto == QETH_PROT_IPV4) &&
555 ((same_type && (tmp->type == addr->type)) ||
556 (!same_type && (tmp->type != addr->type))) &&
557 (tmp->u.a4.addr == addr->u.a4.addr))
558 return 1;
559
560 if ((tmp->proto == QETH_PROT_IPV6) &&
561 (addr->proto == QETH_PROT_IPV6) &&
562 ((same_type && (tmp->type == addr->type)) ||
563 (!same_type && (tmp->type != addr->type))) &&
564 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
565 sizeof(struct in6_addr)) == 0))
566 return 1;
567
568 }
569 return 0;
570}
571
572static int qeth_l3_send_setdelmc(struct qeth_card *card,
573 struct qeth_ipaddr *addr, int ipacmd)
574{
575 int rc;
576 struct qeth_cmd_buffer *iob;
577 struct qeth_ipa_cmd *cmd;
578
Carsten Otte847a50f2010-06-21 22:57:05 +0000579 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100580
581 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
582 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
583 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
584 if (addr->proto == QETH_PROT_IPV6)
585 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
586 sizeof(struct in6_addr));
587 else
588 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
589
590 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
591
592 return rc;
593}
594
595static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
596{
597 int i, j;
598 for (i = 0; i < 16; i++) {
599 j = (len) - (i * 8);
600 if (j >= 8)
601 netmask[i] = 0xff;
602 else if (j > 0)
603 netmask[i] = (u8)(0xFF00 >> j);
604 else
605 netmask[i] = 0;
606 }
607}
608
609static int qeth_l3_send_setdelip(struct qeth_card *card,
610 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
611{
612 int rc;
613 struct qeth_cmd_buffer *iob;
614 struct qeth_ipa_cmd *cmd;
615 __u8 netmask[16];
616
Carsten Otte847a50f2010-06-21 22:57:05 +0000617 QETH_CARD_TEXT(card, 4, "setdelip");
618 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100619
620 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
621 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
622 if (addr->proto == QETH_PROT_IPV6) {
623 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
624 sizeof(struct in6_addr));
625 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
626 memcpy(cmd->data.setdelip6.mask, netmask,
627 sizeof(struct in6_addr));
628 cmd->data.setdelip6.flags = flags;
629 } else {
630 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
631 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
632 cmd->data.setdelip4.flags = flags;
633 }
634
635 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
636
637 return rc;
638}
639
640static int qeth_l3_send_setrouting(struct qeth_card *card,
641 enum qeth_routing_types type, enum qeth_prot_versions prot)
642{
643 int rc;
644 struct qeth_ipa_cmd *cmd;
645 struct qeth_cmd_buffer *iob;
646
Carsten Otte847a50f2010-06-21 22:57:05 +0000647 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
649 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
650 cmd->data.setrtg.type = (type);
651 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
652
653 return rc;
654}
655
656static void qeth_l3_correct_routing_type(struct qeth_card *card,
657 enum qeth_routing_types *type, enum qeth_prot_versions prot)
658{
659 if (card->info.type == QETH_CARD_TYPE_IQD) {
660 switch (*type) {
661 case NO_ROUTER:
662 case PRIMARY_CONNECTOR:
663 case SECONDARY_CONNECTOR:
664 case MULTICAST_ROUTER:
665 return;
666 default:
667 goto out_inval;
668 }
669 } else {
670 switch (*type) {
671 case NO_ROUTER:
672 case PRIMARY_ROUTER:
673 case SECONDARY_ROUTER:
674 return;
675 case MULTICAST_ROUTER:
676 if (qeth_is_ipafunc_supported(card, prot,
677 IPA_OSA_MC_ROUTER))
678 return;
679 default:
680 goto out_inval;
681 }
682 }
683out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684 *type = NO_ROUTER;
685}
686
687int qeth_l3_setrouting_v4(struct qeth_card *card)
688{
689 int rc;
690
Carsten Otte847a50f2010-06-21 22:57:05 +0000691 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692
693 qeth_l3_correct_routing_type(card, &card->options.route4.type,
694 QETH_PROT_IPV4);
695
696 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
697 QETH_PROT_IPV4);
698 if (rc) {
699 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200700 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
701 " on %s. Type set to 'no router'.\n", rc,
702 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100703 }
704 return rc;
705}
706
707int qeth_l3_setrouting_v6(struct qeth_card *card)
708{
709 int rc = 0;
710
Carsten Otte847a50f2010-06-21 22:57:05 +0000711 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100712#ifdef CONFIG_QETH_IPV6
713
714 if (!qeth_is_supported(card, IPA_IPV6))
715 return 0;
716 qeth_l3_correct_routing_type(card, &card->options.route6.type,
717 QETH_PROT_IPV6);
718
719 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
720 QETH_PROT_IPV6);
721 if (rc) {
722 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200723 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
724 " on %s. Type set to 'no router'.\n", rc,
725 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100726 }
727#endif
728 return rc;
729}
730
731/*
732 * IP address takeover related functions
733 */
734static void qeth_l3_clear_ipato_list(struct qeth_card *card)
735{
736
737 struct qeth_ipato_entry *ipatoe, *tmp;
738 unsigned long flags;
739
740 spin_lock_irqsave(&card->ip_lock, flags);
741 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
742 list_del(&ipatoe->entry);
743 kfree(ipatoe);
744 }
745 spin_unlock_irqrestore(&card->ip_lock, flags);
746}
747
748int qeth_l3_add_ipato_entry(struct qeth_card *card,
749 struct qeth_ipato_entry *new)
750{
751 struct qeth_ipato_entry *ipatoe;
752 unsigned long flags;
753 int rc = 0;
754
Carsten Otte847a50f2010-06-21 22:57:05 +0000755 QETH_CARD_TEXT(card, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756 spin_lock_irqsave(&card->ip_lock, flags);
757 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
758 if (ipatoe->proto != new->proto)
759 continue;
760 if (!memcmp(ipatoe->addr, new->addr,
761 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
762 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100763 rc = -EEXIST;
764 break;
765 }
766 }
767 if (!rc)
768 list_add_tail(&new->entry, &card->ipato.entries);
769
770 spin_unlock_irqrestore(&card->ip_lock, flags);
771 return rc;
772}
773
774void qeth_l3_del_ipato_entry(struct qeth_card *card,
775 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
776{
777 struct qeth_ipato_entry *ipatoe, *tmp;
778 unsigned long flags;
779
Carsten Otte847a50f2010-06-21 22:57:05 +0000780 QETH_CARD_TEXT(card, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100781 spin_lock_irqsave(&card->ip_lock, flags);
782 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
783 if (ipatoe->proto != proto)
784 continue;
785 if (!memcmp(ipatoe->addr, addr,
786 (proto == QETH_PROT_IPV4)? 4:16) &&
787 (ipatoe->mask_bits == mask_bits)) {
788 list_del(&ipatoe->entry);
789 kfree(ipatoe);
790 }
791 }
792 spin_unlock_irqrestore(&card->ip_lock, flags);
793}
794
795/*
796 * VIPA related functions
797 */
798int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
799 const u8 *addr)
800{
801 struct qeth_ipaddr *ipaddr;
802 unsigned long flags;
803 int rc = 0;
804
805 ipaddr = qeth_l3_get_addr_buffer(proto);
806 if (ipaddr) {
807 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000808 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100809 memcpy(&ipaddr->u.a4.addr, addr, 4);
810 ipaddr->u.a4.mask = 0;
811 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000812 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100813 memcpy(&ipaddr->u.a6.addr, addr, 16);
814 ipaddr->u.a6.pfxlen = 0;
815 }
816 ipaddr->type = QETH_IP_TYPE_VIPA;
817 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
818 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
819 } else
820 return -ENOMEM;
821 spin_lock_irqsave(&card->ip_lock, flags);
822 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
823 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
824 rc = -EEXIST;
825 spin_unlock_irqrestore(&card->ip_lock, flags);
826 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100827 return rc;
828 }
829 if (!qeth_l3_add_ip(card, ipaddr))
830 kfree(ipaddr);
831 qeth_l3_set_ip_addr_list(card);
832 return rc;
833}
834
835void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
836 const u8 *addr)
837{
838 struct qeth_ipaddr *ipaddr;
839
840 ipaddr = qeth_l3_get_addr_buffer(proto);
841 if (ipaddr) {
842 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000843 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 memcpy(&ipaddr->u.a4.addr, addr, 4);
845 ipaddr->u.a4.mask = 0;
846 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000847 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848 memcpy(&ipaddr->u.a6.addr, addr, 16);
849 ipaddr->u.a6.pfxlen = 0;
850 }
851 ipaddr->type = QETH_IP_TYPE_VIPA;
852 } else
853 return;
854 if (!qeth_l3_delete_ip(card, ipaddr))
855 kfree(ipaddr);
856 qeth_l3_set_ip_addr_list(card);
857}
858
859/*
860 * proxy ARP related functions
861 */
862int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
863 const u8 *addr)
864{
865 struct qeth_ipaddr *ipaddr;
866 unsigned long flags;
867 int rc = 0;
868
869 ipaddr = qeth_l3_get_addr_buffer(proto);
870 if (ipaddr) {
871 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000872 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873 memcpy(&ipaddr->u.a4.addr, addr, 4);
874 ipaddr->u.a4.mask = 0;
875 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000876 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100877 memcpy(&ipaddr->u.a6.addr, addr, 16);
878 ipaddr->u.a6.pfxlen = 0;
879 }
880 ipaddr->type = QETH_IP_TYPE_RXIP;
881 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
882 ipaddr->del_flags = 0;
883 } else
884 return -ENOMEM;
885 spin_lock_irqsave(&card->ip_lock, flags);
886 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
887 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
888 rc = -EEXIST;
889 spin_unlock_irqrestore(&card->ip_lock, flags);
890 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100891 return rc;
892 }
893 if (!qeth_l3_add_ip(card, ipaddr))
894 kfree(ipaddr);
895 qeth_l3_set_ip_addr_list(card);
896 return 0;
897}
898
899void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
900 const u8 *addr)
901{
902 struct qeth_ipaddr *ipaddr;
903
904 ipaddr = qeth_l3_get_addr_buffer(proto);
905 if (ipaddr) {
906 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000907 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 memcpy(&ipaddr->u.a4.addr, addr, 4);
909 ipaddr->u.a4.mask = 0;
910 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000911 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912 memcpy(&ipaddr->u.a6.addr, addr, 16);
913 ipaddr->u.a6.pfxlen = 0;
914 }
915 ipaddr->type = QETH_IP_TYPE_RXIP;
916 } else
917 return;
918 if (!qeth_l3_delete_ip(card, ipaddr))
919 kfree(ipaddr);
920 qeth_l3_set_ip_addr_list(card);
921}
922
923static int qeth_l3_register_addr_entry(struct qeth_card *card,
924 struct qeth_ipaddr *addr)
925{
926 char buf[50];
927 int rc = 0;
928 int cnt = 3;
929
930 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000931 QETH_CARD_TEXT(card, 2, "setaddr4");
932 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000934 QETH_CARD_TEXT(card, 2, "setaddr6");
935 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
936 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000938 QETH_CARD_TEXT(card, 2, "setaddr?");
939 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100940 }
941 do {
942 if (addr->is_multicast)
943 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
944 else
945 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
946 addr->set_flags);
947 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000948 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949 } while ((--cnt > 0) && rc);
950 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000951 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100953 dev_warn(&card->gdev->dev,
954 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 }
956 return rc;
957}
958
959static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
960 struct qeth_ipaddr *addr)
961{
962 int rc = 0;
963
964 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000965 QETH_CARD_TEXT(card, 2, "deladdr4");
966 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000968 QETH_CARD_TEXT(card, 2, "deladdr6");
969 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
970 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100971 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000972 QETH_CARD_TEXT(card, 2, "deladdr?");
973 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100974 }
975 if (addr->is_multicast)
976 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
977 else
978 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
979 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200980 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000981 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100982
983 return rc;
984}
985
986static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
987{
988 if (cast_type == RTN_MULTICAST)
989 return QETH_CAST_MULTICAST;
990 if (cast_type == RTN_BROADCAST)
991 return QETH_CAST_BROADCAST;
992 return QETH_CAST_UNICAST;
993}
994
995static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
996{
997 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
998 if (cast_type == RTN_MULTICAST)
999 return ct | QETH_CAST_MULTICAST;
1000 if (cast_type == RTN_ANYCAST)
1001 return ct | QETH_CAST_ANYCAST;
1002 if (cast_type == RTN_BROADCAST)
1003 return ct | QETH_CAST_BROADCAST;
1004 return ct | QETH_CAST_UNICAST;
1005}
1006
1007static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
1008 __u32 mode)
1009{
1010 int rc;
1011 struct qeth_cmd_buffer *iob;
1012 struct qeth_ipa_cmd *cmd;
1013
Carsten Otte847a50f2010-06-21 22:57:05 +00001014 QETH_CARD_TEXT(card, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001015
1016 iob = qeth_get_adapter_cmd(card, command,
1017 sizeof(struct qeth_ipacmd_setadpparms));
1018 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1019 cmd->data.setadapterparms.data.mode = mode;
1020 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
1021 NULL);
1022 return rc;
1023}
1024
1025static int qeth_l3_setadapter_hstr(struct qeth_card *card)
1026{
1027 int rc;
1028
Carsten Otte847a50f2010-06-21 22:57:05 +00001029 QETH_CARD_TEXT(card, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001030
1031 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1032 rc = qeth_l3_send_setadp_mode(card,
1033 IPA_SETADP_SET_BROADCAST_MODE,
1034 card->options.broadcast_mode);
1035 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001036 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001037 "device %s: x%x\n",
1038 CARD_BUS_ID(card), rc);
1039 rc = qeth_l3_send_setadp_mode(card,
1040 IPA_SETADP_ALTER_MAC_ADDRESS,
1041 card->options.macaddr_mode);
1042 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001043 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1045 return rc;
1046 }
1047 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001048 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001049 "to set broadcast mode, using ALLRINGS "
1050 "on device %s:\n", CARD_BUS_ID(card));
1051 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001052 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001053 "to set macaddr mode, using NONCANONICAL "
1054 "on device %s:\n", CARD_BUS_ID(card));
1055 return 0;
1056}
1057
1058static int qeth_l3_setadapter_parms(struct qeth_card *card)
1059{
1060 int rc;
1061
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001062 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001063
1064 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001065 dev_info(&card->gdev->dev,
1066 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001067 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001068 return 0;
1069 }
1070 rc = qeth_query_setadapterparms(card);
1071 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001072 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +00001073 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001074 return rc;
1075 }
1076 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1077 rc = qeth_setadpparms_change_macaddr(card);
1078 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001079 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001080 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001081 }
1082
1083 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1084 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1085 rc = qeth_l3_setadapter_hstr(card);
1086
1087 return rc;
1088}
1089
1090static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1091 struct qeth_reply *reply, unsigned long data)
1092{
1093 struct qeth_ipa_cmd *cmd;
1094
Carsten Otte847a50f2010-06-21 22:57:05 +00001095 QETH_CARD_TEXT(card, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001096
1097 cmd = (struct qeth_ipa_cmd *) data;
1098 if (cmd->hdr.return_code == 0) {
1099 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1100 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1101 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1102 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1103 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1104 }
1105 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1106 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1107 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001108 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001109 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001110 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1111 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1112 card->info.tx_csum_mask =
1113 cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001114 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001115 }
1116
Frank Blaschka4a71df52008-02-15 09:19:42 +01001117 return 0;
1118}
1119
1120static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1121 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1122 __u16 len, enum qeth_prot_versions prot)
1123{
1124 struct qeth_cmd_buffer *iob;
1125 struct qeth_ipa_cmd *cmd;
1126
Carsten Otte847a50f2010-06-21 22:57:05 +00001127 QETH_CARD_TEXT(card, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001128 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1129
1130 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1131 cmd->data.setassparms.hdr.assist_no = ipa_func;
1132 cmd->data.setassparms.hdr.length = 8 + len;
1133 cmd->data.setassparms.hdr.command_code = cmd_code;
1134 cmd->data.setassparms.hdr.return_code = 0;
1135 cmd->data.setassparms.hdr.seq_no = 0;
1136
1137 return iob;
1138}
1139
1140static int qeth_l3_send_setassparms(struct qeth_card *card,
1141 struct qeth_cmd_buffer *iob, __u16 len, long data,
1142 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1143 unsigned long),
1144 void *reply_param)
1145{
1146 int rc;
1147 struct qeth_ipa_cmd *cmd;
1148
Carsten Otte847a50f2010-06-21 22:57:05 +00001149 QETH_CARD_TEXT(card, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001150
1151 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1152 if (len <= sizeof(__u32))
1153 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1154 else /* (len > sizeof(__u32)) */
1155 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1156
1157 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1158 return rc;
1159}
1160
1161#ifdef CONFIG_QETH_IPV6
1162static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1163 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1164{
1165 int rc;
1166 struct qeth_cmd_buffer *iob;
1167
Carsten Otte847a50f2010-06-21 22:57:05 +00001168 QETH_CARD_TEXT(card, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001169 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1170 0, QETH_PROT_IPV6);
1171 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1172 qeth_l3_default_setassparms_cb, NULL);
1173 return rc;
1174}
1175#endif
1176
1177static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1178 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1179{
1180 int rc;
1181 int length = 0;
1182 struct qeth_cmd_buffer *iob;
1183
Carsten Otte847a50f2010-06-21 22:57:05 +00001184 QETH_CARD_TEXT(card, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185 if (data)
1186 length = sizeof(__u32);
1187 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1188 length, QETH_PROT_IPV4);
1189 rc = qeth_l3_send_setassparms(card, iob, length, data,
1190 qeth_l3_default_setassparms_cb, NULL);
1191 return rc;
1192}
1193
1194static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1195{
1196 int rc;
1197
Carsten Otte847a50f2010-06-21 22:57:05 +00001198 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001199
1200 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001201 dev_info(&card->gdev->dev,
1202 "ARP processing not supported on %s!\n",
1203 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001204 return 0;
1205 }
1206 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1207 IPA_CMD_ASS_START, 0);
1208 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001209 dev_warn(&card->gdev->dev,
1210 "Starting ARP processing support for %s failed\n",
1211 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001212 }
1213 return rc;
1214}
1215
1216static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1217{
1218 int rc;
1219
Carsten Otte847a50f2010-06-21 22:57:05 +00001220 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001221
1222 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001223 dev_info(&card->gdev->dev,
1224 "Hardware IP fragmentation not supported on %s\n",
1225 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001226 return -EOPNOTSUPP;
1227 }
1228
1229 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1230 IPA_CMD_ASS_START, 0);
1231 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001232 dev_warn(&card->gdev->dev,
1233 "Starting IP fragmentation support for %s failed\n",
1234 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001236 dev_info(&card->gdev->dev,
1237 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001238 return rc;
1239}
1240
1241static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1242{
1243 int rc;
1244
Carsten Otte847a50f2010-06-21 22:57:05 +00001245 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001246
Frank Blaschka4a71df52008-02-15 09:19:42 +01001247 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001248 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001249 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001250 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001251 return -EOPNOTSUPP;
1252 }
1253
1254 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1255 IPA_CMD_ASS_START, 0);
1256 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001257 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001258 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001259 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001260 return rc;
1261}
1262
1263static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1264{
1265 int rc = 0;
1266
Carsten Otte847a50f2010-06-21 22:57:05 +00001267 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001268
1269 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001270 dev_info(&card->gdev->dev,
1271 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001272 return -EOPNOTSUPP;
1273 }
1274
1275 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1276 IPA_CMD_ASS_START, 0);
1277 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001278 dev_warn(&card->gdev->dev,
1279 "Starting VLAN support for %s failed\n",
1280 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001281 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001282 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001283 }
1284 return rc;
1285}
1286
1287static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1288{
1289 int rc;
1290
Carsten Otte847a50f2010-06-21 22:57:05 +00001291 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001292
1293 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001294 dev_info(&card->gdev->dev,
1295 "Multicast not supported on %s\n",
1296 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001297 return -EOPNOTSUPP;
1298 }
1299
1300 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1301 IPA_CMD_ASS_START, 0);
1302 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001303 dev_warn(&card->gdev->dev,
1304 "Starting multicast support for %s failed\n",
1305 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001306 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001307 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001308 card->dev->flags |= IFF_MULTICAST;
1309 }
1310 return rc;
1311}
1312
1313static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1314 struct qeth_reply *reply, unsigned long data)
1315{
1316 struct qeth_ipa_cmd *cmd;
1317
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001318 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319
1320 cmd = (struct qeth_ipa_cmd *) data;
1321 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1322 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1323 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1324 } else {
1325 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1326 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1327 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001328 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1329 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1330 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001331 return 0;
1332}
1333
1334static int qeth_l3_query_ipassists(struct qeth_card *card,
1335 enum qeth_prot_versions prot)
1336{
1337 int rc;
1338 struct qeth_cmd_buffer *iob;
1339
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001340 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001341 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1342 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1343 return rc;
1344}
1345
1346#ifdef CONFIG_QETH_IPV6
1347static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1348{
1349 int rc;
1350
Carsten Otte847a50f2010-06-21 22:57:05 +00001351 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001352
1353 if (card->info.type == QETH_CARD_TYPE_IQD)
1354 goto out;
1355
1356 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1357 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001358 dev_err(&card->gdev->dev,
1359 "Activating IPv6 support for %s failed\n",
1360 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001361 return rc;
1362 }
1363 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1364 IPA_CMD_ASS_START, 3);
1365 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001366 dev_err(&card->gdev->dev,
1367 "Activating IPv6 support for %s failed\n",
1368 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001369 return rc;
1370 }
1371 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1372 IPA_CMD_ASS_START);
1373 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001374 dev_err(&card->gdev->dev,
1375 "Activating IPv6 support for %s failed\n",
1376 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001377 return rc;
1378 }
1379 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1380 IPA_CMD_ASS_START);
1381 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001382 dev_warn(&card->gdev->dev,
1383 "Enabling the passthrough mode for %s failed\n",
1384 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001385 return rc;
1386 }
1387out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001388 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001389 return 0;
1390}
1391#endif
1392
1393static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1394{
1395 int rc = 0;
1396
Carsten Otte847a50f2010-06-21 22:57:05 +00001397 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398
1399 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001400 dev_info(&card->gdev->dev,
1401 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001402 return 0;
1403 }
1404#ifdef CONFIG_QETH_IPV6
1405 rc = qeth_l3_softsetup_ipv6(card);
1406#endif
1407 return rc ;
1408}
1409
1410static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1411{
1412 int rc;
1413
Carsten Otte847a50f2010-06-21 22:57:05 +00001414 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001415 card->info.broadcast_capable = 0;
1416 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001417 dev_info(&card->gdev->dev,
1418 "Broadcast not supported on %s\n",
1419 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001420 rc = -EOPNOTSUPP;
1421 goto out;
1422 }
1423 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1424 IPA_CMD_ASS_START, 0);
1425 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001426 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1427 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001428 goto out;
1429 }
1430
1431 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1432 IPA_CMD_ASS_CONFIGURE, 1);
1433 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001434 dev_warn(&card->gdev->dev,
1435 "Setting up broadcast filtering for %s failed\n",
1436 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001437 goto out;
1438 }
1439 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001440 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001441 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1442 IPA_CMD_ASS_ENABLE, 1);
1443 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001444 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1445 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001446 goto out;
1447 }
1448 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1449out:
1450 if (card->info.broadcast_capable)
1451 card->dev->flags |= IFF_BROADCAST;
1452 else
1453 card->dev->flags &= ~IFF_BROADCAST;
1454 return rc;
1455}
1456
1457static int qeth_l3_send_checksum_command(struct qeth_card *card)
1458{
1459 int rc;
1460
1461 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1462 IPA_CMD_ASS_START, 0);
1463 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001464 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1465 "failed, using SW checksumming\n",
1466 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001467 return rc;
1468 }
1469 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1470 IPA_CMD_ASS_ENABLE,
1471 card->info.csum_mask);
1472 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001473 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1474 "failed, using SW checksumming\n",
1475 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001476 return rc;
1477 }
1478 return 0;
1479}
1480
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001481int qeth_l3_set_rx_csum(struct qeth_card *card,
1482 enum qeth_checksum_types csum_type)
1483{
1484 int rc = 0;
1485
1486 if (card->options.checksum_type == HW_CHECKSUMMING) {
1487 if ((csum_type != HW_CHECKSUMMING) &&
1488 (card->state != CARD_STATE_DOWN)) {
1489 rc = qeth_l3_send_simple_setassparms(card,
1490 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1491 if (rc)
1492 return -EIO;
1493 }
1494 } else {
1495 if (csum_type == HW_CHECKSUMMING) {
1496 if (card->state != CARD_STATE_DOWN) {
1497 if (!qeth_is_supported(card,
1498 IPA_INBOUND_CHECKSUM))
1499 return -EPERM;
1500 rc = qeth_l3_send_checksum_command(card);
1501 if (rc)
1502 return -EIO;
1503 }
1504 }
1505 }
1506 card->options.checksum_type = csum_type;
1507 return rc;
1508}
1509
Frank Blaschka4a71df52008-02-15 09:19:42 +01001510static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1511{
1512 int rc = 0;
1513
Carsten Otte847a50f2010-06-21 22:57:05 +00001514 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001515
1516 if (card->options.checksum_type == NO_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001517 dev_info(&card->gdev->dev,
1518 "Using no checksumming on %s.\n",
1519 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001520 return 0;
1521 }
1522 if (card->options.checksum_type == SW_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001523 dev_info(&card->gdev->dev,
1524 "Using SW checksumming on %s.\n",
1525 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001526 return 0;
1527 }
1528 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001529 dev_info(&card->gdev->dev,
1530 "Inbound HW Checksumming not "
1531 "supported on %s,\ncontinuing "
1532 "using Inbound SW Checksumming\n",
1533 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001534 card->options.checksum_type = SW_CHECKSUMMING;
1535 return 0;
1536 }
1537 rc = qeth_l3_send_checksum_command(card);
1538 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001539 dev_info(&card->gdev->dev,
1540 "HW Checksumming (inbound) enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001541
1542 return rc;
1543}
1544
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001545static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1546{
1547 int rc = 0;
1548
1549 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1550 return rc;
1551 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1552 IPA_CMD_ASS_START, 0);
1553 if (rc)
1554 goto err_out;
1555 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1556 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1557 if (rc)
1558 goto err_out;
1559 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1560 return rc;
1561err_out:
1562 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1563 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1564 return rc;
1565}
1566
Frank Blaschka4a71df52008-02-15 09:19:42 +01001567static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1568{
1569 int rc;
1570
Carsten Otte847a50f2010-06-21 22:57:05 +00001571 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001572
1573 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001574 dev_info(&card->gdev->dev,
1575 "Outbound TSO not supported on %s\n",
1576 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001577 rc = -EOPNOTSUPP;
1578 } else {
1579 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1580 IPA_CMD_ASS_START, 0);
1581 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001582 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1583 "segmentation offload for %s failed\n",
1584 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001585 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001586 dev_info(&card->gdev->dev,
1587 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001588 }
1589 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1590 card->options.large_send = QETH_LARGE_SEND_NO;
1591 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1592 }
1593 return rc;
1594}
1595
1596static int qeth_l3_start_ipassists(struct qeth_card *card)
1597{
Carsten Otte847a50f2010-06-21 22:57:05 +00001598 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001599
1600 qeth_set_access_ctrl_online(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001601 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1602 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1603 qeth_l3_start_ipa_source_mac(card); /* go on*/
1604 qeth_l3_start_ipa_vlan(card); /* go on*/
1605 qeth_l3_start_ipa_multicast(card); /* go on*/
1606 qeth_l3_start_ipa_ipv6(card); /* go on*/
1607 qeth_l3_start_ipa_broadcast(card); /* go on*/
1608 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001609 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001610 qeth_l3_start_ipa_tso(card); /* go on*/
1611 return 0;
1612}
1613
1614static int qeth_l3_put_unique_id(struct qeth_card *card)
1615{
1616
1617 int rc = 0;
1618 struct qeth_cmd_buffer *iob;
1619 struct qeth_ipa_cmd *cmd;
1620
Carsten Otte847a50f2010-06-21 22:57:05 +00001621 QETH_CARD_TEXT(card, 2, "puniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001622
1623 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1624 UNIQUE_ID_NOT_BY_CARD)
1625 return -1;
1626 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1627 QETH_PROT_IPV6);
1628 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1629 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1630 card->info.unique_id;
1631 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1632 card->dev->dev_addr, OSA_ADDR_LEN);
1633 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1634 return rc;
1635}
1636
1637static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1638 struct qeth_reply *reply, unsigned long data)
1639{
1640 struct qeth_ipa_cmd *cmd;
1641
1642 cmd = (struct qeth_ipa_cmd *) data;
1643 if (cmd->hdr.return_code == 0)
1644 memcpy(card->dev->dev_addr,
1645 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1646 else
1647 random_ether_addr(card->dev->dev_addr);
1648
1649 return 0;
1650}
1651
1652static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1653{
1654 int rc = 0;
1655 struct qeth_cmd_buffer *iob;
1656 struct qeth_ipa_cmd *cmd;
1657
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001658 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001659
1660 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1661 QETH_PROT_IPV6);
1662 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1663 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1664 card->info.unique_id;
1665
1666 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1667 NULL);
1668 return rc;
1669}
1670
1671static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1672 struct qeth_reply *reply, unsigned long data)
1673{
1674 struct qeth_ipa_cmd *cmd;
1675
1676 cmd = (struct qeth_ipa_cmd *) data;
1677 if (cmd->hdr.return_code == 0)
1678 card->info.unique_id = *((__u16 *)
1679 &cmd->data.create_destroy_addr.unique_id[6]);
1680 else {
1681 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1682 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001683 dev_warn(&card->gdev->dev, "The network adapter failed to "
1684 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001685 }
1686 return 0;
1687}
1688
1689static int qeth_l3_get_unique_id(struct qeth_card *card)
1690{
1691 int rc = 0;
1692 struct qeth_cmd_buffer *iob;
1693 struct qeth_ipa_cmd *cmd;
1694
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001695 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001696
1697 if (!qeth_is_supported(card, IPA_IPV6)) {
1698 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1699 UNIQUE_ID_NOT_BY_CARD;
1700 return 0;
1701 }
1702
1703 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1704 QETH_PROT_IPV6);
1705 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1706 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1707 card->info.unique_id;
1708
1709 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1710 return rc;
1711}
1712
Ursula Braun76b11f82010-01-11 02:50:50 +00001713static int
1714qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1715 unsigned long data)
1716{
1717 struct qeth_ipa_cmd *cmd;
1718 __u16 rc;
1719
1720 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1721
1722 cmd = (struct qeth_ipa_cmd *)data;
1723 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001724 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001725 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001726 switch (cmd->data.diagass.action) {
1727 case QETH_DIAGS_CMD_TRACE_QUERY:
1728 break;
1729 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001730 switch (rc) {
1731 case 0:
1732 case IPA_RC_INVALID_SUBCMD:
1733 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1734 dev_info(&card->gdev->dev, "The HiperSockets network "
1735 "traffic analyzer is deactivated\n");
1736 break;
1737 default:
1738 break;
1739 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001740 break;
1741 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001742 switch (rc) {
1743 case 0:
1744 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1745 dev_info(&card->gdev->dev, "The HiperSockets network "
1746 "traffic analyzer is activated\n");
1747 break;
1748 case IPA_RC_HARDWARE_AUTH_ERROR:
1749 dev_warn(&card->gdev->dev, "The device is not "
1750 "authorized to run as a HiperSockets network "
1751 "traffic analyzer\n");
1752 break;
1753 case IPA_RC_TRACE_ALREADY_ACTIVE:
1754 dev_warn(&card->gdev->dev, "A HiperSockets "
1755 "network traffic analyzer is already "
1756 "active in the HiperSockets LAN\n");
1757 break;
1758 default:
1759 break;
1760 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001761 break;
1762 default:
1763 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1764 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1765 }
1766
1767 return 0;
1768}
1769
1770static int
1771qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1772{
1773 struct qeth_cmd_buffer *iob;
1774 struct qeth_ipa_cmd *cmd;
1775
1776 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1777
1778 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1779 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1780 cmd->data.diagass.subcmd_len = 16;
1781 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1782 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1783 cmd->data.diagass.action = diags_cmd;
1784 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1785}
1786
Frank Blaschka4a71df52008-02-15 09:19:42 +01001787static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1788 struct net_device *dev)
1789{
1790 if (dev->type == ARPHRD_IEEE802_TR)
1791 ip_tr_mc_map(ipm, mac);
1792 else
1793 ip_eth_mc_map(ipm, mac);
1794}
1795
1796static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1797{
1798 struct qeth_ipaddr *ipm;
1799 struct ip_mc_list *im4;
1800 char buf[MAX_ADDR_LEN];
1801
Carsten Otte847a50f2010-06-21 22:57:05 +00001802 QETH_CARD_TEXT(card, 4, "addmc");
Sachin Santf3aa31362010-11-26 02:41:17 +00001803 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1804 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001805 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1806 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1807 if (!ipm)
1808 continue;
1809 ipm->u.a4.addr = im4->multiaddr;
1810 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1811 ipm->is_multicast = 1;
1812 if (!qeth_l3_add_ip(card, ipm))
1813 kfree(ipm);
1814 }
1815}
1816
1817static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1818{
1819 struct in_device *in_dev;
1820 struct vlan_group *vg;
1821 int i;
1822
Carsten Otte847a50f2010-06-21 22:57:05 +00001823 QETH_CARD_TEXT(card, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001824 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1825 return;
1826
1827 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001828 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001829 struct net_device *netdev = vlan_group_get_device(vg, i);
1830 if (netdev == NULL ||
1831 !(netdev->flags & IFF_UP))
1832 continue;
1833 in_dev = in_dev_get(netdev);
1834 if (!in_dev)
1835 continue;
Sachin Santf3aa31362010-11-26 02:41:17 +00001836 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001837 qeth_l3_add_mc(card, in_dev);
Sachin Santf3aa31362010-11-26 02:41:17 +00001838 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001839 in_dev_put(in_dev);
1840 }
1841}
1842
1843static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1844{
1845 struct in_device *in4_dev;
1846
Carsten Otte847a50f2010-06-21 22:57:05 +00001847 QETH_CARD_TEXT(card, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001848 in4_dev = in_dev_get(card->dev);
1849 if (in4_dev == NULL)
1850 return;
Sachin Santf3aa31362010-11-26 02:41:17 +00001851 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001852 qeth_l3_add_mc(card, in4_dev);
1853 qeth_l3_add_vlan_mc(card);
Sachin Santf3aa31362010-11-26 02:41:17 +00001854 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001855 in_dev_put(in4_dev);
1856}
1857
1858#ifdef CONFIG_QETH_IPV6
1859static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1860{
1861 struct qeth_ipaddr *ipm;
1862 struct ifmcaddr6 *im6;
1863 char buf[MAX_ADDR_LEN];
1864
Carsten Otte847a50f2010-06-21 22:57:05 +00001865 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001866 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1867 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1868 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1869 if (!ipm)
1870 continue;
1871 ipm->is_multicast = 1;
1872 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1873 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1874 sizeof(struct in6_addr));
1875 if (!qeth_l3_add_ip(card, ipm))
1876 kfree(ipm);
1877 }
1878}
1879
1880static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1881{
1882 struct inet6_dev *in_dev;
1883 struct vlan_group *vg;
1884 int i;
1885
Carsten Otte847a50f2010-06-21 22:57:05 +00001886 QETH_CARD_TEXT(card, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001887 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1888 return;
1889
1890 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001891 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001892 struct net_device *netdev = vlan_group_get_device(vg, i);
1893 if (netdev == NULL ||
1894 !(netdev->flags & IFF_UP))
1895 continue;
1896 in_dev = in6_dev_get(netdev);
1897 if (!in_dev)
1898 continue;
1899 read_lock_bh(&in_dev->lock);
1900 qeth_l3_add_mc6(card, in_dev);
1901 read_unlock_bh(&in_dev->lock);
1902 in6_dev_put(in_dev);
1903 }
1904}
1905
1906static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1907{
1908 struct inet6_dev *in6_dev;
1909
Carsten Otte847a50f2010-06-21 22:57:05 +00001910 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001911 if (!qeth_is_supported(card, IPA_IPV6))
1912 return ;
1913 in6_dev = in6_dev_get(card->dev);
1914 if (in6_dev == NULL)
1915 return;
1916 read_lock_bh(&in6_dev->lock);
1917 qeth_l3_add_mc6(card, in6_dev);
1918 qeth_l3_add_vlan_mc6(card);
1919 read_unlock_bh(&in6_dev->lock);
1920 in6_dev_put(in6_dev);
1921}
1922#endif /* CONFIG_QETH_IPV6 */
1923
1924static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1925 unsigned short vid)
1926{
1927 struct in_device *in_dev;
1928 struct in_ifaddr *ifa;
1929 struct qeth_ipaddr *addr;
1930
Carsten Otte847a50f2010-06-21 22:57:05 +00001931 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001932
1933 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1934 if (!in_dev)
1935 return;
1936 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1937 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1938 if (addr) {
1939 addr->u.a4.addr = ifa->ifa_address;
1940 addr->u.a4.mask = ifa->ifa_mask;
1941 addr->type = QETH_IP_TYPE_NORMAL;
1942 if (!qeth_l3_delete_ip(card, addr))
1943 kfree(addr);
1944 }
1945 }
1946 in_dev_put(in_dev);
1947}
1948
1949static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1950 unsigned short vid)
1951{
1952#ifdef CONFIG_QETH_IPV6
1953 struct inet6_dev *in6_dev;
1954 struct inet6_ifaddr *ifa;
1955 struct qeth_ipaddr *addr;
1956
Carsten Otte847a50f2010-06-21 22:57:05 +00001957 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001958
1959 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1960 if (!in6_dev)
1961 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001962 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001963 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1964 if (addr) {
1965 memcpy(&addr->u.a6.addr, &ifa->addr,
1966 sizeof(struct in6_addr));
1967 addr->u.a6.pfxlen = ifa->prefix_len;
1968 addr->type = QETH_IP_TYPE_NORMAL;
1969 if (!qeth_l3_delete_ip(card, addr))
1970 kfree(addr);
1971 }
1972 }
1973 in6_dev_put(in6_dev);
1974#endif /* CONFIG_QETH_IPV6 */
1975}
1976
1977static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1978 unsigned short vid)
1979{
1980 if (!card->vlangrp)
1981 return;
1982 qeth_l3_free_vlan_addresses4(card, vid);
1983 qeth_l3_free_vlan_addresses6(card, vid);
1984}
1985
1986static void qeth_l3_vlan_rx_register(struct net_device *dev,
1987 struct vlan_group *grp)
1988{
Heiko Carstens509e2562008-07-26 02:24:10 -07001989 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001990 unsigned long flags;
1991
Carsten Otte847a50f2010-06-21 22:57:05 +00001992 QETH_CARD_TEXT(card, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001993 spin_lock_irqsave(&card->vlanlock, flags);
1994 card->vlangrp = grp;
1995 spin_unlock_irqrestore(&card->vlanlock, flags);
1996}
1997
1998static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1999{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002000 return;
2001}
2002
2003static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2004{
Heiko Carstens509e2562008-07-26 02:24:10 -07002005 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002006 unsigned long flags;
2007
Carsten Otte847a50f2010-06-21 22:57:05 +00002008 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00002009 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002010 QETH_CARD_TEXT(card, 3, "kidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002011 return;
2012 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002013 spin_lock_irqsave(&card->vlanlock, flags);
2014 /* unregister IP addresses of vlan device */
2015 qeth_l3_free_vlan_addresses(card, vid);
2016 vlan_group_set_device(card->vlangrp, vid, NULL);
2017 spin_unlock_irqrestore(&card->vlanlock, flags);
2018 qeth_l3_set_multicast_list(card->dev);
2019}
2020
Ursula Braun10651db2010-10-01 02:51:13 +00002021static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
2022 struct sk_buff *skb, struct qeth_hdr *hdr,
2023 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002024{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002025 __be16 prot;
2026 struct iphdr *ip_hdr;
2027 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00002028 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002029
2030 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
2031 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2032 ETH_P_IP);
2033 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
2034 case QETH_CAST_MULTICAST:
2035 switch (prot) {
2036#ifdef CONFIG_QETH_IPV6
2037 case __constant_htons(ETH_P_IPV6):
2038 ndisc_mc_map((struct in6_addr *)
2039 skb->data + 24,
2040 tg_addr, card->dev, 0);
2041 break;
2042#endif
2043 case __constant_htons(ETH_P_IP):
2044 ip_hdr = (struct iphdr *)skb->data;
2045 (card->dev->type == ARPHRD_IEEE802_TR) ?
2046 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
2047 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
2048 break;
2049 default:
2050 memcpy(tg_addr, card->dev->broadcast,
2051 card->dev->addr_len);
2052 }
2053 card->stats.multicast++;
2054 skb->pkt_type = PACKET_MULTICAST;
2055 break;
2056 case QETH_CAST_BROADCAST:
2057 memcpy(tg_addr, card->dev->broadcast,
2058 card->dev->addr_len);
2059 card->stats.multicast++;
2060 skb->pkt_type = PACKET_BROADCAST;
2061 break;
2062 case QETH_CAST_UNICAST:
2063 case QETH_CAST_ANYCAST:
2064 case QETH_CAST_NOCAST:
2065 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00002066 if (card->options.sniffer)
2067 skb->pkt_type = PACKET_OTHERHOST;
2068 else
2069 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002070 memcpy(tg_addr, card->dev->dev_addr,
2071 card->dev->addr_len);
2072 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08002073 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2074 card->dev->header_ops->create(skb, card->dev, prot,
2075 tg_addr, &hdr->hdr.l3.dest_addr[2],
2076 card->dev->addr_len);
2077 else
2078 card->dev->header_ops->create(skb, card->dev, prot,
2079 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002080 }
2081
2082#ifdef CONFIG_TR
2083 if (card->dev->type == ARPHRD_IEEE802_TR)
2084 skb->protocol = tr_type_trans(skb, card->dev);
2085 else
2086#endif
2087 skb->protocol = eth_type_trans(skb, card->dev);
2088
2089 if (hdr->hdr.l3.ext_flags &
2090 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00002091 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01002092 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00002093 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002094 }
2095
Ursula Braunb9139802009-05-19 21:38:40 +00002096 switch (card->options.checksum_type) {
2097 case SW_CHECKSUMMING:
2098 skb->ip_summed = CHECKSUM_NONE;
2099 break;
2100 case NO_CHECKSUMMING:
2101 skb->ip_summed = CHECKSUM_UNNECESSARY;
2102 break;
2103 case HW_CHECKSUMMING:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002104 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00002105 (QETH_HDR_EXT_CSUM_HDR_REQ |
2106 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2107 (QETH_HDR_EXT_CSUM_HDR_REQ |
2108 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002109 skb->ip_summed = CHECKSUM_UNNECESSARY;
2110 else
Ursula Braunb9139802009-05-19 21:38:40 +00002111 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002112 }
2113
Ursula Braun10651db2010-10-01 02:51:13 +00002114 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002115}
2116
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002117static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
2118 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002119{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002120 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002121 struct sk_buff *skb;
2122 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002123 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00002124 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002125 unsigned int len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002126
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002127 *done = 0;
2128 BUG_ON(!budget);
2129 while (budget) {
2130 skb = qeth_core_get_next_skb(card,
2131 card->qdio.in_q->bufs[card->rx.b_index].buffer,
2132 &card->rx.b_element, &card->rx.e_offset, &hdr);
2133 if (!skb) {
2134 *done = 1;
2135 break;
2136 }
2137 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002138 switch (hdr->hdr.l3.id) {
2139 case QETH_HEADER_TYPE_LAYER3:
Ursula Braun10651db2010-10-01 02:51:13 +00002140 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
2141 &vlan_tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002142 len = skb->len;
Ursula Braun10651db2010-10-01 02:51:13 +00002143 if (is_vlan && !card->options.sniffer)
2144 vlan_gro_receive(&card->napi, card->vlangrp,
2145 vlan_tag, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002146 else
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002147 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002148 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002149 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2150 skb->pkt_type = PACKET_HOST;
2151 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002152 len = skb->len;
2153 netif_receive_skb(skb);
2154 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002155 default:
2156 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002157 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002158 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002159 continue;
2160 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002161 work_done++;
2162 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002163 card->stats.rx_packets++;
2164 card->stats.rx_bytes += len;
2165 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002166 return work_done;
2167}
2168
2169static int qeth_l3_poll(struct napi_struct *napi, int budget)
2170{
2171 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2172 int work_done = 0;
2173 struct qeth_qdio_buffer *buffer;
2174 int done;
2175 int new_budget = budget;
2176
2177 if (card->options.performance_stats) {
2178 card->perf_stats.inbound_cnt++;
2179 card->perf_stats.inbound_start_time = qeth_get_micros();
2180 }
2181
2182 while (1) {
2183 if (!card->rx.b_count) {
2184 card->rx.qdio_err = 0;
2185 card->rx.b_count = qdio_get_next_buffers(
2186 card->data.ccwdev, 0, &card->rx.b_index,
2187 &card->rx.qdio_err);
2188 if (card->rx.b_count <= 0) {
2189 card->rx.b_count = 0;
2190 break;
2191 }
2192 card->rx.b_element =
2193 &card->qdio.in_q->bufs[card->rx.b_index]
2194 .buffer->element[0];
2195 card->rx.e_offset = 0;
2196 }
2197
2198 while (card->rx.b_count) {
2199 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2200 if (!(card->rx.qdio_err &&
2201 qeth_check_qdio_errors(card, buffer->buffer,
2202 card->rx.qdio_err, "qinerr")))
2203 work_done += qeth_l3_process_inbound_buffer(
2204 card, new_budget, &done);
2205 else
2206 done = 1;
2207
2208 if (done) {
2209 if (card->options.performance_stats)
2210 card->perf_stats.bufs_rec++;
2211 qeth_put_buffer_pool_entry(card,
2212 buffer->pool_entry);
2213 qeth_queue_input_buffer(card, card->rx.b_index);
2214 card->rx.b_count--;
2215 if (card->rx.b_count) {
2216 card->rx.b_index =
2217 (card->rx.b_index + 1) %
2218 QDIO_MAX_BUFFERS_PER_Q;
2219 card->rx.b_element =
2220 &card->qdio.in_q
2221 ->bufs[card->rx.b_index]
2222 .buffer->element[0];
2223 card->rx.e_offset = 0;
2224 }
2225 }
2226
2227 if (work_done >= budget)
2228 goto out;
2229 else
2230 new_budget = budget - work_done;
2231 }
2232 }
2233
2234 napi_complete(napi);
2235 if (qdio_start_irq(card->data.ccwdev, 0))
2236 napi_schedule(&card->napi);
2237out:
2238 if (card->options.performance_stats)
2239 card->perf_stats.inbound_time += qeth_get_micros() -
2240 card->perf_stats.inbound_start_time;
2241 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002242}
2243
2244static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2245 struct qeth_card *card)
2246{
2247 int rc = 0;
2248 struct vlan_group *vg;
2249 int i;
2250
2251 vg = card->vlangrp;
2252 if (!vg)
2253 return rc;
2254
Jesse Grossb7381272010-10-20 13:56:02 +00002255 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002256 if (vlan_group_get_device(vg, i) == dev) {
2257 rc = QETH_VLAN_CARD;
2258 break;
2259 }
2260 }
2261
Heiko Carstens509e2562008-07-26 02:24:10 -07002262 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002263 return 0;
2264
2265 return rc;
2266}
2267
2268static int qeth_l3_verify_dev(struct net_device *dev)
2269{
2270 struct qeth_card *card;
2271 unsigned long flags;
2272 int rc = 0;
2273
2274 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2275 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2276 if (card->dev == dev) {
2277 rc = QETH_REAL_CARD;
2278 break;
2279 }
2280 rc = qeth_l3_verify_vlan_dev(dev, card);
2281 if (rc)
2282 break;
2283 }
2284 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2285
2286 return rc;
2287}
2288
2289static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2290{
2291 struct qeth_card *card = NULL;
2292 int rc;
2293
2294 rc = qeth_l3_verify_dev(dev);
2295 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002296 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002297 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002298 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002299 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002300 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002301 if (card)
2302 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002303 return card ;
2304}
2305
2306static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2307{
2308 int rc = 0;
2309
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002310 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2311 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002312
2313 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002314 if (card->options.sniffer &&
2315 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2316 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002317 if (card->read.state == CH_STATE_UP &&
2318 card->write.state == CH_STATE_UP &&
2319 (card->state == CARD_STATE_UP)) {
2320 if (recovery_mode)
2321 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002322 else {
Ursula Braun869da902010-03-08 20:36:56 +00002323 rtnl_lock();
2324 dev_close(card->dev);
2325 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002326 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002327 if (!card->use_hard_stop) {
2328 rc = qeth_send_stoplan(card);
2329 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002330 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002331 }
2332 card->state = CARD_STATE_SOFTSETUP;
2333 }
2334 if (card->state == CARD_STATE_SOFTSETUP) {
2335 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2336 qeth_clear_ipacmd_list(card);
2337 card->state = CARD_STATE_HARDSETUP;
2338 }
2339 if (card->state == CARD_STATE_HARDSETUP) {
2340 if (!card->use_hard_stop &&
2341 (card->info.type != QETH_CARD_TYPE_IQD)) {
2342 rc = qeth_l3_put_unique_id(card);
2343 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002344 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002345 }
2346 qeth_qdio_clear_card(card, 0);
2347 qeth_clear_qdio_buffers(card);
2348 qeth_clear_working_pool_list(card);
2349 card->state = CARD_STATE_DOWN;
2350 }
2351 if (card->state == CARD_STATE_DOWN) {
2352 qeth_clear_cmd_buffers(&card->read);
2353 qeth_clear_cmd_buffers(&card->write);
2354 }
2355 card->use_hard_stop = 0;
2356 return rc;
2357}
2358
Ursula Braun76b11f82010-01-11 02:50:50 +00002359/*
2360 * test for and Switch promiscuous mode (on or off)
2361 * either for guestlan or HiperSocket Sniffer
2362 */
2363static void
2364qeth_l3_handle_promisc_mode(struct qeth_card *card)
2365{
2366 struct net_device *dev = card->dev;
2367
2368 if (((dev->flags & IFF_PROMISC) &&
2369 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2370 (!(dev->flags & IFF_PROMISC) &&
2371 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2372 return;
2373
2374 if (card->info.guestlan) { /* Guestlan trace */
2375 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2376 qeth_setadp_promisc_mode(card);
2377 } else if (card->options.sniffer && /* HiperSockets trace */
2378 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2379 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002380 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002381 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2382 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002383 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002384 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2385 }
2386 }
2387}
2388
Frank Blaschka4a71df52008-02-15 09:19:42 +01002389static void qeth_l3_set_multicast_list(struct net_device *dev)
2390{
Heiko Carstens509e2562008-07-26 02:24:10 -07002391 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002392
Carsten Otte847a50f2010-06-21 22:57:05 +00002393 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002394 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2395 (card->state != CARD_STATE_UP))
2396 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002397 if (!card->options.sniffer) {
2398 qeth_l3_delete_mc_addresses(card);
2399 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002400#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002401 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002402#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002403 qeth_l3_set_ip_addr_list(card);
2404 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2405 return;
2406 }
2407 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002408}
2409
2410static const char *qeth_l3_arp_get_error_cause(int *rc)
2411{
2412 switch (*rc) {
2413 case QETH_IPA_ARP_RC_FAILED:
2414 *rc = -EIO;
2415 return "operation failed";
2416 case QETH_IPA_ARP_RC_NOTSUPP:
2417 *rc = -EOPNOTSUPP;
2418 return "operation not supported";
2419 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2420 *rc = -EINVAL;
2421 return "argument out of range";
2422 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2423 *rc = -EOPNOTSUPP;
2424 return "query operation not supported";
2425 case QETH_IPA_ARP_RC_Q_NO_DATA:
2426 *rc = -ENOENT;
2427 return "no query data available";
2428 default:
2429 return "unknown error";
2430 }
2431}
2432
2433static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2434{
2435 int tmp;
2436 int rc;
2437
Carsten Otte847a50f2010-06-21 22:57:05 +00002438 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002439
2440 /*
2441 * currently GuestLAN only supports the ARP assist function
2442 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2443 * thus we say EOPNOTSUPP for this ARP function
2444 */
2445 if (card->info.guestlan)
2446 return -EOPNOTSUPP;
2447 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002448 return -EOPNOTSUPP;
2449 }
2450 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2451 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2452 no_entries);
2453 if (rc) {
2454 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002455 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2456 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002457 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2458 }
2459 return rc;
2460}
2461
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002462static __u32 get_arp_entry_size(struct qeth_card *card,
2463 struct qeth_arp_query_data *qdata,
2464 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002465{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002466 __u32 rc;
2467 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002468
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002469 is_hsi = qdata->reply_bits == 5;
2470 if (type->ip == QETHARP_IP_ADDR_V4) {
2471 QETH_CARD_TEXT(card, 4, "arpev4");
2472 if (strip_entries) {
2473 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2474 sizeof(struct qeth_arp_qi_entry7_short);
2475 } else {
2476 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2477 sizeof(struct qeth_arp_qi_entry7);
2478 }
2479 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2480 QETH_CARD_TEXT(card, 4, "arpev6");
2481 if (strip_entries) {
2482 rc = is_hsi ?
2483 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2484 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2485 } else {
2486 rc = is_hsi ?
2487 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2488 sizeof(struct qeth_arp_qi_entry7_ipv6);
2489 }
2490 } else {
2491 QETH_CARD_TEXT(card, 4, "arpinv");
2492 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002493 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002494
2495 return rc;
2496}
2497
2498static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2499{
2500 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2501 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002502}
2503
2504static int qeth_l3_arp_query_cb(struct qeth_card *card,
2505 struct qeth_reply *reply, unsigned long data)
2506{
2507 struct qeth_ipa_cmd *cmd;
2508 struct qeth_arp_query_data *qdata;
2509 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002510 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002511 int e;
2512 int entrybytes_done;
2513 int stripped_bytes;
2514 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002515
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002516 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002517
2518 qinfo = (struct qeth_arp_query_info *) reply->param;
2519 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002520 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002521 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002522 QETH_CARD_TEXT(card, 4, "arpcberr");
2523 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002524 return 0;
2525 }
2526 if (cmd->data.setassparms.hdr.return_code) {
2527 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002528 QETH_CARD_TEXT(card, 4, "setaperr");
2529 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002530 return 0;
2531 }
2532 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002533 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002534
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002535 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2536 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2537 entrybytes_done = 0;
2538 for (e = 0; e < qdata->no_entries; ++e) {
2539 char *cur_entry;
2540 __u32 esize;
2541 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002542
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002543 cur_entry = &qdata->data + entrybytes_done;
2544 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2545 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2546 QETH_CARD_TEXT(card, 4, "pmis");
2547 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2548 break;
2549 }
2550 esize = get_arp_entry_size(card, qdata, etype,
2551 do_strip_entries);
2552 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2553 if (!esize)
2554 break;
2555
2556 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2557 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
2558 cmd->hdr.return_code = -ENOMEM;
2559 goto out_error;
2560 }
2561
2562 memcpy(qinfo->udata + qinfo->udata_offset,
2563 &qdata->data + entrybytes_done + stripped_bytes,
2564 esize);
2565 entrybytes_done += esize + stripped_bytes;
2566 qinfo->udata_offset += esize;
2567 ++qinfo->no_entries;
2568 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002569 /* check if all replies received ... */
2570 if (cmd->data.setassparms.hdr.seq_no <
2571 cmd->data.setassparms.hdr.number_of_replies)
2572 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002573 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002574 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2575 /* keep STRIP_ENTRIES flag so the user program can distinguish
2576 * stripped entries from normal ones */
2577 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2578 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2579 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002580 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002581 return 0;
2582out_error:
2583 i = 0;
2584 memcpy(qinfo->udata, &i, 4);
2585 return 0;
2586}
2587
2588static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2589 struct qeth_cmd_buffer *iob, int len,
2590 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2591 unsigned long),
2592 void *reply_param)
2593{
Carsten Otte847a50f2010-06-21 22:57:05 +00002594 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002595
2596 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2597 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2598 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2599 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2600 reply_cb, reply_param);
2601}
2602
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002603static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2604 enum qeth_prot_versions prot,
2605 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002606{
2607 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002608 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002609 int tmp;
2610 int rc;
2611
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002612 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2613
2614 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2615 IPA_CMD_ASS_ARP_QUERY_INFO,
2616 sizeof(struct qeth_arp_query_data) - sizeof(char),
2617 prot);
2618 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2619 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2620 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2621 cmd->data.setassparms.data.query_arp.no_entries = 0;
2622 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2623 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2624 qeth_l3_arp_query_cb, (void *)qinfo);
2625 if (rc) {
2626 tmp = rc;
2627 QETH_DBF_MESSAGE(2,
2628 "Error while querying ARP cache on %s: %s "
2629 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2630 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2631 }
2632
2633 return rc;
2634}
2635
2636static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2637{
2638 struct qeth_arp_query_info qinfo = {0, };
2639 int rc;
2640
Carsten Otte847a50f2010-06-21 22:57:05 +00002641 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002642
2643 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2644 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002645 QETH_CARD_TEXT(card, 3, "arpqnsup");
2646 rc = -EOPNOTSUPP;
2647 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002648 }
2649 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002650 if (copy_from_user(&qinfo, udata, 6)) {
2651 rc = -EFAULT;
2652 goto out;
2653 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002654 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002655 if (!qinfo.udata) {
2656 rc = -ENOMEM;
2657 goto out;
2658 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002659 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002660 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002661 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002662 if (copy_to_user(udata, qinfo.udata, 4))
2663 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002664 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002665 } else {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002666#ifdef CONFIG_QETH_IPV6
2667 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2668 /* fails in case of GuestLAN QDIO mode */
2669 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2670 &qinfo);
2671 }
2672#endif
2673 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2674 QETH_CARD_TEXT(card, 4, "qactf");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002675 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002676 goto free_and_out;
2677 }
2678 QETH_CARD_TEXT_(card, 4, "qacts");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002679 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002680free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002681 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002682out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002683 return rc;
2684}
2685
2686static int qeth_l3_arp_add_entry(struct qeth_card *card,
2687 struct qeth_arp_cache_entry *entry)
2688{
2689 struct qeth_cmd_buffer *iob;
2690 char buf[16];
2691 int tmp;
2692 int rc;
2693
Carsten Otte847a50f2010-06-21 22:57:05 +00002694 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002695
2696 /*
2697 * currently GuestLAN only supports the ARP assist function
2698 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2699 * thus we say EOPNOTSUPP for this ARP function
2700 */
2701 if (card->info.guestlan)
2702 return -EOPNOTSUPP;
2703 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002704 return -EOPNOTSUPP;
2705 }
2706
2707 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2708 IPA_CMD_ASS_ARP_ADD_ENTRY,
2709 sizeof(struct qeth_arp_cache_entry),
2710 QETH_PROT_IPV4);
2711 rc = qeth_l3_send_setassparms(card, iob,
2712 sizeof(struct qeth_arp_cache_entry),
2713 (unsigned long) entry,
2714 qeth_l3_default_setassparms_cb, NULL);
2715 if (rc) {
2716 tmp = rc;
2717 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002718 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2719 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2720 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002721 }
2722 return rc;
2723}
2724
2725static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2726 struct qeth_arp_cache_entry *entry)
2727{
2728 struct qeth_cmd_buffer *iob;
2729 char buf[16] = {0, };
2730 int tmp;
2731 int rc;
2732
Carsten Otte847a50f2010-06-21 22:57:05 +00002733 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002734
2735 /*
2736 * currently GuestLAN only supports the ARP assist function
2737 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2738 * thus we say EOPNOTSUPP for this ARP function
2739 */
2740 if (card->info.guestlan)
2741 return -EOPNOTSUPP;
2742 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002743 return -EOPNOTSUPP;
2744 }
2745 memcpy(buf, entry, 12);
2746 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2747 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2748 12,
2749 QETH_PROT_IPV4);
2750 rc = qeth_l3_send_setassparms(card, iob,
2751 12, (unsigned long)buf,
2752 qeth_l3_default_setassparms_cb, NULL);
2753 if (rc) {
2754 tmp = rc;
2755 memset(buf, 0, 16);
2756 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002757 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2758 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2759 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002760 }
2761 return rc;
2762}
2763
2764static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2765{
2766 int rc;
2767 int tmp;
2768
Carsten Otte847a50f2010-06-21 22:57:05 +00002769 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002770
2771 /*
2772 * currently GuestLAN only supports the ARP assist function
2773 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2774 * thus we say EOPNOTSUPP for this ARP function
2775 */
2776 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2777 return -EOPNOTSUPP;
2778 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002779 return -EOPNOTSUPP;
2780 }
2781 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2782 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2783 if (rc) {
2784 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002785 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2786 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002787 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2788 }
2789 return rc;
2790}
2791
2792static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2793{
Heiko Carstens509e2562008-07-26 02:24:10 -07002794 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002795 struct qeth_arp_cache_entry arp_entry;
2796 struct mii_ioctl_data *mii_data;
2797 int rc = 0;
2798
2799 if (!card)
2800 return -ENODEV;
2801
2802 if ((card->state != CARD_STATE_UP) &&
2803 (card->state != CARD_STATE_SOFTSETUP))
2804 return -ENODEV;
2805
2806 switch (cmd) {
2807 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2808 if (!capable(CAP_NET_ADMIN)) {
2809 rc = -EPERM;
2810 break;
2811 }
2812 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2813 break;
2814 case SIOC_QETH_ARP_QUERY_INFO:
2815 if (!capable(CAP_NET_ADMIN)) {
2816 rc = -EPERM;
2817 break;
2818 }
2819 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2820 break;
2821 case SIOC_QETH_ARP_ADD_ENTRY:
2822 if (!capable(CAP_NET_ADMIN)) {
2823 rc = -EPERM;
2824 break;
2825 }
2826 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2827 sizeof(struct qeth_arp_cache_entry)))
2828 rc = -EFAULT;
2829 else
2830 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2831 break;
2832 case SIOC_QETH_ARP_REMOVE_ENTRY:
2833 if (!capable(CAP_NET_ADMIN)) {
2834 rc = -EPERM;
2835 break;
2836 }
2837 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2838 sizeof(struct qeth_arp_cache_entry)))
2839 rc = -EFAULT;
2840 else
2841 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2842 break;
2843 case SIOC_QETH_ARP_FLUSH_CACHE:
2844 if (!capable(CAP_NET_ADMIN)) {
2845 rc = -EPERM;
2846 break;
2847 }
2848 rc = qeth_l3_arp_flush_cache(card);
2849 break;
2850 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2851 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2852 break;
2853 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002854 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2855 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002856 !card->info.guestlan)
2857 return 1;
2858 return 0;
2859 break;
2860 case SIOCGMIIPHY:
2861 mii_data = if_mii(rq);
2862 mii_data->phy_id = 0;
2863 break;
2864 case SIOCGMIIREG:
2865 mii_data = if_mii(rq);
2866 if (mii_data->phy_id != 0)
2867 rc = -EINVAL;
2868 else
2869 mii_data->val_out = qeth_mdio_read(dev,
2870 mii_data->phy_id,
2871 mii_data->reg_num);
2872 break;
2873 default:
2874 rc = -EOPNOTSUPP;
2875 }
2876 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002877 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002878 return rc;
2879}
2880
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002881int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2882{
2883 int cast_type = RTN_UNSPEC;
2884
2885 if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2886 cast_type = skb_dst(skb)->neighbour->type;
2887 if ((cast_type == RTN_BROADCAST) ||
2888 (cast_type == RTN_MULTICAST) ||
2889 (cast_type == RTN_ANYCAST))
2890 return cast_type;
2891 else
2892 return RTN_UNSPEC;
2893 }
2894 /* try something else */
2895 if (skb->protocol == ETH_P_IPV6)
2896 return (skb_network_header(skb)[24] == 0xff) ?
2897 RTN_MULTICAST : 0;
2898 else if (skb->protocol == ETH_P_IP)
2899 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2900 RTN_MULTICAST : 0;
2901 /* ... */
2902 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2903 return RTN_BROADCAST;
2904 else {
2905 u16 hdr_mac;
2906
2907 hdr_mac = *((u16 *)skb->data);
2908 /* tr multicast? */
2909 switch (card->info.link_type) {
2910 case QETH_LINK_TYPE_HSTR:
2911 case QETH_LINK_TYPE_LANE_TR:
2912 if ((hdr_mac == QETH_TR_MAC_NC) ||
2913 (hdr_mac == QETH_TR_MAC_C))
2914 return RTN_MULTICAST;
2915 break;
2916 /* eth or so multicast? */
2917 default:
2918 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2919 (hdr_mac == QETH_ETH_MAC_V6))
2920 return RTN_MULTICAST;
2921 }
2922 }
2923 return cast_type;
2924}
2925
Frank Blaschka4a71df52008-02-15 09:19:42 +01002926static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2927 struct sk_buff *skb, int ipv, int cast_type)
2928{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002929 memset(hdr, 0, sizeof(struct qeth_hdr));
2930 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2931 hdr->hdr.l3.ext_flags = 0;
2932
2933 /*
2934 * before we're going to overwrite this location with next hop ip.
2935 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2936 */
2937 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002938 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2939 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2940 else
2941 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002942 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2943 }
2944
2945 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2946 if (ipv == 4) {
2947 /* IPv4 */
2948 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2949 memset(hdr->hdr.l3.dest_addr, 0, 12);
Eric Dumazetadf30902009-06-02 05:19:30 +00002950 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002951 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
Eric Dumazetadf30902009-06-02 05:19:30 +00002952 *((u32 *) skb_dst(skb)->neighbour->primary_key);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002953 } else {
2954 /* fill in destination address used in ip header */
2955 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2956 ip_hdr(skb)->daddr;
2957 }
2958 } else if (ipv == 6) {
2959 /* IPv6 */
2960 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2961 if (card->info.type == QETH_CARD_TYPE_IQD)
2962 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
Eric Dumazetadf30902009-06-02 05:19:30 +00002963 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002964 memcpy(hdr->hdr.l3.dest_addr,
Eric Dumazetadf30902009-06-02 05:19:30 +00002965 skb_dst(skb)->neighbour->primary_key, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002966 } else {
2967 /* fill in destination address used in ip header */
2968 memcpy(hdr->hdr.l3.dest_addr,
2969 &ipv6_hdr(skb)->daddr, 16);
2970 }
2971 } else {
2972 /* passthrough */
2973 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2974 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2975 sizeof(__u16), skb->dev->broadcast, 6)) {
2976 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2977 QETH_HDR_PASSTHRU;
2978 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2979 skb->dev->broadcast, 6)) {
2980 /* broadcast? */
2981 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2982 QETH_HDR_PASSTHRU;
2983 } else {
2984 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2985 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2986 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2987 }
2988 }
2989}
2990
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002991static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2992 struct qeth_hdr *hdr, struct sk_buff *skb)
2993{
2994 struct iphdr *iph = ip_hdr(skb);
2995
2996 /* tcph->check contains already the pseudo hdr checksum
2997 * so just set the header flags
2998 */
2999 if (iph->protocol == IPPROTO_UDP)
3000 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
3001 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ;
3002 if (card->options.performance_stats)
3003 card->perf_stats.tx_csum++;
3004}
3005
Frank Blaschka64ef8952009-03-24 20:57:16 +00003006static void qeth_tso_fill_header(struct qeth_card *card,
3007 struct qeth_hdr *qhdr, struct sk_buff *skb)
3008{
3009 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
3010 struct tcphdr *tcph = tcp_hdr(skb);
3011 struct iphdr *iph = ip_hdr(skb);
3012 struct ipv6hdr *ip6h = ipv6_hdr(skb);
3013
3014 /*fix header to TSO values ...*/
3015 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00003016 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003017 /*set values which are fix for the first approach ...*/
3018 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
3019 hdr->ext.imb_hdr_no = 1;
3020 hdr->ext.hdr_type = 1;
3021 hdr->ext.hdr_version = 1;
3022 hdr->ext.hdr_len = 28;
3023 /*insert non-fix values */
3024 hdr->ext.mss = skb_shinfo(skb)->gso_size;
3025 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
3026 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
3027 sizeof(struct qeth_hdr_tso));
3028 tcph->check = 0;
3029 if (skb->protocol == ETH_P_IPV6) {
3030 ip6h->payload_len = 0;
3031 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
3032 0, IPPROTO_TCP, 0);
3033 } else {
3034 /*OSA want us to set these values ...*/
3035 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
3036 0, IPPROTO_TCP, 0);
3037 iph->tot_len = 0;
3038 iph->check = 0;
3039 }
3040}
3041
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003042static inline int qeth_l3_tso_elements(struct sk_buff *skb)
3043{
3044 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
3045 tcp_hdr(skb)->doff * 4;
3046 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003047 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003048 elements += skb_shinfo(skb)->nr_frags;
3049 return elements;
3050}
3051
Frank Blaschka4a71df52008-02-15 09:19:42 +01003052static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3053{
3054 int rc;
3055 u16 *tag;
3056 struct qeth_hdr *hdr = NULL;
3057 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00003058 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07003059 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003060 struct sk_buff *new_skb = NULL;
3061 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00003062 int cast_type = qeth_l3_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003063 struct qeth_qdio_out_q *queue = card->qdio.out_qs
3064 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
3065 int tx_bytes = skb->len;
3066 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
Frank Blaschka683d7182008-08-01 16:39:13 +02003067 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00003068 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003069
Frank Blaschka21fde742010-03-08 20:36:54 +00003070 if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
3071 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003072 goto tx_drop;
3073
3074 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3075 card->stats.tx_carrier_errors++;
3076 goto tx_drop;
3077 }
3078
3079 if ((cast_type == RTN_BROADCAST) &&
3080 (card->info.broadcast_capable == 0))
3081 goto tx_drop;
3082
3083 if (card->options.performance_stats) {
3084 card->perf_stats.outbound_cnt++;
3085 card->perf_stats.outbound_start_time = qeth_get_micros();
3086 }
3087
Frank Blaschka683d7182008-08-01 16:39:13 +02003088 if (skb_is_gso(skb))
3089 large_send = card->options.large_send;
3090
3091 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
3092 (skb_shinfo(skb)->nr_frags == 0)) {
3093 new_skb = skb;
3094 data_offset = ETH_HLEN;
3095 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
3096 if (!hdr)
3097 goto tx_drop;
3098 elements_needed++;
3099 } else {
3100 /* create a clone with writeable headroom */
3101 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
3102 + VLAN_HLEN);
3103 if (!new_skb)
3104 goto tx_drop;
3105 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003106
3107 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02003108 if (data_offset < 0)
3109 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003110 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00003111 if (ipv == 4) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003112 if (card->dev->type == ARPHRD_IEEE802_TR)
3113 skb_pull(new_skb, TR_HLEN);
3114 else
3115 skb_pull(new_skb, ETH_HLEN);
3116 }
3117
Frank Blaschka21fde742010-03-08 20:36:54 +00003118 if (ipv == 6 && card->vlangrp &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01003119 vlan_tx_tag_present(new_skb)) {
3120 skb_push(new_skb, VLAN_HLEN);
3121 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
3122 skb_copy_to_linear_data_offset(new_skb, 4,
3123 new_skb->data + 8, 4);
3124 skb_copy_to_linear_data_offset(new_skb, 8,
3125 new_skb->data + 12, 4);
3126 tag = (u16 *)(new_skb->data + 12);
3127 *tag = __constant_htons(ETH_P_8021Q);
3128 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02003129 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003130 }
3131 }
3132
3133 netif_stop_queue(dev);
3134
Frank Blaschka4a71df52008-02-15 09:19:42 +01003135 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003136 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003137 */
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003138 if (large_send == QETH_LARGE_SEND_TSO) {
3139 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3140 if (skb_linearize(new_skb))
3141 goto tx_drop;
3142 if (card->options.performance_stats)
3143 card->perf_stats.tx_lin++;
3144 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003145 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003146
3147 if ((large_send == QETH_LARGE_SEND_TSO) &&
3148 (cast_type == RTN_UNSPEC)) {
3149 hdr = (struct qeth_hdr *)skb_push(new_skb,
3150 sizeof(struct qeth_hdr_tso));
3151 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3152 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3153 qeth_tso_fill_header(card, hdr, new_skb);
3154 elements_needed++;
3155 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003156 if (data_offset < 0) {
3157 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003158 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003159 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3160 cast_type);
3161 } else {
3162 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3163 cast_type);
3164 hdr->hdr.l3.length = new_skb->len - data_offset;
3165 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003166
3167 if (skb->ip_summed == CHECKSUM_PARTIAL)
3168 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003169 }
3170
Frank Blaschka64ef8952009-03-24 20:57:16 +00003171 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003172 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003173 if (!elems) {
3174 if (data_offset >= 0)
3175 kmem_cache_free(qeth_core_header_cache, hdr);
3176 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003177 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003178 elements_needed += elems;
3179 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003180
Frank Blaschka51aa1652010-06-21 22:57:10 +00003181 if (card->info.type != QETH_CARD_TYPE_IQD) {
3182 int len;
3183 if (large_send == QETH_LARGE_SEND_TSO)
3184 len = ((unsigned long)tcp_hdr(new_skb) +
3185 tcp_hdr(new_skb)->doff * 4) -
3186 (unsigned long)new_skb->data;
3187 else
3188 len = sizeof(struct qeth_hdr_layer3);
3189
3190 if (qeth_hdr_chk_and_bounce(new_skb, len))
3191 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003192 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003193 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003194 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003195 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003196 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003197
3198 if (!rc) {
3199 card->stats.tx_packets++;
3200 card->stats.tx_bytes += tx_bytes;
3201 if (new_skb != skb)
3202 dev_kfree_skb_any(skb);
3203 if (card->options.performance_stats) {
3204 if (large_send != QETH_LARGE_SEND_NO) {
3205 card->perf_stats.large_send_bytes += tx_bytes;
3206 card->perf_stats.large_send_cnt++;
3207 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003208 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003209 card->perf_stats.sg_skbs_sent++;
3210 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003211 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003212 }
3213 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003214 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003215 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003216 if (data_offset >= 0)
3217 kmem_cache_free(qeth_core_header_cache, hdr);
3218
Frank Blaschka4a71df52008-02-15 09:19:42 +01003219 if (rc == -EBUSY) {
3220 if (new_skb != skb)
3221 dev_kfree_skb_any(new_skb);
3222 return NETDEV_TX_BUSY;
3223 } else
3224 goto tx_drop;
3225 }
3226
3227 netif_wake_queue(dev);
3228 if (card->options.performance_stats)
3229 card->perf_stats.outbound_time += qeth_get_micros() -
3230 card->perf_stats.outbound_start_time;
3231 return rc;
3232
3233tx_drop:
3234 card->stats.tx_dropped++;
3235 card->stats.tx_errors++;
3236 if ((new_skb != skb) && new_skb)
3237 dev_kfree_skb_any(new_skb);
3238 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003239 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003240 return NETDEV_TX_OK;
3241}
3242
3243static int qeth_l3_open(struct net_device *dev)
3244{
Heiko Carstens509e2562008-07-26 02:24:10 -07003245 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003246 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003247
Carsten Otte847a50f2010-06-21 22:57:05 +00003248 QETH_CARD_TEXT(card, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003249 if (card->state != CARD_STATE_SOFTSETUP)
3250 return -ENODEV;
3251 card->data.state = CH_STATE_UP;
3252 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003253 netif_start_queue(dev);
3254
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003255 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3256 napi_enable(&card->napi);
3257 napi_schedule(&card->napi);
3258 } else
3259 rc = -EIO;
3260 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003261}
3262
3263static int qeth_l3_stop(struct net_device *dev)
3264{
Heiko Carstens509e2562008-07-26 02:24:10 -07003265 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003266
Carsten Otte847a50f2010-06-21 22:57:05 +00003267 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003268 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003269 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003270 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003271 napi_disable(&card->napi);
3272 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003273 return 0;
3274}
3275
3276static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
3277{
Heiko Carstens509e2562008-07-26 02:24:10 -07003278 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003279
3280 return (card->options.checksum_type == HW_CHECKSUMMING);
3281}
3282
3283static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
3284{
Heiko Carstens509e2562008-07-26 02:24:10 -07003285 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003286 enum qeth_checksum_types csum_type;
3287
Frank Blaschka4a71df52008-02-15 09:19:42 +01003288 if (data)
3289 csum_type = HW_CHECKSUMMING;
3290 else
3291 csum_type = SW_CHECKSUMMING;
3292
Frank Blaschka3fd434d2009-11-12 00:11:45 +00003293 return qeth_l3_set_rx_csum(card, csum_type);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003294}
3295
3296static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
3297{
Heiko Carstens509e2562008-07-26 02:24:10 -07003298 struct qeth_card *card = dev->ml_priv;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003299 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003300
3301 if (data) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003302 rc = qeth_l3_set_large_send(card, QETH_LARGE_SEND_TSO);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003303 } else {
3304 dev->features &= ~NETIF_F_TSO;
3305 card->options.large_send = QETH_LARGE_SEND_NO;
3306 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003307 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003308}
3309
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003310static int qeth_l3_ethtool_set_tx_csum(struct net_device *dev, u32 data)
3311{
3312 struct qeth_card *card = dev->ml_priv;
3313
3314 if (data) {
3315 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3316 dev->features |= NETIF_F_IP_CSUM;
3317 else
3318 return -EPERM;
3319 } else
3320 dev->features &= ~NETIF_F_IP_CSUM;
3321
3322 return 0;
3323}
3324
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003325static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003326 .get_link = ethtool_op_get_link,
3327 .get_tx_csum = ethtool_op_get_tx_csum,
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003328 .set_tx_csum = qeth_l3_ethtool_set_tx_csum,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003329 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
3330 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
3331 .get_sg = ethtool_op_get_sg,
3332 .set_sg = ethtool_op_set_sg,
3333 .get_tso = ethtool_op_get_tso,
3334 .set_tso = qeth_l3_ethtool_set_tso,
3335 .get_strings = qeth_core_get_strings,
3336 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003337 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003338 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003339 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003340};
3341
3342/*
3343 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3344 * NOARP on the netdevice is no option because it also turns off neighbor
3345 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3346 * arp resolution but we want the hard header (packet socket will work
3347 * e.g. tcpdump)
3348 */
3349static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3350{
3351 n->nud_state = NUD_NOARP;
3352 memcpy(n->ha, "FAKELL", 6);
3353 n->output = n->ops->connected_output;
3354 return 0;
3355}
3356
3357static int
3358qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3359{
3360 if (np->tbl->family == AF_INET)
3361 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3362
3363 return 0;
3364}
3365
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003366static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003367 .ndo_open = qeth_l3_open,
3368 .ndo_stop = qeth_l3_stop,
3369 .ndo_get_stats = qeth_get_stats,
3370 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3371 .ndo_validate_addr = eth_validate_addr,
3372 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3373 .ndo_do_ioctl = qeth_l3_do_ioctl,
3374 .ndo_change_mtu = qeth_change_mtu,
3375 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3376 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3377 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3378 .ndo_tx_timeout = qeth_tx_timeout,
3379};
3380
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003381static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3382 .ndo_open = qeth_l3_open,
3383 .ndo_stop = qeth_l3_stop,
3384 .ndo_get_stats = qeth_get_stats,
3385 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3386 .ndo_validate_addr = eth_validate_addr,
3387 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3388 .ndo_do_ioctl = qeth_l3_do_ioctl,
3389 .ndo_change_mtu = qeth_change_mtu,
3390 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3391 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3392 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3393 .ndo_tx_timeout = qeth_tx_timeout,
3394 .ndo_neigh_setup = qeth_l3_neigh_setup,
3395};
3396
Frank Blaschka4a71df52008-02-15 09:19:42 +01003397static int qeth_l3_setup_netdev(struct qeth_card *card)
3398{
Ursula Braun5113fec2010-05-16 21:15:14 +00003399 if (card->info.type == QETH_CARD_TYPE_OSD ||
3400 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003401 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3402 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3403#ifdef CONFIG_TR
3404 card->dev = alloc_trdev(0);
3405#endif
3406 if (!card->dev)
3407 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003408 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003409 } else {
3410 card->dev = alloc_etherdev(0);
3411 if (!card->dev)
3412 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003413 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003414
3415 /*IPv6 address autoconfiguration stuff*/
3416 qeth_l3_get_unique_id(card);
3417 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3418 card->dev->dev_id = card->info.unique_id &
3419 0xffff;
3420 }
3421 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3422 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3423 if (!card->dev)
3424 return -ENODEV;
3425 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003426 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003427 qeth_l3_iqd_read_initial_mac(card);
3428 } else
3429 return -ENODEV;
3430
Heiko Carstens509e2562008-07-26 02:24:10 -07003431 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003432 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003433 card->dev->mtu = card->info.initial_mtu;
3434 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3435 card->dev->features |= NETIF_F_HW_VLAN_TX |
3436 NETIF_F_HW_VLAN_RX |
3437 NETIF_F_HW_VLAN_FILTER;
Eric Dumazet86d15cd2009-05-30 23:04:46 -07003438 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003439 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003440
3441 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003442 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003443 return register_netdev(card->dev);
3444}
3445
Frank Blaschka4a71df52008-02-15 09:19:42 +01003446static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3447{
3448 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3449
3450 qeth_l3_create_device_attributes(&gdev->dev);
3451 card->options.layer2 = 0;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003452 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003453 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003454 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003455 card->discipline.output_handler = (qdio_handler_t *)
3456 qeth_qdio_output_handler;
3457 card->discipline.recover = qeth_l3_recover;
3458 return 0;
3459}
3460
3461static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3462{
3463 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3464
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003465 qeth_l3_remove_device_attributes(&cgdev->dev);
3466
Ursula Braunf2148562009-05-19 21:38:37 +00003467 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003468 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3469
3470 if (cgdev->state == CCWGROUP_ONLINE) {
3471 card->use_hard_stop = 1;
3472 qeth_l3_set_offline(cgdev);
3473 }
3474
3475 if (card->dev) {
3476 unregister_netdev(card->dev);
3477 card->dev = NULL;
3478 }
3479
Frank Blaschka4a71df52008-02-15 09:19:42 +01003480 qeth_l3_clear_ip_list(card, 0, 0);
3481 qeth_l3_clear_ipato_list(card);
3482 return;
3483}
3484
3485static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3486{
3487 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3488 int rc = 0;
3489 enum qeth_card_states recover_flag;
3490
3491 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003492 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003493 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003494 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3495 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003496
Frank Blaschka4a71df52008-02-15 09:19:42 +01003497 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003498 rc = qeth_core_hardsetup_card(card);
3499 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003500 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003501 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003502 goto out_remove;
3503 }
3504
3505 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3506
Ursula Braunaa909222009-11-12 00:11:43 +00003507 if (!card->dev && qeth_l3_setup_netdev(card)) {
3508 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003509 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003510 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003511
3512 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003513 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003514 qeth_print_status_message(card);
3515
3516 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003517 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003518
3519 rc = qeth_send_startlan(card);
3520 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003521 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003522 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003523 dev_warn(&card->gdev->dev,
3524 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003525 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003526 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003527 }
Ursula Braunaa909222009-11-12 00:11:43 +00003528 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003529 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003530 } else
3531 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003532
Ursula Braun2b6203b2010-11-26 02:41:19 +00003533contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003534 rc = qeth_l3_setadapter_parms(card);
3535 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003536 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003537 if (!card->options.sniffer) {
3538 rc = qeth_l3_start_ipassists(card);
3539 if (rc)
3540 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3541 qeth_l3_set_large_send(card, card->options.large_send);
3542 rc = qeth_l3_setrouting_v4(card);
3543 if (rc)
3544 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3545 rc = qeth_l3_setrouting_v6(card);
3546 if (rc)
3547 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3548 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003549 netif_tx_disable(card->dev);
3550
3551 rc = qeth_init_qdio_queues(card);
3552 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003553 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003554 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003555 goto out_remove;
3556 }
3557 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003558
3559 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003560 qeth_l3_set_ip_addr_list(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003561 if (card->lan_online)
3562 netif_carrier_on(card->dev);
3563 else
3564 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003565 if (recover_flag == CARD_STATE_RECOVER) {
3566 if (recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003567 qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003568 else {
3569 rtnl_lock();
3570 dev_open(card->dev);
3571 rtnl_unlock();
3572 }
3573 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003574 }
3575 /* let user_space know that device is online */
3576 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003577 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003578 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003579 return 0;
3580out_remove:
3581 card->use_hard_stop = 1;
3582 qeth_l3_stop_card(card, 0);
3583 ccw_device_set_offline(CARD_DDEV(card));
3584 ccw_device_set_offline(CARD_WDEV(card));
3585 ccw_device_set_offline(CARD_RDEV(card));
3586 if (recover_flag == CARD_STATE_RECOVER)
3587 card->state = CARD_STATE_RECOVER;
3588 else
3589 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003590 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003591 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003592 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003593}
3594
3595static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3596{
3597 return __qeth_l3_set_online(gdev, 0);
3598}
3599
3600static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3601 int recovery_mode)
3602{
3603 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3604 int rc = 0, rc2 = 0, rc3 = 0;
3605 enum qeth_card_states recover_flag;
3606
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003607 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003608 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003609 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3610 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003611
3612 if (card->dev && netif_carrier_ok(card->dev))
3613 netif_carrier_off(card->dev);
3614 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02003615 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003616 rc = ccw_device_set_offline(CARD_DDEV(card));
3617 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3618 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3619 if (!rc)
3620 rc = (rc2) ? rc2 : rc3;
3621 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003622 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003623 if (recover_flag == CARD_STATE_UP)
3624 card->state = CARD_STATE_RECOVER;
3625 /* let user_space know that device is offline */
3626 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003627 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003628 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003629 return 0;
3630}
3631
3632static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3633{
3634 return __qeth_l3_set_offline(cgdev, 0);
3635}
3636
3637static int qeth_l3_recover(void *ptr)
3638{
3639 struct qeth_card *card;
3640 int rc = 0;
3641
3642 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003643 QETH_CARD_TEXT(card, 2, "recover1");
3644 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003645 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3646 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003647 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003648 dev_warn(&card->gdev->dev,
3649 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003650 card->use_hard_stop = 1;
3651 __qeth_l3_set_offline(card->gdev, 1);
3652 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003653 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003654 dev_info(&card->gdev->dev,
3655 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003656 else {
3657 rtnl_lock();
3658 dev_close(card->dev);
3659 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003660 dev_warn(&card->gdev->dev, "The qeth device driver "
3661 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003662 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003663 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3664 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003665 return 0;
3666}
3667
3668static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3669{
3670 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3671 qeth_l3_clear_ip_list(card, 0, 0);
3672 qeth_qdio_clear_card(card, 0);
3673 qeth_clear_qdio_buffers(card);
3674}
3675
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003676static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3677{
3678 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3679
3680 if (card->dev)
3681 netif_device_detach(card->dev);
3682 qeth_set_allowed_threads(card, 0, 1);
3683 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3684 if (gdev->state == CCWGROUP_OFFLINE)
3685 return 0;
3686 if (card->state == CARD_STATE_UP) {
3687 card->use_hard_stop = 1;
3688 __qeth_l3_set_offline(card->gdev, 1);
3689 } else
3690 __qeth_l3_set_offline(card->gdev, 0);
3691 return 0;
3692}
3693
3694static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3695{
3696 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3697 int rc = 0;
3698
3699 if (gdev->state == CCWGROUP_OFFLINE)
3700 goto out;
3701
3702 if (card->state == CARD_STATE_RECOVER) {
3703 rc = __qeth_l3_set_online(card->gdev, 1);
3704 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003705 rtnl_lock();
3706 dev_close(card->dev);
3707 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003708 }
3709 } else
3710 rc = __qeth_l3_set_online(card->gdev, 0);
3711out:
3712 qeth_set_allowed_threads(card, 0xffffffff, 0);
3713 if (card->dev)
3714 netif_device_attach(card->dev);
3715 if (rc)
3716 dev_warn(&card->gdev->dev, "The qeth device driver "
3717 "failed to recover an error on the device\n");
3718 return rc;
3719}
3720
Frank Blaschka4a71df52008-02-15 09:19:42 +01003721struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3722 .probe = qeth_l3_probe_device,
3723 .remove = qeth_l3_remove_device,
3724 .set_online = qeth_l3_set_online,
3725 .set_offline = qeth_l3_set_offline,
3726 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003727 .freeze = qeth_l3_pm_suspend,
3728 .thaw = qeth_l3_pm_resume,
3729 .restore = qeth_l3_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003730};
3731EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3732
3733static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003734 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003735{
3736 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3737 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3738 struct qeth_ipaddr *addr;
3739 struct qeth_card *card;
3740
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003741 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003742 return NOTIFY_DONE;
3743
Frank Blaschka4a71df52008-02-15 09:19:42 +01003744 card = qeth_l3_get_card_from_dev(dev);
Carsten Otte847a50f2010-06-21 22:57:05 +00003745 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003746 if (!card)
3747 return NOTIFY_DONE;
3748
3749 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3750 if (addr != NULL) {
3751 addr->u.a4.addr = ifa->ifa_address;
3752 addr->u.a4.mask = ifa->ifa_mask;
3753 addr->type = QETH_IP_TYPE_NORMAL;
3754 } else
3755 goto out;
3756
3757 switch (event) {
3758 case NETDEV_UP:
3759 if (!qeth_l3_add_ip(card, addr))
3760 kfree(addr);
3761 break;
3762 case NETDEV_DOWN:
3763 if (!qeth_l3_delete_ip(card, addr))
3764 kfree(addr);
3765 break;
3766 default:
3767 break;
3768 }
3769 qeth_l3_set_ip_addr_list(card);
3770out:
3771 return NOTIFY_DONE;
3772}
3773
3774static struct notifier_block qeth_l3_ip_notifier = {
3775 qeth_l3_ip_event,
3776 NULL,
3777};
3778
3779#ifdef CONFIG_QETH_IPV6
3780/**
3781 * IPv6 event handler
3782 */
3783static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003784 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003785{
3786 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3787 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3788 struct qeth_ipaddr *addr;
3789 struct qeth_card *card;
3790
Frank Blaschka4a71df52008-02-15 09:19:42 +01003791
3792 card = qeth_l3_get_card_from_dev(dev);
3793 if (!card)
3794 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003795 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003796 if (!qeth_is_supported(card, IPA_IPV6))
3797 return NOTIFY_DONE;
3798
3799 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3800 if (addr != NULL) {
3801 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3802 addr->u.a6.pfxlen = ifa->prefix_len;
3803 addr->type = QETH_IP_TYPE_NORMAL;
3804 } else
3805 goto out;
3806
3807 switch (event) {
3808 case NETDEV_UP:
3809 if (!qeth_l3_add_ip(card, addr))
3810 kfree(addr);
3811 break;
3812 case NETDEV_DOWN:
3813 if (!qeth_l3_delete_ip(card, addr))
3814 kfree(addr);
3815 break;
3816 default:
3817 break;
3818 }
3819 qeth_l3_set_ip_addr_list(card);
3820out:
3821 return NOTIFY_DONE;
3822}
3823
3824static struct notifier_block qeth_l3_ip6_notifier = {
3825 qeth_l3_ip6_event,
3826 NULL,
3827};
3828#endif
3829
3830static int qeth_l3_register_notifiers(void)
3831{
3832 int rc;
3833
Carsten Otte847a50f2010-06-21 22:57:05 +00003834 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003835 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3836 if (rc)
3837 return rc;
3838#ifdef CONFIG_QETH_IPV6
3839 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3840 if (rc) {
3841 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3842 return rc;
3843 }
3844#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003845 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003846#endif
3847 return 0;
3848}
3849
3850static void qeth_l3_unregister_notifiers(void)
3851{
3852
Carsten Otte847a50f2010-06-21 22:57:05 +00003853 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003854 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3855#ifdef CONFIG_QETH_IPV6
3856 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3857#endif /* QETH_IPV6 */
3858}
3859
3860static int __init qeth_l3_init(void)
3861{
3862 int rc = 0;
3863
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003864 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003865 rc = qeth_l3_register_notifiers();
3866 return rc;
3867}
3868
3869static void __exit qeth_l3_exit(void)
3870{
3871 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003872 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003873}
3874
3875module_init(qeth_l3_init);
3876module_exit(qeth_l3_exit);
3877MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3878MODULE_DESCRIPTION("qeth layer 3 discipline");
3879MODULE_LICENSE("GPL");