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