qeth: Exploit Connection Isolation
[pandora-kernel.git] / drivers / s390 / net / qeth_l3_main.c
1 /*
2  *  drivers/s390/net/qeth_l3_main.c
3  *
4  *    Copyright IBM Corp. 2007, 2009
5  *    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
11 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
14 #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>
22 #include <linux/ipv6.h>
23 #include <linux/inetdevice.h>
24 #include <linux/igmp.h>
25
26 #include <net/ip.h>
27 #include <net/arp.h>
28 #include <net/ip6_checksum.h>
29
30 #include "qeth_l3.h"
31
32 static int qeth_l3_set_offline(struct ccwgroup_device *);
33 static int qeth_l3_recover(void *);
34 static int qeth_l3_stop(struct net_device *);
35 static void qeth_l3_set_multicast_list(struct net_device *);
36 static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
37 static int qeth_l3_register_addr_entry(struct qeth_card *,
38                 struct qeth_ipaddr *);
39 static int qeth_l3_deregister_addr_entry(struct qeth_card *,
40                 struct qeth_ipaddr *);
41 static int __qeth_l3_set_online(struct ccwgroup_device *, int);
42 static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
43
44
45 static int qeth_l3_isxdigit(char *buf)
46 {
47         while (*buf) {
48                 if (!isxdigit(*buf++))
49                         return 0;
50         }
51         return 1;
52 }
53
54 void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
55 {
56         sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
57 }
58
59 int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
60 {
61         int count = 0, rc = 0;
62         int in[4];
63         char c;
64
65         rc = sscanf(buf, "%u.%u.%u.%u%c",
66                     &in[0], &in[1], &in[2], &in[3], &c);
67         if (rc != 4 && (rc != 5 || c != '\n'))
68                 return -EINVAL;
69         for (count = 0; count < 4; count++) {
70                 if (in[count] > 255)
71                         return -EINVAL;
72                 addr[count] = in[count];
73         }
74         return 0;
75 }
76
77 void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
78 {
79         sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
80                      ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
81                      addr[0], addr[1], addr[2], addr[3],
82                      addr[4], addr[5], addr[6], addr[7],
83                      addr[8], addr[9], addr[10], addr[11],
84                      addr[12], addr[13], addr[14], addr[15]);
85 }
86
87 int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
88 {
89         const char *end, *end_tmp, *start;
90         __u16 *in;
91         char num[5];
92         int num2, cnt, out, found, save_cnt;
93         unsigned short in_tmp[8] = {0, };
94
95         cnt = out = found = save_cnt = num2 = 0;
96         end = start = buf;
97         in = (__u16 *) addr;
98         memset(in, 0, 16);
99         while (*end) {
100                 end = strchr(start, ':');
101                 if (end == NULL) {
102                         end = buf + strlen(buf);
103                         end_tmp = strchr(start, '\n');
104                         if (end_tmp != NULL)
105                                 end = end_tmp;
106                         out = 1;
107                 }
108                 if ((end - start)) {
109                         memset(num, 0, 5);
110                         if ((end - start) > 4)
111                                 return -EINVAL;
112                         memcpy(num, start, end - start);
113                         if (!qeth_l3_isxdigit(num))
114                                 return -EINVAL;
115                         sscanf(start, "%x", &num2);
116                         if (found)
117                                 in_tmp[save_cnt++] = num2;
118                         else
119                                 in[cnt++] = num2;
120                         if (out)
121                                 break;
122                 } else {
123                         if (found)
124                                 return -EINVAL;
125                         found = 1;
126                 }
127                 start = ++end;
128         }
129         if (cnt + save_cnt > 8)
130                 return -EINVAL;
131         cnt = 7;
132         while (save_cnt)
133                 in[cnt--] = in_tmp[--save_cnt];
134         return 0;
135 }
136
137 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
138                                 char *buf)
139 {
140         if (proto == QETH_PROT_IPV4)
141                 qeth_l3_ipaddr4_to_string(addr, buf);
142         else if (proto == QETH_PROT_IPV6)
143                 qeth_l3_ipaddr6_to_string(addr, buf);
144 }
145
146 int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
147                                 __u8 *addr)
148 {
149         if (proto == QETH_PROT_IPV4)
150                 return qeth_l3_string_to_ipaddr4(buf, addr);
151         else if (proto == QETH_PROT_IPV6)
152                 return qeth_l3_string_to_ipaddr6(buf, addr);
153         else
154                 return -EINVAL;
155 }
156
157 static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
158 {
159         int i, j;
160         u8 octet;
161
162         for (i = 0; i < len; ++i) {
163                 octet = addr[i];
164                 for (j = 7; j >= 0; --j) {
165                         bits[i*8 + j] = octet & 1;
166                         octet >>= 1;
167                 }
168         }
169 }
170
171 static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
172                                                 struct qeth_ipaddr *addr)
173 {
174         struct qeth_ipato_entry *ipatoe;
175         u8 addr_bits[128] = {0, };
176         u8 ipatoe_bits[128] = {0, };
177         int rc = 0;
178
179         if (!card->ipato.enabled)
180                 return 0;
181
182         qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
183                                   (addr->proto == QETH_PROT_IPV4)? 4:16);
184         list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
185                 if (addr->proto != ipatoe->proto)
186                         continue;
187                 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
188                                           (ipatoe->proto == QETH_PROT_IPV4) ?
189                                           4 : 16);
190                 if (addr->proto == QETH_PROT_IPV4)
191                         rc = !memcmp(addr_bits, ipatoe_bits,
192                                      min(32, ipatoe->mask_bits));
193                 else
194                         rc = !memcmp(addr_bits, ipatoe_bits,
195                                      min(128, ipatoe->mask_bits));
196                 if (rc)
197                         break;
198         }
199         /* invert? */
200         if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
201                 rc = !rc;
202         else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
203                 rc = !rc;
204
205         return rc;
206 }
207
208 /*
209  * Add IP to be added to todo list. If there is already an "add todo"
210  * in this list we just incremenent the reference count.
211  * Returns 0 if we  just incremented reference count.
212  */
213 static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
214                                         struct qeth_ipaddr *addr, int add)
215 {
216         struct qeth_ipaddr *tmp, *t;
217         int found = 0;
218
219         list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
220                 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
221                     (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
222                         return 0;
223                 if ((tmp->proto        == QETH_PROT_IPV4)     &&
224                     (addr->proto       == QETH_PROT_IPV4)     &&
225                     (tmp->type         == addr->type)         &&
226                     (tmp->is_multicast == addr->is_multicast) &&
227                     (tmp->u.a4.addr    == addr->u.a4.addr)    &&
228                     (tmp->u.a4.mask    == addr->u.a4.mask)) {
229                         found = 1;
230                         break;
231                 }
232                 if ((tmp->proto        == QETH_PROT_IPV6)      &&
233                     (addr->proto       == QETH_PROT_IPV6)      &&
234                     (tmp->type         == addr->type)          &&
235                     (tmp->is_multicast == addr->is_multicast)  &&
236                     (tmp->u.a6.pfxlen  == addr->u.a6.pfxlen)   &&
237                     (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
238                             sizeof(struct in6_addr)) == 0)) {
239                         found = 1;
240                         break;
241                 }
242         }
243         if (found) {
244                 if (addr->users != 0)
245                         tmp->users += addr->users;
246                 else
247                         tmp->users += add ? 1 : -1;
248                 if (tmp->users == 0) {
249                         list_del(&tmp->entry);
250                         kfree(tmp);
251                 }
252                 return 0;
253         } else {
254                 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
255                         list_add(&addr->entry, card->ip_tbd_list);
256                 else {
257                         if (addr->users == 0)
258                                 addr->users += add ? 1 : -1;
259                         if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
260                             qeth_l3_is_addr_covered_by_ipato(card, addr)) {
261                                 QETH_DBF_TEXT(TRACE, 2, "tkovaddr");
262                                 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
263                         }
264                         list_add_tail(&addr->entry, card->ip_tbd_list);
265                 }
266                 return 1;
267         }
268 }
269
270 static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
271 {
272         unsigned long flags;
273         int rc = 0;
274
275         QETH_DBF_TEXT(TRACE, 4, "delip");
276
277         if (addr->proto == QETH_PROT_IPV4)
278                 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
279         else {
280                 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
281                 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
282         }
283         spin_lock_irqsave(&card->ip_lock, flags);
284         rc = __qeth_l3_insert_ip_todo(card, addr, 0);
285         spin_unlock_irqrestore(&card->ip_lock, flags);
286         return rc;
287 }
288
289 static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
290 {
291         unsigned long flags;
292         int rc = 0;
293
294         QETH_DBF_TEXT(TRACE, 4, "addip");
295         if (addr->proto == QETH_PROT_IPV4)
296                 QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4);
297         else {
298                 QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8);
299                 QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8);
300         }
301         spin_lock_irqsave(&card->ip_lock, flags);
302         rc = __qeth_l3_insert_ip_todo(card, addr, 1);
303         spin_unlock_irqrestore(&card->ip_lock, flags);
304         return rc;
305 }
306
307
308 static struct qeth_ipaddr *qeth_l3_get_addr_buffer(
309                                 enum qeth_prot_versions prot)
310 {
311         struct qeth_ipaddr *addr;
312
313         addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
314         if (addr == NULL) {
315                 return NULL;
316         }
317         addr->type = QETH_IP_TYPE_NORMAL;
318         addr->proto = prot;
319         return addr;
320 }
321
322 static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
323 {
324         struct qeth_ipaddr *iptodo;
325         unsigned long flags;
326
327         QETH_DBF_TEXT(TRACE, 4, "delmc");
328         iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
329         if (!iptodo) {
330                 QETH_DBF_TEXT(TRACE, 2, "dmcnomem");
331                 return;
332         }
333         iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
334         spin_lock_irqsave(&card->ip_lock, flags);
335         if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
336                 kfree(iptodo);
337         spin_unlock_irqrestore(&card->ip_lock, flags);
338 }
339
340 /*
341  * Add/remove address to/from card's ip list, i.e. try to add or remove
342  * reference to/from an IP address that is already registered on the card.
343  * Returns:
344  *      0  address was on card and its reference count has been adjusted,
345  *         but is still > 0, so nothing has to be done
346  *         also returns 0 if card was not on card and the todo was to delete
347  *         the address -> there is also nothing to be done
348  *      1  address was not on card and the todo is to add it to the card's ip
349  *         list
350  *      -1 address was on card and its reference count has been decremented
351  *         to <= 0 by the todo -> address must be removed from card
352  */
353 static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
354                 struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
355 {
356         struct qeth_ipaddr *addr;
357         int found = 0;
358
359         list_for_each_entry(addr, &card->ip_list, entry) {
360                 if ((addr->proto == QETH_PROT_IPV4) &&
361                     (todo->proto == QETH_PROT_IPV4) &&
362                     (addr->type == todo->type) &&
363                     (addr->u.a4.addr == todo->u.a4.addr) &&
364                     (addr->u.a4.mask == todo->u.a4.mask)) {
365                         found = 1;
366                         break;
367                 }
368                 if ((addr->proto == QETH_PROT_IPV6) &&
369                     (todo->proto == QETH_PROT_IPV6) &&
370                     (addr->type == todo->type) &&
371                     (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
372                     (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
373                             sizeof(struct in6_addr)) == 0)) {
374                         found = 1;
375                         break;
376                 }
377         }
378         if (found) {
379                 addr->users += todo->users;
380                 if (addr->users <= 0) {
381                         *__addr = addr;
382                         return -1;
383                 } else {
384                         /* for VIPA and RXIP limit refcount to 1 */
385                         if (addr->type != QETH_IP_TYPE_NORMAL)
386                                 addr->users = 1;
387                         return 0;
388                 }
389         }
390         if (todo->users > 0) {
391                 /* for VIPA and RXIP limit refcount to 1 */
392                 if (todo->type != QETH_IP_TYPE_NORMAL)
393                         todo->users = 1;
394                 return 1;
395         } else
396                 return 0;
397 }
398
399 static void __qeth_l3_delete_all_mc(struct qeth_card *card,
400                                         unsigned long *flags)
401 {
402         struct list_head fail_list;
403         struct qeth_ipaddr *addr, *tmp;
404         int rc;
405
406         INIT_LIST_HEAD(&fail_list);
407 again:
408         list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
409                 if (addr->is_multicast) {
410                         list_del(&addr->entry);
411                         spin_unlock_irqrestore(&card->ip_lock, *flags);
412                         rc = qeth_l3_deregister_addr_entry(card, addr);
413                         spin_lock_irqsave(&card->ip_lock, *flags);
414                         if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
415                                 kfree(addr);
416                         else
417                                 list_add_tail(&addr->entry, &fail_list);
418                         goto again;
419                 }
420         }
421         list_splice(&fail_list, &card->ip_list);
422 }
423
424 static void qeth_l3_set_ip_addr_list(struct qeth_card *card)
425 {
426         struct list_head *tbd_list;
427         struct qeth_ipaddr *todo, *addr;
428         unsigned long flags;
429         int rc;
430
431         QETH_DBF_TEXT(TRACE, 2, "sdiplist");
432         QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
433
434         spin_lock_irqsave(&card->ip_lock, flags);
435         tbd_list = card->ip_tbd_list;
436         card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
437         if (!card->ip_tbd_list) {
438                 QETH_DBF_TEXT(TRACE, 0, "silnomem");
439                 card->ip_tbd_list = tbd_list;
440                 spin_unlock_irqrestore(&card->ip_lock, flags);
441                 return;
442         } else
443                 INIT_LIST_HEAD(card->ip_tbd_list);
444
445         while (!list_empty(tbd_list)) {
446                 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
447                 list_del(&todo->entry);
448                 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
449                         __qeth_l3_delete_all_mc(card, &flags);
450                         kfree(todo);
451                         continue;
452                 }
453                 rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
454                 if (rc == 0) {
455                         /* nothing to be done; only adjusted refcount */
456                         kfree(todo);
457                 } else if (rc == 1) {
458                         /* new entry to be added to on-card list */
459                         spin_unlock_irqrestore(&card->ip_lock, flags);
460                         rc = qeth_l3_register_addr_entry(card, todo);
461                         spin_lock_irqsave(&card->ip_lock, flags);
462                         if (!rc || (rc == IPA_RC_LAN_OFFLINE))
463                                 list_add_tail(&todo->entry, &card->ip_list);
464                         else
465                                 kfree(todo);
466                 } else if (rc == -1) {
467                         /* on-card entry to be removed */
468                         list_del_init(&addr->entry);
469                         spin_unlock_irqrestore(&card->ip_lock, flags);
470                         rc = qeth_l3_deregister_addr_entry(card, addr);
471                         spin_lock_irqsave(&card->ip_lock, flags);
472                         if (!rc || (rc == IPA_RC_PRIMARY_ALREADY_DEFINED))
473                                 kfree(addr);
474                         else
475                                 list_add_tail(&addr->entry, &card->ip_list);
476                         kfree(todo);
477                 }
478         }
479         spin_unlock_irqrestore(&card->ip_lock, flags);
480         kfree(tbd_list);
481 }
482
483 static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean,
484                                         int recover)
485 {
486         struct qeth_ipaddr *addr, *tmp;
487         unsigned long flags;
488
489         QETH_DBF_TEXT(TRACE, 4, "clearip");
490         spin_lock_irqsave(&card->ip_lock, flags);
491         /* clear todo list */
492         list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
493                 list_del(&addr->entry);
494                 kfree(addr);
495         }
496
497         while (!list_empty(&card->ip_list)) {
498                 addr = list_entry(card->ip_list.next,
499                                   struct qeth_ipaddr, entry);
500                 list_del_init(&addr->entry);
501                 if (clean) {
502                         spin_unlock_irqrestore(&card->ip_lock, flags);
503                         qeth_l3_deregister_addr_entry(card, addr);
504                         spin_lock_irqsave(&card->ip_lock, flags);
505                 }
506                 if (!recover || addr->is_multicast) {
507                         kfree(addr);
508                         continue;
509                 }
510                 list_add_tail(&addr->entry, card->ip_tbd_list);
511         }
512         spin_unlock_irqrestore(&card->ip_lock, flags);
513 }
514
515 static int qeth_l3_address_exists_in_list(struct list_head *list,
516                 struct qeth_ipaddr *addr, int same_type)
517 {
518         struct qeth_ipaddr *tmp;
519
520         list_for_each_entry(tmp, list, entry) {
521                 if ((tmp->proto == QETH_PROT_IPV4) &&
522                     (addr->proto == QETH_PROT_IPV4) &&
523                     ((same_type && (tmp->type == addr->type)) ||
524                     (!same_type && (tmp->type != addr->type))) &&
525                     (tmp->u.a4.addr == addr->u.a4.addr))
526                         return 1;
527
528                 if ((tmp->proto == QETH_PROT_IPV6) &&
529                     (addr->proto == QETH_PROT_IPV6) &&
530                     ((same_type && (tmp->type == addr->type)) ||
531                     (!same_type && (tmp->type != addr->type))) &&
532                     (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
533                             sizeof(struct in6_addr)) == 0))
534                         return 1;
535
536         }
537         return 0;
538 }
539
540 static int qeth_l3_send_setdelmc(struct qeth_card *card,
541                         struct qeth_ipaddr *addr, int ipacmd)
542 {
543         int rc;
544         struct qeth_cmd_buffer *iob;
545         struct qeth_ipa_cmd *cmd;
546
547         QETH_DBF_TEXT(TRACE, 4, "setdelmc");
548
549         iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
550         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
551         memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
552         if (addr->proto == QETH_PROT_IPV6)
553                 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
554                        sizeof(struct in6_addr));
555         else
556                 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
557
558         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
559
560         return rc;
561 }
562
563 static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
564 {
565         int i, j;
566         for (i = 0; i < 16; i++) {
567                 j = (len) - (i * 8);
568                 if (j >= 8)
569                         netmask[i] = 0xff;
570                 else if (j > 0)
571                         netmask[i] = (u8)(0xFF00 >> j);
572                 else
573                         netmask[i] = 0;
574         }
575 }
576
577 static int qeth_l3_send_setdelip(struct qeth_card *card,
578                 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
579 {
580         int rc;
581         struct qeth_cmd_buffer *iob;
582         struct qeth_ipa_cmd *cmd;
583         __u8 netmask[16];
584
585         QETH_DBF_TEXT(TRACE, 4, "setdelip");
586         QETH_DBF_TEXT_(TRACE, 4, "flags%02X", flags);
587
588         iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
589         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
590         if (addr->proto == QETH_PROT_IPV6) {
591                 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
592                        sizeof(struct in6_addr));
593                 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
594                 memcpy(cmd->data.setdelip6.mask, netmask,
595                        sizeof(struct in6_addr));
596                 cmd->data.setdelip6.flags = flags;
597         } else {
598                 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
599                 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
600                 cmd->data.setdelip4.flags = flags;
601         }
602
603         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
604
605         return rc;
606 }
607
608 static int qeth_l3_send_setrouting(struct qeth_card *card,
609         enum qeth_routing_types type, enum qeth_prot_versions prot)
610 {
611         int rc;
612         struct qeth_ipa_cmd *cmd;
613         struct qeth_cmd_buffer *iob;
614
615         QETH_DBF_TEXT(TRACE, 4, "setroutg");
616         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
617         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
618         cmd->data.setrtg.type = (type);
619         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
620
621         return rc;
622 }
623
624 static void qeth_l3_correct_routing_type(struct qeth_card *card,
625                 enum qeth_routing_types *type, enum qeth_prot_versions prot)
626 {
627         if (card->info.type == QETH_CARD_TYPE_IQD) {
628                 switch (*type) {
629                 case NO_ROUTER:
630                 case PRIMARY_CONNECTOR:
631                 case SECONDARY_CONNECTOR:
632                 case MULTICAST_ROUTER:
633                         return;
634                 default:
635                         goto out_inval;
636                 }
637         } else {
638                 switch (*type) {
639                 case NO_ROUTER:
640                 case PRIMARY_ROUTER:
641                 case SECONDARY_ROUTER:
642                         return;
643                 case MULTICAST_ROUTER:
644                         if (qeth_is_ipafunc_supported(card, prot,
645                                                       IPA_OSA_MC_ROUTER))
646                                 return;
647                 default:
648                         goto out_inval;
649                 }
650         }
651 out_inval:
652         *type = NO_ROUTER;
653 }
654
655 int qeth_l3_setrouting_v4(struct qeth_card *card)
656 {
657         int rc;
658
659         QETH_DBF_TEXT(TRACE, 3, "setrtg4");
660
661         qeth_l3_correct_routing_type(card, &card->options.route4.type,
662                                   QETH_PROT_IPV4);
663
664         rc = qeth_l3_send_setrouting(card, card->options.route4.type,
665                                   QETH_PROT_IPV4);
666         if (rc) {
667                 card->options.route4.type = NO_ROUTER;
668                 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
669                         " on %s. Type set to 'no router'.\n", rc,
670                         QETH_CARD_IFNAME(card));
671         }
672         return rc;
673 }
674
675 int qeth_l3_setrouting_v6(struct qeth_card *card)
676 {
677         int rc = 0;
678
679         QETH_DBF_TEXT(TRACE, 3, "setrtg6");
680 #ifdef CONFIG_QETH_IPV6
681
682         if (!qeth_is_supported(card, IPA_IPV6))
683                 return 0;
684         qeth_l3_correct_routing_type(card, &card->options.route6.type,
685                                   QETH_PROT_IPV6);
686
687         rc = qeth_l3_send_setrouting(card, card->options.route6.type,
688                                   QETH_PROT_IPV6);
689         if (rc) {
690                 card->options.route6.type = NO_ROUTER;
691                 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
692                         " on %s. Type set to 'no router'.\n", rc,
693                         QETH_CARD_IFNAME(card));
694         }
695 #endif
696         return rc;
697 }
698
699 /*
700  * IP address takeover related functions
701  */
702 static void qeth_l3_clear_ipato_list(struct qeth_card *card)
703 {
704
705         struct qeth_ipato_entry *ipatoe, *tmp;
706         unsigned long flags;
707
708         spin_lock_irqsave(&card->ip_lock, flags);
709         list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
710                 list_del(&ipatoe->entry);
711                 kfree(ipatoe);
712         }
713         spin_unlock_irqrestore(&card->ip_lock, flags);
714 }
715
716 int qeth_l3_add_ipato_entry(struct qeth_card *card,
717                                 struct qeth_ipato_entry *new)
718 {
719         struct qeth_ipato_entry *ipatoe;
720         unsigned long flags;
721         int rc = 0;
722
723         QETH_DBF_TEXT(TRACE, 2, "addipato");
724         spin_lock_irqsave(&card->ip_lock, flags);
725         list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
726                 if (ipatoe->proto != new->proto)
727                         continue;
728                 if (!memcmp(ipatoe->addr, new->addr,
729                             (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
730                     (ipatoe->mask_bits == new->mask_bits)) {
731                         rc = -EEXIST;
732                         break;
733                 }
734         }
735         if (!rc)
736                 list_add_tail(&new->entry, &card->ipato.entries);
737
738         spin_unlock_irqrestore(&card->ip_lock, flags);
739         return rc;
740 }
741
742 void qeth_l3_del_ipato_entry(struct qeth_card *card,
743                 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
744 {
745         struct qeth_ipato_entry *ipatoe, *tmp;
746         unsigned long flags;
747
748         QETH_DBF_TEXT(TRACE, 2, "delipato");
749         spin_lock_irqsave(&card->ip_lock, flags);
750         list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
751                 if (ipatoe->proto != proto)
752                         continue;
753                 if (!memcmp(ipatoe->addr, addr,
754                             (proto == QETH_PROT_IPV4)? 4:16) &&
755                     (ipatoe->mask_bits == mask_bits)) {
756                         list_del(&ipatoe->entry);
757                         kfree(ipatoe);
758                 }
759         }
760         spin_unlock_irqrestore(&card->ip_lock, flags);
761 }
762
763 /*
764  * VIPA related functions
765  */
766 int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
767               const u8 *addr)
768 {
769         struct qeth_ipaddr *ipaddr;
770         unsigned long flags;
771         int rc = 0;
772
773         ipaddr = qeth_l3_get_addr_buffer(proto);
774         if (ipaddr) {
775                 if (proto == QETH_PROT_IPV4) {
776                         QETH_DBF_TEXT(TRACE, 2, "addvipa4");
777                         memcpy(&ipaddr->u.a4.addr, addr, 4);
778                         ipaddr->u.a4.mask = 0;
779                 } else if (proto == QETH_PROT_IPV6) {
780                         QETH_DBF_TEXT(TRACE, 2, "addvipa6");
781                         memcpy(&ipaddr->u.a6.addr, addr, 16);
782                         ipaddr->u.a6.pfxlen = 0;
783                 }
784                 ipaddr->type = QETH_IP_TYPE_VIPA;
785                 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
786                 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
787         } else
788                 return -ENOMEM;
789         spin_lock_irqsave(&card->ip_lock, flags);
790         if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
791             qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
792                 rc = -EEXIST;
793         spin_unlock_irqrestore(&card->ip_lock, flags);
794         if (rc) {
795                 return rc;
796         }
797         if (!qeth_l3_add_ip(card, ipaddr))
798                 kfree(ipaddr);
799         qeth_l3_set_ip_addr_list(card);
800         return rc;
801 }
802
803 void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
804               const u8 *addr)
805 {
806         struct qeth_ipaddr *ipaddr;
807
808         ipaddr = qeth_l3_get_addr_buffer(proto);
809         if (ipaddr) {
810                 if (proto == QETH_PROT_IPV4) {
811                         QETH_DBF_TEXT(TRACE, 2, "delvipa4");
812                         memcpy(&ipaddr->u.a4.addr, addr, 4);
813                         ipaddr->u.a4.mask = 0;
814                 } else if (proto == QETH_PROT_IPV6) {
815                         QETH_DBF_TEXT(TRACE, 2, "delvipa6");
816                         memcpy(&ipaddr->u.a6.addr, addr, 16);
817                         ipaddr->u.a6.pfxlen = 0;
818                 }
819                 ipaddr->type = QETH_IP_TYPE_VIPA;
820         } else
821                 return;
822         if (!qeth_l3_delete_ip(card, ipaddr))
823                 kfree(ipaddr);
824         qeth_l3_set_ip_addr_list(card);
825 }
826
827 /*
828  * proxy ARP related functions
829  */
830 int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
831               const u8 *addr)
832 {
833         struct qeth_ipaddr *ipaddr;
834         unsigned long flags;
835         int rc = 0;
836
837         ipaddr = qeth_l3_get_addr_buffer(proto);
838         if (ipaddr) {
839                 if (proto == QETH_PROT_IPV4) {
840                         QETH_DBF_TEXT(TRACE, 2, "addrxip4");
841                         memcpy(&ipaddr->u.a4.addr, addr, 4);
842                         ipaddr->u.a4.mask = 0;
843                 } else if (proto == QETH_PROT_IPV6) {
844                         QETH_DBF_TEXT(TRACE, 2, "addrxip6");
845                         memcpy(&ipaddr->u.a6.addr, addr, 16);
846                         ipaddr->u.a6.pfxlen = 0;
847                 }
848                 ipaddr->type = QETH_IP_TYPE_RXIP;
849                 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
850                 ipaddr->del_flags = 0;
851         } else
852                 return -ENOMEM;
853         spin_lock_irqsave(&card->ip_lock, flags);
854         if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
855             qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
856                 rc = -EEXIST;
857         spin_unlock_irqrestore(&card->ip_lock, flags);
858         if (rc) {
859                 return rc;
860         }
861         if (!qeth_l3_add_ip(card, ipaddr))
862                 kfree(ipaddr);
863         qeth_l3_set_ip_addr_list(card);
864         return 0;
865 }
866
867 void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
868                         const u8 *addr)
869 {
870         struct qeth_ipaddr *ipaddr;
871
872         ipaddr = qeth_l3_get_addr_buffer(proto);
873         if (ipaddr) {
874                 if (proto == QETH_PROT_IPV4) {
875                         QETH_DBF_TEXT(TRACE, 2, "addrxip4");
876                         memcpy(&ipaddr->u.a4.addr, addr, 4);
877                         ipaddr->u.a4.mask = 0;
878                 } else if (proto == QETH_PROT_IPV6) {
879                         QETH_DBF_TEXT(TRACE, 2, "addrxip6");
880                         memcpy(&ipaddr->u.a6.addr, addr, 16);
881                         ipaddr->u.a6.pfxlen = 0;
882                 }
883                 ipaddr->type = QETH_IP_TYPE_RXIP;
884         } else
885                 return;
886         if (!qeth_l3_delete_ip(card, ipaddr))
887                 kfree(ipaddr);
888         qeth_l3_set_ip_addr_list(card);
889 }
890
891 static int qeth_l3_register_addr_entry(struct qeth_card *card,
892                                 struct qeth_ipaddr *addr)
893 {
894         char buf[50];
895         int rc = 0;
896         int cnt = 3;
897
898         if (addr->proto == QETH_PROT_IPV4) {
899                 QETH_DBF_TEXT(TRACE, 2, "setaddr4");
900                 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
901         } else if (addr->proto == QETH_PROT_IPV6) {
902                 QETH_DBF_TEXT(TRACE, 2, "setaddr6");
903                 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
904                 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
905         } else {
906                 QETH_DBF_TEXT(TRACE, 2, "setaddr?");
907                 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
908         }
909         do {
910                 if (addr->is_multicast)
911                         rc =  qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
912                 else
913                         rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
914                                         addr->set_flags);
915                 if (rc)
916                         QETH_DBF_TEXT(TRACE, 2, "failed");
917         } while ((--cnt > 0) && rc);
918         if (rc) {
919                 QETH_DBF_TEXT(TRACE, 2, "FAILED");
920                 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
921                 dev_warn(&card->gdev->dev,
922                         "Registering IP address %s failed\n", buf);
923         }
924         return rc;
925 }
926
927 static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
928                                                 struct qeth_ipaddr *addr)
929 {
930         int rc = 0;
931
932         if (addr->proto == QETH_PROT_IPV4) {
933                 QETH_DBF_TEXT(TRACE, 2, "deladdr4");
934                 QETH_DBF_HEX(TRACE, 3, &addr->u.a4.addr, sizeof(int));
935         } else if (addr->proto == QETH_PROT_IPV6) {
936                 QETH_DBF_TEXT(TRACE, 2, "deladdr6");
937                 QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8);
938                 QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8);
939         } else {
940                 QETH_DBF_TEXT(TRACE, 2, "deladdr?");
941                 QETH_DBF_HEX(TRACE, 3, addr, sizeof(struct qeth_ipaddr));
942         }
943         if (addr->is_multicast)
944                 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
945         else
946                 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
947                                         addr->del_flags);
948         if (rc)
949                 QETH_DBF_TEXT(TRACE, 2, "failed");
950
951         return rc;
952 }
953
954 static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
955 {
956         if (cast_type == RTN_MULTICAST)
957                 return QETH_CAST_MULTICAST;
958         if (cast_type == RTN_BROADCAST)
959                 return QETH_CAST_BROADCAST;
960         return QETH_CAST_UNICAST;
961 }
962
963 static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
964 {
965         u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
966         if (cast_type == RTN_MULTICAST)
967                 return ct | QETH_CAST_MULTICAST;
968         if (cast_type == RTN_ANYCAST)
969                 return ct | QETH_CAST_ANYCAST;
970         if (cast_type == RTN_BROADCAST)
971                 return ct | QETH_CAST_BROADCAST;
972         return ct | QETH_CAST_UNICAST;
973 }
974
975 static int qeth_l3_send_setadp_mode(struct qeth_card *card, __u32 command,
976                                         __u32 mode)
977 {
978         int rc;
979         struct qeth_cmd_buffer *iob;
980         struct qeth_ipa_cmd *cmd;
981
982         QETH_DBF_TEXT(TRACE, 4, "adpmode");
983
984         iob = qeth_get_adapter_cmd(card, command,
985                                    sizeof(struct qeth_ipacmd_setadpparms));
986         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
987         cmd->data.setadapterparms.data.mode = mode;
988         rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
989                                NULL);
990         return rc;
991 }
992
993 static int qeth_l3_setadapter_hstr(struct qeth_card *card)
994 {
995         int rc;
996
997         QETH_DBF_TEXT(TRACE, 4, "adphstr");
998
999         if (qeth_adp_supported(card, IPA_SETADP_SET_BROADCAST_MODE)) {
1000                 rc = qeth_l3_send_setadp_mode(card,
1001                                         IPA_SETADP_SET_BROADCAST_MODE,
1002                                         card->options.broadcast_mode);
1003                 if (rc)
1004                         QETH_DBF_MESSAGE(2, "couldn't set broadcast mode on "
1005                                    "device %s: x%x\n",
1006                                    CARD_BUS_ID(card), rc);
1007                 rc = qeth_l3_send_setadp_mode(card,
1008                                         IPA_SETADP_ALTER_MAC_ADDRESS,
1009                                         card->options.macaddr_mode);
1010                 if (rc)
1011                         QETH_DBF_MESSAGE(2, "couldn't set macaddr mode on "
1012                                    "device %s: x%x\n", CARD_BUS_ID(card), rc);
1013                 return rc;
1014         }
1015         if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
1016                 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1017                            "to set broadcast mode, using ALLRINGS "
1018                            "on device %s:\n", CARD_BUS_ID(card));
1019         if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
1020                 QETH_DBF_MESSAGE(2, "set adapter parameters not available "
1021                            "to set macaddr mode, using NONCANONICAL "
1022                            "on device %s:\n", CARD_BUS_ID(card));
1023         return 0;
1024 }
1025
1026 static int qeth_l3_setadapter_parms(struct qeth_card *card)
1027 {
1028         int rc;
1029
1030         QETH_DBF_TEXT(SETUP, 2, "setadprm");
1031
1032         if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
1033                 dev_info(&card->gdev->dev,
1034                         "set adapter parameters not supported.\n");
1035                 QETH_DBF_TEXT(SETUP, 2, " notsupp");
1036                 return 0;
1037         }
1038         rc = qeth_query_setadapterparms(card);
1039         if (rc) {
1040                 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1041                         "0x%x\n", dev_name(&card->gdev->dev), rc);
1042                 return rc;
1043         }
1044         if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
1045                 rc = qeth_setadpparms_change_macaddr(card);
1046                 if (rc)
1047                         dev_warn(&card->gdev->dev, "Reading the adapter MAC"
1048                                 " address failed\n");
1049         }
1050
1051         if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
1052             (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
1053                 rc = qeth_l3_setadapter_hstr(card);
1054
1055         return rc;
1056 }
1057
1058 static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
1059                         struct qeth_reply *reply, unsigned long data)
1060 {
1061         struct qeth_ipa_cmd *cmd;
1062
1063         QETH_DBF_TEXT(TRACE, 4, "defadpcb");
1064
1065         cmd = (struct qeth_ipa_cmd *) data;
1066         if (cmd->hdr.return_code == 0) {
1067                 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
1068                 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
1069                         card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1070                 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
1071                         card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1072         }
1073         if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
1074             cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
1075                 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
1076                 QETH_DBF_TEXT_(TRACE, 3, "csum:%d", card->info.csum_mask);
1077         }
1078         return 0;
1079 }
1080
1081 static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
1082         struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
1083         __u16 len, enum qeth_prot_versions prot)
1084 {
1085         struct qeth_cmd_buffer *iob;
1086         struct qeth_ipa_cmd *cmd;
1087
1088         QETH_DBF_TEXT(TRACE, 4, "getasscm");
1089         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
1090
1091         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1092         cmd->data.setassparms.hdr.assist_no = ipa_func;
1093         cmd->data.setassparms.hdr.length = 8 + len;
1094         cmd->data.setassparms.hdr.command_code = cmd_code;
1095         cmd->data.setassparms.hdr.return_code = 0;
1096         cmd->data.setassparms.hdr.seq_no = 0;
1097
1098         return iob;
1099 }
1100
1101 static int qeth_l3_send_setassparms(struct qeth_card *card,
1102         struct qeth_cmd_buffer *iob, __u16 len, long data,
1103         int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1104                 unsigned long),
1105         void *reply_param)
1106 {
1107         int rc;
1108         struct qeth_ipa_cmd *cmd;
1109
1110         QETH_DBF_TEXT(TRACE, 4, "sendassp");
1111
1112         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1113         if (len <= sizeof(__u32))
1114                 cmd->data.setassparms.data.flags_32bit = (__u32) data;
1115         else   /* (len > sizeof(__u32)) */
1116                 memcpy(&cmd->data.setassparms.data, (void *) data, len);
1117
1118         rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
1119         return rc;
1120 }
1121
1122 #ifdef CONFIG_QETH_IPV6
1123 static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
1124                 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
1125 {
1126         int rc;
1127         struct qeth_cmd_buffer *iob;
1128
1129         QETH_DBF_TEXT(TRACE, 4, "simassp6");
1130         iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1131                                        0, QETH_PROT_IPV6);
1132         rc = qeth_l3_send_setassparms(card, iob, 0, 0,
1133                                    qeth_l3_default_setassparms_cb, NULL);
1134         return rc;
1135 }
1136 #endif
1137
1138 static int qeth_l3_send_simple_setassparms(struct qeth_card *card,
1139                 enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data)
1140 {
1141         int rc;
1142         int length = 0;
1143         struct qeth_cmd_buffer *iob;
1144
1145         QETH_DBF_TEXT(TRACE, 4, "simassp4");
1146         if (data)
1147                 length = sizeof(__u32);
1148         iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
1149                                        length, QETH_PROT_IPV4);
1150         rc = qeth_l3_send_setassparms(card, iob, length, data,
1151                                    qeth_l3_default_setassparms_cb, NULL);
1152         return rc;
1153 }
1154
1155 static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
1156 {
1157         int rc;
1158
1159         QETH_DBF_TEXT(TRACE, 3, "ipaarp");
1160
1161         if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
1162                 dev_info(&card->gdev->dev,
1163                         "ARP processing not supported on %s!\n",
1164                         QETH_CARD_IFNAME(card));
1165                 return 0;
1166         }
1167         rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
1168                                         IPA_CMD_ASS_START, 0);
1169         if (rc) {
1170                 dev_warn(&card->gdev->dev,
1171                         "Starting ARP processing support for %s failed\n",
1172                         QETH_CARD_IFNAME(card));
1173         }
1174         return rc;
1175 }
1176
1177 static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
1178 {
1179         int rc;
1180
1181         QETH_DBF_TEXT(TRACE, 3, "ipaipfrg");
1182
1183         if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
1184                 dev_info(&card->gdev->dev,
1185                         "Hardware IP fragmentation not supported on %s\n",
1186                         QETH_CARD_IFNAME(card));
1187                 return  -EOPNOTSUPP;
1188         }
1189
1190         rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
1191                                           IPA_CMD_ASS_START, 0);
1192         if (rc) {
1193                 dev_warn(&card->gdev->dev,
1194                         "Starting IP fragmentation support for %s failed\n",
1195                         QETH_CARD_IFNAME(card));
1196         } else
1197                 dev_info(&card->gdev->dev,
1198                         "Hardware IP fragmentation enabled \n");
1199         return rc;
1200 }
1201
1202 static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1203 {
1204         int rc;
1205
1206         QETH_DBF_TEXT(TRACE, 3, "stsrcmac");
1207
1208         if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
1209                 dev_info(&card->gdev->dev,
1210                         "Inbound source MAC-address not supported on %s\n",
1211                         QETH_CARD_IFNAME(card));
1212                 return -EOPNOTSUPP;
1213         }
1214
1215         rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC,
1216                                           IPA_CMD_ASS_START, 0);
1217         if (rc)
1218                 dev_warn(&card->gdev->dev,
1219                         "Starting source MAC-address support for %s failed\n",
1220                         QETH_CARD_IFNAME(card));
1221         return rc;
1222 }
1223
1224 static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1225 {
1226         int rc = 0;
1227
1228         QETH_DBF_TEXT(TRACE, 3, "strtvlan");
1229
1230         if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
1231                 dev_info(&card->gdev->dev,
1232                         "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
1233                 return -EOPNOTSUPP;
1234         }
1235
1236         rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO,
1237                                           IPA_CMD_ASS_START, 0);
1238         if (rc) {
1239                 dev_warn(&card->gdev->dev,
1240                         "Starting VLAN support for %s failed\n",
1241                         QETH_CARD_IFNAME(card));
1242         } else {
1243                 dev_info(&card->gdev->dev, "VLAN enabled\n");
1244         }
1245         return rc;
1246 }
1247
1248 static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1249 {
1250         int rc;
1251
1252         QETH_DBF_TEXT(TRACE, 3, "stmcast");
1253
1254         if (!qeth_is_supported(card, IPA_MULTICASTING)) {
1255                 dev_info(&card->gdev->dev,
1256                         "Multicast not supported on %s\n",
1257                         QETH_CARD_IFNAME(card));
1258                 return -EOPNOTSUPP;
1259         }
1260
1261         rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING,
1262                                           IPA_CMD_ASS_START, 0);
1263         if (rc) {
1264                 dev_warn(&card->gdev->dev,
1265                         "Starting multicast support for %s failed\n",
1266                         QETH_CARD_IFNAME(card));
1267         } else {
1268                 dev_info(&card->gdev->dev, "Multicast enabled\n");
1269                 card->dev->flags |= IFF_MULTICAST;
1270         }
1271         return rc;
1272 }
1273
1274 static int qeth_l3_query_ipassists_cb(struct qeth_card *card,
1275                 struct qeth_reply *reply, unsigned long data)
1276 {
1277         struct qeth_ipa_cmd *cmd;
1278
1279         QETH_DBF_TEXT(SETUP, 2, "qipasscb");
1280
1281         cmd = (struct qeth_ipa_cmd *) data;
1282         if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
1283                 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
1284                 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
1285         } else {
1286                 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
1287                 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
1288         }
1289         QETH_DBF_TEXT(SETUP, 2, "suppenbl");
1290         QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
1291         QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
1292         return 0;
1293 }
1294
1295 static int qeth_l3_query_ipassists(struct qeth_card *card,
1296                                 enum qeth_prot_versions prot)
1297 {
1298         int rc;
1299         struct qeth_cmd_buffer *iob;
1300
1301         QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
1302         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
1303         rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL);
1304         return rc;
1305 }
1306
1307 #ifdef CONFIG_QETH_IPV6
1308 static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1309 {
1310         int rc;
1311
1312         QETH_DBF_TEXT(TRACE, 3, "softipv6");
1313
1314         if (card->info.type == QETH_CARD_TYPE_IQD)
1315                 goto out;
1316
1317         rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6);
1318         if (rc) {
1319                 dev_err(&card->gdev->dev,
1320                         "Activating IPv6 support for %s failed\n",
1321                         QETH_CARD_IFNAME(card));
1322                 return rc;
1323         }
1324         rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6,
1325                                           IPA_CMD_ASS_START, 3);
1326         if (rc) {
1327                 dev_err(&card->gdev->dev,
1328                         "Activating IPv6 support for %s failed\n",
1329                         QETH_CARD_IFNAME(card));
1330                 return rc;
1331         }
1332         rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1333                                                IPA_CMD_ASS_START);
1334         if (rc) {
1335                 dev_err(&card->gdev->dev,
1336                         "Activating IPv6 support for %s failed\n",
1337                          QETH_CARD_IFNAME(card));
1338                 return rc;
1339         }
1340         rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1341                                                IPA_CMD_ASS_START);
1342         if (rc) {
1343                 dev_warn(&card->gdev->dev,
1344                         "Enabling the passthrough mode for %s failed\n",
1345                         QETH_CARD_IFNAME(card));
1346                 return rc;
1347         }
1348 out:
1349         dev_info(&card->gdev->dev, "IPV6 enabled\n");
1350         return 0;
1351 }
1352 #endif
1353
1354 static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1355 {
1356         int rc = 0;
1357
1358         QETH_DBF_TEXT(TRACE, 3, "strtipv6");
1359
1360         if (!qeth_is_supported(card, IPA_IPV6)) {
1361                 dev_info(&card->gdev->dev,
1362                         "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
1363                 return 0;
1364         }
1365 #ifdef CONFIG_QETH_IPV6
1366         rc = qeth_l3_softsetup_ipv6(card);
1367 #endif
1368         return rc ;
1369 }
1370
1371 static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1372 {
1373         int rc;
1374
1375         QETH_DBF_TEXT(TRACE, 3, "stbrdcst");
1376         card->info.broadcast_capable = 0;
1377         if (!qeth_is_supported(card, IPA_FILTERING)) {
1378                 dev_info(&card->gdev->dev,
1379                         "Broadcast not supported on %s\n",
1380                         QETH_CARD_IFNAME(card));
1381                 rc = -EOPNOTSUPP;
1382                 goto out;
1383         }
1384         rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1385                                           IPA_CMD_ASS_START, 0);
1386         if (rc) {
1387                 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1388                         "%s failed\n", QETH_CARD_IFNAME(card));
1389                 goto out;
1390         }
1391
1392         rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1393                                           IPA_CMD_ASS_CONFIGURE, 1);
1394         if (rc) {
1395                 dev_warn(&card->gdev->dev,
1396                         "Setting up broadcast filtering for %s failed\n",
1397                         QETH_CARD_IFNAME(card));
1398                 goto out;
1399         }
1400         card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
1401         dev_info(&card->gdev->dev, "Broadcast enabled\n");
1402         rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING,
1403                                           IPA_CMD_ASS_ENABLE, 1);
1404         if (rc) {
1405                 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1406                         "filtering for %s failed\n", QETH_CARD_IFNAME(card));
1407                 goto out;
1408         }
1409         card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1410 out:
1411         if (card->info.broadcast_capable)
1412                 card->dev->flags |= IFF_BROADCAST;
1413         else
1414                 card->dev->flags &= ~IFF_BROADCAST;
1415         return rc;
1416 }
1417
1418 static int qeth_l3_send_checksum_command(struct qeth_card *card)
1419 {
1420         int rc;
1421
1422         rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1423                                           IPA_CMD_ASS_START, 0);
1424         if (rc) {
1425                 dev_warn(&card->gdev->dev, "Starting HW checksumming for %s "
1426                         "failed, using SW checksumming\n",
1427                         QETH_CARD_IFNAME(card));
1428                 return rc;
1429         }
1430         rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
1431                                           IPA_CMD_ASS_ENABLE,
1432                                           card->info.csum_mask);
1433         if (rc) {
1434                 dev_warn(&card->gdev->dev, "Enabling HW checksumming for %s "
1435                         "failed, using SW checksumming\n",
1436                         QETH_CARD_IFNAME(card));
1437                 return rc;
1438         }
1439         return 0;
1440 }
1441
1442 static int qeth_l3_start_ipa_checksum(struct qeth_card *card)
1443 {
1444         int rc = 0;
1445
1446         QETH_DBF_TEXT(TRACE, 3, "strtcsum");
1447
1448         if (card->options.checksum_type == NO_CHECKSUMMING) {
1449                 dev_info(&card->gdev->dev,
1450                         "Using no checksumming on %s.\n",
1451                         QETH_CARD_IFNAME(card));
1452                 return 0;
1453         }
1454         if (card->options.checksum_type == SW_CHECKSUMMING) {
1455                 dev_info(&card->gdev->dev,
1456                         "Using SW checksumming on %s.\n",
1457                         QETH_CARD_IFNAME(card));
1458                 return 0;
1459         }
1460         if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
1461                 dev_info(&card->gdev->dev,
1462                         "Inbound HW Checksumming not "
1463                         "supported on %s,\ncontinuing "
1464                         "using Inbound SW Checksumming\n",
1465                         QETH_CARD_IFNAME(card));
1466                 card->options.checksum_type = SW_CHECKSUMMING;
1467                 return 0;
1468         }
1469         rc = qeth_l3_send_checksum_command(card);
1470         if (!rc)
1471                 dev_info(&card->gdev->dev,
1472                         "HW Checksumming (inbound) enabled\n");
1473
1474         return rc;
1475 }
1476
1477 static int qeth_l3_start_ipa_tso(struct qeth_card *card)
1478 {
1479         int rc;
1480
1481         QETH_DBF_TEXT(TRACE, 3, "sttso");
1482
1483         if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
1484                 dev_info(&card->gdev->dev,
1485                         "Outbound TSO not supported on %s\n",
1486                         QETH_CARD_IFNAME(card));
1487                 rc = -EOPNOTSUPP;
1488         } else {
1489                 rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
1490                                                 IPA_CMD_ASS_START, 0);
1491                 if (rc)
1492                         dev_warn(&card->gdev->dev, "Starting outbound TCP "
1493                                 "segmentation offload for %s failed\n",
1494                                 QETH_CARD_IFNAME(card));
1495                 else
1496                         dev_info(&card->gdev->dev,
1497                                 "Outbound TSO enabled\n");
1498         }
1499         if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) {
1500                 card->options.large_send = QETH_LARGE_SEND_NO;
1501                 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
1502         }
1503         return rc;
1504 }
1505
1506 static int qeth_l3_start_ipassists(struct qeth_card *card)
1507 {
1508         QETH_DBF_TEXT(TRACE, 3, "strtipas");
1509
1510         qeth_set_access_ctrl_online(card);      /* go on*/
1511         qeth_l3_start_ipa_arp_processing(card); /* go on*/
1512         qeth_l3_start_ipa_ip_fragmentation(card);       /* go on*/
1513         qeth_l3_start_ipa_source_mac(card);     /* go on*/
1514         qeth_l3_start_ipa_vlan(card);           /* go on*/
1515         qeth_l3_start_ipa_multicast(card);              /* go on*/
1516         qeth_l3_start_ipa_ipv6(card);           /* go on*/
1517         qeth_l3_start_ipa_broadcast(card);              /* go on*/
1518         qeth_l3_start_ipa_checksum(card);               /* go on*/
1519         qeth_l3_start_ipa_tso(card);            /* go on*/
1520         return 0;
1521 }
1522
1523 static int qeth_l3_put_unique_id(struct qeth_card *card)
1524 {
1525
1526         int rc = 0;
1527         struct qeth_cmd_buffer *iob;
1528         struct qeth_ipa_cmd *cmd;
1529
1530         QETH_DBF_TEXT(TRACE, 2, "puniqeid");
1531
1532         if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
1533                 UNIQUE_ID_NOT_BY_CARD)
1534                 return -1;
1535         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
1536                                      QETH_PROT_IPV6);
1537         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1538         *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1539                                 card->info.unique_id;
1540         memcpy(&cmd->data.create_destroy_addr.unique_id[0],
1541                card->dev->dev_addr, OSA_ADDR_LEN);
1542         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
1543         return rc;
1544 }
1545
1546 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1547                 struct qeth_reply *reply, unsigned long data)
1548 {
1549         struct qeth_ipa_cmd *cmd;
1550
1551         cmd = (struct qeth_ipa_cmd *) data;
1552         if (cmd->hdr.return_code == 0)
1553                 memcpy(card->dev->dev_addr,
1554                         cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1555         else
1556                 random_ether_addr(card->dev->dev_addr);
1557
1558         return 0;
1559 }
1560
1561 static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1562 {
1563         int rc = 0;
1564         struct qeth_cmd_buffer *iob;
1565         struct qeth_ipa_cmd *cmd;
1566
1567         QETH_DBF_TEXT(SETUP, 2, "hsrmac");
1568
1569         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1570                                      QETH_PROT_IPV6);
1571         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1572         *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1573                         card->info.unique_id;
1574
1575         rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1576                                 NULL);
1577         return rc;
1578 }
1579
1580 static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1581                 struct qeth_reply *reply, unsigned long data)
1582 {
1583         struct qeth_ipa_cmd *cmd;
1584
1585         cmd = (struct qeth_ipa_cmd *) data;
1586         if (cmd->hdr.return_code == 0)
1587                 card->info.unique_id = *((__u16 *)
1588                                 &cmd->data.create_destroy_addr.unique_id[6]);
1589         else {
1590                 card->info.unique_id =  UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1591                                         UNIQUE_ID_NOT_BY_CARD;
1592                 dev_warn(&card->gdev->dev, "The network adapter failed to "
1593                         "generate a unique ID\n");
1594         }
1595         return 0;
1596 }
1597
1598 static int qeth_l3_get_unique_id(struct qeth_card *card)
1599 {
1600         int rc = 0;
1601         struct qeth_cmd_buffer *iob;
1602         struct qeth_ipa_cmd *cmd;
1603
1604         QETH_DBF_TEXT(SETUP, 2, "guniqeid");
1605
1606         if (!qeth_is_supported(card, IPA_IPV6)) {
1607                 card->info.unique_id =  UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1608                                         UNIQUE_ID_NOT_BY_CARD;
1609                 return 0;
1610         }
1611
1612         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1613                                      QETH_PROT_IPV6);
1614         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1615         *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1616                         card->info.unique_id;
1617
1618         rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1619         return rc;
1620 }
1621
1622 static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
1623                                 struct net_device *dev)
1624 {
1625         if (dev->type == ARPHRD_IEEE802_TR)
1626                 ip_tr_mc_map(ipm, mac);
1627         else
1628                 ip_eth_mc_map(ipm, mac);
1629 }
1630
1631 static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
1632 {
1633         struct qeth_ipaddr *ipm;
1634         struct ip_mc_list *im4;
1635         char buf[MAX_ADDR_LEN];
1636
1637         QETH_DBF_TEXT(TRACE, 4, "addmc");
1638         for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
1639                 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
1640                 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1641                 if (!ipm)
1642                         continue;
1643                 ipm->u.a4.addr = im4->multiaddr;
1644                 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1645                 ipm->is_multicast = 1;
1646                 if (!qeth_l3_add_ip(card, ipm))
1647                         kfree(ipm);
1648         }
1649 }
1650
1651 static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1652 {
1653         struct in_device *in_dev;
1654         struct vlan_group *vg;
1655         int i;
1656
1657         QETH_DBF_TEXT(TRACE, 4, "addmcvl");
1658         if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1659                 return;
1660
1661         vg = card->vlangrp;
1662         for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1663                 struct net_device *netdev = vlan_group_get_device(vg, i);
1664                 if (netdev == NULL ||
1665                     !(netdev->flags & IFF_UP))
1666                         continue;
1667                 in_dev = in_dev_get(netdev);
1668                 if (!in_dev)
1669                         continue;
1670                 read_lock(&in_dev->mc_list_lock);
1671                 qeth_l3_add_mc(card, in_dev);
1672                 read_unlock(&in_dev->mc_list_lock);
1673                 in_dev_put(in_dev);
1674         }
1675 }
1676
1677 static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1678 {
1679         struct in_device *in4_dev;
1680
1681         QETH_DBF_TEXT(TRACE, 4, "chkmcv4");
1682         in4_dev = in_dev_get(card->dev);
1683         if (in4_dev == NULL)
1684                 return;
1685         read_lock(&in4_dev->mc_list_lock);
1686         qeth_l3_add_mc(card, in4_dev);
1687         qeth_l3_add_vlan_mc(card);
1688         read_unlock(&in4_dev->mc_list_lock);
1689         in_dev_put(in4_dev);
1690 }
1691
1692 #ifdef CONFIG_QETH_IPV6
1693 static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
1694 {
1695         struct qeth_ipaddr *ipm;
1696         struct ifmcaddr6 *im6;
1697         char buf[MAX_ADDR_LEN];
1698
1699         QETH_DBF_TEXT(TRACE, 4, "addmc6");
1700         for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1701                 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
1702                 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1703                 if (!ipm)
1704                         continue;
1705                 ipm->is_multicast = 1;
1706                 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1707                 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1708                        sizeof(struct in6_addr));
1709                 if (!qeth_l3_add_ip(card, ipm))
1710                         kfree(ipm);
1711         }
1712 }
1713
1714 static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1715 {
1716         struct inet6_dev *in_dev;
1717         struct vlan_group *vg;
1718         int i;
1719
1720         QETH_DBF_TEXT(TRACE, 4, "admc6vl");
1721         if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL))
1722                 return;
1723
1724         vg = card->vlangrp;
1725         for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
1726                 struct net_device *netdev = vlan_group_get_device(vg, i);
1727                 if (netdev == NULL ||
1728                     !(netdev->flags & IFF_UP))
1729                         continue;
1730                 in_dev = in6_dev_get(netdev);
1731                 if (!in_dev)
1732                         continue;
1733                 read_lock_bh(&in_dev->lock);
1734                 qeth_l3_add_mc6(card, in_dev);
1735                 read_unlock_bh(&in_dev->lock);
1736                 in6_dev_put(in_dev);
1737         }
1738 }
1739
1740 static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1741 {
1742         struct inet6_dev *in6_dev;
1743
1744         QETH_DBF_TEXT(TRACE, 4, "chkmcv6");
1745         if (!qeth_is_supported(card, IPA_IPV6))
1746                 return ;
1747         in6_dev = in6_dev_get(card->dev);
1748         if (in6_dev == NULL)
1749                 return;
1750         read_lock_bh(&in6_dev->lock);
1751         qeth_l3_add_mc6(card, in6_dev);
1752         qeth_l3_add_vlan_mc6(card);
1753         read_unlock_bh(&in6_dev->lock);
1754         in6_dev_put(in6_dev);
1755 }
1756 #endif /* CONFIG_QETH_IPV6 */
1757
1758 static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1759                         unsigned short vid)
1760 {
1761         struct in_device *in_dev;
1762         struct in_ifaddr *ifa;
1763         struct qeth_ipaddr *addr;
1764
1765         QETH_DBF_TEXT(TRACE, 4, "frvaddr4");
1766
1767         in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid));
1768         if (!in_dev)
1769                 return;
1770         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1771                 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1772                 if (addr) {
1773                         addr->u.a4.addr = ifa->ifa_address;
1774                         addr->u.a4.mask = ifa->ifa_mask;
1775                         addr->type = QETH_IP_TYPE_NORMAL;
1776                         if (!qeth_l3_delete_ip(card, addr))
1777                                 kfree(addr);
1778                 }
1779         }
1780         in_dev_put(in_dev);
1781 }
1782
1783 static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1784                         unsigned short vid)
1785 {
1786 #ifdef CONFIG_QETH_IPV6
1787         struct inet6_dev *in6_dev;
1788         struct inet6_ifaddr *ifa;
1789         struct qeth_ipaddr *addr;
1790
1791         QETH_DBF_TEXT(TRACE, 4, "frvaddr6");
1792
1793         in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
1794         if (!in6_dev)
1795                 return;
1796         for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) {
1797                 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1798                 if (addr) {
1799                         memcpy(&addr->u.a6.addr, &ifa->addr,
1800                                sizeof(struct in6_addr));
1801                         addr->u.a6.pfxlen = ifa->prefix_len;
1802                         addr->type = QETH_IP_TYPE_NORMAL;
1803                         if (!qeth_l3_delete_ip(card, addr))
1804                                 kfree(addr);
1805                 }
1806         }
1807         in6_dev_put(in6_dev);
1808 #endif /* CONFIG_QETH_IPV6 */
1809 }
1810
1811 static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1812                         unsigned short vid)
1813 {
1814         if (!card->vlangrp)
1815                 return;
1816         qeth_l3_free_vlan_addresses4(card, vid);
1817         qeth_l3_free_vlan_addresses6(card, vid);
1818 }
1819
1820 static void qeth_l3_vlan_rx_register(struct net_device *dev,
1821                         struct vlan_group *grp)
1822 {
1823         struct qeth_card *card = dev->ml_priv;
1824         unsigned long flags;
1825
1826         QETH_DBF_TEXT(TRACE, 4, "vlanreg");
1827         spin_lock_irqsave(&card->vlanlock, flags);
1828         card->vlangrp = grp;
1829         spin_unlock_irqrestore(&card->vlanlock, flags);
1830 }
1831
1832 static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1833 {
1834         return;
1835 }
1836
1837 static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1838 {
1839         struct qeth_card *card = dev->ml_priv;
1840         unsigned long flags;
1841
1842         QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
1843         if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
1844                 QETH_DBF_TEXT(TRACE, 3, "kidREC");
1845                 return;
1846         }
1847         spin_lock_irqsave(&card->vlanlock, flags);
1848         /* unregister IP addresses of vlan device */
1849         qeth_l3_free_vlan_addresses(card, vid);
1850         vlan_group_set_device(card->vlangrp, vid, NULL);
1851         spin_unlock_irqrestore(&card->vlanlock, flags);
1852         qeth_l3_set_multicast_list(card->dev);
1853 }
1854
1855 static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card,
1856                         struct sk_buff *skb, struct qeth_hdr *hdr)
1857 {
1858         unsigned short vlan_id = 0;
1859         __be16 prot;
1860         struct iphdr *ip_hdr;
1861         unsigned char tg_addr[MAX_ADDR_LEN];
1862
1863         if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1864                 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1865                               ETH_P_IP);
1866                 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1867                 case QETH_CAST_MULTICAST:
1868                         switch (prot) {
1869 #ifdef CONFIG_QETH_IPV6
1870                         case __constant_htons(ETH_P_IPV6):
1871                                 ndisc_mc_map((struct in6_addr *)
1872                                      skb->data + 24,
1873                                      tg_addr, card->dev, 0);
1874                                 break;
1875 #endif
1876                         case __constant_htons(ETH_P_IP):
1877                                 ip_hdr = (struct iphdr *)skb->data;
1878                                 (card->dev->type == ARPHRD_IEEE802_TR) ?
1879                                 ip_tr_mc_map(ip_hdr->daddr, tg_addr):
1880                                 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1881                                 break;
1882                         default:
1883                                 memcpy(tg_addr, card->dev->broadcast,
1884                                         card->dev->addr_len);
1885                         }
1886                         card->stats.multicast++;
1887                         skb->pkt_type = PACKET_MULTICAST;
1888                         break;
1889                 case QETH_CAST_BROADCAST:
1890                         memcpy(tg_addr, card->dev->broadcast,
1891                                 card->dev->addr_len);
1892                         card->stats.multicast++;
1893                         skb->pkt_type = PACKET_BROADCAST;
1894                         break;
1895                 case QETH_CAST_UNICAST:
1896                 case QETH_CAST_ANYCAST:
1897                 case QETH_CAST_NOCAST:
1898                 default:
1899                         skb->pkt_type = PACKET_HOST;
1900                         memcpy(tg_addr, card->dev->dev_addr,
1901                                 card->dev->addr_len);
1902                 }
1903                 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1904                         card->dev->header_ops->create(skb, card->dev, prot,
1905                                 tg_addr, &hdr->hdr.l3.dest_addr[2],
1906                                 card->dev->addr_len);
1907                 else
1908                         card->dev->header_ops->create(skb, card->dev, prot,
1909                                 tg_addr, "FAKELL", card->dev->addr_len);
1910         }
1911
1912 #ifdef CONFIG_TR
1913         if (card->dev->type == ARPHRD_IEEE802_TR)
1914                 skb->protocol = tr_type_trans(skb, card->dev);
1915         else
1916 #endif
1917                 skb->protocol = eth_type_trans(skb, card->dev);
1918
1919         if (hdr->hdr.l3.ext_flags &
1920             (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
1921                 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
1922                  hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
1923         }
1924
1925         switch (card->options.checksum_type) {
1926         case SW_CHECKSUMMING:
1927                 skb->ip_summed = CHECKSUM_NONE;
1928                 break;
1929         case NO_CHECKSUMMING:
1930                 skb->ip_summed = CHECKSUM_UNNECESSARY;
1931                 break;
1932         case HW_CHECKSUMMING:
1933                 if ((hdr->hdr.l3.ext_flags &
1934                     (QETH_HDR_EXT_CSUM_HDR_REQ |
1935                      QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1936                     (QETH_HDR_EXT_CSUM_HDR_REQ |
1937                      QETH_HDR_EXT_CSUM_TRANSP_REQ))
1938                         skb->ip_summed = CHECKSUM_UNNECESSARY;
1939                 else
1940                         skb->ip_summed = CHECKSUM_NONE;
1941         }
1942
1943         return vlan_id;
1944 }
1945
1946 static void qeth_l3_process_inbound_buffer(struct qeth_card *card,
1947                             struct qeth_qdio_buffer *buf, int index)
1948 {
1949         struct qdio_buffer_element *element;
1950         struct sk_buff *skb;
1951         struct qeth_hdr *hdr;
1952         int offset;
1953         __u16 vlan_tag = 0;
1954         unsigned int len;
1955
1956         /* get first element of current buffer */
1957         element = (struct qdio_buffer_element *)&buf->buffer->element[0];
1958         offset = 0;
1959         if (card->options.performance_stats)
1960                 card->perf_stats.bufs_rec++;
1961         while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
1962                                        &offset, &hdr))) {
1963                 skb->dev = card->dev;
1964                 /* is device UP ? */
1965                 if (!(card->dev->flags & IFF_UP)) {
1966                         dev_kfree_skb_any(skb);
1967                         continue;
1968                 }
1969
1970                 switch (hdr->hdr.l3.id) {
1971                 case QETH_HEADER_TYPE_LAYER3:
1972                         vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr);
1973                         len = skb->len;
1974                         if (vlan_tag)
1975                                 if (card->vlangrp)
1976                                         vlan_hwaccel_rx(skb, card->vlangrp,
1977                                                 vlan_tag);
1978                                 else {
1979                                         dev_kfree_skb_any(skb);
1980                                         continue;
1981                                 }
1982                         else
1983                                 netif_rx(skb);
1984                         break;
1985                 default:
1986                         dev_kfree_skb_any(skb);
1987                         QETH_DBF_TEXT(TRACE, 3, "inbunkno");
1988                         QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
1989                         continue;
1990                 }
1991
1992                 card->stats.rx_packets++;
1993                 card->stats.rx_bytes += len;
1994         }
1995 }
1996
1997 static int qeth_l3_verify_vlan_dev(struct net_device *dev,
1998                         struct qeth_card *card)
1999 {
2000         int rc = 0;
2001         struct vlan_group *vg;
2002         int i;
2003
2004         vg = card->vlangrp;
2005         if (!vg)
2006                 return rc;
2007
2008         for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
2009                 if (vlan_group_get_device(vg, i) == dev) {
2010                         rc = QETH_VLAN_CARD;
2011                         break;
2012                 }
2013         }
2014
2015         if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
2016                 return 0;
2017
2018         return rc;
2019 }
2020
2021 static int qeth_l3_verify_dev(struct net_device *dev)
2022 {
2023         struct qeth_card *card;
2024         unsigned long flags;
2025         int rc = 0;
2026
2027         read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
2028         list_for_each_entry(card, &qeth_core_card_list.list, list) {
2029                 if (card->dev == dev) {
2030                         rc = QETH_REAL_CARD;
2031                         break;
2032                 }
2033                 rc = qeth_l3_verify_vlan_dev(dev, card);
2034                 if (rc)
2035                         break;
2036         }
2037         read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
2038
2039         return rc;
2040 }
2041
2042 static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2043 {
2044         struct qeth_card *card = NULL;
2045         int rc;
2046
2047         rc = qeth_l3_verify_dev(dev);
2048         if (rc == QETH_REAL_CARD)
2049                 card = dev->ml_priv;
2050         else if (rc == QETH_VLAN_CARD)
2051                 card = vlan_dev_real_dev(dev)->ml_priv;
2052         if (card && card->options.layer2)
2053                 card = NULL;
2054         QETH_DBF_TEXT_(TRACE, 4, "%d", rc);
2055         return card ;
2056 }
2057
2058 static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2059 {
2060         int rc = 0;
2061
2062         QETH_DBF_TEXT(SETUP, 2, "stopcard");
2063         QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
2064
2065         qeth_set_allowed_threads(card, 0, 1);
2066         if (card->read.state == CH_STATE_UP &&
2067             card->write.state == CH_STATE_UP &&
2068             (card->state == CARD_STATE_UP)) {
2069                 if (recovery_mode)
2070                         qeth_l3_stop(card->dev);
2071                 else {
2072                         if (card->dev) {
2073                                 rtnl_lock();
2074                                 dev_close(card->dev);
2075                                 rtnl_unlock();
2076                         }
2077                 }
2078                 if (!card->use_hard_stop) {
2079                         rc = qeth_send_stoplan(card);
2080                         if (rc)
2081                                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2082                 }
2083                 card->state = CARD_STATE_SOFTSETUP;
2084         }
2085         if (card->state == CARD_STATE_SOFTSETUP) {
2086                 qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1);
2087                 qeth_clear_ipacmd_list(card);
2088                 card->state = CARD_STATE_HARDSETUP;
2089         }
2090         if (card->state == CARD_STATE_HARDSETUP) {
2091                 if (!card->use_hard_stop &&
2092                     (card->info.type != QETH_CARD_TYPE_IQD)) {
2093                         rc = qeth_l3_put_unique_id(card);
2094                         if (rc)
2095                                 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
2096                 }
2097                 qeth_qdio_clear_card(card, 0);
2098                 qeth_clear_qdio_buffers(card);
2099                 qeth_clear_working_pool_list(card);
2100                 card->state = CARD_STATE_DOWN;
2101         }
2102         if (card->state == CARD_STATE_DOWN) {
2103                 qeth_clear_cmd_buffers(&card->read);
2104                 qeth_clear_cmd_buffers(&card->write);
2105         }
2106         card->use_hard_stop = 0;
2107         return rc;
2108 }
2109
2110 static void qeth_l3_set_multicast_list(struct net_device *dev)
2111 {
2112         struct qeth_card *card = dev->ml_priv;
2113
2114         QETH_DBF_TEXT(TRACE, 3, "setmulti");
2115         if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2116             (card->state != CARD_STATE_UP))
2117                 return;
2118         qeth_l3_delete_mc_addresses(card);
2119         qeth_l3_add_multicast_ipv4(card);
2120 #ifdef CONFIG_QETH_IPV6
2121         qeth_l3_add_multicast_ipv6(card);
2122 #endif
2123         qeth_l3_set_ip_addr_list(card);
2124         if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2125                 return;
2126         qeth_setadp_promisc_mode(card);
2127 }
2128
2129 static const char *qeth_l3_arp_get_error_cause(int *rc)
2130 {
2131         switch (*rc) {
2132         case QETH_IPA_ARP_RC_FAILED:
2133                 *rc = -EIO;
2134                 return "operation failed";
2135         case QETH_IPA_ARP_RC_NOTSUPP:
2136                 *rc = -EOPNOTSUPP;
2137                 return "operation not supported";
2138         case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2139                 *rc = -EINVAL;
2140                 return "argument out of range";
2141         case QETH_IPA_ARP_RC_Q_NOTSUPP:
2142                 *rc = -EOPNOTSUPP;
2143                 return "query operation not supported";
2144         case QETH_IPA_ARP_RC_Q_NO_DATA:
2145                 *rc = -ENOENT;
2146                 return "no query data available";
2147         default:
2148                 return "unknown error";
2149         }
2150 }
2151
2152 static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2153 {
2154         int tmp;
2155         int rc;
2156
2157         QETH_DBF_TEXT(TRACE, 3, "arpstnoe");
2158
2159         /*
2160          * currently GuestLAN only supports the ARP assist function
2161          * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2162          * thus we say EOPNOTSUPP for this ARP function
2163          */
2164         if (card->info.guestlan)
2165                 return -EOPNOTSUPP;
2166         if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2167                 return -EOPNOTSUPP;
2168         }
2169         rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2170                                           IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2171                                           no_entries);
2172         if (rc) {
2173                 tmp = rc;
2174                 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2175                         "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
2176                         qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2177         }
2178         return rc;
2179 }
2180
2181 static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
2182                 struct qeth_arp_query_data *qdata, int entry_size,
2183                 int uentry_size)
2184 {
2185         char *entry_ptr;
2186         char *uentry_ptr;
2187         int i;
2188
2189         entry_ptr = (char *)&qdata->data;
2190         uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
2191         for (i = 0; i < qdata->no_entries; ++i) {
2192                 /* strip off 32 bytes "media specific information" */
2193                 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
2194                 entry_ptr += entry_size;
2195                 uentry_ptr += uentry_size;
2196         }
2197 }
2198
2199 static int qeth_l3_arp_query_cb(struct qeth_card *card,
2200                 struct qeth_reply *reply, unsigned long data)
2201 {
2202         struct qeth_ipa_cmd *cmd;
2203         struct qeth_arp_query_data *qdata;
2204         struct qeth_arp_query_info *qinfo;
2205         int entry_size;
2206         int uentry_size;
2207         int i;
2208
2209         QETH_DBF_TEXT(TRACE, 4, "arpquecb");
2210
2211         qinfo = (struct qeth_arp_query_info *) reply->param;
2212         cmd = (struct qeth_ipa_cmd *) data;
2213         if (cmd->hdr.return_code) {
2214                 QETH_DBF_TEXT_(TRACE, 4, "qaer1%i", cmd->hdr.return_code);
2215                 return 0;
2216         }
2217         if (cmd->data.setassparms.hdr.return_code) {
2218                 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
2219                 QETH_DBF_TEXT_(TRACE, 4, "qaer2%i", cmd->hdr.return_code);
2220                 return 0;
2221         }
2222         qdata = &cmd->data.setassparms.data.query_arp;
2223         switch (qdata->reply_bits) {
2224         case 5:
2225                 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
2226                 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2227                         uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
2228                 break;
2229         case 7:
2230                 /* fall through to default */
2231         default:
2232                 /* tr is the same as eth -> entry7 */
2233                 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
2234                 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2235                         uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
2236                 break;
2237         }
2238         /* check if there is enough room in userspace */
2239         if ((qinfo->udata_len - qinfo->udata_offset) <
2240                         qdata->no_entries * uentry_size){
2241                 QETH_DBF_TEXT_(TRACE, 4, "qaer3%i", -ENOMEM);
2242                 cmd->hdr.return_code = -ENOMEM;
2243                 goto out_error;
2244         }
2245         QETH_DBF_TEXT_(TRACE, 4, "anore%i",
2246                        cmd->data.setassparms.hdr.number_of_replies);
2247         QETH_DBF_TEXT_(TRACE, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
2248         QETH_DBF_TEXT_(TRACE, 4, "anoen%i", qdata->no_entries);
2249
2250         if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
2251                 /* strip off "media specific information" */
2252                 qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size,
2253                                                uentry_size);
2254         } else
2255                 /*copy entries to user buffer*/
2256                 memcpy(qinfo->udata + qinfo->udata_offset,
2257                        (char *)&qdata->data, qdata->no_entries*uentry_size);
2258
2259         qinfo->no_entries += qdata->no_entries;
2260         qinfo->udata_offset += (qdata->no_entries*uentry_size);
2261         /* check if all replies received ... */
2262         if (cmd->data.setassparms.hdr.seq_no <
2263             cmd->data.setassparms.hdr.number_of_replies)
2264                 return 1;
2265         memcpy(qinfo->udata, &qinfo->no_entries, 4);
2266         /* keep STRIP_ENTRIES flag so the user program can distinguish
2267          * stripped entries from normal ones */
2268         if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2269                 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2270         memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
2271         return 0;
2272 out_error:
2273         i = 0;
2274         memcpy(qinfo->udata, &i, 4);
2275         return 0;
2276 }
2277
2278 static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2279                 struct qeth_cmd_buffer *iob, int len,
2280                 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2281                         unsigned long),
2282                 void *reply_param)
2283 {
2284         QETH_DBF_TEXT(TRACE, 4, "sendarp");
2285
2286         memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2287         memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2288                &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2289         return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2290                                       reply_cb, reply_param);
2291 }
2292
2293 static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2294 {
2295         struct qeth_cmd_buffer *iob;
2296         struct qeth_arp_query_info qinfo = {0, };
2297         int tmp;
2298         int rc;
2299
2300         QETH_DBF_TEXT(TRACE, 3, "arpquery");
2301
2302         if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2303                                IPA_ARP_PROCESSING)) {
2304                 return -EOPNOTSUPP;
2305         }
2306         /* get size of userspace buffer and mask_bits -> 6 bytes */
2307         if (copy_from_user(&qinfo, udata, 6))
2308                 return -EFAULT;
2309         qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
2310         if (!qinfo.udata)
2311                 return -ENOMEM;
2312         qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
2313         iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2314                                        IPA_CMD_ASS_ARP_QUERY_INFO,
2315                                        sizeof(int), QETH_PROT_IPV4);
2316
2317         rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2318                                    QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2319                                    qeth_l3_arp_query_cb, (void *)&qinfo);
2320         if (rc) {
2321                 tmp = rc;
2322                 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s "
2323                         "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2324                         qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2325                 if (copy_to_user(udata, qinfo.udata, 4))
2326                         rc = -EFAULT;
2327         } else {
2328                 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
2329                         rc = -EFAULT;
2330         }
2331         kfree(qinfo.udata);
2332         return rc;
2333 }
2334
2335 static int qeth_l3_arp_add_entry(struct qeth_card *card,
2336                                 struct qeth_arp_cache_entry *entry)
2337 {
2338         struct qeth_cmd_buffer *iob;
2339         char buf[16];
2340         int tmp;
2341         int rc;
2342
2343         QETH_DBF_TEXT(TRACE, 3, "arpadent");
2344
2345         /*
2346          * currently GuestLAN only supports the ARP assist function
2347          * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2348          * thus we say EOPNOTSUPP for this ARP function
2349          */
2350         if (card->info.guestlan)
2351                 return -EOPNOTSUPP;
2352         if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2353                 return -EOPNOTSUPP;
2354         }
2355
2356         iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2357                                        IPA_CMD_ASS_ARP_ADD_ENTRY,
2358                                        sizeof(struct qeth_arp_cache_entry),
2359                                        QETH_PROT_IPV4);
2360         rc = qeth_l3_send_setassparms(card, iob,
2361                                    sizeof(struct qeth_arp_cache_entry),
2362                                    (unsigned long) entry,
2363                                    qeth_l3_default_setassparms_cb, NULL);
2364         if (rc) {
2365                 tmp = rc;
2366                 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2367                 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2368                         "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2369                         qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2370         }
2371         return rc;
2372 }
2373
2374 static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2375                                 struct qeth_arp_cache_entry *entry)
2376 {
2377         struct qeth_cmd_buffer *iob;
2378         char buf[16] = {0, };
2379         int tmp;
2380         int rc;
2381
2382         QETH_DBF_TEXT(TRACE, 3, "arprment");
2383
2384         /*
2385          * currently GuestLAN only supports the ARP assist function
2386          * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2387          * thus we say EOPNOTSUPP for this ARP function
2388          */
2389         if (card->info.guestlan)
2390                 return -EOPNOTSUPP;
2391         if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2392                 return -EOPNOTSUPP;
2393         }
2394         memcpy(buf, entry, 12);
2395         iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2396                                        IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2397                                        12,
2398                                        QETH_PROT_IPV4);
2399         rc = qeth_l3_send_setassparms(card, iob,
2400                                    12, (unsigned long)buf,
2401                                    qeth_l3_default_setassparms_cb, NULL);
2402         if (rc) {
2403                 tmp = rc;
2404                 memset(buf, 0, 16);
2405                 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
2406                 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2407                         " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2408                         qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2409         }
2410         return rc;
2411 }
2412
2413 static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2414 {
2415         int rc;
2416         int tmp;
2417
2418         QETH_DBF_TEXT(TRACE, 3, "arpflush");
2419
2420         /*
2421          * currently GuestLAN only supports the ARP assist function
2422          * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2423          * thus we say EOPNOTSUPP for this ARP function
2424         */
2425         if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2426                 return -EOPNOTSUPP;
2427         if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
2428                 return -EOPNOTSUPP;
2429         }
2430         rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING,
2431                                           IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2432         if (rc) {
2433                 tmp = rc;
2434                 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2435                         "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2436                         qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2437         }
2438         return rc;
2439 }
2440
2441 static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2442 {
2443         struct qeth_card *card = dev->ml_priv;
2444         struct qeth_arp_cache_entry arp_entry;
2445         struct mii_ioctl_data *mii_data;
2446         int rc = 0;
2447
2448         if (!card)
2449                 return -ENODEV;
2450
2451         if ((card->state != CARD_STATE_UP) &&
2452                 (card->state != CARD_STATE_SOFTSETUP))
2453                 return -ENODEV;
2454
2455         switch (cmd) {
2456         case SIOC_QETH_ARP_SET_NO_ENTRIES:
2457                 if (!capable(CAP_NET_ADMIN)) {
2458                         rc = -EPERM;
2459                         break;
2460                 }
2461                 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2462                 break;
2463         case SIOC_QETH_ARP_QUERY_INFO:
2464                 if (!capable(CAP_NET_ADMIN)) {
2465                         rc = -EPERM;
2466                         break;
2467                 }
2468                 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2469                 break;
2470         case SIOC_QETH_ARP_ADD_ENTRY:
2471                 if (!capable(CAP_NET_ADMIN)) {
2472                         rc = -EPERM;
2473                         break;
2474                 }
2475                 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2476                                    sizeof(struct qeth_arp_cache_entry)))
2477                         rc = -EFAULT;
2478                 else
2479                         rc = qeth_l3_arp_add_entry(card, &arp_entry);
2480                 break;
2481         case SIOC_QETH_ARP_REMOVE_ENTRY:
2482                 if (!capable(CAP_NET_ADMIN)) {
2483                         rc = -EPERM;
2484                         break;
2485                 }
2486                 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2487                                    sizeof(struct qeth_arp_cache_entry)))
2488                         rc = -EFAULT;
2489                 else
2490                         rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2491                 break;
2492         case SIOC_QETH_ARP_FLUSH_CACHE:
2493                 if (!capable(CAP_NET_ADMIN)) {
2494                         rc = -EPERM;
2495                         break;
2496                 }
2497                 rc = qeth_l3_arp_flush_cache(card);
2498                 break;
2499         case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2500                 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2501                 break;
2502         case SIOC_QETH_GET_CARD_TYPE:
2503                 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
2504                     !card->info.guestlan)
2505                         return 1;
2506                 return 0;
2507                 break;
2508         case SIOCGMIIPHY:
2509                 mii_data = if_mii(rq);
2510                 mii_data->phy_id = 0;
2511                 break;
2512         case SIOCGMIIREG:
2513                 mii_data = if_mii(rq);
2514                 if (mii_data->phy_id != 0)
2515                         rc = -EINVAL;
2516                 else
2517                         mii_data->val_out = qeth_mdio_read(dev,
2518                                                         mii_data->phy_id,
2519                                                         mii_data->reg_num);
2520                 break;
2521         default:
2522                 rc = -EOPNOTSUPP;
2523         }
2524         if (rc)
2525                 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
2526         return rc;
2527 }
2528
2529 int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2530 {
2531         int cast_type = RTN_UNSPEC;
2532
2533         if (skb_dst(skb) && skb_dst(skb)->neighbour) {
2534                 cast_type = skb_dst(skb)->neighbour->type;
2535                 if ((cast_type == RTN_BROADCAST) ||
2536                     (cast_type == RTN_MULTICAST) ||
2537                     (cast_type == RTN_ANYCAST))
2538                         return cast_type;
2539                 else
2540                         return RTN_UNSPEC;
2541         }
2542         /* try something else */
2543         if (skb->protocol == ETH_P_IPV6)
2544                 return (skb_network_header(skb)[24] == 0xff) ?
2545                                 RTN_MULTICAST : 0;
2546         else if (skb->protocol == ETH_P_IP)
2547                 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2548                                 RTN_MULTICAST : 0;
2549         /* ... */
2550         if (!memcmp(skb->data, skb->dev->broadcast, 6))
2551                 return RTN_BROADCAST;
2552         else {
2553                 u16 hdr_mac;
2554
2555                 hdr_mac = *((u16 *)skb->data);
2556                 /* tr multicast? */
2557                 switch (card->info.link_type) {
2558                 case QETH_LINK_TYPE_HSTR:
2559                 case QETH_LINK_TYPE_LANE_TR:
2560                         if ((hdr_mac == QETH_TR_MAC_NC) ||
2561                             (hdr_mac == QETH_TR_MAC_C))
2562                                 return RTN_MULTICAST;
2563                         break;
2564                 /* eth or so multicast? */
2565                 default:
2566                 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2567                             (hdr_mac == QETH_ETH_MAC_V6))
2568                                 return RTN_MULTICAST;
2569                 }
2570         }
2571         return cast_type;
2572 }
2573
2574 static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2575                 struct sk_buff *skb, int ipv, int cast_type)
2576 {
2577         memset(hdr, 0, sizeof(struct qeth_hdr));
2578         hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2579         hdr->hdr.l3.ext_flags = 0;
2580
2581         /*
2582          * before we're going to overwrite this location with next hop ip.
2583          * v6 uses passthrough, v4 sets the tag in the QDIO header.
2584          */
2585         if (card->vlangrp && vlan_tx_tag_present(skb)) {
2586                 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2587                         hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2588                 else
2589                         hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
2590                 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2591         }
2592
2593         hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2594         if (ipv == 4) {
2595                 /* IPv4 */
2596                 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2597                 memset(hdr->hdr.l3.dest_addr, 0, 12);
2598                 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
2599                         *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2600                             *((u32 *) skb_dst(skb)->neighbour->primary_key);
2601                 } else {
2602                         /* fill in destination address used in ip header */
2603                         *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
2604                                                         ip_hdr(skb)->daddr;
2605                 }
2606         } else if (ipv == 6) {
2607                 /* IPv6 */
2608                 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2609                 if (card->info.type == QETH_CARD_TYPE_IQD)
2610                         hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
2611                 if ((skb_dst(skb)) && (skb_dst(skb)->neighbour)) {
2612                         memcpy(hdr->hdr.l3.dest_addr,
2613                                skb_dst(skb)->neighbour->primary_key, 16);
2614                 } else {
2615                         /* fill in destination address used in ip header */
2616                         memcpy(hdr->hdr.l3.dest_addr,
2617                                &ipv6_hdr(skb)->daddr, 16);
2618                 }
2619         } else {
2620                 /* passthrough */
2621                 if ((skb->dev->type == ARPHRD_IEEE802_TR) &&
2622                         !memcmp(skb->data + sizeof(struct qeth_hdr) +
2623                         sizeof(__u16), skb->dev->broadcast, 6)) {
2624                         hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2625                                                 QETH_HDR_PASSTHRU;
2626                 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
2627                             skb->dev->broadcast, 6)) {
2628                         /* broadcast? */
2629                         hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2630                                                 QETH_HDR_PASSTHRU;
2631                 } else {
2632                         hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2633                                 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2634                                 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2635                 }
2636         }
2637 }
2638
2639 static void qeth_tso_fill_header(struct qeth_card *card,
2640                 struct qeth_hdr *qhdr, struct sk_buff *skb)
2641 {
2642         struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2643         struct tcphdr *tcph = tcp_hdr(skb);
2644         struct iphdr *iph = ip_hdr(skb);
2645         struct ipv6hdr *ip6h = ipv6_hdr(skb);
2646
2647         /*fix header to TSO values ...*/
2648         hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
2649         /*set values which are fix for the first approach ...*/
2650         hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2651         hdr->ext.imb_hdr_no  = 1;
2652         hdr->ext.hdr_type    = 1;
2653         hdr->ext.hdr_version = 1;
2654         hdr->ext.hdr_len     = 28;
2655         /*insert non-fix values */
2656         hdr->ext.mss = skb_shinfo(skb)->gso_size;
2657         hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2658         hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2659                                        sizeof(struct qeth_hdr_tso));
2660         tcph->check = 0;
2661         if (skb->protocol == ETH_P_IPV6) {
2662                 ip6h->payload_len = 0;
2663                 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2664                                                0, IPPROTO_TCP, 0);
2665         } else {
2666                 /*OSA want us to set these values ...*/
2667                 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2668                                          0, IPPROTO_TCP, 0);
2669                 iph->tot_len = 0;
2670                 iph->check = 0;
2671         }
2672 }
2673
2674 static void qeth_tx_csum(struct sk_buff *skb)
2675 {
2676         __wsum csum;
2677         int offset;
2678
2679         skb_set_transport_header(skb, skb->csum_start - skb_headroom(skb));
2680         offset = skb->csum_start - skb_headroom(skb);
2681         BUG_ON(offset >= skb_headlen(skb));
2682         csum = skb_checksum(skb, offset, skb->len - offset, 0);
2683
2684         offset += skb->csum_offset;
2685         BUG_ON(offset + sizeof(__sum16) > skb_headlen(skb));
2686         *(__sum16 *)(skb->data + offset) = csum_fold(csum);
2687 }
2688
2689 static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2690 {
2691         int rc;
2692         u16 *tag;
2693         struct qeth_hdr *hdr = NULL;
2694         int elements_needed = 0;
2695         int elems;
2696         struct qeth_card *card = dev->ml_priv;
2697         struct sk_buff *new_skb = NULL;
2698         int ipv = qeth_get_ip_version(skb);
2699         int cast_type = qeth_l3_get_cast_type(card, skb);
2700         struct qeth_qdio_out_q *queue = card->qdio.out_qs
2701                 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
2702         int tx_bytes = skb->len;
2703         enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
2704         int data_offset = -1;
2705         int nr_frags;
2706
2707         if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2708             (skb->protocol != htons(ETH_P_IPV6)) &&
2709             (skb->protocol != htons(ETH_P_IP)))
2710                         goto tx_drop;
2711
2712         if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2713                 card->stats.tx_carrier_errors++;
2714                 goto tx_drop;
2715         }
2716
2717         if ((cast_type == RTN_BROADCAST) &&
2718             (card->info.broadcast_capable == 0))
2719                 goto tx_drop;
2720
2721         if (card->options.performance_stats) {
2722                 card->perf_stats.outbound_cnt++;
2723                 card->perf_stats.outbound_start_time = qeth_get_micros();
2724         }
2725
2726         if (skb_is_gso(skb))
2727                 large_send = card->options.large_send;
2728         else
2729                 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2730                         qeth_tx_csum(skb);
2731                         if (card->options.performance_stats)
2732                                 card->perf_stats.tx_csum++;
2733                 }
2734
2735         if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
2736             (skb_shinfo(skb)->nr_frags == 0)) {
2737                 new_skb = skb;
2738                 data_offset = ETH_HLEN;
2739                 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2740                 if (!hdr)
2741                         goto tx_drop;
2742                 elements_needed++;
2743         } else {
2744                 /* create a clone with writeable headroom */
2745                 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2746                                         + VLAN_HLEN);
2747                 if (!new_skb)
2748                         goto tx_drop;
2749         }
2750
2751         if (card->info.type == QETH_CARD_TYPE_IQD) {
2752                 if (data_offset < 0)
2753                         skb_pull(new_skb, ETH_HLEN);
2754         } else {
2755                 if (new_skb->protocol == htons(ETH_P_IP)) {
2756                         if (card->dev->type == ARPHRD_IEEE802_TR)
2757                                 skb_pull(new_skb, TR_HLEN);
2758                         else
2759                                 skb_pull(new_skb, ETH_HLEN);
2760                 }
2761
2762                 if (new_skb->protocol == ETH_P_IPV6 && card->vlangrp &&
2763                                 vlan_tx_tag_present(new_skb)) {
2764                         skb_push(new_skb, VLAN_HLEN);
2765                         skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2766                         skb_copy_to_linear_data_offset(new_skb, 4,
2767                                 new_skb->data + 8, 4);
2768                         skb_copy_to_linear_data_offset(new_skb, 8,
2769                                 new_skb->data + 12, 4);
2770                         tag = (u16 *)(new_skb->data + 12);
2771                         *tag = __constant_htons(ETH_P_8021Q);
2772                         *(tag + 1) = htons(vlan_tx_tag_get(new_skb));
2773                         new_skb->vlan_tci = 0;
2774                 }
2775         }
2776
2777         netif_stop_queue(dev);
2778
2779         /* fix hardware limitation: as long as we do not have sbal
2780          * chaining we can not send long frag lists
2781          */
2782         if ((large_send == QETH_LARGE_SEND_TSO) &&
2783             ((skb_shinfo(new_skb)->nr_frags + 2) > 16)) {
2784                 if (skb_linearize(new_skb))
2785                         goto tx_drop;
2786         }
2787
2788         if ((large_send == QETH_LARGE_SEND_TSO) &&
2789             (cast_type == RTN_UNSPEC)) {
2790                 hdr = (struct qeth_hdr *)skb_push(new_skb,
2791                                                 sizeof(struct qeth_hdr_tso));
2792                 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2793                 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2794                 qeth_tso_fill_header(card, hdr, new_skb);
2795                 elements_needed++;
2796         } else {
2797                 if (data_offset < 0) {
2798                         hdr = (struct qeth_hdr *)skb_push(new_skb,
2799                                                 sizeof(struct qeth_hdr));
2800                         qeth_l3_fill_header(card, hdr, new_skb, ipv,
2801                                                 cast_type);
2802                 } else {
2803                         qeth_l3_fill_header(card, hdr, new_skb, ipv,
2804                                                 cast_type);
2805                         hdr->hdr.l3.length = new_skb->len - data_offset;
2806                 }
2807         }
2808
2809         elems = qeth_get_elements_no(card, (void *)hdr, new_skb,
2810                                                  elements_needed);
2811         if (!elems) {
2812                 if (data_offset >= 0)
2813                         kmem_cache_free(qeth_core_header_cache, hdr);
2814                 goto tx_drop;
2815         }
2816         elements_needed += elems;
2817         nr_frags = skb_shinfo(new_skb)->nr_frags;
2818
2819         if (card->info.type != QETH_CARD_TYPE_IQD)
2820                 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
2821                                          elements_needed);
2822         else
2823                 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
2824                                         elements_needed, data_offset, 0);
2825
2826         if (!rc) {
2827                 card->stats.tx_packets++;
2828                 card->stats.tx_bytes += tx_bytes;
2829                 if (new_skb != skb)
2830                         dev_kfree_skb_any(skb);
2831                 if (card->options.performance_stats) {
2832                         if (large_send != QETH_LARGE_SEND_NO) {
2833                                 card->perf_stats.large_send_bytes += tx_bytes;
2834                                 card->perf_stats.large_send_cnt++;
2835                         }
2836                         if (nr_frags) {
2837                                 card->perf_stats.sg_skbs_sent++;
2838                                 /* nr_frags + skb->data */
2839                                 card->perf_stats.sg_frags_sent += nr_frags + 1;
2840                         }
2841                 }
2842                 rc = NETDEV_TX_OK;
2843         } else {
2844                 if (data_offset >= 0)
2845                         kmem_cache_free(qeth_core_header_cache, hdr);
2846
2847                 if (rc == -EBUSY) {
2848                         if (new_skb != skb)
2849                                 dev_kfree_skb_any(new_skb);
2850                         return NETDEV_TX_BUSY;
2851                 } else
2852                         goto tx_drop;
2853         }
2854
2855         netif_wake_queue(dev);
2856         if (card->options.performance_stats)
2857                 card->perf_stats.outbound_time += qeth_get_micros() -
2858                         card->perf_stats.outbound_start_time;
2859         return rc;
2860
2861 tx_drop:
2862         card->stats.tx_dropped++;
2863         card->stats.tx_errors++;
2864         if ((new_skb != skb) && new_skb)
2865                 dev_kfree_skb_any(new_skb);
2866         dev_kfree_skb_any(skb);
2867         netif_wake_queue(dev);
2868         return NETDEV_TX_OK;
2869 }
2870
2871 static int qeth_l3_open(struct net_device *dev)
2872 {
2873         struct qeth_card *card = dev->ml_priv;
2874
2875         QETH_DBF_TEXT(TRACE, 4, "qethopen");
2876         if (card->state != CARD_STATE_SOFTSETUP)
2877                 return -ENODEV;
2878         card->data.state = CH_STATE_UP;
2879         card->state = CARD_STATE_UP;
2880         netif_start_queue(dev);
2881
2882         if (!card->lan_online && netif_carrier_ok(dev))
2883                 netif_carrier_off(dev);
2884         return 0;
2885 }
2886
2887 static int qeth_l3_stop(struct net_device *dev)
2888 {
2889         struct qeth_card *card = dev->ml_priv;
2890
2891         QETH_DBF_TEXT(TRACE, 4, "qethstop");
2892         netif_tx_disable(dev);
2893         if (card->state == CARD_STATE_UP)
2894                 card->state = CARD_STATE_SOFTSETUP;
2895         return 0;
2896 }
2897
2898 static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
2899 {
2900         struct qeth_card *card = dev->ml_priv;
2901
2902         return (card->options.checksum_type == HW_CHECKSUMMING);
2903 }
2904
2905 static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
2906 {
2907         struct qeth_card *card = dev->ml_priv;
2908         enum qeth_card_states old_state;
2909         enum qeth_checksum_types csum_type;
2910
2911         if ((card->state != CARD_STATE_UP) &&
2912             (card->state != CARD_STATE_DOWN))
2913                 return -EPERM;
2914
2915         if (data)
2916                 csum_type = HW_CHECKSUMMING;
2917         else
2918                 csum_type = SW_CHECKSUMMING;
2919
2920         if (card->options.checksum_type != csum_type) {
2921                 old_state = card->state;
2922                 if (card->state == CARD_STATE_UP)
2923                         __qeth_l3_set_offline(card->gdev, 1);
2924                 card->options.checksum_type = csum_type;
2925                 if (old_state == CARD_STATE_UP)
2926                         __qeth_l3_set_online(card->gdev, 1);
2927         }
2928         return 0;
2929 }
2930
2931 static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
2932 {
2933         struct qeth_card *card = dev->ml_priv;
2934
2935         if (data) {
2936                 if (card->options.large_send == QETH_LARGE_SEND_NO) {
2937                         if (card->info.type == QETH_CARD_TYPE_IQD)
2938                                 return -EPERM;
2939                         else
2940                                 card->options.large_send = QETH_LARGE_SEND_TSO;
2941                         dev->features |= NETIF_F_TSO;
2942                 }
2943         } else {
2944                 dev->features &= ~NETIF_F_TSO;
2945                 card->options.large_send = QETH_LARGE_SEND_NO;
2946         }
2947         return 0;
2948 }
2949
2950 static const struct ethtool_ops qeth_l3_ethtool_ops = {
2951         .get_link = ethtool_op_get_link,
2952         .get_tx_csum = ethtool_op_get_tx_csum,
2953         .set_tx_csum = ethtool_op_set_tx_hw_csum,
2954         .get_rx_csum = qeth_l3_ethtool_get_rx_csum,
2955         .set_rx_csum = qeth_l3_ethtool_set_rx_csum,
2956         .get_sg      = ethtool_op_get_sg,
2957         .set_sg      = ethtool_op_set_sg,
2958         .get_tso     = ethtool_op_get_tso,
2959         .set_tso     = qeth_l3_ethtool_set_tso,
2960         .get_strings = qeth_core_get_strings,
2961         .get_ethtool_stats = qeth_core_get_ethtool_stats,
2962         .get_sset_count = qeth_core_get_sset_count,
2963         .get_drvinfo = qeth_core_get_drvinfo,
2964         .get_settings = qeth_core_ethtool_get_settings,
2965 };
2966
2967 /*
2968  * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2969  * NOARP on the netdevice is no option because it also turns off neighbor
2970  * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2971  * arp resolution but we want the hard header (packet socket will work
2972  * e.g. tcpdump)
2973  */
2974 static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2975 {
2976         n->nud_state = NUD_NOARP;
2977         memcpy(n->ha, "FAKELL", 6);
2978         n->output = n->ops->connected_output;
2979         return 0;
2980 }
2981
2982 static int
2983 qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2984 {
2985         if (np->tbl->family == AF_INET)
2986                 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2987
2988         return 0;
2989 }
2990
2991 static const struct net_device_ops qeth_l3_netdev_ops = {
2992         .ndo_open               = qeth_l3_open,
2993         .ndo_stop               = qeth_l3_stop,
2994         .ndo_get_stats          = qeth_get_stats,
2995         .ndo_start_xmit         = qeth_l3_hard_start_xmit,
2996         .ndo_validate_addr      = eth_validate_addr,
2997         .ndo_set_multicast_list = qeth_l3_set_multicast_list,
2998         .ndo_do_ioctl           = qeth_l3_do_ioctl,
2999         .ndo_change_mtu         = qeth_change_mtu,
3000         .ndo_vlan_rx_register   = qeth_l3_vlan_rx_register,
3001         .ndo_vlan_rx_add_vid    = qeth_l3_vlan_rx_add_vid,
3002         .ndo_vlan_rx_kill_vid   = qeth_l3_vlan_rx_kill_vid,
3003         .ndo_tx_timeout         = qeth_tx_timeout,
3004 };
3005
3006 static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3007         .ndo_open               = qeth_l3_open,
3008         .ndo_stop               = qeth_l3_stop,
3009         .ndo_get_stats          = qeth_get_stats,
3010         .ndo_start_xmit         = qeth_l3_hard_start_xmit,
3011         .ndo_validate_addr      = eth_validate_addr,
3012         .ndo_set_multicast_list = qeth_l3_set_multicast_list,
3013         .ndo_do_ioctl           = qeth_l3_do_ioctl,
3014         .ndo_change_mtu         = qeth_change_mtu,
3015         .ndo_vlan_rx_register   = qeth_l3_vlan_rx_register,
3016         .ndo_vlan_rx_add_vid    = qeth_l3_vlan_rx_add_vid,
3017         .ndo_vlan_rx_kill_vid   = qeth_l3_vlan_rx_kill_vid,
3018         .ndo_tx_timeout         = qeth_tx_timeout,
3019         .ndo_neigh_setup        = qeth_l3_neigh_setup,
3020 };
3021
3022 static int qeth_l3_setup_netdev(struct qeth_card *card)
3023 {
3024         if (card->info.type == QETH_CARD_TYPE_OSAE) {
3025                 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3026                     (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
3027 #ifdef CONFIG_TR
3028                         card->dev = alloc_trdev(0);
3029 #endif
3030                         if (!card->dev)
3031                                 return -ENODEV;
3032                         card->dev->netdev_ops = &qeth_l3_netdev_ops;
3033                 } else {
3034                         card->dev = alloc_etherdev(0);
3035                         if (!card->dev)
3036                                 return -ENODEV;
3037                         card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
3038
3039                         /*IPv6 address autoconfiguration stuff*/
3040                         qeth_l3_get_unique_id(card);
3041                         if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3042                                 card->dev->dev_id = card->info.unique_id &
3043                                                          0xffff;
3044                 }
3045         } else if (card->info.type == QETH_CARD_TYPE_IQD) {
3046                 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
3047                 if (!card->dev)
3048                         return -ENODEV;
3049                 card->dev->flags |= IFF_NOARP;
3050                 card->dev->netdev_ops = &qeth_l3_netdev_ops;
3051                 qeth_l3_iqd_read_initial_mac(card);
3052         } else
3053                 return -ENODEV;
3054
3055         card->dev->ml_priv = card;
3056         card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
3057         card->dev->mtu = card->info.initial_mtu;
3058         SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops);
3059         card->dev->features |=  NETIF_F_HW_VLAN_TX |
3060                                 NETIF_F_HW_VLAN_RX |
3061                                 NETIF_F_HW_VLAN_FILTER;
3062         card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
3063
3064         SET_NETDEV_DEV(card->dev, &card->gdev->dev);
3065         return register_netdev(card->dev);
3066 }
3067
3068 static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
3069                 unsigned int qdio_err, unsigned int queue, int first_element,
3070                 int count, unsigned long card_ptr)
3071 {
3072         struct net_device *net_dev;
3073         struct qeth_card *card;
3074         struct qeth_qdio_buffer *buffer;
3075         int index;
3076         int i;
3077
3078         card = (struct qeth_card *) card_ptr;
3079         net_dev = card->dev;
3080         if (card->options.performance_stats) {
3081                 card->perf_stats.inbound_cnt++;
3082                 card->perf_stats.inbound_start_time = qeth_get_micros();
3083         }
3084         if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
3085                 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
3086                 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
3087                 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X",
3088                                 first_element, count);
3089                 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
3090                 qeth_schedule_recovery(card);
3091                 return;
3092         }
3093         for (i = first_element; i < (first_element + count); ++i) {
3094                 index = i % QDIO_MAX_BUFFERS_PER_Q;
3095                 buffer = &card->qdio.in_q->bufs[index];
3096                 if (!(qdio_err &&
3097                       qeth_check_qdio_errors(buffer->buffer,
3098                                              qdio_err, "qinerr")))
3099                         qeth_l3_process_inbound_buffer(card, buffer, index);
3100                 /* clear buffer and give back to hardware */
3101                 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
3102                 qeth_queue_input_buffer(card, index);
3103         }
3104         if (card->options.performance_stats)
3105                 card->perf_stats.inbound_time += qeth_get_micros() -
3106                         card->perf_stats.inbound_start_time;
3107 }
3108
3109 static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3110 {
3111         struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3112
3113         qeth_l3_create_device_attributes(&gdev->dev);
3114         card->options.layer2 = 0;
3115         card->discipline.input_handler = (qdio_handler_t *)
3116                 qeth_l3_qdio_input_handler;
3117         card->discipline.output_handler = (qdio_handler_t *)
3118                 qeth_qdio_output_handler;
3119         card->discipline.recover = qeth_l3_recover;
3120         return 0;
3121 }
3122
3123 static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3124 {
3125         struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3126
3127         qeth_set_allowed_threads(card, 0, 1);
3128         wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3129
3130         if (cgdev->state == CCWGROUP_ONLINE) {
3131                 card->use_hard_stop = 1;
3132                 qeth_l3_set_offline(cgdev);
3133         }
3134
3135         if (card->dev) {
3136                 unregister_netdev(card->dev);
3137                 card->dev = NULL;
3138         }
3139
3140         qeth_l3_remove_device_attributes(&cgdev->dev);
3141         qeth_l3_clear_ip_list(card, 0, 0);
3142         qeth_l3_clear_ipato_list(card);
3143         return;
3144 }
3145
3146 static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3147 {
3148         struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3149         int rc = 0;
3150         enum qeth_card_states recover_flag;
3151
3152         BUG_ON(!card);
3153         QETH_DBF_TEXT(SETUP, 2, "setonlin");
3154         QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
3155
3156         qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
3157
3158         recover_flag = card->state;
3159         rc = ccw_device_set_online(CARD_RDEV(card));
3160         if (rc) {
3161                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3162                 return -EIO;
3163         }
3164         rc = ccw_device_set_online(CARD_WDEV(card));
3165         if (rc) {
3166                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3167                 return -EIO;
3168         }
3169         rc = ccw_device_set_online(CARD_DDEV(card));
3170         if (rc) {
3171                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3172                 return -EIO;
3173         }
3174
3175         rc = qeth_core_hardsetup_card(card);
3176         if (rc) {
3177                 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3178                 goto out_remove;
3179         }
3180
3181         qeth_l3_query_ipassists(card, QETH_PROT_IPV4);
3182
3183         if (!card->dev && qeth_l3_setup_netdev(card))
3184                 goto out_remove;
3185
3186         card->state = CARD_STATE_HARDSETUP;
3187         qeth_print_status_message(card);
3188
3189         /* softsetup */
3190         QETH_DBF_TEXT(SETUP, 2, "softsetp");
3191
3192         rc = qeth_send_startlan(card);
3193         if (rc) {
3194                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3195                 if (rc == 0xe080) {
3196                         dev_warn(&card->gdev->dev,
3197                                 "The LAN is offline\n");
3198                         card->lan_online = 0;
3199                         return 0;
3200                 }
3201                 goto out_remove;
3202         } else
3203                 card->lan_online = 1;
3204         qeth_set_large_send(card, card->options.large_send);
3205
3206         rc = qeth_l3_setadapter_parms(card);
3207         if (rc)
3208                 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3209         rc = qeth_l3_start_ipassists(card);
3210         if (rc)
3211                 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3212         rc = qeth_l3_setrouting_v4(card);
3213         if (rc)
3214                 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3215         rc = qeth_l3_setrouting_v6(card);
3216         if (rc)
3217                 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3218         netif_tx_disable(card->dev);
3219
3220         rc = qeth_init_qdio_queues(card);
3221         if (rc) {
3222                 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
3223                 goto out_remove;
3224         }
3225         card->state = CARD_STATE_SOFTSETUP;
3226         netif_carrier_on(card->dev);
3227
3228         qeth_set_allowed_threads(card, 0xffffffff, 0);
3229         qeth_l3_set_ip_addr_list(card);
3230         if (recover_flag == CARD_STATE_RECOVER) {
3231                 if (recovery_mode)
3232                         qeth_l3_open(card->dev);
3233                 else {
3234                         rtnl_lock();
3235                         dev_open(card->dev);
3236                         rtnl_unlock();
3237                 }
3238                 qeth_l3_set_multicast_list(card->dev);
3239         }
3240         /* let user_space know that device is online */
3241         kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3242         return 0;
3243 out_remove:
3244         card->use_hard_stop = 1;
3245         qeth_l3_stop_card(card, 0);
3246         ccw_device_set_offline(CARD_DDEV(card));
3247         ccw_device_set_offline(CARD_WDEV(card));
3248         ccw_device_set_offline(CARD_RDEV(card));
3249         if (recover_flag == CARD_STATE_RECOVER)
3250                 card->state = CARD_STATE_RECOVER;
3251         else
3252                 card->state = CARD_STATE_DOWN;
3253         return -ENODEV;
3254 }
3255
3256 static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3257 {
3258         return __qeth_l3_set_online(gdev, 0);
3259 }
3260
3261 static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3262                         int recovery_mode)
3263 {
3264         struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3265         int rc = 0, rc2 = 0, rc3 = 0;
3266         enum qeth_card_states recover_flag;
3267
3268         QETH_DBF_TEXT(SETUP, 3, "setoffl");
3269         QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
3270
3271         if (card->dev && netif_carrier_ok(card->dev))
3272                 netif_carrier_off(card->dev);
3273         recover_flag = card->state;
3274         qeth_l3_stop_card(card, recovery_mode);
3275         rc  = ccw_device_set_offline(CARD_DDEV(card));
3276         rc2 = ccw_device_set_offline(CARD_WDEV(card));
3277         rc3 = ccw_device_set_offline(CARD_RDEV(card));
3278         if (!rc)
3279                 rc = (rc2) ? rc2 : rc3;
3280         if (rc)
3281                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3282         if (recover_flag == CARD_STATE_UP)
3283                 card->state = CARD_STATE_RECOVER;
3284         /* let user_space know that device is offline */
3285         kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
3286         return 0;
3287 }
3288
3289 static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3290 {
3291         return __qeth_l3_set_offline(cgdev, 0);
3292 }
3293
3294 static int qeth_l3_recover(void *ptr)
3295 {
3296         struct qeth_card *card;
3297         int rc = 0;
3298
3299         card = (struct qeth_card *) ptr;
3300         QETH_DBF_TEXT(TRACE, 2, "recover1");
3301         QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
3302         if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3303                 return 0;
3304         QETH_DBF_TEXT(TRACE, 2, "recover2");
3305         dev_warn(&card->gdev->dev,
3306                 "A recovery process has been started for the device\n");
3307         card->use_hard_stop = 1;
3308         __qeth_l3_set_offline(card->gdev, 1);
3309         rc = __qeth_l3_set_online(card->gdev, 1);
3310         /* don't run another scheduled recovery */
3311         qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3312         qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
3313         if (!rc)
3314                 dev_info(&card->gdev->dev,
3315                         "Device successfully recovered!\n");
3316         else {
3317                 rtnl_lock();
3318                 dev_close(card->dev);
3319                 rtnl_unlock();
3320                 dev_warn(&card->gdev->dev, "The qeth device driver "
3321                         "failed to recover an error on the device\n");
3322         }
3323         return 0;
3324 }
3325
3326 static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3327 {
3328         struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3329         qeth_l3_clear_ip_list(card, 0, 0);
3330         qeth_qdio_clear_card(card, 0);
3331         qeth_clear_qdio_buffers(card);
3332 }
3333
3334 static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3335 {
3336         struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3337
3338         if (card->dev)
3339                 netif_device_detach(card->dev);
3340         qeth_set_allowed_threads(card, 0, 1);
3341         wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3342         if (gdev->state == CCWGROUP_OFFLINE)
3343                 return 0;
3344         if (card->state == CARD_STATE_UP) {
3345                 card->use_hard_stop = 1;
3346                 __qeth_l3_set_offline(card->gdev, 1);
3347         } else
3348                 __qeth_l3_set_offline(card->gdev, 0);
3349         return 0;
3350 }
3351
3352 static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3353 {
3354         struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3355         int rc = 0;
3356
3357         if (gdev->state == CCWGROUP_OFFLINE)
3358                 goto out;
3359
3360         if (card->state == CARD_STATE_RECOVER) {
3361                 rc = __qeth_l3_set_online(card->gdev, 1);
3362                 if (rc) {
3363                         if (card->dev) {
3364                                 rtnl_lock();
3365                                 dev_close(card->dev);
3366                                 rtnl_unlock();
3367                         }
3368                 }
3369         } else
3370                 rc = __qeth_l3_set_online(card->gdev, 0);
3371 out:
3372         qeth_set_allowed_threads(card, 0xffffffff, 0);
3373         if (card->dev)
3374                 netif_device_attach(card->dev);
3375         if (rc)
3376                 dev_warn(&card->gdev->dev, "The qeth device driver "
3377                         "failed to recover an error on the device\n");
3378         return rc;
3379 }
3380
3381 struct ccwgroup_driver qeth_l3_ccwgroup_driver = {
3382         .probe = qeth_l3_probe_device,
3383         .remove = qeth_l3_remove_device,
3384         .set_online = qeth_l3_set_online,
3385         .set_offline = qeth_l3_set_offline,
3386         .shutdown = qeth_l3_shutdown,
3387         .freeze = qeth_l3_pm_suspend,
3388         .thaw = qeth_l3_pm_resume,
3389         .restore = qeth_l3_pm_resume,
3390 };
3391 EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver);
3392
3393 static int qeth_l3_ip_event(struct notifier_block *this,
3394                             unsigned long event, void *ptr)
3395 {
3396         struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3397         struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3398         struct qeth_ipaddr *addr;
3399         struct qeth_card *card;
3400
3401         if (dev_net(dev) != &init_net)
3402                 return NOTIFY_DONE;
3403
3404         QETH_DBF_TEXT(TRACE, 3, "ipevent");
3405         card = qeth_l3_get_card_from_dev(dev);
3406         if (!card)
3407                 return NOTIFY_DONE;
3408
3409         addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
3410         if (addr != NULL) {
3411                 addr->u.a4.addr = ifa->ifa_address;
3412                 addr->u.a4.mask = ifa->ifa_mask;
3413                 addr->type = QETH_IP_TYPE_NORMAL;
3414         } else
3415                 goto out;
3416
3417         switch (event) {
3418         case NETDEV_UP:
3419                 if (!qeth_l3_add_ip(card, addr))
3420                         kfree(addr);
3421                 break;
3422         case NETDEV_DOWN:
3423                 if (!qeth_l3_delete_ip(card, addr))
3424                         kfree(addr);
3425                 break;
3426         default:
3427                 break;
3428         }
3429         qeth_l3_set_ip_addr_list(card);
3430 out:
3431         return NOTIFY_DONE;
3432 }
3433
3434 static struct notifier_block qeth_l3_ip_notifier = {
3435         qeth_l3_ip_event,
3436         NULL,
3437 };
3438
3439 #ifdef CONFIG_QETH_IPV6
3440 /**
3441  * IPv6 event handler
3442  */
3443 static int qeth_l3_ip6_event(struct notifier_block *this,
3444                              unsigned long event, void *ptr)
3445 {
3446         struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3447         struct net_device *dev = (struct net_device *)ifa->idev->dev;
3448         struct qeth_ipaddr *addr;
3449         struct qeth_card *card;
3450
3451         QETH_DBF_TEXT(TRACE, 3, "ip6event");
3452
3453         card = qeth_l3_get_card_from_dev(dev);
3454         if (!card)
3455                 return NOTIFY_DONE;
3456         if (!qeth_is_supported(card, IPA_IPV6))
3457                 return NOTIFY_DONE;
3458
3459         addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
3460         if (addr != NULL) {
3461                 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3462                 addr->u.a6.pfxlen = ifa->prefix_len;
3463                 addr->type = QETH_IP_TYPE_NORMAL;
3464         } else
3465                 goto out;
3466
3467         switch (event) {
3468         case NETDEV_UP:
3469                 if (!qeth_l3_add_ip(card, addr))
3470                         kfree(addr);
3471                 break;
3472         case NETDEV_DOWN:
3473                 if (!qeth_l3_delete_ip(card, addr))
3474                         kfree(addr);
3475                 break;
3476         default:
3477                 break;
3478         }
3479         qeth_l3_set_ip_addr_list(card);
3480 out:
3481         return NOTIFY_DONE;
3482 }
3483
3484 static struct notifier_block qeth_l3_ip6_notifier = {
3485         qeth_l3_ip6_event,
3486         NULL,
3487 };
3488 #endif
3489
3490 static int qeth_l3_register_notifiers(void)
3491 {
3492         int rc;
3493
3494         QETH_DBF_TEXT(TRACE, 5, "regnotif");
3495         rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3496         if (rc)
3497                 return rc;
3498 #ifdef CONFIG_QETH_IPV6
3499         rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3500         if (rc) {
3501                 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3502                 return rc;
3503         }
3504 #else
3505         pr_warning("There is no IPv6 support for the layer 3 discipline\n");
3506 #endif
3507         return 0;
3508 }
3509
3510 static void qeth_l3_unregister_notifiers(void)
3511 {
3512
3513         QETH_DBF_TEXT(TRACE, 5, "unregnot");
3514         BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
3515 #ifdef CONFIG_QETH_IPV6
3516         BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
3517 #endif /* QETH_IPV6 */
3518 }
3519
3520 static int __init qeth_l3_init(void)
3521 {
3522         int rc = 0;
3523
3524         pr_info("register layer 3 discipline\n");
3525         rc = qeth_l3_register_notifiers();
3526         return rc;
3527 }
3528
3529 static void __exit qeth_l3_exit(void)
3530 {
3531         qeth_l3_unregister_notifiers();
3532         pr_info("unregister layer 3 discipline\n");
3533 }
3534
3535 module_init(qeth_l3_init);
3536 module_exit(qeth_l3_exit);
3537 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3538 MODULE_DESCRIPTION("qeth layer 3 discipline");
3539 MODULE_LICENSE("GPL");