blob: 142e5f6ef4f3ac0c6df656fa7c266b7488c7d1da [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
Ursula Braun70919e22011-02-26 22:41:36 -0800513static void qeth_l3_clear_ip_list(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100514{
515 struct qeth_ipaddr *addr, *tmp;
516 unsigned long flags;
517
Carsten Otte847a50f2010-06-21 22:57:05 +0000518 QETH_CARD_TEXT(card, 4, "clearip");
Ursula Braun76b11f82010-01-11 02:50:50 +0000519 if (recover && card->options.sniffer)
520 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100521 spin_lock_irqsave(&card->ip_lock, flags);
522 /* clear todo list */
523 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
524 list_del(&addr->entry);
525 kfree(addr);
526 }
527
528 while (!list_empty(&card->ip_list)) {
529 addr = list_entry(card->ip_list.next,
530 struct qeth_ipaddr, entry);
531 list_del_init(&addr->entry);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100532 if (!recover || addr->is_multicast) {
533 kfree(addr);
534 continue;
535 }
536 list_add_tail(&addr->entry, card->ip_tbd_list);
537 }
538 spin_unlock_irqrestore(&card->ip_lock, flags);
539}
540
541static int qeth_l3_address_exists_in_list(struct list_head *list,
542 struct qeth_ipaddr *addr, int same_type)
543{
544 struct qeth_ipaddr *tmp;
545
546 list_for_each_entry(tmp, list, entry) {
547 if ((tmp->proto == QETH_PROT_IPV4) &&
548 (addr->proto == QETH_PROT_IPV4) &&
549 ((same_type && (tmp->type == addr->type)) ||
550 (!same_type && (tmp->type != addr->type))) &&
551 (tmp->u.a4.addr == addr->u.a4.addr))
552 return 1;
553
554 if ((tmp->proto == QETH_PROT_IPV6) &&
555 (addr->proto == QETH_PROT_IPV6) &&
556 ((same_type && (tmp->type == addr->type)) ||
557 (!same_type && (tmp->type != addr->type))) &&
558 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
559 sizeof(struct in6_addr)) == 0))
560 return 1;
561
562 }
563 return 0;
564}
565
566static int qeth_l3_send_setdelmc(struct qeth_card *card,
567 struct qeth_ipaddr *addr, int ipacmd)
568{
569 int rc;
570 struct qeth_cmd_buffer *iob;
571 struct qeth_ipa_cmd *cmd;
572
Carsten Otte847a50f2010-06-21 22:57:05 +0000573 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100574
575 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
576 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
577 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
578 if (addr->proto == QETH_PROT_IPV6)
579 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
580 sizeof(struct in6_addr));
581 else
582 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
583
584 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
585
586 return rc;
587}
588
589static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
590{
591 int i, j;
592 for (i = 0; i < 16; i++) {
593 j = (len) - (i * 8);
594 if (j >= 8)
595 netmask[i] = 0xff;
596 else if (j > 0)
597 netmask[i] = (u8)(0xFF00 >> j);
598 else
599 netmask[i] = 0;
600 }
601}
602
603static int qeth_l3_send_setdelip(struct qeth_card *card,
604 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
605{
606 int rc;
607 struct qeth_cmd_buffer *iob;
608 struct qeth_ipa_cmd *cmd;
609 __u8 netmask[16];
610
Carsten Otte847a50f2010-06-21 22:57:05 +0000611 QETH_CARD_TEXT(card, 4, "setdelip");
612 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100613
614 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
615 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
616 if (addr->proto == QETH_PROT_IPV6) {
617 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
618 sizeof(struct in6_addr));
619 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
620 memcpy(cmd->data.setdelip6.mask, netmask,
621 sizeof(struct in6_addr));
622 cmd->data.setdelip6.flags = flags;
623 } else {
624 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
625 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
626 cmd->data.setdelip4.flags = flags;
627 }
628
629 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
630
631 return rc;
632}
633
634static int qeth_l3_send_setrouting(struct qeth_card *card,
635 enum qeth_routing_types type, enum qeth_prot_versions prot)
636{
637 int rc;
638 struct qeth_ipa_cmd *cmd;
639 struct qeth_cmd_buffer *iob;
640
Carsten Otte847a50f2010-06-21 22:57:05 +0000641 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100642 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
643 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
644 cmd->data.setrtg.type = (type);
645 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
646
647 return rc;
648}
649
650static void qeth_l3_correct_routing_type(struct qeth_card *card,
651 enum qeth_routing_types *type, enum qeth_prot_versions prot)
652{
653 if (card->info.type == QETH_CARD_TYPE_IQD) {
654 switch (*type) {
655 case NO_ROUTER:
656 case PRIMARY_CONNECTOR:
657 case SECONDARY_CONNECTOR:
658 case MULTICAST_ROUTER:
659 return;
660 default:
661 goto out_inval;
662 }
663 } else {
664 switch (*type) {
665 case NO_ROUTER:
666 case PRIMARY_ROUTER:
667 case SECONDARY_ROUTER:
668 return;
669 case MULTICAST_ROUTER:
670 if (qeth_is_ipafunc_supported(card, prot,
671 IPA_OSA_MC_ROUTER))
672 return;
673 default:
674 goto out_inval;
675 }
676 }
677out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100678 *type = NO_ROUTER;
679}
680
681int qeth_l3_setrouting_v4(struct qeth_card *card)
682{
683 int rc;
684
Carsten Otte847a50f2010-06-21 22:57:05 +0000685 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100686
687 qeth_l3_correct_routing_type(card, &card->options.route4.type,
688 QETH_PROT_IPV4);
689
690 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
691 QETH_PROT_IPV4);
692 if (rc) {
693 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200694 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
695 " on %s. Type set to 'no router'.\n", rc,
696 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100697 }
698 return rc;
699}
700
701int qeth_l3_setrouting_v6(struct qeth_card *card)
702{
703 int rc = 0;
704
Carsten Otte847a50f2010-06-21 22:57:05 +0000705 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100706#ifdef CONFIG_QETH_IPV6
707
708 if (!qeth_is_supported(card, IPA_IPV6))
709 return 0;
710 qeth_l3_correct_routing_type(card, &card->options.route6.type,
711 QETH_PROT_IPV6);
712
713 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
714 QETH_PROT_IPV6);
715 if (rc) {
716 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200717 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
718 " on %s. Type set to 'no router'.\n", rc,
719 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100720 }
721#endif
722 return rc;
723}
724
725/*
726 * IP address takeover related functions
727 */
728static void qeth_l3_clear_ipato_list(struct qeth_card *card)
729{
730
731 struct qeth_ipato_entry *ipatoe, *tmp;
732 unsigned long flags;
733
734 spin_lock_irqsave(&card->ip_lock, flags);
735 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
736 list_del(&ipatoe->entry);
737 kfree(ipatoe);
738 }
739 spin_unlock_irqrestore(&card->ip_lock, flags);
740}
741
742int qeth_l3_add_ipato_entry(struct qeth_card *card,
743 struct qeth_ipato_entry *new)
744{
745 struct qeth_ipato_entry *ipatoe;
746 unsigned long flags;
747 int rc = 0;
748
Carsten Otte847a50f2010-06-21 22:57:05 +0000749 QETH_CARD_TEXT(card, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100750 spin_lock_irqsave(&card->ip_lock, flags);
751 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
752 if (ipatoe->proto != new->proto)
753 continue;
754 if (!memcmp(ipatoe->addr, new->addr,
755 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
756 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100757 rc = -EEXIST;
758 break;
759 }
760 }
761 if (!rc)
762 list_add_tail(&new->entry, &card->ipato.entries);
763
764 spin_unlock_irqrestore(&card->ip_lock, flags);
765 return rc;
766}
767
768void qeth_l3_del_ipato_entry(struct qeth_card *card,
769 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
770{
771 struct qeth_ipato_entry *ipatoe, *tmp;
772 unsigned long flags;
773
Carsten Otte847a50f2010-06-21 22:57:05 +0000774 QETH_CARD_TEXT(card, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100775 spin_lock_irqsave(&card->ip_lock, flags);
776 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
777 if (ipatoe->proto != proto)
778 continue;
779 if (!memcmp(ipatoe->addr, addr,
780 (proto == QETH_PROT_IPV4)? 4:16) &&
781 (ipatoe->mask_bits == mask_bits)) {
782 list_del(&ipatoe->entry);
783 kfree(ipatoe);
784 }
785 }
786 spin_unlock_irqrestore(&card->ip_lock, flags);
787}
788
789/*
790 * VIPA related functions
791 */
792int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
793 const u8 *addr)
794{
795 struct qeth_ipaddr *ipaddr;
796 unsigned long flags;
797 int rc = 0;
798
799 ipaddr = qeth_l3_get_addr_buffer(proto);
800 if (ipaddr) {
801 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000802 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100803 memcpy(&ipaddr->u.a4.addr, addr, 4);
804 ipaddr->u.a4.mask = 0;
805 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000806 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100807 memcpy(&ipaddr->u.a6.addr, addr, 16);
808 ipaddr->u.a6.pfxlen = 0;
809 }
810 ipaddr->type = QETH_IP_TYPE_VIPA;
811 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
812 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
813 } else
814 return -ENOMEM;
815 spin_lock_irqsave(&card->ip_lock, flags);
816 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
817 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
818 rc = -EEXIST;
819 spin_unlock_irqrestore(&card->ip_lock, flags);
820 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100821 return rc;
822 }
823 if (!qeth_l3_add_ip(card, ipaddr))
824 kfree(ipaddr);
825 qeth_l3_set_ip_addr_list(card);
826 return rc;
827}
828
829void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
830 const u8 *addr)
831{
832 struct qeth_ipaddr *ipaddr;
833
834 ipaddr = qeth_l3_get_addr_buffer(proto);
835 if (ipaddr) {
836 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000837 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 memcpy(&ipaddr->u.a4.addr, addr, 4);
839 ipaddr->u.a4.mask = 0;
840 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000841 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100842 memcpy(&ipaddr->u.a6.addr, addr, 16);
843 ipaddr->u.a6.pfxlen = 0;
844 }
845 ipaddr->type = QETH_IP_TYPE_VIPA;
846 } else
847 return;
848 if (!qeth_l3_delete_ip(card, ipaddr))
849 kfree(ipaddr);
850 qeth_l3_set_ip_addr_list(card);
851}
852
853/*
854 * proxy ARP related functions
855 */
856int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
857 const u8 *addr)
858{
859 struct qeth_ipaddr *ipaddr;
860 unsigned long flags;
861 int rc = 0;
862
863 ipaddr = qeth_l3_get_addr_buffer(proto);
864 if (ipaddr) {
865 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000866 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867 memcpy(&ipaddr->u.a4.addr, addr, 4);
868 ipaddr->u.a4.mask = 0;
869 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000870 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100871 memcpy(&ipaddr->u.a6.addr, addr, 16);
872 ipaddr->u.a6.pfxlen = 0;
873 }
874 ipaddr->type = QETH_IP_TYPE_RXIP;
875 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
876 ipaddr->del_flags = 0;
877 } else
878 return -ENOMEM;
879 spin_lock_irqsave(&card->ip_lock, flags);
880 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
881 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
882 rc = -EEXIST;
883 spin_unlock_irqrestore(&card->ip_lock, flags);
884 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100885 return rc;
886 }
887 if (!qeth_l3_add_ip(card, ipaddr))
888 kfree(ipaddr);
889 qeth_l3_set_ip_addr_list(card);
890 return 0;
891}
892
893void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
894 const u8 *addr)
895{
896 struct qeth_ipaddr *ipaddr;
897
898 ipaddr = qeth_l3_get_addr_buffer(proto);
899 if (ipaddr) {
900 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000901 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100902 memcpy(&ipaddr->u.a4.addr, addr, 4);
903 ipaddr->u.a4.mask = 0;
904 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000905 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100906 memcpy(&ipaddr->u.a6.addr, addr, 16);
907 ipaddr->u.a6.pfxlen = 0;
908 }
909 ipaddr->type = QETH_IP_TYPE_RXIP;
910 } else
911 return;
912 if (!qeth_l3_delete_ip(card, ipaddr))
913 kfree(ipaddr);
914 qeth_l3_set_ip_addr_list(card);
915}
916
917static int qeth_l3_register_addr_entry(struct qeth_card *card,
918 struct qeth_ipaddr *addr)
919{
920 char buf[50];
921 int rc = 0;
922 int cnt = 3;
923
924 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000925 QETH_CARD_TEXT(card, 2, "setaddr4");
926 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000928 QETH_CARD_TEXT(card, 2, "setaddr6");
929 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
930 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100931 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000932 QETH_CARD_TEXT(card, 2, "setaddr?");
933 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100934 }
935 do {
936 if (addr->is_multicast)
937 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
938 else
939 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
940 addr->set_flags);
941 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000942 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100943 } while ((--cnt > 0) && rc);
944 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000945 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100946 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100947 dev_warn(&card->gdev->dev,
948 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949 }
950 return rc;
951}
952
953static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
954 struct qeth_ipaddr *addr)
955{
956 int rc = 0;
957
958 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000959 QETH_CARD_TEXT(card, 2, "deladdr4");
960 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100961 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000962 QETH_CARD_TEXT(card, 2, "deladdr6");
963 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
964 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100965 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000966 QETH_CARD_TEXT(card, 2, "deladdr?");
967 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968 }
969 if (addr->is_multicast)
970 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
971 else
972 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
973 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200974 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000975 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100976
977 return rc;
978}
979
980static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
981{
982 if (cast_type == RTN_MULTICAST)
983 return QETH_CAST_MULTICAST;
984 if (cast_type == RTN_BROADCAST)
985 return QETH_CAST_BROADCAST;
986 return QETH_CAST_UNICAST;
987}
988
989static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
990{
991 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
992 if (cast_type == RTN_MULTICAST)
993 return ct | QETH_CAST_MULTICAST;
994 if (cast_type == RTN_ANYCAST)
995 return ct | QETH_CAST_ANYCAST;
996 if (cast_type == RTN_BROADCAST)
997 return ct | QETH_CAST_BROADCAST;
998 return ct | QETH_CAST_UNICAST;
999}
1000
1001static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
1002 __u32 mode)
1003{
1004 int rc;
1005 struct qeth_cmd_buffer *iob;
1006 struct qeth_ipa_cmd *cmd;
1007
Carsten Otte847a50f2010-06-21 22:57:05 +00001008 QETH_CARD_TEXT(card, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001009
1010 iob = qeth_get_adapter_cmd(card, command,
1011 sizeof(struct qeth_ipacmd_setadpparms));
1012 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1013 cmd->data.setadapterparms.data.mode = mode;
1014 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
1015 NULL);
1016 return rc;
1017}
1018
1019static int qeth_l3_setadapter_hstr(struct qeth_card *card)
1020{
1021 int rc;
1022
Carsten Otte847a50f2010-06-21 22:57:05 +00001023 QETH_CARD_TEXT(card, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001024
1025 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1026 rc = qeth_l3_send_setadp_mode(card,
1027 IPA_SETADP_SET_BROADCAST_MODE,
1028 card->options.broadcast_mode);
1029 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001030 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001031 "device %s: x%x\n",
1032 CARD_BUS_ID(card), rc);
1033 rc = qeth_l3_send_setadp_mode(card,
1034 IPA_SETADP_ALTER_MAC_ADDRESS,
1035 card->options.macaddr_mode);
1036 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001037 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001038 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1039 return rc;
1040 }
1041 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001042 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043 "to set broadcast mode, using ALLRINGS "
1044 "on device %s:\n", CARD_BUS_ID(card));
1045 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001046 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001047 "to set macaddr mode, using NONCANONICAL "
1048 "on device %s:\n", CARD_BUS_ID(card));
1049 return 0;
1050}
1051
1052static int qeth_l3_setadapter_parms(struct qeth_card *card)
1053{
1054 int rc;
1055
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001056 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001057
1058 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001059 dev_info(&card->gdev->dev,
1060 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001061 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001062 return 0;
1063 }
1064 rc = qeth_query_setadapterparms(card);
1065 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001066 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +00001067 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001068 return rc;
1069 }
1070 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1071 rc = qeth_setadpparms_change_macaddr(card);
1072 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001073 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001074 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075 }
1076
1077 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1078 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1079 rc = qeth_l3_setadapter_hstr(card);
1080
1081 return rc;
1082}
1083
1084static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1085 struct qeth_reply *reply, unsigned long data)
1086{
1087 struct qeth_ipa_cmd *cmd;
1088
Carsten Otte847a50f2010-06-21 22:57:05 +00001089 QETH_CARD_TEXT(card, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001090
1091 cmd = (struct qeth_ipa_cmd *) data;
1092 if (cmd->hdr.return_code == 0) {
1093 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1094 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1095 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1096 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1097 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1098 }
1099 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1100 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1101 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001102 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001103 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001104 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1105 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1106 card->info.tx_csum_mask =
1107 cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001108 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001109 }
1110
Frank Blaschka4a71df52008-02-15 09:19:42 +01001111 return 0;
1112}
1113
1114static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1115 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1116 __u16 len, enum qeth_prot_versions prot)
1117{
1118 struct qeth_cmd_buffer *iob;
1119 struct qeth_ipa_cmd *cmd;
1120
Carsten Otte847a50f2010-06-21 22:57:05 +00001121 QETH_CARD_TEXT(card, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001122 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1123
1124 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1125 cmd->data.setassparms.hdr.assist_no = ipa_func;
1126 cmd->data.setassparms.hdr.length = 8 + len;
1127 cmd->data.setassparms.hdr.command_code = cmd_code;
1128 cmd->data.setassparms.hdr.return_code = 0;
1129 cmd->data.setassparms.hdr.seq_no = 0;
1130
1131 return iob;
1132}
1133
1134static int qeth_l3_send_setassparms(struct qeth_card *card,
1135 struct qeth_cmd_buffer *iob, __u16 len, long data,
1136 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1137 unsigned long),
1138 void *reply_param)
1139{
1140 int rc;
1141 struct qeth_ipa_cmd *cmd;
1142
Carsten Otte847a50f2010-06-21 22:57:05 +00001143 QETH_CARD_TEXT(card, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001144
1145 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1146 if (len <= sizeof(__u32))
1147 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1148 else /* (len > sizeof(__u32)) */
1149 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1150
1151 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1152 return rc;
1153}
1154
1155#ifdef CONFIG_QETH_IPV6
1156static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1157 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1158{
1159 int rc;
1160 struct qeth_cmd_buffer *iob;
1161
Carsten Otte847a50f2010-06-21 22:57:05 +00001162 QETH_CARD_TEXT(card, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001163 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1164 0, QETH_PROT_IPV6);
1165 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1166 qeth_l3_default_setassparms_cb, NULL);
1167 return rc;
1168}
1169#endif
1170
1171static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1172 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1173{
1174 int rc;
1175 int length = 0;
1176 struct qeth_cmd_buffer *iob;
1177
Carsten Otte847a50f2010-06-21 22:57:05 +00001178 QETH_CARD_TEXT(card, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001179 if (data)
1180 length = sizeof(__u32);
1181 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1182 length, QETH_PROT_IPV4);
1183 rc = qeth_l3_send_setassparms(card, iob, length, data,
1184 qeth_l3_default_setassparms_cb, NULL);
1185 return rc;
1186}
1187
1188static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1189{
1190 int rc;
1191
Carsten Otte847a50f2010-06-21 22:57:05 +00001192 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001193
1194 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001195 dev_info(&card->gdev->dev,
1196 "ARP processing not supported on %s!\n",
1197 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001198 return 0;
1199 }
1200 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1201 IPA_CMD_ASS_START, 0);
1202 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001203 dev_warn(&card->gdev->dev,
1204 "Starting ARP processing support for %s failed\n",
1205 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001206 }
1207 return rc;
1208}
1209
1210static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1211{
1212 int rc;
1213
Carsten Otte847a50f2010-06-21 22:57:05 +00001214 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001215
1216 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001217 dev_info(&card->gdev->dev,
1218 "Hardware IP fragmentation not supported on %s\n",
1219 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001220 return -EOPNOTSUPP;
1221 }
1222
1223 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1224 IPA_CMD_ASS_START, 0);
1225 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001226 dev_warn(&card->gdev->dev,
1227 "Starting IP fragmentation support for %s failed\n",
1228 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001229 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001230 dev_info(&card->gdev->dev,
1231 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001232 return rc;
1233}
1234
1235static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1236{
1237 int rc;
1238
Carsten Otte847a50f2010-06-21 22:57:05 +00001239 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001240
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001242 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001243 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001244 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001245 return -EOPNOTSUPP;
1246 }
1247
1248 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1249 IPA_CMD_ASS_START, 0);
1250 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001251 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001252 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001253 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001254 return rc;
1255}
1256
1257static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1258{
1259 int rc = 0;
1260
Carsten Otte847a50f2010-06-21 22:57:05 +00001261 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262
1263 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001264 dev_info(&card->gdev->dev,
1265 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001266 return -EOPNOTSUPP;
1267 }
1268
1269 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1270 IPA_CMD_ASS_START, 0);
1271 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001272 dev_warn(&card->gdev->dev,
1273 "Starting VLAN support for %s failed\n",
1274 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001276 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001277 }
1278 return rc;
1279}
1280
1281static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1282{
1283 int rc;
1284
Carsten Otte847a50f2010-06-21 22:57:05 +00001285 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001286
1287 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001288 dev_info(&card->gdev->dev,
1289 "Multicast not supported on %s\n",
1290 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001291 return -EOPNOTSUPP;
1292 }
1293
1294 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1295 IPA_CMD_ASS_START, 0);
1296 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001297 dev_warn(&card->gdev->dev,
1298 "Starting multicast support for %s failed\n",
1299 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001300 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001301 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001302 card->dev->flags |= IFF_MULTICAST;
1303 }
1304 return rc;
1305}
1306
1307static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1308 struct qeth_reply *reply, unsigned long data)
1309{
1310 struct qeth_ipa_cmd *cmd;
1311
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001312 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001313
1314 cmd = (struct qeth_ipa_cmd *) data;
1315 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1316 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1317 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1318 } else {
1319 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1320 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1321 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001322 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1323 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1324 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001325 return 0;
1326}
1327
1328static int qeth_l3_query_ipassists(struct qeth_card *card,
1329 enum qeth_prot_versions prot)
1330{
1331 int rc;
1332 struct qeth_cmd_buffer *iob;
1333
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001334 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1336 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1337 return rc;
1338}
1339
1340#ifdef CONFIG_QETH_IPV6
1341static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1342{
1343 int rc;
1344
Carsten Otte847a50f2010-06-21 22:57:05 +00001345 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001346
1347 if (card->info.type == QETH_CARD_TYPE_IQD)
1348 goto out;
1349
1350 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1351 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001352 dev_err(&card->gdev->dev,
1353 "Activating IPv6 support for %s failed\n",
1354 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001355 return rc;
1356 }
1357 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1358 IPA_CMD_ASS_START, 3);
1359 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001360 dev_err(&card->gdev->dev,
1361 "Activating IPv6 support for %s failed\n",
1362 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001363 return rc;
1364 }
1365 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1366 IPA_CMD_ASS_START);
1367 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001368 dev_err(&card->gdev->dev,
1369 "Activating IPv6 support for %s failed\n",
1370 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001371 return rc;
1372 }
1373 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1374 IPA_CMD_ASS_START);
1375 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001376 dev_warn(&card->gdev->dev,
1377 "Enabling the passthrough mode for %s failed\n",
1378 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001379 return rc;
1380 }
1381out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001382 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001383 return 0;
1384}
1385#endif
1386
1387static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1388{
1389 int rc = 0;
1390
Carsten Otte847a50f2010-06-21 22:57:05 +00001391 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001392
1393 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001394 dev_info(&card->gdev->dev,
1395 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001396 return 0;
1397 }
1398#ifdef CONFIG_QETH_IPV6
1399 rc = qeth_l3_softsetup_ipv6(card);
1400#endif
1401 return rc ;
1402}
1403
1404static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1405{
1406 int rc;
1407
Carsten Otte847a50f2010-06-21 22:57:05 +00001408 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001409 card->info.broadcast_capable = 0;
1410 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001411 dev_info(&card->gdev->dev,
1412 "Broadcast not supported on %s\n",
1413 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001414 rc = -EOPNOTSUPP;
1415 goto out;
1416 }
1417 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1418 IPA_CMD_ASS_START, 0);
1419 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001420 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1421 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001422 goto out;
1423 }
1424
1425 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1426 IPA_CMD_ASS_CONFIGURE, 1);
1427 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001428 dev_warn(&card->gdev->dev,
1429 "Setting up broadcast filtering for %s failed\n",
1430 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001431 goto out;
1432 }
1433 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001434 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001435 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1436 IPA_CMD_ASS_ENABLE, 1);
1437 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001438 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1439 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001440 goto out;
1441 }
1442 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1443out:
1444 if (card->info.broadcast_capable)
1445 card->dev->flags |= IFF_BROADCAST;
1446 else
1447 card->dev->flags &= ~IFF_BROADCAST;
1448 return rc;
1449}
1450
1451static int qeth_l3_send_checksum_command(struct qeth_card *card)
1452{
1453 int rc;
1454
1455 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1456 IPA_CMD_ASS_START, 0);
1457 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001458 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1459 "failed, using SW checksumming\n",
1460 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001461 return rc;
1462 }
1463 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1464 IPA_CMD_ASS_ENABLE,
1465 card->info.csum_mask);
1466 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001467 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1468 "failed, using SW checksumming\n",
1469 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001470 return rc;
1471 }
1472 return 0;
1473}
1474
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001475int qeth_l3_set_rx_csum(struct qeth_card *card,
1476 enum qeth_checksum_types csum_type)
1477{
1478 int rc = 0;
1479
1480 if (card->options.checksum_type == HW_CHECKSUMMING) {
1481 if ((csum_type != HW_CHECKSUMMING) &&
1482 (card->state != CARD_STATE_DOWN)) {
1483 rc = qeth_l3_send_simple_setassparms(card,
1484 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1485 if (rc)
1486 return -EIO;
1487 }
1488 } else {
1489 if (csum_type == HW_CHECKSUMMING) {
1490 if (card->state != CARD_STATE_DOWN) {
1491 if (!qeth_is_supported(card,
1492 IPA_INBOUND_CHECKSUM))
1493 return -EPERM;
1494 rc = qeth_l3_send_checksum_command(card);
1495 if (rc)
1496 return -EIO;
1497 }
1498 }
1499 }
1500 card->options.checksum_type = csum_type;
1501 return rc;
1502}
1503
Frank Blaschka4a71df52008-02-15 09:19:42 +01001504static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1505{
1506 int rc = 0;
1507
Carsten Otte847a50f2010-06-21 22:57:05 +00001508 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001509
1510 if (card->options.checksum_type == NO_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001511 dev_info(&card->gdev->dev,
1512 "Using no checksumming on %s.\n",
1513 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001514 return 0;
1515 }
1516 if (card->options.checksum_type == SW_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001517 dev_info(&card->gdev->dev,
1518 "Using SW checksumming on %s.\n",
1519 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001520 return 0;
1521 }
1522 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001523 dev_info(&card->gdev->dev,
1524 "Inbound HW Checksumming not "
1525 "supported on %s,\ncontinuing "
1526 "using Inbound SW Checksumming\n",
1527 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001528 card->options.checksum_type = SW_CHECKSUMMING;
1529 return 0;
1530 }
1531 rc = qeth_l3_send_checksum_command(card);
1532 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001533 dev_info(&card->gdev->dev,
1534 "HW Checksumming (inbound) enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001535
1536 return rc;
1537}
1538
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001539static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1540{
1541 int rc = 0;
1542
1543 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1544 return rc;
1545 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1546 IPA_CMD_ASS_START, 0);
1547 if (rc)
1548 goto err_out;
1549 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1550 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1551 if (rc)
1552 goto err_out;
1553 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1554 return rc;
1555err_out:
1556 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1557 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1558 return rc;
1559}
1560
Frank Blaschka4a71df52008-02-15 09:19:42 +01001561static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1562{
1563 int rc;
1564
Carsten Otte847a50f2010-06-21 22:57:05 +00001565 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001566
1567 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001568 dev_info(&card->gdev->dev,
1569 "Outbound TSO not supported on %s\n",
1570 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001571 rc = -EOPNOTSUPP;
1572 } else {
1573 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1574 IPA_CMD_ASS_START, 0);
1575 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001576 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1577 "segmentation offload for %s failed\n",
1578 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001579 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001580 dev_info(&card->gdev->dev,
1581 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001582 }
1583 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1584 card->options.large_send = QETH_LARGE_SEND_NO;
1585 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1586 }
1587 return rc;
1588}
1589
1590static int qeth_l3_start_ipassists(struct qeth_card *card)
1591{
Carsten Otte847a50f2010-06-21 22:57:05 +00001592 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001593
1594 qeth_set_access_ctrl_online(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001595 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1596 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1597 qeth_l3_start_ipa_source_mac(card); /* go on*/
1598 qeth_l3_start_ipa_vlan(card); /* go on*/
1599 qeth_l3_start_ipa_multicast(card); /* go on*/
1600 qeth_l3_start_ipa_ipv6(card); /* go on*/
1601 qeth_l3_start_ipa_broadcast(card); /* go on*/
1602 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001603 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001604 qeth_l3_start_ipa_tso(card); /* go on*/
1605 return 0;
1606}
1607
Frank Blaschka4a71df52008-02-15 09:19:42 +01001608static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1609 struct qeth_reply *reply, unsigned long data)
1610{
1611 struct qeth_ipa_cmd *cmd;
1612
1613 cmd = (struct qeth_ipa_cmd *) data;
1614 if (cmd->hdr.return_code == 0)
1615 memcpy(card->dev->dev_addr,
1616 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1617 else
1618 random_ether_addr(card->dev->dev_addr);
1619
1620 return 0;
1621}
1622
1623static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1624{
1625 int rc = 0;
1626 struct qeth_cmd_buffer *iob;
1627 struct qeth_ipa_cmd *cmd;
1628
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001629 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001630
1631 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1632 QETH_PROT_IPV6);
1633 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1634 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1635 card->info.unique_id;
1636
1637 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1638 NULL);
1639 return rc;
1640}
1641
1642static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1643 struct qeth_reply *reply, unsigned long data)
1644{
1645 struct qeth_ipa_cmd *cmd;
1646
1647 cmd = (struct qeth_ipa_cmd *) data;
1648 if (cmd->hdr.return_code == 0)
1649 card->info.unique_id = *((__u16 *)
1650 &cmd->data.create_destroy_addr.unique_id[6]);
1651 else {
1652 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1653 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001654 dev_warn(&card->gdev->dev, "The network adapter failed to "
1655 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001656 }
1657 return 0;
1658}
1659
1660static int qeth_l3_get_unique_id(struct qeth_card *card)
1661{
1662 int rc = 0;
1663 struct qeth_cmd_buffer *iob;
1664 struct qeth_ipa_cmd *cmd;
1665
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001666 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001667
1668 if (!qeth_is_supported(card, IPA_IPV6)) {
1669 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1670 UNIQUE_ID_NOT_BY_CARD;
1671 return 0;
1672 }
1673
1674 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1675 QETH_PROT_IPV6);
1676 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1677 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1678 card->info.unique_id;
1679
1680 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1681 return rc;
1682}
1683
Ursula Braun76b11f82010-01-11 02:50:50 +00001684static int
1685qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1686 unsigned long data)
1687{
1688 struct qeth_ipa_cmd *cmd;
1689 __u16 rc;
1690
1691 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1692
1693 cmd = (struct qeth_ipa_cmd *)data;
1694 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001695 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001696 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001697 switch (cmd->data.diagass.action) {
1698 case QETH_DIAGS_CMD_TRACE_QUERY:
1699 break;
1700 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001701 switch (rc) {
1702 case 0:
1703 case IPA_RC_INVALID_SUBCMD:
1704 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1705 dev_info(&card->gdev->dev, "The HiperSockets network "
1706 "traffic analyzer is deactivated\n");
1707 break;
1708 default:
1709 break;
1710 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001711 break;
1712 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001713 switch (rc) {
1714 case 0:
1715 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1716 dev_info(&card->gdev->dev, "The HiperSockets network "
1717 "traffic analyzer is activated\n");
1718 break;
1719 case IPA_RC_HARDWARE_AUTH_ERROR:
1720 dev_warn(&card->gdev->dev, "The device is not "
1721 "authorized to run as a HiperSockets network "
1722 "traffic analyzer\n");
1723 break;
1724 case IPA_RC_TRACE_ALREADY_ACTIVE:
1725 dev_warn(&card->gdev->dev, "A HiperSockets "
1726 "network traffic analyzer is already "
1727 "active in the HiperSockets LAN\n");
1728 break;
1729 default:
1730 break;
1731 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001732 break;
1733 default:
1734 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1735 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1736 }
1737
1738 return 0;
1739}
1740
1741static int
1742qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1743{
1744 struct qeth_cmd_buffer *iob;
1745 struct qeth_ipa_cmd *cmd;
1746
1747 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1748
1749 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1750 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1751 cmd->data.diagass.subcmd_len = 16;
1752 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1753 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1754 cmd->data.diagass.action = diags_cmd;
1755 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1756}
1757
Frank Blaschka4a71df52008-02-15 09:19:42 +01001758static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1759 struct net_device *dev)
1760{
1761 if (dev->type == ARPHRD_IEEE802_TR)
1762 ip_tr_mc_map(ipm, mac);
1763 else
1764 ip_eth_mc_map(ipm, mac);
1765}
1766
1767static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1768{
1769 struct qeth_ipaddr *ipm;
1770 struct ip_mc_list *im4;
1771 char buf[MAX_ADDR_LEN];
1772
Carsten Otte847a50f2010-06-21 22:57:05 +00001773 QETH_CARD_TEXT(card, 4, "addmc");
Sachin Santf3aa3132010-11-26 02:41:17 +00001774 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1775 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001776 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1777 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1778 if (!ipm)
1779 continue;
1780 ipm->u.a4.addr = im4->multiaddr;
1781 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1782 ipm->is_multicast = 1;
1783 if (!qeth_l3_add_ip(card, ipm))
1784 kfree(ipm);
1785 }
1786}
1787
1788static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1789{
1790 struct in_device *in_dev;
1791 struct vlan_group *vg;
1792 int i;
1793
Carsten Otte847a50f2010-06-21 22:57:05 +00001794 QETH_CARD_TEXT(card, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001795 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1796 return;
1797
1798 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001799 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001800 struct net_device *netdev = vlan_group_get_device(vg, i);
1801 if (netdev == NULL ||
1802 !(netdev->flags & IFF_UP))
1803 continue;
1804 in_dev = in_dev_get(netdev);
1805 if (!in_dev)
1806 continue;
Sachin Santf3aa3132010-11-26 02:41:17 +00001807 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001808 qeth_l3_add_mc(card, in_dev);
Sachin Santf3aa3132010-11-26 02:41:17 +00001809 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001810 in_dev_put(in_dev);
1811 }
1812}
1813
1814static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1815{
1816 struct in_device *in4_dev;
1817
Carsten Otte847a50f2010-06-21 22:57:05 +00001818 QETH_CARD_TEXT(card, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001819 in4_dev = in_dev_get(card->dev);
1820 if (in4_dev == NULL)
1821 return;
Sachin Santf3aa3132010-11-26 02:41:17 +00001822 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001823 qeth_l3_add_mc(card, in4_dev);
1824 qeth_l3_add_vlan_mc(card);
Sachin Santf3aa3132010-11-26 02:41:17 +00001825 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001826 in_dev_put(in4_dev);
1827}
1828
1829#ifdef CONFIG_QETH_IPV6
1830static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1831{
1832 struct qeth_ipaddr *ipm;
1833 struct ifmcaddr6 *im6;
1834 char buf[MAX_ADDR_LEN];
1835
Carsten Otte847a50f2010-06-21 22:57:05 +00001836 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001837 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1838 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1839 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1840 if (!ipm)
1841 continue;
1842 ipm->is_multicast = 1;
1843 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1844 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1845 sizeof(struct in6_addr));
1846 if (!qeth_l3_add_ip(card, ipm))
1847 kfree(ipm);
1848 }
1849}
1850
1851static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1852{
1853 struct inet6_dev *in_dev;
1854 struct vlan_group *vg;
1855 int i;
1856
Carsten Otte847a50f2010-06-21 22:57:05 +00001857 QETH_CARD_TEXT(card, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001858 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1859 return;
1860
1861 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001862 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001863 struct net_device *netdev = vlan_group_get_device(vg, i);
1864 if (netdev == NULL ||
1865 !(netdev->flags & IFF_UP))
1866 continue;
1867 in_dev = in6_dev_get(netdev);
1868 if (!in_dev)
1869 continue;
1870 read_lock_bh(&in_dev->lock);
1871 qeth_l3_add_mc6(card, in_dev);
1872 read_unlock_bh(&in_dev->lock);
1873 in6_dev_put(in_dev);
1874 }
1875}
1876
1877static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1878{
1879 struct inet6_dev *in6_dev;
1880
Carsten Otte847a50f2010-06-21 22:57:05 +00001881 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001882 if (!qeth_is_supported(card, IPA_IPV6))
1883 return ;
1884 in6_dev = in6_dev_get(card->dev);
1885 if (in6_dev == NULL)
1886 return;
1887 read_lock_bh(&in6_dev->lock);
1888 qeth_l3_add_mc6(card, in6_dev);
1889 qeth_l3_add_vlan_mc6(card);
1890 read_unlock_bh(&in6_dev->lock);
1891 in6_dev_put(in6_dev);
1892}
1893#endif /* CONFIG_QETH_IPV6 */
1894
1895static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1896 unsigned short vid)
1897{
1898 struct in_device *in_dev;
1899 struct in_ifaddr *ifa;
1900 struct qeth_ipaddr *addr;
1901
Carsten Otte847a50f2010-06-21 22:57:05 +00001902 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001903
1904 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1905 if (!in_dev)
1906 return;
1907 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1908 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1909 if (addr) {
1910 addr->u.a4.addr = ifa->ifa_address;
1911 addr->u.a4.mask = ifa->ifa_mask;
1912 addr->type = QETH_IP_TYPE_NORMAL;
1913 if (!qeth_l3_delete_ip(card, addr))
1914 kfree(addr);
1915 }
1916 }
1917 in_dev_put(in_dev);
1918}
1919
1920static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1921 unsigned short vid)
1922{
1923#ifdef CONFIG_QETH_IPV6
1924 struct inet6_dev *in6_dev;
1925 struct inet6_ifaddr *ifa;
1926 struct qeth_ipaddr *addr;
1927
Carsten Otte847a50f2010-06-21 22:57:05 +00001928 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001929
1930 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1931 if (!in6_dev)
1932 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001933 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001934 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1935 if (addr) {
1936 memcpy(&addr->u.a6.addr, &ifa->addr,
1937 sizeof(struct in6_addr));
1938 addr->u.a6.pfxlen = ifa->prefix_len;
1939 addr->type = QETH_IP_TYPE_NORMAL;
1940 if (!qeth_l3_delete_ip(card, addr))
1941 kfree(addr);
1942 }
1943 }
1944 in6_dev_put(in6_dev);
1945#endif /* CONFIG_QETH_IPV6 */
1946}
1947
1948static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1949 unsigned short vid)
1950{
1951 if (!card->vlangrp)
1952 return;
1953 qeth_l3_free_vlan_addresses4(card, vid);
1954 qeth_l3_free_vlan_addresses6(card, vid);
1955}
1956
1957static void qeth_l3_vlan_rx_register(struct net_device *dev,
1958 struct vlan_group *grp)
1959{
Heiko Carstens509e2562008-07-26 02:24:10 -07001960 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001961 unsigned long flags;
1962
Carsten Otte847a50f2010-06-21 22:57:05 +00001963 QETH_CARD_TEXT(card, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001964 spin_lock_irqsave(&card->vlanlock, flags);
1965 card->vlangrp = grp;
1966 spin_unlock_irqrestore(&card->vlanlock, flags);
1967}
1968
1969static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1970{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001971 return;
1972}
1973
1974static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1975{
Heiko Carstens509e2562008-07-26 02:24:10 -07001976 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001977 unsigned long flags;
1978
Carsten Otte847a50f2010-06-21 22:57:05 +00001979 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00001980 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001981 QETH_CARD_TEXT(card, 3, "kidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001982 return;
1983 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001984 spin_lock_irqsave(&card->vlanlock, flags);
1985 /* unregister IP addresses of vlan device */
1986 qeth_l3_free_vlan_addresses(card, vid);
1987 vlan_group_set_device(card->vlangrp, vid, NULL);
1988 spin_unlock_irqrestore(&card->vlanlock, flags);
1989 qeth_l3_set_multicast_list(card->dev);
1990}
1991
Ursula Braun10651db2010-10-01 02:51:13 +00001992static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1993 struct sk_buff *skb, struct qeth_hdr *hdr,
1994 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001995{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001996 __be16 prot;
1997 struct iphdr *ip_hdr;
1998 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001999 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002000
2001 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
2002 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2003 ETH_P_IP);
2004 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
2005 case QETH_CAST_MULTICAST:
2006 switch (prot) {
2007#ifdef CONFIG_QETH_IPV6
2008 case __constant_htons(ETH_P_IPV6):
2009 ndisc_mc_map((struct in6_addr *)
2010 skb->data + 24,
2011 tg_addr, card->dev, 0);
2012 break;
2013#endif
2014 case __constant_htons(ETH_P_IP):
2015 ip_hdr = (struct iphdr *)skb->data;
2016 (card->dev->type == ARPHRD_IEEE802_TR) ?
2017 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
2018 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
2019 break;
2020 default:
2021 memcpy(tg_addr, card->dev->broadcast,
2022 card->dev->addr_len);
2023 }
2024 card->stats.multicast++;
2025 skb->pkt_type = PACKET_MULTICAST;
2026 break;
2027 case QETH_CAST_BROADCAST:
2028 memcpy(tg_addr, card->dev->broadcast,
2029 card->dev->addr_len);
2030 card->stats.multicast++;
2031 skb->pkt_type = PACKET_BROADCAST;
2032 break;
2033 case QETH_CAST_UNICAST:
2034 case QETH_CAST_ANYCAST:
2035 case QETH_CAST_NOCAST:
2036 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00002037 if (card->options.sniffer)
2038 skb->pkt_type = PACKET_OTHERHOST;
2039 else
2040 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002041 memcpy(tg_addr, card->dev->dev_addr,
2042 card->dev->addr_len);
2043 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08002044 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2045 card->dev->header_ops->create(skb, card->dev, prot,
2046 tg_addr, &hdr->hdr.l3.dest_addr[2],
2047 card->dev->addr_len);
2048 else
2049 card->dev->header_ops->create(skb, card->dev, prot,
2050 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002051 }
2052
2053#ifdef CONFIG_TR
2054 if (card->dev->type == ARPHRD_IEEE802_TR)
2055 skb->protocol = tr_type_trans(skb, card->dev);
2056 else
2057#endif
2058 skb->protocol = eth_type_trans(skb, card->dev);
2059
2060 if (hdr->hdr.l3.ext_flags &
2061 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00002062 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01002063 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00002064 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002065 }
2066
Ursula Braunb9139802009-05-19 21:38:40 +00002067 switch (card->options.checksum_type) {
2068 case SW_CHECKSUMMING:
2069 skb->ip_summed = CHECKSUM_NONE;
2070 break;
2071 case NO_CHECKSUMMING:
2072 skb->ip_summed = CHECKSUM_UNNECESSARY;
2073 break;
2074 case HW_CHECKSUMMING:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002075 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00002076 (QETH_HDR_EXT_CSUM_HDR_REQ |
2077 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2078 (QETH_HDR_EXT_CSUM_HDR_REQ |
2079 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002080 skb->ip_summed = CHECKSUM_UNNECESSARY;
2081 else
Ursula Braunb9139802009-05-19 21:38:40 +00002082 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002083 }
2084
Ursula Braun10651db2010-10-01 02:51:13 +00002085 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002086}
2087
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002088static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
2089 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002090{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002091 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002092 struct sk_buff *skb;
2093 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002094 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00002095 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002096 unsigned int len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002097
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002098 *done = 0;
2099 BUG_ON(!budget);
2100 while (budget) {
2101 skb = qeth_core_get_next_skb(card,
2102 card->qdio.in_q->bufs[card->rx.b_index].buffer,
2103 &card->rx.b_element, &card->rx.e_offset, &hdr);
2104 if (!skb) {
2105 *done = 1;
2106 break;
2107 }
2108 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002109 switch (hdr->hdr.l3.id) {
2110 case QETH_HEADER_TYPE_LAYER3:
Ursula Braun10651db2010-10-01 02:51:13 +00002111 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
2112 &vlan_tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002113 len = skb->len;
Ursula Braun10651db2010-10-01 02:51:13 +00002114 if (is_vlan && !card->options.sniffer)
2115 vlan_gro_receive(&card->napi, card->vlangrp,
2116 vlan_tag, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002117 else
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002118 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002119 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002120 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2121 skb->pkt_type = PACKET_HOST;
2122 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002123 len = skb->len;
2124 netif_receive_skb(skb);
2125 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002126 default:
2127 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002128 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002129 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002130 continue;
2131 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002132 work_done++;
2133 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002134 card->stats.rx_packets++;
2135 card->stats.rx_bytes += len;
2136 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002137 return work_done;
2138}
2139
2140static int qeth_l3_poll(struct napi_struct *napi, int budget)
2141{
2142 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2143 int work_done = 0;
2144 struct qeth_qdio_buffer *buffer;
2145 int done;
2146 int new_budget = budget;
2147
2148 if (card->options.performance_stats) {
2149 card->perf_stats.inbound_cnt++;
2150 card->perf_stats.inbound_start_time = qeth_get_micros();
2151 }
2152
2153 while (1) {
2154 if (!card->rx.b_count) {
2155 card->rx.qdio_err = 0;
2156 card->rx.b_count = qdio_get_next_buffers(
2157 card->data.ccwdev, 0, &card->rx.b_index,
2158 &card->rx.qdio_err);
2159 if (card->rx.b_count <= 0) {
2160 card->rx.b_count = 0;
2161 break;
2162 }
2163 card->rx.b_element =
2164 &card->qdio.in_q->bufs[card->rx.b_index]
2165 .buffer->element[0];
2166 card->rx.e_offset = 0;
2167 }
2168
2169 while (card->rx.b_count) {
2170 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2171 if (!(card->rx.qdio_err &&
2172 qeth_check_qdio_errors(card, buffer->buffer,
2173 card->rx.qdio_err, "qinerr")))
2174 work_done += qeth_l3_process_inbound_buffer(
2175 card, new_budget, &done);
2176 else
2177 done = 1;
2178
2179 if (done) {
2180 if (card->options.performance_stats)
2181 card->perf_stats.bufs_rec++;
2182 qeth_put_buffer_pool_entry(card,
2183 buffer->pool_entry);
2184 qeth_queue_input_buffer(card, card->rx.b_index);
2185 card->rx.b_count--;
2186 if (card->rx.b_count) {
2187 card->rx.b_index =
2188 (card->rx.b_index + 1) %
2189 QDIO_MAX_BUFFERS_PER_Q;
2190 card->rx.b_element =
2191 &card->qdio.in_q
2192 ->bufs[card->rx.b_index]
2193 .buffer->element[0];
2194 card->rx.e_offset = 0;
2195 }
2196 }
2197
2198 if (work_done >= budget)
2199 goto out;
2200 else
2201 new_budget = budget - work_done;
2202 }
2203 }
2204
2205 napi_complete(napi);
2206 if (qdio_start_irq(card->data.ccwdev, 0))
2207 napi_schedule(&card->napi);
2208out:
2209 if (card->options.performance_stats)
2210 card->perf_stats.inbound_time += qeth_get_micros() -
2211 card->perf_stats.inbound_start_time;
2212 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002213}
2214
2215static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2216 struct qeth_card *card)
2217{
2218 int rc = 0;
2219 struct vlan_group *vg;
2220 int i;
2221
2222 vg = card->vlangrp;
2223 if (!vg)
2224 return rc;
2225
Jesse Grossb7381272010-10-20 13:56:02 +00002226 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002227 if (vlan_group_get_device(vg, i) == dev) {
2228 rc = QETH_VLAN_CARD;
2229 break;
2230 }
2231 }
2232
Heiko Carstens509e2562008-07-26 02:24:10 -07002233 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002234 return 0;
2235
2236 return rc;
2237}
2238
2239static int qeth_l3_verify_dev(struct net_device *dev)
2240{
2241 struct qeth_card *card;
2242 unsigned long flags;
2243 int rc = 0;
2244
2245 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2246 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2247 if (card->dev == dev) {
2248 rc = QETH_REAL_CARD;
2249 break;
2250 }
2251 rc = qeth_l3_verify_vlan_dev(dev, card);
2252 if (rc)
2253 break;
2254 }
2255 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2256
2257 return rc;
2258}
2259
2260static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2261{
2262 struct qeth_card *card = NULL;
2263 int rc;
2264
2265 rc = qeth_l3_verify_dev(dev);
2266 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002267 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002268 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002269 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002270 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002271 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002272 if (card)
2273 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002274 return card ;
2275}
2276
2277static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2278{
2279 int rc = 0;
2280
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002281 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2282 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002283
2284 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002285 if (card->options.sniffer &&
2286 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2287 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002288 if (card->read.state == CH_STATE_UP &&
2289 card->write.state == CH_STATE_UP &&
2290 (card->state == CARD_STATE_UP)) {
2291 if (recovery_mode)
2292 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002293 else {
Ursula Braun869da902010-03-08 20:36:56 +00002294 rtnl_lock();
2295 dev_close(card->dev);
2296 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002297 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002298 card->state = CARD_STATE_SOFTSETUP;
2299 }
2300 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -08002301 qeth_l3_clear_ip_list(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002302 qeth_clear_ipacmd_list(card);
2303 card->state = CARD_STATE_HARDSETUP;
2304 }
2305 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002306 qeth_qdio_clear_card(card, 0);
2307 qeth_clear_qdio_buffers(card);
2308 qeth_clear_working_pool_list(card);
2309 card->state = CARD_STATE_DOWN;
2310 }
2311 if (card->state == CARD_STATE_DOWN) {
2312 qeth_clear_cmd_buffers(&card->read);
2313 qeth_clear_cmd_buffers(&card->write);
2314 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002315 return rc;
2316}
2317
Ursula Braun76b11f82010-01-11 02:50:50 +00002318/*
2319 * test for and Switch promiscuous mode (on or off)
2320 * either for guestlan or HiperSocket Sniffer
2321 */
2322static void
2323qeth_l3_handle_promisc_mode(struct qeth_card *card)
2324{
2325 struct net_device *dev = card->dev;
2326
2327 if (((dev->flags & IFF_PROMISC) &&
2328 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2329 (!(dev->flags & IFF_PROMISC) &&
2330 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2331 return;
2332
2333 if (card->info.guestlan) { /* Guestlan trace */
2334 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2335 qeth_setadp_promisc_mode(card);
2336 } else if (card->options.sniffer && /* HiperSockets trace */
2337 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2338 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002339 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002340 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2341 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002342 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002343 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2344 }
2345 }
2346}
2347
Frank Blaschka4a71df52008-02-15 09:19:42 +01002348static void qeth_l3_set_multicast_list(struct net_device *dev)
2349{
Heiko Carstens509e2562008-07-26 02:24:10 -07002350 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002351
Carsten Otte847a50f2010-06-21 22:57:05 +00002352 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002353 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2354 (card->state != CARD_STATE_UP))
2355 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002356 if (!card->options.sniffer) {
2357 qeth_l3_delete_mc_addresses(card);
2358 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002359#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002360 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002361#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002362 qeth_l3_set_ip_addr_list(card);
2363 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2364 return;
2365 }
2366 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002367}
2368
2369static const char *qeth_l3_arp_get_error_cause(int *rc)
2370{
2371 switch (*rc) {
2372 case QETH_IPA_ARP_RC_FAILED:
2373 *rc = -EIO;
2374 return "operation failed";
2375 case QETH_IPA_ARP_RC_NOTSUPP:
2376 *rc = -EOPNOTSUPP;
2377 return "operation not supported";
2378 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2379 *rc = -EINVAL;
2380 return "argument out of range";
2381 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2382 *rc = -EOPNOTSUPP;
2383 return "query operation not supported";
2384 case QETH_IPA_ARP_RC_Q_NO_DATA:
2385 *rc = -ENOENT;
2386 return "no query data available";
2387 default:
2388 return "unknown error";
2389 }
2390}
2391
2392static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2393{
2394 int tmp;
2395 int rc;
2396
Carsten Otte847a50f2010-06-21 22:57:05 +00002397 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002398
2399 /*
2400 * currently GuestLAN only supports the ARP assist function
2401 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2402 * thus we say EOPNOTSUPP for this ARP function
2403 */
2404 if (card->info.guestlan)
2405 return -EOPNOTSUPP;
2406 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002407 return -EOPNOTSUPP;
2408 }
2409 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2410 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2411 no_entries);
2412 if (rc) {
2413 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002414 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2415 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002416 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2417 }
2418 return rc;
2419}
2420
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002421static __u32 get_arp_entry_size(struct qeth_card *card,
2422 struct qeth_arp_query_data *qdata,
2423 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002424{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002425 __u32 rc;
2426 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002427
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002428 is_hsi = qdata->reply_bits == 5;
2429 if (type->ip == QETHARP_IP_ADDR_V4) {
2430 QETH_CARD_TEXT(card, 4, "arpev4");
2431 if (strip_entries) {
2432 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2433 sizeof(struct qeth_arp_qi_entry7_short);
2434 } else {
2435 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2436 sizeof(struct qeth_arp_qi_entry7);
2437 }
2438 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2439 QETH_CARD_TEXT(card, 4, "arpev6");
2440 if (strip_entries) {
2441 rc = is_hsi ?
2442 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2443 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2444 } else {
2445 rc = is_hsi ?
2446 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2447 sizeof(struct qeth_arp_qi_entry7_ipv6);
2448 }
2449 } else {
2450 QETH_CARD_TEXT(card, 4, "arpinv");
2451 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002452 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002453
2454 return rc;
2455}
2456
2457static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2458{
2459 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2460 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002461}
2462
2463static int qeth_l3_arp_query_cb(struct qeth_card *card,
2464 struct qeth_reply *reply, unsigned long data)
2465{
2466 struct qeth_ipa_cmd *cmd;
2467 struct qeth_arp_query_data *qdata;
2468 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002469 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002470 int e;
2471 int entrybytes_done;
2472 int stripped_bytes;
2473 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002474
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002475 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002476
2477 qinfo = (struct qeth_arp_query_info *) reply->param;
2478 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002479 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002480 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002481 QETH_CARD_TEXT(card, 4, "arpcberr");
2482 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002483 return 0;
2484 }
2485 if (cmd->data.setassparms.hdr.return_code) {
2486 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002487 QETH_CARD_TEXT(card, 4, "setaperr");
2488 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002489 return 0;
2490 }
2491 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002492 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002493
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002494 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2495 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2496 entrybytes_done = 0;
2497 for (e = 0; e < qdata->no_entries; ++e) {
2498 char *cur_entry;
2499 __u32 esize;
2500 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002501
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002502 cur_entry = &qdata->data + entrybytes_done;
2503 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2504 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2505 QETH_CARD_TEXT(card, 4, "pmis");
2506 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2507 break;
2508 }
2509 esize = get_arp_entry_size(card, qdata, etype,
2510 do_strip_entries);
2511 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2512 if (!esize)
2513 break;
2514
2515 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2516 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
2517 cmd->hdr.return_code = -ENOMEM;
2518 goto out_error;
2519 }
2520
2521 memcpy(qinfo->udata + qinfo->udata_offset,
2522 &qdata->data + entrybytes_done + stripped_bytes,
2523 esize);
2524 entrybytes_done += esize + stripped_bytes;
2525 qinfo->udata_offset += esize;
2526 ++qinfo->no_entries;
2527 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002528 /* check if all replies received ... */
2529 if (cmd->data.setassparms.hdr.seq_no <
2530 cmd->data.setassparms.hdr.number_of_replies)
2531 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002532 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002533 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2534 /* keep STRIP_ENTRIES flag so the user program can distinguish
2535 * stripped entries from normal ones */
2536 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2537 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2538 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002539 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002540 return 0;
2541out_error:
2542 i = 0;
2543 memcpy(qinfo->udata, &i, 4);
2544 return 0;
2545}
2546
2547static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2548 struct qeth_cmd_buffer *iob, int len,
2549 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2550 unsigned long),
2551 void *reply_param)
2552{
Carsten Otte847a50f2010-06-21 22:57:05 +00002553 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002554
2555 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2556 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2557 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2558 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2559 reply_cb, reply_param);
2560}
2561
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002562static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2563 enum qeth_prot_versions prot,
2564 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002565{
2566 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002567 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002568 int tmp;
2569 int rc;
2570
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002571 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2572
2573 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2574 IPA_CMD_ASS_ARP_QUERY_INFO,
2575 sizeof(struct qeth_arp_query_data) - sizeof(char),
2576 prot);
2577 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2578 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2579 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2580 cmd->data.setassparms.data.query_arp.no_entries = 0;
2581 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2582 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2583 qeth_l3_arp_query_cb, (void *)qinfo);
2584 if (rc) {
2585 tmp = rc;
2586 QETH_DBF_MESSAGE(2,
2587 "Error while querying ARP cache on %s: %s "
2588 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2589 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2590 }
2591
2592 return rc;
2593}
2594
2595static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2596{
2597 struct qeth_arp_query_info qinfo = {0, };
2598 int rc;
2599
Carsten Otte847a50f2010-06-21 22:57:05 +00002600 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002601
2602 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2603 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002604 QETH_CARD_TEXT(card, 3, "arpqnsup");
2605 rc = -EOPNOTSUPP;
2606 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002607 }
2608 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002609 if (copy_from_user(&qinfo, udata, 6)) {
2610 rc = -EFAULT;
2611 goto out;
2612 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002613 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002614 if (!qinfo.udata) {
2615 rc = -ENOMEM;
2616 goto out;
2617 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002618 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002619 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002620 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002621 if (copy_to_user(udata, qinfo.udata, 4))
2622 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002623 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002624 } else {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002625#ifdef CONFIG_QETH_IPV6
2626 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2627 /* fails in case of GuestLAN QDIO mode */
2628 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
2629 &qinfo);
2630 }
2631#endif
2632 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2633 QETH_CARD_TEXT(card, 4, "qactf");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002634 rc = -EFAULT;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002635 goto free_and_out;
2636 }
2637 QETH_CARD_TEXT_(card, 4, "qacts");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002638 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002639free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002640 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002641out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002642 return rc;
2643}
2644
2645static int qeth_l3_arp_add_entry(struct qeth_card *card,
2646 struct qeth_arp_cache_entry *entry)
2647{
2648 struct qeth_cmd_buffer *iob;
2649 char buf[16];
2650 int tmp;
2651 int rc;
2652
Carsten Otte847a50f2010-06-21 22:57:05 +00002653 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002654
2655 /*
2656 * currently GuestLAN only supports the ARP assist function
2657 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2658 * thus we say EOPNOTSUPP for this ARP function
2659 */
2660 if (card->info.guestlan)
2661 return -EOPNOTSUPP;
2662 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002663 return -EOPNOTSUPP;
2664 }
2665
2666 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2667 IPA_CMD_ASS_ARP_ADD_ENTRY,
2668 sizeof(struct qeth_arp_cache_entry),
2669 QETH_PROT_IPV4);
2670 rc = qeth_l3_send_setassparms(card, iob,
2671 sizeof(struct qeth_arp_cache_entry),
2672 (unsigned long) entry,
2673 qeth_l3_default_setassparms_cb, NULL);
2674 if (rc) {
2675 tmp = rc;
2676 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002677 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2678 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2679 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002680 }
2681 return rc;
2682}
2683
2684static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2685 struct qeth_arp_cache_entry *entry)
2686{
2687 struct qeth_cmd_buffer *iob;
2688 char buf[16] = {0, };
2689 int tmp;
2690 int rc;
2691
Carsten Otte847a50f2010-06-21 22:57:05 +00002692 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002693
2694 /*
2695 * currently GuestLAN only supports the ARP assist function
2696 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2697 * thus we say EOPNOTSUPP for this ARP function
2698 */
2699 if (card->info.guestlan)
2700 return -EOPNOTSUPP;
2701 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002702 return -EOPNOTSUPP;
2703 }
2704 memcpy(buf, entry, 12);
2705 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2706 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2707 12,
2708 QETH_PROT_IPV4);
2709 rc = qeth_l3_send_setassparms(card, iob,
2710 12, (unsigned long)buf,
2711 qeth_l3_default_setassparms_cb, NULL);
2712 if (rc) {
2713 tmp = rc;
2714 memset(buf, 0, 16);
2715 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002716 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2717 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2718 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002719 }
2720 return rc;
2721}
2722
2723static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2724{
2725 int rc;
2726 int tmp;
2727
Carsten Otte847a50f2010-06-21 22:57:05 +00002728 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002729
2730 /*
2731 * currently GuestLAN only supports the ARP assist function
2732 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2733 * thus we say EOPNOTSUPP for this ARP function
2734 */
2735 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2736 return -EOPNOTSUPP;
2737 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002738 return -EOPNOTSUPP;
2739 }
2740 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2741 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2742 if (rc) {
2743 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002744 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2745 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002746 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2747 }
2748 return rc;
2749}
2750
2751static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2752{
Heiko Carstens509e2562008-07-26 02:24:10 -07002753 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002754 struct qeth_arp_cache_entry arp_entry;
2755 struct mii_ioctl_data *mii_data;
2756 int rc = 0;
2757
2758 if (!card)
2759 return -ENODEV;
2760
2761 if ((card->state != CARD_STATE_UP) &&
2762 (card->state != CARD_STATE_SOFTSETUP))
2763 return -ENODEV;
2764
2765 switch (cmd) {
2766 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2767 if (!capable(CAP_NET_ADMIN)) {
2768 rc = -EPERM;
2769 break;
2770 }
2771 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2772 break;
2773 case SIOC_QETH_ARP_QUERY_INFO:
2774 if (!capable(CAP_NET_ADMIN)) {
2775 rc = -EPERM;
2776 break;
2777 }
2778 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2779 break;
2780 case SIOC_QETH_ARP_ADD_ENTRY:
2781 if (!capable(CAP_NET_ADMIN)) {
2782 rc = -EPERM;
2783 break;
2784 }
2785 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2786 sizeof(struct qeth_arp_cache_entry)))
2787 rc = -EFAULT;
2788 else
2789 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2790 break;
2791 case SIOC_QETH_ARP_REMOVE_ENTRY:
2792 if (!capable(CAP_NET_ADMIN)) {
2793 rc = -EPERM;
2794 break;
2795 }
2796 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2797 sizeof(struct qeth_arp_cache_entry)))
2798 rc = -EFAULT;
2799 else
2800 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2801 break;
2802 case SIOC_QETH_ARP_FLUSH_CACHE:
2803 if (!capable(CAP_NET_ADMIN)) {
2804 rc = -EPERM;
2805 break;
2806 }
2807 rc = qeth_l3_arp_flush_cache(card);
2808 break;
2809 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2810 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2811 break;
2812 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002813 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2814 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002815 !card->info.guestlan)
2816 return 1;
2817 return 0;
2818 break;
2819 case SIOCGMIIPHY:
2820 mii_data = if_mii(rq);
2821 mii_data->phy_id = 0;
2822 break;
2823 case SIOCGMIIREG:
2824 mii_data = if_mii(rq);
2825 if (mii_data->phy_id != 0)
2826 rc = -EINVAL;
2827 else
2828 mii_data->val_out = qeth_mdio_read(dev,
2829 mii_data->phy_id,
2830 mii_data->reg_num);
2831 break;
2832 default:
2833 rc = -EOPNOTSUPP;
2834 }
2835 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002836 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002837 return rc;
2838}
2839
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002840int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2841{
2842 int cast_type = RTN_UNSPEC;
2843
2844 if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2845 cast_type = skb_dst(skb)->neighbour->type;
2846 if ((cast_type == RTN_BROADCAST) ||
2847 (cast_type == RTN_MULTICAST) ||
2848 (cast_type == RTN_ANYCAST))
2849 return cast_type;
2850 else
2851 return RTN_UNSPEC;
2852 }
2853 /* try something else */
2854 if (skb->protocol == ETH_P_IPV6)
2855 return (skb_network_header(skb)[24] == 0xff) ?
2856 RTN_MULTICAST : 0;
2857 else if (skb->protocol == ETH_P_IP)
2858 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2859 RTN_MULTICAST : 0;
2860 /* ... */
2861 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2862 return RTN_BROADCAST;
2863 else {
2864 u16 hdr_mac;
2865
2866 hdr_mac = *((u16 *)skb->data);
2867 /* tr multicast? */
2868 switch (card->info.link_type) {
2869 case QETH_LINK_TYPE_HSTR:
2870 case QETH_LINK_TYPE_LANE_TR:
2871 if ((hdr_mac == QETH_TR_MAC_NC) ||
2872 (hdr_mac == QETH_TR_MAC_C))
2873 return RTN_MULTICAST;
2874 break;
2875 /* eth or so multicast? */
2876 default:
2877 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2878 (hdr_mac == QETH_ETH_MAC_V6))
2879 return RTN_MULTICAST;
2880 }
2881 }
2882 return cast_type;
2883}
2884
Frank Blaschka4a71df52008-02-15 09:19:42 +01002885static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2886 struct sk_buff *skb, int ipv, int cast_type)
2887{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002888 memset(hdr, 0, sizeof(struct qeth_hdr));
2889 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2890 hdr->hdr.l3.ext_flags = 0;
2891
2892 /*
2893 * before we're going to overwrite this location with next hop ip.
2894 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2895 */
2896 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002897 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2898 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2899 else
2900 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002901 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2902 }
2903
2904 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2905 if (ipv == 4) {
2906 /* IPv4 */
2907 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2908 memset(hdr->hdr.l3.dest_addr, 0, 12);
Eric Dumazetadf30902009-06-02 05:19:30 +00002909 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002910 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
Eric Dumazetadf30902009-06-02 05:19:30 +00002911 *((u32 *) skb_dst(skb)->neighbour->primary_key);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002912 } else {
2913 /* fill in destination address used in ip header */
2914 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2915 ip_hdr(skb)->daddr;
2916 }
2917 } else if (ipv == 6) {
2918 /* IPv6 */
2919 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2920 if (card->info.type == QETH_CARD_TYPE_IQD)
2921 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
Eric Dumazetadf30902009-06-02 05:19:30 +00002922 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002923 memcpy(hdr->hdr.l3.dest_addr,
Eric Dumazetadf30902009-06-02 05:19:30 +00002924 skb_dst(skb)->neighbour->primary_key, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002925 } else {
2926 /* fill in destination address used in ip header */
2927 memcpy(hdr->hdr.l3.dest_addr,
2928 &ipv6_hdr(skb)->daddr, 16);
2929 }
2930 } else {
2931 /* passthrough */
2932 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2933 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2934 sizeof(__u16), skb->dev->broadcast, 6)) {
2935 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2936 QETH_HDR_PASSTHRU;
2937 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2938 skb->dev->broadcast, 6)) {
2939 /* broadcast? */
2940 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2941 QETH_HDR_PASSTHRU;
2942 } else {
2943 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2944 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2945 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2946 }
2947 }
2948}
2949
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002950static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2951 struct qeth_hdr *hdr, struct sk_buff *skb)
2952{
2953 struct iphdr *iph = ip_hdr(skb);
2954
2955 /* tcph->check contains already the pseudo hdr checksum
2956 * so just set the header flags
2957 */
2958 if (iph->protocol == IPPROTO_UDP)
2959 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002960 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2961 QETH_HDR_EXT_CSUM_HDR_REQ;
2962 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002963 if (card->options.performance_stats)
2964 card->perf_stats.tx_csum++;
2965}
2966
Frank Blaschka64ef8952009-03-24 20:57:16 +00002967static void qeth_tso_fill_header(struct qeth_card *card,
2968 struct qeth_hdr *qhdr, struct sk_buff *skb)
2969{
2970 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2971 struct tcphdr *tcph = tcp_hdr(skb);
2972 struct iphdr *iph = ip_hdr(skb);
2973 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2974
2975 /*fix header to TSO values ...*/
2976 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002977 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002978 /*set values which are fix for the first approach ...*/
2979 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2980 hdr->ext.imb_hdr_no = 1;
2981 hdr->ext.hdr_type = 1;
2982 hdr->ext.hdr_version = 1;
2983 hdr->ext.hdr_len = 28;
2984 /*insert non-fix values */
2985 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2986 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2987 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2988 sizeof(struct qeth_hdr_tso));
2989 tcph->check = 0;
2990 if (skb->protocol == ETH_P_IPV6) {
2991 ip6h->payload_len = 0;
2992 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2993 0, IPPROTO_TCP, 0);
2994 } else {
2995 /*OSA want us to set these values ...*/
2996 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2997 0, IPPROTO_TCP, 0);
2998 iph->tot_len = 0;
2999 iph->check = 0;
3000 }
3001}
3002
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003003static inline int qeth_l3_tso_elements(struct sk_buff *skb)
3004{
3005 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
3006 tcp_hdr(skb)->doff * 4;
3007 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003008 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003009 elements += skb_shinfo(skb)->nr_frags;
3010 return elements;
3011}
3012
Frank Blaschka4a71df52008-02-15 09:19:42 +01003013static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3014{
3015 int rc;
3016 u16 *tag;
3017 struct qeth_hdr *hdr = NULL;
3018 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00003019 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07003020 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003021 struct sk_buff *new_skb = NULL;
3022 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00003023 int cast_type = qeth_l3_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003024 struct qeth_qdio_out_q *queue = card->qdio.out_qs
3025 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
3026 int tx_bytes = skb->len;
3027 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
Frank Blaschka683d7182008-08-01 16:39:13 +02003028 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00003029 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003030
Frank Blaschka21fde742010-03-08 20:36:54 +00003031 if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
3032 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003033 goto tx_drop;
3034
3035 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3036 card->stats.tx_carrier_errors++;
3037 goto tx_drop;
3038 }
3039
3040 if ((cast_type == RTN_BROADCAST) &&
3041 (card->info.broadcast_capable == 0))
3042 goto tx_drop;
3043
3044 if (card->options.performance_stats) {
3045 card->perf_stats.outbound_cnt++;
3046 card->perf_stats.outbound_start_time = qeth_get_micros();
3047 }
3048
Frank Blaschka683d7182008-08-01 16:39:13 +02003049 if (skb_is_gso(skb))
3050 large_send = card->options.large_send;
3051
3052 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
3053 (skb_shinfo(skb)->nr_frags == 0)) {
3054 new_skb = skb;
3055 data_offset = ETH_HLEN;
3056 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
3057 if (!hdr)
3058 goto tx_drop;
3059 elements_needed++;
3060 } else {
3061 /* create a clone with writeable headroom */
3062 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
3063 + VLAN_HLEN);
3064 if (!new_skb)
3065 goto tx_drop;
3066 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003067
3068 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02003069 if (data_offset < 0)
3070 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003071 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00003072 if (ipv == 4) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003073 if (card->dev->type == ARPHRD_IEEE802_TR)
3074 skb_pull(new_skb, TR_HLEN);
3075 else
3076 skb_pull(new_skb, ETH_HLEN);
3077 }
3078
Frank Blaschka91d45762010-12-08 02:58:00 +00003079 if (ipv != 4 && card->vlangrp &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01003080 vlan_tx_tag_present(new_skb)) {
3081 skb_push(new_skb, VLAN_HLEN);
3082 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
3083 skb_copy_to_linear_data_offset(new_skb, 4,
3084 new_skb->data + 8, 4);
3085 skb_copy_to_linear_data_offset(new_skb, 8,
3086 new_skb->data + 12, 4);
3087 tag = (u16 *)(new_skb->data + 12);
3088 *tag = __constant_htons(ETH_P_8021Q);
3089 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02003090 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003091 }
3092 }
3093
3094 netif_stop_queue(dev);
3095
Frank Blaschka4a71df52008-02-15 09:19:42 +01003096 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003097 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003098 */
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003099 if (large_send == QETH_LARGE_SEND_TSO) {
3100 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3101 if (skb_linearize(new_skb))
3102 goto tx_drop;
3103 if (card->options.performance_stats)
3104 card->perf_stats.tx_lin++;
3105 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003106 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003107
3108 if ((large_send == QETH_LARGE_SEND_TSO) &&
3109 (cast_type == RTN_UNSPEC)) {
3110 hdr = (struct qeth_hdr *)skb_push(new_skb,
3111 sizeof(struct qeth_hdr_tso));
3112 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3113 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3114 qeth_tso_fill_header(card, hdr, new_skb);
3115 elements_needed++;
3116 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003117 if (data_offset < 0) {
3118 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003119 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003120 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3121 cast_type);
3122 } else {
3123 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3124 cast_type);
3125 hdr->hdr.l3.length = new_skb->len - data_offset;
3126 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003127
3128 if (skb->ip_summed == CHECKSUM_PARTIAL)
3129 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003130 }
3131
Frank Blaschka64ef8952009-03-24 20:57:16 +00003132 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003133 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003134 if (!elems) {
3135 if (data_offset >= 0)
3136 kmem_cache_free(qeth_core_header_cache, hdr);
3137 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003138 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003139 elements_needed += elems;
3140 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003141
Frank Blaschka51aa1652010-06-21 22:57:10 +00003142 if (card->info.type != QETH_CARD_TYPE_IQD) {
3143 int len;
3144 if (large_send == QETH_LARGE_SEND_TSO)
3145 len = ((unsigned long)tcp_hdr(new_skb) +
3146 tcp_hdr(new_skb)->doff * 4) -
3147 (unsigned long)new_skb->data;
3148 else
3149 len = sizeof(struct qeth_hdr_layer3);
3150
3151 if (qeth_hdr_chk_and_bounce(new_skb, len))
3152 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003153 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003154 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003155 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003156 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003157 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003158
3159 if (!rc) {
3160 card->stats.tx_packets++;
3161 card->stats.tx_bytes += tx_bytes;
3162 if (new_skb != skb)
3163 dev_kfree_skb_any(skb);
3164 if (card->options.performance_stats) {
3165 if (large_send != QETH_LARGE_SEND_NO) {
3166 card->perf_stats.large_send_bytes += tx_bytes;
3167 card->perf_stats.large_send_cnt++;
3168 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003169 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003170 card->perf_stats.sg_skbs_sent++;
3171 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003172 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003173 }
3174 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003175 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003176 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003177 if (data_offset >= 0)
3178 kmem_cache_free(qeth_core_header_cache, hdr);
3179
Frank Blaschka4a71df52008-02-15 09:19:42 +01003180 if (rc == -EBUSY) {
3181 if (new_skb != skb)
3182 dev_kfree_skb_any(new_skb);
3183 return NETDEV_TX_BUSY;
3184 } else
3185 goto tx_drop;
3186 }
3187
3188 netif_wake_queue(dev);
3189 if (card->options.performance_stats)
3190 card->perf_stats.outbound_time += qeth_get_micros() -
3191 card->perf_stats.outbound_start_time;
3192 return rc;
3193
3194tx_drop:
3195 card->stats.tx_dropped++;
3196 card->stats.tx_errors++;
3197 if ((new_skb != skb) && new_skb)
3198 dev_kfree_skb_any(new_skb);
3199 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003200 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003201 return NETDEV_TX_OK;
3202}
3203
Ursula Braun39423442011-01-12 20:42:24 +00003204static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003205{
Heiko Carstens509e2562008-07-26 02:24:10 -07003206 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003207 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003208
Carsten Otte847a50f2010-06-21 22:57:05 +00003209 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00003210 if (card->state == CARD_STATE_UP)
3211 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003212 if (card->state != CARD_STATE_SOFTSETUP)
3213 return -ENODEV;
3214 card->data.state = CH_STATE_UP;
3215 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003216 netif_start_queue(dev);
3217
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003218 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3219 napi_enable(&card->napi);
3220 napi_schedule(&card->napi);
3221 } else
3222 rc = -EIO;
3223 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003224}
3225
Ursula Braun39423442011-01-12 20:42:24 +00003226static int qeth_l3_open(struct net_device *dev)
3227{
3228 struct qeth_card *card = dev->ml_priv;
3229
3230 QETH_CARD_TEXT(card, 5, "qethope_");
3231 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3232 QETH_CARD_TEXT(card, 3, "openREC");
3233 return -ERESTARTSYS;
3234 }
3235 return __qeth_l3_open(dev);
3236}
3237
Frank Blaschka4a71df52008-02-15 09:19:42 +01003238static int qeth_l3_stop(struct net_device *dev)
3239{
Heiko Carstens509e2562008-07-26 02:24:10 -07003240 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003241
Carsten Otte847a50f2010-06-21 22:57:05 +00003242 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003243 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003244 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003245 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003246 napi_disable(&card->napi);
3247 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003248 return 0;
3249}
3250
3251static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
3252{
Heiko Carstens509e2562008-07-26 02:24:10 -07003253 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003254
3255 return (card->options.checksum_type == HW_CHECKSUMMING);
3256}
3257
3258static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
3259{
Heiko Carstens509e2562008-07-26 02:24:10 -07003260 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003261 enum qeth_checksum_types csum_type;
3262
Frank Blaschka4a71df52008-02-15 09:19:42 +01003263 if (data)
3264 csum_type = HW_CHECKSUMMING;
3265 else
3266 csum_type = SW_CHECKSUMMING;
3267
Frank Blaschka3fd434d2009-11-12 00:11:45 +00003268 return qeth_l3_set_rx_csum(card, csum_type);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003269}
3270
3271static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
3272{
Heiko Carstens509e2562008-07-26 02:24:10 -07003273 struct qeth_card *card = dev->ml_priv;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003274 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003275
3276 if (data) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003277 rc = qeth_l3_set_large_send(card, QETH_LARGE_SEND_TSO);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003278 } else {
3279 dev->features &= ~NETIF_F_TSO;
3280 card->options.large_send = QETH_LARGE_SEND_NO;
3281 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003282 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003283}
3284
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003285static int qeth_l3_ethtool_set_tx_csum(struct net_device *dev, u32 data)
3286{
3287 struct qeth_card *card = dev->ml_priv;
3288
3289 if (data) {
3290 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3291 dev->features |= NETIF_F_IP_CSUM;
3292 else
3293 return -EPERM;
3294 } else
3295 dev->features &= ~NETIF_F_IP_CSUM;
3296
3297 return 0;
3298}
3299
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003300static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003301 .get_link = ethtool_op_get_link,
3302 .get_tx_csum = ethtool_op_get_tx_csum,
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003303 .set_tx_csum = qeth_l3_ethtool_set_tx_csum,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003304 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
3305 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
3306 .get_sg = ethtool_op_get_sg,
3307 .set_sg = ethtool_op_set_sg,
3308 .get_tso = ethtool_op_get_tso,
3309 .set_tso = qeth_l3_ethtool_set_tso,
3310 .get_strings = qeth_core_get_strings,
3311 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003312 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003313 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003314 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003315};
3316
3317/*
3318 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3319 * NOARP on the netdevice is no option because it also turns off neighbor
3320 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3321 * arp resolution but we want the hard header (packet socket will work
3322 * e.g. tcpdump)
3323 */
3324static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3325{
3326 n->nud_state = NUD_NOARP;
3327 memcpy(n->ha, "FAKELL", 6);
3328 n->output = n->ops->connected_output;
3329 return 0;
3330}
3331
3332static int
3333qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3334{
3335 if (np->tbl->family == AF_INET)
3336 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3337
3338 return 0;
3339}
3340
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003341static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003342 .ndo_open = qeth_l3_open,
3343 .ndo_stop = qeth_l3_stop,
3344 .ndo_get_stats = qeth_get_stats,
3345 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3346 .ndo_validate_addr = eth_validate_addr,
3347 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3348 .ndo_do_ioctl = qeth_l3_do_ioctl,
3349 .ndo_change_mtu = qeth_change_mtu,
3350 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3351 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3352 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3353 .ndo_tx_timeout = qeth_tx_timeout,
3354};
3355
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003356static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3357 .ndo_open = qeth_l3_open,
3358 .ndo_stop = qeth_l3_stop,
3359 .ndo_get_stats = qeth_get_stats,
3360 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3361 .ndo_validate_addr = eth_validate_addr,
3362 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3363 .ndo_do_ioctl = qeth_l3_do_ioctl,
3364 .ndo_change_mtu = qeth_change_mtu,
3365 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3366 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3367 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3368 .ndo_tx_timeout = qeth_tx_timeout,
3369 .ndo_neigh_setup = qeth_l3_neigh_setup,
3370};
3371
Frank Blaschka4a71df52008-02-15 09:19:42 +01003372static int qeth_l3_setup_netdev(struct qeth_card *card)
3373{
Ursula Braun5113fec2010-05-16 21:15:14 +00003374 if (card->info.type == QETH_CARD_TYPE_OSD ||
3375 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003376 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3377 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3378#ifdef CONFIG_TR
3379 card->dev = alloc_trdev(0);
3380#endif
3381 if (!card->dev)
3382 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003383 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003384 } else {
3385 card->dev = alloc_etherdev(0);
3386 if (!card->dev)
3387 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003388 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003389
3390 /*IPv6 address autoconfiguration stuff*/
3391 qeth_l3_get_unique_id(card);
3392 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3393 card->dev->dev_id = card->info.unique_id &
3394 0xffff;
Frank Blaschkadcf4ae22011-03-14 15:39:47 -07003395 if (!card->info.guestlan)
3396 card->dev->features |= NETIF_F_GRO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003397 }
3398 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3399 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3400 if (!card->dev)
3401 return -ENODEV;
3402 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003403 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003404 qeth_l3_iqd_read_initial_mac(card);
3405 } else
3406 return -ENODEV;
3407
Heiko Carstens509e2562008-07-26 02:24:10 -07003408 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003409 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003410 card->dev->mtu = card->info.initial_mtu;
3411 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3412 card->dev->features |= NETIF_F_HW_VLAN_TX |
3413 NETIF_F_HW_VLAN_RX |
3414 NETIF_F_HW_VLAN_FILTER;
Eric Dumazet86d15cd2009-05-30 23:04:46 -07003415 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003416 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003417
3418 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003419 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003420 return register_netdev(card->dev);
3421}
3422
Frank Blaschka4a71df52008-02-15 09:19:42 +01003423static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3424{
3425 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3426
3427 qeth_l3_create_device_attributes(&gdev->dev);
3428 card->options.layer2 = 0;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003429 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003430 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003431 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003432 card->discipline.output_handler = (qdio_handler_t *)
3433 qeth_qdio_output_handler;
3434 card->discipline.recover = qeth_l3_recover;
Frank Blaschkadcf4ae22011-03-14 15:39:47 -07003435 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
3436 (card->info.type == QETH_CARD_TYPE_OSX))
3437 card->options.checksum_type = HW_CHECKSUMMING;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003438 return 0;
3439}
3440
3441static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3442{
3443 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3444
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003445 qeth_l3_remove_device_attributes(&cgdev->dev);
3446
Ursula Braunf2148562009-05-19 21:38:37 +00003447 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003448 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3449
Ursula Braun70919e22011-02-26 22:41:36 -08003450 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003451 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003452
3453 if (card->dev) {
3454 unregister_netdev(card->dev);
3455 card->dev = NULL;
3456 }
3457
Ursula Braun70919e22011-02-26 22:41:36 -08003458 qeth_l3_clear_ip_list(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003459 qeth_l3_clear_ipato_list(card);
3460 return;
3461}
3462
3463static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3464{
3465 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3466 int rc = 0;
3467 enum qeth_card_states recover_flag;
3468
3469 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003470 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003471 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003472 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3473 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003474
Frank Blaschka4a71df52008-02-15 09:19:42 +01003475 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003476 rc = qeth_core_hardsetup_card(card);
3477 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003478 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003479 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003480 goto out_remove;
3481 }
3482
3483 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3484
Ursula Braunaa909222009-11-12 00:11:43 +00003485 if (!card->dev && qeth_l3_setup_netdev(card)) {
3486 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003487 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003488 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003489
3490 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003491 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003492 qeth_print_status_message(card);
3493
3494 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003495 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003496
3497 rc = qeth_send_startlan(card);
3498 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003499 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003500 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003501 dev_warn(&card->gdev->dev,
3502 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003503 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003504 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003505 }
Ursula Braunaa909222009-11-12 00:11:43 +00003506 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003507 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003508 } else
3509 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003510
Ursula Braun2b6203b2010-11-26 02:41:19 +00003511contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003512 rc = qeth_l3_setadapter_parms(card);
3513 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003514 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003515 if (!card->options.sniffer) {
3516 rc = qeth_l3_start_ipassists(card);
3517 if (rc)
3518 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3519 qeth_l3_set_large_send(card, card->options.large_send);
3520 rc = qeth_l3_setrouting_v4(card);
3521 if (rc)
3522 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3523 rc = qeth_l3_setrouting_v6(card);
3524 if (rc)
3525 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3526 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003527 netif_tx_disable(card->dev);
3528
3529 rc = qeth_init_qdio_queues(card);
3530 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003531 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003532 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003533 goto out_remove;
3534 }
3535 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003536
3537 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003538 qeth_l3_set_ip_addr_list(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003539 if (card->lan_online)
3540 netif_carrier_on(card->dev);
3541 else
3542 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003543 if (recover_flag == CARD_STATE_RECOVER) {
3544 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003545 __qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003546 else {
3547 rtnl_lock();
3548 dev_open(card->dev);
3549 rtnl_unlock();
3550 }
3551 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003552 }
3553 /* let user_space know that device is online */
3554 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003555 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003556 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003557 return 0;
3558out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003559 qeth_l3_stop_card(card, 0);
3560 ccw_device_set_offline(CARD_DDEV(card));
3561 ccw_device_set_offline(CARD_WDEV(card));
3562 ccw_device_set_offline(CARD_RDEV(card));
3563 if (recover_flag == CARD_STATE_RECOVER)
3564 card->state = CARD_STATE_RECOVER;
3565 else
3566 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003567 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003568 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003569 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003570}
3571
3572static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3573{
3574 return __qeth_l3_set_online(gdev, 0);
3575}
3576
3577static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3578 int recovery_mode)
3579{
3580 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3581 int rc = 0, rc2 = 0, rc3 = 0;
3582 enum qeth_card_states recover_flag;
3583
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003584 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003585 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003586 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3587 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003588
3589 if (card->dev && netif_carrier_ok(card->dev))
3590 netif_carrier_off(card->dev);
3591 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02003592 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003593 rc = ccw_device_set_offline(CARD_DDEV(card));
3594 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3595 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3596 if (!rc)
3597 rc = (rc2) ? rc2 : rc3;
3598 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003599 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003600 if (recover_flag == CARD_STATE_UP)
3601 card->state = CARD_STATE_RECOVER;
3602 /* let user_space know that device is offline */
3603 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003604 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003605 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003606 return 0;
3607}
3608
3609static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3610{
3611 return __qeth_l3_set_offline(cgdev, 0);
3612}
3613
3614static int qeth_l3_recover(void *ptr)
3615{
3616 struct qeth_card *card;
3617 int rc = 0;
3618
3619 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003620 QETH_CARD_TEXT(card, 2, "recover1");
3621 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003622 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3623 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003624 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003625 dev_warn(&card->gdev->dev,
3626 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003627 __qeth_l3_set_offline(card->gdev, 1);
3628 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003629 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003630 dev_info(&card->gdev->dev,
3631 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003632 else {
3633 rtnl_lock();
3634 dev_close(card->dev);
3635 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003636 dev_warn(&card->gdev->dev, "The qeth device driver "
3637 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003638 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003639 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3640 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003641 return 0;
3642}
3643
3644static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3645{
3646 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003647 qeth_qdio_clear_card(card, 0);
3648 qeth_clear_qdio_buffers(card);
3649}
3650
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003651static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3652{
3653 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3654
3655 if (card->dev)
3656 netif_device_detach(card->dev);
3657 qeth_set_allowed_threads(card, 0, 1);
3658 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3659 if (gdev->state == CCWGROUP_OFFLINE)
3660 return 0;
3661 if (card->state == CARD_STATE_UP) {
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003662 __qeth_l3_set_offline(card->gdev, 1);
3663 } else
3664 __qeth_l3_set_offline(card->gdev, 0);
3665 return 0;
3666}
3667
3668static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3669{
3670 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3671 int rc = 0;
3672
3673 if (gdev->state == CCWGROUP_OFFLINE)
3674 goto out;
3675
3676 if (card->state == CARD_STATE_RECOVER) {
3677 rc = __qeth_l3_set_online(card->gdev, 1);
3678 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003679 rtnl_lock();
3680 dev_close(card->dev);
3681 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003682 }
3683 } else
3684 rc = __qeth_l3_set_online(card->gdev, 0);
3685out:
3686 qeth_set_allowed_threads(card, 0xffffffff, 0);
3687 if (card->dev)
3688 netif_device_attach(card->dev);
3689 if (rc)
3690 dev_warn(&card->gdev->dev, "The qeth device driver "
3691 "failed to recover an error on the device\n");
3692 return rc;
3693}
3694
Frank Blaschka4a71df52008-02-15 09:19:42 +01003695struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3696 .probe = qeth_l3_probe_device,
3697 .remove = qeth_l3_remove_device,
3698 .set_online = qeth_l3_set_online,
3699 .set_offline = qeth_l3_set_offline,
3700 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003701 .freeze = qeth_l3_pm_suspend,
3702 .thaw = qeth_l3_pm_resume,
3703 .restore = qeth_l3_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003704};
3705EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3706
3707static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003708 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003709{
3710 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3711 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3712 struct qeth_ipaddr *addr;
3713 struct qeth_card *card;
3714
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003715 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003716 return NOTIFY_DONE;
3717
Frank Blaschka4a71df52008-02-15 09:19:42 +01003718 card = qeth_l3_get_card_from_dev(dev);
Carsten Otte847a50f2010-06-21 22:57:05 +00003719 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003720 if (!card)
3721 return NOTIFY_DONE;
3722
3723 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3724 if (addr != NULL) {
3725 addr->u.a4.addr = ifa->ifa_address;
3726 addr->u.a4.mask = ifa->ifa_mask;
3727 addr->type = QETH_IP_TYPE_NORMAL;
3728 } else
3729 goto out;
3730
3731 switch (event) {
3732 case NETDEV_UP:
3733 if (!qeth_l3_add_ip(card, addr))
3734 kfree(addr);
3735 break;
3736 case NETDEV_DOWN:
3737 if (!qeth_l3_delete_ip(card, addr))
3738 kfree(addr);
3739 break;
3740 default:
3741 break;
3742 }
3743 qeth_l3_set_ip_addr_list(card);
3744out:
3745 return NOTIFY_DONE;
3746}
3747
3748static struct notifier_block qeth_l3_ip_notifier = {
3749 qeth_l3_ip_event,
3750 NULL,
3751};
3752
3753#ifdef CONFIG_QETH_IPV6
3754/**
3755 * IPv6 event handler
3756 */
3757static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003758 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003759{
3760 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3761 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3762 struct qeth_ipaddr *addr;
3763 struct qeth_card *card;
3764
Frank Blaschka4a71df52008-02-15 09:19:42 +01003765
3766 card = qeth_l3_get_card_from_dev(dev);
3767 if (!card)
3768 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003769 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003770 if (!qeth_is_supported(card, IPA_IPV6))
3771 return NOTIFY_DONE;
3772
3773 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3774 if (addr != NULL) {
3775 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3776 addr->u.a6.pfxlen = ifa->prefix_len;
3777 addr->type = QETH_IP_TYPE_NORMAL;
3778 } else
3779 goto out;
3780
3781 switch (event) {
3782 case NETDEV_UP:
3783 if (!qeth_l3_add_ip(card, addr))
3784 kfree(addr);
3785 break;
3786 case NETDEV_DOWN:
3787 if (!qeth_l3_delete_ip(card, addr))
3788 kfree(addr);
3789 break;
3790 default:
3791 break;
3792 }
3793 qeth_l3_set_ip_addr_list(card);
3794out:
3795 return NOTIFY_DONE;
3796}
3797
3798static struct notifier_block qeth_l3_ip6_notifier = {
3799 qeth_l3_ip6_event,
3800 NULL,
3801};
3802#endif
3803
3804static int qeth_l3_register_notifiers(void)
3805{
3806 int rc;
3807
Carsten Otte847a50f2010-06-21 22:57:05 +00003808 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003809 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3810 if (rc)
3811 return rc;
3812#ifdef CONFIG_QETH_IPV6
3813 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3814 if (rc) {
3815 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3816 return rc;
3817 }
3818#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003819 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003820#endif
3821 return 0;
3822}
3823
3824static void qeth_l3_unregister_notifiers(void)
3825{
3826
Carsten Otte847a50f2010-06-21 22:57:05 +00003827 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003828 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3829#ifdef CONFIG_QETH_IPV6
3830 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3831#endif /* QETH_IPV6 */
3832}
3833
3834static int __init qeth_l3_init(void)
3835{
3836 int rc = 0;
3837
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003838 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003839 rc = qeth_l3_register_notifiers();
3840 return rc;
3841}
3842
3843static void __exit qeth_l3_exit(void)
3844{
3845 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003846 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003847}
3848
3849module_init(qeth_l3_init);
3850module_exit(qeth_l3_exit);
3851MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3852MODULE_DESCRIPTION("qeth layer 3 discipline");
3853MODULE_LICENSE("GPL");