blob: c094707fcbff86be4ba2477827237674d55e7a60 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
2 * drivers/s390/net/qeth_l3_main.c
3 *
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02004 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01005 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
10
Frank Blaschka74eacdb2008-12-25 13:39:49 +010011#define KMSG_COMPONENT "qeth"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Frank Blaschka4a71df52008-02-15 09:19:42 +010014#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/etherdevice.h>
20#include <linux/mii.h>
21#include <linux/ip.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000022#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010023#include <linux/inetdevice.h>
24#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
27#include <net/ip.h>
28#include <net/arp.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000029#include <net/ip6_checksum.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010030
Frank Blaschka4a71df52008-02-15 09:19:42 +010031#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010032
Frank Blaschka4a71df52008-02-15 09:19:42 +010033static int qeth_l3_set_offline(struct ccwgroup_device *);
34static int qeth_l3_recover(void *);
35static int qeth_l3_stop(struct net_device *);
36static void qeth_l3_set_multicast_list(struct net_device *);
37static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
38static int qeth_l3_register_addr_entry(struct qeth_card *,
39 struct qeth_ipaddr *);
40static int qeth_l3_deregister_addr_entry(struct qeth_card *,
41 struct qeth_ipaddr *);
42static int __qeth_l3_set_online(struct ccwgroup_device *, int);
43static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
44
Frank Blaschkac3b4a742009-11-12 00:11:44 +000045int qeth_l3_set_large_send(struct qeth_card *card,
46 enum qeth_large_send_types type)
47{
48 int rc = 0;
49
50 card->options.large_send = type;
51 if (card->dev == NULL)
52 return 0;
53
54 if (card->options.large_send == QETH_LARGE_SEND_TSO) {
55 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
56 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
Frank Blaschkaf6b85b62010-05-11 19:34:45 +000057 NETIF_F_IP_CSUM;
Frank Blaschkac3b4a742009-11-12 00:11:44 +000058 } else {
59 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
Frank Blaschkaf6b85b62010-05-11 19:34:45 +000060 NETIF_F_IP_CSUM);
Frank Blaschkac3b4a742009-11-12 00:11:44 +000061 card->options.large_send = QETH_LARGE_SEND_NO;
62 rc = -EOPNOTSUPP;
63 }
64 } else {
65 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
Frank Blaschkaf6b85b62010-05-11 19:34:45 +000066 NETIF_F_IP_CSUM);
Frank Blaschkac3b4a742009-11-12 00:11:44 +000067 card->options.large_send = QETH_LARGE_SEND_NO;
68 }
69 return rc;
70}
Frank Blaschka4a71df52008-02-15 09:19:42 +010071
72static int qeth_l3_isxdigit(char *buf)
73{
74 while (*buf) {
75 if (!isxdigit(*buf++))
76 return 0;
77 }
78 return 1;
79}
80
81void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
82{
83 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
84}
85
86int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
87{
88 int count = 0, rc = 0;
89 int in[4];
90 char c;
91
92 rc = sscanf(buf, "%u.%u.%u.%u%c",
93 &in[0], &in[1], &in[2], &in[3], &c);
94 if (rc != 4 && (rc != 5 || c != '\n'))
95 return -EINVAL;
96 for (count = 0; count < 4; count++) {
97 if (in[count] > 255)
98 return -EINVAL;
99 addr[count] = in[count];
100 }
101 return 0;
102}
103
104void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
105{
Joe Perches963a9fd2010-09-07 21:14:40 +0000106 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100107}
108
109int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
110{
111 const char *end, *end_tmp, *start;
112 __u16 *in;
113 char num[5];
114 int num2, cnt, out, found, save_cnt;
115 unsigned short in_tmp[8] = {0, };
116
117 cnt = out = found = save_cnt = num2 = 0;
118 end = start = buf;
119 in = (__u16 *) addr;
120 memset(in, 0, 16);
121 while (*end) {
122 end = strchr(start, ':');
123 if (end == NULL) {
124 end = buf + strlen(buf);
125 end_tmp = strchr(start, '\n');
126 if (end_tmp != NULL)
127 end = end_tmp;
128 out = 1;
129 }
130 if ((end - start)) {
131 memset(num, 0, 5);
132 if ((end - start) > 4)
133 return -EINVAL;
134 memcpy(num, start, end - start);
135 if (!qeth_l3_isxdigit(num))
136 return -EINVAL;
137 sscanf(start, "%x", &num2);
138 if (found)
139 in_tmp[save_cnt++] = num2;
140 else
141 in[cnt++] = num2;
142 if (out)
143 break;
144 } else {
145 if (found)
146 return -EINVAL;
147 found = 1;
148 }
149 start = ++end;
150 }
151 if (cnt + save_cnt > 8)
152 return -EINVAL;
153 cnt = 7;
154 while (save_cnt)
155 in[cnt--] = in_tmp[--save_cnt];
156 return 0;
157}
158
159void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
160 char *buf)
161{
162 if (proto == QETH_PROT_IPV4)
163 qeth_l3_ipaddr4_to_string(addr, buf);
164 else if (proto == QETH_PROT_IPV6)
165 qeth_l3_ipaddr6_to_string(addr, buf);
166}
167
168int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
169 __u8 *addr)
170{
171 if (proto == QETH_PROT_IPV4)
172 return qeth_l3_string_to_ipaddr4(buf, addr);
173 else if (proto == QETH_PROT_IPV6)
174 return qeth_l3_string_to_ipaddr6(buf, addr);
175 else
176 return -EINVAL;
177}
178
179static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
180{
181 int i, j;
182 u8 octet;
183
184 for (i = 0; i < len; ++i) {
185 octet = addr[i];
186 for (j = 7; j >= 0; --j) {
187 bits[i*8 + j] = octet & 1;
188 octet >>= 1;
189 }
190 }
191}
192
Klaus-Dieter Wacker62982632010-07-22 23:15:03 +0000193int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100194 struct qeth_ipaddr *addr)
195{
196 struct qeth_ipato_entry *ipatoe;
197 u8 addr_bits[128] = {0, };
198 u8 ipatoe_bits[128] = {0, };
199 int rc = 0;
200
201 if (!card->ipato.enabled)
202 return 0;
203
204 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
205 (addr->proto == QETH_PROT_IPV4)? 4:16);
206 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
207 if (addr->proto != ipatoe->proto)
208 continue;
209 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
210 (ipatoe->proto == QETH_PROT_IPV4) ?
211 4 : 16);
212 if (addr->proto == QETH_PROT_IPV4)
213 rc = !memcmp(addr_bits, ipatoe_bits,
214 min(32, ipatoe->mask_bits));
215 else
216 rc = !memcmp(addr_bits, ipatoe_bits,
217 min(128, ipatoe->mask_bits));
218 if (rc)
219 break;
220 }
221 /* invert? */
222 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
223 rc = !rc;
224 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
225 rc = !rc;
226
227 return rc;
228}
229
230/*
231 * Add IP to be added to todo list. If there is already an "add todo"
232 * in this list we just incremenent the reference count.
233 * Returns 0 if we just incremented reference count.
234 */
235static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
236 struct qeth_ipaddr *addr, int add)
237{
238 struct qeth_ipaddr *tmp, *t;
239 int found = 0;
240
Ursula Braun76b11f82010-01-11 02:50:50 +0000241 if (card->options.sniffer)
242 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100243 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
244 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
245 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
246 return 0;
247 if ((tmp->proto == QETH_PROT_IPV4) &&
248 (addr->proto == QETH_PROT_IPV4) &&
249 (tmp->type == addr->type) &&
250 (tmp->is_multicast == addr->is_multicast) &&
251 (tmp->u.a4.addr == addr->u.a4.addr) &&
252 (tmp->u.a4.mask == addr->u.a4.mask)) {
253 found = 1;
254 break;
255 }
256 if ((tmp->proto == QETH_PROT_IPV6) &&
257 (addr->proto == QETH_PROT_IPV6) &&
258 (tmp->type == addr->type) &&
259 (tmp->is_multicast == addr->is_multicast) &&
260 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
261 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
262 sizeof(struct in6_addr)) == 0)) {
263 found = 1;
264 break;
265 }
266 }
267 if (found) {
268 if (addr->users != 0)
269 tmp->users += addr->users;
270 else
271 tmp->users += add ? 1 : -1;
272 if (tmp->users == 0) {
273 list_del(&tmp->entry);
274 kfree(tmp);
275 }
276 return 0;
277 } else {
278 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
279 list_add(&addr->entry, card->ip_tbd_list);
280 else {
281 if (addr->users == 0)
282 addr->users += add ? 1 : -1;
283 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
284 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000285 QETH_CARD_TEXT(card, 2, "tkovaddr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
287 }
288 list_add_tail(&addr->entry, card->ip_tbd_list);
289 }
290 return 1;
291 }
292}
293
294static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
295{
296 unsigned long flags;
297 int rc = 0;
298
Carsten Otte847a50f2010-06-21 22:57:05 +0000299 QETH_CARD_TEXT(card, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100300
301 if (addr->proto == QETH_PROT_IPV4)
Carsten Otte847a50f2010-06-21 22:57:05 +0000302 QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100303 else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000304 QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
305 QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306 }
307 spin_lock_irqsave(&card->ip_lock, flags);
308 rc = __qeth_l3_insert_ip_todo(card, addr, 0);
309 spin_unlock_irqrestore(&card->ip_lock, flags);
310 return rc;
311}
312
313static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
314{
315 unsigned long flags;
316 int rc = 0;
317
Carsten Otte847a50f2010-06-21 22:57:05 +0000318 QETH_CARD_TEXT(card, 4, "addip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100319 if (addr->proto == QETH_PROT_IPV4)
Carsten Otte847a50f2010-06-21 22:57:05 +0000320 QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100321 else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000322 QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
323 QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100324 }
325 spin_lock_irqsave(&card->ip_lock, flags);
326 rc = __qeth_l3_insert_ip_todo(card, addr, 1);
327 spin_unlock_irqrestore(&card->ip_lock, flags);
328 return rc;
329}
330
331
332static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
333 enum qeth_prot_versions prot)
334{
335 struct qeth_ipaddr *addr;
336
337 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
338 if (addr == NULL) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100339 return NULL;
340 }
341 addr->type = QETH_IP_TYPE_NORMAL;
342 addr->proto = prot;
343 return addr;
344}
345
346static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
347{
348 struct qeth_ipaddr *iptodo;
349 unsigned long flags;
350
Carsten Otte847a50f2010-06-21 22:57:05 +0000351 QETH_CARD_TEXT(card, 4, "delmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352 iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
353 if (!iptodo) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000354 QETH_CARD_TEXT(card, 2, "dmcnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100355 return;
356 }
357 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
358 spin_lock_irqsave(&card->ip_lock, flags);
359 if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
360 kfree(iptodo);
361 spin_unlock_irqrestore(&card->ip_lock, flags);
362}
363
364/*
365 * Add/remove address to/from card's ip list, i.e. try to add or remove
366 * reference to/from an IP address that is already registered on the card.
367 * Returns:
368 * 0 address was on card and its reference count has been adjusted,
369 * but is still > 0, so nothing has to be done
370 * also returns 0 if card was not on card and the todo was to delete
371 * the address -> there is also nothing to be done
372 * 1 address was not on card and the todo is to add it to the card's ip
373 * list
374 * -1 address was on card and its reference count has been decremented
375 * to <= 0 by the todo -> address must be removed from card
376 */
377static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
378 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
379{
380 struct qeth_ipaddr *addr;
381 int found = 0;
382
383 list_for_each_entry(addr, &card->ip_list, entry) {
384 if ((addr->proto == QETH_PROT_IPV4) &&
385 (todo->proto == QETH_PROT_IPV4) &&
386 (addr->type == todo->type) &&
387 (addr->u.a4.addr == todo->u.a4.addr) &&
388 (addr->u.a4.mask == todo->u.a4.mask)) {
389 found = 1;
390 break;
391 }
392 if ((addr->proto == QETH_PROT_IPV6) &&
393 (todo->proto == QETH_PROT_IPV6) &&
394 (addr->type == todo->type) &&
395 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
396 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
397 sizeof(struct in6_addr)) == 0)) {
398 found = 1;
399 break;
400 }
401 }
402 if (found) {
403 addr->users += todo->users;
404 if (addr->users <= 0) {
405 *__addr = addr;
406 return -1;
407 } else {
408 /* for VIPA and RXIP limit refcount to 1 */
409 if (addr->type != QETH_IP_TYPE_NORMAL)
410 addr->users = 1;
411 return 0;
412 }
413 }
414 if (todo->users > 0) {
415 /* for VIPA and RXIP limit refcount to 1 */
416 if (todo->type != QETH_IP_TYPE_NORMAL)
417 todo->users = 1;
418 return 1;
419 } else
420 return 0;
421}
422
423static void __qeth_l3_delete_all_mc(struct qeth_card *card,
424 unsigned long *flags)
425{
Ursula Braun2d921c32008-04-01 10:26:53 +0200426 struct list_head fail_list;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100427 struct qeth_ipaddr *addr, *tmp;
428 int rc;
Ursula Braun2d921c32008-04-01 10:26:53 +0200429
430 INIT_LIST_HEAD(&fail_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431again:
432 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
433 if (addr->is_multicast) {
434 list_del(&addr->entry);
435 spin_unlock_irqrestore(&card->ip_lock, *flags);
436 rc = qeth_l3_deregister_addr_entry(card, addr);
437 spin_lock_irqsave(&card->ip_lock, *flags);
Ursula Braun2d921c32008-04-01 10:26:53 +0200438 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439 kfree(addr);
Ursula Braun2d921c32008-04-01 10:26:53 +0200440 else
441 list_add_tail(&addr->entry, &fail_list);
442 goto again;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443 }
444 }
Ursula Braun2d921c32008-04-01 10:26:53 +0200445 list_splice(&fail_list, &card->ip_list);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446}
447
448static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
449{
450 struct list_head *tbd_list;
451 struct qeth_ipaddr *todo, *addr;
452 unsigned long flags;
453 int rc;
454
Carsten Otte847a50f2010-06-21 22:57:05 +0000455 QETH_CARD_TEXT(card, 2, "sdiplist");
456 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100457
Ursula Braun76b11f82010-01-11 02:50:50 +0000458 if (card->options.sniffer)
459 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100460 spin_lock_irqsave(&card->ip_lock, flags);
461 tbd_list = card->ip_tbd_list;
462 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
463 if (!card->ip_tbd_list) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000464 QETH_CARD_TEXT(card, 0, "silnomem");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100465 card->ip_tbd_list = tbd_list;
466 spin_unlock_irqrestore(&card->ip_lock, flags);
467 return;
468 } else
469 INIT_LIST_HEAD(card->ip_tbd_list);
470
471 while (!list_empty(tbd_list)) {
472 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
473 list_del(&todo->entry);
474 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
475 __qeth_l3_delete_all_mc(card, &flags);
476 kfree(todo);
477 continue;
478 }
479 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
480 if (rc == 0) {
481 /* nothing to be done; only adjusted refcount */
482 kfree(todo);
483 } else if (rc == 1) {
484 /* new entry to be added to on-card list */
485 spin_unlock_irqrestore(&card->ip_lock, flags);
486 rc = qeth_l3_register_addr_entry(card, todo);
487 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun3caa4af2008-04-01 10:27:00 +0200488 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100489 list_add_tail(&todo->entry, &card->ip_list);
490 else
491 kfree(todo);
492 } else if (rc == -1) {
493 /* on-card entry to be removed */
494 list_del_init(&addr->entry);
495 spin_unlock_irqrestore(&card->ip_lock, flags);
496 rc = qeth_l3_deregister_addr_entry(card, addr);
497 spin_lock_irqsave(&card->ip_lock, flags);
Ursula Braun76b11f82010-01-11 02:50:50 +0000498 if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100499 kfree(addr);
500 else
501 list_add_tail(&addr->entry, &card->ip_list);
502 kfree(todo);
503 }
504 }
505 spin_unlock_irqrestore(&card->ip_lock, flags);
506 kfree(tbd_list);
507}
508
509static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
510 int recover)
511{
512 struct qeth_ipaddr *addr, *tmp;
513 unsigned long flags;
514
Carsten Otte847a50f2010-06-21 22:57:05 +0000515 QETH_CARD_TEXT(card, 4, "clearip");
Ursula Braun76b11f82010-01-11 02:50:50 +0000516 if (recover && card->options.sniffer)
517 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100518 spin_lock_irqsave(&card->ip_lock, flags);
519 /* clear todo list */
520 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
521 list_del(&addr->entry);
522 kfree(addr);
523 }
524
525 while (!list_empty(&card->ip_list)) {
526 addr = list_entry(card->ip_list.next,
527 struct qeth_ipaddr, entry);
528 list_del_init(&addr->entry);
529 if (clean) {
530 spin_unlock_irqrestore(&card->ip_lock, flags);
531 qeth_l3_deregister_addr_entry(card, addr);
532 spin_lock_irqsave(&card->ip_lock, flags);
533 }
534 if (!recover || addr->is_multicast) {
535 kfree(addr);
536 continue;
537 }
538 list_add_tail(&addr->entry, card->ip_tbd_list);
539 }
540 spin_unlock_irqrestore(&card->ip_lock, flags);
541}
542
543static int qeth_l3_address_exists_in_list(struct list_head *list,
544 struct qeth_ipaddr *addr, int same_type)
545{
546 struct qeth_ipaddr *tmp;
547
548 list_for_each_entry(tmp, list, entry) {
549 if ((tmp->proto == QETH_PROT_IPV4) &&
550 (addr->proto == QETH_PROT_IPV4) &&
551 ((same_type && (tmp->type == addr->type)) ||
552 (!same_type && (tmp->type != addr->type))) &&
553 (tmp->u.a4.addr == addr->u.a4.addr))
554 return 1;
555
556 if ((tmp->proto == QETH_PROT_IPV6) &&
557 (addr->proto == QETH_PROT_IPV6) &&
558 ((same_type && (tmp->type == addr->type)) ||
559 (!same_type && (tmp->type != addr->type))) &&
560 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
561 sizeof(struct in6_addr)) == 0))
562 return 1;
563
564 }
565 return 0;
566}
567
568static int qeth_l3_send_setdelmc(struct qeth_card *card,
569 struct qeth_ipaddr *addr, int ipacmd)
570{
571 int rc;
572 struct qeth_cmd_buffer *iob;
573 struct qeth_ipa_cmd *cmd;
574
Carsten Otte847a50f2010-06-21 22:57:05 +0000575 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100576
577 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
578 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
579 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
580 if (addr->proto == QETH_PROT_IPV6)
581 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
582 sizeof(struct in6_addr));
583 else
584 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
585
586 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
587
588 return rc;
589}
590
591static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
592{
593 int i, j;
594 for (i = 0; i < 16; i++) {
595 j = (len) - (i * 8);
596 if (j >= 8)
597 netmask[i] = 0xff;
598 else if (j > 0)
599 netmask[i] = (u8)(0xFF00 >> j);
600 else
601 netmask[i] = 0;
602 }
603}
604
605static int qeth_l3_send_setdelip(struct qeth_card *card,
606 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
607{
608 int rc;
609 struct qeth_cmd_buffer *iob;
610 struct qeth_ipa_cmd *cmd;
611 __u8 netmask[16];
612
Carsten Otte847a50f2010-06-21 22:57:05 +0000613 QETH_CARD_TEXT(card, 4, "setdelip");
614 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100615
616 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
617 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
618 if (addr->proto == QETH_PROT_IPV6) {
619 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
620 sizeof(struct in6_addr));
621 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
622 memcpy(cmd->data.setdelip6.mask, netmask,
623 sizeof(struct in6_addr));
624 cmd->data.setdelip6.flags = flags;
625 } else {
626 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
627 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
628 cmd->data.setdelip4.flags = flags;
629 }
630
631 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
632
633 return rc;
634}
635
636static int qeth_l3_send_setrouting(struct qeth_card *card,
637 enum qeth_routing_types type, enum qeth_prot_versions prot)
638{
639 int rc;
640 struct qeth_ipa_cmd *cmd;
641 struct qeth_cmd_buffer *iob;
642
Carsten Otte847a50f2010-06-21 22:57:05 +0000643 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100644 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
645 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
646 cmd->data.setrtg.type = (type);
647 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
648
649 return rc;
650}
651
652static void qeth_l3_correct_routing_type(struct qeth_card *card,
653 enum qeth_routing_types *type, enum qeth_prot_versions prot)
654{
655 if (card->info.type == QETH_CARD_TYPE_IQD) {
656 switch (*type) {
657 case NO_ROUTER:
658 case PRIMARY_CONNECTOR:
659 case SECONDARY_CONNECTOR:
660 case MULTICAST_ROUTER:
661 return;
662 default:
663 goto out_inval;
664 }
665 } else {
666 switch (*type) {
667 case NO_ROUTER:
668 case PRIMARY_ROUTER:
669 case SECONDARY_ROUTER:
670 return;
671 case MULTICAST_ROUTER:
672 if (qeth_is_ipafunc_supported(card, prot,
673 IPA_OSA_MC_ROUTER))
674 return;
675 default:
676 goto out_inval;
677 }
678 }
679out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100680 *type = NO_ROUTER;
681}
682
683int qeth_l3_setrouting_v4(struct qeth_card *card)
684{
685 int rc;
686
Carsten Otte847a50f2010-06-21 22:57:05 +0000687 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100688
689 qeth_l3_correct_routing_type(card, &card->options.route4.type,
690 QETH_PROT_IPV4);
691
692 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
693 QETH_PROT_IPV4);
694 if (rc) {
695 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200696 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
697 " on %s. Type set to 'no router'.\n", rc,
698 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699 }
700 return rc;
701}
702
703int qeth_l3_setrouting_v6(struct qeth_card *card)
704{
705 int rc = 0;
706
Carsten Otte847a50f2010-06-21 22:57:05 +0000707 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708#ifdef CONFIG_QETH_IPV6
709
710 if (!qeth_is_supported(card, IPA_IPV6))
711 return 0;
712 qeth_l3_correct_routing_type(card, &card->options.route6.type,
713 QETH_PROT_IPV6);
714
715 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
716 QETH_PROT_IPV6);
717 if (rc) {
718 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200719 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
720 " on %s. Type set to 'no router'.\n", rc,
721 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100722 }
723#endif
724 return rc;
725}
726
727/*
728 * IP address takeover related functions
729 */
730static void qeth_l3_clear_ipato_list(struct qeth_card *card)
731{
732
733 struct qeth_ipato_entry *ipatoe, *tmp;
734 unsigned long flags;
735
736 spin_lock_irqsave(&card->ip_lock, flags);
737 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
738 list_del(&ipatoe->entry);
739 kfree(ipatoe);
740 }
741 spin_unlock_irqrestore(&card->ip_lock, flags);
742}
743
744int qeth_l3_add_ipato_entry(struct qeth_card *card,
745 struct qeth_ipato_entry *new)
746{
747 struct qeth_ipato_entry *ipatoe;
748 unsigned long flags;
749 int rc = 0;
750
Carsten Otte847a50f2010-06-21 22:57:05 +0000751 QETH_CARD_TEXT(card, 2, "addipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100752 spin_lock_irqsave(&card->ip_lock, flags);
753 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
754 if (ipatoe->proto != new->proto)
755 continue;
756 if (!memcmp(ipatoe->addr, new->addr,
757 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
758 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100759 rc = -EEXIST;
760 break;
761 }
762 }
763 if (!rc)
764 list_add_tail(&new->entry, &card->ipato.entries);
765
766 spin_unlock_irqrestore(&card->ip_lock, flags);
767 return rc;
768}
769
770void qeth_l3_del_ipato_entry(struct qeth_card *card,
771 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
772{
773 struct qeth_ipato_entry *ipatoe, *tmp;
774 unsigned long flags;
775
Carsten Otte847a50f2010-06-21 22:57:05 +0000776 QETH_CARD_TEXT(card, 2, "delipato");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100777 spin_lock_irqsave(&card->ip_lock, flags);
778 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
779 if (ipatoe->proto != proto)
780 continue;
781 if (!memcmp(ipatoe->addr, addr,
782 (proto == QETH_PROT_IPV4)? 4:16) &&
783 (ipatoe->mask_bits == mask_bits)) {
784 list_del(&ipatoe->entry);
785 kfree(ipatoe);
786 }
787 }
788 spin_unlock_irqrestore(&card->ip_lock, flags);
789}
790
791/*
792 * VIPA related functions
793 */
794int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
795 const u8 *addr)
796{
797 struct qeth_ipaddr *ipaddr;
798 unsigned long flags;
799 int rc = 0;
800
801 ipaddr = qeth_l3_get_addr_buffer(proto);
802 if (ipaddr) {
803 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000804 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100805 memcpy(&ipaddr->u.a4.addr, addr, 4);
806 ipaddr->u.a4.mask = 0;
807 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000808 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100809 memcpy(&ipaddr->u.a6.addr, addr, 16);
810 ipaddr->u.a6.pfxlen = 0;
811 }
812 ipaddr->type = QETH_IP_TYPE_VIPA;
813 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
814 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
815 } else
816 return -ENOMEM;
817 spin_lock_irqsave(&card->ip_lock, flags);
818 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
819 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
820 rc = -EEXIST;
821 spin_unlock_irqrestore(&card->ip_lock, flags);
822 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100823 return rc;
824 }
825 if (!qeth_l3_add_ip(card, ipaddr))
826 kfree(ipaddr);
827 qeth_l3_set_ip_addr_list(card);
828 return rc;
829}
830
831void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
832 const u8 *addr)
833{
834 struct qeth_ipaddr *ipaddr;
835
836 ipaddr = qeth_l3_get_addr_buffer(proto);
837 if (ipaddr) {
838 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000839 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840 memcpy(&ipaddr->u.a4.addr, addr, 4);
841 ipaddr->u.a4.mask = 0;
842 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000843 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 memcpy(&ipaddr->u.a6.addr, addr, 16);
845 ipaddr->u.a6.pfxlen = 0;
846 }
847 ipaddr->type = QETH_IP_TYPE_VIPA;
848 } else
849 return;
850 if (!qeth_l3_delete_ip(card, ipaddr))
851 kfree(ipaddr);
852 qeth_l3_set_ip_addr_list(card);
853}
854
855/*
856 * proxy ARP related functions
857 */
858int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
859 const u8 *addr)
860{
861 struct qeth_ipaddr *ipaddr;
862 unsigned long flags;
863 int rc = 0;
864
865 ipaddr = qeth_l3_get_addr_buffer(proto);
866 if (ipaddr) {
867 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000868 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100869 memcpy(&ipaddr->u.a4.addr, addr, 4);
870 ipaddr->u.a4.mask = 0;
871 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000872 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873 memcpy(&ipaddr->u.a6.addr, addr, 16);
874 ipaddr->u.a6.pfxlen = 0;
875 }
876 ipaddr->type = QETH_IP_TYPE_RXIP;
877 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
878 ipaddr->del_flags = 0;
879 } else
880 return -ENOMEM;
881 spin_lock_irqsave(&card->ip_lock, flags);
882 if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
883 qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
884 rc = -EEXIST;
885 spin_unlock_irqrestore(&card->ip_lock, flags);
886 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100887 return rc;
888 }
889 if (!qeth_l3_add_ip(card, ipaddr))
890 kfree(ipaddr);
891 qeth_l3_set_ip_addr_list(card);
892 return 0;
893}
894
895void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
896 const u8 *addr)
897{
898 struct qeth_ipaddr *ipaddr;
899
900 ipaddr = qeth_l3_get_addr_buffer(proto);
901 if (ipaddr) {
902 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000903 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904 memcpy(&ipaddr->u.a4.addr, addr, 4);
905 ipaddr->u.a4.mask = 0;
906 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000907 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 memcpy(&ipaddr->u.a6.addr, addr, 16);
909 ipaddr->u.a6.pfxlen = 0;
910 }
911 ipaddr->type = QETH_IP_TYPE_RXIP;
912 } else
913 return;
914 if (!qeth_l3_delete_ip(card, ipaddr))
915 kfree(ipaddr);
916 qeth_l3_set_ip_addr_list(card);
917}
918
919static int qeth_l3_register_addr_entry(struct qeth_card *card,
920 struct qeth_ipaddr *addr)
921{
922 char buf[50];
923 int rc = 0;
924 int cnt = 3;
925
926 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000927 QETH_CARD_TEXT(card, 2, "setaddr4");
928 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000930 QETH_CARD_TEXT(card, 2, "setaddr6");
931 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
932 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000934 QETH_CARD_TEXT(card, 2, "setaddr?");
935 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100936 }
937 do {
938 if (addr->is_multicast)
939 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
940 else
941 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
942 addr->set_flags);
943 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000944 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100945 } while ((--cnt > 0) && rc);
946 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000947 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100948 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100949 dev_warn(&card->gdev->dev,
950 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100951 }
952 return rc;
953}
954
955static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
956 struct qeth_ipaddr *addr)
957{
958 int rc = 0;
959
960 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000961 QETH_CARD_TEXT(card, 2, "deladdr4");
962 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000964 QETH_CARD_TEXT(card, 2, "deladdr6");
965 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
966 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000968 QETH_CARD_TEXT(card, 2, "deladdr?");
969 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100970 }
971 if (addr->is_multicast)
972 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
973 else
974 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
975 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200976 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000977 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100978
979 return rc;
980}
981
982static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
983{
984 if (cast_type == RTN_MULTICAST)
985 return QETH_CAST_MULTICAST;
986 if (cast_type == RTN_BROADCAST)
987 return QETH_CAST_BROADCAST;
988 return QETH_CAST_UNICAST;
989}
990
991static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
992{
993 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
994 if (cast_type == RTN_MULTICAST)
995 return ct | QETH_CAST_MULTICAST;
996 if (cast_type == RTN_ANYCAST)
997 return ct | QETH_CAST_ANYCAST;
998 if (cast_type == RTN_BROADCAST)
999 return ct | QETH_CAST_BROADCAST;
1000 return ct | QETH_CAST_UNICAST;
1001}
1002
1003static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
1004 __u32 mode)
1005{
1006 int rc;
1007 struct qeth_cmd_buffer *iob;
1008 struct qeth_ipa_cmd *cmd;
1009
Carsten Otte847a50f2010-06-21 22:57:05 +00001010 QETH_CARD_TEXT(card, 4, "adpmode");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011
1012 iob = qeth_get_adapter_cmd(card, command,
1013 sizeof(struct qeth_ipacmd_setadpparms));
1014 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1015 cmd->data.setadapterparms.data.mode = mode;
1016 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
1017 NULL);
1018 return rc;
1019}
1020
1021static int qeth_l3_setadapter_hstr(struct qeth_card *card)
1022{
1023 int rc;
1024
Carsten Otte847a50f2010-06-21 22:57:05 +00001025 QETH_CARD_TEXT(card, 4, "adphstr");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001026
1027 if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1028 rc = qeth_l3_send_setadp_mode(card,
1029 IPA_SETADP_SET_BROADCAST_MODE,
1030 card->options.broadcast_mode);
1031 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001032 QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001033 "device %s: x%x\n",
1034 CARD_BUS_ID(card), rc);
1035 rc = qeth_l3_send_setadp_mode(card,
1036 IPA_SETADP_ALTER_MAC_ADDRESS,
1037 card->options.macaddr_mode);
1038 if (rc)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001039 QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001040 "device %s: x%x\n", CARD_BUS_ID(card), rc);
1041 return rc;
1042 }
1043 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001044 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001045 "to set broadcast mode, using ALLRINGS "
1046 "on device %s:\n", CARD_BUS_ID(card));
1047 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
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 macaddr mode, using NONCANONICAL "
1050 "on device %s:\n", CARD_BUS_ID(card));
1051 return 0;
1052}
1053
1054static int qeth_l3_setadapter_parms(struct qeth_card *card)
1055{
1056 int rc;
1057
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001058 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001059
1060 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001061 dev_info(&card->gdev->dev,
1062 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001063 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001064 return 0;
1065 }
1066 rc = qeth_query_setadapterparms(card);
1067 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001068 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +00001069 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001070 return rc;
1071 }
1072 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1073 rc = qeth_setadpparms_change_macaddr(card);
1074 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001075 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -08001076 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001077 }
1078
1079 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1080 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1081 rc = qeth_l3_setadapter_hstr(card);
1082
1083 return rc;
1084}
1085
1086static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1087 struct qeth_reply *reply, unsigned long data)
1088{
1089 struct qeth_ipa_cmd *cmd;
1090
Carsten Otte847a50f2010-06-21 22:57:05 +00001091 QETH_CARD_TEXT(card, 4, "defadpcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001092
1093 cmd = (struct qeth_ipa_cmd *) data;
1094 if (cmd->hdr.return_code == 0) {
1095 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1096 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1097 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1098 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1099 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1100 }
1101 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1102 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1103 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001104 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001105 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001106 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
1107 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1108 card->info.tx_csum_mask =
1109 cmd->data.setassparms.data.flags_32bit;
Carsten Otte847a50f2010-06-21 22:57:05 +00001110 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001111 }
1112
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113 return 0;
1114}
1115
1116static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1117 struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1118 __u16 len, enum qeth_prot_versions prot)
1119{
1120 struct qeth_cmd_buffer *iob;
1121 struct qeth_ipa_cmd *cmd;
1122
Carsten Otte847a50f2010-06-21 22:57:05 +00001123 QETH_CARD_TEXT(card, 4, "getasscm");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001124 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1125
1126 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1127 cmd->data.setassparms.hdr.assist_no = ipa_func;
1128 cmd->data.setassparms.hdr.length = 8 + len;
1129 cmd->data.setassparms.hdr.command_code = cmd_code;
1130 cmd->data.setassparms.hdr.return_code = 0;
1131 cmd->data.setassparms.hdr.seq_no = 0;
1132
1133 return iob;
1134}
1135
1136static int qeth_l3_send_setassparms(struct qeth_card *card,
1137 struct qeth_cmd_buffer *iob, __u16 len, long data,
1138 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1139 unsigned long),
1140 void *reply_param)
1141{
1142 int rc;
1143 struct qeth_ipa_cmd *cmd;
1144
Carsten Otte847a50f2010-06-21 22:57:05 +00001145 QETH_CARD_TEXT(card, 4, "sendassp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001146
1147 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1148 if (len <= sizeof(__u32))
1149 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1150 else /* (len > sizeof(__u32)) */
1151 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1152
1153 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1154 return rc;
1155}
1156
1157#ifdef CONFIG_QETH_IPV6
1158static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1159 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1160{
1161 int rc;
1162 struct qeth_cmd_buffer *iob;
1163
Carsten Otte847a50f2010-06-21 22:57:05 +00001164 QETH_CARD_TEXT(card, 4, "simassp6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001165 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1166 0, QETH_PROT_IPV6);
1167 rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1168 qeth_l3_default_setassparms_cb, NULL);
1169 return rc;
1170}
1171#endif
1172
1173static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1174 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1175{
1176 int rc;
1177 int length = 0;
1178 struct qeth_cmd_buffer *iob;
1179
Carsten Otte847a50f2010-06-21 22:57:05 +00001180 QETH_CARD_TEXT(card, 4, "simassp4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001181 if (data)
1182 length = sizeof(__u32);
1183 iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1184 length, QETH_PROT_IPV4);
1185 rc = qeth_l3_send_setassparms(card, iob, length, data,
1186 qeth_l3_default_setassparms_cb, NULL);
1187 return rc;
1188}
1189
1190static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1191{
1192 int rc;
1193
Carsten Otte847a50f2010-06-21 22:57:05 +00001194 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001195
1196 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001197 dev_info(&card->gdev->dev,
1198 "ARP processing not supported on %s!\n",
1199 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001200 return 0;
1201 }
1202 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1203 IPA_CMD_ASS_START, 0);
1204 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001205 dev_warn(&card->gdev->dev,
1206 "Starting ARP processing support for %s failed\n",
1207 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001208 }
1209 return rc;
1210}
1211
1212static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1213{
1214 int rc;
1215
Carsten Otte847a50f2010-06-21 22:57:05 +00001216 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001217
1218 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001219 dev_info(&card->gdev->dev,
1220 "Hardware IP fragmentation not supported on %s\n",
1221 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001222 return -EOPNOTSUPP;
1223 }
1224
1225 rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1226 IPA_CMD_ASS_START, 0);
1227 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001228 dev_warn(&card->gdev->dev,
1229 "Starting IP fragmentation support for %s failed\n",
1230 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001232 dev_info(&card->gdev->dev,
1233 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001234 return rc;
1235}
1236
1237static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1238{
1239 int rc;
1240
Carsten Otte847a50f2010-06-21 22:57:05 +00001241 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001242
Frank Blaschka4a71df52008-02-15 09:19:42 +01001243 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001244 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001245 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001246 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001247 return -EOPNOTSUPP;
1248 }
1249
1250 rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1251 IPA_CMD_ASS_START, 0);
1252 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001253 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001254 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001255 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256 return rc;
1257}
1258
1259static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1260{
1261 int rc = 0;
1262
Carsten Otte847a50f2010-06-21 22:57:05 +00001263 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001264
1265 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001266 dev_info(&card->gdev->dev,
1267 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001268 return -EOPNOTSUPP;
1269 }
1270
1271 rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1272 IPA_CMD_ASS_START, 0);
1273 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001274 dev_warn(&card->gdev->dev,
1275 "Starting VLAN support for %s failed\n",
1276 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001277 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001278 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001279 }
1280 return rc;
1281}
1282
1283static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1284{
1285 int rc;
1286
Carsten Otte847a50f2010-06-21 22:57:05 +00001287 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001288
1289 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001290 dev_info(&card->gdev->dev,
1291 "Multicast not supported on %s\n",
1292 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001293 return -EOPNOTSUPP;
1294 }
1295
1296 rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1297 IPA_CMD_ASS_START, 0);
1298 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001299 dev_warn(&card->gdev->dev,
1300 "Starting multicast support for %s failed\n",
1301 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001302 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001303 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001304 card->dev->flags |= IFF_MULTICAST;
1305 }
1306 return rc;
1307}
1308
1309static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1310 struct qeth_reply *reply, unsigned long data)
1311{
1312 struct qeth_ipa_cmd *cmd;
1313
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001314 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001315
1316 cmd = (struct qeth_ipa_cmd *) data;
1317 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1318 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1319 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1320 } else {
1321 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1322 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1323 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001324 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1325 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1326 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001327 return 0;
1328}
1329
1330static int qeth_l3_query_ipassists(struct qeth_card *card,
1331 enum qeth_prot_versions prot)
1332{
1333 int rc;
1334 struct qeth_cmd_buffer *iob;
1335
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001336 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001337 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1338 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1339 return rc;
1340}
1341
1342#ifdef CONFIG_QETH_IPV6
1343static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1344{
1345 int rc;
1346
Carsten Otte847a50f2010-06-21 22:57:05 +00001347 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001348
1349 if (card->info.type == QETH_CARD_TYPE_IQD)
1350 goto out;
1351
1352 rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1353 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001354 dev_err(&card->gdev->dev,
1355 "Activating IPv6 support for %s failed\n",
1356 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001357 return rc;
1358 }
1359 rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1360 IPA_CMD_ASS_START, 3);
1361 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001362 dev_err(&card->gdev->dev,
1363 "Activating IPv6 support for %s failed\n",
1364 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365 return rc;
1366 }
1367 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1368 IPA_CMD_ASS_START);
1369 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001370 dev_err(&card->gdev->dev,
1371 "Activating IPv6 support for %s failed\n",
1372 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001373 return rc;
1374 }
1375 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1376 IPA_CMD_ASS_START);
1377 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001378 dev_warn(&card->gdev->dev,
1379 "Enabling the passthrough mode for %s failed\n",
1380 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001381 return rc;
1382 }
1383out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001384 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001385 return 0;
1386}
1387#endif
1388
1389static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1390{
1391 int rc = 0;
1392
Carsten Otte847a50f2010-06-21 22:57:05 +00001393 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001394
1395 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001396 dev_info(&card->gdev->dev,
1397 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398 return 0;
1399 }
1400#ifdef CONFIG_QETH_IPV6
1401 rc = qeth_l3_softsetup_ipv6(card);
1402#endif
1403 return rc ;
1404}
1405
1406static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1407{
1408 int rc;
1409
Carsten Otte847a50f2010-06-21 22:57:05 +00001410 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001411 card->info.broadcast_capable = 0;
1412 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001413 dev_info(&card->gdev->dev,
1414 "Broadcast not supported on %s\n",
1415 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001416 rc = -EOPNOTSUPP;
1417 goto out;
1418 }
1419 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1420 IPA_CMD_ASS_START, 0);
1421 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001422 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1423 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001424 goto out;
1425 }
1426
1427 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1428 IPA_CMD_ASS_CONFIGURE, 1);
1429 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001430 dev_warn(&card->gdev->dev,
1431 "Setting up broadcast filtering for %s failed\n",
1432 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001433 goto out;
1434 }
1435 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001436 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001437 rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1438 IPA_CMD_ASS_ENABLE, 1);
1439 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001440 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1441 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001442 goto out;
1443 }
1444 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1445out:
1446 if (card->info.broadcast_capable)
1447 card->dev->flags |= IFF_BROADCAST;
1448 else
1449 card->dev->flags &= ~IFF_BROADCAST;
1450 return rc;
1451}
1452
1453static int qeth_l3_send_checksum_command(struct qeth_card *card)
1454{
1455 int rc;
1456
1457 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1458 IPA_CMD_ASS_START, 0);
1459 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001460 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1461 "failed, using SW checksumming\n",
1462 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001463 return rc;
1464 }
1465 rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1466 IPA_CMD_ASS_ENABLE,
1467 card->info.csum_mask);
1468 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001469 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1470 "failed, using SW checksumming\n",
1471 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001472 return rc;
1473 }
1474 return 0;
1475}
1476
Frank Blaschka3fd434d2009-11-12 00:11:45 +00001477int qeth_l3_set_rx_csum(struct qeth_card *card,
1478 enum qeth_checksum_types csum_type)
1479{
1480 int rc = 0;
1481
1482 if (card->options.checksum_type == HW_CHECKSUMMING) {
1483 if ((csum_type != HW_CHECKSUMMING) &&
1484 (card->state != CARD_STATE_DOWN)) {
1485 rc = qeth_l3_send_simple_setassparms(card,
1486 IPA_INBOUND_CHECKSUM, IPA_CMD_ASS_STOP, 0);
1487 if (rc)
1488 return -EIO;
1489 }
1490 } else {
1491 if (csum_type == HW_CHECKSUMMING) {
1492 if (card->state != CARD_STATE_DOWN) {
1493 if (!qeth_is_supported(card,
1494 IPA_INBOUND_CHECKSUM))
1495 return -EPERM;
1496 rc = qeth_l3_send_checksum_command(card);
1497 if (rc)
1498 return -EIO;
1499 }
1500 }
1501 }
1502 card->options.checksum_type = csum_type;
1503 return rc;
1504}
1505
Frank Blaschka4a71df52008-02-15 09:19:42 +01001506static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1507{
1508 int rc = 0;
1509
Carsten Otte847a50f2010-06-21 22:57:05 +00001510 QETH_CARD_TEXT(card, 3, "strtcsum");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001511
1512 if (card->options.checksum_type == NO_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001513 dev_info(&card->gdev->dev,
1514 "Using no checksumming on %s.\n",
1515 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001516 return 0;
1517 }
1518 if (card->options.checksum_type == SW_CHECKSUMMING) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001519 dev_info(&card->gdev->dev,
1520 "Using SW checksumming on %s.\n",
1521 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001522 return 0;
1523 }
1524 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001525 dev_info(&card->gdev->dev,
1526 "Inbound HW Checksumming not "
1527 "supported on %s,\ncontinuing "
1528 "using Inbound SW Checksumming\n",
1529 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001530 card->options.checksum_type = SW_CHECKSUMMING;
1531 return 0;
1532 }
1533 rc = qeth_l3_send_checksum_command(card);
1534 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001535 dev_info(&card->gdev->dev,
1536 "HW Checksumming (inbound) enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001537
1538 return rc;
1539}
1540
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001541static int qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
1542{
1543 int rc = 0;
1544
1545 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
1546 return rc;
1547 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1548 IPA_CMD_ASS_START, 0);
1549 if (rc)
1550 goto err_out;
1551 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_CHECKSUM,
1552 IPA_CMD_ASS_ENABLE, card->info.tx_csum_mask);
1553 if (rc)
1554 goto err_out;
1555 dev_info(&card->gdev->dev, "HW TX Checksumming enabled\n");
1556 return rc;
1557err_out:
1558 dev_warn(&card->gdev->dev, "Enabling HW TX checksumming for %s "
1559 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card));
1560 return rc;
1561}
1562
Frank Blaschka4a71df52008-02-15 09:19:42 +01001563static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1564{
1565 int rc;
1566
Carsten Otte847a50f2010-06-21 22:57:05 +00001567 QETH_CARD_TEXT(card, 3, "sttso");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001568
1569 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001570 dev_info(&card->gdev->dev,
1571 "Outbound TSO not supported on %s\n",
1572 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001573 rc = -EOPNOTSUPP;
1574 } else {
1575 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1576 IPA_CMD_ASS_START, 0);
1577 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001578 dev_warn(&card->gdev->dev, "Starting outbound TCP "
1579 "segmentation offload for %s failed\n",
1580 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001581 else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001582 dev_info(&card->gdev->dev,
1583 "Outbound TSO enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001584 }
1585 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1586 card->options.large_send = QETH_LARGE_SEND_NO;
1587 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1588 }
1589 return rc;
1590}
1591
1592static int qeth_l3_start_ipassists(struct qeth_card *card)
1593{
Carsten Otte847a50f2010-06-21 22:57:05 +00001594 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001595
1596 qeth_set_access_ctrl_online(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001597 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1598 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1599 qeth_l3_start_ipa_source_mac(card); /* go on*/
1600 qeth_l3_start_ipa_vlan(card); /* go on*/
1601 qeth_l3_start_ipa_multicast(card); /* go on*/
1602 qeth_l3_start_ipa_ipv6(card); /* go on*/
1603 qeth_l3_start_ipa_broadcast(card); /* go on*/
1604 qeth_l3_start_ipa_checksum(card); /* go on*/
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00001605 qeth_l3_start_ipa_tx_checksum(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001606 qeth_l3_start_ipa_tso(card); /* go on*/
1607 return 0;
1608}
1609
1610static int qeth_l3_put_unique_id(struct qeth_card *card)
1611{
1612
1613 int rc = 0;
1614 struct qeth_cmd_buffer *iob;
1615 struct qeth_ipa_cmd *cmd;
1616
Carsten Otte847a50f2010-06-21 22:57:05 +00001617 QETH_CARD_TEXT(card, 2, "puniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001618
1619 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1620 UNIQUE_ID_NOT_BY_CARD)
1621 return -1;
1622 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1623 QETH_PROT_IPV6);
1624 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1625 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1626 card->info.unique_id;
1627 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1628 card->dev->dev_addr, OSA_ADDR_LEN);
1629 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1630 return rc;
1631}
1632
1633static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1634 struct qeth_reply *reply, unsigned long data)
1635{
1636 struct qeth_ipa_cmd *cmd;
1637
1638 cmd = (struct qeth_ipa_cmd *) data;
1639 if (cmd->hdr.return_code == 0)
1640 memcpy(card->dev->dev_addr,
1641 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1642 else
1643 random_ether_addr(card->dev->dev_addr);
1644
1645 return 0;
1646}
1647
1648static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1649{
1650 int rc = 0;
1651 struct qeth_cmd_buffer *iob;
1652 struct qeth_ipa_cmd *cmd;
1653
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001654 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001655
1656 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1657 QETH_PROT_IPV6);
1658 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1659 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1660 card->info.unique_id;
1661
1662 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1663 NULL);
1664 return rc;
1665}
1666
1667static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1668 struct qeth_reply *reply, unsigned long data)
1669{
1670 struct qeth_ipa_cmd *cmd;
1671
1672 cmd = (struct qeth_ipa_cmd *) data;
1673 if (cmd->hdr.return_code == 0)
1674 card->info.unique_id = *((__u16 *)
1675 &cmd->data.create_destroy_addr.unique_id[6]);
1676 else {
1677 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1678 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001679 dev_warn(&card->gdev->dev, "The network adapter failed to "
1680 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001681 }
1682 return 0;
1683}
1684
1685static int qeth_l3_get_unique_id(struct qeth_card *card)
1686{
1687 int rc = 0;
1688 struct qeth_cmd_buffer *iob;
1689 struct qeth_ipa_cmd *cmd;
1690
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001691 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001692
1693 if (!qeth_is_supported(card, IPA_IPV6)) {
1694 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1695 UNIQUE_ID_NOT_BY_CARD;
1696 return 0;
1697 }
1698
1699 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1700 QETH_PROT_IPV6);
1701 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1702 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1703 card->info.unique_id;
1704
1705 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1706 return rc;
1707}
1708
Ursula Braun76b11f82010-01-11 02:50:50 +00001709static int
1710qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1711 unsigned long data)
1712{
1713 struct qeth_ipa_cmd *cmd;
1714 __u16 rc;
1715
1716 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1717
1718 cmd = (struct qeth_ipa_cmd *)data;
1719 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001720 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001721 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001722 switch (cmd->data.diagass.action) {
1723 case QETH_DIAGS_CMD_TRACE_QUERY:
1724 break;
1725 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001726 switch (rc) {
1727 case 0:
1728 case IPA_RC_INVALID_SUBCMD:
1729 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1730 dev_info(&card->gdev->dev, "The HiperSockets network "
1731 "traffic analyzer is deactivated\n");
1732 break;
1733 default:
1734 break;
1735 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001736 break;
1737 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001738 switch (rc) {
1739 case 0:
1740 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1741 dev_info(&card->gdev->dev, "The HiperSockets network "
1742 "traffic analyzer is activated\n");
1743 break;
1744 case IPA_RC_HARDWARE_AUTH_ERROR:
1745 dev_warn(&card->gdev->dev, "The device is not "
1746 "authorized to run as a HiperSockets network "
1747 "traffic analyzer\n");
1748 break;
1749 case IPA_RC_TRACE_ALREADY_ACTIVE:
1750 dev_warn(&card->gdev->dev, "A HiperSockets "
1751 "network traffic analyzer is already "
1752 "active in the HiperSockets LAN\n");
1753 break;
1754 default:
1755 break;
1756 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001757 break;
1758 default:
1759 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1760 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1761 }
1762
1763 return 0;
1764}
1765
1766static int
1767qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1768{
1769 struct qeth_cmd_buffer *iob;
1770 struct qeth_ipa_cmd *cmd;
1771
1772 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1773
1774 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
1775 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1776 cmd->data.diagass.subcmd_len = 16;
1777 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1778 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1779 cmd->data.diagass.action = diags_cmd;
1780 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1781}
1782
Frank Blaschka4a71df52008-02-15 09:19:42 +01001783static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1784 struct net_device *dev)
1785{
1786 if (dev->type == ARPHRD_IEEE802_TR)
1787 ip_tr_mc_map(ipm, mac);
1788 else
1789 ip_eth_mc_map(ipm, mac);
1790}
1791
1792static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1793{
1794 struct qeth_ipaddr *ipm;
1795 struct ip_mc_list *im4;
1796 char buf[MAX_ADDR_LEN];
1797
Carsten Otte847a50f2010-06-21 22:57:05 +00001798 QETH_CARD_TEXT(card, 4, "addmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001799 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1800 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1801 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1802 if (!ipm)
1803 continue;
1804 ipm->u.a4.addr = im4->multiaddr;
1805 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1806 ipm->is_multicast = 1;
1807 if (!qeth_l3_add_ip(card, ipm))
1808 kfree(ipm);
1809 }
1810}
1811
1812static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1813{
1814 struct in_device *in_dev;
1815 struct vlan_group *vg;
1816 int i;
1817
Carsten Otte847a50f2010-06-21 22:57:05 +00001818 QETH_CARD_TEXT(card, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001819 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1820 return;
1821
1822 vg = card->vlangrp;
1823 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1824 struct net_device *netdev = vlan_group_get_device(vg, i);
1825 if (netdev == NULL ||
1826 !(netdev->flags & IFF_UP))
1827 continue;
1828 in_dev = in_dev_get(netdev);
1829 if (!in_dev)
1830 continue;
1831 read_lock(&in_dev->mc_list_lock);
1832 qeth_l3_add_mc(card, in_dev);
1833 read_unlock(&in_dev->mc_list_lock);
1834 in_dev_put(in_dev);
1835 }
1836}
1837
1838static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1839{
1840 struct in_device *in4_dev;
1841
Carsten Otte847a50f2010-06-21 22:57:05 +00001842 QETH_CARD_TEXT(card, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001843 in4_dev = in_dev_get(card->dev);
1844 if (in4_dev == NULL)
1845 return;
1846 read_lock(&in4_dev->mc_list_lock);
1847 qeth_l3_add_mc(card, in4_dev);
1848 qeth_l3_add_vlan_mc(card);
1849 read_unlock(&in4_dev->mc_list_lock);
1850 in_dev_put(in4_dev);
1851}
1852
1853#ifdef CONFIG_QETH_IPV6
1854static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1855{
1856 struct qeth_ipaddr *ipm;
1857 struct ifmcaddr6 *im6;
1858 char buf[MAX_ADDR_LEN];
1859
Carsten Otte847a50f2010-06-21 22:57:05 +00001860 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001861 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1862 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1863 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1864 if (!ipm)
1865 continue;
1866 ipm->is_multicast = 1;
1867 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1868 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1869 sizeof(struct in6_addr));
1870 if (!qeth_l3_add_ip(card, ipm))
1871 kfree(ipm);
1872 }
1873}
1874
1875static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1876{
1877 struct inet6_dev *in_dev;
1878 struct vlan_group *vg;
1879 int i;
1880
Carsten Otte847a50f2010-06-21 22:57:05 +00001881 QETH_CARD_TEXT(card, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001882 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1883 return;
1884
1885 vg = card->vlangrp;
1886 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1887 struct net_device *netdev = vlan_group_get_device(vg, i);
1888 if (netdev == NULL ||
1889 !(netdev->flags & IFF_UP))
1890 continue;
1891 in_dev = in6_dev_get(netdev);
1892 if (!in_dev)
1893 continue;
1894 read_lock_bh(&in_dev->lock);
1895 qeth_l3_add_mc6(card, in_dev);
1896 read_unlock_bh(&in_dev->lock);
1897 in6_dev_put(in_dev);
1898 }
1899}
1900
1901static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1902{
1903 struct inet6_dev *in6_dev;
1904
Carsten Otte847a50f2010-06-21 22:57:05 +00001905 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001906 if (!qeth_is_supported(card, IPA_IPV6))
1907 return ;
1908 in6_dev = in6_dev_get(card->dev);
1909 if (in6_dev == NULL)
1910 return;
1911 read_lock_bh(&in6_dev->lock);
1912 qeth_l3_add_mc6(card, in6_dev);
1913 qeth_l3_add_vlan_mc6(card);
1914 read_unlock_bh(&in6_dev->lock);
1915 in6_dev_put(in6_dev);
1916}
1917#endif /* CONFIG_QETH_IPV6 */
1918
1919static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1920 unsigned short vid)
1921{
1922 struct in_device *in_dev;
1923 struct in_ifaddr *ifa;
1924 struct qeth_ipaddr *addr;
1925
Carsten Otte847a50f2010-06-21 22:57:05 +00001926 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001927
1928 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1929 if (!in_dev)
1930 return;
1931 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1932 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1933 if (addr) {
1934 addr->u.a4.addr = ifa->ifa_address;
1935 addr->u.a4.mask = ifa->ifa_mask;
1936 addr->type = QETH_IP_TYPE_NORMAL;
1937 if (!qeth_l3_delete_ip(card, addr))
1938 kfree(addr);
1939 }
1940 }
1941 in_dev_put(in_dev);
1942}
1943
1944static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1945 unsigned short vid)
1946{
1947#ifdef CONFIG_QETH_IPV6
1948 struct inet6_dev *in6_dev;
1949 struct inet6_ifaddr *ifa;
1950 struct qeth_ipaddr *addr;
1951
Carsten Otte847a50f2010-06-21 22:57:05 +00001952 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001953
1954 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1955 if (!in6_dev)
1956 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001957 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001958 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1959 if (addr) {
1960 memcpy(&addr->u.a6.addr, &ifa->addr,
1961 sizeof(struct in6_addr));
1962 addr->u.a6.pfxlen = ifa->prefix_len;
1963 addr->type = QETH_IP_TYPE_NORMAL;
1964 if (!qeth_l3_delete_ip(card, addr))
1965 kfree(addr);
1966 }
1967 }
1968 in6_dev_put(in6_dev);
1969#endif /* CONFIG_QETH_IPV6 */
1970}
1971
1972static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1973 unsigned short vid)
1974{
1975 if (!card->vlangrp)
1976 return;
1977 qeth_l3_free_vlan_addresses4(card, vid);
1978 qeth_l3_free_vlan_addresses6(card, vid);
1979}
1980
1981static void qeth_l3_vlan_rx_register(struct net_device *dev,
1982 struct vlan_group *grp)
1983{
Heiko Carstens509e2562008-07-26 02:24:10 -07001984 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001985 unsigned long flags;
1986
Carsten Otte847a50f2010-06-21 22:57:05 +00001987 QETH_CARD_TEXT(card, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001988 spin_lock_irqsave(&card->vlanlock, flags);
1989 card->vlangrp = grp;
1990 spin_unlock_irqrestore(&card->vlanlock, flags);
1991}
1992
1993static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1994{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001995 return;
1996}
1997
1998static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1999{
Heiko Carstens509e2562008-07-26 02:24:10 -07002000 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002001 unsigned long flags;
2002
Carsten Otte847a50f2010-06-21 22:57:05 +00002003 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00002004 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002005 QETH_CARD_TEXT(card, 3, "kidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002006 return;
2007 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002008 spin_lock_irqsave(&card->vlanlock, flags);
2009 /* unregister IP addresses of vlan device */
2010 qeth_l3_free_vlan_addresses(card, vid);
2011 vlan_group_set_device(card->vlangrp, vid, NULL);
2012 spin_unlock_irqrestore(&card->vlanlock, flags);
2013 qeth_l3_set_multicast_list(card->dev);
2014}
2015
Ursula Braun10651db2010-10-01 02:51:13 +00002016static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
2017 struct sk_buff *skb, struct qeth_hdr *hdr,
2018 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002019{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002020 __be16 prot;
2021 struct iphdr *ip_hdr;
2022 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00002023 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002024
2025 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
2026 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2027 ETH_P_IP);
2028 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
2029 case QETH_CAST_MULTICAST:
2030 switch (prot) {
2031#ifdef CONFIG_QETH_IPV6
2032 case __constant_htons(ETH_P_IPV6):
2033 ndisc_mc_map((struct in6_addr *)
2034 skb->data + 24,
2035 tg_addr, card->dev, 0);
2036 break;
2037#endif
2038 case __constant_htons(ETH_P_IP):
2039 ip_hdr = (struct iphdr *)skb->data;
2040 (card->dev->type == ARPHRD_IEEE802_TR) ?
2041 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
2042 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
2043 break;
2044 default:
2045 memcpy(tg_addr, card->dev->broadcast,
2046 card->dev->addr_len);
2047 }
2048 card->stats.multicast++;
2049 skb->pkt_type = PACKET_MULTICAST;
2050 break;
2051 case QETH_CAST_BROADCAST:
2052 memcpy(tg_addr, card->dev->broadcast,
2053 card->dev->addr_len);
2054 card->stats.multicast++;
2055 skb->pkt_type = PACKET_BROADCAST;
2056 break;
2057 case QETH_CAST_UNICAST:
2058 case QETH_CAST_ANYCAST:
2059 case QETH_CAST_NOCAST:
2060 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00002061 if (card->options.sniffer)
2062 skb->pkt_type = PACKET_OTHERHOST;
2063 else
2064 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002065 memcpy(tg_addr, card->dev->dev_addr,
2066 card->dev->addr_len);
2067 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08002068 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2069 card->dev->header_ops->create(skb, card->dev, prot,
2070 tg_addr, &hdr->hdr.l3.dest_addr[2],
2071 card->dev->addr_len);
2072 else
2073 card->dev->header_ops->create(skb, card->dev, prot,
2074 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002075 }
2076
2077#ifdef CONFIG_TR
2078 if (card->dev->type == ARPHRD_IEEE802_TR)
2079 skb->protocol = tr_type_trans(skb, card->dev);
2080 else
2081#endif
2082 skb->protocol = eth_type_trans(skb, card->dev);
2083
2084 if (hdr->hdr.l3.ext_flags &
2085 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00002086 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01002087 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00002088 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002089 }
2090
Ursula Braunb9139802009-05-19 21:38:40 +00002091 switch (card->options.checksum_type) {
2092 case SW_CHECKSUMMING:
2093 skb->ip_summed = CHECKSUM_NONE;
2094 break;
2095 case NO_CHECKSUMMING:
2096 skb->ip_summed = CHECKSUM_UNNECESSARY;
2097 break;
2098 case HW_CHECKSUMMING:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002099 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00002100 (QETH_HDR_EXT_CSUM_HDR_REQ |
2101 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2102 (QETH_HDR_EXT_CSUM_HDR_REQ |
2103 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002104 skb->ip_summed = CHECKSUM_UNNECESSARY;
2105 else
Ursula Braunb9139802009-05-19 21:38:40 +00002106 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002107 }
2108
Ursula Braun10651db2010-10-01 02:51:13 +00002109 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002110}
2111
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002112static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
2113 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002114{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002115 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002116 struct sk_buff *skb;
2117 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002118 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00002119 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002120 unsigned int len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002121
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002122 *done = 0;
2123 BUG_ON(!budget);
2124 while (budget) {
2125 skb = qeth_core_get_next_skb(card,
2126 card->qdio.in_q->bufs[card->rx.b_index].buffer,
2127 &card->rx.b_element, &card->rx.e_offset, &hdr);
2128 if (!skb) {
2129 *done = 1;
2130 break;
2131 }
2132 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002133 switch (hdr->hdr.l3.id) {
2134 case QETH_HEADER_TYPE_LAYER3:
Ursula Braun10651db2010-10-01 02:51:13 +00002135 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
2136 &vlan_tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002137 len = skb->len;
Ursula Braun10651db2010-10-01 02:51:13 +00002138 if (is_vlan && !card->options.sniffer)
2139 vlan_gro_receive(&card->napi, card->vlangrp,
2140 vlan_tag, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002141 else
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002142 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002143 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002144 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2145 skb->pkt_type = PACKET_HOST;
2146 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002147 len = skb->len;
2148 netif_receive_skb(skb);
2149 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002150 default:
2151 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002152 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002153 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002154 continue;
2155 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002156 work_done++;
2157 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002158 card->stats.rx_packets++;
2159 card->stats.rx_bytes += len;
2160 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002161 return work_done;
2162}
2163
2164static int qeth_l3_poll(struct napi_struct *napi, int budget)
2165{
2166 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2167 int work_done = 0;
2168 struct qeth_qdio_buffer *buffer;
2169 int done;
2170 int new_budget = budget;
2171
2172 if (card->options.performance_stats) {
2173 card->perf_stats.inbound_cnt++;
2174 card->perf_stats.inbound_start_time = qeth_get_micros();
2175 }
2176
2177 while (1) {
2178 if (!card->rx.b_count) {
2179 card->rx.qdio_err = 0;
2180 card->rx.b_count = qdio_get_next_buffers(
2181 card->data.ccwdev, 0, &card->rx.b_index,
2182 &card->rx.qdio_err);
2183 if (card->rx.b_count <= 0) {
2184 card->rx.b_count = 0;
2185 break;
2186 }
2187 card->rx.b_element =
2188 &card->qdio.in_q->bufs[card->rx.b_index]
2189 .buffer->element[0];
2190 card->rx.e_offset = 0;
2191 }
2192
2193 while (card->rx.b_count) {
2194 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2195 if (!(card->rx.qdio_err &&
2196 qeth_check_qdio_errors(card, buffer->buffer,
2197 card->rx.qdio_err, "qinerr")))
2198 work_done += qeth_l3_process_inbound_buffer(
2199 card, new_budget, &done);
2200 else
2201 done = 1;
2202
2203 if (done) {
2204 if (card->options.performance_stats)
2205 card->perf_stats.bufs_rec++;
2206 qeth_put_buffer_pool_entry(card,
2207 buffer->pool_entry);
2208 qeth_queue_input_buffer(card, card->rx.b_index);
2209 card->rx.b_count--;
2210 if (card->rx.b_count) {
2211 card->rx.b_index =
2212 (card->rx.b_index + 1) %
2213 QDIO_MAX_BUFFERS_PER_Q;
2214 card->rx.b_element =
2215 &card->qdio.in_q
2216 ->bufs[card->rx.b_index]
2217 .buffer->element[0];
2218 card->rx.e_offset = 0;
2219 }
2220 }
2221
2222 if (work_done >= budget)
2223 goto out;
2224 else
2225 new_budget = budget - work_done;
2226 }
2227 }
2228
2229 napi_complete(napi);
2230 if (qdio_start_irq(card->data.ccwdev, 0))
2231 napi_schedule(&card->napi);
2232out:
2233 if (card->options.performance_stats)
2234 card->perf_stats.inbound_time += qeth_get_micros() -
2235 card->perf_stats.inbound_start_time;
2236 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002237}
2238
2239static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2240 struct qeth_card *card)
2241{
2242 int rc = 0;
2243 struct vlan_group *vg;
2244 int i;
2245
2246 vg = card->vlangrp;
2247 if (!vg)
2248 return rc;
2249
2250 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
2251 if (vlan_group_get_device(vg, i) == dev) {
2252 rc = QETH_VLAN_CARD;
2253 break;
2254 }
2255 }
2256
Heiko Carstens509e2562008-07-26 02:24:10 -07002257 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002258 return 0;
2259
2260 return rc;
2261}
2262
2263static int qeth_l3_verify_dev(struct net_device *dev)
2264{
2265 struct qeth_card *card;
2266 unsigned long flags;
2267 int rc = 0;
2268
2269 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2270 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2271 if (card->dev == dev) {
2272 rc = QETH_REAL_CARD;
2273 break;
2274 }
2275 rc = qeth_l3_verify_vlan_dev(dev, card);
2276 if (rc)
2277 break;
2278 }
2279 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2280
2281 return rc;
2282}
2283
2284static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2285{
2286 struct qeth_card *card = NULL;
2287 int rc;
2288
2289 rc = qeth_l3_verify_dev(dev);
2290 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002291 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002292 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002293 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002294 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002295 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002296 if (card)
2297 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002298 return card ;
2299}
2300
2301static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2302{
2303 int rc = 0;
2304
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002305 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2306 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002307
2308 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002309 if (card->options.sniffer &&
2310 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2311 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002312 if (card->read.state == CH_STATE_UP &&
2313 card->write.state == CH_STATE_UP &&
2314 (card->state == CARD_STATE_UP)) {
2315 if (recovery_mode)
2316 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002317 else {
Ursula Braun869da902010-03-08 20:36:56 +00002318 rtnl_lock();
2319 dev_close(card->dev);
2320 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002321 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002322 if (!card->use_hard_stop) {
2323 rc = qeth_send_stoplan(card);
2324 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002325 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002326 }
2327 card->state = CARD_STATE_SOFTSETUP;
2328 }
2329 if (card->state == CARD_STATE_SOFTSETUP) {
2330 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2331 qeth_clear_ipacmd_list(card);
2332 card->state = CARD_STATE_HARDSETUP;
2333 }
2334 if (card->state == CARD_STATE_HARDSETUP) {
2335 if (!card->use_hard_stop &&
2336 (card->info.type != QETH_CARD_TYPE_IQD)) {
2337 rc = qeth_l3_put_unique_id(card);
2338 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002339 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002340 }
2341 qeth_qdio_clear_card(card, 0);
2342 qeth_clear_qdio_buffers(card);
2343 qeth_clear_working_pool_list(card);
2344 card->state = CARD_STATE_DOWN;
2345 }
2346 if (card->state == CARD_STATE_DOWN) {
2347 qeth_clear_cmd_buffers(&card->read);
2348 qeth_clear_cmd_buffers(&card->write);
2349 }
2350 card->use_hard_stop = 0;
2351 return rc;
2352}
2353
Ursula Braun76b11f82010-01-11 02:50:50 +00002354/*
2355 * test for and Switch promiscuous mode (on or off)
2356 * either for guestlan or HiperSocket Sniffer
2357 */
2358static void
2359qeth_l3_handle_promisc_mode(struct qeth_card *card)
2360{
2361 struct net_device *dev = card->dev;
2362
2363 if (((dev->flags & IFF_PROMISC) &&
2364 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2365 (!(dev->flags & IFF_PROMISC) &&
2366 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2367 return;
2368
2369 if (card->info.guestlan) { /* Guestlan trace */
2370 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2371 qeth_setadp_promisc_mode(card);
2372 } else if (card->options.sniffer && /* HiperSockets trace */
2373 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2374 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002375 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002376 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2377 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002378 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002379 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2380 }
2381 }
2382}
2383
Frank Blaschka4a71df52008-02-15 09:19:42 +01002384static void qeth_l3_set_multicast_list(struct net_device *dev)
2385{
Heiko Carstens509e2562008-07-26 02:24:10 -07002386 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002387
Carsten Otte847a50f2010-06-21 22:57:05 +00002388 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002389 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2390 (card->state != CARD_STATE_UP))
2391 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002392 if (!card->options.sniffer) {
2393 qeth_l3_delete_mc_addresses(card);
2394 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002395#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002396 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002397#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002398 qeth_l3_set_ip_addr_list(card);
2399 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2400 return;
2401 }
2402 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002403}
2404
2405static const char *qeth_l3_arp_get_error_cause(int *rc)
2406{
2407 switch (*rc) {
2408 case QETH_IPA_ARP_RC_FAILED:
2409 *rc = -EIO;
2410 return "operation failed";
2411 case QETH_IPA_ARP_RC_NOTSUPP:
2412 *rc = -EOPNOTSUPP;
2413 return "operation not supported";
2414 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2415 *rc = -EINVAL;
2416 return "argument out of range";
2417 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2418 *rc = -EOPNOTSUPP;
2419 return "query operation not supported";
2420 case QETH_IPA_ARP_RC_Q_NO_DATA:
2421 *rc = -ENOENT;
2422 return "no query data available";
2423 default:
2424 return "unknown error";
2425 }
2426}
2427
2428static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2429{
2430 int tmp;
2431 int rc;
2432
Carsten Otte847a50f2010-06-21 22:57:05 +00002433 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002434
2435 /*
2436 * currently GuestLAN only supports the ARP assist function
2437 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2438 * thus we say EOPNOTSUPP for this ARP function
2439 */
2440 if (card->info.guestlan)
2441 return -EOPNOTSUPP;
2442 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002443 return -EOPNOTSUPP;
2444 }
2445 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2446 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2447 no_entries);
2448 if (rc) {
2449 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002450 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2451 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002452 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2453 }
2454 return rc;
2455}
2456
2457static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2458 struct qeth_arp_query_data *qdata, int entry_size,
2459 int uentry_size)
2460{
2461 char *entry_ptr;
2462 char *uentry_ptr;
2463 int i;
2464
2465 entry_ptr = (char *)&qdata->data;
2466 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2467 for (i = 0; i < qdata->no_entries; ++i) {
2468 /* strip off 32 bytes "media specific information" */
2469 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2470 entry_ptr += entry_size;
2471 uentry_ptr += uentry_size;
2472 }
2473}
2474
2475static int qeth_l3_arp_query_cb(struct qeth_card *card,
2476 struct qeth_reply *reply, unsigned long data)
2477{
2478 struct qeth_ipa_cmd *cmd;
2479 struct qeth_arp_query_data *qdata;
2480 struct qeth_arp_query_info *qinfo;
2481 int entry_size;
2482 int uentry_size;
2483 int i;
2484
Carsten Otte847a50f2010-06-21 22:57:05 +00002485 QETH_CARD_TEXT(card, 4, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002486
2487 qinfo = (struct qeth_arp_query_info *) reply->param;
2488 cmd = (struct qeth_ipa_cmd *) data;
2489 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002490 QETH_CARD_TEXT_(card, 4, "qaer1%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002491 return 0;
2492 }
2493 if (cmd->data.setassparms.hdr.return_code) {
2494 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Carsten Otte847a50f2010-06-21 22:57:05 +00002495 QETH_CARD_TEXT_(card, 4, "qaer2%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002496 return 0;
2497 }
2498 qdata = &cmd->data.setassparms.data.query_arp;
2499 switch (qdata->reply_bits) {
2500 case 5:
2501 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2502 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2503 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2504 break;
2505 case 7:
2506 /* fall through to default */
2507 default:
2508 /* tr is the same as eth -> entry7 */
2509 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2510 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2511 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2512 break;
2513 }
2514 /* check if there is enough room in userspace */
2515 if ((qinfo->udata_len - qinfo->udata_offset) <
2516 qdata->no_entries * uentry_size){
Carsten Otte847a50f2010-06-21 22:57:05 +00002517 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002518 cmd->hdr.return_code = -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002519 goto out_error;
2520 }
Carsten Otte847a50f2010-06-21 22:57:05 +00002521 QETH_CARD_TEXT_(card, 4, "anore%i",
Frank Blaschka4a71df52008-02-15 09:19:42 +01002522 cmd->data.setassparms.hdr.number_of_replies);
Carsten Otte847a50f2010-06-21 22:57:05 +00002523 QETH_CARD_TEXT_(card, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2524 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002525
2526 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2527 /* strip off "media specific information" */
2528 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2529 uentry_size);
2530 } else
2531 /*copy entries to user buffer*/
2532 memcpy(qinfo->udata + qinfo->udata_offset,
2533 (char *)&qdata->data, qdata->no_entries*uentry_size);
2534
2535 qinfo->no_entries += qdata->no_entries;
2536 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2537 /* check if all replies received ... */
2538 if (cmd->data.setassparms.hdr.seq_no <
2539 cmd->data.setassparms.hdr.number_of_replies)
2540 return 1;
2541 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2542 /* keep STRIP_ENTRIES flag so the user program can distinguish
2543 * stripped entries from normal ones */
2544 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2545 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2546 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2547 return 0;
2548out_error:
2549 i = 0;
2550 memcpy(qinfo->udata, &i, 4);
2551 return 0;
2552}
2553
2554static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2555 struct qeth_cmd_buffer *iob, int len,
2556 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2557 unsigned long),
2558 void *reply_param)
2559{
Carsten Otte847a50f2010-06-21 22:57:05 +00002560 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002561
2562 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2563 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2564 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2565 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2566 reply_cb, reply_param);
2567}
2568
2569static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2570{
2571 struct qeth_cmd_buffer *iob;
2572 struct qeth_arp_query_info qinfo = {0, };
2573 int tmp;
2574 int rc;
2575
Carsten Otte847a50f2010-06-21 22:57:05 +00002576 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002577
2578 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2579 IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002580 return -EOPNOTSUPP;
2581 }
2582 /* get size of userspace buffer and mask_bits -> 6 bytes */
2583 if (copy_from_user(&qinfo, udata, 6))
2584 return -EFAULT;
2585 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2586 if (!qinfo.udata)
2587 return -ENOMEM;
2588 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2589 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2590 IPA_CMD_ASS_ARP_QUERY_INFO,
2591 sizeof(int), QETH_PROT_IPV4);
2592
2593 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2594 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2595 qeth_l3_arp_query_cb, (void *)&qinfo);
2596 if (rc) {
2597 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002598 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
Frank Blaschka4a71df52008-02-15 09:19:42 +01002599 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2600 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2601 if (copy_to_user(udata, qinfo.udata, 4))
2602 rc = -EFAULT;
2603 } else {
2604 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2605 rc = -EFAULT;
2606 }
2607 kfree(qinfo.udata);
2608 return rc;
2609}
2610
2611static int qeth_l3_arp_add_entry(struct qeth_card *card,
2612 struct qeth_arp_cache_entry *entry)
2613{
2614 struct qeth_cmd_buffer *iob;
2615 char buf[16];
2616 int tmp;
2617 int rc;
2618
Carsten Otte847a50f2010-06-21 22:57:05 +00002619 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002620
2621 /*
2622 * currently GuestLAN only supports the ARP assist function
2623 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2624 * thus we say EOPNOTSUPP for this ARP function
2625 */
2626 if (card->info.guestlan)
2627 return -EOPNOTSUPP;
2628 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002629 return -EOPNOTSUPP;
2630 }
2631
2632 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2633 IPA_CMD_ASS_ARP_ADD_ENTRY,
2634 sizeof(struct qeth_arp_cache_entry),
2635 QETH_PROT_IPV4);
2636 rc = qeth_l3_send_setassparms(card, iob,
2637 sizeof(struct qeth_arp_cache_entry),
2638 (unsigned long) entry,
2639 qeth_l3_default_setassparms_cb, NULL);
2640 if (rc) {
2641 tmp = rc;
2642 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002643 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2644 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2645 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002646 }
2647 return rc;
2648}
2649
2650static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2651 struct qeth_arp_cache_entry *entry)
2652{
2653 struct qeth_cmd_buffer *iob;
2654 char buf[16] = {0, };
2655 int tmp;
2656 int rc;
2657
Carsten Otte847a50f2010-06-21 22:57:05 +00002658 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002659
2660 /*
2661 * currently GuestLAN only supports the ARP assist function
2662 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2663 * thus we say EOPNOTSUPP for this ARP function
2664 */
2665 if (card->info.guestlan)
2666 return -EOPNOTSUPP;
2667 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002668 return -EOPNOTSUPP;
2669 }
2670 memcpy(buf, entry, 12);
2671 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2672 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2673 12,
2674 QETH_PROT_IPV4);
2675 rc = qeth_l3_send_setassparms(card, iob,
2676 12, (unsigned long)buf,
2677 qeth_l3_default_setassparms_cb, NULL);
2678 if (rc) {
2679 tmp = rc;
2680 memset(buf, 0, 16);
2681 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002682 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2683 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2684 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002685 }
2686 return rc;
2687}
2688
2689static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2690{
2691 int rc;
2692 int tmp;
2693
Carsten Otte847a50f2010-06-21 22:57:05 +00002694 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002695
2696 /*
2697 * currently GuestLAN only supports the ARP assist function
2698 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2699 * thus we say EOPNOTSUPP for this ARP function
2700 */
2701 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2702 return -EOPNOTSUPP;
2703 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002704 return -EOPNOTSUPP;
2705 }
2706 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2707 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2708 if (rc) {
2709 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002710 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2711 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002712 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2713 }
2714 return rc;
2715}
2716
2717static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2718{
Heiko Carstens509e2562008-07-26 02:24:10 -07002719 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002720 struct qeth_arp_cache_entry arp_entry;
2721 struct mii_ioctl_data *mii_data;
2722 int rc = 0;
2723
2724 if (!card)
2725 return -ENODEV;
2726
2727 if ((card->state != CARD_STATE_UP) &&
2728 (card->state != CARD_STATE_SOFTSETUP))
2729 return -ENODEV;
2730
2731 switch (cmd) {
2732 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2733 if (!capable(CAP_NET_ADMIN)) {
2734 rc = -EPERM;
2735 break;
2736 }
2737 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2738 break;
2739 case SIOC_QETH_ARP_QUERY_INFO:
2740 if (!capable(CAP_NET_ADMIN)) {
2741 rc = -EPERM;
2742 break;
2743 }
2744 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2745 break;
2746 case SIOC_QETH_ARP_ADD_ENTRY:
2747 if (!capable(CAP_NET_ADMIN)) {
2748 rc = -EPERM;
2749 break;
2750 }
2751 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2752 sizeof(struct qeth_arp_cache_entry)))
2753 rc = -EFAULT;
2754 else
2755 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2756 break;
2757 case SIOC_QETH_ARP_REMOVE_ENTRY:
2758 if (!capable(CAP_NET_ADMIN)) {
2759 rc = -EPERM;
2760 break;
2761 }
2762 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2763 sizeof(struct qeth_arp_cache_entry)))
2764 rc = -EFAULT;
2765 else
2766 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2767 break;
2768 case SIOC_QETH_ARP_FLUSH_CACHE:
2769 if (!capable(CAP_NET_ADMIN)) {
2770 rc = -EPERM;
2771 break;
2772 }
2773 rc = qeth_l3_arp_flush_cache(card);
2774 break;
2775 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2776 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2777 break;
2778 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002779 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2780 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002781 !card->info.guestlan)
2782 return 1;
2783 return 0;
2784 break;
2785 case SIOCGMIIPHY:
2786 mii_data = if_mii(rq);
2787 mii_data->phy_id = 0;
2788 break;
2789 case SIOCGMIIREG:
2790 mii_data = if_mii(rq);
2791 if (mii_data->phy_id != 0)
2792 rc = -EINVAL;
2793 else
2794 mii_data->val_out = qeth_mdio_read(dev,
2795 mii_data->phy_id,
2796 mii_data->reg_num);
2797 break;
2798 default:
2799 rc = -EOPNOTSUPP;
2800 }
2801 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002802 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002803 return rc;
2804}
2805
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002806int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2807{
2808 int cast_type = RTN_UNSPEC;
2809
2810 if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2811 cast_type = skb_dst(skb)->neighbour->type;
2812 if ((cast_type == RTN_BROADCAST) ||
2813 (cast_type == RTN_MULTICAST) ||
2814 (cast_type == RTN_ANYCAST))
2815 return cast_type;
2816 else
2817 return RTN_UNSPEC;
2818 }
2819 /* try something else */
2820 if (skb->protocol == ETH_P_IPV6)
2821 return (skb_network_header(skb)[24] == 0xff) ?
2822 RTN_MULTICAST : 0;
2823 else if (skb->protocol == ETH_P_IP)
2824 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2825 RTN_MULTICAST : 0;
2826 /* ... */
2827 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2828 return RTN_BROADCAST;
2829 else {
2830 u16 hdr_mac;
2831
2832 hdr_mac = *((u16 *)skb->data);
2833 /* tr multicast? */
2834 switch (card->info.link_type) {
2835 case QETH_LINK_TYPE_HSTR:
2836 case QETH_LINK_TYPE_LANE_TR:
2837 if ((hdr_mac == QETH_TR_MAC_NC) ||
2838 (hdr_mac == QETH_TR_MAC_C))
2839 return RTN_MULTICAST;
2840 break;
2841 /* eth or so multicast? */
2842 default:
2843 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2844 (hdr_mac == QETH_ETH_MAC_V6))
2845 return RTN_MULTICAST;
2846 }
2847 }
2848 return cast_type;
2849}
2850
Frank Blaschka4a71df52008-02-15 09:19:42 +01002851static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2852 struct sk_buff *skb, int ipv, int cast_type)
2853{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002854 memset(hdr, 0, sizeof(struct qeth_hdr));
2855 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2856 hdr->hdr.l3.ext_flags = 0;
2857
2858 /*
2859 * before we're going to overwrite this location with next hop ip.
2860 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2861 */
2862 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002863 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2864 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2865 else
2866 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002867 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2868 }
2869
2870 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2871 if (ipv == 4) {
2872 /* IPv4 */
2873 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2874 memset(hdr->hdr.l3.dest_addr, 0, 12);
Eric Dumazetadf30902009-06-02 05:19:30 +00002875 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002876 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
Eric Dumazetadf30902009-06-02 05:19:30 +00002877 *((u32 *) skb_dst(skb)->neighbour->primary_key);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002878 } else {
2879 /* fill in destination address used in ip header */
2880 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2881 ip_hdr(skb)->daddr;
2882 }
2883 } else if (ipv == 6) {
2884 /* IPv6 */
2885 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2886 if (card->info.type == QETH_CARD_TYPE_IQD)
2887 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
Eric Dumazetadf30902009-06-02 05:19:30 +00002888 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002889 memcpy(hdr->hdr.l3.dest_addr,
Eric Dumazetadf30902009-06-02 05:19:30 +00002890 skb_dst(skb)->neighbour->primary_key, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002891 } else {
2892 /* fill in destination address used in ip header */
2893 memcpy(hdr->hdr.l3.dest_addr,
2894 &ipv6_hdr(skb)->daddr, 16);
2895 }
2896 } else {
2897 /* passthrough */
2898 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2899 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2900 sizeof(__u16), skb->dev->broadcast, 6)) {
2901 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2902 QETH_HDR_PASSTHRU;
2903 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2904 skb->dev->broadcast, 6)) {
2905 /* broadcast? */
2906 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2907 QETH_HDR_PASSTHRU;
2908 } else {
2909 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2910 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2911 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2912 }
2913 }
2914}
2915
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002916static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2917 struct qeth_hdr *hdr, struct sk_buff *skb)
2918{
2919 struct iphdr *iph = ip_hdr(skb);
2920
2921 /* tcph->check contains already the pseudo hdr checksum
2922 * so just set the header flags
2923 */
2924 if (iph->protocol == IPPROTO_UDP)
2925 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
2926 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ;
2927 if (card->options.performance_stats)
2928 card->perf_stats.tx_csum++;
2929}
2930
Frank Blaschka64ef8952009-03-24 20:57:16 +00002931static void qeth_tso_fill_header(struct qeth_card *card,
2932 struct qeth_hdr *qhdr, struct sk_buff *skb)
2933{
2934 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2935 struct tcphdr *tcph = tcp_hdr(skb);
2936 struct iphdr *iph = ip_hdr(skb);
2937 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2938
2939 /*fix header to TSO values ...*/
2940 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
2941 /*set values which are fix for the first approach ...*/
2942 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2943 hdr->ext.imb_hdr_no = 1;
2944 hdr->ext.hdr_type = 1;
2945 hdr->ext.hdr_version = 1;
2946 hdr->ext.hdr_len = 28;
2947 /*insert non-fix values */
2948 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2949 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2950 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2951 sizeof(struct qeth_hdr_tso));
2952 tcph->check = 0;
2953 if (skb->protocol == ETH_P_IPV6) {
2954 ip6h->payload_len = 0;
2955 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2956 0, IPPROTO_TCP, 0);
2957 } else {
2958 /*OSA want us to set these values ...*/
2959 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2960 0, IPPROTO_TCP, 0);
2961 iph->tot_len = 0;
2962 iph->check = 0;
2963 }
2964}
2965
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002966static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2967{
2968 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2969 tcp_hdr(skb)->doff * 4;
2970 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002971 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002972 elements += skb_shinfo(skb)->nr_frags;
2973 return elements;
2974}
2975
Frank Blaschka4a71df52008-02-15 09:19:42 +01002976static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2977{
2978 int rc;
2979 u16 *tag;
2980 struct qeth_hdr *hdr = NULL;
2981 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002982 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002983 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002984 struct sk_buff *new_skb = NULL;
2985 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002986 int cast_type = qeth_l3_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002987 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2988 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2989 int tx_bytes = skb->len;
2990 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
Frank Blaschka683d7182008-08-01 16:39:13 +02002991 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002992 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002993
Frank Blaschka21fde742010-03-08 20:36:54 +00002994 if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
2995 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002996 goto tx_drop;
2997
2998 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2999 card->stats.tx_carrier_errors++;
3000 goto tx_drop;
3001 }
3002
3003 if ((cast_type == RTN_BROADCAST) &&
3004 (card->info.broadcast_capable == 0))
3005 goto tx_drop;
3006
3007 if (card->options.performance_stats) {
3008 card->perf_stats.outbound_cnt++;
3009 card->perf_stats.outbound_start_time = qeth_get_micros();
3010 }
3011
Frank Blaschka683d7182008-08-01 16:39:13 +02003012 if (skb_is_gso(skb))
3013 large_send = card->options.large_send;
3014
3015 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
3016 (skb_shinfo(skb)->nr_frags == 0)) {
3017 new_skb = skb;
3018 data_offset = ETH_HLEN;
3019 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
3020 if (!hdr)
3021 goto tx_drop;
3022 elements_needed++;
3023 } else {
3024 /* create a clone with writeable headroom */
3025 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
3026 + VLAN_HLEN);
3027 if (!new_skb)
3028 goto tx_drop;
3029 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003030
3031 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02003032 if (data_offset < 0)
3033 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003034 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00003035 if (ipv == 4) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003036 if (card->dev->type == ARPHRD_IEEE802_TR)
3037 skb_pull(new_skb, TR_HLEN);
3038 else
3039 skb_pull(new_skb, ETH_HLEN);
3040 }
3041
Frank Blaschka21fde742010-03-08 20:36:54 +00003042 if (ipv == 6 && card->vlangrp &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01003043 vlan_tx_tag_present(new_skb)) {
3044 skb_push(new_skb, VLAN_HLEN);
3045 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
3046 skb_copy_to_linear_data_offset(new_skb, 4,
3047 new_skb->data + 8, 4);
3048 skb_copy_to_linear_data_offset(new_skb, 8,
3049 new_skb->data + 12, 4);
3050 tag = (u16 *)(new_skb->data + 12);
3051 *tag = __constant_htons(ETH_P_8021Q);
3052 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02003053 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003054 }
3055 }
3056
3057 netif_stop_queue(dev);
3058
Frank Blaschka4a71df52008-02-15 09:19:42 +01003059 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003060 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003061 */
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003062 if (large_send == QETH_LARGE_SEND_TSO) {
3063 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3064 if (skb_linearize(new_skb))
3065 goto tx_drop;
3066 if (card->options.performance_stats)
3067 card->perf_stats.tx_lin++;
3068 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003069 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003070
3071 if ((large_send == QETH_LARGE_SEND_TSO) &&
3072 (cast_type == RTN_UNSPEC)) {
3073 hdr = (struct qeth_hdr *)skb_push(new_skb,
3074 sizeof(struct qeth_hdr_tso));
3075 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3076 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3077 qeth_tso_fill_header(card, hdr, new_skb);
3078 elements_needed++;
3079 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003080 if (data_offset < 0) {
3081 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003082 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003083 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3084 cast_type);
3085 } else {
3086 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3087 cast_type);
3088 hdr->hdr.l3.length = new_skb->len - data_offset;
3089 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003090
3091 if (skb->ip_summed == CHECKSUM_PARTIAL)
3092 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003093 }
3094
Frank Blaschka64ef8952009-03-24 20:57:16 +00003095 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003096 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003097 if (!elems) {
3098 if (data_offset >= 0)
3099 kmem_cache_free(qeth_core_header_cache, hdr);
3100 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003101 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003102 elements_needed += elems;
3103 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003104
Frank Blaschka51aa1652010-06-21 22:57:10 +00003105 if (card->info.type != QETH_CARD_TYPE_IQD) {
3106 int len;
3107 if (large_send == QETH_LARGE_SEND_TSO)
3108 len = ((unsigned long)tcp_hdr(new_skb) +
3109 tcp_hdr(new_skb)->doff * 4) -
3110 (unsigned long)new_skb->data;
3111 else
3112 len = sizeof(struct qeth_hdr_layer3);
3113
3114 if (qeth_hdr_chk_and_bounce(new_skb, len))
3115 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003116 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003117 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003118 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003119 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003120 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003121
3122 if (!rc) {
3123 card->stats.tx_packets++;
3124 card->stats.tx_bytes += tx_bytes;
3125 if (new_skb != skb)
3126 dev_kfree_skb_any(skb);
3127 if (card->options.performance_stats) {
3128 if (large_send != QETH_LARGE_SEND_NO) {
3129 card->perf_stats.large_send_bytes += tx_bytes;
3130 card->perf_stats.large_send_cnt++;
3131 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003132 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003133 card->perf_stats.sg_skbs_sent++;
3134 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003135 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003136 }
3137 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003138 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003139 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003140 if (data_offset >= 0)
3141 kmem_cache_free(qeth_core_header_cache, hdr);
3142
Frank Blaschka4a71df52008-02-15 09:19:42 +01003143 if (rc == -EBUSY) {
3144 if (new_skb != skb)
3145 dev_kfree_skb_any(new_skb);
3146 return NETDEV_TX_BUSY;
3147 } else
3148 goto tx_drop;
3149 }
3150
3151 netif_wake_queue(dev);
3152 if (card->options.performance_stats)
3153 card->perf_stats.outbound_time += qeth_get_micros() -
3154 card->perf_stats.outbound_start_time;
3155 return rc;
3156
3157tx_drop:
3158 card->stats.tx_dropped++;
3159 card->stats.tx_errors++;
3160 if ((new_skb != skb) && new_skb)
3161 dev_kfree_skb_any(new_skb);
3162 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003163 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003164 return NETDEV_TX_OK;
3165}
3166
3167static int qeth_l3_open(struct net_device *dev)
3168{
Heiko Carstens509e2562008-07-26 02:24:10 -07003169 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003170 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003171
Carsten Otte847a50f2010-06-21 22:57:05 +00003172 QETH_CARD_TEXT(card, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003173 if (card->state != CARD_STATE_SOFTSETUP)
3174 return -ENODEV;
3175 card->data.state = CH_STATE_UP;
3176 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003177 netif_start_queue(dev);
3178
3179 if (!card->lan_online && netif_carrier_ok(dev))
3180 netif_carrier_off(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003181 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3182 napi_enable(&card->napi);
3183 napi_schedule(&card->napi);
3184 } else
3185 rc = -EIO;
3186 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003187}
3188
3189static int qeth_l3_stop(struct net_device *dev)
3190{
Heiko Carstens509e2562008-07-26 02:24:10 -07003191 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003192
Carsten Otte847a50f2010-06-21 22:57:05 +00003193 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003194 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003195 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003196 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003197 napi_disable(&card->napi);
3198 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003199 return 0;
3200}
3201
3202static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
3203{
Heiko Carstens509e2562008-07-26 02:24:10 -07003204 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003205
3206 return (card->options.checksum_type == HW_CHECKSUMMING);
3207}
3208
3209static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
3210{
Heiko Carstens509e2562008-07-26 02:24:10 -07003211 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003212 enum qeth_checksum_types csum_type;
3213
Frank Blaschka4a71df52008-02-15 09:19:42 +01003214 if (data)
3215 csum_type = HW_CHECKSUMMING;
3216 else
3217 csum_type = SW_CHECKSUMMING;
3218
Frank Blaschka3fd434d2009-11-12 00:11:45 +00003219 return qeth_l3_set_rx_csum(card, csum_type);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003220}
3221
3222static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
3223{
Heiko Carstens509e2562008-07-26 02:24:10 -07003224 struct qeth_card *card = dev->ml_priv;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003225 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003226
3227 if (data) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003228 rc = qeth_l3_set_large_send(card, QETH_LARGE_SEND_TSO);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003229 } else {
3230 dev->features &= ~NETIF_F_TSO;
3231 card->options.large_send = QETH_LARGE_SEND_NO;
3232 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003233 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003234}
3235
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003236static int qeth_l3_ethtool_set_tx_csum(struct net_device *dev, u32 data)
3237{
3238 struct qeth_card *card = dev->ml_priv;
3239
3240 if (data) {
3241 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3242 dev->features |= NETIF_F_IP_CSUM;
3243 else
3244 return -EPERM;
3245 } else
3246 dev->features &= ~NETIF_F_IP_CSUM;
3247
3248 return 0;
3249}
3250
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003251static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003252 .get_link = ethtool_op_get_link,
3253 .get_tx_csum = ethtool_op_get_tx_csum,
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003254 .set_tx_csum = qeth_l3_ethtool_set_tx_csum,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003255 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
3256 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
3257 .get_sg = ethtool_op_get_sg,
3258 .set_sg = ethtool_op_set_sg,
3259 .get_tso = ethtool_op_get_tso,
3260 .set_tso = qeth_l3_ethtool_set_tso,
3261 .get_strings = qeth_core_get_strings,
3262 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003263 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003264 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003265 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003266};
3267
3268/*
3269 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3270 * NOARP on the netdevice is no option because it also turns off neighbor
3271 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3272 * arp resolution but we want the hard header (packet socket will work
3273 * e.g. tcpdump)
3274 */
3275static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3276{
3277 n->nud_state = NUD_NOARP;
3278 memcpy(n->ha, "FAKELL", 6);
3279 n->output = n->ops->connected_output;
3280 return 0;
3281}
3282
3283static int
3284qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3285{
3286 if (np->tbl->family == AF_INET)
3287 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3288
3289 return 0;
3290}
3291
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003292static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003293 .ndo_open = qeth_l3_open,
3294 .ndo_stop = qeth_l3_stop,
3295 .ndo_get_stats = qeth_get_stats,
3296 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3297 .ndo_validate_addr = eth_validate_addr,
3298 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3299 .ndo_do_ioctl = qeth_l3_do_ioctl,
3300 .ndo_change_mtu = qeth_change_mtu,
3301 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3302 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3303 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3304 .ndo_tx_timeout = qeth_tx_timeout,
3305};
3306
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003307static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3308 .ndo_open = qeth_l3_open,
3309 .ndo_stop = qeth_l3_stop,
3310 .ndo_get_stats = qeth_get_stats,
3311 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3312 .ndo_validate_addr = eth_validate_addr,
3313 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3314 .ndo_do_ioctl = qeth_l3_do_ioctl,
3315 .ndo_change_mtu = qeth_change_mtu,
3316 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3317 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3318 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3319 .ndo_tx_timeout = qeth_tx_timeout,
3320 .ndo_neigh_setup = qeth_l3_neigh_setup,
3321};
3322
Frank Blaschka4a71df52008-02-15 09:19:42 +01003323static int qeth_l3_setup_netdev(struct qeth_card *card)
3324{
Ursula Braun5113fec2010-05-16 21:15:14 +00003325 if (card->info.type == QETH_CARD_TYPE_OSD ||
3326 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003327 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3328 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3329#ifdef CONFIG_TR
3330 card->dev = alloc_trdev(0);
3331#endif
3332 if (!card->dev)
3333 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003334 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003335 } else {
3336 card->dev = alloc_etherdev(0);
3337 if (!card->dev)
3338 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003339 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003340
3341 /*IPv6 address autoconfiguration stuff*/
3342 qeth_l3_get_unique_id(card);
3343 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3344 card->dev->dev_id = card->info.unique_id &
3345 0xffff;
3346 }
3347 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3348 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3349 if (!card->dev)
3350 return -ENODEV;
3351 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003352 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003353 qeth_l3_iqd_read_initial_mac(card);
3354 } else
3355 return -ENODEV;
3356
Heiko Carstens509e2562008-07-26 02:24:10 -07003357 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003358 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003359 card->dev->mtu = card->info.initial_mtu;
3360 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3361 card->dev->features |= NETIF_F_HW_VLAN_TX |
3362 NETIF_F_HW_VLAN_RX |
3363 NETIF_F_HW_VLAN_FILTER;
Eric Dumazet86d15cd2009-05-30 23:04:46 -07003364 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003365 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003366
3367 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003368 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003369 return register_netdev(card->dev);
3370}
3371
Frank Blaschka4a71df52008-02-15 09:19:42 +01003372static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3373{
3374 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3375
3376 qeth_l3_create_device_attributes(&gdev->dev);
3377 card->options.layer2 = 0;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003378 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003379 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003380 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003381 card->discipline.output_handler = (qdio_handler_t *)
3382 qeth_qdio_output_handler;
3383 card->discipline.recover = qeth_l3_recover;
3384 return 0;
3385}
3386
3387static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3388{
3389 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3390
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003391 qeth_l3_remove_device_attributes(&cgdev->dev);
3392
Ursula Braunf2148562009-05-19 21:38:37 +00003393 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003394 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3395
3396 if (cgdev->state == CCWGROUP_ONLINE) {
3397 card->use_hard_stop = 1;
3398 qeth_l3_set_offline(cgdev);
3399 }
3400
3401 if (card->dev) {
3402 unregister_netdev(card->dev);
3403 card->dev = NULL;
3404 }
3405
Frank Blaschka4a71df52008-02-15 09:19:42 +01003406 qeth_l3_clear_ip_list(card, 0, 0);
3407 qeth_l3_clear_ipato_list(card);
3408 return;
3409}
3410
3411static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3412{
3413 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3414 int rc = 0;
3415 enum qeth_card_states recover_flag;
3416
3417 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003418 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003419 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003420 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3421 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003422
Frank Blaschka4a71df52008-02-15 09:19:42 +01003423 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003424 rc = qeth_core_hardsetup_card(card);
3425 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003426 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003427 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003428 goto out_remove;
3429 }
3430
3431 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3432
Ursula Braunaa909222009-11-12 00:11:43 +00003433 if (!card->dev && qeth_l3_setup_netdev(card)) {
3434 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003435 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003436 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003437
3438 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003439 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003440 qeth_print_status_message(card);
3441
3442 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003443 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003444
3445 rc = qeth_send_startlan(card);
3446 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003447 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003448 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003449 dev_warn(&card->gdev->dev,
3450 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003451 card->lan_online = 0;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003452 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003453 }
Ursula Braunaa909222009-11-12 00:11:43 +00003454 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003455 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003456 } else
3457 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003458
3459 rc = qeth_l3_setadapter_parms(card);
3460 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003461 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003462 if (!card->options.sniffer) {
3463 rc = qeth_l3_start_ipassists(card);
3464 if (rc)
3465 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3466 qeth_l3_set_large_send(card, card->options.large_send);
3467 rc = qeth_l3_setrouting_v4(card);
3468 if (rc)
3469 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3470 rc = qeth_l3_setrouting_v6(card);
3471 if (rc)
3472 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3473 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003474 netif_tx_disable(card->dev);
3475
3476 rc = qeth_init_qdio_queues(card);
3477 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003478 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003479 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003480 goto out_remove;
3481 }
3482 card->state = CARD_STATE_SOFTSETUP;
3483 netif_carrier_on(card->dev);
3484
3485 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003486 qeth_l3_set_ip_addr_list(card);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003487 if (recover_flag == CARD_STATE_RECOVER) {
3488 if (recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003489 qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003490 else {
3491 rtnl_lock();
3492 dev_open(card->dev);
3493 rtnl_unlock();
3494 }
3495 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003496 }
3497 /* let user_space know that device is online */
3498 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003499out:
3500 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003501 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003502 return 0;
3503out_remove:
3504 card->use_hard_stop = 1;
3505 qeth_l3_stop_card(card, 0);
3506 ccw_device_set_offline(CARD_DDEV(card));
3507 ccw_device_set_offline(CARD_WDEV(card));
3508 ccw_device_set_offline(CARD_RDEV(card));
3509 if (recover_flag == CARD_STATE_RECOVER)
3510 card->state = CARD_STATE_RECOVER;
3511 else
3512 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003513 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003514 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003515 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003516}
3517
3518static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3519{
3520 return __qeth_l3_set_online(gdev, 0);
3521}
3522
3523static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3524 int recovery_mode)
3525{
3526 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3527 int rc = 0, rc2 = 0, rc3 = 0;
3528 enum qeth_card_states recover_flag;
3529
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003530 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003531 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003532 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3533 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003534
3535 if (card->dev && netif_carrier_ok(card->dev))
3536 netif_carrier_off(card->dev);
3537 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02003538 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003539 rc = ccw_device_set_offline(CARD_DDEV(card));
3540 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3541 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3542 if (!rc)
3543 rc = (rc2) ? rc2 : rc3;
3544 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003545 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003546 if (recover_flag == CARD_STATE_UP)
3547 card->state = CARD_STATE_RECOVER;
3548 /* let user_space know that device is offline */
3549 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003550 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003551 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003552 return 0;
3553}
3554
3555static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3556{
3557 return __qeth_l3_set_offline(cgdev, 0);
3558}
3559
3560static int qeth_l3_recover(void *ptr)
3561{
3562 struct qeth_card *card;
3563 int rc = 0;
3564
3565 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003566 QETH_CARD_TEXT(card, 2, "recover1");
3567 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003568 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3569 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003570 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003571 dev_warn(&card->gdev->dev,
3572 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003573 card->use_hard_stop = 1;
3574 __qeth_l3_set_offline(card->gdev, 1);
3575 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003576 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003577 dev_info(&card->gdev->dev,
3578 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003579 else {
3580 rtnl_lock();
3581 dev_close(card->dev);
3582 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003583 dev_warn(&card->gdev->dev, "The qeth device driver "
3584 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003585 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003586 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3587 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003588 return 0;
3589}
3590
3591static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3592{
3593 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3594 qeth_l3_clear_ip_list(card, 0, 0);
3595 qeth_qdio_clear_card(card, 0);
3596 qeth_clear_qdio_buffers(card);
3597}
3598
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003599static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3600{
3601 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3602
3603 if (card->dev)
3604 netif_device_detach(card->dev);
3605 qeth_set_allowed_threads(card, 0, 1);
3606 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3607 if (gdev->state == CCWGROUP_OFFLINE)
3608 return 0;
3609 if (card->state == CARD_STATE_UP) {
3610 card->use_hard_stop = 1;
3611 __qeth_l3_set_offline(card->gdev, 1);
3612 } else
3613 __qeth_l3_set_offline(card->gdev, 0);
3614 return 0;
3615}
3616
3617static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3618{
3619 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3620 int rc = 0;
3621
3622 if (gdev->state == CCWGROUP_OFFLINE)
3623 goto out;
3624
3625 if (card->state == CARD_STATE_RECOVER) {
3626 rc = __qeth_l3_set_online(card->gdev, 1);
3627 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003628 rtnl_lock();
3629 dev_close(card->dev);
3630 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003631 }
3632 } else
3633 rc = __qeth_l3_set_online(card->gdev, 0);
3634out:
3635 qeth_set_allowed_threads(card, 0xffffffff, 0);
3636 if (card->dev)
3637 netif_device_attach(card->dev);
3638 if (rc)
3639 dev_warn(&card->gdev->dev, "The qeth device driver "
3640 "failed to recover an error on the device\n");
3641 return rc;
3642}
3643
Frank Blaschka4a71df52008-02-15 09:19:42 +01003644struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3645 .probe = qeth_l3_probe_device,
3646 .remove = qeth_l3_remove_device,
3647 .set_online = qeth_l3_set_online,
3648 .set_offline = qeth_l3_set_offline,
3649 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003650 .freeze = qeth_l3_pm_suspend,
3651 .thaw = qeth_l3_pm_resume,
3652 .restore = qeth_l3_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003653};
3654EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3655
3656static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003657 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003658{
3659 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3660 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3661 struct qeth_ipaddr *addr;
3662 struct qeth_card *card;
3663
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003664 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003665 return NOTIFY_DONE;
3666
Frank Blaschka4a71df52008-02-15 09:19:42 +01003667 card = qeth_l3_get_card_from_dev(dev);
Carsten Otte847a50f2010-06-21 22:57:05 +00003668 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003669 if (!card)
3670 return NOTIFY_DONE;
3671
3672 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3673 if (addr != NULL) {
3674 addr->u.a4.addr = ifa->ifa_address;
3675 addr->u.a4.mask = ifa->ifa_mask;
3676 addr->type = QETH_IP_TYPE_NORMAL;
3677 } else
3678 goto out;
3679
3680 switch (event) {
3681 case NETDEV_UP:
3682 if (!qeth_l3_add_ip(card, addr))
3683 kfree(addr);
3684 break;
3685 case NETDEV_DOWN:
3686 if (!qeth_l3_delete_ip(card, addr))
3687 kfree(addr);
3688 break;
3689 default:
3690 break;
3691 }
3692 qeth_l3_set_ip_addr_list(card);
3693out:
3694 return NOTIFY_DONE;
3695}
3696
3697static struct notifier_block qeth_l3_ip_notifier = {
3698 qeth_l3_ip_event,
3699 NULL,
3700};
3701
3702#ifdef CONFIG_QETH_IPV6
3703/**
3704 * IPv6 event handler
3705 */
3706static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003707 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003708{
3709 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3710 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3711 struct qeth_ipaddr *addr;
3712 struct qeth_card *card;
3713
Frank Blaschka4a71df52008-02-15 09:19:42 +01003714
3715 card = qeth_l3_get_card_from_dev(dev);
3716 if (!card)
3717 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003718 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003719 if (!qeth_is_supported(card, IPA_IPV6))
3720 return NOTIFY_DONE;
3721
3722 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3723 if (addr != NULL) {
3724 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3725 addr->u.a6.pfxlen = ifa->prefix_len;
3726 addr->type = QETH_IP_TYPE_NORMAL;
3727 } else
3728 goto out;
3729
3730 switch (event) {
3731 case NETDEV_UP:
3732 if (!qeth_l3_add_ip(card, addr))
3733 kfree(addr);
3734 break;
3735 case NETDEV_DOWN:
3736 if (!qeth_l3_delete_ip(card, addr))
3737 kfree(addr);
3738 break;
3739 default:
3740 break;
3741 }
3742 qeth_l3_set_ip_addr_list(card);
3743out:
3744 return NOTIFY_DONE;
3745}
3746
3747static struct notifier_block qeth_l3_ip6_notifier = {
3748 qeth_l3_ip6_event,
3749 NULL,
3750};
3751#endif
3752
3753static int qeth_l3_register_notifiers(void)
3754{
3755 int rc;
3756
Carsten Otte847a50f2010-06-21 22:57:05 +00003757 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003758 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3759 if (rc)
3760 return rc;
3761#ifdef CONFIG_QETH_IPV6
3762 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3763 if (rc) {
3764 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3765 return rc;
3766 }
3767#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003768 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003769#endif
3770 return 0;
3771}
3772
3773static void qeth_l3_unregister_notifiers(void)
3774{
3775
Carsten Otte847a50f2010-06-21 22:57:05 +00003776 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003777 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3778#ifdef CONFIG_QETH_IPV6
3779 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3780#endif /* QETH_IPV6 */
3781}
3782
3783static int __init qeth_l3_init(void)
3784{
3785 int rc = 0;
3786
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003787 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003788 rc = qeth_l3_register_notifiers();
3789 return rc;
3790}
3791
3792static void __exit qeth_l3_exit(void)
3793{
3794 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003795 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003796}
3797
3798module_init(qeth_l3_init);
3799module_exit(qeth_l3_exit);
3800MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3801MODULE_DESCRIPTION("qeth layer 3 discipline");
3802MODULE_LICENSE("GPL");