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