blob: 3ddd5add798432848425d6cfcdbefb4c6a52aa32 [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");
Sachin Santf3aa31362010-11-26 02:41:17 +00001799 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1800 im4 = rcu_dereference(im4->next_rcu)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001801 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1802 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1803 if (!ipm)
1804 continue;
1805 ipm->u.a4.addr = im4->multiaddr;
1806 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1807 ipm->is_multicast = 1;
1808 if (!qeth_l3_add_ip(card, ipm))
1809 kfree(ipm);
1810 }
1811}
1812
1813static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1814{
1815 struct in_device *in_dev;
1816 struct vlan_group *vg;
1817 int i;
1818
Carsten Otte847a50f2010-06-21 22:57:05 +00001819 QETH_CARD_TEXT(card, 4, "addmcvl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001820 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1821 return;
1822
1823 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001824 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001825 struct net_device *netdev = vlan_group_get_device(vg, i);
1826 if (netdev == NULL ||
1827 !(netdev->flags & IFF_UP))
1828 continue;
1829 in_dev = in_dev_get(netdev);
1830 if (!in_dev)
1831 continue;
Sachin Santf3aa31362010-11-26 02:41:17 +00001832 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001833 qeth_l3_add_mc(card, in_dev);
Sachin Santf3aa31362010-11-26 02:41:17 +00001834 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001835 in_dev_put(in_dev);
1836 }
1837}
1838
1839static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1840{
1841 struct in_device *in4_dev;
1842
Carsten Otte847a50f2010-06-21 22:57:05 +00001843 QETH_CARD_TEXT(card, 4, "chkmcv4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001844 in4_dev = in_dev_get(card->dev);
1845 if (in4_dev == NULL)
1846 return;
Sachin Santf3aa31362010-11-26 02:41:17 +00001847 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001848 qeth_l3_add_mc(card, in4_dev);
1849 qeth_l3_add_vlan_mc(card);
Sachin Santf3aa31362010-11-26 02:41:17 +00001850 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001851 in_dev_put(in4_dev);
1852}
1853
1854#ifdef CONFIG_QETH_IPV6
1855static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1856{
1857 struct qeth_ipaddr *ipm;
1858 struct ifmcaddr6 *im6;
1859 char buf[MAX_ADDR_LEN];
1860
Carsten Otte847a50f2010-06-21 22:57:05 +00001861 QETH_CARD_TEXT(card, 4, "addmc6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001862 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1863 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1864 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1865 if (!ipm)
1866 continue;
1867 ipm->is_multicast = 1;
1868 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1869 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1870 sizeof(struct in6_addr));
1871 if (!qeth_l3_add_ip(card, ipm))
1872 kfree(ipm);
1873 }
1874}
1875
1876static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1877{
1878 struct inet6_dev *in_dev;
1879 struct vlan_group *vg;
1880 int i;
1881
Carsten Otte847a50f2010-06-21 22:57:05 +00001882 QETH_CARD_TEXT(card, 4, "admc6vl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001883 if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1884 return;
1885
1886 vg = card->vlangrp;
Jesse Grossb7381272010-10-20 13:56:02 +00001887 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001888 struct net_device *netdev = vlan_group_get_device(vg, i);
1889 if (netdev == NULL ||
1890 !(netdev->flags & IFF_UP))
1891 continue;
1892 in_dev = in6_dev_get(netdev);
1893 if (!in_dev)
1894 continue;
1895 read_lock_bh(&in_dev->lock);
1896 qeth_l3_add_mc6(card, in_dev);
1897 read_unlock_bh(&in_dev->lock);
1898 in6_dev_put(in_dev);
1899 }
1900}
1901
1902static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1903{
1904 struct inet6_dev *in6_dev;
1905
Carsten Otte847a50f2010-06-21 22:57:05 +00001906 QETH_CARD_TEXT(card, 4, "chkmcv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001907 if (!qeth_is_supported(card, IPA_IPV6))
1908 return ;
1909 in6_dev = in6_dev_get(card->dev);
1910 if (in6_dev == NULL)
1911 return;
1912 read_lock_bh(&in6_dev->lock);
1913 qeth_l3_add_mc6(card, in6_dev);
1914 qeth_l3_add_vlan_mc6(card);
1915 read_unlock_bh(&in6_dev->lock);
1916 in6_dev_put(in6_dev);
1917}
1918#endif /* CONFIG_QETH_IPV6 */
1919
1920static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1921 unsigned short vid)
1922{
1923 struct in_device *in_dev;
1924 struct in_ifaddr *ifa;
1925 struct qeth_ipaddr *addr;
1926
Carsten Otte847a50f2010-06-21 22:57:05 +00001927 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001928
1929 in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1930 if (!in_dev)
1931 return;
1932 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1933 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1934 if (addr) {
1935 addr->u.a4.addr = ifa->ifa_address;
1936 addr->u.a4.mask = ifa->ifa_mask;
1937 addr->type = QETH_IP_TYPE_NORMAL;
1938 if (!qeth_l3_delete_ip(card, addr))
1939 kfree(addr);
1940 }
1941 }
1942 in_dev_put(in_dev);
1943}
1944
1945static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1946 unsigned short vid)
1947{
1948#ifdef CONFIG_QETH_IPV6
1949 struct inet6_dev *in6_dev;
1950 struct inet6_ifaddr *ifa;
1951 struct qeth_ipaddr *addr;
1952
Carsten Otte847a50f2010-06-21 22:57:05 +00001953 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001954
1955 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1956 if (!in6_dev)
1957 return;
Frank Blaschka70f60a22010-03-22 09:59:48 -07001958 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001959 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1960 if (addr) {
1961 memcpy(&addr->u.a6.addr, &ifa->addr,
1962 sizeof(struct in6_addr));
1963 addr->u.a6.pfxlen = ifa->prefix_len;
1964 addr->type = QETH_IP_TYPE_NORMAL;
1965 if (!qeth_l3_delete_ip(card, addr))
1966 kfree(addr);
1967 }
1968 }
1969 in6_dev_put(in6_dev);
1970#endif /* CONFIG_QETH_IPV6 */
1971}
1972
1973static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1974 unsigned short vid)
1975{
1976 if (!card->vlangrp)
1977 return;
1978 qeth_l3_free_vlan_addresses4(card, vid);
1979 qeth_l3_free_vlan_addresses6(card, vid);
1980}
1981
1982static void qeth_l3_vlan_rx_register(struct net_device *dev,
1983 struct vlan_group *grp)
1984{
Heiko Carstens509e2562008-07-26 02:24:10 -07001985 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001986 unsigned long flags;
1987
Carsten Otte847a50f2010-06-21 22:57:05 +00001988 QETH_CARD_TEXT(card, 4, "vlanreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001989 spin_lock_irqsave(&card->vlanlock, flags);
1990 card->vlangrp = grp;
1991 spin_unlock_irqrestore(&card->vlanlock, flags);
1992}
1993
1994static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1995{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001996 return;
1997}
1998
1999static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2000{
Heiko Carstens509e2562008-07-26 02:24:10 -07002001 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002002 unsigned long flags;
2003
Carsten Otte847a50f2010-06-21 22:57:05 +00002004 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +00002005 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002006 QETH_CARD_TEXT(card, 3, "kidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002007 return;
2008 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002009 spin_lock_irqsave(&card->vlanlock, flags);
2010 /* unregister IP addresses of vlan device */
2011 qeth_l3_free_vlan_addresses(card, vid);
2012 vlan_group_set_device(card->vlangrp, vid, NULL);
2013 spin_unlock_irqrestore(&card->vlanlock, flags);
2014 qeth_l3_set_multicast_list(card->dev);
2015}
2016
Ursula Braun10651db2010-10-01 02:51:13 +00002017static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
2018 struct sk_buff *skb, struct qeth_hdr *hdr,
2019 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002020{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002021 __be16 prot;
2022 struct iphdr *ip_hdr;
2023 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00002024 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002025
2026 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
2027 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2028 ETH_P_IP);
2029 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
2030 case QETH_CAST_MULTICAST:
2031 switch (prot) {
2032#ifdef CONFIG_QETH_IPV6
2033 case __constant_htons(ETH_P_IPV6):
2034 ndisc_mc_map((struct in6_addr *)
2035 skb->data + 24,
2036 tg_addr, card->dev, 0);
2037 break;
2038#endif
2039 case __constant_htons(ETH_P_IP):
2040 ip_hdr = (struct iphdr *)skb->data;
2041 (card->dev->type == ARPHRD_IEEE802_TR) ?
2042 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
2043 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
2044 break;
2045 default:
2046 memcpy(tg_addr, card->dev->broadcast,
2047 card->dev->addr_len);
2048 }
2049 card->stats.multicast++;
2050 skb->pkt_type = PACKET_MULTICAST;
2051 break;
2052 case QETH_CAST_BROADCAST:
2053 memcpy(tg_addr, card->dev->broadcast,
2054 card->dev->addr_len);
2055 card->stats.multicast++;
2056 skb->pkt_type = PACKET_BROADCAST;
2057 break;
2058 case QETH_CAST_UNICAST:
2059 case QETH_CAST_ANYCAST:
2060 case QETH_CAST_NOCAST:
2061 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00002062 if (card->options.sniffer)
2063 skb->pkt_type = PACKET_OTHERHOST;
2064 else
2065 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002066 memcpy(tg_addr, card->dev->dev_addr,
2067 card->dev->addr_len);
2068 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08002069 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2070 card->dev->header_ops->create(skb, card->dev, prot,
2071 tg_addr, &hdr->hdr.l3.dest_addr[2],
2072 card->dev->addr_len);
2073 else
2074 card->dev->header_ops->create(skb, card->dev, prot,
2075 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002076 }
2077
2078#ifdef CONFIG_TR
2079 if (card->dev->type == ARPHRD_IEEE802_TR)
2080 skb->protocol = tr_type_trans(skb, card->dev);
2081 else
2082#endif
2083 skb->protocol = eth_type_trans(skb, card->dev);
2084
2085 if (hdr->hdr.l3.ext_flags &
2086 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00002087 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01002088 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00002089 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002090 }
2091
Ursula Braunb9139802009-05-19 21:38:40 +00002092 switch (card->options.checksum_type) {
2093 case SW_CHECKSUMMING:
2094 skb->ip_summed = CHECKSUM_NONE;
2095 break;
2096 case NO_CHECKSUMMING:
2097 skb->ip_summed = CHECKSUM_UNNECESSARY;
2098 break;
2099 case HW_CHECKSUMMING:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002100 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00002101 (QETH_HDR_EXT_CSUM_HDR_REQ |
2102 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2103 (QETH_HDR_EXT_CSUM_HDR_REQ |
2104 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002105 skb->ip_summed = CHECKSUM_UNNECESSARY;
2106 else
Ursula Braunb9139802009-05-19 21:38:40 +00002107 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002108 }
2109
Ursula Braun10651db2010-10-01 02:51:13 +00002110 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002111}
2112
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002113static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
2114 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002115{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002116 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002117 struct sk_buff *skb;
2118 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002119 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00002120 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002121 unsigned int len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002122
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002123 *done = 0;
2124 BUG_ON(!budget);
2125 while (budget) {
2126 skb = qeth_core_get_next_skb(card,
2127 card->qdio.in_q->bufs[card->rx.b_index].buffer,
2128 &card->rx.b_element, &card->rx.e_offset, &hdr);
2129 if (!skb) {
2130 *done = 1;
2131 break;
2132 }
2133 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002134 switch (hdr->hdr.l3.id) {
2135 case QETH_HEADER_TYPE_LAYER3:
Ursula Braun10651db2010-10-01 02:51:13 +00002136 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
2137 &vlan_tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002138 len = skb->len;
Ursula Braun10651db2010-10-01 02:51:13 +00002139 if (is_vlan && !card->options.sniffer)
2140 vlan_gro_receive(&card->napi, card->vlangrp,
2141 vlan_tag, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002142 else
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002143 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002144 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00002145 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
2146 skb->pkt_type = PACKET_HOST;
2147 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00002148 len = skb->len;
2149 netif_receive_skb(skb);
2150 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002151 default:
2152 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00002153 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002154 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002155 continue;
2156 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002157 work_done++;
2158 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002159 card->stats.rx_packets++;
2160 card->stats.rx_bytes += len;
2161 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002162 return work_done;
2163}
2164
2165static int qeth_l3_poll(struct napi_struct *napi, int budget)
2166{
2167 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
2168 int work_done = 0;
2169 struct qeth_qdio_buffer *buffer;
2170 int done;
2171 int new_budget = budget;
2172
2173 if (card->options.performance_stats) {
2174 card->perf_stats.inbound_cnt++;
2175 card->perf_stats.inbound_start_time = qeth_get_micros();
2176 }
2177
2178 while (1) {
2179 if (!card->rx.b_count) {
2180 card->rx.qdio_err = 0;
2181 card->rx.b_count = qdio_get_next_buffers(
2182 card->data.ccwdev, 0, &card->rx.b_index,
2183 &card->rx.qdio_err);
2184 if (card->rx.b_count <= 0) {
2185 card->rx.b_count = 0;
2186 break;
2187 }
2188 card->rx.b_element =
2189 &card->qdio.in_q->bufs[card->rx.b_index]
2190 .buffer->element[0];
2191 card->rx.e_offset = 0;
2192 }
2193
2194 while (card->rx.b_count) {
2195 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
2196 if (!(card->rx.qdio_err &&
2197 qeth_check_qdio_errors(card, buffer->buffer,
2198 card->rx.qdio_err, "qinerr")))
2199 work_done += qeth_l3_process_inbound_buffer(
2200 card, new_budget, &done);
2201 else
2202 done = 1;
2203
2204 if (done) {
2205 if (card->options.performance_stats)
2206 card->perf_stats.bufs_rec++;
2207 qeth_put_buffer_pool_entry(card,
2208 buffer->pool_entry);
2209 qeth_queue_input_buffer(card, card->rx.b_index);
2210 card->rx.b_count--;
2211 if (card->rx.b_count) {
2212 card->rx.b_index =
2213 (card->rx.b_index + 1) %
2214 QDIO_MAX_BUFFERS_PER_Q;
2215 card->rx.b_element =
2216 &card->qdio.in_q
2217 ->bufs[card->rx.b_index]
2218 .buffer->element[0];
2219 card->rx.e_offset = 0;
2220 }
2221 }
2222
2223 if (work_done >= budget)
2224 goto out;
2225 else
2226 new_budget = budget - work_done;
2227 }
2228 }
2229
2230 napi_complete(napi);
2231 if (qdio_start_irq(card->data.ccwdev, 0))
2232 napi_schedule(&card->napi);
2233out:
2234 if (card->options.performance_stats)
2235 card->perf_stats.inbound_time += qeth_get_micros() -
2236 card->perf_stats.inbound_start_time;
2237 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002238}
2239
2240static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2241 struct qeth_card *card)
2242{
2243 int rc = 0;
2244 struct vlan_group *vg;
2245 int i;
2246
2247 vg = card->vlangrp;
2248 if (!vg)
2249 return rc;
2250
Jesse Grossb7381272010-10-20 13:56:02 +00002251 for (i = 0; i < VLAN_N_VID; i++) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002252 if (vlan_group_get_device(vg, i) == dev) {
2253 rc = QETH_VLAN_CARD;
2254 break;
2255 }
2256 }
2257
Heiko Carstens509e2562008-07-26 02:24:10 -07002258 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002259 return 0;
2260
2261 return rc;
2262}
2263
2264static int qeth_l3_verify_dev(struct net_device *dev)
2265{
2266 struct qeth_card *card;
2267 unsigned long flags;
2268 int rc = 0;
2269
2270 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2271 list_for_each_entry(card, &qeth_core_card_list.list, list) {
2272 if (card->dev == dev) {
2273 rc = QETH_REAL_CARD;
2274 break;
2275 }
2276 rc = qeth_l3_verify_vlan_dev(dev, card);
2277 if (rc)
2278 break;
2279 }
2280 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2281
2282 return rc;
2283}
2284
2285static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2286{
2287 struct qeth_card *card = NULL;
2288 int rc;
2289
2290 rc = qeth_l3_verify_dev(dev);
2291 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002292 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002293 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07002294 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02002295 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002296 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00002297 if (card)
2298 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002299 return card ;
2300}
2301
2302static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2303{
2304 int rc = 0;
2305
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002306 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2307 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002308
2309 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002310 if (card->options.sniffer &&
2311 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2312 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002313 if (card->read.state == CH_STATE_UP &&
2314 card->write.state == CH_STATE_UP &&
2315 (card->state == CARD_STATE_UP)) {
2316 if (recovery_mode)
2317 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002318 else {
Ursula Braun869da902010-03-08 20:36:56 +00002319 rtnl_lock();
2320 dev_close(card->dev);
2321 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002322 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002323 if (!card->use_hard_stop) {
2324 rc = qeth_send_stoplan(card);
2325 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002326 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002327 }
2328 card->state = CARD_STATE_SOFTSETUP;
2329 }
2330 if (card->state == CARD_STATE_SOFTSETUP) {
2331 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2332 qeth_clear_ipacmd_list(card);
2333 card->state = CARD_STATE_HARDSETUP;
2334 }
2335 if (card->state == CARD_STATE_HARDSETUP) {
2336 if (!card->use_hard_stop &&
2337 (card->info.type != QETH_CARD_TYPE_IQD)) {
2338 rc = qeth_l3_put_unique_id(card);
2339 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002340 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002341 }
2342 qeth_qdio_clear_card(card, 0);
2343 qeth_clear_qdio_buffers(card);
2344 qeth_clear_working_pool_list(card);
2345 card->state = CARD_STATE_DOWN;
2346 }
2347 if (card->state == CARD_STATE_DOWN) {
2348 qeth_clear_cmd_buffers(&card->read);
2349 qeth_clear_cmd_buffers(&card->write);
2350 }
2351 card->use_hard_stop = 0;
2352 return rc;
2353}
2354
Ursula Braun76b11f82010-01-11 02:50:50 +00002355/*
2356 * test for and Switch promiscuous mode (on or off)
2357 * either for guestlan or HiperSocket Sniffer
2358 */
2359static void
2360qeth_l3_handle_promisc_mode(struct qeth_card *card)
2361{
2362 struct net_device *dev = card->dev;
2363
2364 if (((dev->flags & IFF_PROMISC) &&
2365 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2366 (!(dev->flags & IFF_PROMISC) &&
2367 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2368 return;
2369
2370 if (card->info.guestlan) { /* Guestlan trace */
2371 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2372 qeth_setadp_promisc_mode(card);
2373 } else if (card->options.sniffer && /* HiperSockets trace */
2374 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2375 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002376 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002377 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2378 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002379 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002380 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2381 }
2382 }
2383}
2384
Frank Blaschka4a71df52008-02-15 09:19:42 +01002385static void qeth_l3_set_multicast_list(struct net_device *dev)
2386{
Heiko Carstens509e2562008-07-26 02:24:10 -07002387 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002388
Carsten Otte847a50f2010-06-21 22:57:05 +00002389 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002390 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2391 (card->state != CARD_STATE_UP))
2392 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002393 if (!card->options.sniffer) {
2394 qeth_l3_delete_mc_addresses(card);
2395 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002396#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002397 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002398#endif
Ursula Braun76b11f82010-01-11 02:50:50 +00002399 qeth_l3_set_ip_addr_list(card);
2400 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2401 return;
2402 }
2403 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002404}
2405
2406static const char *qeth_l3_arp_get_error_cause(int *rc)
2407{
2408 switch (*rc) {
2409 case QETH_IPA_ARP_RC_FAILED:
2410 *rc = -EIO;
2411 return "operation failed";
2412 case QETH_IPA_ARP_RC_NOTSUPP:
2413 *rc = -EOPNOTSUPP;
2414 return "operation not supported";
2415 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2416 *rc = -EINVAL;
2417 return "argument out of range";
2418 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2419 *rc = -EOPNOTSUPP;
2420 return "query operation not supported";
2421 case QETH_IPA_ARP_RC_Q_NO_DATA:
2422 *rc = -ENOENT;
2423 return "no query data available";
2424 default:
2425 return "unknown error";
2426 }
2427}
2428
2429static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2430{
2431 int tmp;
2432 int rc;
2433
Carsten Otte847a50f2010-06-21 22:57:05 +00002434 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002435
2436 /*
2437 * currently GuestLAN only supports the ARP assist function
2438 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2439 * thus we say EOPNOTSUPP for this ARP function
2440 */
2441 if (card->info.guestlan)
2442 return -EOPNOTSUPP;
2443 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002444 return -EOPNOTSUPP;
2445 }
2446 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2447 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2448 no_entries);
2449 if (rc) {
2450 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002451 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2452 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002453 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2454 }
2455 return rc;
2456}
2457
2458static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2459 struct qeth_arp_query_data *qdata, int entry_size,
2460 int uentry_size)
2461{
2462 char *entry_ptr;
2463 char *uentry_ptr;
2464 int i;
2465
2466 entry_ptr = (char *)&qdata->data;
2467 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2468 for (i = 0; i < qdata->no_entries; ++i) {
2469 /* strip off 32 bytes "media specific information" */
2470 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2471 entry_ptr += entry_size;
2472 uentry_ptr += uentry_size;
2473 }
2474}
2475
2476static int qeth_l3_arp_query_cb(struct qeth_card *card,
2477 struct qeth_reply *reply, unsigned long data)
2478{
2479 struct qeth_ipa_cmd *cmd;
2480 struct qeth_arp_query_data *qdata;
2481 struct qeth_arp_query_info *qinfo;
2482 int entry_size;
2483 int uentry_size;
2484 int i;
2485
Carsten Otte847a50f2010-06-21 22:57:05 +00002486 QETH_CARD_TEXT(card, 4, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002487
2488 qinfo = (struct qeth_arp_query_info *) reply->param;
2489 cmd = (struct qeth_ipa_cmd *) data;
2490 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002491 QETH_CARD_TEXT_(card, 4, "qaer1%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002492 return 0;
2493 }
2494 if (cmd->data.setassparms.hdr.return_code) {
2495 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Carsten Otte847a50f2010-06-21 22:57:05 +00002496 QETH_CARD_TEXT_(card, 4, "qaer2%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002497 return 0;
2498 }
2499 qdata = &cmd->data.setassparms.data.query_arp;
2500 switch (qdata->reply_bits) {
2501 case 5:
2502 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2503 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2504 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2505 break;
2506 case 7:
2507 /* fall through to default */
2508 default:
2509 /* tr is the same as eth -> entry7 */
2510 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2511 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2512 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2513 break;
2514 }
2515 /* check if there is enough room in userspace */
2516 if ((qinfo->udata_len - qinfo->udata_offset) <
2517 qdata->no_entries * uentry_size){
Carsten Otte847a50f2010-06-21 22:57:05 +00002518 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002519 cmd->hdr.return_code = -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002520 goto out_error;
2521 }
Carsten Otte847a50f2010-06-21 22:57:05 +00002522 QETH_CARD_TEXT_(card, 4, "anore%i",
Frank Blaschka4a71df52008-02-15 09:19:42 +01002523 cmd->data.setassparms.hdr.number_of_replies);
Carsten Otte847a50f2010-06-21 22:57:05 +00002524 QETH_CARD_TEXT_(card, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2525 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002526
2527 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2528 /* strip off "media specific information" */
2529 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2530 uentry_size);
2531 } else
2532 /*copy entries to user buffer*/
2533 memcpy(qinfo->udata + qinfo->udata_offset,
2534 (char *)&qdata->data, qdata->no_entries*uentry_size);
2535
2536 qinfo->no_entries += qdata->no_entries;
2537 qinfo->udata_offset += (qdata->no_entries*uentry_size);
2538 /* check if all replies received ... */
2539 if (cmd->data.setassparms.hdr.seq_no <
2540 cmd->data.setassparms.hdr.number_of_replies)
2541 return 1;
2542 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2543 /* keep STRIP_ENTRIES flag so the user program can distinguish
2544 * stripped entries from normal ones */
2545 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2546 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2547 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2548 return 0;
2549out_error:
2550 i = 0;
2551 memcpy(qinfo->udata, &i, 4);
2552 return 0;
2553}
2554
2555static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2556 struct qeth_cmd_buffer *iob, int len,
2557 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2558 unsigned long),
2559 void *reply_param)
2560{
Carsten Otte847a50f2010-06-21 22:57:05 +00002561 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002562
2563 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2564 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2565 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2566 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2567 reply_cb, reply_param);
2568}
2569
2570static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2571{
2572 struct qeth_cmd_buffer *iob;
2573 struct qeth_arp_query_info qinfo = {0, };
2574 int tmp;
2575 int rc;
2576
Carsten Otte847a50f2010-06-21 22:57:05 +00002577 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002578
2579 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2580 IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002581 return -EOPNOTSUPP;
2582 }
2583 /* get size of userspace buffer and mask_bits -> 6 bytes */
2584 if (copy_from_user(&qinfo, udata, 6))
2585 return -EFAULT;
2586 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2587 if (!qinfo.udata)
2588 return -ENOMEM;
2589 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2590 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2591 IPA_CMD_ASS_ARP_QUERY_INFO,
2592 sizeof(int), QETH_PROT_IPV4);
2593
2594 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2595 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2596 qeth_l3_arp_query_cb, (void *)&qinfo);
2597 if (rc) {
2598 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002599 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
Frank Blaschka4a71df52008-02-15 09:19:42 +01002600 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2601 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2602 if (copy_to_user(udata, qinfo.udata, 4))
2603 rc = -EFAULT;
2604 } else {
2605 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2606 rc = -EFAULT;
2607 }
2608 kfree(qinfo.udata);
2609 return rc;
2610}
2611
2612static int qeth_l3_arp_add_entry(struct qeth_card *card,
2613 struct qeth_arp_cache_entry *entry)
2614{
2615 struct qeth_cmd_buffer *iob;
2616 char buf[16];
2617 int tmp;
2618 int rc;
2619
Carsten Otte847a50f2010-06-21 22:57:05 +00002620 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002621
2622 /*
2623 * currently GuestLAN only supports the ARP assist function
2624 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2625 * thus we say EOPNOTSUPP for this ARP function
2626 */
2627 if (card->info.guestlan)
2628 return -EOPNOTSUPP;
2629 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002630 return -EOPNOTSUPP;
2631 }
2632
2633 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2634 IPA_CMD_ASS_ARP_ADD_ENTRY,
2635 sizeof(struct qeth_arp_cache_entry),
2636 QETH_PROT_IPV4);
2637 rc = qeth_l3_send_setassparms(card, iob,
2638 sizeof(struct qeth_arp_cache_entry),
2639 (unsigned long) entry,
2640 qeth_l3_default_setassparms_cb, NULL);
2641 if (rc) {
2642 tmp = rc;
2643 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002644 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2645 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2646 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002647 }
2648 return rc;
2649}
2650
2651static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2652 struct qeth_arp_cache_entry *entry)
2653{
2654 struct qeth_cmd_buffer *iob;
2655 char buf[16] = {0, };
2656 int tmp;
2657 int rc;
2658
Carsten Otte847a50f2010-06-21 22:57:05 +00002659 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002660
2661 /*
2662 * currently GuestLAN only supports the ARP assist function
2663 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2664 * thus we say EOPNOTSUPP for this ARP function
2665 */
2666 if (card->info.guestlan)
2667 return -EOPNOTSUPP;
2668 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002669 return -EOPNOTSUPP;
2670 }
2671 memcpy(buf, entry, 12);
2672 iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2673 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2674 12,
2675 QETH_PROT_IPV4);
2676 rc = qeth_l3_send_setassparms(card, iob,
2677 12, (unsigned long)buf,
2678 qeth_l3_default_setassparms_cb, NULL);
2679 if (rc) {
2680 tmp = rc;
2681 memset(buf, 0, 16);
2682 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002683 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2684 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2685 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002686 }
2687 return rc;
2688}
2689
2690static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2691{
2692 int rc;
2693 int tmp;
2694
Carsten Otte847a50f2010-06-21 22:57:05 +00002695 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002696
2697 /*
2698 * currently GuestLAN only supports the ARP assist function
2699 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2700 * thus we say EOPNOTSUPP for this ARP function
2701 */
2702 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2703 return -EOPNOTSUPP;
2704 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002705 return -EOPNOTSUPP;
2706 }
2707 rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2708 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2709 if (rc) {
2710 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002711 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2712 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002713 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2714 }
2715 return rc;
2716}
2717
2718static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2719{
Heiko Carstens509e2562008-07-26 02:24:10 -07002720 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002721 struct qeth_arp_cache_entry arp_entry;
2722 struct mii_ioctl_data *mii_data;
2723 int rc = 0;
2724
2725 if (!card)
2726 return -ENODEV;
2727
2728 if ((card->state != CARD_STATE_UP) &&
2729 (card->state != CARD_STATE_SOFTSETUP))
2730 return -ENODEV;
2731
2732 switch (cmd) {
2733 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2734 if (!capable(CAP_NET_ADMIN)) {
2735 rc = -EPERM;
2736 break;
2737 }
2738 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2739 break;
2740 case SIOC_QETH_ARP_QUERY_INFO:
2741 if (!capable(CAP_NET_ADMIN)) {
2742 rc = -EPERM;
2743 break;
2744 }
2745 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2746 break;
2747 case SIOC_QETH_ARP_ADD_ENTRY:
2748 if (!capable(CAP_NET_ADMIN)) {
2749 rc = -EPERM;
2750 break;
2751 }
2752 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2753 sizeof(struct qeth_arp_cache_entry)))
2754 rc = -EFAULT;
2755 else
2756 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2757 break;
2758 case SIOC_QETH_ARP_REMOVE_ENTRY:
2759 if (!capable(CAP_NET_ADMIN)) {
2760 rc = -EPERM;
2761 break;
2762 }
2763 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2764 sizeof(struct qeth_arp_cache_entry)))
2765 rc = -EFAULT;
2766 else
2767 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2768 break;
2769 case SIOC_QETH_ARP_FLUSH_CACHE:
2770 if (!capable(CAP_NET_ADMIN)) {
2771 rc = -EPERM;
2772 break;
2773 }
2774 rc = qeth_l3_arp_flush_cache(card);
2775 break;
2776 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2777 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2778 break;
2779 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002780 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2781 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002782 !card->info.guestlan)
2783 return 1;
2784 return 0;
2785 break;
2786 case SIOCGMIIPHY:
2787 mii_data = if_mii(rq);
2788 mii_data->phy_id = 0;
2789 break;
2790 case SIOCGMIIREG:
2791 mii_data = if_mii(rq);
2792 if (mii_data->phy_id != 0)
2793 rc = -EINVAL;
2794 else
2795 mii_data->val_out = qeth_mdio_read(dev,
2796 mii_data->phy_id,
2797 mii_data->reg_num);
2798 break;
2799 default:
2800 rc = -EOPNOTSUPP;
2801 }
2802 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002803 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002804 return rc;
2805}
2806
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002807int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2808{
2809 int cast_type = RTN_UNSPEC;
2810
2811 if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2812 cast_type = skb_dst(skb)->neighbour->type;
2813 if ((cast_type == RTN_BROADCAST) ||
2814 (cast_type == RTN_MULTICAST) ||
2815 (cast_type == RTN_ANYCAST))
2816 return cast_type;
2817 else
2818 return RTN_UNSPEC;
2819 }
2820 /* try something else */
2821 if (skb->protocol == ETH_P_IPV6)
2822 return (skb_network_header(skb)[24] == 0xff) ?
2823 RTN_MULTICAST : 0;
2824 else if (skb->protocol == ETH_P_IP)
2825 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2826 RTN_MULTICAST : 0;
2827 /* ... */
2828 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2829 return RTN_BROADCAST;
2830 else {
2831 u16 hdr_mac;
2832
2833 hdr_mac = *((u16 *)skb->data);
2834 /* tr multicast? */
2835 switch (card->info.link_type) {
2836 case QETH_LINK_TYPE_HSTR:
2837 case QETH_LINK_TYPE_LANE_TR:
2838 if ((hdr_mac == QETH_TR_MAC_NC) ||
2839 (hdr_mac == QETH_TR_MAC_C))
2840 return RTN_MULTICAST;
2841 break;
2842 /* eth or so multicast? */
2843 default:
2844 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2845 (hdr_mac == QETH_ETH_MAC_V6))
2846 return RTN_MULTICAST;
2847 }
2848 }
2849 return cast_type;
2850}
2851
Frank Blaschka4a71df52008-02-15 09:19:42 +01002852static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2853 struct sk_buff *skb, int ipv, int cast_type)
2854{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002855 memset(hdr, 0, sizeof(struct qeth_hdr));
2856 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2857 hdr->hdr.l3.ext_flags = 0;
2858
2859 /*
2860 * before we're going to overwrite this location with next hop ip.
2861 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2862 */
2863 if (card->vlangrp && vlan_tx_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002864 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2865 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2866 else
2867 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002868 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2869 }
2870
2871 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2872 if (ipv == 4) {
2873 /* IPv4 */
2874 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2875 memset(hdr->hdr.l3.dest_addr, 0, 12);
Eric Dumazetadf30902009-06-02 05:19:30 +00002876 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002877 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
Eric Dumazetadf30902009-06-02 05:19:30 +00002878 *((u32 *) skb_dst(skb)->neighbour->primary_key);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002879 } else {
2880 /* fill in destination address used in ip header */
2881 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2882 ip_hdr(skb)->daddr;
2883 }
2884 } else if (ipv == 6) {
2885 /* IPv6 */
2886 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2887 if (card->info.type == QETH_CARD_TYPE_IQD)
2888 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
Eric Dumazetadf30902009-06-02 05:19:30 +00002889 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002890 memcpy(hdr->hdr.l3.dest_addr,
Eric Dumazetadf30902009-06-02 05:19:30 +00002891 skb_dst(skb)->neighbour->primary_key, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002892 } else {
2893 /* fill in destination address used in ip header */
2894 memcpy(hdr->hdr.l3.dest_addr,
2895 &ipv6_hdr(skb)->daddr, 16);
2896 }
2897 } else {
2898 /* passthrough */
2899 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2900 !memcmp(skb->data + sizeof(struct qeth_hdr) +
2901 sizeof(__u16), skb->dev->broadcast, 6)) {
2902 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2903 QETH_HDR_PASSTHRU;
2904 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2905 skb->dev->broadcast, 6)) {
2906 /* broadcast? */
2907 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2908 QETH_HDR_PASSTHRU;
2909 } else {
2910 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2911 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2912 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2913 }
2914 }
2915}
2916
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002917static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2918 struct qeth_hdr *hdr, struct sk_buff *skb)
2919{
2920 struct iphdr *iph = ip_hdr(skb);
2921
2922 /* tcph->check contains already the pseudo hdr checksum
2923 * so just set the header flags
2924 */
2925 if (iph->protocol == IPPROTO_UDP)
2926 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
2927 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ;
2928 if (card->options.performance_stats)
2929 card->perf_stats.tx_csum++;
2930}
2931
Frank Blaschka64ef8952009-03-24 20:57:16 +00002932static void qeth_tso_fill_header(struct qeth_card *card,
2933 struct qeth_hdr *qhdr, struct sk_buff *skb)
2934{
2935 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2936 struct tcphdr *tcph = tcp_hdr(skb);
2937 struct iphdr *iph = ip_hdr(skb);
2938 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2939
2940 /*fix header to TSO values ...*/
2941 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
2942 /*set values which are fix for the first approach ...*/
2943 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2944 hdr->ext.imb_hdr_no = 1;
2945 hdr->ext.hdr_type = 1;
2946 hdr->ext.hdr_version = 1;
2947 hdr->ext.hdr_len = 28;
2948 /*insert non-fix values */
2949 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2950 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2951 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2952 sizeof(struct qeth_hdr_tso));
2953 tcph->check = 0;
2954 if (skb->protocol == ETH_P_IPV6) {
2955 ip6h->payload_len = 0;
2956 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2957 0, IPPROTO_TCP, 0);
2958 } else {
2959 /*OSA want us to set these values ...*/
2960 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2961 0, IPPROTO_TCP, 0);
2962 iph->tot_len = 0;
2963 iph->check = 0;
2964 }
2965}
2966
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002967static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2968{
2969 unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
2970 tcp_hdr(skb)->doff * 4;
2971 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002972 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002973 elements += skb_shinfo(skb)->nr_frags;
2974 return elements;
2975}
2976
Frank Blaschka4a71df52008-02-15 09:19:42 +01002977static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2978{
2979 int rc;
2980 u16 *tag;
2981 struct qeth_hdr *hdr = NULL;
2982 int elements_needed = 0;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002983 int elems;
Heiko Carstens509e2562008-07-26 02:24:10 -07002984 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002985 struct sk_buff *new_skb = NULL;
2986 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002987 int cast_type = qeth_l3_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002988 struct qeth_qdio_out_q *queue = card->qdio.out_qs
2989 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2990 int tx_bytes = skb->len;
2991 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
Frank Blaschka683d7182008-08-01 16:39:13 +02002992 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002993 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002994
Frank Blaschka21fde742010-03-08 20:36:54 +00002995 if (((card->info.type == QETH_CARD_TYPE_IQD) && (!ipv)) ||
2996 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002997 goto tx_drop;
2998
2999 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3000 card->stats.tx_carrier_errors++;
3001 goto tx_drop;
3002 }
3003
3004 if ((cast_type == RTN_BROADCAST) &&
3005 (card->info.broadcast_capable == 0))
3006 goto tx_drop;
3007
3008 if (card->options.performance_stats) {
3009 card->perf_stats.outbound_cnt++;
3010 card->perf_stats.outbound_start_time = qeth_get_micros();
3011 }
3012
Frank Blaschka683d7182008-08-01 16:39:13 +02003013 if (skb_is_gso(skb))
3014 large_send = card->options.large_send;
3015
3016 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
3017 (skb_shinfo(skb)->nr_frags == 0)) {
3018 new_skb = skb;
3019 data_offset = ETH_HLEN;
3020 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
3021 if (!hdr)
3022 goto tx_drop;
3023 elements_needed++;
3024 } else {
3025 /* create a clone with writeable headroom */
3026 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
3027 + VLAN_HLEN);
3028 if (!new_skb)
3029 goto tx_drop;
3030 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003031
3032 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02003033 if (data_offset < 0)
3034 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003035 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00003036 if (ipv == 4) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003037 if (card->dev->type == ARPHRD_IEEE802_TR)
3038 skb_pull(new_skb, TR_HLEN);
3039 else
3040 skb_pull(new_skb, ETH_HLEN);
3041 }
3042
Frank Blaschka21fde742010-03-08 20:36:54 +00003043 if (ipv == 6 && card->vlangrp &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01003044 vlan_tx_tag_present(new_skb)) {
3045 skb_push(new_skb, VLAN_HLEN);
3046 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
3047 skb_copy_to_linear_data_offset(new_skb, 4,
3048 new_skb->data + 8, 4);
3049 skb_copy_to_linear_data_offset(new_skb, 8,
3050 new_skb->data + 12, 4);
3051 tag = (u16 *)(new_skb->data + 12);
3052 *tag = __constant_htons(ETH_P_8021Q);
3053 *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
frank.blaschka@de.ibm.com2b4ff112008-07-22 09:39:25 +02003054 new_skb->vlan_tci = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003055 }
3056 }
3057
3058 netif_stop_queue(dev);
3059
Frank Blaschka4a71df52008-02-15 09:19:42 +01003060 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00003061 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01003062 */
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003063 if (large_send == QETH_LARGE_SEND_TSO) {
3064 if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
3065 if (skb_linearize(new_skb))
3066 goto tx_drop;
3067 if (card->options.performance_stats)
3068 card->perf_stats.tx_lin++;
3069 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003070 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003071
3072 if ((large_send == QETH_LARGE_SEND_TSO) &&
3073 (cast_type == RTN_UNSPEC)) {
3074 hdr = (struct qeth_hdr *)skb_push(new_skb,
3075 sizeof(struct qeth_hdr_tso));
3076 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
3077 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
3078 qeth_tso_fill_header(card, hdr, new_skb);
3079 elements_needed++;
3080 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003081 if (data_offset < 0) {
3082 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003083 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02003084 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3085 cast_type);
3086 } else {
3087 qeth_l3_fill_header(card, hdr, new_skb, ipv,
3088 cast_type);
3089 hdr->hdr.l3.length = new_skb->len - data_offset;
3090 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003091
3092 if (skb->ip_summed == CHECKSUM_PARTIAL)
3093 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003094 }
3095
Frank Blaschka64ef8952009-03-24 20:57:16 +00003096 elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003097 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +00003098 if (!elems) {
3099 if (data_offset >= 0)
3100 kmem_cache_free(qeth_core_header_cache, hdr);
3101 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003102 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003103 elements_needed += elems;
3104 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003105
Frank Blaschka51aa1652010-06-21 22:57:10 +00003106 if (card->info.type != QETH_CARD_TYPE_IQD) {
3107 int len;
3108 if (large_send == QETH_LARGE_SEND_TSO)
3109 len = ((unsigned long)tcp_hdr(new_skb) +
3110 tcp_hdr(new_skb)->doff * 4) -
3111 (unsigned long)new_skb->data;
3112 else
3113 len = sizeof(struct qeth_hdr_layer3);
3114
3115 if (qeth_hdr_chk_and_bounce(new_skb, len))
3116 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003117 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003118 elements_needed);
Frank Blaschka51aa1652010-06-21 22:57:10 +00003119 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01003120 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +00003121 elements_needed, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003122
3123 if (!rc) {
3124 card->stats.tx_packets++;
3125 card->stats.tx_bytes += tx_bytes;
3126 if (new_skb != skb)
3127 dev_kfree_skb_any(skb);
3128 if (card->options.performance_stats) {
3129 if (large_send != QETH_LARGE_SEND_NO) {
3130 card->perf_stats.large_send_bytes += tx_bytes;
3131 card->perf_stats.large_send_cnt++;
3132 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00003133 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003134 card->perf_stats.sg_skbs_sent++;
3135 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00003136 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003137 }
3138 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07003139 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003140 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02003141 if (data_offset >= 0)
3142 kmem_cache_free(qeth_core_header_cache, hdr);
3143
Frank Blaschka4a71df52008-02-15 09:19:42 +01003144 if (rc == -EBUSY) {
3145 if (new_skb != skb)
3146 dev_kfree_skb_any(new_skb);
3147 return NETDEV_TX_BUSY;
3148 } else
3149 goto tx_drop;
3150 }
3151
3152 netif_wake_queue(dev);
3153 if (card->options.performance_stats)
3154 card->perf_stats.outbound_time += qeth_get_micros() -
3155 card->perf_stats.outbound_start_time;
3156 return rc;
3157
3158tx_drop:
3159 card->stats.tx_dropped++;
3160 card->stats.tx_errors++;
3161 if ((new_skb != skb) && new_skb)
3162 dev_kfree_skb_any(new_skb);
3163 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003164 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003165 return NETDEV_TX_OK;
3166}
3167
3168static int qeth_l3_open(struct net_device *dev)
3169{
Heiko Carstens509e2562008-07-26 02:24:10 -07003170 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003171 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003172
Carsten Otte847a50f2010-06-21 22:57:05 +00003173 QETH_CARD_TEXT(card, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003174 if (card->state != CARD_STATE_SOFTSETUP)
3175 return -ENODEV;
3176 card->data.state = CH_STATE_UP;
3177 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003178 netif_start_queue(dev);
3179
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003180 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3181 napi_enable(&card->napi);
3182 napi_schedule(&card->napi);
3183 } else
3184 rc = -EIO;
3185 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003186}
3187
3188static int qeth_l3_stop(struct net_device *dev)
3189{
Heiko Carstens509e2562008-07-26 02:24:10 -07003190 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003191
Carsten Otte847a50f2010-06-21 22:57:05 +00003192 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003193 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003194 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003195 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003196 napi_disable(&card->napi);
3197 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003198 return 0;
3199}
3200
3201static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
3202{
Heiko Carstens509e2562008-07-26 02:24:10 -07003203 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003204
3205 return (card->options.checksum_type == HW_CHECKSUMMING);
3206}
3207
3208static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
3209{
Heiko Carstens509e2562008-07-26 02:24:10 -07003210 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003211 enum qeth_checksum_types csum_type;
3212
Frank Blaschka4a71df52008-02-15 09:19:42 +01003213 if (data)
3214 csum_type = HW_CHECKSUMMING;
3215 else
3216 csum_type = SW_CHECKSUMMING;
3217
Frank Blaschka3fd434d2009-11-12 00:11:45 +00003218 return qeth_l3_set_rx_csum(card, csum_type);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003219}
3220
3221static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
3222{
Heiko Carstens509e2562008-07-26 02:24:10 -07003223 struct qeth_card *card = dev->ml_priv;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003224 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003225
3226 if (data) {
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003227 rc = qeth_l3_set_large_send(card, QETH_LARGE_SEND_TSO);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003228 } else {
3229 dev->features &= ~NETIF_F_TSO;
3230 card->options.large_send = QETH_LARGE_SEND_NO;
3231 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003232 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003233}
3234
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003235static int qeth_l3_ethtool_set_tx_csum(struct net_device *dev, u32 data)
3236{
3237 struct qeth_card *card = dev->ml_priv;
3238
3239 if (data) {
3240 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
3241 dev->features |= NETIF_F_IP_CSUM;
3242 else
3243 return -EPERM;
3244 } else
3245 dev->features &= ~NETIF_F_IP_CSUM;
3246
3247 return 0;
3248}
3249
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003250static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003251 .get_link = ethtool_op_get_link,
3252 .get_tx_csum = ethtool_op_get_tx_csum,
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00003253 .set_tx_csum = qeth_l3_ethtool_set_tx_csum,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003254 .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
3255 .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
3256 .get_sg = ethtool_op_get_sg,
3257 .set_sg = ethtool_op_set_sg,
3258 .get_tso = ethtool_op_get_tso,
3259 .set_tso = qeth_l3_ethtool_set_tso,
3260 .get_strings = qeth_core_get_strings,
3261 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003262 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003263 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003264 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003265};
3266
3267/*
3268 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3269 * NOARP on the netdevice is no option because it also turns off neighbor
3270 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3271 * arp resolution but we want the hard header (packet socket will work
3272 * e.g. tcpdump)
3273 */
3274static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3275{
3276 n->nud_state = NUD_NOARP;
3277 memcpy(n->ha, "FAKELL", 6);
3278 n->output = n->ops->connected_output;
3279 return 0;
3280}
3281
3282static int
3283qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3284{
3285 if (np->tbl->family == AF_INET)
3286 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3287
3288 return 0;
3289}
3290
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003291static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003292 .ndo_open = qeth_l3_open,
3293 .ndo_stop = qeth_l3_stop,
3294 .ndo_get_stats = qeth_get_stats,
3295 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3296 .ndo_validate_addr = eth_validate_addr,
3297 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3298 .ndo_do_ioctl = qeth_l3_do_ioctl,
3299 .ndo_change_mtu = qeth_change_mtu,
3300 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3301 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3302 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3303 .ndo_tx_timeout = qeth_tx_timeout,
3304};
3305
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003306static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3307 .ndo_open = qeth_l3_open,
3308 .ndo_stop = qeth_l3_stop,
3309 .ndo_get_stats = qeth_get_stats,
3310 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3311 .ndo_validate_addr = eth_validate_addr,
3312 .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3313 .ndo_do_ioctl = qeth_l3_do_ioctl,
3314 .ndo_change_mtu = qeth_change_mtu,
3315 .ndo_vlan_rx_register = qeth_l3_vlan_rx_register,
3316 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3317 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
3318 .ndo_tx_timeout = qeth_tx_timeout,
3319 .ndo_neigh_setup = qeth_l3_neigh_setup,
3320};
3321
Frank Blaschka4a71df52008-02-15 09:19:42 +01003322static int qeth_l3_setup_netdev(struct qeth_card *card)
3323{
Ursula Braun5113fec2010-05-16 21:15:14 +00003324 if (card->info.type == QETH_CARD_TYPE_OSD ||
3325 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003326 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3327 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3328#ifdef CONFIG_TR
3329 card->dev = alloc_trdev(0);
3330#endif
3331 if (!card->dev)
3332 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003333 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003334 } else {
3335 card->dev = alloc_etherdev(0);
3336 if (!card->dev)
3337 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003338 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003339
3340 /*IPv6 address autoconfiguration stuff*/
3341 qeth_l3_get_unique_id(card);
3342 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3343 card->dev->dev_id = card->info.unique_id &
3344 0xffff;
3345 }
3346 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3347 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3348 if (!card->dev)
3349 return -ENODEV;
3350 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003351 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003352 qeth_l3_iqd_read_initial_mac(card);
3353 } else
3354 return -ENODEV;
3355
Heiko Carstens509e2562008-07-26 02:24:10 -07003356 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003357 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003358 card->dev->mtu = card->info.initial_mtu;
3359 SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3360 card->dev->features |= NETIF_F_HW_VLAN_TX |
3361 NETIF_F_HW_VLAN_RX |
3362 NETIF_F_HW_VLAN_FILTER;
Eric Dumazet86d15cd2009-05-30 23:04:46 -07003363 card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
Frank Blaschkac3b4a742009-11-12 00:11:44 +00003364 card->dev->gso_max_size = 15 * PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003365
3366 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003367 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003368 return register_netdev(card->dev);
3369}
3370
Frank Blaschka4a71df52008-02-15 09:19:42 +01003371static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3372{
3373 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3374
3375 qeth_l3_create_device_attributes(&gdev->dev);
3376 card->options.layer2 = 0;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003377 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003378 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003379 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003380 card->discipline.output_handler = (qdio_handler_t *)
3381 qeth_qdio_output_handler;
3382 card->discipline.recover = qeth_l3_recover;
3383 return 0;
3384}
3385
3386static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3387{
3388 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3389
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003390 qeth_l3_remove_device_attributes(&cgdev->dev);
3391
Ursula Braunf2148562009-05-19 21:38:37 +00003392 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003393 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3394
3395 if (cgdev->state == CCWGROUP_ONLINE) {
3396 card->use_hard_stop = 1;
3397 qeth_l3_set_offline(cgdev);
3398 }
3399
3400 if (card->dev) {
3401 unregister_netdev(card->dev);
3402 card->dev = NULL;
3403 }
3404
Frank Blaschka4a71df52008-02-15 09:19:42 +01003405 qeth_l3_clear_ip_list(card, 0, 0);
3406 qeth_l3_clear_ipato_list(card);
3407 return;
3408}
3409
3410static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3411{
3412 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3413 int rc = 0;
3414 enum qeth_card_states recover_flag;
3415
3416 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003417 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003418 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003419 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3420 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003421
Frank Blaschka4a71df52008-02-15 09:19:42 +01003422 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003423 rc = qeth_core_hardsetup_card(card);
3424 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003425 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003426 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003427 goto out_remove;
3428 }
3429
3430 qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3431
Ursula Braunaa909222009-11-12 00:11:43 +00003432 if (!card->dev && qeth_l3_setup_netdev(card)) {
3433 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003434 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003435 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003436
3437 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003438 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003439 qeth_print_status_message(card);
3440
3441 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003442 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003443
3444 rc = qeth_send_startlan(card);
3445 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003446 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003447 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003448 dev_warn(&card->gdev->dev,
3449 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003450 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003451 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003452 }
Ursula Braunaa909222009-11-12 00:11:43 +00003453 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003454 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003455 } else
3456 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003457
Ursula Braun2b6203b2010-11-26 02:41:19 +00003458contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003459 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;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003483
3484 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkae8069042009-08-26 02:01:07 +00003485 qeth_l3_set_ip_addr_list(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003486 if (card->lan_online)
3487 netif_carrier_on(card->dev);
3488 else
3489 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003490 if (recover_flag == CARD_STATE_RECOVER) {
3491 if (recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003492 qeth_l3_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003493 else {
3494 rtnl_lock();
3495 dev_open(card->dev);
3496 rtnl_unlock();
3497 }
3498 qeth_l3_set_multicast_list(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003499 }
3500 /* let user_space know that device is online */
3501 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003502 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003503 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003504 return 0;
3505out_remove:
3506 card->use_hard_stop = 1;
3507 qeth_l3_stop_card(card, 0);
3508 ccw_device_set_offline(CARD_DDEV(card));
3509 ccw_device_set_offline(CARD_WDEV(card));
3510 ccw_device_set_offline(CARD_RDEV(card));
3511 if (recover_flag == CARD_STATE_RECOVER)
3512 card->state = CARD_STATE_RECOVER;
3513 else
3514 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003515 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003516 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003517 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003518}
3519
3520static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3521{
3522 return __qeth_l3_set_online(gdev, 0);
3523}
3524
3525static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3526 int recovery_mode)
3527{
3528 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3529 int rc = 0, rc2 = 0, rc3 = 0;
3530 enum qeth_card_states recover_flag;
3531
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003532 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003533 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003534 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3535 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003536
3537 if (card->dev && netif_carrier_ok(card->dev))
3538 netif_carrier_off(card->dev);
3539 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02003540 qeth_l3_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003541 rc = ccw_device_set_offline(CARD_DDEV(card));
3542 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3543 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3544 if (!rc)
3545 rc = (rc2) ? rc2 : rc3;
3546 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003547 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003548 if (recover_flag == CARD_STATE_UP)
3549 card->state = CARD_STATE_RECOVER;
3550 /* let user_space know that device is offline */
3551 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003552 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003553 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003554 return 0;
3555}
3556
3557static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3558{
3559 return __qeth_l3_set_offline(cgdev, 0);
3560}
3561
3562static int qeth_l3_recover(void *ptr)
3563{
3564 struct qeth_card *card;
3565 int rc = 0;
3566
3567 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003568 QETH_CARD_TEXT(card, 2, "recover1");
3569 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003570 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3571 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003572 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003573 dev_warn(&card->gdev->dev,
3574 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003575 card->use_hard_stop = 1;
3576 __qeth_l3_set_offline(card->gdev, 1);
3577 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003578 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003579 dev_info(&card->gdev->dev,
3580 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003581 else {
3582 rtnl_lock();
3583 dev_close(card->dev);
3584 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003585 dev_warn(&card->gdev->dev, "The qeth device driver "
3586 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003587 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003588 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3589 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003590 return 0;
3591}
3592
3593static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3594{
3595 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3596 qeth_l3_clear_ip_list(card, 0, 0);
3597 qeth_qdio_clear_card(card, 0);
3598 qeth_clear_qdio_buffers(card);
3599}
3600
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003601static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3602{
3603 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3604
3605 if (card->dev)
3606 netif_device_detach(card->dev);
3607 qeth_set_allowed_threads(card, 0, 1);
3608 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3609 if (gdev->state == CCWGROUP_OFFLINE)
3610 return 0;
3611 if (card->state == CARD_STATE_UP) {
3612 card->use_hard_stop = 1;
3613 __qeth_l3_set_offline(card->gdev, 1);
3614 } else
3615 __qeth_l3_set_offline(card->gdev, 0);
3616 return 0;
3617}
3618
3619static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3620{
3621 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3622 int rc = 0;
3623
3624 if (gdev->state == CCWGROUP_OFFLINE)
3625 goto out;
3626
3627 if (card->state == CARD_STATE_RECOVER) {
3628 rc = __qeth_l3_set_online(card->gdev, 1);
3629 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003630 rtnl_lock();
3631 dev_close(card->dev);
3632 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003633 }
3634 } else
3635 rc = __qeth_l3_set_online(card->gdev, 0);
3636out:
3637 qeth_set_allowed_threads(card, 0xffffffff, 0);
3638 if (card->dev)
3639 netif_device_attach(card->dev);
3640 if (rc)
3641 dev_warn(&card->gdev->dev, "The qeth device driver "
3642 "failed to recover an error on the device\n");
3643 return rc;
3644}
3645
Frank Blaschka4a71df52008-02-15 09:19:42 +01003646struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3647 .probe = qeth_l3_probe_device,
3648 .remove = qeth_l3_remove_device,
3649 .set_online = qeth_l3_set_online,
3650 .set_offline = qeth_l3_set_offline,
3651 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003652 .freeze = qeth_l3_pm_suspend,
3653 .thaw = qeth_l3_pm_resume,
3654 .restore = qeth_l3_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003655};
3656EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3657
3658static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003659 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003660{
3661 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3662 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3663 struct qeth_ipaddr *addr;
3664 struct qeth_card *card;
3665
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003666 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003667 return NOTIFY_DONE;
3668
Frank Blaschka4a71df52008-02-15 09:19:42 +01003669 card = qeth_l3_get_card_from_dev(dev);
Carsten Otte847a50f2010-06-21 22:57:05 +00003670 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003671 if (!card)
3672 return NOTIFY_DONE;
3673
3674 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3675 if (addr != NULL) {
3676 addr->u.a4.addr = ifa->ifa_address;
3677 addr->u.a4.mask = ifa->ifa_mask;
3678 addr->type = QETH_IP_TYPE_NORMAL;
3679 } else
3680 goto out;
3681
3682 switch (event) {
3683 case NETDEV_UP:
3684 if (!qeth_l3_add_ip(card, addr))
3685 kfree(addr);
3686 break;
3687 case NETDEV_DOWN:
3688 if (!qeth_l3_delete_ip(card, addr))
3689 kfree(addr);
3690 break;
3691 default:
3692 break;
3693 }
3694 qeth_l3_set_ip_addr_list(card);
3695out:
3696 return NOTIFY_DONE;
3697}
3698
3699static struct notifier_block qeth_l3_ip_notifier = {
3700 qeth_l3_ip_event,
3701 NULL,
3702};
3703
3704#ifdef CONFIG_QETH_IPV6
3705/**
3706 * IPv6 event handler
3707 */
3708static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003709 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003710{
3711 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3712 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3713 struct qeth_ipaddr *addr;
3714 struct qeth_card *card;
3715
Frank Blaschka4a71df52008-02-15 09:19:42 +01003716
3717 card = qeth_l3_get_card_from_dev(dev);
3718 if (!card)
3719 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003720 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003721 if (!qeth_is_supported(card, IPA_IPV6))
3722 return NOTIFY_DONE;
3723
3724 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3725 if (addr != NULL) {
3726 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3727 addr->u.a6.pfxlen = ifa->prefix_len;
3728 addr->type = QETH_IP_TYPE_NORMAL;
3729 } else
3730 goto out;
3731
3732 switch (event) {
3733 case NETDEV_UP:
3734 if (!qeth_l3_add_ip(card, addr))
3735 kfree(addr);
3736 break;
3737 case NETDEV_DOWN:
3738 if (!qeth_l3_delete_ip(card, addr))
3739 kfree(addr);
3740 break;
3741 default:
3742 break;
3743 }
3744 qeth_l3_set_ip_addr_list(card);
3745out:
3746 return NOTIFY_DONE;
3747}
3748
3749static struct notifier_block qeth_l3_ip6_notifier = {
3750 qeth_l3_ip6_event,
3751 NULL,
3752};
3753#endif
3754
3755static int qeth_l3_register_notifiers(void)
3756{
3757 int rc;
3758
Carsten Otte847a50f2010-06-21 22:57:05 +00003759 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003760 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3761 if (rc)
3762 return rc;
3763#ifdef CONFIG_QETH_IPV6
3764 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3765 if (rc) {
3766 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3767 return rc;
3768 }
3769#else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003770 pr_warning("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003771#endif
3772 return 0;
3773}
3774
3775static void qeth_l3_unregister_notifiers(void)
3776{
3777
Carsten Otte847a50f2010-06-21 22:57:05 +00003778 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003779 BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3780#ifdef CONFIG_QETH_IPV6
3781 BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3782#endif /* QETH_IPV6 */
3783}
3784
3785static int __init qeth_l3_init(void)
3786{
3787 int rc = 0;
3788
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003789 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003790 rc = qeth_l3_register_notifiers();
3791 return rc;
3792}
3793
3794static void __exit qeth_l3_exit(void)
3795{
3796 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003797 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003798}
3799
3800module_init(qeth_l3_init);
3801module_exit(qeth_l3_exit);
3802MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3803MODULE_DESCRIPTION("qeth layer 3 discipline");
3804MODULE_LICENSE("GPL");