blob: 42fe92c08c29eab841c9f0705a3eacd30b1e6f15 [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>
25
26#include <net/ip.h>
27#include <net/arp.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000028#include <net/ip6_checksum.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010029
Frank Blaschka4a71df52008-02-15 09:19:42 +010030#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010031
Frank Blaschka4a71df52008-02-15 09:19:42 +010032static int qeth_l3_set_offline(struct ccwgroup_device *);
33static int qeth_l3_recover(void *);
34static int qeth_l3_stop(struct net_device *);
35static void qeth_l3_set_multicast_list(struct net_device *);
36static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
37static int qeth_l3_register_addr_entry(struct qeth_card *,
38 struct qeth_ipaddr *);
39static int qeth_l3_deregister_addr_entry(struct qeth_card *,
40 struct qeth_ipaddr *);
41static int __qeth_l3_set_online(struct ccwgroup_device *, int);
42static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
43
Frank Blaschkac3b4a742009-11-12 00:11:44 +000044int qeth_l3_set_large_send(struct qeth_card *card,
45 enum qeth_large_send_types type)
46{
47 int rc = 0;
48
49 card->options.large_send = type;
50 if (card->dev == NULL)
51 return 0;
52
53 if (card->options.large_send == QETH_LARGE_SEND_TSO) {
54 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
55 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
56 NETIF_F_HW_CSUM;
57 } else {
58 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
59 NETIF_F_HW_CSUM);
60 card->options.large_send = QETH_LARGE_SEND_NO;
61 rc = -EOPNOTSUPP;
62 }
63 } else {
64 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
65 NETIF_F_HW_CSUM);
66 card->options.large_send = QETH_LARGE_SEND_NO;
67 }
68 return rc;
69}
Frank Blaschka4a71df52008-02-15 09:19:42 +010070
71static int qeth_l3_isxdigit(char *buf)
72{
73 while (*buf) {
74 if (!isxdigit(*buf++))
75 return 0;
76 }
77 return 1;
78}
79
80void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
81{
82 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
83}
84
85int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
86{
87 int count = 0, rc = 0;
88 int in[4];
89 char c;
90
91 rc = sscanf(buf, "%u.%u.%u.%u%c",
92 &in[0], &in[1], &in[2], &in[3], &c);
93 if (rc != 4 && (rc != 5 || c != '\n'))
94 return -EINVAL;
95 for (count = 0; count < 4; count++) {
96 if (in[count] > 255)
97 return -EINVAL;
98 addr[count] = in[count];
99 }
100 return 0;
101}
102
103void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
104{
105 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
106 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
107 addr[0], addr[1], addr[2], addr[3],
108 addr[4], addr[5], addr[6], addr[7],
109 addr[8], addr[9], addr[10], addr[11],
110 addr[12], addr[13], addr[14], addr[15]);
111}
112
113int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
114{
115 const char *end, *end_tmp, *start;
116 __u16 *in;
117 char num[5];
118 int num2, cnt, out, found, save_cnt;
119 unsigned short in_tmp[8] = {0, };
120
121 cnt = out = found = save_cnt = num2 = 0;
122 end = start = buf;
123 in = (__u16 *) addr;
124 memset(in, 0, 16);
125 while (*end) {
126 end = strchr(start, ':');
127 if (end == NULL) {
128 end = buf + strlen(buf);
129 end_tmp = strchr(start, '\n');
130 if (end_tmp != NULL)
131 end = end_tmp;
132 out = 1;
133 }
134 if ((end - start)) {
135 memset(num, 0, 5);
136 if ((end - start) > 4)
137 return -EINVAL;
138 memcpy(num, start, end - start);
139 if (!qeth_l3_isxdigit(num))
140 return -EINVAL;
141 sscanf(start, "%x", &num2);
142 if (found)
143 in_tmp[save_cnt++] = num2;
144 else
145 in[cnt++] = num2;
146 if (out)
147 break;
148 } else {
149 if (found)
150 return -EINVAL;
151 found = 1;
152 }
153 start = ++end;
154 }
155 if (cnt + save_cnt > 8)
156 return -EINVAL;
157 cnt = 7;
158 while (save_cnt)
159 in[cnt--] = in_tmp[--save_cnt];
160 return 0;
161}
162
163void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
164 char *buf)
165{
166 if (proto == QETH_PROT_IPV4)
167 qeth_l3_ipaddr4_to_string(addr, buf);
168 else if (proto == QETH_PROT_IPV6)
169 qeth_l3_ipaddr6_to_string(addr, buf);
170}
171
172int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
173 __u8 *addr)
174{
175 if (proto == QETH_PROT_IPV4)
176 return qeth_l3_string_to_ipaddr4(buf, addr);
177 else if (proto == QETH_PROT_IPV6)
178 return qeth_l3_string_to_ipaddr6(buf, addr);
179 else
180 return -EINVAL;
181}
182
183static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
184{
185 int i, j;
186 u8 octet;
187
188 for (i = 0; i < len; ++i) {
189 octet = addr[i];
190 for (j = 7; j >= 0; --j) {
191 bits[i*8 + j] = octet & 1;
192 octet >>= 1;
193 }
194 }
195}
196
197static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
198 struct qeth_ipaddr *addr)
199{
200 struct qeth_ipato_entry *ipatoe;
201 u8 addr_bits[128] = {0, };
202 u8 ipatoe_bits[128] = {0, };
203 int rc = 0;
204
205 if (!card->ipato.enabled)
206 return 0;
207
208 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
209 (addr->proto == QETH_PROT_IPV4)? 4:16);
210 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
211 if (addr->proto != ipatoe->proto)
212 continue;
213 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
214 (ipatoe->proto == QETH_PROT_IPV4) ?
215 4 : 16);
216 if (addr->proto == QETH_PROT_IPV4)
217 rc = !memcmp(addr_bits, ipatoe_bits,
218 min(32, ipatoe->mask_bits));
219 else
220 rc = !memcmp(addr_bits, ipatoe_bits,
221 min(128, ipatoe->mask_bits));
222 if (rc)
223 break;
224 }
225 /* invert? */
226 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
227 rc = !rc;
228 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
229 rc = !rc;
230
231 return rc;
232}
233
234/*
235 * Add IP to be added to todo list. If there is already an "add todo"
236 * in this list we just incremenent the reference count.
237 * Returns 0 if we just incremented reference count.
238 */
239static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
240 struct qeth_ipaddr *addr, int add)
241{
242 struct qeth_ipaddr *tmp, *t;
243 int found = 0;
244
Ursula Braun76b11f82010-01-11 02:50:50 +0000245 if (card->options.sniffer)
246 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100247 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
248 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
249 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
250 return 0;
251 if ((tmp->proto == QETH_PROT_IPV4) &&
252 (addr->proto == QETH_PROT_IPV4) &&
253 (tmp->type == addr->type) &&
254 (tmp->is_multicast == addr->is_multicast) &&
255 (tmp->u.a4.addr == addr->u.a4.addr) &&
256 (tmp->u.a4.mask == addr->u.a4.mask)) {
257 found = 1;
258 break;
259 }
260 if ((tmp->proto == QETH_PROT_IPV6) &&
261 (addr->proto == QETH_PROT_IPV6) &&
262 (tmp->type == addr->type) &&
263 (tmp->is_multicast == addr->is_multicast) &&
264 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
265 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
266 sizeof(struct in6_addr)) == 0)) {
267 found = 1;
268 break;
269 }
270 }
271 if (found) {
272 if (addr->users != 0)
273 tmp->users += addr->users;
274 else
275 tmp->users += add ? 1 : -1;
276 if (tmp->users == 0) {
277 list_del(&tmp->entry);
278 kfree(tmp);
279 }
280 return 0;
281 } else {
282 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
283 list_add(&addr->entry, card->ip_tbd_list);
284 else {
285 if (addr->users == 0)
286 addr->users += add ? 1 : -1;
287 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
288 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200289 QETH_DBF_TEXT(TRACE, 2, "tkovaddr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100290 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
291 }
292 list_add_tail(&addr->entry, card->ip_tbd_list);
293 }
294 return 1;
295 }
296}
297
298static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
299{
300 unsigned long flags;
301 int rc = 0;
302
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200303 QETH_DBF_TEXT(TRACE, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304
305 if (addr->proto == QETH_PROT_IPV4)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200306 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100307 else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200308 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
309 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100310 }
311 spin_lock_irqsave(&card->ip_lock, flags);
312 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
313 spin_unlock_irqrestore(&card->ip_lock, flags);
314 return rc;
315}
316
317static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
318{
319 unsigned long flags;
320 int rc = 0;
321
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200322 QETH_DBF_TEXT(TRACE, 4, "addip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323 if (addr->proto == QETH_PROT_IPV4)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200324 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100325 else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200326 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
327 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100328 }
329 spin_lock_irqsave(&card->ip_lock, flags);
330 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
331 spin_unlock_irqrestore(&card->ip_lock, flags);
332 return rc;
333}
334
335
336static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
337 enum qeth_prot_versions prot)
338{
339 struct qeth_ipaddr *addr;
340
341 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
342 if (addr == NULL) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 return NULL;
344 }
345 addr->type = QETH_IP_TYPE_NORMAL;
346 addr->proto = prot;
347 return addr;
348}
349
350static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
351{
352 struct qeth_ipaddr *iptodo;
353 unsigned long flags;
354
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200355 QETH_DBF_TEXT(TRACE, 4, "delmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100356 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
357 if (!iptodo) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200358 QETH_DBF_TEXT(TRACE, 2, "dmcnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100359 return;
360 }
361 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
362 spin_lock_irqsave(&card->ip_lock, flags);
363 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
364 kfree(iptodo);
365 spin_unlock_irqrestore(&card->ip_lock, flags);
366}
367
368/*
369 * Add/remove address to/from card's ip list, i.e. try to add or remove
370 * reference to/from an IP address that is already registered on the card.
371 * Returns:
372 * 0 address was on card and its reference count has been adjusted,
373 * but is still > 0, so nothing has to be done
374 * also returns 0 if card was not on card and the todo was to delete
375 * the address -> there is also nothing to be done
376 * 1 address was not on card and the todo is to add it to the card's ip
377 * list
378 * -1 address was on card and its reference count has been decremented
379 * to <= 0 by the todo -> address must be removed from card
380 */
381static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
382 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
383{
384 struct qeth_ipaddr *addr;
385 int found = 0;
386
387 list_for_each_entry(addr, &card->ip_list, entry) {
388 if ((addr->proto == QETH_PROT_IPV4) &&
389 (todo->proto == QETH_PROT_IPV4) &&
390 (addr->type == todo->type) &&
391 (addr->u.a4.addr == todo->u.a4.addr) &&
392 (addr->u.a4.mask == todo->u.a4.mask)) {
393 found = 1;
394 break;
395 }
396 if ((addr->proto == QETH_PROT_IPV6) &&
397 (todo->proto == QETH_PROT_IPV6) &&
398 (addr->type == todo->type) &&
399 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
400 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
401 sizeof(struct in6_addr)) == 0)) {
402 found = 1;
403 break;
404 }
405 }
406 if (found) {
407 addr->users += todo->users;
408 if (addr->users <= 0) {
409 *__addr = addr;
410 return -1;
411 } else {
412 /* for VIPA and RXIP limit refcount to 1 */
413 if (addr->type != QETH_IP_TYPE_NORMAL)
414 addr->users = 1;
415 return 0;
416 }
417 }
418 if (todo->users > 0) {
419 /* for VIPA and RXIP limit refcount to 1 */
420 if (todo->type != QETH_IP_TYPE_NORMAL)
421 todo->users = 1;
422 return 1;
423 } else
424 return 0;
425}
426
427static void __qeth_l3_delete_all_mc(struct qeth_card *card,
428 unsigned long *flags)
429{
Ursula Braun2d921c32008-04-01 10:26:53 +0200430 struct list_head fail_list;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431 struct qeth_ipaddr *addr, *tmp;
432 int rc;
Ursula Braun2d921c32008-04-01 10:26:53 +0200433
434 INIT_LIST_HEAD(&fail_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435again:
436 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
437 if (addr->is_multicast) {
438 list_del(&addr->entry);
439 spin_unlock_irqrestore(&card->ip_lock, *flags);
440 rc = qeth_l3_deregister_addr_entry(card, addr);
441 spin_lock_irqsave(&card->ip_lock, *flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200442 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443 kfree(addr);
Ursula Braun2d921c32008-04-01 10:26:53 +0200444 else
445 list_add_tail(&addr->entry, &fail_list);
446 goto again;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100447 }
448 }
Ursula Braun2d921c32008-04-01 10:26:53 +0200449 list_splice(&fail_list, &card->ip_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450}
451
452static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
453{
454 struct list_head *tbd_list;
455 struct qeth_ipaddr *todo, *addr;
456 unsigned long flags;
457 int rc;
458
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200459 QETH_DBF_TEXT(TRACE, 2, "sdiplist");
460 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100461
Ursula Braun76b11f82010-01-11 02:50:50 +0000462 if (card->options.sniffer)
463 return;
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) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200468 QETH_DBF_TEXT(TRACE, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100469 card->ip_tbd_list = tbd_list;
470 spin_unlock_irqrestore(&card->ip_lock, flags);
471 return;
472 } else
473 INIT_LIST_HEAD(card->ip_tbd_list);
474
475 while (!list_empty(tbd_list)) {
476 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
477 list_del(&todo->entry);
478 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
479 __qeth_l3_delete_all_mc(card, &flags);
480 kfree(todo);
481 continue;
482 }
483 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
484 if (rc == 0) {
485 /* nothing to be done; only adjusted refcount */
486 kfree(todo);
487 } else if (rc == 1) {
488 /* new entry to be added to on-card list */
489 spin_unlock_irqrestore(&card->ip_lock, flags);
490 rc = qeth_l3_register_addr_entry(card, todo);
491 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200492 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493 list_add_tail(&todo->entry, &card->ip_list);
494 else
495 kfree(todo);
496 } else if (rc == -1) {
497 /* on-card entry to be removed */
498 list_del_init(&addr->entry);
499 spin_unlock_irqrestore(&card->ip_lock, flags);
500 rc = qeth_l3_deregister_addr_entry(card, addr);
501 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun76b11f82010-01-11 02:50:50 +0000502 if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100503 kfree(addr);
504 else
505 list_add_tail(&addr->entry, &card->ip_list);
506 kfree(todo);
507 }
508 }
509 spin_unlock_irqrestore(&card->ip_lock, flags);
510 kfree(tbd_list);
511}
512
513static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
514 int recover)
515{
516 struct qeth_ipaddr *addr, *tmp;
517 unsigned long flags;
518
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200519 QETH_DBF_TEXT(TRACE, 4, "clearip");
Ursula Braun76b11f82010-01-11 02:50:50 +0000520 if (recover && card->options.sniffer)
521 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100522 spin_lock_irqsave(&card->ip_lock, flags);
523 /* clear todo list */
524 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
525 list_del(&addr->entry);
526 kfree(addr);
527 }
528
529 while (!list_empty(&card->ip_list)) {
530 addr = list_entry(card->ip_list.next,
531 struct qeth_ipaddr, entry);
532 list_del_init(&addr->entry);
533 if (clean) {
534 spin_unlock_irqrestore(&card->ip_lock, flags);
535 qeth_l3_deregister_addr_entry(card, addr);
536 spin_lock_irqsave(&card->ip_lock, flags);
537 }
538 if (!recover || addr->is_multicast) {
539 kfree(addr);
540 continue;
541 }
542 list_add_tail(&addr->entry, card->ip_tbd_list);
543 }
544 spin_unlock_irqrestore(&card->ip_lock, flags);
545}
546
547static int qeth_l3_address_exists_in_list(struct list_head *list,
548 struct qeth_ipaddr *addr, int same_type)
549{
550 struct qeth_ipaddr *tmp;
551
552 list_for_each_entry(tmp, list, entry) {
553 if ((tmp->proto == QETH_PROT_IPV4) &&
554 (addr->proto == QETH_PROT_IPV4) &&
555 ((same_type && (tmp->type == addr->type)) ||
556 (!same_type && (tmp->type != addr->type))) &&
557 (tmp->u.a4.addr == addr->u.a4.addr))
558 return 1;
559
560 if ((tmp->proto == QETH_PROT_IPV6) &&
561 (addr->proto == QETH_PROT_IPV6) &&
562 ((same_type && (tmp->type == addr->type)) ||
563 (!same_type && (tmp->type != addr->type))) &&
564 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
565 sizeof(struct in6_addr)) == 0))
566 return 1;
567
568 }
569 return 0;
570}
571
572static int qeth_l3_send_setdelmc(struct qeth_card *card,
573 struct qeth_ipaddr *addr, int ipacmd)
574{
575 int rc;
576 struct qeth_cmd_buffer *iob;
577 struct qeth_ipa_cmd *cmd;
578
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200579 QETH_DBF_TEXT(TRACE, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100580
581 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
582 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
583 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
584 if (addr->proto == QETH_PROT_IPV6)
585 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
586 sizeof(struct in6_addr));
587 else
588 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
589
590 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
591
592 return rc;
593}
594
595static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
596{
597 int i, j;
598 for (i = 0; i < 16; i++) {
599 j = (len) - (i * 8);
600 if (j >= 8)
601 netmask[i] = 0xff;
602 else if (j > 0)
603 netmask[i] = (u8)(0xFF00 >> j);
604 else
605 netmask[i] = 0;
606 }
607}
608
609static int qeth_l3_send_setdelip(struct qeth_card *card,
610 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
611{
612 int rc;
613 struct qeth_cmd_buffer *iob;
614 struct qeth_ipa_cmd *cmd;
615 __u8 netmask[16];
616
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200617 QETH_DBF_TEXT(TRACE, 4, "setdelip");
618 QETH_DBF_TEXT_(TRACE, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100619
620 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
621 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
622 if (addr->proto == QETH_PROT_IPV6) {
623 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
624 sizeof(struct in6_addr));
625 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
626 memcpy(cmd->data.setdelip6.mask, netmask,
627 sizeof(struct in6_addr));
628 cmd->data.setdelip6.flags = flags;
629 } else {
630 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
631 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
632 cmd->data.setdelip4.flags = flags;
633 }
634
635 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
636
637 return rc;
638}
639
640static int qeth_l3_send_setrouting(struct qeth_card *card,
641 enum qeth_routing_types type, enum qeth_prot_versions prot)
642{
643 int rc;
644 struct qeth_ipa_cmd *cmd;
645 struct qeth_cmd_buffer *iob;
646
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200647 QETH_DBF_TEXT(TRACE, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
649 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
650 cmd->data.setrtg.type = (type);
651 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
652
653 return rc;
654}
655
656static void qeth_l3_correct_routing_type(struct qeth_card *card,
657 enum qeth_routing_types *type, enum qeth_prot_versions prot)
658{
659 if (card->info.type == QETH_CARD_TYPE_IQD) {
660 switch (*type) {
661 case NO_ROUTER:
662 case PRIMARY_CONNECTOR:
663 case SECONDARY_CONNECTOR:
664 case MULTICAST_ROUTER:
665 return;
666 default:
667 goto out_inval;
668 }
669 } else {
670 switch (*type) {
671 case NO_ROUTER:
672 case PRIMARY_ROUTER:
673 case SECONDARY_ROUTER:
674 return;
675 case MULTICAST_ROUTER:
676 if (qeth_is_ipafunc_supported(card, prot,
677 IPA_OSA_MC_ROUTER))
678 return;
679 default:
680 goto out_inval;
681 }
682 }
683out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684 *type = NO_ROUTER;
685}
686
687int qeth_l3_setrouting_v4(struct qeth_card *card)
688{
689 int rc;
690
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200691 QETH_DBF_TEXT(TRACE, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692
693 qeth_l3_correct_routing_type(card, &card->options.route4.type,
694 QETH_PROT_IPV4);
695
696 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
697 QETH_PROT_IPV4);
698 if (rc) {
699 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200700 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
701 " on %s. Type set to 'no router'.\n", rc,
702 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100703 }
704 return rc;
705}
706
707int qeth_l3_setrouting_v6(struct qeth_card *card)
708{
709 int rc = 0;
710
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200711 QETH_DBF_TEXT(TRACE, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100712#ifdef CONFIG_QETH_IPV6
713
714 if (!qeth_is_supported(card, IPA_IPV6))
715 return 0;
716 qeth_l3_correct_routing_type(card, &card->options.route6.type,
717 QETH_PROT_IPV6);
718
719 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
720 QETH_PROT_IPV6);
721 if (rc) {
722 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200723 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
724 " on %s. Type set to 'no router'.\n", rc,
725 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100726 }
727#endif
728 return rc;
729}
730
731/*
732 * IP address takeover related functions
733 */
734static void qeth_l3_clear_ipato_list(struct qeth_card *card)
735{
736
737 struct qeth_ipato_entry *ipatoe, *tmp;
738 unsigned long flags;
739
740 spin_lock_irqsave(&card->ip_lock, flags);
741 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
742 list_del(&ipatoe->entry);
743 kfree(ipatoe);
744 }
745 spin_unlock_irqrestore(&card->ip_lock, flags);
746}
747
748int qeth_l3_add_ipato_entry(struct qeth_card *card,
749 struct qeth_ipato_entry *new)
750{
751 struct qeth_ipato_entry *ipatoe;
752 unsigned long flags;
753 int rc = 0;
754
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200755 QETH_DBF_TEXT(TRACE, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756 spin_lock_irqsave(&card->ip_lock, flags);
757 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
758 if (ipatoe->proto != new->proto)
759 continue;
760 if (!memcmp(ipatoe->addr, new->addr,
761 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
762 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100763 rc = -EEXIST;
764 break;
765 }
766 }
767 if (!rc)
768 list_add_tail(&new->entry, &card->ipato.entries);
769
770 spin_unlock_irqrestore(&card->ip_lock, flags);
771 return rc;
772}
773
774void qeth_l3_del_ipato_entry(struct qeth_card *card,
775 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
776{
777 struct qeth_ipato_entry *ipatoe, *tmp;
778 unsigned long flags;
779
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200780 QETH_DBF_TEXT(TRACE, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100781 spin_lock_irqsave(&card->ip_lock, flags);
782 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
783 if (ipatoe->proto != proto)
784 continue;
785 if (!memcmp(ipatoe->addr, addr,
786 (proto == QETH_PROT_IPV4)? 4:16) &&
787 (ipatoe->mask_bits == mask_bits)) {
788 list_del(&ipatoe->entry);
789 kfree(ipatoe);
790 }
791 }
792 spin_unlock_irqrestore(&card->ip_lock, flags);
793}
794
795/*
796 * VIPA related functions
797 */
798int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
799 const u8 *addr)
800{
801 struct qeth_ipaddr *ipaddr;
802 unsigned long flags;
803 int rc = 0;
804
805 ipaddr = qeth_l3_get_addr_buffer(proto);
806 if (ipaddr) {
807 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200808 QETH_DBF_TEXT(TRACE, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100809 memcpy(&ipaddr->u.a4.addr, addr, 4);
810 ipaddr->u.a4.mask = 0;
811 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200812 QETH_DBF_TEXT(TRACE, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100813 memcpy(&ipaddr->u.a6.addr, addr, 16);
814 ipaddr->u.a6.pfxlen = 0;
815 }
816 ipaddr->type = QETH_IP_TYPE_VIPA;
817 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
818 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
819 } else
820 return -ENOMEM;
821 spin_lock_irqsave(&card->ip_lock, flags);
822 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
823 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
824 rc = -EEXIST;
825 spin_unlock_irqrestore(&card->ip_lock, flags);
826 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100827 return rc;
828 }
829 if (!qeth_l3_add_ip(card, ipaddr))
830 kfree(ipaddr);
831 qeth_l3_set_ip_addr_list(card);
832 return rc;
833}
834
835void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
836 const u8 *addr)
837{
838 struct qeth_ipaddr *ipaddr;
839
840 ipaddr = qeth_l3_get_addr_buffer(proto);
841 if (ipaddr) {
842 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200843 QETH_DBF_TEXT(TRACE, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 memcpy(&ipaddr->u.a4.addr, addr, 4);
845 ipaddr->u.a4.mask = 0;
846 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200847 QETH_DBF_TEXT(TRACE, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848 memcpy(&ipaddr->u.a6.addr, addr, 16);
849 ipaddr->u.a6.pfxlen = 0;
850 }
851 ipaddr->type = QETH_IP_TYPE_VIPA;
852 } else
853 return;
854 if (!qeth_l3_delete_ip(card, ipaddr))
855 kfree(ipaddr);
856 qeth_l3_set_ip_addr_list(card);
857}
858
859/*
860 * proxy ARP related functions
861 */
862int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
863 const u8 *addr)
864{
865 struct qeth_ipaddr *ipaddr;
866 unsigned long flags;
867 int rc = 0;
868
869 ipaddr = qeth_l3_get_addr_buffer(proto);
870 if (ipaddr) {
871 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200872 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873 memcpy(&ipaddr->u.a4.addr, addr, 4);
874 ipaddr->u.a4.mask = 0;
875 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200876 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100877 memcpy(&ipaddr->u.a6.addr, addr, 16);
878 ipaddr->u.a6.pfxlen = 0;
879 }
880 ipaddr->type = QETH_IP_TYPE_RXIP;
881 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
882 ipaddr->del_flags = 0;
883 } else
884 return -ENOMEM;
885 spin_lock_irqsave(&card->ip_lock, flags);
886 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
887 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
888 rc = -EEXIST;
889 spin_unlock_irqrestore(&card->ip_lock, flags);
890 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100891 return rc;
892 }
893 if (!qeth_l3_add_ip(card, ipaddr))
894 kfree(ipaddr);
895 qeth_l3_set_ip_addr_list(card);
896 return 0;
897}
898
899void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
900 const u8 *addr)
901{
902 struct qeth_ipaddr *ipaddr;
903
904 ipaddr = qeth_l3_get_addr_buffer(proto);
905 if (ipaddr) {
906 if (proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200907 QETH_DBF_TEXT(TRACE, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 memcpy(&ipaddr->u.a4.addr, addr, 4);
909 ipaddr->u.a4.mask = 0;
910 } else if (proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200911 QETH_DBF_TEXT(TRACE, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912 memcpy(&ipaddr->u.a6.addr, addr, 16);
913 ipaddr->u.a6.pfxlen = 0;
914 }
915 ipaddr->type = QETH_IP_TYPE_RXIP;
916 } else
917 return;
918 if (!qeth_l3_delete_ip(card, ipaddr))
919 kfree(ipaddr);
920 qeth_l3_set_ip_addr_list(card);
921}
922
923static int qeth_l3_register_addr_entry(struct qeth_card *card,
924 struct qeth_ipaddr *addr)
925{
926 char buf[50];
927 int rc = 0;
928 int cnt = 3;
929
930 if (addr->proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200931 QETH_DBF_TEXT(TRACE, 2, "setaddr4");
932 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 } else if (addr->proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200934 QETH_DBF_TEXT(TRACE, 2, "setaddr6");
935 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
936 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937 } else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200938 QETH_DBF_TEXT(TRACE, 2, "setaddr?");
939 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100940 }
941 do {
942 if (addr->is_multicast)
943 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
944 else
945 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
946 addr->set_flags);
947 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200948 QETH_DBF_TEXT(TRACE, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949 } while ((--cnt > 0) && rc);
950 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200951 QETH_DBF_TEXT(TRACE, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100953 dev_warn(&card->gdev->dev,
954 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 }
956 return rc;
957}
958
959static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
960 struct qeth_ipaddr *addr)
961{
962 int rc = 0;
963
964 if (addr->proto == QETH_PROT_IPV4) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200965 QETH_DBF_TEXT(TRACE, 2, "deladdr4");
966 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967 } else if (addr->proto == QETH_PROT_IPV6) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200968 QETH_DBF_TEXT(TRACE, 2, "deladdr6");
969 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
970 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100971 } else {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200972 QETH_DBF_TEXT(TRACE, 2, "deladdr?");
973 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100974 }
975 if (addr->is_multicast)
976 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
977 else
978 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
979 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200980 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200981 QETH_DBF_TEXT(TRACE, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100982
983 return rc;
984}
985
986static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
987{
988 if (cast_type == RTN_MULTICAST)
989 return QETH_CAST_MULTICAST;
990 if (cast_type == RTN_BROADCAST)
991 return QETH_CAST_BROADCAST;
992 return QETH_CAST_UNICAST;
993}
994
995static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
996{
997 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
998 if (cast_type == RTN_MULTICAST)
999 return ct | QETH_CAST_MULTICAST;
1000 if (cast_type == RTN_ANYCAST)
1001 return ct | QETH_CAST_ANYCAST;
1002 if (cast_type == RTN_BROADCAST)
1003 return ct | QETH_CAST_BROADCAST;
1004 return ct | QETH_CAST_UNICAST;
1005}
1006
1007static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
1008 __u32 mode)
1009{
1010 int rc;
1011 struct qeth_cmd_buffer *iob;
1012 struct qeth_ipa_cmd *cmd;
1013
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001014 QETH_DBF_TEXT(TRACE, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001015
1016 iob = qeth_get_adapter_cmd(card, command,
1017 sizeof(struct qeth_ipacmd_setadpparms));
1018 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1019 cmd->data.setadapterparms.data.mode = mode;
1020 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
1021 NULL);
1022 return rc;
1023}
1024
1025static int qeth_l3_setadapter_hstr(struct qeth_card *card)
1026{
1027 int rc;
1028
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001029 QETH_DBF_TEXT(TRACE, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001030
1031 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1032 rc = qeth_l3_send_setadp_mode(card,
1033 IPA_SETADP_SET_BROADCAST_MODE,
1034 card->options.broadcast_mode);
1035 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001036 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001037 "device %s: x%x\n",
1038 CARD_BUS_ID(card), rc);
1039 rc = qeth_l3_send_setadp_mode(card,
1040 IPA_SETADP_ALTER_MAC_ADDRESS,
1041 card->options.macaddr_mode);
1042 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001043 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1045 return rc;
1046 }
1047 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001048 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001049 "to set broadcast mode, using ALLRINGS "
1050 "on device %s:\n", CARD_BUS_ID(card));
1051 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001052 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001053 "to set macaddr mode, using NONCANONICAL "
1054 "on device %s:\n", CARD_BUS_ID(card));
1055 return 0;
1056}
1057
1058static int qeth_l3_setadapter_parms(struct qeth_card *card)
1059{
1060 int rc;
1061
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001062 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001063
1064 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001065 dev_info(&card->gdev->dev,
1066 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001067 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001068 return 0;
1069 }
1070 rc = qeth_query_setadapterparms(card);
1071 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001072 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +00001073 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001074 return rc;
1075 }
1076 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1077 rc = qeth_setadpparms_change_macaddr(card);
1078 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001079 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001080 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001081 }
1082
1083 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1084 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1085 rc = qeth_l3_setadapter_hstr(card);
1086
1087 return rc;
1088}
1089
1090static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1091 struct qeth_reply *reply, unsigned long data)
1092{
1093 struct qeth_ipa_cmd *cmd;
1094
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001095 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001096
1097 cmd = (struct qeth_ipa_cmd *) data;
1098 if (cmd->hdr.return_code == 0) {
1099 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1100 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1101 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1102 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1103 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1104 }
1105 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1106 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1107 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001108 QETH_DBF_TEXT_(TRACE, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001109 }
1110 return 0;
1111}
1112
1113static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1114 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1115 __u16 len, enum qeth_prot_versions prot)
1116{
1117 struct qeth_cmd_buffer *iob;
1118 struct qeth_ipa_cmd *cmd;
1119
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001120 QETH_DBF_TEXT(TRACE, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001121 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1122
1123 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1124 cmd->data.setassparms.hdr.assist_no = ipa_func;
1125 cmd->data.setassparms.hdr.length = 8 + len;
1126 cmd->data.setassparms.hdr.command_code = cmd_code;
1127 cmd->data.setassparms.hdr.return_code = 0;
1128 cmd->data.setassparms.hdr.seq_no = 0;
1129
1130 return iob;
1131}
1132
1133static int qeth_l3_send_setassparms(struct qeth_card *card,
1134 struct qeth_cmd_buffer *iob, __u16 len, long data,
1135 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1136 unsigned long),
1137 void *reply_param)
1138{
1139 int rc;
1140 struct qeth_ipa_cmd *cmd;
1141
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001142 QETH_DBF_TEXT(TRACE, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143
1144 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1145 if (len <= sizeof(__u32))
1146 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1147 else /* (len > sizeof(__u32)) */
1148 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1149
1150 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1151 return rc;
1152}
1153
1154#ifdef CONFIG_QETH_IPV6
1155static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1156 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1157{
1158 int rc;
1159 struct qeth_cmd_buffer *iob;
1160
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001161 QETH_DBF_TEXT(TRACE, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001162 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1163 0, QETH_PROT_IPV6);
1164 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1165 qeth_l3_default_setassparms_cb, NULL);
1166 return rc;
1167}
1168#endif
1169
1170static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1171 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1172{
1173 int rc;
1174 int length = 0;
1175 struct qeth_cmd_buffer *iob;
1176
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001177 QETH_DBF_TEXT(TRACE, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178 if (data)
1179 length = sizeof(__u32);
1180 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1181 length, QETH_PROT_IPV4);
1182 rc = qeth_l3_send_setassparms(card, iob, length, data,
1183 qeth_l3_default_setassparms_cb, NULL);
1184 return rc;
1185}
1186
1187static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1188{
1189 int rc;
1190
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001191 QETH_DBF_TEXT(TRACE, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001192
1193 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001194 dev_info(&card->gdev->dev,
1195 "ARP processing not supported on %s!\n",
1196 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001197 return 0;
1198 }
1199 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1200 IPA_CMD_ASS_START, 0);
1201 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001202 dev_warn(&card->gdev->dev,
1203 "Starting ARP processing support for %s failed\n",
1204 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001205 }
1206 return rc;
1207}
1208
1209static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1210{
1211 int rc;
1212
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001213 QETH_DBF_TEXT(TRACE, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001214
1215 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001216 dev_info(&card->gdev->dev,
1217 "Hardware IP fragmentation not supported on %s\n",
1218 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001219 return -EOPNOTSUPP;
1220 }
1221
1222 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1223 IPA_CMD_ASS_START, 0);
1224 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001225 dev_warn(&card->gdev->dev,
1226 "Starting IP fragmentation support for %s failed\n",
1227 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001229 dev_info(&card->gdev->dev,
1230 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231 return rc;
1232}
1233
1234static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1235{
1236 int rc;
1237
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001238 QETH_DBF_TEXT(TRACE, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001239
Frank Blaschka4a71df52008-02-15 09:19:42 +01001240 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001241 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001242 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001243 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001244 return -EOPNOTSUPP;
1245 }
1246
1247 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1248 IPA_CMD_ASS_START, 0);
1249 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001250 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001251 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001252 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001253 return rc;
1254}
1255
1256static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1257{
1258 int rc = 0;
1259
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001260 QETH_DBF_TEXT(TRACE, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001261
1262 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001263 dev_info(&card->gdev->dev,
1264 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001265 return -EOPNOTSUPP;
1266 }
1267
1268 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1269 IPA_CMD_ASS_START, 0);
1270 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001271 dev_warn(&card->gdev->dev,
1272 "Starting VLAN support for %s failed\n",
1273 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001274 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001275 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001276 }
1277 return rc;
1278}
1279
1280static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1281{
1282 int rc;
1283
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001284 QETH_DBF_TEXT(TRACE, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001285
1286 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001287 dev_info(&card->gdev->dev,
1288 "Multicast not supported on %s\n",
1289 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001290 return -EOPNOTSUPP;
1291 }
1292
1293 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1294 IPA_CMD_ASS_START, 0);
1295 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001296 dev_warn(&card->gdev->dev,
1297 "Starting multicast support for %s failed\n",
1298 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001299 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001300 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001301 card->dev->flags |= IFF_MULTICAST;
1302 }
1303 return rc;
1304}
1305
1306static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1307 struct qeth_reply *reply, unsigned long data)
1308{
1309 struct qeth_ipa_cmd *cmd;
1310
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001311 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001312
1313 cmd = (struct qeth_ipa_cmd *) data;
1314 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1315 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1316 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1317 } else {
1318 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1319 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1320 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001321 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1322 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1323 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001324 return 0;
1325}
1326
1327static int qeth_l3_query_ipassists(struct qeth_card *card,
1328 enum qeth_prot_versions prot)
1329{
1330 int rc;
1331 struct qeth_cmd_buffer *iob;
1332
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001333 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001334 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1335 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1336 return rc;
1337}
1338
1339#ifdef CONFIG_QETH_IPV6
1340static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1341{
1342 int rc;
1343
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001344 QETH_DBF_TEXT(TRACE, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001345
1346 if (card->info.type == QETH_CARD_TYPE_IQD)
1347 goto out;
1348
1349 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1350 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001351 dev_err(&card->gdev->dev,
1352 "Activating IPv6 support for %s failed\n",
1353 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001354 return rc;
1355 }
1356 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1357 IPA_CMD_ASS_START, 3);
1358 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001359 dev_err(&card->gdev->dev,
1360 "Activating IPv6 support for %s failed\n",
1361 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001362 return rc;
1363 }
1364 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1365 IPA_CMD_ASS_START);
1366 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001367 dev_err(&card->gdev->dev,
1368 "Activating IPv6 support for %s failed\n",
1369 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001370 return rc;
1371 }
1372 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1373 IPA_CMD_ASS_START);
1374 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001375 dev_warn(&card->gdev->dev,
1376 "Enabling the passthrough mode for %s failed\n",
1377 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001378 return rc;
1379 }
1380out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001381 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001382 return 0;
1383}
1384#endif
1385
1386static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1387{
1388 int rc = 0;
1389
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001390 QETH_DBF_TEXT(TRACE, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001391
1392 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001393 dev_info(&card->gdev->dev,
1394 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001395 return 0;
1396 }
1397#ifdef CONFIG_QETH_IPV6
1398 rc = qeth_l3_softsetup_ipv6(card);
1399#endif
1400 return rc ;
1401}
1402
1403static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1404{
1405 int rc;
1406
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001407 QETH_DBF_TEXT(TRACE, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001408 card->info.broadcast_capable = 0;
1409 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001410 dev_info(&card->gdev->dev,
1411 "Broadcast not supported on %s\n",
1412 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001413 rc = -EOPNOTSUPP;
1414 goto out;
1415 }
1416 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1417 IPA_CMD_ASS_START, 0);
1418 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001419 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1420 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001421 goto out;
1422 }
1423
1424 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1425 IPA_CMD_ASS_CONFIGURE, 1);
1426 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001427 dev_warn(&card->gdev->dev,
1428 "Setting up broadcast filtering for %s failed\n",
1429 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001430 goto out;
1431 }
1432 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001433 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001434 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1435 IPA_CMD_ASS_ENABLE, 1);
1436 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001437 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1438 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001439 goto out;
1440 }
1441 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1442out:
1443 if (card->info.broadcast_capable)
1444 card->dev->flags |= IFF_BROADCAST;
1445 else
1446 card->dev->flags &= ~IFF_BROADCAST;
1447 return rc;
1448}
1449
1450static int qeth_l3_send_checksum_command(struct qeth_card *card)
1451{
1452 int rc;
1453
1454 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1455 IPA_CMD_ASS_START, 0);
1456 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001457 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1458 "failed, using SW checksumming\n",
1459 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001460 return rc;
1461 }
1462 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1463 IPA_CMD_ASS_ENABLE,
1464 card->info.csum_mask);
1465 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001466 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1467 "failed, using SW checksumming\n",
1468 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001469 return rc;
1470 }
1471 return 0;
1472}
1473
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001474int qeth_l3_set_rx_csum(struct qeth_card *card,
1475 enum qeth_checksum_types csum_type)
1476{
1477 int rc = 0;
1478
1479 if (card->options.checksum_type == HW_CHECKSUMMING) {
1480 if ((csum_type != HW_CHECKSUMMING) &&
1481 (card->state != CARD_STATE_DOWN)) {
1482 rc = qeth_l3_send_simple_setassparms(card,
1483 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1484 if (rc)
1485 return -EIO;
1486 }
1487 } else {
1488 if (csum_type == HW_CHECKSUMMING) {
1489 if (card->state != CARD_STATE_DOWN) {
1490 if (!qeth_is_supported(card,
1491 IPA_INBOUND_CHECKSUM))
1492 return -EPERM;
1493 rc = qeth_l3_send_checksum_command(card);
1494 if (rc)
1495 return -EIO;
1496 }
1497 }
1498 }
1499 card->options.checksum_type = csum_type;
1500 return rc;
1501}
1502
Frank Blaschka4a71df52008-02-15 09:19:42 +01001503static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1504{
1505 int rc = 0;
1506
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001507 QETH_DBF_TEXT(TRACE, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001508
1509 if (card->options.checksum_type == NO_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001510 dev_info(&card->gdev->dev,
1511 "Using no checksumming on %s.\n",
1512 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001513 return 0;
1514 }
1515 if (card->options.checksum_type == SW_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001516 dev_info(&card->gdev->dev,
1517 "Using SW checksumming on %s.\n",
1518 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001519 return 0;
1520 }
1521 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001522 dev_info(&card->gdev->dev,
1523 "Inbound HW Checksumming not "
1524 "supported on %s,\ncontinuing "
1525 "using Inbound SW Checksumming\n",
1526 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001527 card->options.checksum_type = SW_CHECKSUMMING;
1528 return 0;
1529 }
1530 rc = qeth_l3_send_checksum_command(card);
1531 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001532 dev_info(&card->gdev->dev,
1533 "HW Checksumming (inbound) enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001534
1535 return rc;
1536}
1537
1538static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1539{
1540 int rc;
1541
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001542 QETH_DBF_TEXT(TRACE, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001543
1544 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001545 dev_info(&card->gdev->dev,
1546 "Outbound TSO not supported on %s\n",
1547 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001548 rc = -EOPNOTSUPP;
1549 } else {
1550 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1551 IPA_CMD_ASS_START, 0);
1552 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001553 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1554 "segmentation offload for %s failed\n",
1555 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001556 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001557 dev_info(&card->gdev->dev,
1558 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001559 }
1560 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1561 card->options.large_send = QETH_LARGE_SEND_NO;
1562 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1563 }
1564 return rc;
1565}
1566
1567static int qeth_l3_start_ipassists(struct qeth_card *card)
1568{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001569 QETH_DBF_TEXT(TRACE, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001570
1571 qeth_set_access_ctrl_online(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001572 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1573 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1574 qeth_l3_start_ipa_source_mac(card); /* go on*/
1575 qeth_l3_start_ipa_vlan(card); /* go on*/
1576 qeth_l3_start_ipa_multicast(card); /* go on*/
1577 qeth_l3_start_ipa_ipv6(card); /* go on*/
1578 qeth_l3_start_ipa_broadcast(card); /* go on*/
1579 qeth_l3_start_ipa_checksum(card); /* go on*/
1580 qeth_l3_start_ipa_tso(card); /* go on*/
1581 return 0;
1582}
1583
1584static int qeth_l3_put_unique_id(struct qeth_card *card)
1585{
1586
1587 int rc = 0;
1588 struct qeth_cmd_buffer *iob;
1589 struct qeth_ipa_cmd *cmd;
1590
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001591 QETH_DBF_TEXT(TRACE, 2, "puniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001592
1593 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1594 UNIQUE_ID_NOT_BY_CARD)
1595 return -1;
1596 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1597 QETH_PROT_IPV6);
1598 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1599 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1600 card->info.unique_id;
1601 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1602 card->dev->dev_addr, OSA_ADDR_LEN);
1603 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1604 return rc;
1605}
1606
1607static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1608 struct qeth_reply *reply, unsigned long data)
1609{
1610 struct qeth_ipa_cmd *cmd;
1611
1612 cmd = (struct qeth_ipa_cmd *) data;
1613 if (cmd->hdr.return_code == 0)
1614 memcpy(card->dev->dev_addr,
1615 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1616 else
1617 random_ether_addr(card->dev->dev_addr);
1618
1619 return 0;
1620}
1621
1622static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1623{
1624 int rc = 0;
1625 struct qeth_cmd_buffer *iob;
1626 struct qeth_ipa_cmd *cmd;
1627
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001628 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001629
1630 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1631 QETH_PROT_IPV6);
1632 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1633 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1634 card->info.unique_id;
1635
1636 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1637 NULL);
1638 return rc;
1639}
1640
1641static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1642 struct qeth_reply *reply, unsigned long data)
1643{
1644 struct qeth_ipa_cmd *cmd;
1645
1646 cmd = (struct qeth_ipa_cmd *) data;
1647 if (cmd->hdr.return_code == 0)
1648 card->info.unique_id = *((__u16 *)
1649 &cmd->data.create_destroy_addr.unique_id[6]);
1650 else {
1651 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1652 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001653 dev_warn(&card->gdev->dev, "The network adapter failed to "
1654 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001655 }
1656 return 0;
1657}
1658
1659static int qeth_l3_get_unique_id(struct qeth_card *card)
1660{
1661 int rc = 0;
1662 struct qeth_cmd_buffer *iob;
1663 struct qeth_ipa_cmd *cmd;
1664
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001665 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001666
1667 if (!qeth_is_supported(card, IPA_IPV6)) {
1668 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1669 UNIQUE_ID_NOT_BY_CARD;
1670 return 0;
1671 }
1672
1673 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1674 QETH_PROT_IPV6);
1675 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1676 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1677 card->info.unique_id;
1678
1679 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1680 return rc;
1681}
1682
Ursula Braun76b11f82010-01-11 02:50:50 +00001683static int
1684qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1685 unsigned long data)
1686{
1687 struct qeth_ipa_cmd *cmd;
1688 __u16 rc;
1689
1690 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1691
1692 cmd = (struct qeth_ipa_cmd *)data;
1693 rc = cmd->hdr.return_code;
1694 if (rc) {
1695 QETH_DBF_TEXT_(TRACE, 2, "dxter%x", rc);
1696 if (cmd->data.diagass.action == QETH_DIAGS_CMD_TRACE_ENABLE) {
1697 switch (rc) {
1698 case IPA_RC_HARDWARE_AUTH_ERROR:
1699 dev_warn(&card->gdev->dev, "The device is not "
1700 "authorized to run as a HiperSockets "
1701 "network traffic analyzer\n");
1702 break;
1703 case IPA_RC_TRACE_ALREADY_ACTIVE:
1704 dev_warn(&card->gdev->dev, "A HiperSockets "
1705 "network traffic analyzer is already "
1706 "active in the HiperSockets LAN\n");
1707 break;
1708 default:
1709 break;
1710 }
1711 }
1712 return 0;
1713 }
1714
1715 switch (cmd->data.diagass.action) {
1716 case QETH_DIAGS_CMD_TRACE_QUERY:
1717 break;
1718 case QETH_DIAGS_CMD_TRACE_DISABLE:
1719 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1720 dev_info(&card->gdev->dev, "The HiperSockets network traffic "
1721 "analyzer is deactivated\n");
1722 break;
1723 case QETH_DIAGS_CMD_TRACE_ENABLE:
1724 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1725 dev_info(&card->gdev->dev, "The HiperSockets network traffic "
1726 "analyzer is activated\n");
1727 break;
1728 default:
1729 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1730 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1731 }
1732
1733 return 0;
1734}
1735
1736static int
1737qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1738{
1739 struct qeth_cmd_buffer *iob;
1740 struct qeth_ipa_cmd *cmd;
1741
1742 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1743
1744 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1745 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1746 cmd->data.diagass.subcmd_len = 16;
1747 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1748 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1749 cmd->data.diagass.action = diags_cmd;
1750 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1751}
1752
Frank Blaschka4a71df52008-02-15 09:19:42 +01001753static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1754 struct net_device *dev)
1755{
1756 if (dev->type == ARPHRD_IEEE802_TR)
1757 ip_tr_mc_map(ipm, mac);
1758 else
1759 ip_eth_mc_map(ipm, mac);
1760}
1761
1762static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1763{
1764 struct qeth_ipaddr *ipm;
1765 struct ip_mc_list *im4;
1766 char buf[MAX_ADDR_LEN];
1767
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001768 QETH_DBF_TEXT(TRACE, 4, "addmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001769 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1770 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1771 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1772 if (!ipm)
1773 continue;
1774 ipm->u.a4.addr = im4->multiaddr;
1775 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1776 ipm->is_multicast = 1;
1777 if (!qeth_l3_add_ip(card, ipm))
1778 kfree(ipm);
1779 }
1780}
1781
1782static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1783{
1784 struct in_device *in_dev;
1785 struct vlan_group *vg;
1786 int i;
1787
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001788 QETH_DBF_TEXT(TRACE, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001789 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1790 return;
1791
1792 vg = card->vlangrp;
1793 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1794 struct net_device *netdev = vlan_group_get_device(vg, i);
1795 if (netdev == NULL ||
1796 !(netdev->flags & IFF_UP))
1797 continue;
1798 in_dev = in_dev_get(netdev);
1799 if (!in_dev)
1800 continue;
1801 read_lock(&in_dev->mc_list_lock);
1802 qeth_l3_add_mc(card, in_dev);
1803 read_unlock(&in_dev->mc_list_lock);
1804 in_dev_put(in_dev);
1805 }
1806}
1807
1808static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1809{
1810 struct in_device *in4_dev;
1811
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001812 QETH_DBF_TEXT(TRACE, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001813 in4_dev = in_dev_get(card->dev);
1814 if (in4_dev == NULL)
1815 return;
1816 read_lock(&in4_dev->mc_list_lock);
1817 qeth_l3_add_mc(card, in4_dev);
1818 qeth_l3_add_vlan_mc(card);
1819 read_unlock(&in4_dev->mc_list_lock);
1820 in_dev_put(in4_dev);
1821}
1822
1823#ifdef CONFIG_QETH_IPV6
1824static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1825{
1826 struct qeth_ipaddr *ipm;
1827 struct ifmcaddr6 *im6;
1828 char buf[MAX_ADDR_LEN];
1829
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001830 QETH_DBF_TEXT(TRACE, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001831 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1832 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1833 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1834 if (!ipm)
1835 continue;
1836 ipm->is_multicast = 1;
1837 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1838 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1839 sizeof(struct in6_addr));
1840 if (!qeth_l3_add_ip(card, ipm))
1841 kfree(ipm);
1842 }
1843}
1844
1845static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1846{
1847 struct inet6_dev *in_dev;
1848 struct vlan_group *vg;
1849 int i;
1850
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001851 QETH_DBF_TEXT(TRACE, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001852 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1853 return;
1854
1855 vg = card->vlangrp;
1856 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1857 struct net_device *netdev = vlan_group_get_device(vg, i);
1858 if (netdev == NULL ||
1859 !(netdev->flags & IFF_UP))
1860 continue;
1861 in_dev = in6_dev_get(netdev);
1862 if (!in_dev)
1863 continue;
1864 read_lock_bh(&in_dev->lock);
1865 qeth_l3_add_mc6(card, in_dev);
1866 read_unlock_bh(&in_dev->lock);
1867 in6_dev_put(in_dev);
1868 }
1869}
1870
1871static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1872{
1873 struct inet6_dev *in6_dev;
1874
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001875 QETH_DBF_TEXT(TRACE, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001876 if (!qeth_is_supported(card, IPA_IPV6))
1877 return ;
1878 in6_dev = in6_dev_get(card->dev);
1879 if (in6_dev == NULL)
1880 return;
1881 read_lock_bh(&in6_dev->lock);
1882 qeth_l3_add_mc6(card, in6_dev);
1883 qeth_l3_add_vlan_mc6(card);
1884 read_unlock_bh(&in6_dev->lock);
1885 in6_dev_put(in6_dev);
1886}
1887#endif /* CONFIG_QETH_IPV6 */
1888
1889static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1890 unsigned short vid)
1891{
1892 struct in_device *in_dev;
1893 struct in_ifaddr *ifa;
1894 struct qeth_ipaddr *addr;
1895
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001896 QETH_DBF_TEXT(TRACE, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001897
1898 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1899 if (!in_dev)
1900 return;
1901 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1902 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1903 if (addr) {
1904 addr->u.a4.addr = ifa->ifa_address;
1905 addr->u.a4.mask = ifa->ifa_mask;
1906 addr->type = QETH_IP_TYPE_NORMAL;
1907 if (!qeth_l3_delete_ip(card, addr))
1908 kfree(addr);
1909 }
1910 }
1911 in_dev_put(in_dev);
1912}
1913
1914static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1915 unsigned short vid)
1916{
1917#ifdef CONFIG_QETH_IPV6
1918 struct inet6_dev *in6_dev;
1919 struct inet6_ifaddr *ifa;
1920 struct qeth_ipaddr *addr;
1921
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001922 QETH_DBF_TEXT(TRACE, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001923
1924 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1925 if (!in6_dev)
1926 return;
1927 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) {
1928 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1929 if (addr) {
1930 memcpy(&addr->u.a6.addr, &ifa->addr,
1931 sizeof(struct in6_addr));
1932 addr->u.a6.pfxlen = ifa->prefix_len;
1933 addr->type = QETH_IP_TYPE_NORMAL;
1934 if (!qeth_l3_delete_ip(card, addr))
1935 kfree(addr);
1936 }
1937 }
1938 in6_dev_put(in6_dev);
1939#endif /* CONFIG_QETH_IPV6 */
1940}
1941
1942static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1943 unsigned short vid)
1944{
1945 if (!card->vlangrp)
1946 return;
1947 qeth_l3_free_vlan_addresses4(card, vid);
1948 qeth_l3_free_vlan_addresses6(card, vid);
1949}
1950
1951static void qeth_l3_vlan_rx_register(struct net_device *dev,
1952 struct vlan_group *grp)
1953{
Heiko Carstens509e2562008-07-26 02:24:10 -07001954 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001955 unsigned long flags;
1956
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001957 QETH_DBF_TEXT(TRACE, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001958 spin_lock_irqsave(&card->vlanlock, flags);
1959 card->vlangrp = grp;
1960 spin_unlock_irqrestore(&card->vlanlock, flags);
1961}
1962
1963static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1964{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001965 return;
1966}
1967
1968static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1969{
Heiko Carstens509e2562008-07-26 02:24:10 -07001970 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001971 unsigned long flags;
1972
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001973 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00001974 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
1975 QETH_DBF_TEXT(TRACE, 3, "kidREC");
1976 return;
1977 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001978 spin_lock_irqsave(&card->vlanlock, flags);
1979 /* unregister IP addresses of vlan device */
1980 qeth_l3_free_vlan_addresses(card, vid);
1981 vlan_group_set_device(card->vlangrp, vid, NULL);
1982 spin_unlock_irqrestore(&card->vlanlock, flags);
1983 qeth_l3_set_multicast_list(card->dev);
1984}
1985
1986static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card,
1987 struct sk_buff *skb, struct qeth_hdr *hdr)
1988{
1989 unsigned short vlan_id = 0;
1990 __be16 prot;
1991 struct iphdr *ip_hdr;
1992 unsigned char tg_addr[MAX_ADDR_LEN];
1993
1994 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1995 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1996 ETH_P_IP);
1997 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1998 case QETH_CAST_MULTICAST:
1999 switch (prot) {
2000#ifdef CONFIG_QETH_IPV6
2001 case __constant_htons(ETH_P_IPV6):
2002 ndisc_mc_map((struct in6_addr *)
2003 skb->data + 24,
2004 tg_addr, card->dev, 0);
2005 break;
2006#endif
2007 case __constant_htons(ETH_P_IP):
2008 ip_hdr = (struct iphdr *)skb->data;
2009 (card->dev->type == ARPHRD_IEEE802_TR) ?
2010 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
2011 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
2012 break;
2013 default:
2014 memcpy(tg_addr, card->dev->broadcast,
2015 card->dev->addr_len);
2016 }
2017 card->stats.multicast++;
2018 skb->pkt_type = PACKET_MULTICAST;
2019 break;
2020 case QETH_CAST_BROADCAST:
2021 memcpy(tg_addr, card->dev->broadcast,
2022 card->dev->addr_len);
2023 card->stats.multicast++;
2024 skb->pkt_type = PACKET_BROADCAST;
2025 break;
2026 case QETH_CAST_UNICAST:
2027 case QETH_CAST_ANYCAST:
2028 case QETH_CAST_NOCAST:
2029 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00002030 if (card->options.sniffer)
2031 skb->pkt_type = PACKET_OTHERHOST;
2032 else
2033 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002034 memcpy(tg_addr, card->dev->dev_addr,
2035 card->dev->addr_len);
2036 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08002037 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2038 card->dev->header_ops->create(skb, card->dev, prot,
2039 tg_addr, &hdr->hdr.l3.dest_addr[2],
2040 card->dev->addr_len);
2041 else
2042 card->dev->header_ops->create(skb, card->dev, prot,
2043 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002044 }
2045
2046#ifdef CONFIG_TR
2047 if (card->dev->type == ARPHRD_IEEE802_TR)
2048 skb->protocol = tr_type_trans(skb, card->dev);
2049 else
2050#endif
2051 skb->protocol = eth_type_trans(skb, card->dev);
2052
2053 if (hdr->hdr.l3.ext_flags &
2054 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2055 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2056 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2057 }
2058
Ursula Braunb9139802009-05-19 21:38:40 +00002059 switch (card->options.checksum_type) {
2060 case SW_CHECKSUMMING:
2061 skb->ip_summed = CHECKSUM_NONE;
2062 break;
2063 case NO_CHECKSUMMING:
2064 skb->ip_summed = CHECKSUM_UNNECESSARY;
2065 break;
2066 case HW_CHECKSUMMING:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002067 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00002068 (QETH_HDR_EXT_CSUM_HDR_REQ |
2069 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2070 (QETH_HDR_EXT_CSUM_HDR_REQ |
2071 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002072 skb->ip_summed = CHECKSUM_UNNECESSARY;
2073 else
Ursula Braunb9139802009-05-19 21:38:40 +00002074 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002075 }
2076
2077 return vlan_id;
2078}
2079
2080static void qeth_l3_process_inbound_buffer(struct qeth_card *card,
2081 struct qeth_qdio_buffer *buf, int index)
2082{
2083 struct qdio_buffer_element *element;
2084 struct sk_buff *skb;
2085 struct qeth_hdr *hdr;
2086 int offset;
2087 __u16 vlan_tag = 0;
2088 unsigned int len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002089 /* get first element of current buffer */
2090 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2091 offset = 0;
2092 if (card->options.performance_stats)
2093 card->perf_stats.bufs_rec++;
2094 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
2095 &offset, &hdr))) {
2096 skb->dev = card->dev;
2097 /* is device UP ? */
2098 if (!(card->dev->flags & IFF_UP)) {
2099 dev_kfree_skb_any(skb);
2100 continue;
2101 }
2102
2103 switch (hdr->hdr.l3.id) {
2104 case QETH_HEADER_TYPE_LAYER3:
2105 vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr);
2106 len = skb->len;
Ursula Braun76b11f82010-01-11 02:50:50 +00002107 if (vlan_tag && !card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002108 if (card->vlangrp)
2109 vlan_hwaccel_rx(skb, card->vlangrp,
2110 vlan_tag);
2111 else {
2112 dev_kfree_skb_any(skb);
2113 continue;
2114 }
2115 else
2116 netif_rx(skb);
2117 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002118 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2119 skb->pkt_type = PACKET_HOST;
2120 skb->protocol = eth_type_trans(skb, skb->dev);
2121 if (card->options.checksum_type == NO_CHECKSUMMING)
2122 skb->ip_summed = CHECKSUM_UNNECESSARY;
2123 else
2124 skb->ip_summed = CHECKSUM_NONE;
2125 len = skb->len;
2126 netif_receive_skb(skb);
2127 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002128 default:
2129 dev_kfree_skb_any(skb);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002130 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
2131 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002132 continue;
2133 }
2134
Frank Blaschka4a71df52008-02-15 09:19:42 +01002135 card->stats.rx_packets++;
2136 card->stats.rx_bytes += len;
2137 }
2138}
2139
2140static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2141 struct qeth_card *card)
2142{
2143 int rc = 0;
2144 struct vlan_group *vg;
2145 int i;
2146
2147 vg = card->vlangrp;
2148 if (!vg)
2149 return rc;
2150
2151 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
2152 if (vlan_group_get_device(vg, i) == dev) {
2153 rc = QETH_VLAN_CARD;
2154 break;
2155 }
2156 }
2157
Heiko Carstens509e2562008-07-26 02:24:10 -07002158 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002159 return 0;
2160
2161 return rc;
2162}
2163
2164static int qeth_l3_verify_dev(struct net_device *dev)
2165{
2166 struct qeth_card *card;
2167 unsigned long flags;
2168 int rc = 0;
2169
2170 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2171 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2172 if (card->dev == dev) {
2173 rc = QETH_REAL_CARD;
2174 break;
2175 }
2176 rc = qeth_l3_verify_vlan_dev(dev, card);
2177 if (rc)
2178 break;
2179 }
2180 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2181
2182 return rc;
2183}
2184
2185static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2186{
2187 struct qeth_card *card = NULL;
2188 int rc;
2189
2190 rc = qeth_l3_verify_dev(dev);
2191 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002192 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002193 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002194 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002195 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002196 card = NULL;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002197 QETH_DBF_TEXT_(TRACE, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002198 return card ;
2199}
2200
2201static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2202{
2203 int rc = 0;
2204
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002205 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2206 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002207
2208 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002209 if (card->options.sniffer &&
2210 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2211 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002212 if (card->read.state == CH_STATE_UP &&
2213 card->write.state == CH_STATE_UP &&
2214 (card->state == CARD_STATE_UP)) {
2215 if (recovery_mode)
2216 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002217 else {
Ursula Braunfc9c2462009-01-04 17:35:18 -08002218 if (card->dev) {
2219 rtnl_lock();
2220 dev_close(card->dev);
2221 rtnl_unlock();
2222 }
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002223 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002224 if (!card->use_hard_stop) {
2225 rc = qeth_send_stoplan(card);
2226 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002227 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002228 }
2229 card->state = CARD_STATE_SOFTSETUP;
2230 }
2231 if (card->state == CARD_STATE_SOFTSETUP) {
2232 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2233 qeth_clear_ipacmd_list(card);
2234 card->state = CARD_STATE_HARDSETUP;
2235 }
2236 if (card->state == CARD_STATE_HARDSETUP) {
2237 if (!card->use_hard_stop &&
2238 (card->info.type != QETH_CARD_TYPE_IQD)) {
2239 rc = qeth_l3_put_unique_id(card);
2240 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002241 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002242 }
2243 qeth_qdio_clear_card(card, 0);
2244 qeth_clear_qdio_buffers(card);
2245 qeth_clear_working_pool_list(card);
2246 card->state = CARD_STATE_DOWN;
2247 }
2248 if (card->state == CARD_STATE_DOWN) {
2249 qeth_clear_cmd_buffers(&card->read);
2250 qeth_clear_cmd_buffers(&card->write);
2251 }
2252 card->use_hard_stop = 0;
2253 return rc;
2254}
2255
Ursula Braun76b11f82010-01-11 02:50:50 +00002256/*
2257 * test for and Switch promiscuous mode (on or off)
2258 * either for guestlan or HiperSocket Sniffer
2259 */
2260static void
2261qeth_l3_handle_promisc_mode(struct qeth_card *card)
2262{
2263 struct net_device *dev = card->dev;
2264
2265 if (((dev->flags & IFF_PROMISC) &&
2266 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2267 (!(dev->flags & IFF_PROMISC) &&
2268 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2269 return;
2270
2271 if (card->info.guestlan) { /* Guestlan trace */
2272 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2273 qeth_setadp_promisc_mode(card);
2274 } else if (card->options.sniffer && /* HiperSockets trace */
2275 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2276 if (dev->flags & IFF_PROMISC) {
2277 QETH_DBF_TEXT(TRACE, 3, "+promisc");
2278 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2279 } else {
2280 QETH_DBF_TEXT(TRACE, 3, "-promisc");
2281 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2282 }
2283 }
2284}
2285
Frank Blaschka4a71df52008-02-15 09:19:42 +01002286static void qeth_l3_set_multicast_list(struct net_device *dev)
2287{
Heiko Carstens509e2562008-07-26 02:24:10 -07002288 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002289
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002290 QETH_DBF_TEXT(TRACE, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002291 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2292 (card->state != CARD_STATE_UP))
2293 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002294 if (!card->options.sniffer) {
2295 qeth_l3_delete_mc_addresses(card);
2296 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002297#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002298 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002299#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002300 qeth_l3_set_ip_addr_list(card);
2301 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2302 return;
2303 }
2304 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002305}
2306
2307static const char *qeth_l3_arp_get_error_cause(int *rc)
2308{
2309 switch (*rc) {
2310 case QETH_IPA_ARP_RC_FAILED:
2311 *rc = -EIO;
2312 return "operation failed";
2313 case QETH_IPA_ARP_RC_NOTSUPP:
2314 *rc = -EOPNOTSUPP;
2315 return "operation not supported";
2316 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2317 *rc = -EINVAL;
2318 return "argument out of range";
2319 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2320 *rc = -EOPNOTSUPP;
2321 return "query operation not supported";
2322 case QETH_IPA_ARP_RC_Q_NO_DATA:
2323 *rc = -ENOENT;
2324 return "no query data available";
2325 default:
2326 return "unknown error";
2327 }
2328}
2329
2330static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2331{
2332 int tmp;
2333 int rc;
2334
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002335 QETH_DBF_TEXT(TRACE, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002336
2337 /*
2338 * currently GuestLAN only supports the ARP assist function
2339 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2340 * thus we say EOPNOTSUPP for this ARP function
2341 */
2342 if (card->info.guestlan)
2343 return -EOPNOTSUPP;
2344 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002345 return -EOPNOTSUPP;
2346 }
2347 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2348 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2349 no_entries);
2350 if (rc) {
2351 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002352 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2353 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002354 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2355 }
2356 return rc;
2357}
2358
2359static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2360 struct qeth_arp_query_data *qdata, int entry_size,
2361 int uentry_size)
2362{
2363 char *entry_ptr;
2364 char *uentry_ptr;
2365 int i;
2366
2367 entry_ptr = (char *)&qdata->data;
2368 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2369 for (i = 0; i < qdata->no_entries; ++i) {
2370 /* strip off 32 bytes "media specific information" */
2371 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2372 entry_ptr += entry_size;
2373 uentry_ptr += uentry_size;
2374 }
2375}
2376
2377static int qeth_l3_arp_query_cb(struct qeth_card *card,
2378 struct qeth_reply *reply, unsigned long data)
2379{
2380 struct qeth_ipa_cmd *cmd;
2381 struct qeth_arp_query_data *qdata;
2382 struct qeth_arp_query_info *qinfo;
2383 int entry_size;
2384 int uentry_size;
2385 int i;
2386
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002387 QETH_DBF_TEXT(TRACE, 4, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002388
2389 qinfo = (struct qeth_arp_query_info *) reply->param;
2390 cmd = (struct qeth_ipa_cmd *) data;
2391 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002392 QETH_DBF_TEXT_(TRACE, 4, "qaer1%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002393 return 0;
2394 }
2395 if (cmd->data.setassparms.hdr.return_code) {
2396 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002397 QETH_DBF_TEXT_(TRACE, 4, "qaer2%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002398 return 0;
2399 }
2400 qdata = &cmd->data.setassparms.data.query_arp;
2401 switch (qdata->reply_bits) {
2402 case 5:
2403 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2404 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2405 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2406 break;
2407 case 7:
2408 /* fall through to default */
2409 default:
2410 /* tr is the same as eth -> entry7 */
2411 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2412 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2413 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2414 break;
2415 }
2416 /* check if there is enough room in userspace */
2417 if ((qinfo->udata_len - qinfo->udata_offset) <
2418 qdata->no_entries * uentry_size){
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002419 QETH_DBF_TEXT_(TRACE, 4, "qaer3%i", -ENOMEM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002420 cmd->hdr.return_code = -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002421 goto out_error;
2422 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002423 QETH_DBF_TEXT_(TRACE, 4, "anore%i",
Frank Blaschka4a71df52008-02-15 09:19:42 +01002424 cmd->data.setassparms.hdr.number_of_replies);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002425 QETH_DBF_TEXT_(TRACE, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2426 QETH_DBF_TEXT_(TRACE, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002427
2428 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2429 /* strip off "media specific information" */
2430 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2431 uentry_size);
2432 } else
2433 /*copy entries to user buffer*/
2434 memcpy(qinfo->udata + qinfo->udata_offset,
2435 (char *)&qdata->data, qdata->no_entries*uentry_size);
2436
2437 qinfo->no_entries += qdata->no_entries;
2438 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2439 /* check if all replies received ... */
2440 if (cmd->data.setassparms.hdr.seq_no <
2441 cmd->data.setassparms.hdr.number_of_replies)
2442 return 1;
2443 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2444 /* keep STRIP_ENTRIES flag so the user program can distinguish
2445 * stripped entries from normal ones */
2446 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2447 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2448 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2449 return 0;
2450out_error:
2451 i = 0;
2452 memcpy(qinfo->udata, &i, 4);
2453 return 0;
2454}
2455
2456static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2457 struct qeth_cmd_buffer *iob, int len,
2458 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2459 unsigned long),
2460 void *reply_param)
2461{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002462 QETH_DBF_TEXT(TRACE, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002463
2464 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2465 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2466 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2467 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2468 reply_cb, reply_param);
2469}
2470
2471static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2472{
2473 struct qeth_cmd_buffer *iob;
2474 struct qeth_arp_query_info qinfo = {0, };
2475 int tmp;
2476 int rc;
2477
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002478 QETH_DBF_TEXT(TRACE, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002479
2480 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2481 IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002482 return -EOPNOTSUPP;
2483 }
2484 /* get size of userspace buffer and mask_bits -> 6 bytes */
2485 if (copy_from_user(&qinfo, udata, 6))
2486 return -EFAULT;
2487 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2488 if (!qinfo.udata)
2489 return -ENOMEM;
2490 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2491 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2492 IPA_CMD_ASS_ARP_QUERY_INFO,
2493 sizeof(int), QETH_PROT_IPV4);
2494
2495 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2496 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2497 qeth_l3_arp_query_cb, (void *)&qinfo);
2498 if (rc) {
2499 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002500 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
Frank Blaschka4a71df52008-02-15 09:19:42 +01002501 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2502 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2503 if (copy_to_user(udata, qinfo.udata, 4))
2504 rc = -EFAULT;
2505 } else {
2506 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2507 rc = -EFAULT;
2508 }
2509 kfree(qinfo.udata);
2510 return rc;
2511}
2512
2513static int qeth_l3_arp_add_entry(struct qeth_card *card,
2514 struct qeth_arp_cache_entry *entry)
2515{
2516 struct qeth_cmd_buffer *iob;
2517 char buf[16];
2518 int tmp;
2519 int rc;
2520
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002521 QETH_DBF_TEXT(TRACE, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002522
2523 /*
2524 * currently GuestLAN only supports the ARP assist function
2525 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2526 * thus we say EOPNOTSUPP for this ARP function
2527 */
2528 if (card->info.guestlan)
2529 return -EOPNOTSUPP;
2530 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002531 return -EOPNOTSUPP;
2532 }
2533
2534 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2535 IPA_CMD_ASS_ARP_ADD_ENTRY,
2536 sizeof(struct qeth_arp_cache_entry),
2537 QETH_PROT_IPV4);
2538 rc = qeth_l3_send_setassparms(card, iob,
2539 sizeof(struct qeth_arp_cache_entry),
2540 (unsigned long) entry,
2541 qeth_l3_default_setassparms_cb, NULL);
2542 if (rc) {
2543 tmp = rc;
2544 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002545 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2546 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2547 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002548 }
2549 return rc;
2550}
2551
2552static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2553 struct qeth_arp_cache_entry *entry)
2554{
2555 struct qeth_cmd_buffer *iob;
2556 char buf[16] = {0, };
2557 int tmp;
2558 int rc;
2559
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002560 QETH_DBF_TEXT(TRACE, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002561
2562 /*
2563 * currently GuestLAN only supports the ARP assist function
2564 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2565 * thus we say EOPNOTSUPP for this ARP function
2566 */
2567 if (card->info.guestlan)
2568 return -EOPNOTSUPP;
2569 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002570 return -EOPNOTSUPP;
2571 }
2572 memcpy(buf, entry, 12);
2573 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2574 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2575 12,
2576 QETH_PROT_IPV4);
2577 rc = qeth_l3_send_setassparms(card, iob,
2578 12, (unsigned long)buf,
2579 qeth_l3_default_setassparms_cb, NULL);
2580 if (rc) {
2581 tmp = rc;
2582 memset(buf, 0, 16);
2583 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002584 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2585 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2586 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002587 }
2588 return rc;
2589}
2590
2591static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2592{
2593 int rc;
2594 int tmp;
2595
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002596 QETH_DBF_TEXT(TRACE, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002597
2598 /*
2599 * currently GuestLAN only supports the ARP assist function
2600 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2601 * thus we say EOPNOTSUPP for this ARP function
2602 */
2603 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2604 return -EOPNOTSUPP;
2605 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002606 return -EOPNOTSUPP;
2607 }
2608 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2609 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2610 if (rc) {
2611 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002612 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2613 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002614 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2615 }
2616 return rc;
2617}
2618
2619static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2620{
Heiko Carstens509e2562008-07-26 02:24:10 -07002621 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002622 struct qeth_arp_cache_entry arp_entry;
2623 struct mii_ioctl_data *mii_data;
2624 int rc = 0;
2625
2626 if (!card)
2627 return -ENODEV;
2628
2629 if ((card->state != CARD_STATE_UP) &&
2630 (card->state != CARD_STATE_SOFTSETUP))
2631 return -ENODEV;
2632
2633 switch (cmd) {
2634 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2635 if (!capable(CAP_NET_ADMIN)) {
2636 rc = -EPERM;
2637 break;
2638 }
2639 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2640 break;
2641 case SIOC_QETH_ARP_QUERY_INFO:
2642 if (!capable(CAP_NET_ADMIN)) {
2643 rc = -EPERM;
2644 break;
2645 }
2646 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2647 break;
2648 case SIOC_QETH_ARP_ADD_ENTRY:
2649 if (!capable(CAP_NET_ADMIN)) {
2650 rc = -EPERM;
2651 break;
2652 }
2653 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2654 sizeof(struct qeth_arp_cache_entry)))
2655 rc = -EFAULT;
2656 else
2657 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2658 break;
2659 case SIOC_QETH_ARP_REMOVE_ENTRY:
2660 if (!capable(CAP_NET_ADMIN)) {
2661 rc = -EPERM;
2662 break;
2663 }
2664 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2665 sizeof(struct qeth_arp_cache_entry)))
2666 rc = -EFAULT;
2667 else
2668 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2669 break;
2670 case SIOC_QETH_ARP_FLUSH_CACHE:
2671 if (!capable(CAP_NET_ADMIN)) {
2672 rc = -EPERM;
2673 break;
2674 }
2675 rc = qeth_l3_arp_flush_cache(card);
2676 break;
2677 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2678 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2679 break;
2680 case SIOC_QETH_GET_CARD_TYPE:
2681 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
2682 !card->info.guestlan)
2683 return 1;
2684 return 0;
2685 break;
2686 case SIOCGMIIPHY:
2687 mii_data = if_mii(rq);
2688 mii_data->phy_id = 0;
2689 break;
2690 case SIOCGMIIREG:
2691 mii_data = if_mii(rq);
2692 if (mii_data->phy_id != 0)
2693 rc = -EINVAL;
2694 else
2695 mii_data->val_out = qeth_mdio_read(dev,
2696 mii_data->phy_id,
2697 mii_data->reg_num);
2698 break;
2699 default:
2700 rc = -EOPNOTSUPP;
2701 }
2702 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002703 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002704 return rc;
2705}
2706
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002707int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2708{
2709 int cast_type = RTN_UNSPEC;
2710
2711 if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2712 cast_type = skb_dst(skb)->neighbour->type;
2713 if ((cast_type == RTN_BROADCAST) ||
2714 (cast_type == RTN_MULTICAST) ||
2715 (cast_type == RTN_ANYCAST))
2716 return cast_type;
2717 else
2718 return RTN_UNSPEC;
2719 }
2720 /* try something else */
2721 if (skb->protocol == ETH_P_IPV6)
2722 return (skb_network_header(skb)[24] == 0xff) ?
2723 RTN_MULTICAST : 0;
2724 else if (skb->protocol == ETH_P_IP)
2725 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2726 RTN_MULTICAST : 0;
2727 /* ... */
2728 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2729 return RTN_BROADCAST;
2730 else {
2731 u16 hdr_mac;
2732
2733 hdr_mac = *((u16 *)skb->data);
2734 /* tr multicast? */
2735 switch (card->info.link_type) {
2736 case QETH_LINK_TYPE_HSTR:
2737 case QETH_LINK_TYPE_LANE_TR:
2738 if ((hdr_mac == QETH_TR_MAC_NC) ||
2739 (hdr_mac == QETH_TR_MAC_C))
2740 return RTN_MULTICAST;
2741 break;
2742 /* eth or so multicast? */
2743 default:
2744 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2745 (hdr_mac == QETH_ETH_MAC_V6))
2746 return RTN_MULTICAST;
2747 }
2748 }
2749 return cast_type;
2750}
2751
Frank Blaschka4a71df52008-02-15 09:19:42 +01002752static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2753 struct sk_buff *skb, int ipv, int cast_type)
2754{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002755 memset(hdr, 0, sizeof(struct qeth_hdr));
2756 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2757 hdr->hdr.l3.ext_flags = 0;
2758
2759 /*
2760 * before we're going to overwrite this location with next hop ip.
2761 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2762 */
2763 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002764 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2765 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2766 else
2767 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002768 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2769 }
2770
2771 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2772 if (ipv == 4) {
2773 /* IPv4 */
2774 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2775 memset(hdr->hdr.l3.dest_addr, 0, 12);
Eric Dumazetadf30902009-06-02 05:19:30 +00002776 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002777 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
Eric Dumazetadf30902009-06-02 05:19:30 +00002778 *((u32 *) skb_dst(skb)->neighbour->primary_key);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002779 } else {
2780 /* fill in destination address used in ip header */
2781 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2782 ip_hdr(skb)->daddr;
2783 }
2784 } else if (ipv == 6) {
2785 /* IPv6 */
2786 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2787 if (card->info.type == QETH_CARD_TYPE_IQD)
2788 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
Eric Dumazetadf30902009-06-02 05:19:30 +00002789 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002790 memcpy(hdr->hdr.l3.dest_addr,
Eric Dumazetadf30902009-06-02 05:19:30 +00002791 skb_dst(skb)->neighbour->primary_key, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002792 } else {
2793 /* fill in destination address used in ip header */
2794 memcpy(hdr->hdr.l3.dest_addr,
2795 &ipv6_hdr(skb)->daddr, 16);
2796 }
2797 } else {
2798 /* passthrough */
2799 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2800 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2801 sizeof(__u16), skb->dev->broadcast, 6)) {
2802 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2803 QETH_HDR_PASSTHRU;
2804 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2805 skb->dev->broadcast, 6)) {
2806 /* broadcast? */
2807 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2808 QETH_HDR_PASSTHRU;
2809 } else {
2810 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2811 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2812 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2813 }
2814 }
2815}
2816
Frank Blaschka64ef8952009-03-24 20:57:16 +00002817static void qeth_tso_fill_header(struct qeth_card *card,
2818 struct qeth_hdr *qhdr, struct sk_buff *skb)
2819{
2820 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2821 struct tcphdr *tcph = tcp_hdr(skb);
2822 struct iphdr *iph = ip_hdr(skb);
2823 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2824
2825 /*fix header to TSO values ...*/
2826 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
2827 /*set values which are fix for the first approach ...*/
2828 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2829 hdr->ext.imb_hdr_no = 1;
2830 hdr->ext.hdr_type = 1;
2831 hdr->ext.hdr_version = 1;
2832 hdr->ext.hdr_len = 28;
2833 /*insert non-fix values */
2834 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2835 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2836 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2837 sizeof(struct qeth_hdr_tso));
2838 tcph->check = 0;
2839 if (skb->protocol == ETH_P_IPV6) {
2840 ip6h->payload_len = 0;
2841 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2842 0, IPPROTO_TCP, 0);
2843 } else {
2844 /*OSA want us to set these values ...*/
2845 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2846 0, IPPROTO_TCP, 0);
2847 iph->tot_len = 0;
2848 iph->check = 0;
2849 }
2850}
2851
2852static void qeth_tx_csum(struct sk_buff *skb)
2853{
2854 __wsum csum;
2855 int offset;
2856
2857 skb_set_transport_header(skb, skb->csum_start - skb_headroom(skb));
2858 offset = skb->csum_start - skb_headroom(skb);
2859 BUG_ON(offset >= skb_headlen(skb));
2860 csum = skb_checksum(skb, offset, skb->len - offset, 0);
2861
2862 offset += skb->csum_offset;
2863 BUG_ON(offset + sizeof(__sum16) > skb_headlen(skb));
2864 *(__sum16 *)(skb->data + offset) = csum_fold(csum);
2865}
2866
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002867static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2868{
2869 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2870 tcp_hdr(skb)->doff * 4;
2871 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
2872 int elements = PFN_UP(tcpd + tcpd_len) - PFN_DOWN(tcpd);
2873 elements += skb_shinfo(skb)->nr_frags;
2874 return elements;
2875}
2876
2877static inline int qeth_l3_tso_check(struct sk_buff *skb)
2878{
2879 int len = ((unsigned long)tcp_hdr(skb) + tcp_hdr(skb)->doff * 4) -
2880 (unsigned long)skb->data;
2881 return (((unsigned long)skb->data & PAGE_MASK) !=
2882 (((unsigned long)skb->data + len) & PAGE_MASK));
2883}
2884
Frank Blaschka4a71df52008-02-15 09:19:42 +01002885static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2886{
2887 int rc;
2888 u16 *tag;
2889 struct qeth_hdr *hdr = NULL;
2890 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002891 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002892 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002893 struct sk_buff *new_skb = NULL;
2894 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002895 int cast_type = qeth_l3_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002896 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2897 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2898 int tx_bytes = skb->len;
2899 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
Frank Blaschka683d7182008-08-01 16:39:13 +02002900 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002901 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002902
Frank Blaschka21fde742010-03-08 20:36:54 +00002903 if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
2904 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002905 goto tx_drop;
2906
2907 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2908 card->stats.tx_carrier_errors++;
2909 goto tx_drop;
2910 }
2911
2912 if ((cast_type == RTN_BROADCAST) &&
2913 (card->info.broadcast_capable == 0))
2914 goto tx_drop;
2915
2916 if (card->options.performance_stats) {
2917 card->perf_stats.outbound_cnt++;
2918 card->perf_stats.outbound_start_time = qeth_get_micros();
2919 }
2920
Frank Blaschka683d7182008-08-01 16:39:13 +02002921 if (skb_is_gso(skb))
2922 large_send = card->options.large_send;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002923 else
2924 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2925 qeth_tx_csum(skb);
2926 if (card->options.performance_stats)
2927 card->perf_stats.tx_csum++;
2928 }
Frank Blaschka683d7182008-08-01 16:39:13 +02002929
2930 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2931 (skb_shinfo(skb)->nr_frags == 0)) {
2932 new_skb = skb;
2933 data_offset = ETH_HLEN;
2934 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2935 if (!hdr)
2936 goto tx_drop;
2937 elements_needed++;
2938 } else {
2939 /* create a clone with writeable headroom */
2940 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2941 + VLAN_HLEN);
2942 if (!new_skb)
2943 goto tx_drop;
2944 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002945
2946 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002947 if (data_offset < 0)
2948 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002949 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00002950 if (ipv == 4) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002951 if (card->dev->type == ARPHRD_IEEE802_TR)
2952 skb_pull(new_skb, TR_HLEN);
2953 else
2954 skb_pull(new_skb, ETH_HLEN);
2955 }
2956
Frank Blaschka21fde742010-03-08 20:36:54 +00002957 if (ipv == 6 && card->vlangrp &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002958 vlan_tx_tag_present(new_skb)) {
2959 skb_push(new_skb, VLAN_HLEN);
2960 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2961 skb_copy_to_linear_data_offset(new_skb, 4,
2962 new_skb->data + 8, 4);
2963 skb_copy_to_linear_data_offset(new_skb, 8,
2964 new_skb->data + 12, 4);
2965 tag = (u16 *)(new_skb->data + 12);
2966 *tag = __constant_htons(ETH_P_8021Q);
2967 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02002968 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002969 }
2970 }
2971
2972 netif_stop_queue(dev);
2973
Frank Blaschka4a71df52008-02-15 09:19:42 +01002974 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002975 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002976 */
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002977 if (large_send == QETH_LARGE_SEND_TSO) {
2978 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
2979 if (skb_linearize(new_skb))
2980 goto tx_drop;
2981 if (card->options.performance_stats)
2982 card->perf_stats.tx_lin++;
2983 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00002984 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002985
2986 if ((large_send == QETH_LARGE_SEND_TSO) &&
2987 (cast_type == RTN_UNSPEC)) {
2988 hdr = (struct qeth_hdr *)skb_push(new_skb,
2989 sizeof(struct qeth_hdr_tso));
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002990 if (qeth_l3_tso_check(new_skb))
2991 QETH_DBF_MESSAGE(2, "tso skb misaligned\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002992 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2993 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2994 qeth_tso_fill_header(card, hdr, new_skb);
2995 elements_needed++;
2996 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002997 if (data_offset < 0) {
2998 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002999 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003000 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3001 cast_type);
3002 } else {
3003 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3004 cast_type);
3005 hdr->hdr.l3.length = new_skb->len - data_offset;
3006 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003007 }
3008
Frank Blaschka64ef8952009-03-24 20:57:16 +00003009 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003010 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003011 if (!elems) {
3012 if (data_offset >= 0)
3013 kmem_cache_free(qeth_core_header_cache, hdr);
3014 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003015 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003016 elements_needed += elems;
3017 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003018
3019 if (card->info.type != QETH_CARD_TYPE_IQD)
3020 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003021 elements_needed);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003022 else
3023 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003024 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003025
3026 if (!rc) {
3027 card->stats.tx_packets++;
3028 card->stats.tx_bytes += tx_bytes;
3029 if (new_skb != skb)
3030 dev_kfree_skb_any(skb);
3031 if (card->options.performance_stats) {
3032 if (large_send != QETH_LARGE_SEND_NO) {
3033 card->perf_stats.large_send_bytes += tx_bytes;
3034 card->perf_stats.large_send_cnt++;
3035 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003036 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003037 card->perf_stats.sg_skbs_sent++;
3038 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003039 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003040 }
3041 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003042 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003043 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003044 if (data_offset >= 0)
3045 kmem_cache_free(qeth_core_header_cache, hdr);
3046
Frank Blaschka4a71df52008-02-15 09:19:42 +01003047 if (rc == -EBUSY) {
3048 if (new_skb != skb)
3049 dev_kfree_skb_any(new_skb);
3050 return NETDEV_TX_BUSY;
3051 } else
3052 goto tx_drop;
3053 }
3054
3055 netif_wake_queue(dev);
3056 if (card->options.performance_stats)
3057 card->perf_stats.outbound_time += qeth_get_micros() -
3058 card->perf_stats.outbound_start_time;
3059 return rc;
3060
3061tx_drop:
3062 card->stats.tx_dropped++;
3063 card->stats.tx_errors++;
3064 if ((new_skb != skb) && new_skb)
3065 dev_kfree_skb_any(new_skb);
3066 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003067 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003068 return NETDEV_TX_OK;
3069}
3070
3071static int qeth_l3_open(struct net_device *dev)
3072{
Heiko Carstens509e2562008-07-26 02:24:10 -07003073 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003074
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003075 QETH_DBF_TEXT(TRACE, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003076 if (card->state != CARD_STATE_SOFTSETUP)
3077 return -ENODEV;
3078 card->data.state = CH_STATE_UP;
3079 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003080 netif_start_queue(dev);
3081
3082 if (!card->lan_online && netif_carrier_ok(dev))
3083 netif_carrier_off(dev);
3084 return 0;
3085}
3086
3087static int qeth_l3_stop(struct net_device *dev)
3088{
Heiko Carstens509e2562008-07-26 02:24:10 -07003089 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003090
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003091 QETH_DBF_TEXT(TRACE, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003092 netif_tx_disable(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003093 if (card->state == CARD_STATE_UP)
3094 card->state = CARD_STATE_SOFTSETUP;
3095 return 0;
3096}
3097
3098static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
3099{
Heiko Carstens509e2562008-07-26 02:24:10 -07003100 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003101
3102 return (card->options.checksum_type == HW_CHECKSUMMING);
3103}
3104
3105static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
3106{
Heiko Carstens509e2562008-07-26 02:24:10 -07003107 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003108 enum qeth_checksum_types csum_type;
3109
Frank Blaschka4a71df52008-02-15 09:19:42 +01003110 if (data)
3111 csum_type = HW_CHECKSUMMING;
3112 else
3113 csum_type = SW_CHECKSUMMING;
3114
Frank Blaschka3fd434d2009-11-12 00:11:45 +00003115 return qeth_l3_set_rx_csum(card, csum_type);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003116}
3117
3118static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
3119{
Heiko Carstens509e2562008-07-26 02:24:10 -07003120 struct qeth_card *card = dev->ml_priv;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003121 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003122
3123 if (data) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003124 rc = qeth_l3_set_large_send(card, QETH_LARGE_SEND_TSO);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003125 } else {
3126 dev->features &= ~NETIF_F_TSO;
3127 card->options.large_send = QETH_LARGE_SEND_NO;
3128 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003129 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003130}
3131
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003132static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003133 .get_link = ethtool_op_get_link,
3134 .get_tx_csum = ethtool_op_get_tx_csum,
3135 .set_tx_csum = ethtool_op_set_tx_hw_csum,
3136 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
3137 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
3138 .get_sg = ethtool_op_get_sg,
3139 .set_sg = ethtool_op_set_sg,
3140 .get_tso = ethtool_op_get_tso,
3141 .set_tso = qeth_l3_ethtool_set_tso,
3142 .get_strings = qeth_core_get_strings,
3143 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003144 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003145 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003146 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003147};
3148
3149/*
3150 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3151 * NOARP on the netdevice is no option because it also turns off neighbor
3152 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3153 * arp resolution but we want the hard header (packet socket will work
3154 * e.g. tcpdump)
3155 */
3156static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3157{
3158 n->nud_state = NUD_NOARP;
3159 memcpy(n->ha, "FAKELL", 6);
3160 n->output = n->ops->connected_output;
3161 return 0;
3162}
3163
3164static int
3165qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3166{
3167 if (np->tbl->family == AF_INET)
3168 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3169
3170 return 0;
3171}
3172
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003173static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003174 .ndo_open = qeth_l3_open,
3175 .ndo_stop = qeth_l3_stop,
3176 .ndo_get_stats = qeth_get_stats,
3177 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3178 .ndo_validate_addr = eth_validate_addr,
3179 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3180 .ndo_do_ioctl = qeth_l3_do_ioctl,
3181 .ndo_change_mtu = qeth_change_mtu,
3182 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3183 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3184 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3185 .ndo_tx_timeout = qeth_tx_timeout,
3186};
3187
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003188static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3189 .ndo_open = qeth_l3_open,
3190 .ndo_stop = qeth_l3_stop,
3191 .ndo_get_stats = qeth_get_stats,
3192 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3193 .ndo_validate_addr = eth_validate_addr,
3194 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3195 .ndo_do_ioctl = qeth_l3_do_ioctl,
3196 .ndo_change_mtu = qeth_change_mtu,
3197 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3198 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3199 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3200 .ndo_tx_timeout = qeth_tx_timeout,
3201 .ndo_neigh_setup = qeth_l3_neigh_setup,
3202};
3203
Frank Blaschka4a71df52008-02-15 09:19:42 +01003204static int qeth_l3_setup_netdev(struct qeth_card *card)
3205{
3206 if (card->info.type == QETH_CARD_TYPE_OSAE) {
3207 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3208 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3209#ifdef CONFIG_TR
3210 card->dev = alloc_trdev(0);
3211#endif
3212 if (!card->dev)
3213 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003214 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003215 } else {
3216 card->dev = alloc_etherdev(0);
3217 if (!card->dev)
3218 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003219 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003220
3221 /*IPv6 address autoconfiguration stuff*/
3222 qeth_l3_get_unique_id(card);
3223 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3224 card->dev->dev_id = card->info.unique_id &
3225 0xffff;
3226 }
3227 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3228 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3229 if (!card->dev)
3230 return -ENODEV;
3231 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003232 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003233 qeth_l3_iqd_read_initial_mac(card);
3234 } else
3235 return -ENODEV;
3236
Heiko Carstens509e2562008-07-26 02:24:10 -07003237 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003238 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003239 card->dev->mtu = card->info.initial_mtu;
3240 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3241 card->dev->features |= NETIF_F_HW_VLAN_TX |
3242 NETIF_F_HW_VLAN_RX |
3243 NETIF_F_HW_VLAN_FILTER;
Eric Dumazet86d15cd2009-05-30 23:04:46 -07003244 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003245 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003246
3247 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
3248 return register_netdev(card->dev);
3249}
3250
3251static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
Jan Glauber779e6e12008-07-17 17:16:48 +02003252 unsigned int qdio_err, unsigned int queue, int first_element,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003253 int count, unsigned long card_ptr)
3254{
3255 struct net_device *net_dev;
3256 struct qeth_card *card;
3257 struct qeth_qdio_buffer *buffer;
3258 int index;
3259 int i;
3260
Frank Blaschka4a71df52008-02-15 09:19:42 +01003261 card = (struct qeth_card *) card_ptr;
3262 net_dev = card->dev;
3263 if (card->options.performance_stats) {
3264 card->perf_stats.inbound_cnt++;
3265 card->perf_stats.inbound_start_time = qeth_get_micros();
3266 }
Jan Glauber779e6e12008-07-17 17:16:48 +02003267 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
3268 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
3269 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
3270 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X",
3271 first_element, count);
3272 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
3273 qeth_schedule_recovery(card);
3274 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003275 }
3276 for (i = first_element; i < (first_element + count); ++i) {
3277 index = i % QDIO_MAX_BUFFERS_PER_Q;
3278 buffer = &card->qdio.in_q->bufs[index];
Jan Glauber779e6e12008-07-17 17:16:48 +02003279 if (!(qdio_err &&
Ursula Braun76b11f82010-01-11 02:50:50 +00003280 qeth_check_qdio_errors(card, buffer->buffer,
Jan Glauber779e6e12008-07-17 17:16:48 +02003281 qdio_err, "qinerr")))
Frank Blaschka4a71df52008-02-15 09:19:42 +01003282 qeth_l3_process_inbound_buffer(card, buffer, index);
3283 /* clear buffer and give back to hardware */
3284 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
3285 qeth_queue_input_buffer(card, index);
3286 }
3287 if (card->options.performance_stats)
3288 card->perf_stats.inbound_time += qeth_get_micros() -
3289 card->perf_stats.inbound_start_time;
3290}
3291
3292static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3293{
3294 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3295
3296 qeth_l3_create_device_attributes(&gdev->dev);
3297 card->options.layer2 = 0;
3298 card->discipline.input_handler = (qdio_handler_t *)
3299 qeth_l3_qdio_input_handler;
3300 card->discipline.output_handler = (qdio_handler_t *)
3301 qeth_qdio_output_handler;
3302 card->discipline.recover = qeth_l3_recover;
3303 return 0;
3304}
3305
3306static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3307{
3308 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3309
Ursula Braunf2148562009-05-19 21:38:37 +00003310 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003311 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3312
3313 if (cgdev->state == CCWGROUP_ONLINE) {
3314 card->use_hard_stop = 1;
3315 qeth_l3_set_offline(cgdev);
3316 }
3317
3318 if (card->dev) {
3319 unregister_netdev(card->dev);
3320 card->dev = NULL;
3321 }
3322
3323 qeth_l3_remove_device_attributes(&cgdev->dev);
3324 qeth_l3_clear_ip_list(card, 0, 0);
3325 qeth_l3_clear_ipato_list(card);
3326 return;
3327}
3328
3329static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3330{
3331 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3332 int rc = 0;
3333 enum qeth_card_states recover_flag;
3334
3335 BUG_ON(!card);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003336 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3337 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003338
Frank Blaschka4a71df52008-02-15 09:19:42 +01003339 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003340 rc = qeth_core_hardsetup_card(card);
3341 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003342 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003343 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003344 goto out_remove;
3345 }
3346
3347 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3348
Ursula Braunaa909222009-11-12 00:11:43 +00003349 if (!card->dev && qeth_l3_setup_netdev(card)) {
3350 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003351 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003352 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003353
3354 card->state = CARD_STATE_HARDSETUP;
3355 qeth_print_status_message(card);
3356
3357 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003358 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003359
3360 rc = qeth_send_startlan(card);
3361 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003362 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003363 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003364 dev_warn(&card->gdev->dev,
3365 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003366 card->lan_online = 0;
Ursula Braunf2148562009-05-19 21:38:37 +00003367 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003368 }
Ursula Braunaa909222009-11-12 00:11:43 +00003369 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003370 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003371 } else
3372 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003373
3374 rc = qeth_l3_setadapter_parms(card);
3375 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003376 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003377 if (!card->options.sniffer) {
3378 rc = qeth_l3_start_ipassists(card);
3379 if (rc)
3380 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3381 qeth_l3_set_large_send(card, card->options.large_send);
3382 rc = qeth_l3_setrouting_v4(card);
3383 if (rc)
3384 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3385 rc = qeth_l3_setrouting_v6(card);
3386 if (rc)
3387 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3388 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003389 netif_tx_disable(card->dev);
3390
3391 rc = qeth_init_qdio_queues(card);
3392 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003393 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003394 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003395 goto out_remove;
3396 }
3397 card->state = CARD_STATE_SOFTSETUP;
3398 netif_carrier_on(card->dev);
3399
3400 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003401 qeth_l3_set_ip_addr_list(card);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003402 if (recover_flag == CARD_STATE_RECOVER) {
3403 if (recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003404 qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003405 else {
3406 rtnl_lock();
3407 dev_open(card->dev);
3408 rtnl_unlock();
3409 }
3410 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003411 }
3412 /* let user_space know that device is online */
3413 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3414 return 0;
3415out_remove:
3416 card->use_hard_stop = 1;
3417 qeth_l3_stop_card(card, 0);
3418 ccw_device_set_offline(CARD_DDEV(card));
3419 ccw_device_set_offline(CARD_WDEV(card));
3420 ccw_device_set_offline(CARD_RDEV(card));
3421 if (recover_flag == CARD_STATE_RECOVER)
3422 card->state = CARD_STATE_RECOVER;
3423 else
3424 card->state = CARD_STATE_DOWN;
Ursula Braunaa909222009-11-12 00:11:43 +00003425 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003426}
3427
3428static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3429{
3430 return __qeth_l3_set_online(gdev, 0);
3431}
3432
3433static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3434 int recovery_mode)
3435{
3436 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3437 int rc = 0, rc2 = 0, rc3 = 0;
3438 enum qeth_card_states recover_flag;
3439
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003440 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3441 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003442
3443 if (card->dev && netif_carrier_ok(card->dev))
3444 netif_carrier_off(card->dev);
3445 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02003446 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003447 rc = ccw_device_set_offline(CARD_DDEV(card));
3448 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3449 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3450 if (!rc)
3451 rc = (rc2) ? rc2 : rc3;
3452 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003453 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003454 if (recover_flag == CARD_STATE_UP)
3455 card->state = CARD_STATE_RECOVER;
3456 /* let user_space know that device is offline */
3457 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3458 return 0;
3459}
3460
3461static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3462{
3463 return __qeth_l3_set_offline(cgdev, 0);
3464}
3465
3466static int qeth_l3_recover(void *ptr)
3467{
3468 struct qeth_card *card;
3469 int rc = 0;
3470
3471 card = (struct qeth_card *) ptr;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003472 QETH_DBF_TEXT(TRACE, 2, "recover1");
3473 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003474 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3475 return 0;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003476 QETH_DBF_TEXT(TRACE, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003477 dev_warn(&card->gdev->dev,
3478 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003479 card->use_hard_stop = 1;
3480 __qeth_l3_set_offline(card->gdev, 1);
3481 rc = __qeth_l3_set_online(card->gdev, 1);
3482 /* don't run another scheduled recovery */
3483 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3484 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3485 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003486 dev_info(&card->gdev->dev,
3487 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003488 else {
3489 rtnl_lock();
3490 dev_close(card->dev);
3491 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003492 dev_warn(&card->gdev->dev, "The qeth device driver "
3493 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003494 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003495 return 0;
3496}
3497
3498static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3499{
3500 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3501 qeth_l3_clear_ip_list(card, 0, 0);
3502 qeth_qdio_clear_card(card, 0);
3503 qeth_clear_qdio_buffers(card);
3504}
3505
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003506static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3507{
3508 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3509
3510 if (card->dev)
3511 netif_device_detach(card->dev);
3512 qeth_set_allowed_threads(card, 0, 1);
3513 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3514 if (gdev->state == CCWGROUP_OFFLINE)
3515 return 0;
3516 if (card->state == CARD_STATE_UP) {
3517 card->use_hard_stop = 1;
3518 __qeth_l3_set_offline(card->gdev, 1);
3519 } else
3520 __qeth_l3_set_offline(card->gdev, 0);
3521 return 0;
3522}
3523
3524static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3525{
3526 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3527 int rc = 0;
3528
3529 if (gdev->state == CCWGROUP_OFFLINE)
3530 goto out;
3531
3532 if (card->state == CARD_STATE_RECOVER) {
3533 rc = __qeth_l3_set_online(card->gdev, 1);
3534 if (rc) {
3535 if (card->dev) {
3536 rtnl_lock();
3537 dev_close(card->dev);
3538 rtnl_unlock();
3539 }
3540 }
3541 } else
3542 rc = __qeth_l3_set_online(card->gdev, 0);
3543out:
3544 qeth_set_allowed_threads(card, 0xffffffff, 0);
3545 if (card->dev)
3546 netif_device_attach(card->dev);
3547 if (rc)
3548 dev_warn(&card->gdev->dev, "The qeth device driver "
3549 "failed to recover an error on the device\n");
3550 return rc;
3551}
3552
Frank Blaschka4a71df52008-02-15 09:19:42 +01003553struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3554 .probe = qeth_l3_probe_device,
3555 .remove = qeth_l3_remove_device,
3556 .set_online = qeth_l3_set_online,
3557 .set_offline = qeth_l3_set_offline,
3558 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003559 .freeze = qeth_l3_pm_suspend,
3560 .thaw = qeth_l3_pm_resume,
3561 .restore = qeth_l3_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003562};
3563EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3564
3565static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003566 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003567{
3568 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3569 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3570 struct qeth_ipaddr *addr;
3571 struct qeth_card *card;
3572
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003573 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003574 return NOTIFY_DONE;
3575
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003576 QETH_DBF_TEXT(TRACE, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003577 card = qeth_l3_get_card_from_dev(dev);
3578 if (!card)
3579 return NOTIFY_DONE;
3580
3581 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3582 if (addr != NULL) {
3583 addr->u.a4.addr = ifa->ifa_address;
3584 addr->u.a4.mask = ifa->ifa_mask;
3585 addr->type = QETH_IP_TYPE_NORMAL;
3586 } else
3587 goto out;
3588
3589 switch (event) {
3590 case NETDEV_UP:
3591 if (!qeth_l3_add_ip(card, addr))
3592 kfree(addr);
3593 break;
3594 case NETDEV_DOWN:
3595 if (!qeth_l3_delete_ip(card, addr))
3596 kfree(addr);
3597 break;
3598 default:
3599 break;
3600 }
3601 qeth_l3_set_ip_addr_list(card);
3602out:
3603 return NOTIFY_DONE;
3604}
3605
3606static struct notifier_block qeth_l3_ip_notifier = {
3607 qeth_l3_ip_event,
3608 NULL,
3609};
3610
3611#ifdef CONFIG_QETH_IPV6
3612/**
3613 * IPv6 event handler
3614 */
3615static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003616 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003617{
3618 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3619 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3620 struct qeth_ipaddr *addr;
3621 struct qeth_card *card;
3622
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003623 QETH_DBF_TEXT(TRACE, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003624
3625 card = qeth_l3_get_card_from_dev(dev);
3626 if (!card)
3627 return NOTIFY_DONE;
3628 if (!qeth_is_supported(card, IPA_IPV6))
3629 return NOTIFY_DONE;
3630
3631 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3632 if (addr != NULL) {
3633 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3634 addr->u.a6.pfxlen = ifa->prefix_len;
3635 addr->type = QETH_IP_TYPE_NORMAL;
3636 } else
3637 goto out;
3638
3639 switch (event) {
3640 case NETDEV_UP:
3641 if (!qeth_l3_add_ip(card, addr))
3642 kfree(addr);
3643 break;
3644 case NETDEV_DOWN:
3645 if (!qeth_l3_delete_ip(card, addr))
3646 kfree(addr);
3647 break;
3648 default:
3649 break;
3650 }
3651 qeth_l3_set_ip_addr_list(card);
3652out:
3653 return NOTIFY_DONE;
3654}
3655
3656static struct notifier_block qeth_l3_ip6_notifier = {
3657 qeth_l3_ip6_event,
3658 NULL,
3659};
3660#endif
3661
3662static int qeth_l3_register_notifiers(void)
3663{
3664 int rc;
3665
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003666 QETH_DBF_TEXT(TRACE, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003667 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3668 if (rc)
3669 return rc;
3670#ifdef CONFIG_QETH_IPV6
3671 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3672 if (rc) {
3673 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3674 return rc;
3675 }
3676#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003677 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003678#endif
3679 return 0;
3680}
3681
3682static void qeth_l3_unregister_notifiers(void)
3683{
3684
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003685 QETH_DBF_TEXT(TRACE, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003686 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3687#ifdef CONFIG_QETH_IPV6
3688 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3689#endif /* QETH_IPV6 */
3690}
3691
3692static int __init qeth_l3_init(void)
3693{
3694 int rc = 0;
3695
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003696 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003697 rc = qeth_l3_register_notifiers();
3698 return rc;
3699}
3700
3701static void __exit qeth_l3_exit(void)
3702{
3703 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003704 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003705}
3706
3707module_init(qeth_l3_init);
3708module_exit(qeth_l3_exit);
3709MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3710MODULE_DESCRIPTION("qeth layer 3 discipline");
3711MODULE_LICENSE("GPL");