Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6] / drivers / s390 / net / qeth_main.c
1 /*
2  * linux/drivers/s390/net/qeth_main.c
3  *
4  * Linux on zSeries OSA Express and HiperSockets support
5  *
6  * Copyright 2000,2003 IBM Corporation
7  *
8  *    Author(s): Original Code written by
9  *                        Utz Bacher (utz.bacher@de.ibm.com)
10  *               Rewritten by
11  *                        Frank Pavlic (fpavlic@de.ibm.com) and
12  *                        Thomas Spatzier <tspat@de.ibm.com>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  */
28
29
30 #include <linux/module.h>
31 #include <linux/moduleparam.h>
32 #include <linux/string.h>
33 #include <linux/errno.h>
34 #include <linux/mm.h>
35 #include <linux/ip.h>
36 #include <linux/inetdevice.h>
37 #include <linux/netdevice.h>
38 #include <linux/sched.h>
39 #include <linux/workqueue.h>
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/interrupt.h>
43 #include <linux/tcp.h>
44 #include <linux/icmp.h>
45 #include <linux/skbuff.h>
46 #include <linux/in.h>
47 #include <linux/igmp.h>
48 #include <linux/init.h>
49 #include <linux/reboot.h>
50 #include <linux/mii.h>
51 #include <linux/rcupdate.h>
52 #include <linux/ethtool.h>
53
54 #include <net/arp.h>
55 #include <net/ip.h>
56 #include <net/route.h>
57
58 #include <asm/ebcdic.h>
59 #include <asm/io.h>
60 #include <asm/qeth.h>
61 #include <asm/timex.h>
62 #include <asm/semaphore.h>
63 #include <asm/uaccess.h>
64 #include <asm/s390_rdev.h>
65
66 #include "qeth.h"
67 #include "qeth_mpc.h"
68 #include "qeth_fs.h"
69 #include "qeth_eddp.h"
70 #include "qeth_tso.h"
71
72 static const char *version = "qeth S/390 OSA-Express driver";
73
74 /**
75  * Debug Facility Stuff
76  */
77 static debug_info_t *qeth_dbf_setup = NULL;
78 static debug_info_t *qeth_dbf_data = NULL;
79 static debug_info_t *qeth_dbf_misc = NULL;
80 static debug_info_t *qeth_dbf_control = NULL;
81 debug_info_t *qeth_dbf_trace = NULL;
82 static debug_info_t *qeth_dbf_sense = NULL;
83 static debug_info_t *qeth_dbf_qerr = NULL;
84
85 DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
86
87 static struct lock_class_key qdio_out_skb_queue_key;
88
89 /**
90  * some more definitions and declarations
91  */
92 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
93
94 /* list of our cards */
95 struct qeth_card_list_struct qeth_card_list;
96 /*process list want to be notified*/
97 spinlock_t qeth_notify_lock;
98 struct list_head qeth_notify_list;
99
100 static void qeth_send_control_data_cb(struct qeth_channel *,
101                                       struct qeth_cmd_buffer *);
102
103 /**
104  * here we go with function implementation
105  */
106 static void
107 qeth_init_qdio_info(struct qeth_card *card);
108
109 static int
110 qeth_init_qdio_queues(struct qeth_card *card);
111
112 static int
113 qeth_alloc_qdio_buffers(struct qeth_card *card);
114
115 static void
116 qeth_free_qdio_buffers(struct qeth_card *);
117
118 static void
119 qeth_clear_qdio_buffers(struct qeth_card *);
120
121 static void
122 qeth_clear_ip_list(struct qeth_card *, int, int);
123
124 static void
125 qeth_clear_ipacmd_list(struct qeth_card *);
126
127 static int
128 qeth_qdio_clear_card(struct qeth_card *, int);
129
130 static void
131 qeth_clear_working_pool_list(struct qeth_card *);
132
133 static void
134 qeth_clear_cmd_buffers(struct qeth_channel *);
135
136 static int
137 qeth_stop(struct net_device *);
138
139 static void
140 qeth_clear_ipato_list(struct qeth_card *);
141
142 static int
143 qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
144
145 static void
146 qeth_irq_tasklet(unsigned long);
147
148 static int
149 qeth_set_online(struct ccwgroup_device *);
150
151 static int
152 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
153
154 static struct qeth_ipaddr *
155 qeth_get_addr_buffer(enum qeth_prot_versions);
156
157 static void
158 qeth_set_multicast_list(struct net_device *);
159
160 static void
161 qeth_setadp_promisc_mode(struct qeth_card *);
162
163 static void
164 qeth_notify_processes(void)
165 {
166         /*notify all  registered processes */
167         struct qeth_notify_list_struct *n_entry;
168
169         QETH_DBF_TEXT(trace,3,"procnoti");
170         spin_lock(&qeth_notify_lock);
171         list_for_each_entry(n_entry, &qeth_notify_list, list) {
172                 send_sig(n_entry->signum, n_entry->task, 1);
173         }
174         spin_unlock(&qeth_notify_lock);
175
176 }
177 int
178 qeth_notifier_unregister(struct task_struct *p)
179 {
180         struct qeth_notify_list_struct *n_entry, *tmp;
181
182         QETH_DBF_TEXT(trace, 2, "notunreg");
183         spin_lock(&qeth_notify_lock);
184         list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
185                 if (n_entry->task == p) {
186                         list_del(&n_entry->list);
187                         kfree(n_entry);
188                         goto out;
189                 }
190         }
191 out:
192         spin_unlock(&qeth_notify_lock);
193         return 0;
194 }
195 int
196 qeth_notifier_register(struct task_struct *p, int signum)
197 {
198         struct qeth_notify_list_struct *n_entry;
199
200         /*check first if entry already exists*/
201         spin_lock(&qeth_notify_lock);
202         list_for_each_entry(n_entry, &qeth_notify_list, list) {
203                 if (n_entry->task == p) {
204                         n_entry->signum = signum;
205                         spin_unlock(&qeth_notify_lock);
206                         return 0;
207                 }
208         }
209         spin_unlock(&qeth_notify_lock);
210
211         n_entry = (struct qeth_notify_list_struct *)
212                 kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL);
213         if (!n_entry)
214                 return -ENOMEM;
215         n_entry->task = p;
216         n_entry->signum = signum;
217         spin_lock(&qeth_notify_lock);
218         list_add(&n_entry->list,&qeth_notify_list);
219         spin_unlock(&qeth_notify_lock);
220         return 0;
221 }
222
223
224 /**
225  * free channel command buffers
226  */
227 static void
228 qeth_clean_channel(struct qeth_channel *channel)
229 {
230         int cnt;
231
232         QETH_DBF_TEXT(setup, 2, "freech");
233         for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
234                 kfree(channel->iob[cnt].data);
235 }
236
237 /**
238  * free card
239  */
240 static void
241 qeth_free_card(struct qeth_card *card)
242 {
243
244         QETH_DBF_TEXT(setup, 2, "freecrd");
245         QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
246         qeth_clean_channel(&card->read);
247         qeth_clean_channel(&card->write);
248         if (card->dev)
249                 free_netdev(card->dev);
250         qeth_clear_ip_list(card, 0, 0);
251         qeth_clear_ipato_list(card);
252         kfree(card->ip_tbd_list);
253         qeth_free_qdio_buffers(card);
254         kfree(card);
255 }
256
257 /**
258  * alloc memory for command buffer per channel
259  */
260 static int
261 qeth_setup_channel(struct qeth_channel *channel)
262 {
263         int cnt;
264
265         QETH_DBF_TEXT(setup, 2, "setupch");
266         for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
267                 channel->iob[cnt].data = (char *)
268                         kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
269                 if (channel->iob[cnt].data == NULL)
270                         break;
271                 channel->iob[cnt].state = BUF_STATE_FREE;
272                 channel->iob[cnt].channel = channel;
273                 channel->iob[cnt].callback = qeth_send_control_data_cb;
274                 channel->iob[cnt].rc = 0;
275         }
276         if (cnt < QETH_CMD_BUFFER_NO) {
277                 while (cnt-- > 0)
278                         kfree(channel->iob[cnt].data);
279                 return -ENOMEM;
280         }
281         channel->buf_no = 0;
282         channel->io_buf_no = 0;
283         atomic_set(&channel->irq_pending, 0);
284         spin_lock_init(&channel->iob_lock);
285
286         init_waitqueue_head(&channel->wait_q);
287         channel->irq_tasklet.data = (unsigned long) channel;
288         channel->irq_tasklet.func = qeth_irq_tasklet;
289         return 0;
290 }
291
292 /**
293  * alloc memory for card structure
294  */
295 static struct qeth_card *
296 qeth_alloc_card(void)
297 {
298         struct qeth_card *card;
299
300         QETH_DBF_TEXT(setup, 2, "alloccrd");
301         card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
302         if (!card)
303                 return NULL;
304         QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
305         if (qeth_setup_channel(&card->read)) {
306                 kfree(card);
307                 return NULL;
308         }
309         if (qeth_setup_channel(&card->write)) {
310                 qeth_clean_channel(&card->read);
311                 kfree(card);
312                 return NULL;
313         }
314         return card;
315 }
316
317 static long
318 __qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb)
319 {
320         if (!IS_ERR(irb))
321                 return 0;
322
323         switch (PTR_ERR(irb)) {
324         case -EIO:
325                 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
326                 QETH_DBF_TEXT(trace, 2, "ckirberr");
327                 QETH_DBF_TEXT_(trace, 2, "  rc%d", -EIO);
328                 break;
329         case -ETIMEDOUT:
330                 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
331                 QETH_DBF_TEXT(trace, 2, "ckirberr");
332                 QETH_DBF_TEXT_(trace, 2, "  rc%d", -ETIMEDOUT);
333                 break;
334         default:
335                 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
336                            cdev->dev.bus_id);
337                 QETH_DBF_TEXT(trace, 2, "ckirberr");
338                 QETH_DBF_TEXT(trace, 2, "  rc???");
339         }
340         return PTR_ERR(irb);
341 }
342
343 static int
344 qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
345 {
346         int dstat,cstat;
347         char *sense;
348
349         sense = (char *) irb->ecw;
350         cstat = irb->scsw.cstat;
351         dstat = irb->scsw.dstat;
352
353         if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
354                      SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
355                      SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
356                 QETH_DBF_TEXT(trace,2, "CGENCHK");
357                 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
358                            cdev->dev.bus_id, dstat, cstat);
359                 HEXDUMP16(WARN, "irb: ", irb);
360                 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
361                 return 1;
362         }
363
364         if (dstat & DEV_STAT_UNIT_CHECK) {
365                 if (sense[SENSE_RESETTING_EVENT_BYTE] &
366                     SENSE_RESETTING_EVENT_FLAG) {
367                         QETH_DBF_TEXT(trace,2,"REVIND");
368                         return 1;
369                 }
370                 if (sense[SENSE_COMMAND_REJECT_BYTE] &
371                     SENSE_COMMAND_REJECT_FLAG) {
372                         QETH_DBF_TEXT(trace,2,"CMDREJi");
373                         return 0;
374                 }
375                 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
376                         QETH_DBF_TEXT(trace,2,"AFFE");
377                         return 1;
378                 }
379                 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
380                         QETH_DBF_TEXT(trace,2,"ZEROSEN");
381                         return 0;
382                 }
383                 QETH_DBF_TEXT(trace,2,"DGENCHK");
384                         return 1;
385         }
386         return 0;
387 }
388 static int qeth_issue_next_read(struct qeth_card *);
389
390 /**
391  * interrupt handler
392  */
393 static void
394 qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
395 {
396         int rc;
397         int cstat,dstat;
398         struct qeth_cmd_buffer *buffer;
399         struct qeth_channel *channel;
400         struct qeth_card *card;
401
402         QETH_DBF_TEXT(trace,5,"irq");
403
404         if (__qeth_check_irb_error(cdev, irb))
405                 return;
406         cstat = irb->scsw.cstat;
407         dstat = irb->scsw.dstat;
408
409         card = CARD_FROM_CDEV(cdev);
410         if (!card)
411                 return;
412
413         if (card->read.ccwdev == cdev){
414                 channel = &card->read;
415                 QETH_DBF_TEXT(trace,5,"read");
416         } else if (card->write.ccwdev == cdev) {
417                 channel = &card->write;
418                 QETH_DBF_TEXT(trace,5,"write");
419         } else {
420                 channel = &card->data;
421                 QETH_DBF_TEXT(trace,5,"data");
422         }
423         atomic_set(&channel->irq_pending, 0);
424
425         if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
426                 channel->state = CH_STATE_STOPPED;
427
428         if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
429                 channel->state = CH_STATE_HALTED;
430
431         /*let's wake up immediately on data channel*/
432         if ((channel == &card->data) && (intparm != 0))
433                 goto out;
434
435         if (intparm == QETH_CLEAR_CHANNEL_PARM) {
436                 QETH_DBF_TEXT(trace, 6, "clrchpar");
437                 /* we don't have to handle this further */
438                 intparm = 0;
439         }
440         if (intparm == QETH_HALT_CHANNEL_PARM) {
441                 QETH_DBF_TEXT(trace, 6, "hltchpar");
442                 /* we don't have to handle this further */
443                 intparm = 0;
444         }
445         if ((dstat & DEV_STAT_UNIT_EXCEP) ||
446             (dstat & DEV_STAT_UNIT_CHECK) ||
447             (cstat)) {
448                 if (irb->esw.esw0.erw.cons) {
449                         /* TODO: we should make this s390dbf */
450                         PRINT_WARN("sense data available on channel %s.\n",
451                                    CHANNEL_ID(channel));
452                         PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
453                         HEXDUMP16(WARN,"irb: ",irb);
454                         HEXDUMP16(WARN,"sense data: ",irb->ecw);
455                 }
456                 rc = qeth_get_problem(cdev,irb);
457                 if (rc) {
458                         qeth_schedule_recovery(card);
459                         goto out;
460                 }
461         }
462
463         if (intparm) {
464                 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
465                 buffer->state = BUF_STATE_PROCESSED;
466         }
467         if (channel == &card->data)
468                 return;
469
470         if (channel == &card->read &&
471             channel->state == CH_STATE_UP)
472                 qeth_issue_next_read(card);
473
474         qeth_irq_tasklet((unsigned long)channel);
475         return;
476 out:
477         wake_up(&card->wait_q);
478 }
479
480 /**
481  * tasklet function scheduled from irq handler
482  */
483 static void
484 qeth_irq_tasklet(unsigned long data)
485 {
486         struct qeth_card *card;
487         struct qeth_channel *channel;
488         struct qeth_cmd_buffer *iob;
489         __u8 index;
490
491         QETH_DBF_TEXT(trace,5,"irqtlet");
492         channel = (struct qeth_channel *) data;
493         iob = channel->iob;
494         index = channel->buf_no;
495         card = CARD_FROM_CDEV(channel->ccwdev);
496         while (iob[index].state == BUF_STATE_PROCESSED) {
497                 if (iob[index].callback !=NULL) {
498                         iob[index].callback(channel,iob + index);
499                 }
500                 index = (index + 1) % QETH_CMD_BUFFER_NO;
501         }
502         channel->buf_no = index;
503         wake_up(&card->wait_q);
504 }
505
506 static int qeth_stop_card(struct qeth_card *, int);
507
508 static int
509 __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
510 {
511         struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
512         int rc = 0, rc2 = 0, rc3 = 0;
513         enum qeth_card_states recover_flag;
514
515         QETH_DBF_TEXT(setup, 3, "setoffl");
516         QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
517
518         if (card->dev && netif_carrier_ok(card->dev))
519                 netif_carrier_off(card->dev);
520         recover_flag = card->state;
521         if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
522                 PRINT_WARN("Stopping card %s interrupted by user!\n",
523                            CARD_BUS_ID(card));
524                 return -ERESTARTSYS;
525         }
526         rc  = ccw_device_set_offline(CARD_DDEV(card));
527         rc2 = ccw_device_set_offline(CARD_WDEV(card));
528         rc3 = ccw_device_set_offline(CARD_RDEV(card));
529         if (!rc)
530                 rc = (rc2) ? rc2 : rc3;
531         if (rc)
532                 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
533         if (recover_flag == CARD_STATE_UP)
534                 card->state = CARD_STATE_RECOVER;
535         qeth_notify_processes();
536         return 0;
537 }
538
539 static int
540 qeth_set_offline(struct ccwgroup_device *cgdev)
541 {
542         return  __qeth_set_offline(cgdev, 0);
543 }
544
545 static int
546 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads);
547
548
549 static void
550 qeth_remove_device(struct ccwgroup_device *cgdev)
551 {
552         struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
553         unsigned long flags;
554
555         QETH_DBF_TEXT(setup, 3, "rmdev");
556         QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
557
558         if (!card)
559                 return;
560
561         if (qeth_wait_for_threads(card, 0xffffffff))
562                 return;
563
564         if (cgdev->state == CCWGROUP_ONLINE){
565                 card->use_hard_stop = 1;
566                 qeth_set_offline(cgdev);
567         }
568         /* remove form our internal list */
569         write_lock_irqsave(&qeth_card_list.rwlock, flags);
570         list_del(&card->list);
571         write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
572         if (card->dev)
573                 unregister_netdev(card->dev);
574         qeth_remove_device_attributes(&cgdev->dev);
575         qeth_free_card(card);
576         cgdev->dev.driver_data = NULL;
577         put_device(&cgdev->dev);
578 }
579
580 static int
581 qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
582 static int
583 qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
584
585 /**
586  * Add/remove address to/from card's ip list, i.e. try to add or remove
587  * reference to/from an IP address that is already registered on the card.
588  * Returns:
589  *      0  address was on card and its reference count has been adjusted,
590  *         but is still > 0, so nothing has to be done
591  *         also returns 0 if card was not on card and the todo was to delete
592  *         the address -> there is also nothing to be done
593  *      1  address was not on card and the todo is to add it to the card's ip
594  *         list
595  *      -1 address was on card and its reference count has been decremented
596  *         to <= 0 by the todo -> address must be removed from card
597  */
598 static int
599 __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
600                       struct qeth_ipaddr **__addr)
601 {
602         struct qeth_ipaddr *addr;
603         int found = 0;
604
605         list_for_each_entry(addr, &card->ip_list, entry) {
606                 if (card->options.layer2) {
607                         if ((addr->type == todo->type) &&
608                             (memcmp(&addr->mac, &todo->mac,
609                                     OSA_ADDR_LEN) == 0)) {
610                                 found = 1;
611                                 break;
612                         }
613                         continue;
614                 }
615                 if ((addr->proto     == QETH_PROT_IPV4)  &&
616                     (todo->proto     == QETH_PROT_IPV4)  &&
617                     (addr->type      == todo->type)      &&
618                     (addr->u.a4.addr == todo->u.a4.addr) &&
619                     (addr->u.a4.mask == todo->u.a4.mask)) {
620                         found = 1;
621                         break;
622                 }
623                 if ((addr->proto       == QETH_PROT_IPV6)     &&
624                     (todo->proto       == QETH_PROT_IPV6)     &&
625                     (addr->type        == todo->type)         &&
626                     (addr->u.a6.pfxlen == todo->u.a6.pfxlen)  &&
627                     (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
628                             sizeof(struct in6_addr)) == 0)) {
629                         found = 1;
630                         break;
631                 }
632         }
633         if (found) {
634                 addr->users += todo->users;
635                 if (addr->users <= 0){
636                         *__addr = addr;
637                         return -1;
638                 } else {
639                         /* for VIPA and RXIP limit refcount to 1 */
640                         if (addr->type != QETH_IP_TYPE_NORMAL)
641                                 addr->users = 1;
642                         return 0;
643                 }
644         }
645         if (todo->users > 0) {
646                 /* for VIPA and RXIP limit refcount to 1 */
647                 if (todo->type != QETH_IP_TYPE_NORMAL)
648                         todo->users = 1;
649                 return 1;
650         } else
651                 return 0;
652 }
653
654 static int
655 __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
656                               int same_type)
657 {
658         struct qeth_ipaddr *tmp;
659
660         list_for_each_entry(tmp, list, entry) {
661                 if ((tmp->proto     == QETH_PROT_IPV4)            &&
662                     (addr->proto    == QETH_PROT_IPV4)            &&
663                     ((same_type && (tmp->type == addr->type)) ||
664                      (!same_type && (tmp->type != addr->type))  ) &&
665                     (tmp->u.a4.addr == addr->u.a4.addr)             ){
666                         return 1;
667                 }
668                 if ((tmp->proto  == QETH_PROT_IPV6)               &&
669                     (addr->proto == QETH_PROT_IPV6)               &&
670                     ((same_type && (tmp->type == addr->type)) ||
671                      (!same_type && (tmp->type != addr->type))  ) &&
672                     (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
673                             sizeof(struct in6_addr)) == 0)          ) {
674                         return 1;
675                 }
676         }
677         return 0;
678 }
679
680 /*
681  * Add IP to be added to todo list. If there is already an "add todo"
682  * in this list we just incremenent the reference count.
683  * Returns 0 if we  just incremented reference count.
684  */
685 static int
686 __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
687 {
688         struct qeth_ipaddr *tmp, *t;
689         int found = 0;
690
691         list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
692                 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
693                     (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
694                         return 0;
695                 if (card->options.layer2) {
696                         if ((tmp->type  == addr->type)  &&
697                             (tmp->is_multicast == addr->is_multicast) &&
698                             (memcmp(&tmp->mac, &addr->mac,
699                                     OSA_ADDR_LEN) == 0)) {
700                                 found = 1;
701                                 break;
702                         }
703                         continue;
704                 }
705                 if ((tmp->proto        == QETH_PROT_IPV4)     &&
706                     (addr->proto       == QETH_PROT_IPV4)     &&
707                     (tmp->type         == addr->type)         &&
708                     (tmp->is_multicast == addr->is_multicast) &&
709                     (tmp->u.a4.addr    == addr->u.a4.addr)    &&
710                     (tmp->u.a4.mask    == addr->u.a4.mask)) {
711                         found = 1;
712                         break;
713                 }
714                 if ((tmp->proto        == QETH_PROT_IPV6)      &&
715                     (addr->proto       == QETH_PROT_IPV6)      &&
716                     (tmp->type         == addr->type)          &&
717                     (tmp->is_multicast == addr->is_multicast)  &&
718                     (tmp->u.a6.pfxlen  == addr->u.a6.pfxlen)   &&
719                     (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
720                             sizeof(struct in6_addr)) == 0)) {
721                         found = 1;
722                         break;
723                 }
724         }
725         if (found){
726                 if (addr->users != 0)
727                         tmp->users += addr->users;
728                 else
729                         tmp->users += add? 1:-1;
730                 if (tmp->users == 0) {
731                         list_del(&tmp->entry);
732                         kfree(tmp);
733                 }
734                 return 0;
735         } else {
736                 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
737                         list_add(&addr->entry, card->ip_tbd_list);
738                 else {
739                         if (addr->users == 0)
740                                 addr->users += add? 1:-1;
741                         if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
742                             qeth_is_addr_covered_by_ipato(card, addr)){
743                                 QETH_DBF_TEXT(trace, 2, "tkovaddr");
744                                 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
745                         }
746                         list_add_tail(&addr->entry, card->ip_tbd_list);
747                 }
748                 return 1;
749         }
750 }
751
752 /**
753  * Remove IP address from list
754  */
755 static int
756 qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
757 {
758         unsigned long flags;
759         int rc = 0;
760
761         QETH_DBF_TEXT(trace, 4, "delip");
762
763         if (card->options.layer2)
764                 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
765         else if (addr->proto == QETH_PROT_IPV4)
766                 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
767         else {
768                 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
769                 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
770         }
771         spin_lock_irqsave(&card->ip_lock, flags);
772         rc = __qeth_insert_ip_todo(card, addr, 0);
773         spin_unlock_irqrestore(&card->ip_lock, flags);
774         return rc;
775 }
776
777 static int
778 qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
779 {
780         unsigned long flags;
781         int rc = 0;
782
783         QETH_DBF_TEXT(trace, 4, "addip");
784         if (card->options.layer2)
785                 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
786         else if (addr->proto == QETH_PROT_IPV4)
787                 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
788         else {
789                 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
790                 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
791         }
792         spin_lock_irqsave(&card->ip_lock, flags);
793         rc = __qeth_insert_ip_todo(card, addr, 1);
794         spin_unlock_irqrestore(&card->ip_lock, flags);
795         return rc;
796 }
797
798 static void
799 __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
800 {
801         struct qeth_ipaddr *addr, *tmp;
802         int rc;
803 again:
804         list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
805                 if (addr->is_multicast) {
806                         spin_unlock_irqrestore(&card->ip_lock, *flags);
807                         rc = qeth_deregister_addr_entry(card, addr);
808                         spin_lock_irqsave(&card->ip_lock, *flags);
809                         if (!rc) {
810                                 list_del(&addr->entry);
811                                 kfree(addr);
812                                 goto again;
813                         }
814                 }
815         }
816 }
817
818 static void
819 qeth_set_ip_addr_list(struct qeth_card *card)
820 {
821         struct list_head *tbd_list;
822         struct qeth_ipaddr *todo, *addr;
823         unsigned long flags;
824         int rc;
825
826         QETH_DBF_TEXT(trace, 2, "sdiplist");
827         QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
828
829         spin_lock_irqsave(&card->ip_lock, flags);
830         tbd_list = card->ip_tbd_list;
831         card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
832         if (!card->ip_tbd_list) {
833                 QETH_DBF_TEXT(trace, 0, "silnomem");
834                 card->ip_tbd_list = tbd_list;
835                 spin_unlock_irqrestore(&card->ip_lock, flags);
836                 return;
837         } else
838                 INIT_LIST_HEAD(card->ip_tbd_list);
839
840         while (!list_empty(tbd_list)){
841                 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
842                 list_del(&todo->entry);
843                 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
844                         __qeth_delete_all_mc(card, &flags);
845                         kfree(todo);
846                         continue;
847                 }
848                 rc = __qeth_ref_ip_on_card(card, todo, &addr);
849                 if (rc == 0) {
850                         /* nothing to be done; only adjusted refcount */
851                         kfree(todo);
852                 } else if (rc == 1) {
853                         /* new entry to be added to on-card list */
854                         spin_unlock_irqrestore(&card->ip_lock, flags);
855                         rc = qeth_register_addr_entry(card, todo);
856                         spin_lock_irqsave(&card->ip_lock, flags);
857                         if (!rc)
858                                 list_add_tail(&todo->entry, &card->ip_list);
859                         else
860                                 kfree(todo);
861                 } else if (rc == -1) {
862                         /* on-card entry to be removed */
863                         list_del_init(&addr->entry);
864                         spin_unlock_irqrestore(&card->ip_lock, flags);
865                         rc = qeth_deregister_addr_entry(card, addr);
866                         spin_lock_irqsave(&card->ip_lock, flags);
867                         if (!rc)
868                                 kfree(addr);
869                         else
870                                 list_add_tail(&addr->entry, &card->ip_list);
871                         kfree(todo);
872                 }
873         }
874         spin_unlock_irqrestore(&card->ip_lock, flags);
875         kfree(tbd_list);
876 }
877
878 static void qeth_delete_mc_addresses(struct qeth_card *);
879 static void qeth_add_multicast_ipv4(struct qeth_card *);
880 static void qeth_layer2_add_multicast(struct qeth_card *);
881 #ifdef CONFIG_QETH_IPV6
882 static void qeth_add_multicast_ipv6(struct qeth_card *);
883 #endif
884
885 static int
886 qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
887 {
888         unsigned long flags;
889
890         spin_lock_irqsave(&card->thread_mask_lock, flags);
891         if ( !(card->thread_allowed_mask & thread) ||
892               (card->thread_start_mask & thread) ) {
893                 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
894                 return -EPERM;
895         }
896         card->thread_start_mask |= thread;
897         spin_unlock_irqrestore(&card->thread_mask_lock, flags);
898         return 0;
899 }
900
901 static void
902 qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
903 {
904         unsigned long flags;
905
906         spin_lock_irqsave(&card->thread_mask_lock, flags);
907         card->thread_start_mask &= ~thread;
908         spin_unlock_irqrestore(&card->thread_mask_lock, flags);
909         wake_up(&card->wait_q);
910 }
911
912 static void
913 qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
914 {
915         unsigned long flags;
916
917         spin_lock_irqsave(&card->thread_mask_lock, flags);
918         card->thread_running_mask &= ~thread;
919         spin_unlock_irqrestore(&card->thread_mask_lock, flags);
920         wake_up(&card->wait_q);
921 }
922
923 static int
924 __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
925 {
926         unsigned long flags;
927         int rc = 0;
928
929         spin_lock_irqsave(&card->thread_mask_lock, flags);
930         if (card->thread_start_mask & thread){
931                 if ((card->thread_allowed_mask & thread) &&
932                     !(card->thread_running_mask & thread)){
933                         rc = 1;
934                         card->thread_start_mask &= ~thread;
935                         card->thread_running_mask |= thread;
936                 } else
937                         rc = -EPERM;
938         }
939         spin_unlock_irqrestore(&card->thread_mask_lock, flags);
940         return rc;
941 }
942
943 static int
944 qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
945 {
946         int rc = 0;
947
948         wait_event(card->wait_q,
949                    (rc = __qeth_do_run_thread(card, thread)) >= 0);
950         return rc;
951 }
952
953 static int
954 qeth_recover(void *ptr)
955 {
956         struct qeth_card *card;
957         int rc = 0;
958
959         card = (struct qeth_card *) ptr;
960         daemonize("qeth_recover");
961         QETH_DBF_TEXT(trace,2,"recover1");
962         QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
963         if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
964                 return 0;
965         QETH_DBF_TEXT(trace,2,"recover2");
966         PRINT_WARN("Recovery of device %s started ...\n",
967                    CARD_BUS_ID(card));
968         card->use_hard_stop = 1;
969         __qeth_set_offline(card->gdev,1);
970         rc = __qeth_set_online(card->gdev,1);
971         if (!rc)
972                 PRINT_INFO("Device %s successfully recovered!\n",
973                            CARD_BUS_ID(card));
974         else
975                 PRINT_INFO("Device %s could not be recovered!\n",
976                            CARD_BUS_ID(card));
977         /* don't run another scheduled recovery */
978         qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
979         qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
980         return 0;
981 }
982
983 void
984 qeth_schedule_recovery(struct qeth_card *card)
985 {
986         QETH_DBF_TEXT(trace,2,"startrec");
987         if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
988                 schedule_work(&card->kernel_thread_starter);
989 }
990
991 static int
992 qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
993 {
994         unsigned long flags;
995         int rc = 0;
996
997         spin_lock_irqsave(&card->thread_mask_lock, flags);
998         QETH_DBF_TEXT_(trace, 4, "  %02x%02x%02x",
999                         (u8) card->thread_start_mask,
1000                         (u8) card->thread_allowed_mask,
1001                         (u8) card->thread_running_mask);
1002         rc = (card->thread_start_mask & thread);
1003         spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1004         return rc;
1005 }
1006
1007 static void
1008 qeth_start_kernel_thread(struct work_struct *work)
1009 {
1010         struct qeth_card *card = container_of(work, struct qeth_card, kernel_thread_starter);
1011         QETH_DBF_TEXT(trace , 2, "strthrd");
1012
1013         if (card->read.state != CH_STATE_UP &&
1014             card->write.state != CH_STATE_UP)
1015                 return;
1016         if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1017                 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1018 }
1019
1020
1021 static void
1022 qeth_set_intial_options(struct qeth_card *card)
1023 {
1024         card->options.route4.type = NO_ROUTER;
1025 #ifdef CONFIG_QETH_IPV6
1026         card->options.route6.type = NO_ROUTER;
1027 #endif /* QETH_IPV6 */
1028         card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1029         card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1030         card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1031         card->options.fake_broadcast = 0;
1032         card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1033         card->options.fake_ll = 0;
1034         if (card->info.type == QETH_CARD_TYPE_OSN)
1035                 card->options.layer2 = 1;
1036         else
1037                 card->options.layer2 = 0;
1038         card->options.performance_stats = 0;
1039 }
1040
1041 /**
1042  * initialize channels ,card and all state machines
1043  */
1044 static int
1045 qeth_setup_card(struct qeth_card *card)
1046 {
1047
1048         QETH_DBF_TEXT(setup, 2, "setupcrd");
1049         QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1050
1051         card->read.state  = CH_STATE_DOWN;
1052         card->write.state = CH_STATE_DOWN;
1053         card->data.state  = CH_STATE_DOWN;
1054         card->state = CARD_STATE_DOWN;
1055         card->lan_online = 0;
1056         card->use_hard_stop = 0;
1057         card->dev = NULL;
1058 #ifdef CONFIG_QETH_VLAN
1059         spin_lock_init(&card->vlanlock);
1060         card->vlangrp = NULL;
1061 #endif
1062         spin_lock_init(&card->lock);
1063         spin_lock_init(&card->ip_lock);
1064         spin_lock_init(&card->thread_mask_lock);
1065         card->thread_start_mask = 0;
1066         card->thread_allowed_mask = 0;
1067         card->thread_running_mask = 0;
1068         INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1069         INIT_LIST_HEAD(&card->ip_list);
1070         card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1071         if (!card->ip_tbd_list) {
1072                 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1073                 return -ENOMEM;
1074         }
1075         INIT_LIST_HEAD(card->ip_tbd_list);
1076         INIT_LIST_HEAD(&card->cmd_waiter_list);
1077         init_waitqueue_head(&card->wait_q);
1078         /* intial options */
1079         qeth_set_intial_options(card);
1080         /* IP address takeover */
1081         INIT_LIST_HEAD(&card->ipato.entries);
1082         card->ipato.enabled = 0;
1083         card->ipato.invert4 = 0;
1084         card->ipato.invert6 = 0;
1085         /* init QDIO stuff */
1086         qeth_init_qdio_info(card);
1087         return 0;
1088 }
1089
1090 static int
1091 is_1920_device (struct qeth_card *card)
1092 {
1093         int single_queue = 0;
1094         struct ccw_device *ccwdev;
1095         struct channelPath_dsc {
1096                 u8 flags;
1097                 u8 lsn;
1098                 u8 desc;
1099                 u8 chpid;
1100                 u8 swla;
1101                 u8 zeroes;
1102                 u8 chla;
1103                 u8 chpp;
1104         } *chp_dsc;
1105
1106         QETH_DBF_TEXT(setup, 2, "chk_1920");
1107
1108         ccwdev = card->data.ccwdev;
1109         chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1110         if (chp_dsc != NULL) {
1111                 /* CHPP field bit 6 == 1 -> single queue */
1112                 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1113                 kfree(chp_dsc);
1114         }
1115         QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1116         return single_queue;
1117 }
1118
1119 static int
1120 qeth_determine_card_type(struct qeth_card *card)
1121 {
1122         int i = 0;
1123
1124         QETH_DBF_TEXT(setup, 2, "detcdtyp");
1125
1126         card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1127         card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1128         while (known_devices[i][4]) {
1129                 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1130                     (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1131                         card->info.type = known_devices[i][4];
1132                         card->qdio.no_out_queues = known_devices[i][8];
1133                         card->info.is_multicast_different = known_devices[i][9];
1134                         if (is_1920_device(card)) {
1135                                 PRINT_INFO("Priority Queueing not able "
1136                                            "due to hardware limitations!\n");
1137                                 card->qdio.no_out_queues = 1;
1138                                 card->qdio.default_out_queue = 0;
1139                         }
1140                         return 0;
1141                 }
1142                 i++;
1143         }
1144         card->info.type = QETH_CARD_TYPE_UNKNOWN;
1145         PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1146         return -ENOENT;
1147 }
1148
1149 static int
1150 qeth_probe_device(struct ccwgroup_device *gdev)
1151 {
1152         struct qeth_card *card;
1153         struct device *dev;
1154         unsigned long flags;
1155         int rc;
1156
1157         QETH_DBF_TEXT(setup, 2, "probedev");
1158
1159         dev = &gdev->dev;
1160         if (!get_device(dev))
1161                 return -ENODEV;
1162
1163         QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
1164
1165         card = qeth_alloc_card();
1166         if (!card) {
1167                 put_device(dev);
1168                 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1169                 return -ENOMEM;
1170         }
1171         card->read.ccwdev  = gdev->cdev[0];
1172         card->write.ccwdev = gdev->cdev[1];
1173         card->data.ccwdev  = gdev->cdev[2];
1174         gdev->dev.driver_data = card;
1175         card->gdev = gdev;
1176         gdev->cdev[0]->handler = qeth_irq;
1177         gdev->cdev[1]->handler = qeth_irq;
1178         gdev->cdev[2]->handler = qeth_irq;
1179
1180         if ((rc = qeth_determine_card_type(card))){
1181                 PRINT_WARN("%s: not a valid card type\n", __func__);
1182                 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1183                 put_device(dev);
1184                 qeth_free_card(card);
1185                 return rc;
1186         }
1187         if ((rc = qeth_setup_card(card))){
1188                 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1189                 put_device(dev);
1190                 qeth_free_card(card);
1191                 return rc;
1192         }
1193         rc = qeth_create_device_attributes(dev);
1194         if (rc) {
1195                 put_device(dev);
1196                 qeth_free_card(card);
1197                 return rc;
1198         }
1199         /* insert into our internal list */
1200         write_lock_irqsave(&qeth_card_list.rwlock, flags);
1201         list_add_tail(&card->list, &qeth_card_list.list);
1202         write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1203         return rc;
1204 }
1205
1206
1207 static int
1208 qeth_get_unitaddr(struct qeth_card *card)
1209 {
1210         int length;
1211         char *prcd;
1212         int rc;
1213
1214         QETH_DBF_TEXT(setup, 2, "getunit");
1215         rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length);
1216         if (rc) {
1217                 PRINT_ERR("read_conf_data for device %s returned %i\n",
1218                           CARD_DDEV_ID(card), rc);
1219                 return rc;
1220         }
1221         card->info.chpid = prcd[30];
1222         card->info.unit_addr2 = prcd[31];
1223         card->info.cula = prcd[63];
1224         card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1225                                (prcd[0x11] == _ascebc['M']));
1226         return 0;
1227 }
1228
1229 static void
1230 qeth_init_tokens(struct qeth_card *card)
1231 {
1232         card->token.issuer_rm_w = 0x00010103UL;
1233         card->token.cm_filter_w = 0x00010108UL;
1234         card->token.cm_connection_w = 0x0001010aUL;
1235         card->token.ulp_filter_w = 0x0001010bUL;
1236         card->token.ulp_connection_w = 0x0001010dUL;
1237 }
1238
1239 static inline __u16
1240 raw_devno_from_bus_id(char *id)
1241 {
1242         id += (strlen(id) - 4);
1243         return (__u16) simple_strtoul(id, &id, 16);
1244 }
1245 /**
1246  * setup channel
1247  */
1248 static void
1249 qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1250 {
1251         struct qeth_card *card;
1252
1253         QETH_DBF_TEXT(trace, 4, "setupccw");
1254         card = CARD_FROM_CDEV(channel->ccwdev);
1255         if (channel == &card->read)
1256                 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1257         else
1258                 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1259         channel->ccw.count = len;
1260         channel->ccw.cda = (__u32) __pa(iob);
1261 }
1262
1263 /**
1264  * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1265  */
1266 static struct qeth_cmd_buffer *
1267 __qeth_get_buffer(struct qeth_channel *channel)
1268 {
1269         __u8 index;
1270
1271         QETH_DBF_TEXT(trace, 6, "getbuff");
1272         index = channel->io_buf_no;
1273         do {
1274                 if (channel->iob[index].state == BUF_STATE_FREE) {
1275                         channel->iob[index].state = BUF_STATE_LOCKED;
1276                         channel->io_buf_no = (channel->io_buf_no + 1) %
1277                                 QETH_CMD_BUFFER_NO;
1278                         memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1279                         return channel->iob + index;
1280                 }
1281                 index = (index + 1) % QETH_CMD_BUFFER_NO;
1282         } while(index != channel->io_buf_no);
1283
1284         return NULL;
1285 }
1286
1287 /**
1288  * release command buffer
1289  */
1290 static void
1291 qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1292 {
1293         unsigned long flags;
1294
1295         QETH_DBF_TEXT(trace, 6, "relbuff");
1296         spin_lock_irqsave(&channel->iob_lock, flags);
1297         memset(iob->data, 0, QETH_BUFSIZE);
1298         iob->state = BUF_STATE_FREE;
1299         iob->callback = qeth_send_control_data_cb;
1300         iob->rc = 0;
1301         spin_unlock_irqrestore(&channel->iob_lock, flags);
1302 }
1303
1304 static struct qeth_cmd_buffer *
1305 qeth_get_buffer(struct qeth_channel *channel)
1306 {
1307         struct qeth_cmd_buffer *buffer = NULL;
1308         unsigned long flags;
1309
1310         spin_lock_irqsave(&channel->iob_lock, flags);
1311         buffer = __qeth_get_buffer(channel);
1312         spin_unlock_irqrestore(&channel->iob_lock, flags);
1313         return buffer;
1314 }
1315
1316 static struct qeth_cmd_buffer *
1317 qeth_wait_for_buffer(struct qeth_channel *channel)
1318 {
1319         struct qeth_cmd_buffer *buffer;
1320         wait_event(channel->wait_q,
1321                    ((buffer = qeth_get_buffer(channel)) != NULL));
1322         return buffer;
1323 }
1324
1325 static void
1326 qeth_clear_cmd_buffers(struct qeth_channel *channel)
1327 {
1328         int cnt;
1329
1330         for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1331                 qeth_release_buffer(channel,&channel->iob[cnt]);
1332         channel->buf_no = 0;
1333         channel->io_buf_no = 0;
1334 }
1335
1336 /**
1337  * start IDX for read and write channel
1338  */
1339 static int
1340 qeth_idx_activate_get_answer(struct qeth_channel *channel,
1341                               void (*idx_reply_cb)(struct qeth_channel *,
1342                                                    struct qeth_cmd_buffer *))
1343 {
1344         struct qeth_cmd_buffer *iob;
1345         unsigned long flags;
1346         int rc;
1347         struct qeth_card *card;
1348
1349         QETH_DBF_TEXT(setup, 2, "idxanswr");
1350         card = CARD_FROM_CDEV(channel->ccwdev);
1351         iob = qeth_get_buffer(channel);
1352         iob->callback = idx_reply_cb;
1353         memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1354         channel->ccw.count = QETH_BUFSIZE;
1355         channel->ccw.cda = (__u32) __pa(iob->data);
1356
1357         wait_event(card->wait_q,
1358                    atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1359         QETH_DBF_TEXT(setup, 6, "noirqpnd");
1360         spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1361         rc = ccw_device_start(channel->ccwdev,
1362                               &channel->ccw,(addr_t) iob, 0, 0);
1363         spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1364
1365         if (rc) {
1366                 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1367                 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1368                 atomic_set(&channel->irq_pending, 0);
1369                 wake_up(&card->wait_q);
1370                 return rc;
1371         }
1372         rc = wait_event_interruptible_timeout(card->wait_q,
1373                          channel->state == CH_STATE_UP, QETH_TIMEOUT);
1374         if (rc == -ERESTARTSYS)
1375                 return rc;
1376         if (channel->state != CH_STATE_UP){
1377                 rc = -ETIME;
1378                 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1379                 qeth_clear_cmd_buffers(channel);
1380         } else
1381                 rc = 0;
1382         return rc;
1383 }
1384
1385 static int
1386 qeth_idx_activate_channel(struct qeth_channel *channel,
1387                            void (*idx_reply_cb)(struct qeth_channel *,
1388                                                 struct qeth_cmd_buffer *))
1389 {
1390         struct qeth_card *card;
1391         struct qeth_cmd_buffer *iob;
1392         unsigned long flags;
1393         __u16 temp;
1394         int rc;
1395
1396         card = CARD_FROM_CDEV(channel->ccwdev);
1397
1398         QETH_DBF_TEXT(setup, 2, "idxactch");
1399
1400         iob = qeth_get_buffer(channel);
1401         iob->callback = idx_reply_cb;
1402         memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1403         channel->ccw.count = IDX_ACTIVATE_SIZE;
1404         channel->ccw.cda = (__u32) __pa(iob->data);
1405         if (channel == &card->write) {
1406                 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1407                 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1408                        &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1409                 card->seqno.trans_hdr++;
1410         } else {
1411                 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1412                 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1413                        &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1414         }
1415         memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1416                &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1417         memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1418                &card->info.func_level,sizeof(__u16));
1419         temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1420         memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1421         temp = (card->info.cula << 8) + card->info.unit_addr2;
1422         memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1423
1424         wait_event(card->wait_q,
1425                    atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1426         QETH_DBF_TEXT(setup, 6, "noirqpnd");
1427         spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1428         rc = ccw_device_start(channel->ccwdev,
1429                               &channel->ccw,(addr_t) iob, 0, 0);
1430         spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1431
1432         if (rc) {
1433                 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1434                 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1435                 atomic_set(&channel->irq_pending, 0);
1436                 wake_up(&card->wait_q);
1437                 return rc;
1438         }
1439         rc = wait_event_interruptible_timeout(card->wait_q,
1440                         channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1441         if (rc == -ERESTARTSYS)
1442                 return rc;
1443         if (channel->state != CH_STATE_ACTIVATING) {
1444                 PRINT_WARN("qeth: IDX activate timed out!\n");
1445                 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1446                 qeth_clear_cmd_buffers(channel);
1447                 return -ETIME;
1448         }
1449         return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1450 }
1451
1452 static int
1453 qeth_peer_func_level(int level)
1454 {
1455         if ((level & 0xff) == 8)
1456                 return (level & 0xff) + 0x400;
1457         if (((level >> 8) & 3) == 1)
1458                 return (level & 0xff) + 0x200;
1459         return level;
1460 }
1461
1462 static void
1463 qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1464 {
1465         struct qeth_card *card;
1466         __u16 temp;
1467
1468         QETH_DBF_TEXT(setup ,2, "idxwrcb");
1469
1470         if (channel->state == CH_STATE_DOWN) {
1471                 channel->state = CH_STATE_ACTIVATING;
1472                 goto out;
1473         }
1474         card = CARD_FROM_CDEV(channel->ccwdev);
1475
1476         if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1477                 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1478                           "reply\n", CARD_WDEV_ID(card));
1479                 goto out;
1480         }
1481         memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1482         if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1483                 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1484                            "function level mismatch "
1485                            "(sent: 0x%x, received: 0x%x)\n",
1486                            CARD_WDEV_ID(card), card->info.func_level, temp);
1487                 goto out;
1488         }
1489         channel->state = CH_STATE_UP;
1490 out:
1491         qeth_release_buffer(channel, iob);
1492 }
1493
1494 static int
1495 qeth_check_idx_response(unsigned char *buffer)
1496 {
1497         if (!buffer)
1498                 return 0;
1499
1500         QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1501         if ((buffer[2] & 0xc0) == 0xc0) {
1502                 PRINT_WARN("received an IDX TERMINATE "
1503                            "with cause code 0x%02x%s\n",
1504                            buffer[4],
1505                            ((buffer[4] == 0x22) ?
1506                             " -- try another portname" : ""));
1507                 QETH_DBF_TEXT(trace, 2, "ckidxres");
1508                 QETH_DBF_TEXT(trace, 2, " idxterm");
1509                 QETH_DBF_TEXT_(trace, 2, "  rc%d", -EIO);
1510                 return -EIO;
1511         }
1512         return 0;
1513 }
1514
1515 static void
1516 qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1517 {
1518         struct qeth_card *card;
1519         __u16 temp;
1520
1521         QETH_DBF_TEXT(setup , 2, "idxrdcb");
1522         if (channel->state == CH_STATE_DOWN) {
1523                 channel->state = CH_STATE_ACTIVATING;
1524                 goto out;
1525         }
1526
1527         card = CARD_FROM_CDEV(channel->ccwdev);
1528         if (qeth_check_idx_response(iob->data)) {
1529                         goto out;
1530         }
1531         if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1532                 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1533                           "reply\n", CARD_RDEV_ID(card));
1534                 goto out;
1535         }
1536
1537 /**
1538  * temporary fix for microcode bug
1539  * to revert it,replace OR by AND
1540  */
1541         if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1542              (card->info.type == QETH_CARD_TYPE_OSAE) )
1543                 card->info.portname_required = 1;
1544
1545         memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1546         if (temp != qeth_peer_func_level(card->info.func_level)) {
1547                 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1548                            "level mismatch (sent: 0x%x, received: 0x%x)\n",
1549                            CARD_RDEV_ID(card), card->info.func_level, temp);
1550                 goto out;
1551         }
1552         memcpy(&card->token.issuer_rm_r,
1553                QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1554                QETH_MPC_TOKEN_LENGTH);
1555         memcpy(&card->info.mcl_level[0],
1556                QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1557         channel->state = CH_STATE_UP;
1558 out:
1559         qeth_release_buffer(channel,iob);
1560 }
1561
1562 static int
1563 qeth_issue_next_read(struct qeth_card *card)
1564 {
1565         int rc;
1566         struct qeth_cmd_buffer *iob;
1567
1568         QETH_DBF_TEXT(trace,5,"issnxrd");
1569         if (card->read.state != CH_STATE_UP)
1570                 return -EIO;
1571         iob = qeth_get_buffer(&card->read);
1572         if (!iob) {
1573                 PRINT_WARN("issue_next_read failed: no iob available!\n");
1574                 return -ENOMEM;
1575         }
1576         qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1577         QETH_DBF_TEXT(trace, 6, "noirqpnd");
1578         rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1579                               (addr_t) iob, 0, 0);
1580         if (rc) {
1581                 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1582                 atomic_set(&card->read.irq_pending, 0);
1583                 qeth_schedule_recovery(card);
1584                 wake_up(&card->wait_q);
1585         }
1586         return rc;
1587 }
1588
1589 static struct qeth_reply *
1590 qeth_alloc_reply(struct qeth_card *card)
1591 {
1592         struct qeth_reply *reply;
1593
1594         reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1595         if (reply){
1596                 atomic_set(&reply->refcnt, 1);
1597                 atomic_set(&reply->received, 0);
1598                 reply->card = card;
1599         };
1600         return reply;
1601 }
1602
1603 static void
1604 qeth_get_reply(struct qeth_reply *reply)
1605 {
1606         WARN_ON(atomic_read(&reply->refcnt) <= 0);
1607         atomic_inc(&reply->refcnt);
1608 }
1609
1610 static void
1611 qeth_put_reply(struct qeth_reply *reply)
1612 {
1613         WARN_ON(atomic_read(&reply->refcnt) <= 0);
1614         if (atomic_dec_and_test(&reply->refcnt))
1615                 kfree(reply);
1616 }
1617
1618 static struct qeth_ipa_cmd *
1619 qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1620 {
1621         struct qeth_ipa_cmd *cmd = NULL;
1622
1623         QETH_DBF_TEXT(trace,5,"chkipad");
1624         if (IS_IPA(iob->data)){
1625                 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1626                 if (IS_IPA_REPLY(cmd))
1627                         return cmd;
1628                 else {
1629                         switch (cmd->hdr.command) {
1630                         case IPA_CMD_STOPLAN:
1631                                 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1632                                            "there is a network problem or "
1633                                            "someone pulled the cable or "
1634                                            "disabled the port.\n",
1635                                            QETH_CARD_IFNAME(card),
1636                                            card->info.chpid);
1637                                 card->lan_online = 0;
1638                                 if (card->dev && netif_carrier_ok(card->dev))
1639                                         netif_carrier_off(card->dev);
1640                                 return NULL;
1641                         case IPA_CMD_STARTLAN:
1642                                 PRINT_INFO("Link reestablished on %s "
1643                                            "(CHPID 0x%X). Scheduling "
1644                                            "IP address reset.\n",
1645                                            QETH_CARD_IFNAME(card),
1646                                            card->info.chpid);
1647                                 netif_carrier_on(card->dev);
1648                                 qeth_schedule_recovery(card);
1649                                 return NULL;
1650                         case IPA_CMD_MODCCID:
1651                                 return cmd;
1652                         case IPA_CMD_REGISTER_LOCAL_ADDR:
1653                                 QETH_DBF_TEXT(trace,3, "irla");
1654                                 break;
1655                         case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1656                                 QETH_DBF_TEXT(trace,3, "urla");
1657                                 break;
1658                         default:
1659                                 PRINT_WARN("Received data is IPA "
1660                                            "but not a reply!\n");
1661                                 break;
1662                         }
1663                 }
1664         }
1665         return cmd;
1666 }
1667
1668 /**
1669  * wake all waiting ipa commands
1670  */
1671 static void
1672 qeth_clear_ipacmd_list(struct qeth_card *card)
1673 {
1674         struct qeth_reply *reply, *r;
1675         unsigned long flags;
1676
1677         QETH_DBF_TEXT(trace, 4, "clipalst");
1678
1679         spin_lock_irqsave(&card->lock, flags);
1680         list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1681                 qeth_get_reply(reply);
1682                 reply->rc = -EIO;
1683                 atomic_inc(&reply->received);
1684                 list_del_init(&reply->list);
1685                 wake_up(&reply->wait_q);
1686                 qeth_put_reply(reply);
1687         }
1688         spin_unlock_irqrestore(&card->lock, flags);
1689 }
1690
1691 static void
1692 qeth_send_control_data_cb(struct qeth_channel *channel,
1693                           struct qeth_cmd_buffer *iob)
1694 {
1695         struct qeth_card *card;
1696         struct qeth_reply *reply, *r;
1697         struct qeth_ipa_cmd *cmd;
1698         unsigned long flags;
1699         int keep_reply;
1700
1701         QETH_DBF_TEXT(trace,4,"sndctlcb");
1702
1703         card = CARD_FROM_CDEV(channel->ccwdev);
1704         if (qeth_check_idx_response(iob->data)) {
1705                 qeth_clear_ipacmd_list(card);
1706                 qeth_schedule_recovery(card);
1707                 goto out;
1708         }
1709
1710         cmd = qeth_check_ipa_data(card, iob);
1711         if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1712                 goto out;
1713         /*in case of OSN : check if cmd is set */
1714         if (card->info.type == QETH_CARD_TYPE_OSN &&
1715             cmd &&
1716             cmd->hdr.command != IPA_CMD_STARTLAN &&
1717             card->osn_info.assist_cb != NULL) {
1718                 card->osn_info.assist_cb(card->dev, cmd);
1719                 goto out;
1720         }
1721
1722         spin_lock_irqsave(&card->lock, flags);
1723         list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1724                 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1725                     ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1726                         qeth_get_reply(reply);
1727                         list_del_init(&reply->list);
1728                         spin_unlock_irqrestore(&card->lock, flags);
1729                         keep_reply = 0;
1730                         if (reply->callback != NULL) {
1731                                 if (cmd) {
1732                                         reply->offset = (__u16)((char*)cmd -
1733                                                                 (char *)iob->data);
1734                                         keep_reply = reply->callback(card,
1735                                                         reply,
1736                                                         (unsigned long)cmd);
1737                                 } else
1738                                         keep_reply = reply->callback(card,
1739                                                         reply,
1740                                                         (unsigned long)iob);
1741                         }
1742                         if (cmd)
1743                                 reply->rc = (u16) cmd->hdr.return_code;
1744                         else if (iob->rc)
1745                                 reply->rc = iob->rc;
1746                         if (keep_reply) {
1747                                 spin_lock_irqsave(&card->lock, flags);
1748                                 list_add_tail(&reply->list,
1749                                               &card->cmd_waiter_list);
1750                                 spin_unlock_irqrestore(&card->lock, flags);
1751                         } else {
1752                                 atomic_inc(&reply->received);
1753                                 wake_up(&reply->wait_q);
1754                         }
1755                         qeth_put_reply(reply);
1756                         goto out;
1757                 }
1758         }
1759         spin_unlock_irqrestore(&card->lock, flags);
1760 out:
1761         memcpy(&card->seqno.pdu_hdr_ack,
1762                 QETH_PDU_HEADER_SEQ_NO(iob->data),
1763                 QETH_SEQ_NO_LENGTH);
1764         qeth_release_buffer(channel,iob);
1765 }
1766
1767 static void
1768 qeth_prepare_control_data(struct qeth_card *card, int len,
1769                           struct qeth_cmd_buffer *iob)
1770 {
1771         qeth_setup_ccw(&card->write,iob->data,len);
1772         iob->callback = qeth_release_buffer;
1773
1774         memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1775                &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1776         card->seqno.trans_hdr++;
1777         memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1778                &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1779         card->seqno.pdu_hdr++;
1780         memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1781                &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1782         QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1783 }
1784
1785 static int
1786 qeth_send_control_data(struct qeth_card *card, int len,
1787                        struct qeth_cmd_buffer *iob,
1788                        int (*reply_cb)
1789                        (struct qeth_card *, struct qeth_reply*, unsigned long),
1790                        void *reply_param)
1791
1792 {
1793         int rc;
1794         unsigned long flags;
1795         struct qeth_reply *reply = NULL;
1796         unsigned long timeout;
1797
1798         QETH_DBF_TEXT(trace, 2, "sendctl");
1799
1800         reply = qeth_alloc_reply(card);
1801         if (!reply) {
1802                 PRINT_WARN("Could no alloc qeth_reply!\n");
1803                 return -ENOMEM;
1804         }
1805         reply->callback = reply_cb;
1806         reply->param = reply_param;
1807         if (card->state == CARD_STATE_DOWN)
1808                 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1809         else
1810                 reply->seqno = card->seqno.ipa++;
1811         init_waitqueue_head(&reply->wait_q);
1812         spin_lock_irqsave(&card->lock, flags);
1813         list_add_tail(&reply->list, &card->cmd_waiter_list);
1814         spin_unlock_irqrestore(&card->lock, flags);
1815         QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1816
1817         while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
1818         qeth_prepare_control_data(card, len, iob);
1819
1820         if (IS_IPA(iob->data))
1821                 timeout = jiffies + QETH_IPA_TIMEOUT;
1822         else
1823                 timeout = jiffies + QETH_TIMEOUT;
1824
1825         QETH_DBF_TEXT(trace, 6, "noirqpnd");
1826         spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1827         rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1828                               (addr_t) iob, 0, 0);
1829         spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1830         if (rc){
1831                 PRINT_WARN("qeth_send_control_data: "
1832                            "ccw_device_start rc = %i\n", rc);
1833                 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1834                 spin_lock_irqsave(&card->lock, flags);
1835                 list_del_init(&reply->list);
1836                 qeth_put_reply(reply);
1837                 spin_unlock_irqrestore(&card->lock, flags);
1838                 qeth_release_buffer(iob->channel, iob);
1839                 atomic_set(&card->write.irq_pending, 0);
1840                 wake_up(&card->wait_q);
1841                 return rc;
1842         }
1843         while (!atomic_read(&reply->received)) {
1844                 if (time_after(jiffies, timeout)) {
1845                         spin_lock_irqsave(&reply->card->lock, flags);
1846                         list_del_init(&reply->list);
1847                         spin_unlock_irqrestore(&reply->card->lock, flags);
1848                         reply->rc = -ETIME;
1849                         atomic_inc(&reply->received);
1850                         wake_up(&reply->wait_q);
1851                 }
1852         };
1853         rc = reply->rc;
1854         qeth_put_reply(reply);
1855         return rc;
1856 }
1857
1858 static int
1859 qeth_osn_send_control_data(struct qeth_card *card, int len,
1860                            struct qeth_cmd_buffer *iob)
1861 {
1862         unsigned long flags;
1863         int rc = 0;
1864
1865         QETH_DBF_TEXT(trace, 5, "osndctrd");
1866
1867         wait_event(card->wait_q,
1868                    atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1869         qeth_prepare_control_data(card, len, iob);
1870         QETH_DBF_TEXT(trace, 6, "osnoirqp");
1871         spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1872         rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1873                               (addr_t) iob, 0, 0);
1874         spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1875         if (rc){
1876                 PRINT_WARN("qeth_osn_send_control_data: "
1877                            "ccw_device_start rc = %i\n", rc);
1878                 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1879                 qeth_release_buffer(iob->channel, iob);
1880                 atomic_set(&card->write.irq_pending, 0);
1881                 wake_up(&card->wait_q);
1882         }
1883         return rc;
1884 }
1885
1886 static inline void
1887 qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1888                      char prot_type)
1889 {
1890         memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1891         memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1892         memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1893                &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1894 }
1895
1896 static int
1897 qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1898                       int data_len)
1899 {
1900         u16 s1, s2;
1901
1902         QETH_DBF_TEXT(trace,4,"osndipa");
1903
1904         qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1905         s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1906         s2 = (u16)data_len;
1907         memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1908         memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1909         memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1910         memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1911         return qeth_osn_send_control_data(card, s1, iob);
1912 }
1913
1914 static int
1915 qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1916                   int (*reply_cb)
1917                   (struct qeth_card *,struct qeth_reply*, unsigned long),
1918                   void *reply_param)
1919 {
1920         int rc;
1921         char prot_type;
1922
1923         QETH_DBF_TEXT(trace,4,"sendipa");
1924
1925         if (card->options.layer2)
1926                 if (card->info.type == QETH_CARD_TYPE_OSN)
1927                         prot_type = QETH_PROT_OSN2;
1928                 else
1929                         prot_type = QETH_PROT_LAYER2;
1930         else
1931                 prot_type = QETH_PROT_TCPIP;
1932         qeth_prepare_ipa_cmd(card,iob,prot_type);
1933         rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
1934                                     reply_cb, reply_param);
1935         return rc;
1936 }
1937
1938
1939 static int
1940 qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1941                   unsigned long data)
1942 {
1943         struct qeth_cmd_buffer *iob;
1944
1945         QETH_DBF_TEXT(setup, 2, "cmenblcb");
1946
1947         iob = (struct qeth_cmd_buffer *) data;
1948         memcpy(&card->token.cm_filter_r,
1949                QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
1950                QETH_MPC_TOKEN_LENGTH);
1951         QETH_DBF_TEXT_(setup, 2, "  rc%d", iob->rc);
1952         return 0;
1953 }
1954
1955 static int
1956 qeth_cm_enable(struct qeth_card *card)
1957 {
1958         int rc;
1959         struct qeth_cmd_buffer *iob;
1960
1961         QETH_DBF_TEXT(setup,2,"cmenable");
1962
1963         iob = qeth_wait_for_buffer(&card->write);
1964         memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
1965         memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
1966                &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1967         memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
1968                &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
1969
1970         rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
1971                                     qeth_cm_enable_cb, NULL);
1972         return rc;
1973 }
1974
1975 static int
1976 qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
1977                  unsigned long data)
1978 {
1979
1980         struct qeth_cmd_buffer *iob;
1981
1982         QETH_DBF_TEXT(setup, 2, "cmsetpcb");
1983
1984         iob = (struct qeth_cmd_buffer *) data;
1985         memcpy(&card->token.cm_connection_r,
1986                QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
1987                QETH_MPC_TOKEN_LENGTH);
1988         QETH_DBF_TEXT_(setup, 2, "  rc%d", iob->rc);
1989         return 0;
1990 }
1991
1992 static int
1993 qeth_cm_setup(struct qeth_card *card)
1994 {
1995         int rc;
1996         struct qeth_cmd_buffer *iob;
1997
1998         QETH_DBF_TEXT(setup,2,"cmsetup");
1999
2000         iob = qeth_wait_for_buffer(&card->write);
2001         memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2002         memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2003                &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2004         memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2005                &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2006         memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2007                &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2008         rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2009                                     qeth_cm_setup_cb, NULL);
2010         return rc;
2011
2012 }
2013
2014 static int
2015 qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2016                    unsigned long data)
2017 {
2018
2019         __u16 mtu, framesize;
2020         __u16 len;
2021         __u8 link_type;
2022         struct qeth_cmd_buffer *iob;
2023
2024         QETH_DBF_TEXT(setup, 2, "ulpenacb");
2025
2026         iob = (struct qeth_cmd_buffer *) data;
2027         memcpy(&card->token.ulp_filter_r,
2028                QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2029                QETH_MPC_TOKEN_LENGTH);
2030         if (qeth_get_mtu_out_of_mpc(card->info.type)) {
2031                 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2032                 mtu = qeth_get_mtu_outof_framesize(framesize);
2033                 if (!mtu) {
2034                         iob->rc = -EINVAL;
2035                         QETH_DBF_TEXT_(setup, 2, "  rc%d", iob->rc);
2036                         return 0;
2037                 }
2038                 card->info.max_mtu = mtu;
2039                 card->info.initial_mtu = mtu;
2040                 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2041         } else {
2042                 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2043                 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
2044                 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2045         }
2046
2047         memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2048         if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2049                 memcpy(&link_type,
2050                        QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2051                 card->info.link_type = link_type;
2052         } else
2053                 card->info.link_type = 0;
2054         QETH_DBF_TEXT_(setup, 2, "  rc%d", iob->rc);
2055         return 0;
2056 }
2057
2058 static int
2059 qeth_ulp_enable(struct qeth_card *card)
2060 {
2061         int rc;
2062         char prot_type;
2063         struct qeth_cmd_buffer *iob;
2064
2065         /*FIXME: trace view callbacks*/
2066         QETH_DBF_TEXT(setup,2,"ulpenabl");
2067
2068         iob = qeth_wait_for_buffer(&card->write);
2069         memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2070
2071         *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2072                 (__u8) card->info.portno;
2073         if (card->options.layer2)
2074                 if (card->info.type == QETH_CARD_TYPE_OSN)
2075                         prot_type = QETH_PROT_OSN2;
2076                 else
2077                         prot_type = QETH_PROT_LAYER2;
2078         else
2079                 prot_type = QETH_PROT_TCPIP;
2080
2081         memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2082         memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2083                &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2084         memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2085                &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2086         memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2087                card->info.portname, 9);
2088         rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2089                                     qeth_ulp_enable_cb, NULL);
2090         return rc;
2091
2092 }
2093
2094 static inline __u16
2095 __raw_devno_from_bus_id(char *id)
2096 {
2097         id += (strlen(id) - 4);
2098         return (__u16) simple_strtoul(id, &id, 16);
2099 }
2100
2101 static int
2102 qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2103                   unsigned long data)
2104 {
2105         struct qeth_cmd_buffer *iob;
2106
2107         QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2108
2109         iob = (struct qeth_cmd_buffer *) data;
2110         memcpy(&card->token.ulp_connection_r,
2111                QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2112                QETH_MPC_TOKEN_LENGTH);
2113         QETH_DBF_TEXT_(setup, 2, "  rc%d", iob->rc);
2114         return 0;
2115 }
2116
2117 static int
2118 qeth_ulp_setup(struct qeth_card *card)
2119 {
2120         int rc;
2121         __u16 temp;
2122         struct qeth_cmd_buffer *iob;
2123
2124         QETH_DBF_TEXT(setup,2,"ulpsetup");
2125
2126         iob = qeth_wait_for_buffer(&card->write);
2127         memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2128
2129         memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2130                &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2131         memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2132                &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2133         memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2134                &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2135
2136         temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card));
2137         memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2);
2138         temp = (card->info.cula << 8) + card->info.unit_addr2;
2139         memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2140         rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2141                                     qeth_ulp_setup_cb, NULL);
2142         return rc;
2143 }
2144
2145 static inline int
2146 qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2147                        unsigned int siga_error, const char *dbftext)
2148 {
2149         if (qdio_error || siga_error) {
2150                 QETH_DBF_TEXT(trace, 2, dbftext);
2151                 QETH_DBF_TEXT(qerr, 2, dbftext);
2152                 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
2153                                buf->element[15].flags & 0xff);
2154                 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
2155                                buf->element[14].flags & 0xff);
2156                 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2157                 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
2158                 return 1;
2159         }
2160         return 0;
2161 }
2162
2163 static struct sk_buff *
2164 qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
2165 {
2166         struct sk_buff* skb;
2167         int add_len;
2168
2169         add_len = 0;
2170         if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2171                 add_len = sizeof(struct qeth_hdr);
2172 #ifdef CONFIG_QETH_VLAN
2173         else
2174                 add_len = VLAN_HLEN;
2175 #endif
2176         skb = dev_alloc_skb(length + add_len);
2177         if (skb && add_len)
2178                 skb_reserve(skb, add_len);
2179         return skb;
2180 }
2181
2182 static struct sk_buff *
2183 qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2184                   struct qdio_buffer_element **__element, int *__offset,
2185                   struct qeth_hdr **hdr)
2186 {
2187         struct qdio_buffer_element *element = *__element;
2188         int offset = *__offset;
2189         struct sk_buff *skb = NULL;
2190         int skb_len;
2191         void *data_ptr;
2192         int data_len;
2193
2194         QETH_DBF_TEXT(trace,6,"nextskb");
2195         /* qeth_hdr must not cross element boundaries */
2196         if (element->length < offset + sizeof(struct qeth_hdr)){
2197                 if (qeth_is_last_sbale(element))
2198                         return NULL;
2199                 element++;
2200                 offset = 0;
2201                 if (element->length < sizeof(struct qeth_hdr))
2202                         return NULL;
2203         }
2204         *hdr = element->addr + offset;
2205
2206         offset += sizeof(struct qeth_hdr);
2207         if (card->options.layer2)
2208                 if (card->info.type == QETH_CARD_TYPE_OSN)
2209                         skb_len = (*hdr)->hdr.osn.pdu_length;
2210                 else
2211                         skb_len = (*hdr)->hdr.l2.pkt_length;
2212         else
2213                 skb_len = (*hdr)->hdr.l3.length;
2214
2215         if (!skb_len)
2216                 return NULL;
2217         if (card->options.fake_ll){
2218                 if(card->dev->type == ARPHRD_IEEE802_TR){
2219                         if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR, *hdr)))
2220                                 goto no_mem;
2221                         skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2222                 } else {
2223                         if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH, *hdr)))
2224                                 goto no_mem;
2225                         skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2226                 }
2227         } else if (!(skb = qeth_get_skb(skb_len, *hdr)))
2228                 goto no_mem;
2229         data_ptr = element->addr + offset;
2230         while (skb_len) {
2231                 data_len = min(skb_len, (int)(element->length - offset));
2232                 if (data_len)
2233                         memcpy(skb_put(skb, data_len), data_ptr, data_len);
2234                 skb_len -= data_len;
2235                 if (skb_len){
2236                         if (qeth_is_last_sbale(element)){
2237                                 QETH_DBF_TEXT(trace,4,"unexeob");
2238                                 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2239                                 QETH_DBF_TEXT(qerr,2,"unexeob");
2240                                 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2241                                 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2242                                 dev_kfree_skb_any(skb);
2243                                 card->stats.rx_errors++;
2244                                 return NULL;
2245                         }
2246                         element++;
2247                         offset = 0;
2248                         data_ptr = element->addr;
2249                 } else {
2250                         offset += data_len;
2251                 }
2252         }
2253         *__element = element;
2254         *__offset = offset;
2255         return skb;
2256 no_mem:
2257         if (net_ratelimit()){
2258                 PRINT_WARN("No memory for packet received on %s.\n",
2259                            QETH_CARD_IFNAME(card));
2260                 QETH_DBF_TEXT(trace,2,"noskbmem");
2261                 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2262         }
2263         card->stats.rx_dropped++;
2264         return NULL;
2265 }
2266
2267 static __be16
2268 qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2269 {
2270         struct qeth_card *card;
2271         struct ethhdr *eth;
2272
2273         QETH_DBF_TEXT(trace,6,"typtrans");
2274
2275         card = (struct qeth_card *)dev->priv;
2276 #ifdef CONFIG_TR
2277         if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2278             (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2279                 return tr_type_trans(skb,dev);
2280 #endif /* CONFIG_TR */
2281         skb_reset_mac_header(skb);
2282         skb_pull(skb, ETH_HLEN );
2283         eth = eth_hdr(skb);
2284
2285         if (*eth->h_dest & 1) {
2286                 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2287                         skb->pkt_type = PACKET_BROADCAST;
2288                 else
2289                         skb->pkt_type = PACKET_MULTICAST;
2290         } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2291                 skb->pkt_type = PACKET_OTHERHOST;
2292
2293         if (ntohs(eth->h_proto) >= 1536)
2294                 return eth->h_proto;
2295         if (*(unsigned short *) (skb->data) == 0xFFFF)
2296                 return htons(ETH_P_802_3);
2297         return htons(ETH_P_802_2);
2298 }
2299
2300 static void
2301 qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2302                          struct qeth_hdr *hdr)
2303 {
2304         struct trh_hdr *fake_hdr;
2305         struct trllc *fake_llc;
2306         struct iphdr *ip_hdr;
2307
2308         QETH_DBF_TEXT(trace,5,"skbfktr");
2309         skb_set_mac_header(skb, -QETH_FAKE_LL_LEN_TR);
2310         /* this is a fake ethernet header */
2311         fake_hdr = tr_hdr(skb);
2312
2313         /* the destination MAC address */
2314         switch (skb->pkt_type){
2315         case PACKET_MULTICAST:
2316                 switch (skb->protocol){
2317 #ifdef CONFIG_QETH_IPV6
2318                 case __constant_htons(ETH_P_IPV6):
2319                         ndisc_mc_map((struct in6_addr *)
2320                                      skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2321                                      fake_hdr->daddr, card->dev, 0);
2322                         break;
2323 #endif /* CONFIG_QETH_IPV6 */
2324                 case __constant_htons(ETH_P_IP):
2325                         ip_hdr = (struct iphdr *)skb->data;
2326                         ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2327                         break;
2328                 default:
2329                         memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2330                 }
2331                 break;
2332         case PACKET_BROADCAST:
2333                 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2334                 break;
2335         default:
2336                 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2337         }
2338         /* the source MAC address */
2339         if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2340                 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2341         else
2342                 memset(fake_hdr->saddr, 0, TR_ALEN);
2343         fake_hdr->rcf=0;
2344         fake_llc = (struct trllc*)&(fake_hdr->rcf);
2345         fake_llc->dsap = EXTENDED_SAP;
2346         fake_llc->ssap = EXTENDED_SAP;
2347         fake_llc->llc  = UI_CMD;
2348         fake_llc->protid[0] = 0;
2349         fake_llc->protid[1] = 0;
2350         fake_llc->protid[2] = 0;
2351         fake_llc->ethertype = ETH_P_IP;
2352 }
2353
2354 static void
2355 qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
2356                          struct qeth_hdr *hdr)
2357 {
2358         struct ethhdr *fake_hdr;
2359         struct iphdr *ip_hdr;
2360
2361         QETH_DBF_TEXT(trace,5,"skbfketh");
2362         skb_set_mac_header(skb, -QETH_FAKE_LL_LEN_ETH);
2363         /* this is a fake ethernet header */
2364         fake_hdr = eth_hdr(skb);
2365
2366         /* the destination MAC address */
2367         switch (skb->pkt_type){
2368         case PACKET_MULTICAST:
2369                 switch (skb->protocol){
2370 #ifdef CONFIG_QETH_IPV6
2371                 case __constant_htons(ETH_P_IPV6):
2372                         ndisc_mc_map((struct in6_addr *)
2373                                      skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2374                                      fake_hdr->h_dest, card->dev, 0);
2375                         break;
2376 #endif /* CONFIG_QETH_IPV6 */
2377                 case __constant_htons(ETH_P_IP):
2378                         ip_hdr = (struct iphdr *)skb->data;
2379                         ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
2380                         break;
2381                 default:
2382                         memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2383                 }
2384                 break;
2385         case PACKET_BROADCAST:
2386                 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2387                 break;
2388         default:
2389                 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2390         }
2391         /* the source MAC address */
2392         if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2393                 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2394         else
2395                 memset(fake_hdr->h_source, 0, ETH_ALEN);
2396         /* the protocol */
2397         fake_hdr->h_proto = skb->protocol;
2398 }
2399
2400 static inline void
2401 qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2402                         struct qeth_hdr *hdr)
2403 {
2404         if (card->dev->type == ARPHRD_IEEE802_TR)
2405                 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2406         else
2407                 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2408 }
2409
2410 static inline void
2411 qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2412                         struct qeth_hdr *hdr)
2413 {
2414         skb->pkt_type = PACKET_HOST;
2415         skb->protocol = qeth_type_trans(skb, skb->dev);
2416         if (card->options.checksum_type == NO_CHECKSUMMING)
2417                 skb->ip_summed = CHECKSUM_UNNECESSARY;
2418         else
2419                 skb->ip_summed = CHECKSUM_NONE;
2420         *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
2421 }
2422
2423 static __u16
2424 qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2425                  struct qeth_hdr *hdr)
2426 {
2427         unsigned short vlan_id = 0;
2428 #ifdef CONFIG_QETH_IPV6
2429         if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2430                 skb->pkt_type = PACKET_HOST;
2431                 skb->protocol = qeth_type_trans(skb, card->dev);
2432                 return 0;
2433         }
2434 #endif /* CONFIG_QETH_IPV6 */
2435         skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2436                               ETH_P_IP);
2437         switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2438         case QETH_CAST_UNICAST:
2439                 skb->pkt_type = PACKET_HOST;
2440                 break;
2441         case QETH_CAST_MULTICAST:
2442                 skb->pkt_type = PACKET_MULTICAST;
2443                 card->stats.multicast++;
2444                 break;
2445         case QETH_CAST_BROADCAST:
2446                 skb->pkt_type = PACKET_BROADCAST;
2447                 card->stats.multicast++;
2448                 break;
2449         case QETH_CAST_ANYCAST:
2450         case QETH_CAST_NOCAST:
2451         default:
2452                 skb->pkt_type = PACKET_HOST;
2453         }
2454
2455         if (hdr->hdr.l3.ext_flags &
2456             (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2457                 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2458                         hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2459         }
2460
2461         if (card->options.fake_ll)
2462                 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2463         else
2464                 skb_reset_mac_header(skb);
2465         skb->ip_summed = card->options.checksum_type;
2466         if (card->options.checksum_type == HW_CHECKSUMMING){
2467                 if ( (hdr->hdr.l3.ext_flags &
2468                       (QETH_HDR_EXT_CSUM_HDR_REQ |
2469                        QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2470                      (QETH_HDR_EXT_CSUM_HDR_REQ |
2471                       QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2472                         skb->ip_summed = CHECKSUM_UNNECESSARY;
2473                 else
2474                         skb->ip_summed = SW_CHECKSUMMING;
2475         }
2476         return vlan_id;
2477 }
2478
2479 static void
2480 qeth_process_inbound_buffer(struct qeth_card *card,
2481                             struct qeth_qdio_buffer *buf, int index)
2482 {
2483         struct qdio_buffer_element *element;
2484         struct sk_buff *skb;
2485         struct qeth_hdr *hdr;
2486         int offset;
2487         int rxrc;
2488         __u16 vlan_tag = 0;
2489
2490         /* get first element of current buffer */
2491         element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2492         offset = 0;
2493         if (card->options.performance_stats)
2494                 card->perf_stats.bufs_rec++;
2495         while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2496                                        &offset, &hdr))) {
2497                 skb->dev = card->dev;
2498                 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2499                         qeth_layer2_rebuild_skb(card, skb, hdr);
2500                 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2501                         vlan_tag = qeth_rebuild_skb(card, skb, hdr);
2502                 else { /*in case of OSN*/
2503                         skb_push(skb, sizeof(struct qeth_hdr));
2504                         skb_copy_to_linear_data(skb, hdr,
2505                                                 sizeof(struct qeth_hdr));
2506                 }
2507                 /* is device UP ? */
2508                 if (!(card->dev->flags & IFF_UP)){
2509                         dev_kfree_skb_any(skb);
2510                         continue;
2511                 }
2512                 if (card->info.type == QETH_CARD_TYPE_OSN)
2513                         rxrc = card->osn_info.data_cb(skb);
2514                 else
2515 #ifdef CONFIG_QETH_VLAN
2516                 if (vlan_tag)
2517                         if (card->vlangrp)
2518                                 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2519                         else {
2520                                 dev_kfree_skb_any(skb);
2521                                 continue;
2522                         }
2523                 else
2524 #endif
2525                         rxrc = netif_rx(skb);
2526                 card->dev->last_rx = jiffies;
2527                 card->stats.rx_packets++;
2528                 card->stats.rx_bytes += skb->len;
2529         }
2530 }
2531
2532 static struct qeth_buffer_pool_entry *
2533 qeth_get_buffer_pool_entry(struct qeth_card *card)
2534 {
2535         struct qeth_buffer_pool_entry *entry;
2536
2537         QETH_DBF_TEXT(trace, 6, "gtbfplen");
2538         if (!list_empty(&card->qdio.in_buf_pool.entry_list)) {
2539                 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2540                                 struct qeth_buffer_pool_entry, list);
2541                 list_del_init(&entry->list);
2542                 return entry;
2543         }
2544         return NULL;
2545 }
2546
2547 static void
2548 qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2549 {
2550         struct qeth_buffer_pool_entry *pool_entry;
2551         int i;
2552  
2553         pool_entry = qeth_get_buffer_pool_entry(card);
2554         /*
2555          * since the buffer is accessed only from the input_tasklet
2556          * there shouldn't be a need to synchronize; also, since we use
2557          * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run  out off
2558          * buffers
2559          */
2560         BUG_ON(!pool_entry);
2561
2562         buf->pool_entry = pool_entry;
2563         for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2564                 buf->buffer->element[i].length = PAGE_SIZE;
2565                 buf->buffer->element[i].addr =  pool_entry->elements[i];
2566                 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2567                         buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2568                 else
2569                         buf->buffer->element[i].flags = 0;
2570         }
2571         buf->state = QETH_QDIO_BUF_EMPTY;
2572 }
2573
2574 static void
2575 qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2576                          struct qeth_qdio_out_buffer *buf)
2577 {
2578         int i;
2579         struct sk_buff *skb;
2580
2581         /* is PCI flag set on buffer? */
2582         if (buf->buffer->element[0].flags & 0x40)
2583                 atomic_dec(&queue->set_pci_flags_count);
2584
2585         while ((skb = skb_dequeue(&buf->skb_list))){
2586                 atomic_dec(&skb->users);
2587                 dev_kfree_skb_any(skb);
2588         }
2589         qeth_eddp_buf_release_contexts(buf);
2590         for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2591                 buf->buffer->element[i].length = 0;
2592                 buf->buffer->element[i].addr = NULL;
2593                 buf->buffer->element[i].flags = 0;
2594         }
2595         buf->next_element_to_fill = 0;
2596         atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2597 }
2598
2599 static void
2600 qeth_queue_input_buffer(struct qeth_card *card, int index)
2601 {
2602         struct qeth_qdio_q *queue = card->qdio.in_q;
2603         int count;
2604         int i;
2605         int rc;
2606
2607         QETH_DBF_TEXT(trace,6,"queinbuf");
2608         count = (index < queue->next_buf_to_init)?
2609                 card->qdio.in_buf_pool.buf_count -
2610                 (queue->next_buf_to_init - index) :
2611                 card->qdio.in_buf_pool.buf_count -
2612                 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2613         /* only requeue at a certain threshold to avoid SIGAs */
2614         if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2615                 for (i = queue->next_buf_to_init;
2616                      i < queue->next_buf_to_init + count; ++i)
2617                         qeth_init_input_buffer(card,
2618                                 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]);
2619                 /*
2620                  * according to old code it should be avoided to requeue all
2621                  * 128 buffers in order to benefit from PCI avoidance.
2622                  * this function keeps at least one buffer (the buffer at
2623                  * 'index') un-requeued -> this buffer is the first buffer that
2624                  * will be requeued the next time
2625                  */
2626                 if (card->options.performance_stats) {
2627                         card->perf_stats.inbound_do_qdio_cnt++;
2628                         card->perf_stats.inbound_do_qdio_start_time =
2629                                 qeth_get_micros();
2630                 }
2631                 rc = do_QDIO(CARD_DDEV(card),
2632                              QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2633                              0, queue->next_buf_to_init, count, NULL);
2634                 if (card->options.performance_stats)
2635                         card->perf_stats.inbound_do_qdio_time +=
2636                                 qeth_get_micros() -
2637                                 card->perf_stats.inbound_do_qdio_start_time;
2638                 if (rc){
2639                         PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2640                                    "return %i (device %s).\n",
2641                                    rc, CARD_DDEV_ID(card));
2642                         QETH_DBF_TEXT(trace,2,"qinberr");
2643                         QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2644                 }
2645                 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2646                                           QDIO_MAX_BUFFERS_PER_Q;
2647         }
2648 }
2649
2650 static inline void
2651 qeth_put_buffer_pool_entry(struct qeth_card *card,
2652                            struct qeth_buffer_pool_entry *entry)
2653 {
2654         QETH_DBF_TEXT(trace, 6, "ptbfplen");
2655         list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2656 }
2657
2658 static void
2659 qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2660                         unsigned int qdio_err, unsigned int siga_err,
2661                         unsigned int queue, int first_element, int count,
2662                         unsigned long card_ptr)
2663 {
2664         struct net_device *net_dev;
2665         struct qeth_card *card;
2666         struct qeth_qdio_buffer *buffer;
2667         int index;
2668         int i;
2669
2670         QETH_DBF_TEXT(trace, 6, "qdinput");
2671         card = (struct qeth_card *) card_ptr;
2672         net_dev = card->dev;
2673         if (card->options.performance_stats) {
2674                 card->perf_stats.inbound_cnt++;
2675                 card->perf_stats.inbound_start_time = qeth_get_micros();
2676         }
2677         if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2678                 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2679                         QETH_DBF_TEXT(trace, 1,"qdinchk");
2680                         QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2681                         QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2682                         QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2683                         qeth_schedule_recovery(card);
2684                         return;
2685                 }
2686         }
2687         for (i = first_element; i < (first_element + count); ++i) {
2688                 index = i % QDIO_MAX_BUFFERS_PER_Q;
2689                 buffer = &card->qdio.in_q->bufs[index];
2690                 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
2691                       qeth_check_qdio_errors(buffer->buffer,
2692                                              qdio_err, siga_err,"qinerr")))
2693                         qeth_process_inbound_buffer(card, buffer, index);
2694                 /* clear buffer and give back to hardware */
2695                 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2696                 qeth_queue_input_buffer(card, index);
2697         }
2698         if (card->options.performance_stats)
2699                 card->perf_stats.inbound_time += qeth_get_micros() -
2700                         card->perf_stats.inbound_start_time;
2701 }
2702
2703 static int
2704 qeth_handle_send_error(struct qeth_card *card,
2705                        struct qeth_qdio_out_buffer *buffer,
2706                        unsigned int qdio_err, unsigned int siga_err)
2707 {
2708         int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2709         int cc = siga_err & 3;
2710
2711         QETH_DBF_TEXT(trace, 6, "hdsnderr");
2712         qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr");
2713         switch (cc) {
2714         case 0:
2715                 if (qdio_err){
2716                         QETH_DBF_TEXT(trace, 1,"lnkfail");
2717                         QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2718                         QETH_DBF_TEXT_(trace,1,"%04x %02x",
2719                                        (u16)qdio_err, (u8)sbalf15);
2720                         return QETH_SEND_ERROR_LINK_FAILURE;
2721                 }
2722                 return QETH_SEND_ERROR_NONE;
2723         case 2:
2724                 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2725                         QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2726                         QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2727                         return QETH_SEND_ERROR_KICK_IT;
2728                 }
2729                 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2730                         return QETH_SEND_ERROR_RETRY;
2731                 return QETH_SEND_ERROR_LINK_FAILURE;
2732                 /* look at qdio_error and sbalf 15 */
2733         case 1:
2734                 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2735                 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2736                 return QETH_SEND_ERROR_LINK_FAILURE;
2737         case 3:
2738         default:
2739                 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2740                 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2741                 return QETH_SEND_ERROR_KICK_IT;
2742         }
2743 }
2744
2745 void
2746 qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2747                    int index, int count)
2748 {
2749         struct qeth_qdio_out_buffer *buf;
2750         int rc;
2751         int i;
2752
2753         QETH_DBF_TEXT(trace, 6, "flushbuf");
2754
2755         for (i = index; i < index + count; ++i) {
2756                 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2757                 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2758                                 SBAL_FLAGS_LAST_ENTRY;
2759
2760                 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2761                         continue;
2762
2763                 if (!queue->do_pack){
2764                         if ((atomic_read(&queue->used_buffers) >=
2765                                 (QETH_HIGH_WATERMARK_PACK -
2766                                  QETH_WATERMARK_PACK_FUZZ)) &&
2767                             !atomic_read(&queue->set_pci_flags_count)){
2768                                 /* it's likely that we'll go to packing
2769                                  * mode soon */
2770                                 atomic_inc(&queue->set_pci_flags_count);
2771                                 buf->buffer->element[0].flags |= 0x40;
2772                         }
2773                 } else {
2774                         if (!atomic_read(&queue->set_pci_flags_count)){
2775                                 /*
2776                                  * there's no outstanding PCI any more, so we
2777                                  * have to request a PCI to be sure the the PCI
2778                                  * will wake at some time in the future then we
2779                                  * can flush packed buffers that might still be
2780                                  * hanging around, which can happen if no
2781                                  * further send was requested by the stack
2782                                  */
2783                                 atomic_inc(&queue->set_pci_flags_count);
2784                                 buf->buffer->element[0].flags |= 0x40;
2785                         }
2786                 }
2787         }
2788
2789         queue->card->dev->trans_start = jiffies;
2790         if (queue->card->options.performance_stats) {
2791                 queue->card->perf_stats.outbound_do_qdio_cnt++;
2792                 queue->card->perf_stats.outbound_do_qdio_start_time =
2793                         qeth_get_micros();
2794         }
2795         if (under_int)
2796                 rc = do_QDIO(CARD_DDEV(queue->card),
2797                              QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT,
2798                              queue->queue_no, index, count, NULL);
2799         else
2800                 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT,
2801                              queue->queue_no, index, count, NULL);
2802         if (queue->card->options.performance_stats)
2803                 queue->card->perf_stats.outbound_do_qdio_time +=
2804                         qeth_get_micros() -
2805                         queue->card->perf_stats.outbound_do_qdio_start_time;
2806         if (rc){
2807                 QETH_DBF_TEXT(trace, 2, "flushbuf");
2808                 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
2809                 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
2810                 queue->card->stats.tx_errors += count;
2811                 /* this must not happen under normal circumstances. if it
2812                  * happens something is really wrong -> recover */
2813                 qeth_schedule_recovery(queue->card);
2814                 return;
2815         }
2816         atomic_add(count, &queue->used_buffers);
2817         if (queue->card->options.performance_stats)
2818                 queue->card->perf_stats.bufs_sent += count;
2819 }
2820
2821 /*
2822  * Switched to packing state if the number of used buffers on a queue
2823  * reaches a certain limit.
2824  */
2825 static void
2826 qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2827 {
2828         if (!queue->do_pack) {
2829                 if (atomic_read(&queue->used_buffers)
2830                     >= QETH_HIGH_WATERMARK_PACK){
2831                         /* switch non-PACKING -> PACKING */
2832                         QETH_DBF_TEXT(trace, 6, "np->pack");
2833                         if (queue->card->options.performance_stats)
2834                                 queue->card->perf_stats.sc_dp_p++;
2835                         queue->do_pack = 1;
2836                 }
2837         }
2838 }
2839
2840 /*
2841  * Switches from packing to non-packing mode. If there is a packing
2842  * buffer on the queue this buffer will be prepared to be flushed.
2843  * In that case 1 is returned to inform the caller. If no buffer
2844  * has to be flushed, zero is returned.
2845  */
2846 static int
2847 qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2848 {
2849         struct qeth_qdio_out_buffer *buffer;
2850         int flush_count = 0;
2851
2852         if (queue->do_pack) {
2853                 if (atomic_read(&queue->used_buffers)
2854                     <= QETH_LOW_WATERMARK_PACK) {
2855                         /* switch PACKING -> non-PACKING */
2856                         QETH_DBF_TEXT(trace, 6, "pack->np");
2857                         if (queue->card->options.performance_stats)
2858                                 queue->card->perf_stats.sc_p_dp++;
2859                         queue->do_pack = 0;
2860                         /* flush packing buffers */
2861                         buffer = &queue->bufs[queue->next_buf_to_fill];
2862                         if ((atomic_read(&buffer->state) ==
2863                                                 QETH_QDIO_BUF_EMPTY) &&
2864                             (buffer->next_element_to_fill > 0)) {
2865                                 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
2866                                 flush_count++;
2867                                 queue->next_buf_to_fill =
2868                                         (queue->next_buf_to_fill + 1) %
2869                                         QDIO_MAX_BUFFERS_PER_Q;
2870                         }
2871                 }
2872         }
2873         return flush_count;
2874 }
2875
2876 /*
2877  * Called to flush a packing buffer if no more pci flags are on the queue.
2878  * Checks if there is a packing buffer and prepares it to be flushed.
2879  * In that case returns 1, otherwise zero.
2880  */
2881 static int
2882 qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2883 {
2884         struct qeth_qdio_out_buffer *buffer;
2885
2886         buffer = &queue->bufs[queue->next_buf_to_fill];
2887         if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2888            (buffer->next_element_to_fill > 0)){
2889                 /* it's a packing buffer */
2890                 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2891                 queue->next_buf_to_fill =
2892                         (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2893                 return 1;
2894         }
2895         return 0;
2896 }
2897
2898 static void
2899 qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2900 {
2901         int index;
2902         int flush_cnt = 0;
2903         int q_was_packing = 0;
2904
2905         /*
2906          * check if weed have to switch to non-packing mode or if
2907          * we have to get a pci flag out on the queue
2908          */
2909         if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2910             !atomic_read(&queue->set_pci_flags_count)){
2911                 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2912                                 QETH_OUT_Q_UNLOCKED) {
2913                         /*
2914                          * If we get in here, there was no action in
2915                          * do_send_packet. So, we check if there is a
2916                          * packing buffer to be flushed here.
2917                          */
2918                         netif_stop_queue(queue->card->dev);
2919                         index = queue->next_buf_to_fill;
2920                         q_was_packing = queue->do_pack;
2921                         flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
2922                         if (!flush_cnt &&
2923                             !atomic_read(&queue->set_pci_flags_count))
2924                                 flush_cnt +=
2925                                         qeth_flush_buffers_on_no_pci(queue);
2926                         if (queue->card->options.performance_stats &&
2927                             q_was_packing)
2928                                 queue->card->perf_stats.bufs_sent_pack +=
2929                                         flush_cnt;
2930                         if (flush_cnt)
2931                                 qeth_flush_buffers(queue, 1, index, flush_cnt);
2932                         atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
2933                 }
2934         }
2935 }
2936
2937 static void
2938 qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
2939                         unsigned int qdio_error, unsigned int siga_error,
2940                         unsigned int __queue, int first_element, int count,
2941                         unsigned long card_ptr)
2942 {
2943         struct qeth_card *card        = (struct qeth_card *) card_ptr;
2944         struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
2945         struct qeth_qdio_out_buffer *buffer;
2946         int i;
2947
2948         QETH_DBF_TEXT(trace, 6, "qdouhdl");
2949         if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2950                 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2951                         QETH_DBF_TEXT(trace, 2, "achkcond");
2952                         QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
2953                         QETH_DBF_TEXT_(trace, 2, "%08x", status);
2954                         netif_stop_queue(card->dev);
2955                         qeth_schedule_recovery(card);
2956                         return;
2957                 }
2958         }
2959         if (card->options.performance_stats) {
2960                 card->perf_stats.outbound_handler_cnt++;
2961                 card->perf_stats.outbound_handler_start_time =
2962                         qeth_get_micros();
2963         }
2964         for(i = first_element; i < (first_element + count); ++i){
2965                 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2966                 /*we only handle the KICK_IT error by doing a recovery */
2967                 if (qeth_handle_send_error(card, buffer,
2968                                            qdio_error, siga_error)
2969                                 == QETH_SEND_ERROR_KICK_IT){
2970                         netif_stop_queue(card->dev);
2971                         qeth_schedule_recovery(card);
2972                         return;
2973                 }
2974                 qeth_clear_output_buffer(queue, buffer);
2975         }
2976         atomic_sub(count, &queue->used_buffers);
2977         /* check if we need to do something on this outbound queue */
2978         if (card->info.type != QETH_CARD_TYPE_IQD)
2979                 qeth_check_outbound_queue(queue);
2980
2981         netif_wake_queue(queue->card->dev);
2982         if (card->options.performance_stats)
2983                 card->perf_stats.outbound_handler_time += qeth_get_micros() -
2984                         card->perf_stats.outbound_handler_start_time;
2985 }
2986
2987 static void
2988 qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
2989 {
2990
2991         param_field[0] = _ascebc['P'];
2992         param_field[1] = _ascebc['C'];
2993         param_field[2] = _ascebc['I'];
2994         param_field[3] = _ascebc['T'];
2995         *((unsigned int *) (&param_field[4])) = QETH_PCI_THRESHOLD_A(card);
2996         *((unsigned int *) (&param_field[8])) = QETH_PCI_THRESHOLD_B(card);
2997         *((unsigned int *) (&param_field[12])) = QETH_PCI_TIMER_VALUE(card);
2998 }
2999
3000 static void
3001 qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
3002 {
3003         param_field[16] = _ascebc['B'];
3004         param_field[17] = _ascebc['L'];
3005         param_field[18] = _ascebc['K'];
3006         param_field[19] = _ascebc['T'];
3007         *((unsigned int *) (&param_field[20])) = card->info.blkt.time_total;
3008         *((unsigned int *) (&param_field[24])) = card->info.blkt.inter_packet;
3009         *((unsigned int *) (&param_field[28])) = card->info.blkt.inter_packet_jumbo;
3010 }
3011
3012 static void
3013 qeth_initialize_working_pool_list(struct qeth_card *card)
3014 {
3015         struct qeth_buffer_pool_entry *entry;
3016
3017         QETH_DBF_TEXT(trace,5,"inwrklst");
3018
3019         list_for_each_entry(entry,
3020                             &card->qdio.init_pool.entry_list, init_list) {
3021                 qeth_put_buffer_pool_entry(card,entry);
3022         }
3023 }
3024
3025 static void
3026 qeth_clear_working_pool_list(struct qeth_card *card)
3027 {
3028         struct qeth_buffer_pool_entry *pool_entry, *tmp;
3029
3030         QETH_DBF_TEXT(trace,5,"clwrklst");
3031         list_for_each_entry_safe(pool_entry, tmp,
3032                             &card->qdio.in_buf_pool.entry_list, list){
3033                         list_del(&pool_entry->list);
3034         }
3035 }
3036
3037 static void
3038 qeth_free_buffer_pool(struct qeth_card *card)
3039 {
3040         struct qeth_buffer_pool_entry *pool_entry, *tmp;
3041         int i=0;
3042         QETH_DBF_TEXT(trace,5,"freepool");
3043         list_for_each_entry_safe(pool_entry, tmp,
3044                                  &card->qdio.init_pool.entry_list, init_list){
3045                 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3046                         free_page((unsigned long)pool_entry->elements[i]);
3047                 list_del(&pool_entry->init_list);
3048                 kfree(pool_entry);
3049         }
3050 }
3051
3052 static int
3053 qeth_alloc_buffer_pool(struct qeth_card *card)
3054 {
3055         struct qeth_buffer_pool_entry *pool_entry;
3056         void *ptr;
3057         int i, j;
3058
3059         QETH_DBF_TEXT(trace,5,"alocpool");
3060         for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3061                 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3062                 if (!pool_entry){
3063                         qeth_free_buffer_pool(card);
3064                         return -ENOMEM;
3065                 }
3066                 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
3067                         ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
3068                         if (!ptr) {
3069                                 while (j > 0)
3070                                         free_page((unsigned long)
3071                                                   pool_entry->elements[--j]);
3072                                 kfree(pool_entry);
3073                                 qeth_free_buffer_pool(card);
3074                                 return -ENOMEM;
3075                         }
3076                         pool_entry->elements[j] = ptr;
3077                 }
3078                 list_add(&pool_entry->init_list,
3079                          &card->qdio.init_pool.entry_list);
3080         }
3081         return 0;
3082 }
3083
3084 int
3085 qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3086 {
3087         QETH_DBF_TEXT(trace, 2, "realcbp");
3088
3089         if ((card->state != CARD_STATE_DOWN) &&
3090             (card->state != CARD_STATE_RECOVER))
3091                 return -EPERM;
3092
3093         /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3094         qeth_clear_working_pool_list(card);
3095         qeth_free_buffer_pool(card);
3096         card->qdio.in_buf_pool.buf_count = bufcnt;
3097         card->qdio.init_pool.buf_count = bufcnt;
3098         return qeth_alloc_buffer_pool(card);
3099 }
3100
3101 static int
3102 qeth_alloc_qdio_buffers(struct qeth_card *card)
3103 {
3104         int i, j;
3105
3106         QETH_DBF_TEXT(setup, 2, "allcqdbf");
3107
3108         if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
3109                 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
3110                 return 0;
3111
3112         card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3113                                   GFP_KERNEL|GFP_DMA);
3114         if (!card->qdio.in_q)
3115                 goto out_nomem;
3116         QETH_DBF_TEXT(setup, 2, "inq");
3117         QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3118         memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3119         /* give inbound qeth_qdio_buffers their qdio_buffers */
3120         for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3121                 card->qdio.in_q->bufs[i].buffer =
3122                         &card->qdio.in_q->qdio_bufs[i];
3123         /* inbound buffer pool */
3124         if (qeth_alloc_buffer_pool(card))
3125                 goto out_freeinq;
3126         /* outbound */
3127         card->qdio.out_qs =
3128                 kmalloc(card->qdio.no_out_queues *
3129                         sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3130         if (!card->qdio.out_qs)
3131                 goto out_freepool;
3132         for (i = 0; i < card->qdio.no_out_queues; ++i) {
3133                 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3134                                                GFP_KERNEL|GFP_DMA);
3135                 if (!card->qdio.out_qs[i])
3136                         goto out_freeoutq;
3137                 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3138                 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3139                 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3140                 card->qdio.out_qs[i]->queue_no = i;
3141                 /* give outbound qeth_qdio_buffers their qdio_buffers */
3142                 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3143                         card->qdio.out_qs[i]->bufs[j].buffer =
3144                                 &card->qdio.out_qs[i]->qdio_bufs[j];
3145                         skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3146                                             skb_list);
3147                         lockdep_set_class(
3148                                 &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
3149                                 &qdio_out_skb_queue_key);
3150                         INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3151                 }
3152         }
3153         return 0;
3154
3155 out_freeoutq:
3156         while (i > 0)
3157                 kfree(card->qdio.out_qs[--i]);
3158         kfree(card->qdio.out_qs);
3159 out_freepool:
3160         qeth_free_buffer_pool(card);
3161 out_freeinq:
3162         kfree(card->qdio.in_q);
3163 out_nomem:
3164         atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3165         return -ENOMEM;
3166 }
3167
3168 static void
3169 qeth_free_qdio_buffers(struct qeth_card *card)
3170 {
3171         int i, j;
3172
3173         QETH_DBF_TEXT(trace, 2, "freeqdbf");
3174         if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
3175                 QETH_QDIO_UNINITIALIZED)
3176                 return;
3177         kfree(card->qdio.in_q);
3178         /* inbound buffer pool */
3179         qeth_free_buffer_pool(card);
3180         /* free outbound qdio_qs */
3181         for (i = 0; i < card->qdio.no_out_queues; ++i){
3182                 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3183                         qeth_clear_output_buffer(card->qdio.out_qs[i],
3184                                         &card->qdio.out_qs[i]->bufs[j]);
3185                 kfree(card->qdio.out_qs[i]);
3186         }
3187         kfree(card->qdio.out_qs);
3188 }
3189
3190 static void
3191 qeth_clear_qdio_buffers(struct qeth_card *card)
3192 {
3193         int i, j;
3194
3195         QETH_DBF_TEXT(trace, 2, "clearqdbf");
3196         /* clear outbound buffers to free skbs */
3197         for (i = 0; i < card->qdio.no_out_queues; ++i)
3198                 if (card->qdio.out_qs[i]){
3199                         for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3200                                 qeth_clear_output_buffer(card->qdio.out_qs[i],
3201                                                 &card->qdio.out_qs[i]->bufs[j]);
3202                 }
3203 }
3204
3205 static void
3206 qeth_init_qdio_info(struct qeth_card *card)
3207 {
3208         QETH_DBF_TEXT(setup, 4, "intqdinf");
3209         atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3210         /* inbound */
3211         card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3212         card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3213         card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3214         INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3215         INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3216 }
3217
3218 static int
3219 qeth_init_qdio_queues(struct qeth_card *card)
3220 {
3221         int i, j;
3222         int rc;
3223
3224         QETH_DBF_TEXT(setup, 2, "initqdqs");
3225
3226         /* inbound queue */
3227         memset(card->qdio.in_q->qdio_bufs, 0,
3228                QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3229         qeth_initialize_working_pool_list(card);
3230         /*give only as many buffers to hardware as we have buffer pool entries*/
3231         for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3232                 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3233         card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3234         rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3235                      card->qdio.in_buf_pool.buf_count - 1, NULL);
3236         if (rc) {
3237                 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3238                 return rc;
3239         }
3240         rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3241         if (rc) {
3242                 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3243                 return rc;
3244         }
3245         /* outbound queue */
3246         for (i = 0; i < card->qdio.no_out_queues; ++i){
3247                 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3248                        QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3249                 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3250                         qeth_clear_output_buffer(card->qdio.out_qs[i],
3251                                         &card->qdio.out_qs[i]->bufs[j]);
3252                 }
3253                 card->qdio.out_qs[i]->card = card;
3254                 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3255                 card->qdio.out_qs[i]->do_pack = 0;
3256                 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3257                 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3258                 atomic_set(&card->qdio.out_qs[i]->state,
3259                            QETH_OUT_Q_UNLOCKED);
3260         }
3261         return 0;
3262 }
3263
3264 static int
3265 qeth_qdio_establish(struct qeth_card *card)
3266 {
3267         struct qdio_initialize init_data;
3268         char *qib_param_field;
3269         struct qdio_buffer **in_sbal_ptrs;
3270         struct qdio_buffer **out_sbal_ptrs;
3271         int i, j, k;
3272         int rc = 0;
3273
3274         QETH_DBF_TEXT(setup, 2, "qdioest");
3275
3276         qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3277                               GFP_KERNEL);
3278         if (!qib_param_field)
3279                 return -ENOMEM;
3280
3281         qeth_create_qib_param_field(card, qib_param_field);
3282         qeth_create_qib_param_field_blkt(card, qib_param_field);
3283
3284         in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3285                                GFP_KERNEL);
3286         if (!in_sbal_ptrs) {
3287                 kfree(qib_param_field);
3288                 return -ENOMEM;
3289         }
3290         for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3291                 in_sbal_ptrs[i] = (struct qdio_buffer *)
3292                         virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3293
3294         out_sbal_ptrs =
3295                 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3296                         sizeof(void *), GFP_KERNEL);
3297         if (!out_sbal_ptrs) {
3298                 kfree(in_sbal_ptrs);
3299                 kfree(qib_param_field);
3300                 return -ENOMEM;
3301         }
3302         for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3303                 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3304                         out_sbal_ptrs[k] = (struct qdio_buffer *)
3305                                 virt_to_phys(card->qdio.out_qs[i]->
3306                                              bufs[j].buffer);
3307                 }
3308
3309         memset(&init_data, 0, sizeof(struct qdio_initialize));
3310         init_data.cdev                   = CARD_DDEV(card);
3311         init_data.q_format               = qeth_get_qdio_q_format(card);
3312         init_data.qib_param_field_format = 0;
3313         init_data.qib_param_field        = qib_param_field;
3314         init_data.min_input_threshold    = QETH_MIN_INPUT_THRESHOLD;
3315         init_data.max_input_threshold    = QETH_MAX_INPUT_THRESHOLD;
3316         init_data.min_output_threshold   = QETH_MIN_OUTPUT_THRESHOLD;
3317         init_data.max_output_threshold   = QETH_MAX_OUTPUT_THRESHOLD;
3318         init_data.no_input_qs            = 1;
3319         init_data.no_output_qs           = card->qdio.no_out_queues;
3320         init_data.input_handler          = (qdio_handler_t *)
3321                                            qeth_qdio_input_handler;
3322         init_data.output_handler         = (qdio_handler_t *)
3323                                            qeth_qdio_output_handler;
3324         init_data.int_parm               = (unsigned long) card;
3325         init_data.flags                  = QDIO_INBOUND_0COPY_SBALS |
3326                                            QDIO_OUTBOUND_0COPY_SBALS |
3327                                            QDIO_USE_OUTBOUND_PCIS;
3328         init_data.input_sbal_addr_array  = (void **) in_sbal_ptrs;
3329         init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3330
3331         if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3332                 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED)
3333                 if ((rc = qdio_initialize(&init_data)))
3334                         atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3335
3336         kfree(out_sbal_ptrs);
3337         kfree(in_sbal_ptrs);
3338         kfree(qib_param_field);
3339         return rc;
3340 }
3341
3342 static int
3343 qeth_qdio_activate(struct qeth_card *card)
3344 {
3345         QETH_DBF_TEXT(setup,3,"qdioact");
3346         return qdio_activate(CARD_DDEV(card), 0);
3347 }
3348
3349 static int
3350 qeth_clear_channel(struct qeth_channel *channel)
3351 {
3352         unsigned long flags;
3353         struct qeth_card *card;
3354         int rc;
3355
3356         QETH_DBF_TEXT(trace,3,"clearch");
3357         card = CARD_FROM_CDEV(channel->ccwdev);
3358         spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3359         rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3360         spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3361
3362         if (rc)
3363                 return rc;
3364         rc = wait_event_interruptible_timeout(card->wait_q,
3365                         channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3366         if (rc == -ERESTARTSYS)
3367                 return rc;
3368         if (channel->state != CH_STATE_STOPPED)
3369                 return -ETIME;
3370         channel->state = CH_STATE_DOWN;
3371         return 0;
3372 }
3373
3374 static int
3375 qeth_halt_channel(struct qeth_channel *channel)
3376 {
3377         unsigned long flags;
3378         struct qeth_card *card;
3379         int rc;
3380
3381         QETH_DBF_TEXT(trace,3,"haltch");
3382         card = CARD_FROM_CDEV(channel->ccwdev);
3383         spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3384         rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3385         spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3386
3387         if (rc)
3388                 return rc;
3389         rc = wait_event_interruptible_timeout(card->wait_q,
3390                         channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3391         if (rc == -ERESTARTSYS)
3392                 return rc;
3393         if (channel->state != CH_STATE_HALTED)
3394                 return -ETIME;
3395         return 0;
3396 }
3397
3398 static int
3399 qeth_halt_channels(struct qeth_card *card)
3400 {
3401         int rc1 = 0, rc2=0, rc3 = 0;
3402
3403         QETH_DBF_TEXT(trace,3,"haltchs");
3404         rc1 = qeth_halt_channel(&card->read);
3405         rc2 = qeth_halt_channel(&card->write);
3406         rc3 = qeth_halt_channel(&card->data);
3407         if (rc1)
3408                 return rc1;
3409         if (rc2)
3410                 return rc2;
3411         return rc3;
3412 }
3413 static int
3414 qeth_clear_channels(struct qeth_card *card)
3415 {
3416         int rc1 = 0, rc2=0, rc3 = 0;
3417
3418         QETH_DBF_TEXT(trace,3,"clearchs");
3419         rc1 = qeth_clear_channel(&card->read);
3420         rc2 = qeth_clear_channel(&card->write);
3421         rc3 = qeth_clear_channel(&card->data);
3422         if (rc1)
3423                 return rc1;
3424         if (rc2)
3425                 return rc2;
3426         return rc3;
3427 }
3428
3429 static int
3430 qeth_clear_halt_card(struct qeth_card *card, int halt)
3431 {
3432         int rc = 0;
3433
3434         QETH_DBF_TEXT(trace,3,"clhacrd");
3435         QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3436
3437         if (halt)
3438                 rc = qeth_halt_channels(card);
3439         if (rc)
3440                 return rc;
3441         return qeth_clear_channels(card);
3442 }
3443
3444 static int
3445 qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3446 {
3447         int rc = 0;
3448
3449         QETH_DBF_TEXT(trace,3,"qdioclr");
3450         switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
3451                 QETH_QDIO_CLEANING)) {
3452         case QETH_QDIO_ESTABLISHED:
3453                 if ((rc = qdio_cleanup(CARD_DDEV(card),
3454                                 (card->info.type == QETH_CARD_TYPE_IQD) ?
3455                                 QDIO_FLAG_CLEANUP_USING_HALT :
3456                                 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3457                         QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3458                 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3459                 break;
3460         case QETH_QDIO_CLEANING:
3461                 return rc;
3462         default:
3463                 break;
3464         }
3465         if ((rc = qeth_clear_halt_card(card, use_halt)))
3466                 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3467         card->state = CARD_STATE_DOWN;
3468         return rc;
3469 }
3470
3471 static int
3472 qeth_dm_act(struct qeth_card *card)
3473 {
3474         int rc;
3475         struct qeth_cmd_buffer *iob;
3476
3477         QETH_DBF_TEXT(setup,2,"dmact");
3478
3479         iob = qeth_wait_for_buffer(&card->write);
3480         memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3481
3482         memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3483                &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3484         memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3485                &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3486         rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3487         return rc;
3488 }
3489
3490 static int
3491 qeth_mpc_initialize(struct qeth_card *card)
3492 {
3493         int rc;
3494
3495         QETH_DBF_TEXT(setup,2,"mpcinit");
3496
3497         if ((rc = qeth_issue_next_read(card))){
3498                 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3499                 return rc;
3500         }
3501         if ((rc = qeth_cm_enable(card))){
3502                 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3503                 goto out_qdio;
3504         }
3505         if ((rc = qeth_cm_setup(card))){
3506                 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3507                 goto out_qdio;
3508         }
3509         if ((rc = qeth_ulp_enable(card))){
3510                 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3511                 goto out_qdio;
3512         }
3513         if ((rc = qeth_ulp_setup(card))){
3514                 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3515                 goto out_qdio;
3516         }
3517         if ((rc = qeth_alloc_qdio_buffers(card))){
3518                 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3519                 goto out_qdio;
3520         }
3521         if ((rc = qeth_qdio_establish(card))){
3522                 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3523                 qeth_free_qdio_buffers(card);
3524                 goto out_qdio;
3525         }
3526         if ((rc = qeth_qdio_activate(card))){
3527                 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3528                 goto out_qdio;
3529         }
3530         if ((rc = qeth_dm_act(card))){
3531                 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3532                 goto out_qdio;
3533         }
3534
3535         return 0;
3536 out_qdio:
3537         qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
3538         return rc;
3539 }
3540
3541 static struct net_device *
3542 qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3543 {
3544         struct net_device *dev = NULL;
3545
3546         switch (type) {
3547         case QETH_CARD_TYPE_OSAE:
3548                 switch (linktype) {
3549                 case QETH_LINK_TYPE_LANE_TR:
3550                 case QETH_LINK_TYPE_HSTR:
3551 #ifdef CONFIG_TR
3552                         dev = alloc_trdev(0);
3553 #endif /* CONFIG_TR */
3554                         break;
3555                 default:
3556                         dev = alloc_etherdev(0);
3557                 }
3558                 break;
3559         case QETH_CARD_TYPE_IQD:
3560                 dev = alloc_netdev(0, "hsi%d", ether_setup);
3561                 break;
3562         case QETH_CARD_TYPE_OSN:
3563                 dev = alloc_netdev(0, "osn%d", ether_setup);
3564                 break;
3565         default:
3566                 dev = alloc_etherdev(0);
3567         }
3568         return dev;
3569 }
3570
3571 /*hard_header fake function; used in case fake_ll is set */
3572 static int
3573 qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3574                      unsigned short type, void *daddr, void *saddr,
3575                      unsigned len)
3576 {
3577         if(dev->type == ARPHRD_IEEE802_TR){
3578                 struct trh_hdr *hdr;
3579                 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3580                 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3581                 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3582                 return QETH_FAKE_LL_LEN_TR;
3583
3584         } else {
3585                 struct ethhdr *hdr;
3586                 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3587                 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3588                 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3589                 if (type != ETH_P_802_3)
3590                         hdr->h_proto = htons(type);
3591                 else
3592                         hdr->h_proto = htons(len);
3593                 return QETH_FAKE_LL_LEN_ETH;
3594
3595         }
3596 }
3597
3598 static int
3599 qeth_send_packet(struct qeth_card *, struct sk_buff *);
3600
3601 static int
3602 qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3603 {
3604         int rc;
3605         struct qeth_card *card;
3606
3607         QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3608         card = (struct qeth_card *)dev->priv;
3609         if (skb==NULL) {
3610                 card->stats.tx_dropped++;
3611                 card->stats.tx_errors++;
3612                 /* return OK; otherwise ksoftirqd goes to 100% */
3613                 return NETDEV_TX_OK;
3614         }
3615         if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3616                 card->stats.tx_dropped++;
3617                 card->stats.tx_errors++;
3618                 card->stats.tx_carrier_errors++;
3619                 dev_kfree_skb_any(skb);
3620                 /* return OK; otherwise ksoftirqd goes to 100% */
3621                 return NETDEV_TX_OK;
3622         }
3623         if (card->options.performance_stats) {
3624                 card->perf_stats.outbound_cnt++;
3625                 card->perf_stats.outbound_start_time = qeth_get_micros();
3626         }
3627         netif_stop_queue(dev);
3628         if ((rc = qeth_send_packet(card, skb))) {
3629                 if (rc == -EBUSY) {
3630                         return NETDEV_TX_BUSY;
3631                 } else {
3632                         card->stats.tx_errors++;
3633                         card->stats.tx_dropped++;
3634                         dev_kfree_skb_any(skb);
3635                         /*set to OK; otherwise ksoftirqd goes to 100% */
3636                         rc = NETDEV_TX_OK;
3637                 }
3638         }
3639         netif_wake_queue(dev);
3640         if (card->options.performance_stats)
3641                 card->perf_stats.outbound_time += qeth_get_micros() -
3642                         card->perf_stats.outbound_start_time;
3643         return rc;
3644 }
3645
3646 static int
3647 qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3648 {
3649         int rc = 0;
3650 #ifdef CONFIG_QETH_VLAN
3651         struct vlan_group *vg;
3652         int i;
3653
3654         if (!(vg = card->vlangrp))
3655                 return rc;
3656
3657         for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3658                 if (vlan_group_get_device(vg, i) == dev){
3659                         rc = QETH_VLAN_CARD;
3660                         break;
3661                 }
3662         }
3663         if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card))
3664                 return 0;
3665
3666 #endif
3667         return rc;
3668 }
3669
3670 static int
3671 qeth_verify_dev(struct net_device *dev)
3672 {
3673         struct qeth_card *card;
3674         unsigned long flags;
3675         int rc = 0;
3676
3677         read_lock_irqsave(&qeth_card_list.rwlock, flags);
3678         list_for_each_entry(card, &qeth_card_list.list, list){
3679                 if (card->dev == dev){
3680                         rc = QETH_REAL_CARD;
3681                         break;
3682                 }
3683                 rc = qeth_verify_vlan_dev(dev, card);
3684                 if (rc)
3685                         break;
3686         }
3687         read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3688
3689         return rc;
3690 }
3691
3692 static struct qeth_card *
3693 qeth_get_card_from_dev(struct net_device *dev)
3694 {
3695         struct qeth_card *card = NULL;
3696         int rc;
3697
3698         rc = qeth_verify_dev(dev);
3699         if (rc == QETH_REAL_CARD)
3700                 card = (struct qeth_card *)dev->priv;
3701         else if (rc == QETH_VLAN_CARD)
3702                 card = (struct qeth_card *)
3703                         VLAN_DEV_INFO(dev)->real_dev->priv;
3704
3705         QETH_DBF_TEXT_(trace, 4, "%d", rc);
3706         return card ;
3707 }
3708
3709 static void
3710 qeth_tx_timeout(struct net_device *dev)
3711 {
3712         struct qeth_card *card;
3713
3714         card = (struct qeth_card *) dev->priv;
3715         card->stats.tx_errors++;
3716         qeth_schedule_recovery(card);
3717 }
3718
3719 static int
3720 qeth_open(struct net_device *dev)
3721 {
3722         struct qeth_card *card;
3723
3724         QETH_DBF_TEXT(trace, 4, "qethopen");
3725
3726         card = (struct qeth_card *) dev->priv;
3727
3728         if (card->state != CARD_STATE_SOFTSETUP)
3729                 return -ENODEV;
3730
3731         if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3732              (card->options.layer2) &&
3733              (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
3734                 QETH_DBF_TEXT(trace,4,"nomacadr");
3735                 return -EPERM;
3736         }
3737         card->data.state = CH_STATE_UP;
3738         card->state = CARD_STATE_UP;
3739         card->dev->flags |= IFF_UP;
3740         netif_start_queue(dev);
3741
3742         if (!card->lan_online && netif_carrier_ok(dev))
3743                 netif_carrier_off(dev);
3744         return 0;
3745 }
3746
3747 static int
3748 qeth_stop(struct net_device *dev)
3749 {
3750         struct qeth_card *card;
3751
3752         QETH_DBF_TEXT(trace, 4, "qethstop");
3753
3754         card = (struct qeth_card *) dev->priv;
3755
3756         netif_tx_disable(dev);
3757         card->dev->flags &= ~IFF_UP;
3758         if (card->state == CARD_STATE_UP)
3759                 card->state = CARD_STATE_SOFTSETUP;
3760         return 0;
3761 }
3762
3763 static int
3764 qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3765 {
3766         int cast_type = RTN_UNSPEC;
3767
3768         if (card->info.type == QETH_CARD_TYPE_OSN)
3769                 return cast_type;
3770
3771         if (skb->dst && skb->dst->neighbour){
3772                 cast_type = skb->dst->neighbour->type;
3773                 if ((cast_type == RTN_BROADCAST) ||
3774                     (cast_type == RTN_MULTICAST) ||
3775                     (cast_type == RTN_ANYCAST))
3776                         return cast_type;
3777                 else
3778                         return RTN_UNSPEC;
3779         }
3780         /* try something else */
3781         if (skb->protocol == ETH_P_IPV6)
3782                 return (skb_network_header(skb)[24] == 0xff) ?
3783                                 RTN_MULTICAST : 0;
3784         else if (skb->protocol == ETH_P_IP)
3785                 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
3786                                 RTN_MULTICAST : 0;
3787         /* ... */
3788         if (!memcmp(skb->data, skb->dev->broadcast, 6))
3789                 return RTN_BROADCAST;
3790         else {
3791                 u16 hdr_mac;
3792
3793                 hdr_mac = *((u16 *)skb->data);
3794                 /* tr multicast? */
3795                 switch (card->info.link_type) {
3796                 case QETH_LINK_TYPE_HSTR:
3797                 case QETH_LINK_TYPE_LANE_TR:
3798                         if ((hdr_mac == QETH_TR_MAC_NC) ||
3799                             (hdr_mac == QETH_TR_MAC_C))
3800                                 return RTN_MULTICAST;
3801                         break;
3802                 /* eth or so multicast? */
3803                 default:
3804                         if ((hdr_mac == QETH_ETH_MAC_V4) ||
3805                             (hdr_mac == QETH_ETH_MAC_V6))
3806                                 return RTN_MULTICAST;
3807                 }
3808         }
3809         return cast_type;
3810 }
3811
3812 static int
3813 qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3814                         int ipv, int cast_type)
3815 {
3816         if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3817                 return card->qdio.default_out_queue;
3818         switch (card->qdio.no_out_queues) {
3819         case 4:
3820                 if (cast_type && card->info.is_multicast_different)
3821                         return card->info.is_multicast_different &
3822                                 (card->qdio.no_out_queues - 1);
3823                 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3824                         const u8 tos = ip_hdr(skb)->tos;
3825
3826                         if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
3827                                 if (tos & IP_TOS_NOTIMPORTANT)
3828                                         return 3;
3829                                 if (tos & IP_TOS_HIGHRELIABILITY)
3830                                         return 2;
3831                                 if (tos & IP_TOS_HIGHTHROUGHPUT)
3832                                         return 1;
3833                                 if (tos & IP_TOS_LOWDELAY)
3834                                         return 0;
3835                         }
3836                         if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
3837                                 return 3 - (tos >> 6);
3838                 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3839                         /* TODO: IPv6!!! */
3840                 }
3841                 return card->qdio.default_out_queue;
3842         case 1: /* fallthrough for single-out-queue 1920-device */
3843         default:
3844                 return card->qdio.default_out_queue;
3845         }
3846 }
3847
3848 static inline int
3849 qeth_get_ip_version(struct sk_buff *skb)
3850 {
3851         switch (skb->protocol) {
3852         case ETH_P_IPV6:
3853                 return 6;
3854         case ETH_P_IP:
3855                 return 4;
3856         default:
3857                 return 0;
3858         }
3859 }
3860
3861 static struct qeth_hdr *
3862 __qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, int ipv)
3863 {
3864 #ifdef CONFIG_QETH_VLAN
3865         u16 *tag;
3866         if (card->vlangrp && vlan_tx_tag_present(skb) &&
3867             ((ipv == 6) || card->options.layer2) ) {
3868                 /*
3869                  * Move the mac addresses (6 bytes src, 6 bytes dest)
3870                  * to the beginning of the new header.  We are using three
3871                  * memcpys instead of one memmove to save cycles.
3872                  */
3873                 skb_push(skb, VLAN_HLEN);
3874                 skb_copy_to_linear_data(skb, skb->data + 4, 4);
3875                 skb_copy_to_linear_data_offset(skb, 4, skb->data + 8, 4);
3876                 skb_copy_to_linear_data_offset(skb, 8, skb->data + 12, 4);
3877                 tag = (u16 *)(skb->data + 12);
3878                 /*
3879                  * first two bytes  = ETH_P_8021Q (0x8100)
3880                  * second two bytes = VLANID
3881                  */
3882                 *tag = __constant_htons(ETH_P_8021Q);
3883                 *(tag + 1) = htons(vlan_tx_tag_get(skb));
3884         }
3885 #endif
3886         return ((struct qeth_hdr *)
3887                 qeth_push_skb(card, skb, sizeof(struct qeth_hdr)));
3888 }
3889
3890 static void
3891 __qeth_free_new_skb(struct sk_buff *orig_skb, struct sk_buff *new_skb)
3892 {
3893         if (orig_skb != new_skb)
3894                 dev_kfree_skb_any(new_skb);
3895 }
3896
3897 static struct sk_buff *
3898 qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb,
3899                  struct qeth_hdr **hdr, int ipv)
3900 {
3901         struct sk_buff *new_skb, *new_skb2;
3902         
3903         QETH_DBF_TEXT(trace, 6, "prepskb");
3904         new_skb = skb;
3905         new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
3906         if (!new_skb)
3907                 return NULL;
3908         new_skb2 = qeth_realloc_headroom(card, new_skb,
3909                                          sizeof(struct qeth_hdr));
3910         if (!new_skb2) {
3911                 __qeth_free_new_skb(skb, new_skb);
3912                 return NULL;
3913         }
3914         if (new_skb != skb)
3915                 __qeth_free_new_skb(new_skb2, new_skb);
3916         new_skb = new_skb2;
3917         *hdr = __qeth_prepare_skb(card, new_skb, ipv);
3918         if (*hdr == NULL) {
3919                 __qeth_free_new_skb(skb, new_skb);
3920                 return NULL;
3921         }
3922         return new_skb;
3923 }
3924
3925 static inline u8
3926 qeth_get_qeth_hdr_flags4(int cast_type)
3927 {
3928         if (cast_type == RTN_MULTICAST)
3929                 return QETH_CAST_MULTICAST;
3930         if (cast_type == RTN_BROADCAST)
3931                 return QETH_CAST_BROADCAST;
3932         return QETH_CAST_UNICAST;
3933 }
3934
3935 static inline u8
3936 qeth_get_qeth_hdr_flags6(int cast_type)
3937 {
3938         u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
3939         if (cast_type == RTN_MULTICAST)
3940                 return ct | QETH_CAST_MULTICAST;
3941         if (cast_type == RTN_ANYCAST)
3942                 return ct | QETH_CAST_ANYCAST;
3943         if (cast_type == RTN_BROADCAST)
3944                 return ct | QETH_CAST_BROADCAST;
3945         return ct | QETH_CAST_UNICAST;
3946 }
3947
3948 static void
3949 qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
3950                             struct sk_buff *skb)
3951 {
3952         __u16 hdr_mac;
3953
3954         if (!memcmp(skb->data+QETH_HEADER_SIZE,
3955                     skb->dev->broadcast,6)) { /* broadcast? */
3956                 *(__u32 *)hdr->hdr.l2.flags |=
3957                          QETH_LAYER2_FLAG_BROADCAST << 8;
3958                 return;
3959         }
3960         hdr_mac=*((__u16*)skb->data);
3961         /* tr multicast? */
3962         switch (card->info.link_type) {
3963         case QETH_LINK_TYPE_HSTR:
3964         case QETH_LINK_TYPE_LANE_TR:
3965                 if ((hdr_mac == QETH_TR_MAC_NC) ||
3966                     (hdr_mac == QETH_TR_MAC_C) )
3967                         *(__u32 *)hdr->hdr.l2.flags |=
3968                                 QETH_LAYER2_FLAG_MULTICAST << 8;
3969                 else
3970                         *(__u32 *)hdr->hdr.l2.flags |=
3971                                 QETH_LAYER2_FLAG_UNICAST << 8;
3972                 break;
3973                 /* eth or so multicast? */
3974         default:
3975                 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
3976                      (hdr_mac==QETH_ETH_MAC_V6) )
3977                         *(__u32 *)hdr->hdr.l2.flags |=
3978                                 QETH_LAYER2_FLAG_MULTICAST << 8;
3979                 else
3980                         *(__u32 *)hdr->hdr.l2.flags |=
3981                                 QETH_LAYER2_FLAG_UNICAST << 8;
3982         }
3983 }
3984
3985 static void
3986 qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
3987                         struct sk_buff *skb, int cast_type)
3988 {
3989         memset(hdr, 0, sizeof(struct qeth_hdr));
3990         hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
3991
3992         /* set byte 0 to "0x02" and byte 3 to casting flags */
3993         if (cast_type==RTN_MULTICAST)
3994                 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
3995         else if (cast_type==RTN_BROADCAST)
3996                 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
3997          else
3998                 qeth_layer2_get_packet_type(card, hdr, skb);
3999
4000         hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
4001 #ifdef CONFIG_QETH_VLAN
4002         /* VSWITCH relies on the VLAN
4003          * information to be present in
4004          * the QDIO header */
4005         if ((card->vlangrp != NULL) &&
4006             vlan_tx_tag_present(skb)) {
4007                 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
4008                 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
4009         }
4010 #endif
4011 }
4012
4013 void
4014 qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4015                 struct sk_buff *skb, int ipv, int cast_type)
4016 {
4017         QETH_DBF_TEXT(trace, 6, "fillhdr");
4018
4019         memset(hdr, 0, sizeof(struct qeth_hdr));
4020         if (card->options.layer2) {
4021                 qeth_layer2_fill_header(card, hdr, skb, cast_type);
4022                 return;
4023         }
4024         hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
4025         hdr->hdr.l3.ext_flags = 0;
4026 #ifdef CONFIG_QETH_VLAN
4027         /*
4028          * before we're going to overwrite this location with next hop ip.
4029          * v6 uses passthrough, v4 sets the tag in the QDIO header.
4030          */
4031         if (card->vlangrp && vlan_tx_tag_present(skb)) {
4032                 hdr->hdr.l3.ext_flags = (ipv == 4) ?
4033                         QETH_HDR_EXT_VLAN_FRAME :
4034                         QETH_HDR_EXT_INCLUDE_VLAN_TAG;
4035                 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
4036         }
4037 #endif /* CONFIG_QETH_VLAN */
4038         hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
4039         if (ipv == 4) {  /* IPv4 */
4040                 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
4041                 memset(hdr->hdr.l3.dest_addr, 0, 12);
4042                 if ((skb->dst) && (skb->dst->neighbour)) {
4043                         *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
4044                             *((u32 *) skb->dst->neighbour->primary_key);
4045                 } else {
4046                         /* fill in destination address used in ip header */
4047                         *((u32 *)(&hdr->hdr.l3.dest_addr[12])) =
4048                                                            ip_hdr(skb)->daddr;
4049                 }
4050         } else if (ipv == 6) { /* IPv6 or passthru */
4051                 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
4052                 if ((skb->dst) && (skb->dst->neighbour)) {
4053                         memcpy(hdr->hdr.l3.dest_addr,
4054                                skb->dst->neighbour->primary_key, 16);
4055                 } else {
4056                         /* fill in destination address used in ip header */
4057                         memcpy(hdr->hdr.l3.dest_addr,
4058                                &ipv6_hdr(skb)->daddr, 16);
4059                 }
4060         } else { /* passthrough */
4061                 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
4062                     !memcmp(skb->data + sizeof(struct qeth_hdr) +
4063                     sizeof(__u16), skb->dev->broadcast, 6)) {
4064                         hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4065                                                 QETH_HDR_PASSTHRU;
4066                 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
4067                             skb->dev->broadcast, 6)) {   /* broadcast? */
4068                         hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4069                                                 QETH_HDR_PASSTHRU;
4070                 } else {
4071                         hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
4072                                 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
4073                                 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
4074                 }
4075         }
4076 }
4077
4078 static void
4079 __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
4080                    int is_tso, int *next_element_to_fill)
4081 {
4082         int length = skb->len;
4083         int length_here;
4084         int element;
4085         char *data;
4086         int first_lap ;
4087
4088         element = *next_element_to_fill;
4089         data = skb->data;
4090         first_lap = (is_tso == 0 ? 1 : 0);
4091
4092         while (length > 0) {
4093                 /* length_here is the remaining amount of data in this page */
4094                 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4095                 if (length < length_here)
4096                         length_here = length;
4097
4098                 buffer->element[element].addr = data;
4099                 buffer->element[element].length = length_here;
4100                 length -= length_here;
4101                 if (!length) {
4102                         if (first_lap)
4103                                 buffer->element[element].flags = 0;
4104                         else
4105                                 buffer->element[element].flags =
4106                                     SBAL_FLAGS_LAST_FRAG;
4107                 } else {
4108                         if (first_lap)
4109                                 buffer->element[element].flags =
4110                                     SBAL_FLAGS_FIRST_FRAG;
4111                         else
4112                                 buffer->element[element].flags =
4113                                     SBAL_FLAGS_MIDDLE_FRAG;
4114                 }
4115                 data += length_here;
4116                 element++;
4117                 first_lap = 0;
4118         }
4119         *next_element_to_fill = element;
4120 }
4121
4122 static int
4123 qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4124                  struct qeth_qdio_out_buffer *buf,
4125                  struct sk_buff *skb)
4126 {
4127         struct qdio_buffer *buffer;
4128         struct qeth_hdr_tso *hdr;
4129         int flush_cnt = 0, hdr_len, large_send = 0;
4130
4131         QETH_DBF_TEXT(trace, 6, "qdfillbf");
4132
4133         buffer = buf->buffer;
4134         atomic_inc(&skb->users);
4135         skb_queue_tail(&buf->skb_list, skb);
4136
4137         hdr  = (struct qeth_hdr_tso *) skb->data;
4138         /*check first on TSO ....*/
4139         if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4140                 int element = buf->next_element_to_fill;
4141
4142                 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4143                 /*fill first buffer entry only with header information */
4144                 buffer->element[element].addr = skb->data;
4145                 buffer->element[element].length = hdr_len;
4146                 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4147                 buf->next_element_to_fill++;
4148                 skb->data += hdr_len;
4149                 skb->len  -= hdr_len;
4150                 large_send = 1;
4151         }
4152         if (skb_shinfo(skb)->nr_frags == 0)
4153                 __qeth_fill_buffer(skb, buffer, large_send,
4154                                    (int *)&buf->next_element_to_fill);
4155         else
4156                 __qeth_fill_buffer_frag(skb, buffer, large_send,
4157                                         (int *)&buf->next_element_to_fill);
4158
4159         if (!queue->do_pack) {
4160                 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4161                 /* set state to PRIMED -> will be flushed */
4162                 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4163                 flush_cnt = 1;
4164         } else {
4165                 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4166                 if (queue->card->options.performance_stats)
4167                         queue->card->perf_stats.skbs_sent_pack++;
4168                 if (buf->next_element_to_fill >=
4169                                 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4170                         /*
4171                          * packed buffer if full -> set state PRIMED
4172                          * -> will be flushed
4173                          */
4174                         atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4175                         flush_cnt = 1;
4176                 }
4177         }
4178         return flush_cnt;
4179 }
4180
4181 static int
4182 qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4183                          struct sk_buff *skb, struct qeth_hdr *hdr,
4184                          int elements_needed,
4185                          struct qeth_eddp_context *ctx)
4186 {
4187         struct qeth_qdio_out_buffer *buffer;
4188         int buffers_needed = 0;
4189         int flush_cnt = 0;
4190         int index;
4191
4192         QETH_DBF_TEXT(trace, 6, "dosndpfa");
4193
4194         /* spin until we get the queue ... */
4195         while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4196                               QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4197         /* ... now we've got the queue */
4198         index = queue->next_buf_to_fill;
4199         buffer = &queue->bufs[queue->next_buf_to_fill];
4200         /*
4201          * check if buffer is empty to make sure that we do not 'overtake'
4202          * ourselves and try to fill a buffer that is already primed
4203          */
4204         if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) 
4205                 goto out;
4206         if (ctx == NULL)
4207                 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4208                                           QDIO_MAX_BUFFERS_PER_Q;
4209         else {
4210                 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4211                 if (buffers_needed < 0) 
4212                         goto out;
4213                 queue->next_buf_to_fill =
4214                         (queue->next_buf_to_fill + buffers_needed) %
4215                         QDIO_MAX_BUFFERS_PER_Q;
4216         }
4217         atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4218         if (ctx == NULL) {
4219                 qeth_fill_buffer(queue, buffer, skb);
4220                 qeth_flush_buffers(queue, 0, index, 1);
4221         } else {
4222                 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4223                 WARN_ON(buffers_needed != flush_cnt);
4224                 qeth_flush_buffers(queue, 0, index, flush_cnt);
4225         }
4226         return 0;
4227 out:
4228         atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4229         return -EBUSY;
4230 }
4231
4232 static int
4233 qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4234                     struct sk_buff *skb, struct qeth_hdr *hdr,
4235                     int elements_needed, struct qeth_eddp_context *ctx)
4236 {
4237         struct qeth_qdio_out_buffer *buffer;
4238         int start_index;
4239         int flush_count = 0;
4240         int do_pack = 0;
4241         int tmp;
4242         int rc = 0;
4243
4244         QETH_DBF_TEXT(trace, 6, "dosndpkt");
4245
4246         /* spin until we get the queue ... */
4247         while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4248                               QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4249         start_index = queue->next_buf_to_fill;
4250         buffer = &queue->bufs[queue->next_buf_to_fill];
4251         /*
4252          * check if buffer is empty to make sure that we do not 'overtake'
4253          * ourselves and try to fill a buffer that is already primed
4254          */
4255         if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4256                 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4257                 return -EBUSY;
4258         }
4259         /* check if we need to switch packing state of this queue */
4260         qeth_switch_to_packing_if_needed(queue);
4261         if (queue->do_pack){
4262                 do_pack = 1;
4263                 if (ctx == NULL) {
4264                         /* does packet fit in current buffer? */
4265                         if((QETH_MAX_BUFFER_ELEMENTS(card) -
4266                             buffer->next_element_to_fill) < elements_needed){
4267                                 /* ... no -> set state PRIMED */
4268                                 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4269                                 flush_count++;
4270                                 queue->next_buf_to_fill =
4271                                         (queue->next_buf_to_fill + 1) %
4272                                         QDIO_MAX_BUFFERS_PER_Q;
4273                                 buffer = &queue->bufs[queue->next_buf_to_fill];
4274                                 /* we did a step forward, so check buffer state
4275                                  * again */
4276                                 if (atomic_read(&buffer->state) !=
4277                                                 QETH_QDIO_BUF_EMPTY){
4278                                         qeth_flush_buffers(queue, 0, start_index, flush_count);
4279                                         atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4280                                         return -EBUSY;
4281                                 }
4282                         }
4283                 } else {
4284                         /* check if we have enough elements (including following
4285                          * free buffers) to handle eddp context */
4286                         if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4287                                 printk("eddp tx_dropped 1\n");
4288                                 rc = -EBUSY;
4289                                 goto out;
4290                         }
4291                 }
4292         }
4293         if (ctx == NULL)
4294                 tmp = qeth_fill_buffer(queue, buffer, skb);
4295         else {
4296                 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4297                 if (tmp < 0) {
4298                         printk("eddp tx_dropped 2\n");
4299                         rc = - EBUSY;
4300                         goto out;
4301                 }
4302         }
4303         queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4304                                   QDIO_MAX_BUFFERS_PER_Q;
4305         flush_count += tmp;
4306 out:
4307         if (flush_count)
4308                 qeth_flush_buffers(queue, 0, start_index, flush_count);
4309         else if (!atomic_read(&queue->set_pci_flags_count))
4310                 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
4311         /*
4312          * queue->state will go from LOCKED -> UNLOCKED or from
4313          * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4314          * (switch packing state or flush buffer to get another pci flag out).
4315          * In that case we will enter this loop
4316          */
4317         while (atomic_dec_return(&queue->state)){
4318                 flush_count = 0;
4319                 start_index = queue->next_buf_to_fill;
4320                 /* check if we can go back to non-packing state */
4321                 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4322                 /*
4323                  * check if we need to flush a packing buffer to get a pci
4324                  * flag out on the queue
4325                  */
4326                 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4327                         flush_count += qeth_flush_buffers_on_no_pci(queue);
4328                 if (flush_count)
4329                         qeth_flush_buffers(queue, 0, start_index, flush_count);
4330         }
4331         /* at this point the queue is UNLOCKED again */
4332         if (queue->card->options.performance_stats && do_pack)
4333                 queue->card->perf_stats.bufs_sent_pack += flush_count;
4334
4335         return rc;
4336 }
4337
4338 static int
4339 qeth_get_elements_no(struct qeth_card *card, void *hdr,
4340                      struct sk_buff *skb, int elems)
4341 {
4342         int elements_needed = 0;
4343
4344         if (skb_shinfo(skb)->nr_frags > 0) 
4345                 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4346         if (elements_needed == 0)
4347                 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4348                                         + skb->len) >> PAGE_SHIFT);
4349         if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4350                 PRINT_ERR("Invalid size of IP packet "
4351                           "(Number=%d / Length=%d). Discarded.\n",
4352                           (elements_needed+elems), skb->len);
4353                 return 0;
4354         }
4355         return elements_needed;
4356 }
4357
4358
4359 static int
4360 qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4361 {
4362         int ipv = 0;
4363         int cast_type;
4364         struct qeth_qdio_out_q *queue;
4365         struct qeth_hdr *hdr = NULL;
4366         int elements_needed = 0;
4367         enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4368         struct qeth_eddp_context *ctx = NULL;
4369         int tx_bytes = skb->len;
4370         unsigned short nr_frags = skb_shinfo(skb)->nr_frags;
4371         unsigned short tso_size = skb_shinfo(skb)->gso_size;
4372         struct sk_buff *new_skb, *new_skb2;
4373         int rc;
4374
4375         QETH_DBF_TEXT(trace, 6, "sendpkt");
4376
4377         new_skb = skb;
4378         if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4379             (skb->protocol == htons(ETH_P_IPV6)))
4380                 return -EPERM;
4381         cast_type = qeth_get_cast_type(card, skb);
4382         if ((cast_type == RTN_BROADCAST) &&
4383             (card->info.broadcast_capable == 0))
4384                 return -EPERM;
4385         queue = card->qdio.out_qs
4386                 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4387         if (!card->options.layer2) {
4388                 ipv = qeth_get_ip_version(skb);
4389                 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4390                         new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
4391                         if (!new_skb)
4392                                 return -ENOMEM;
4393                         if(card->dev->type == ARPHRD_IEEE802_TR){
4394                                 skb_pull(new_skb, QETH_FAKE_LL_LEN_TR);
4395                         } else {
4396                                 skb_pull(new_skb, QETH_FAKE_LL_LEN_ETH);
4397                         }
4398                 }
4399         }
4400         if (skb_is_gso(skb))
4401                 large_send = card->options.large_send;
4402         /* check on OSN device*/
4403         if (card->info.type == QETH_CARD_TYPE_OSN)
4404                 hdr = (struct qeth_hdr *)new_skb->data;
4405         /*are we able to do TSO ? */
4406         if ((large_send == QETH_LARGE_SEND_TSO) &&
4407             (cast_type == RTN_UNSPEC)) {
4408                 rc = qeth_tso_prepare_packet(card, new_skb, ipv, cast_type);
4409                 if (rc) {
4410                         __qeth_free_new_skb(skb, new_skb);
4411                         return rc;
4412                 }
4413                 elements_needed++;
4414         } else if (card->info.type != QETH_CARD_TYPE_OSN) {
4415                 new_skb2 = qeth_prepare_skb(card, new_skb, &hdr, ipv);
4416                 if (!new_skb2) {
4417                         __qeth_free_new_skb(skb, new_skb);
4418                         return -EINVAL;
4419                 }
4420                 if (new_skb != skb)
4421                         __qeth_free_new_skb(new_skb2, new_skb);
4422                 new_skb = new_skb2;
4423                 qeth_fill_header(card, hdr, new_skb, ipv, cast_type);
4424         }
4425         if (large_send == QETH_LARGE_SEND_EDDP) {
4426                 ctx = qeth_eddp_create_context(card, new_skb, hdr);
4427                 if (ctx == NULL) {
4428                         __qeth_free_new_skb(skb, new_skb);
4429                         PRINT_WARN("could not create eddp context\n");
4430                         return -EINVAL;
4431                 }
4432         } else {
4433                 int elems = qeth_get_elements_no(card,(void*) hdr, new_skb,
4434                                                  elements_needed);
4435                 if (!elems) {
4436                         __qeth_free_new_skb(skb, new_skb);
4437                         return -EINVAL;
4438                 }
4439                 elements_needed += elems;
4440         }
4441
4442         if (card->info.type != QETH_CARD_TYPE_IQD)
4443                 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
4444                                          elements_needed, ctx);
4445         else
4446                 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
4447                                               elements_needed, ctx);
4448         if (!rc) {
4449                 card->stats.tx_packets++;
4450                 card->stats.tx_bytes += tx_bytes;
4451                 if (new_skb != skb)
4452                         dev_kfree_skb_any(skb);
4453                 if (card->options.performance_stats) {
4454                         if (tso_size &&
4455                             !(large_send == QETH_LARGE_SEND_NO)) {
4456                                 card->perf_stats.large_send_bytes += tx_bytes;
4457                                 card->perf_stats.large_send_cnt++;
4458                         }
4459                         if (nr_frags > 0) {
4460                                 card->perf_stats.sg_skbs_sent++;
4461                                 /* nr_frags + skb->data */
4462                                 card->perf_stats.sg_frags_sent +=
4463                                         nr_frags + 1;
4464                         }
4465                 }
4466         } else {
4467                 card->stats.tx_dropped++;
4468                 __qeth_free_new_skb(skb, new_skb);
4469         }
4470         if (ctx != NULL) {
4471                 /* drop creator's reference */
4472                 qeth_eddp_put_context(ctx);
4473                 /* free skb; it's not referenced by a buffer */
4474                 if (!rc)
4475                        dev_kfree_skb_any(new_skb);
4476         }
4477         return rc;
4478 }
4479
4480 static int
4481 qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4482 {
4483         struct qeth_card *card = (struct qeth_card *) dev->priv;
4484         int rc = 0;
4485
4486         switch(regnum){
4487         case MII_BMCR: /* Basic mode control register */
4488                 rc = BMCR_FULLDPLX;
4489                 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4490                     (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4491                     (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4492                         rc |= BMCR_SPEED100;
4493                 break;
4494         case MII_BMSR: /* Basic mode status register */
4495                 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4496                      BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4497                      BMSR_100BASE4;
4498                 break;
4499         case MII_PHYSID1: /* PHYS ID 1 */
4500                 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4501                      dev->dev_addr[2];
4502                 rc = (rc >> 5) & 0xFFFF;
4503                 break;
4504         case MII_PHYSID2: /* PHYS ID 2 */
4505                 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4506                 break;
4507         case MII_ADVERTISE: /* Advertisement control reg */
4508                 rc = ADVERTISE_ALL;
4509                 break;
4510         case MII_LPA: /* Link partner ability reg */
4511                 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4512                      LPA_100BASE4 | LPA_LPACK;
4513                 break;
4514         case MII_EXPANSION: /* Expansion register */
4515                 break;
4516         case MII_DCOUNTER: /* disconnect counter */
4517                 break;
4518         case MII_FCSCOUNTER: /* false carrier counter */
4519                 break;
4520         case MII_NWAYTEST: /* N-way auto-neg test register */
4521                 break;
4522         case MII_RERRCOUNTER: /* rx error counter */
4523                 rc = card->stats.rx_errors;
4524                 break;
4525         case MII_SREVISION: /* silicon revision */
4526                 break;
4527         case MII_RESV1: /* reserved 1 */
4528                 break;
4529         case MII_LBRERROR: /* loopback, rx, bypass error */
4530                 break;
4531         case MII_PHYADDR: /* physical address */
4532                 break;
4533         case MII_RESV2: /* reserved 2 */
4534                 break;
4535         case MII_TPISTATUS: /* TPI status for 10mbps */
4536                 break;
4537         case MII_NCONFIG: /* network interface config */
4538                 break;
4539         default:
4540                 break;
4541         }
4542         return rc;
4543 }
4544
4545
4546 static const char *
4547 qeth_arp_get_error_cause(int *rc)
4548 {
4549         switch (*rc) {
4550         case QETH_IPA_ARP_RC_FAILED:
4551                 *rc = -EIO;
4552                 return "operation failed";
4553         case QETH_IPA_ARP_RC_NOTSUPP:
4554                 *rc = -EOPNOTSUPP;
4555                 return "operation not supported";
4556         case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4557                 *rc = -EINVAL;
4558                 return "argument out of range";
4559         case QETH_IPA_ARP_RC_Q_NOTSUPP:
4560                 *rc = -EOPNOTSUPP;
4561                 return "query operation not supported";
4562         case QETH_IPA_ARP_RC_Q_NO_DATA:
4563                 *rc = -ENOENT;
4564                 return "no query data available";
4565         default:
4566                 return "unknown error";
4567         }
4568 }
4569
4570 static int
4571 qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4572                              __u16, long);
4573
4574 static int
4575 qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4576 {
4577         int tmp;
4578         int rc;
4579
4580         QETH_DBF_TEXT(trace,3,"arpstnoe");
4581
4582         /*
4583          * currently GuestLAN only supports the ARP assist function
4584          * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4585          * thus we say EOPNOTSUPP for this ARP function
4586          */
4587         if (card->info.guestlan)
4588                 return -EOPNOTSUPP;
4589         if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4590                 PRINT_WARN("ARP processing not supported "
4591                            "on %s!\n", QETH_CARD_IFNAME(card));
4592                 return -EOPNOTSUPP;
4593         }
4594         rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4595                                           IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4596                                           no_entries);
4597         if (rc) {
4598                 tmp = rc;
4599                 PRINT_WARN("Could not set number of ARP entries on %s: "
4600                            "%s (0x%x/%d)\n",
4601                            QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4602                            tmp, tmp);
4603         }
4604         return rc;
4605 }
4606
4607 static void
4608 qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4609                                struct qeth_arp_query_data *qdata,
4610                                int entry_size, int uentry_size)
4611 {
4612         char *entry_ptr;
4613         char *uentry_ptr;
4614         int i;
4615
4616         entry_ptr = (char *)&qdata->data;
4617         uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4618         for (i = 0; i < qdata->no_entries; ++i){
4619                 /* strip off 32 bytes "media specific information" */
4620                 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4621                 entry_ptr += entry_size;
4622                 uentry_ptr += uentry_size;
4623         }
4624 }
4625
4626 static int
4627 qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4628                   unsigned long data)
4629 {
4630         struct qeth_ipa_cmd *cmd;
4631         struct qeth_arp_query_data *qdata;
4632         struct qeth_arp_query_info *qinfo;
4633         int entry_size;
4634         int uentry_size;
4635         int i;
4636
4637         QETH_DBF_TEXT(trace,4,"arpquecb");
4638
4639         qinfo = (struct qeth_arp_query_info *) reply->param;
4640         cmd = (struct qeth_ipa_cmd *) data;
4641         if (cmd->hdr.return_code) {
4642                 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4643                 return 0;
4644         }
4645         if (cmd->data.setassparms.hdr.return_code) {
4646                 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4647                 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4648                 return 0;
4649         }
4650         qdata = &cmd->data.setassparms.data.query_arp;
4651         switch(qdata->reply_bits){
4652         case 5:
4653                 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4654                 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4655                         uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4656                 break;
4657         case 7:
4658                 /* fall through to default */
4659         default:
4660                 /* tr is the same as eth -> entry7 */
4661                 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4662                 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4663                         uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4664                 break;
4665         }
4666         /* check if there is enough room in userspace */
4667         if ((qinfo->udata_len - qinfo->udata_offset) <
4668                         qdata->no_entries * uentry_size){
4669                 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4670                 cmd->hdr.return_code = -ENOMEM;
4671                 PRINT_WARN("query ARP user space buffer is too small for "
4672                            "the returned number of ARP entries. "
4673                            "Aborting query!\n");
4674                 goto out_error;
4675         }
4676         QETH_DBF_TEXT_(trace, 4, "anore%i",
4677                        cmd->data.setassparms.hdr.number_of_replies);
4678         QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4679         QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4680
4681         if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4682                 /* strip off "media specific information" */
4683                 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4684                                                uentry_size);
4685         } else
4686                 /*copy entries to user buffer*/
4687                 memcpy(qinfo->udata + qinfo->udata_offset,
4688                        (char *)&qdata->data, qdata->no_entries*uentry_size);
4689
4690         qinfo->no_entries += qdata->no_entries;
4691         qinfo->udata_offset += (qdata->no_entries*uentry_size);
4692         /* check if all replies received ... */
4693         if (cmd->data.setassparms.hdr.seq_no <
4694             cmd->data.setassparms.hdr.number_of_replies)
4695                 return 1;
4696         memcpy(qinfo->udata, &qinfo->no_entries, 4);
4697         /* keep STRIP_ENTRIES flag so the user program can distinguish
4698          * stripped entries from normal ones */
4699         if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4700                 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4701         memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4702         return 0;
4703 out_error:
4704         i = 0;
4705         memcpy(qinfo->udata, &i, 4);
4706         return 0;
4707 }
4708
4709 static int
4710 qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4711                       int len, int (*reply_cb)(struct qeth_card *,
4712                                                struct qeth_reply *,
4713                                                unsigned long),
4714                       void *reply_param)
4715 {
4716         QETH_DBF_TEXT(trace,4,"sendarp");
4717
4718         memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4719         memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4720                &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4721         return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4722                                       reply_cb, reply_param);
4723 }
4724
4725 static int
4726 qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4727                       int len, int (*reply_cb)(struct qeth_card *,
4728                                                struct qeth_reply *,
4729                                                unsigned long),
4730                       void *reply_param)
4731 {
4732         u16 s1, s2;
4733
4734         QETH_DBF_TEXT(trace,4,"sendsnmp");
4735
4736         memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4737         memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4738                &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4739         /* adjust PDU length fields in IPA_PDU_HEADER */
4740         s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4741         s2 = (u32) len;
4742         memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4743         memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4744         memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4745         memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4746         return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4747                                       reply_cb, reply_param);
4748 }
4749
4750 static struct qeth_cmd_buffer *
4751 qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4752                          __u16, __u16, enum qeth_prot_versions);
4753 static int
4754 qeth_arp_query(struct qeth_card *card, char __user *udata)
4755 {
4756         struct qeth_cmd_buffer *iob;
4757         struct qeth_arp_query_info qinfo = {0, };
4758         int tmp;
4759         int rc;
4760
4761         QETH_DBF_TEXT(trace,3,"arpquery");
4762
4763         if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4764                                IPA_ARP_PROCESSING)) {
4765                 PRINT_WARN("ARP processing not supported "
4766                            "on %s!\n", QETH_CARD_IFNAME(card));
4767                 return -EOPNOTSUPP;
4768         }
4769         /* get size of userspace buffer and mask_bits -> 6 bytes */
4770         if (copy_from_user(&qinfo, udata, 6))
4771                 return -EFAULT;
4772         if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL)))
4773                 return -ENOMEM;
4774         qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4775         iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4776                                        IPA_CMD_ASS_ARP_QUERY_INFO,
4777                                        sizeof(int),QETH_PROT_IPV4);
4778
4779         rc = qeth_send_ipa_arp_cmd(card, iob,
4780                                    QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4781                                    qeth_arp_query_cb, (void *)&qinfo);
4782         if (rc) {
4783                 tmp = rc;
4784                 PRINT_WARN("Error while querying ARP cache on %s: %s "
4785                            "(0x%x/%d)\n",
4786                            QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4787                            tmp, tmp);
4788                 if (copy_to_user(udata, qinfo.udata, 4))
4789                         rc = -EFAULT;
4790         } else {
4791                 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4792                         rc = -EFAULT;
4793         }
4794         kfree(qinfo.udata);
4795         return rc;
4796 }
4797
4798 /**
4799  * SNMP command callback
4800  */
4801 static int
4802 qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4803                      unsigned long sdata)
4804 {
4805         struct qeth_ipa_cmd *cmd;
4806         struct qeth_arp_query_info *qinfo;
4807         struct qeth_snmp_cmd *snmp;
4808         unsigned char *data;
4809         __u16 data_len;
4810
4811         QETH_DBF_TEXT(trace,3,"snpcmdcb");
4812
4813         cmd = (struct qeth_ipa_cmd *) sdata;
4814         data = (unsigned char *)((char *)cmd - reply->offset);
4815         qinfo = (struct qeth_arp_query_info *) reply->param;
4816         snmp = &cmd->data.setadapterparms.data.snmp;
4817
4818         if (cmd->hdr.return_code) {
4819                 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4820                 return 0;
4821         }
4822         if (cmd->data.setadapterparms.hdr.return_code) {
4823                 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4824                 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4825                 return 0;
4826         }
4827         data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4828         if (cmd->data.setadapterparms.hdr.seq_no == 1)
4829                 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4830         else
4831                 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4832
4833         /* check if there is enough room in userspace */
4834         if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4835                 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4836                 cmd->hdr.return_code = -ENOMEM;
4837                 return 0;
4838         }
4839         QETH_DBF_TEXT_(trace, 4, "snore%i",
4840                        cmd->data.setadapterparms.hdr.used_total);
4841         QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4842         /*copy entries to user buffer*/
4843         if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4844                 memcpy(qinfo->udata + qinfo->udata_offset,
4845                        (char *)snmp,
4846                        data_len + offsetof(struct qeth_snmp_cmd,data));
4847                 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4848         } else {
4849                 memcpy(qinfo->udata + qinfo->udata_offset,
4850                        (char *)&snmp->request, data_len);
4851         }
4852         qinfo->udata_offset += data_len;
4853         /* check if all replies received ... */
4854                 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4855                                cmd->data.setadapterparms.hdr.used_total);
4856                 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4857                                cmd->data.setadapterparms.hdr.seq_no);
4858         if (cmd->data.setadapterparms.hdr.seq_no <
4859             cmd->data.setadapterparms.hdr.used_total)
4860                 return 1;
4861         return 0;
4862 }
4863
4864 static struct qeth_cmd_buffer *
4865 qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4866                        enum qeth_prot_versions );
4867
4868 static struct qeth_cmd_buffer *
4869 qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4870 {
4871         struct qeth_cmd_buffer *iob;
4872         struct qeth_ipa_cmd *cmd;
4873
4874         iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4875                                      QETH_PROT_IPV4);
4876         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4877         cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4878         cmd->data.setadapterparms.hdr.command_code = command;
4879         cmd->data.setadapterparms.hdr.used_total = 1;
4880         cmd->data.setadapterparms.hdr.seq_no = 1;
4881
4882         return iob;
4883 }
4884
4885 /**
4886  * function to send SNMP commands to OSA-E card
4887  */
4888 static int
4889 qeth_snmp_command(struct qeth_card *card, char __user *udata)
4890 {
4891         struct qeth_cmd_buffer *iob;
4892         struct qeth_ipa_cmd *cmd;
4893         struct qeth_snmp_ureq *ureq;
4894         int req_len;
4895         struct qeth_arp_query_info qinfo = {0, };
4896         int rc = 0;
4897
4898         QETH_DBF_TEXT(trace,3,"snmpcmd");
4899
4900         if (card->info.guestlan)
4901                 return -EOPNOTSUPP;
4902
4903         if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4904             (!card->options.layer2) ) {
4905                 PRINT_WARN("SNMP Query MIBS not supported "
4906                            "on %s!\n", QETH_CARD_IFNAME(card));
4907                 return -EOPNOTSUPP;
4908         }
4909         /* skip 4 bytes (data_len struct member) to get req_len */
4910         if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4911                 return -EFAULT;
4912         ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4913         if (!ureq) {
4914                 QETH_DBF_TEXT(trace, 2, "snmpnome");
4915                 return -ENOMEM;
4916         }
4917         if (copy_from_user(ureq, udata,
4918                         req_len+sizeof(struct qeth_snmp_ureq_hdr))){
4919                 kfree(ureq);
4920                 return -EFAULT;
4921         }
4922         qinfo.udata_len = ureq->hdr.data_len;
4923         if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){
4924                 kfree(ureq);
4925                 return -ENOMEM;
4926         }
4927         qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4928
4929         iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
4930                                    QETH_SNMP_SETADP_CMDLENGTH + req_len);
4931         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4932         memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
4933         rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
4934                                     qeth_snmp_command_cb, (void *)&qinfo);
4935         if (rc)
4936                 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
4937                            QETH_CARD_IFNAME(card), rc);
4938         else {
4939                 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4940                         rc = -EFAULT;
4941         }
4942
4943         kfree(ureq);
4944         kfree(qinfo.udata);
4945         return rc;
4946 }
4947
4948 static int
4949 qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
4950                             unsigned long);
4951
4952 static int
4953 qeth_default_setadapterparms_cb(struct qeth_card *card,
4954                                 struct qeth_reply *reply,
4955                                 unsigned long data);
4956 static int
4957 qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
4958                       __u16, long,
4959                       int (*reply_cb)
4960                       (struct qeth_card *, struct qeth_reply *, unsigned long),
4961                       void *reply_param);
4962
4963 static int
4964 qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
4965 {
4966         struct qeth_cmd_buffer *iob;
4967         char buf[16];
4968         int tmp;
4969         int rc;
4970
4971         QETH_DBF_TEXT(trace,3,"arpadent");
4972
4973         /*
4974          * currently GuestLAN only supports the ARP assist function
4975          * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
4976          * thus we say EOPNOTSUPP for this ARP function
4977          */
4978         if (card->info.guestlan)
4979                 return -EOPNOTSUPP;
4980         if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4981                 PRINT_WARN("ARP processing not supported "
4982                            "on %s!\n", QETH_CARD_IFNAME(card));
4983                 return -EOPNOTSUPP;
4984         }
4985
4986         iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4987                                        IPA_CMD_ASS_ARP_ADD_ENTRY,
4988                                        sizeof(struct qeth_arp_cache_entry),
4989                                        QETH_PROT_IPV4);
4990         rc = qeth_send_setassparms(card, iob,
4991                                    sizeof(struct qeth_arp_cache_entry),
4992                                    (unsigned long) entry,
4993                                    qeth_default_setassparms_cb, NULL);
4994         if (rc) {
4995                 tmp = rc;
4996                 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
4997                 PRINT_WARN("Could not add ARP entry for address %s on %s: "
4998                            "%s (0x%x/%d)\n",
4999                            buf, QETH_CARD_IFNAME(card),
5000                            qeth_arp_get_error_cause(&rc), tmp, tmp);
5001         }
5002         return rc;
5003 }
5004
5005 static int
5006 qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5007 {
5008         struct qeth_cmd_buffer *iob;
5009         char buf[16] = {0, };
5010         int tmp;
5011         int rc;
5012
5013         QETH_DBF_TEXT(trace,3,"arprment");
5014
5015         /*
5016          * currently GuestLAN only supports the ARP assist function
5017          * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5018          * thus we say EOPNOTSUPP for this ARP function
5019          */
5020         if (card->info.guestlan)
5021                 return -EOPNOTSUPP;
5022         if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5023                 PRINT_WARN("ARP processing not supported "
5024                            "on %s!\n", QETH_CARD_IFNAME(card));
5025                 return -EOPNOTSUPP;
5026         }
5027         memcpy(buf, entry, 12);
5028         iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5029                                        IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5030                                        12,
5031                                        QETH_PROT_IPV4);
5032         rc = qeth_send_setassparms(card, iob,
5033                                    12, (unsigned long)buf,
5034                                    qeth_default_setassparms_cb, NULL);
5035         if (rc) {
5036                 tmp = rc;
5037                 memset(buf, 0, 16);
5038                 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5039                 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5040                            "%s (0x%x/%d)\n",
5041                            buf, QETH_CARD_IFNAME(card),
5042                            qeth_arp_get_error_cause(&rc), tmp, tmp);
5043         }
5044         return rc;
5045 }
5046
5047 static int
5048 qeth_arp_flush_cache(struct qeth_card *card)
5049 {
5050         int rc;
5051         int tmp;
5052
5053         QETH_DBF_TEXT(trace,3,"arpflush");
5054
5055         /*
5056          * currently GuestLAN only supports the ARP assist function
5057          * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5058          * thus we say EOPNOTSUPP for this ARP function
5059         */
5060         if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5061                 return -EOPNOTSUPP;
5062         if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5063                 PRINT_WARN("ARP processing not supported "
5064                            "on %s!\n", QETH_CARD_IFNAME(card));
5065                 return -EOPNOTSUPP;
5066         }
5067         rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5068                                           IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5069         if (rc){
5070                 tmp = rc;
5071                 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5072                            QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5073                            tmp, tmp);
5074         }
5075         return rc;
5076 }
5077
5078 static int
5079 qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5080 {
5081         struct qeth_card *card = (struct qeth_card *)dev->priv;
5082         struct qeth_arp_cache_entry arp_entry;
5083         struct mii_ioctl_data *mii_data;
5084         int rc = 0;
5085
5086         if (!card)
5087                 return -ENODEV;
5088
5089         if ((card->state != CARD_STATE_UP) &&
5090             (card->state != CARD_STATE_SOFTSETUP))
5091                 return -ENODEV;
5092
5093         if (card->info.type == QETH_CARD_TYPE_OSN)
5094                 return -EPERM;
5095
5096         switch (cmd){
5097         case SIOC_QETH_ARP_SET_NO_ENTRIES:
5098                 if ( !capable(CAP_NET_ADMIN) ||
5099                      (card->options.layer2) ) {
5100                         rc = -EPERM;
5101                         break;
5102                 }
5103                 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5104                 break;
5105         case SIOC_QETH_ARP_QUERY_INFO:
5106                 if ( !capable(CAP_NET_ADMIN) ||
5107                      (card->options.layer2) ) {
5108                         rc = -EPERM;
5109                         break;
5110                 }
5111                 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5112                 break;
5113         case SIOC_QETH_ARP_ADD_ENTRY:
5114                 if ( !capable(CAP_NET_ADMIN) ||
5115                      (card->options.layer2) ) {
5116                         rc = -EPERM;
5117                         break;
5118                 }
5119                 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5120                                    sizeof(struct qeth_arp_cache_entry)))
5121                         rc = -EFAULT;
5122                 else
5123                         rc = qeth_arp_add_entry(card, &arp_entry);
5124                 break;
5125         case SIOC_QETH_ARP_REMOVE_ENTRY:
5126                 if ( !capable(CAP_NET_ADMIN) ||
5127                      (card->options.layer2) ) {
5128                         rc = -EPERM;
5129                         break;
5130                 }
5131                 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5132                                    sizeof(struct qeth_arp_cache_entry)))
5133                         rc = -EFAULT;
5134                 else
5135                         rc = qeth_arp_remove_entry(card, &arp_entry);
5136                 break;
5137         case SIOC_QETH_ARP_FLUSH_CACHE:
5138                 if ( !capable(CAP_NET_ADMIN) ||
5139                      (card->options.layer2) ) {
5140                         rc = -EPERM;
5141                         break;
5142                 }
5143                 rc = qeth_arp_flush_cache(card);
5144                 break;
5145         case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5146                 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5147                 break;
5148         case SIOC_QETH_GET_CARD_TYPE:
5149                 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5150                     !card->info.guestlan)
5151                         return 1;
5152                 return 0;
5153                 break;
5154         case SIOCGMIIPHY:
5155                 mii_data = if_mii(rq);
5156                 mii_data->phy_id = 0;
5157                 break;
5158         case SIOCGMIIREG:
5159                 mii_data = if_mii(rq);
5160                 if (mii_data->phy_id != 0)
5161                         rc = -EINVAL;
5162                 else
5163                         mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5164                                                            mii_data->reg_num);
5165                 break;
5166         default:
5167                 rc = -EOPNOTSUPP;
5168         }
5169         if (rc)
5170                 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5171         return rc;
5172 }
5173
5174 static struct net_device_stats *
5175 qeth_get_stats(struct net_device *dev)
5176 {
5177         struct qeth_card *card;
5178
5179         card = (struct qeth_card *) (dev->priv);
5180
5181         QETH_DBF_TEXT(trace,5,"getstat");
5182
5183         return &card->stats;
5184 }
5185
5186 static int
5187 qeth_change_mtu(struct net_device *dev, int new_mtu)
5188 {
5189         struct qeth_card *card;
5190         char dbf_text[15];
5191
5192         card = (struct qeth_card *) (dev->priv);
5193
5194         QETH_DBF_TEXT(trace,4,"chgmtu");
5195         sprintf(dbf_text, "%8x", new_mtu);
5196         QETH_DBF_TEXT(trace,4,dbf_text);
5197
5198         if (new_mtu < 64)
5199                 return -EINVAL;
5200         if (new_mtu > 65535)
5201                 return -EINVAL;
5202         if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5203             (!qeth_mtu_is_valid(card, new_mtu)))
5204                 return -EINVAL;
5205         dev->mtu = new_mtu;
5206         return 0;
5207 }
5208
5209 #ifdef CONFIG_QETH_VLAN
5210 static void
5211 qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5212 {
5213         struct qeth_card *card;
5214         unsigned long flags;
5215
5216         QETH_DBF_TEXT(trace,4,"vlanreg");
5217
5218         card = (struct qeth_card *) dev->priv;
5219         spin_lock_irqsave(&card->vlanlock, flags);
5220         card->vlangrp = grp;
5221         spin_unlock_irqrestore(&card->vlanlock, flags);
5222 }
5223
5224 static void
5225 qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5226                       unsigned short vid)
5227 {
5228         int i;
5229         struct sk_buff *skb;
5230         struct sk_buff_head tmp_list;
5231
5232         skb_queue_head_init(&tmp_list);
5233         lockdep_set_class(&tmp_list.lock, &qdio_out_skb_queue_key);
5234         for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5235                 while ((skb = skb_dequeue(&buf->skb_list))){
5236                         if (vlan_tx_tag_present(skb) &&
5237                             (vlan_tx_tag_get(skb) == vid)) {
5238                                 atomic_dec(&skb->users);
5239                                 dev_kfree_skb(skb);
5240                         } else
5241                                 skb_queue_tail(&tmp_list, skb);
5242                 }
5243         }
5244         while ((skb = skb_dequeue(&tmp_list)))
5245                 skb_queue_tail(&buf->skb_list, skb);
5246 }
5247
5248 static void
5249 qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5250 {
5251         int i, j;
5252
5253         QETH_DBF_TEXT(trace, 4, "frvlskbs");
5254         for (i = 0; i < card->qdio.no_out_queues; ++i){
5255                 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5256                         qeth_free_vlan_buffer(card, &card->qdio.
5257                                               out_qs[i]->bufs[j], vid);
5258         }
5259 }
5260
5261 static void
5262 qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5263 {
5264         struct in_device *in_dev;
5265         struct in_ifaddr *ifa;
5266         struct qeth_ipaddr *addr;
5267
5268         QETH_DBF_TEXT(trace, 4, "frvaddr4");
5269
5270         rcu_read_lock();
5271         in_dev = __in_dev_get_rcu(vlan_group_get_device(card->vlangrp, vid));
5272         if (!in_dev)
5273                 goto out;
5274         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5275                 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5276                 if (addr){
5277                         addr->u.a4.addr = ifa->ifa_address;
5278                         addr->u.a4.mask = ifa->ifa_mask;
5279                         addr->type = QETH_IP_TYPE_NORMAL;
5280                         if (!qeth_delete_ip(card, addr))
5281                                 kfree(addr);
5282                 }
5283         }
5284 out:
5285         rcu_read_unlock();
5286 }
5287
5288 static void
5289 qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5290 {
5291 #ifdef CONFIG_QETH_IPV6
5292         struct inet6_dev *in6_dev;
5293         struct inet6_ifaddr *ifa;
5294         struct qeth_ipaddr *addr;
5295
5296         QETH_DBF_TEXT(trace, 4, "frvaddr6");
5297
5298         in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
5299         if (!in6_dev)
5300                 return;
5301         for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5302                 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5303                 if (addr){
5304                         memcpy(&addr->u.a6.addr, &ifa->addr,
5305                                sizeof(struct in6_addr));
5306                         addr->u.a6.pfxlen = ifa->prefix_len;
5307                         addr->type = QETH_IP_TYPE_NORMAL;
5308                         if (!qeth_delete_ip(card, addr))
5309                                 kfree(addr);
5310                 }
5311         }
5312         in6_dev_put(in6_dev);
5313 #endif /* CONFIG_QETH_IPV6 */
5314 }
5315
5316 static void
5317 qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5318 {
5319         if (card->options.layer2 || !card->vlangrp)
5320                 return;
5321         qeth_free_vlan_addresses4(card, vid);
5322         qeth_free_vlan_addresses6(card, vid);
5323 }
5324
5325 static int
5326 qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5327                                struct qeth_reply *reply,
5328                                unsigned long data)
5329 {
5330         struct qeth_ipa_cmd *cmd;
5331
5332         QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5333         cmd = (struct qeth_ipa_cmd *) data;
5334         if (cmd->hdr.return_code) {
5335                 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5336                           "Continuing\n",cmd->data.setdelvlan.vlan_id,
5337                           QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5338                 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5339                 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5340                 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5341         }
5342         return 0;
5343 }
5344
5345 static int
5346 qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5347                             enum qeth_ipa_cmds ipacmd)
5348 {
5349         struct qeth_ipa_cmd *cmd;
5350         struct qeth_cmd_buffer *iob;
5351
5352         QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5353         iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5354         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5355         cmd->data.setdelvlan.vlan_id = i;
5356         return qeth_send_ipa_cmd(card, iob,
5357                                  qeth_layer2_send_setdelvlan_cb, NULL);
5358 }
5359
5360 static void
5361 qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5362 {
5363         unsigned short  i;
5364
5365         QETH_DBF_TEXT(trace, 3, "L2prcvln");
5366
5367         if (!card->vlangrp)
5368                 return;
5369         for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5370                 if (vlan_group_get_device(card->vlangrp, i) == NULL)
5371                         continue;
5372                 if (clear)
5373                         qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5374                 else
5375                         qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5376         }
5377 }
5378
5379 /*add_vid is layer 2 used only ....*/
5380 static void
5381 qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5382 {
5383         struct qeth_card *card;
5384
5385         QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5386
5387         card = (struct qeth_card *) dev->priv;
5388         if (!card->options.layer2)
5389                 return;
5390         qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5391 }
5392
5393 /*... kill_vid used for both modes*/
5394 static void
5395 qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5396 {
5397         struct qeth_card *card;
5398         unsigned long flags;
5399
5400         QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5401
5402         card = (struct qeth_card *) dev->priv;
5403         /* free all skbs for the vlan device */
5404         qeth_free_vlan_skbs(card, vid);
5405         spin_lock_irqsave(&card->vlanlock, flags);
5406         /* unregister IP addresses of vlan device */
5407         qeth_free_vlan_addresses(card, vid);
5408         vlan_group_set_device(card->vlangrp, vid, NULL);
5409         spin_unlock_irqrestore(&card->vlanlock, flags);
5410         if (card->options.layer2)
5411                 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5412         qeth_set_multicast_list(card->dev);
5413 }
5414 #endif
5415 /**
5416  * Examine hardware response to SET_PROMISC_MODE
5417  */
5418 static int
5419 qeth_setadp_promisc_mode_cb(struct qeth_card *card,
5420                             struct qeth_reply *reply,
5421                             unsigned long data)
5422 {
5423         struct qeth_ipa_cmd *cmd;
5424         struct qeth_ipacmd_setadpparms *setparms;
5425
5426         QETH_DBF_TEXT(trace,4,"prmadpcb");
5427
5428         cmd = (struct qeth_ipa_cmd *) data;
5429         setparms = &(cmd->data.setadapterparms);
5430
5431         qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
5432         if (cmd->hdr.return_code) {
5433                 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
5434                 setparms->data.mode = SET_PROMISC_MODE_OFF;
5435         }
5436         card->info.promisc_mode = setparms->data.mode;
5437         return 0;
5438 }
5439 /*
5440  * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5441  */
5442 static void
5443 qeth_setadp_promisc_mode(struct qeth_card *card)
5444 {
5445         enum qeth_ipa_promisc_modes mode;
5446         struct net_device *dev = card->dev;
5447         struct qeth_cmd_buffer *iob;
5448         struct qeth_ipa_cmd *cmd;
5449
5450         QETH_DBF_TEXT(trace, 4, "setprom");
5451
5452         if (((dev->flags & IFF_PROMISC) &&
5453              (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5454             (!(dev->flags & IFF_PROMISC) &&
5455              (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5456                 return;
5457         mode = SET_PROMISC_MODE_OFF;
5458         if (dev->flags & IFF_PROMISC)
5459                 mode = SET_PROMISC_MODE_ON;
5460         QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5461
5462         iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5463                         sizeof(struct qeth_ipacmd_setadpparms));
5464         cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5465         cmd->data.setadapterparms.data.mode = mode;
5466         qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5467 }
5468
5469 /**
5470  * set multicast address on card
5471  */
5472 static void
5473 qeth_set_multicast_list(struct net_device *dev)
5474 {
5475         struct qeth_card *card = (struct qeth_card *) dev->priv;
5476
5477         if (card->info.type == QETH_CARD_TYPE_OSN)
5478                 return ;
5479
5480         QETH_DBF_TEXT(trace, 3, "setmulti");
5481         qeth_delete_mc_addresses(card);
5482         if (card->options.layer2) {
5483                 qeth_layer2_add_multicast(card);
5484                 goto out;
5485         }
5486         qeth_add_multicast_ipv4(card);
5487 #ifdef CONFIG_QETH_IPV6
5488         qeth_add_multicast_ipv6(card);
5489 #endif
5490 out:
5491         qeth_set_ip_addr_list(card);
5492         if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5493                 return;
5494         qeth_setadp_promisc_mode(card);
5495 }
5496
5497 static int
5498 qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5499 {
5500         return 0;
5501 }
5502
5503 static void
5504 qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5505 {
5506         if (dev->type == ARPHRD_IEEE802_TR)
5507                 ip_tr_mc_map(ipm, mac);
5508         else
5509                 ip_eth_mc_map(ipm, mac);
5510 }
5511
5512 static struct qeth_ipaddr *
5513 qeth_get_addr_buffer(enum qeth_prot_versions prot)
5514 {
5515         struct qeth_ipaddr *addr;
5516
5517         addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5518         if (addr == NULL) {
5519                 PRINT_WARN("Not enough memory to add address\n");
5520                 return NULL;
5521         }
5522         addr->type = QETH_IP_TYPE_NORMAL;
5523         addr->proto = prot;
5524         return addr;
5525 }
5526
5527 int
5528 qeth_osn_assist(struct net_device *dev,
5529                 void *data,
5530                 int data_len)
5531 {
5532         struct qeth_cmd_buffer *iob;
5533         struct qeth_card *card;
5534         int rc;
5535
5536         QETH_DBF_TEXT(trace, 2, "osnsdmc");
5537         if (!dev)
5538                 return -ENODEV;
5539         card = (struct qeth_card *)dev->priv;
5540         if (!card)
5541                 return -ENODEV;
5542         if ((card->state != CARD_STATE_UP) &&
5543             (card->state != CARD_STATE_SOFTSETUP))
5544                 return -ENODEV;
5545         iob = qeth_wait_for_buffer(&card->write);
5546         memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5547         rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5548         return rc;
5549 }
5550
5551 static struct net_device *
5552 qeth_netdev_by_devno(unsigned char *read_dev_no)
5553 {
5554         struct qeth_card *card;
5555         struct net_device *ndev;
5556         unsigned char *readno;
5557         __u16 temp_dev_no, card_dev_no;
5558         char *endp;
5559         unsigned long flags;
5560
5561         ndev = NULL;
5562         memcpy(&temp_dev_no, read_dev_no, 2);
5563         read_lock_irqsave(&qeth_card_list.rwlock, flags);
5564         list_for_each_entry(card, &qeth_card_list.list, list) {
5565                 readno = CARD_RDEV_ID(card);
5566                 readno += (strlen(readno) - 4);
5567                 card_dev_no = simple_strtoul(readno, &endp, 16);
5568                 if (card_dev_no == temp_dev_no) {
5569                         ndev = card->dev;
5570                         break;
5571                 }
5572         }
5573         read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5574         return ndev;
5575 }
5576
5577 int
5578 qeth_osn_register(unsigned char *read_dev_no,
5579                   struct net_device **dev,
5580                   int (*assist_cb)(struct net_device *, void *),
5581                   int (*data_cb)(struct sk_buff *))
5582 {
5583         struct qeth_card * card;
5584
5585         QETH_DBF_TEXT(trace, 2, "osnreg");
5586         *dev = qeth_netdev_by_devno(read_dev_no);
5587         if (*dev == NULL)
5588                 return -ENODEV;
5589         card = (struct qeth_card *)(*dev)->priv;
5590         if (!card)
5591                 return -ENODEV;
5592         if ((assist_cb == NULL) || (data_cb == NULL))
5593                 return -EINVAL;
5594         card->osn_info.assist_cb = assist_cb;
5595         card->osn_info.data_cb = data_cb;
5596         return 0;
5597 }
5598
5599 void
5600 qeth_osn_deregister(struct net_device * dev)
5601 {
5602         struct qeth_card *card;
5603
5604         QETH_DBF_TEXT(trace, 2, "osndereg");
5605         if (!dev)
5606                 return;
5607         card = (struct qeth_card *)dev->priv;
5608         if (!card)
5609                 return;
5610         card->osn_info.assist_cb = NULL;
5611         card->osn_info.data_cb = NULL;
5612         return;
5613 }
5614
5615 static void
5616 qeth_delete_mc_addresses(struct qeth_card *card)
5617 {
5618         struct qeth_ipaddr *iptodo;
5619         unsigned long flags;
5620
5621         QETH_DBF_TEXT(trace,4,"delmc");
5622         iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5623         if (!iptodo) {
5624                 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5625                 return;
5626         }
5627         iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5628         spin_lock_irqsave(&card->ip_lock, flags);
5629         if (!__qeth_insert_ip_todo(card, iptodo, 0))
5630                 kfree(iptodo);
5631         spin_unlock_irqrestore(&card->ip_lock, flags);
5632 }
5633
5634 static void
5635 qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5636 {
5637         struct qeth_ipaddr *ipm;
5638         struct ip_mc_list *im4;
5639         char buf[MAX_ADDR_LEN];
5640
5641         QETH_DBF_TEXT(trace,4,"addmc");
5642         for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5643                 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5644                 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5645                 if (!ipm)
5646                         continue;
5647                 ipm->u.a4.addr = im4->multiaddr;
5648                 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5649                 ipm->is_multicast = 1;
5650                 if (!qeth_add_ip(card,ipm))
5651                         kfree(ipm);
5652         }
5653 }
5654
5655 static inline void
5656 qeth_add_vlan_mc(struct qeth_card *card)
5657 {
5658 #ifdef CONFIG_QETH_VLAN
5659         struct in_device *in_dev;
5660         struct vlan_group *vg;
5661         int i;
5662
5663         QETH_DBF_TEXT(trace,4,"addmcvl");
5664         if ( ((card->options.layer2 == 0) &&
5665               (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5666              (card->vlangrp == NULL) )
5667                 return ;
5668
5669         vg = card->vlangrp;
5670         for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5671                 struct net_device *netdev = vlan_group_get_device(vg, i);
5672                 if (netdev == NULL ||
5673                     !(netdev->flags & IFF_UP))
5674                         continue;
5675                 in_dev = in_dev_get(netdev);
5676                 if (!in_dev)
5677                         continue;
5678                 read_lock(&in_dev->mc_list_lock);
5679                 qeth_add_mc(card,in_dev);
5680                 read_unlock(&in_dev->mc_list_lock);
5681                 in_dev_put(in_dev);
5682         }
5683 #endif
5684 }
5685
5686 static void
5687 qeth_add_multicast_ipv4(struct qeth_card *card)
5688 {
5689         struct in_device *in4_dev;
5690
5691         QETH_DBF_TEXT(trace,4,"chkmcv4");
5692         in4_dev = in_dev_get(card->dev);
5693         if (in4_dev == NULL)
5694                 return;
5695         read_lock(&in4_dev->mc_list_lock);
5696         qeth_add_mc(card, in4_dev);
5697         qeth_add_vlan_mc(card);
5698         read_unlock(&in4_dev->mc_list_lock);
5699         in_dev_put(in4_dev);
5700 }
5701
5702 static void
5703 qeth_layer2_add_multicast(struct qeth_card *card)
5704 {
5705         struct qeth_ipaddr *ipm;
5706         struct dev_mc_list *dm;
5707
5708         QETH_DBF_TEXT(trace,4,"L2addmc");
5709         for (dm = card->dev->mc_list; dm; dm = dm->next) {
5710                 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5711                 if (!ipm)
5712                         continue;
5713                 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5714                 ipm->is_multicast = 1;
5715                 if (!qeth_add_ip(card, ipm))
5716                         kfree(ipm);
5717         }
5718 }
5719
5720 #ifdef CONFIG_QETH_IPV6
5721 static void
5722 qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5723 {
5724         struct qeth_ipaddr *ipm;
5725         struct ifmcaddr6 *im6;
5726         char buf[MAX_ADDR_LEN];
5727
5728         QETH_DBF_TEXT(trace,4,"addmc6");
5729         for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5730                 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5731                 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5732                 if (!ipm)
5733                         continue;
5734                 ipm->is_multicast = 1;
5735                 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5736                 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5737                        sizeof(struct in6_addr));
5738                 if (!qeth_add_ip(card,ipm))
5739                         kfree(ipm);
5740         }
5741 }
5742
5743 static inline void
5744 qeth_add_vlan_mc6(struct qeth_card *card)
5745 {
5746 #ifdef CONFIG_QETH_VLAN
5747         struct inet6_dev *in_dev;
5748         struct vlan_group *vg;
5749         int i;
5750
5751         QETH_DBF_TEXT(trace,4,"admc6vl");
5752         if ( ((card->options.layer2 == 0) &&
5753               (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5754              (card->vlangrp == NULL))
5755                 return ;
5756
5757         vg = card->vlangrp;
5758         for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5759                 struct net_device *netdev = vlan_group_get_device(vg, i);
5760                 if (netdev == NULL ||
5761                     !(netdev->flags & IFF_UP))
5762                         continue;
5763                 in_dev = in6_dev_get(netdev);
5764                 if (!in_dev)
5765                         continue;
5766                 read_lock(&in_dev->lock);
5767                 qeth_add_mc6(card,in_dev);
5768                 read_unlock(&in_dev->lock);
5769                 in6_dev_put(in_dev);
5770         }
5771 #endif /* CONFIG_QETH_VLAN */
5772 }
5773
5774 static void
5775 qeth_add_multicast_ipv6(struct qeth_card *card)
5776 {
5777         struct inet6_dev *in6_dev;
5778
5779         QETH_DBF_TEXT(trace,4,"chkmcv6");
5780         if (!qeth_is_supported(card, IPA_IPV6))
5781                 return ;
5782         in6_dev = in6_dev_get(card->dev);
5783         if (in6_dev == NULL)
5784                 return;
5785         read_lock(&in6_dev->lock);
5786         qeth_add_mc6(card, in6_dev);
5787         qeth_add_vlan_mc6(card);
5788         read_unlock(&in6_dev->lock);
5789         in6_dev_put(in6_dev);
5790 }
5791 #endif /* CONFIG_QETH_IPV6 */
5792
5793 static int
5794 qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5795                            enum qeth_ipa_cmds ipacmd,
5796                            int (*reply_cb) (struct qeth_card *,
5797                                             struct qeth_reply*,
5798                                             unsigned long))
5799 {
5800         struct qeth_ipa_cmd *cmd;
5801         struct qeth_cmd_buffer *iob;
5802
5803         QETH_DBF_TEXT(trace, 2, "L2sdmac");
5804         iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5805         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5806         cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5807         memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5808         return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5809 }
5810
5811 static int
5812 qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5813                                 struct qeth_reply *reply,
5814                                 unsigned long data)
5815 {
5816         struct qeth_ipa_cmd *cmd;
5817         __u8 *mac;
5818
5819         QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5820         cmd = (struct qeth_ipa_cmd *) data;
5821         mac = &cmd->data.setdelmac.mac[0];
5822         /* MAC already registered, needed in couple/uncouple case */
5823         if (cmd->hdr.return_code == 0x2005) {
5824                 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5825                           "already existing on %s \n",
5826                           mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5827                           QETH_CARD_IFNAME(card));
5828                 cmd->hdr.return_code = 0;
5829         }
5830         if (cmd->hdr.return_code)
5831                 PRINT_ERR("Could not set group MAC " \
5832                           "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5833                           mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5834                           QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5835         return 0;
5836 }
5837
5838 static int
5839 qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5840 {
5841         QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5842         return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5843                                           qeth_layer2_send_setgroupmac_cb);
5844 }
5845
5846 static int
5847 qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5848                                 struct qeth_reply *reply,
5849                                 unsigned long data)
5850 {
5851         struct qeth_ipa_cmd *cmd;
5852         __u8 *mac;
5853
5854         QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5855         cmd = (struct qeth_ipa_cmd *) data;
5856         mac = &cmd->data.setdelmac.mac[0];
5857         if (cmd->hdr.return_code)
5858                 PRINT_ERR("Could not delete group MAC " \
5859                           "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5860                           mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5861                           QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5862         return 0;
5863 }
5864
5865 static int
5866 qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5867 {
5868         QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5869         return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5870                                           qeth_layer2_send_delgroupmac_cb);
5871 }
5872
5873 static int
5874 qeth_layer2_send_setmac_cb(struct qeth_card *card,
5875                            struct qeth_reply *reply,
5876                            unsigned long data)
5877 {
5878         struct qeth_ipa_cmd *cmd;
5879
5880         QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5881         cmd = (struct qeth_ipa_cmd *) data;
5882         if (cmd->hdr.return_code) {
5883                 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5884                 PRINT_WARN("Error in registering MAC address on " \
5885                            "device %s: x%x\n", CARD_BUS_ID(card),
5886                            cmd->hdr.return_code);
5887                 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
5888                 cmd->hdr.return_code = -EIO;
5889         } else {
5890                 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
5891                 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5892                        OSA_ADDR_LEN);
5893                 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5894                            "successfully registered on device %s\n",
5895                            card->dev->dev_addr[0], card->dev->dev_addr[1],
5896                            card->dev->dev_addr[2], card->dev->dev_addr[3],
5897                            card->dev->dev_addr[4], card->dev->dev_addr[5],
5898                            card->dev->name);
5899         }
5900         return 0;
5901 }
5902
5903 static int
5904 qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
5905 {
5906         QETH_DBF_TEXT(trace, 2, "L2Setmac");
5907         return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
5908                                           qeth_layer2_send_setmac_cb);
5909 }
5910
5911 static int
5912 qeth_layer2_send_delmac_cb(struct qeth_card *card,
5913                            struct qeth_reply *reply,
5914                            unsigned long data)
5915 {
5916         struct qeth_ipa_cmd *cmd;
5917
5918         QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
5919         cmd = (struct qeth_ipa_cmd *) data;
5920         if (cmd->hdr.return_code) {
5921                 PRINT_WARN("Error in deregistering MAC address on " \
5922                            "device %s: x%x\n", CARD_BUS_ID(card),
5923                            cmd->hdr.return_code);
5924                 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5925                 cmd->hdr.return_code = -EIO;
5926                 return 0;
5927         }
5928         card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
5929
5930         return 0;
5931 }
5932 static int
5933 qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
5934 {
5935         QETH_DBF_TEXT(trace, 2, "L2Delmac");
5936         if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
5937                 return 0;
5938         return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
5939                                           qeth_layer2_send_delmac_cb);
5940 }
5941
5942 static int
5943 qeth_layer2_set_mac_address(struct net_device *dev, void *p)
5944 {
5945         struct sockaddr *addr = p;
5946         struct qeth_card *card;
5947         int rc = 0;
5948
5949         QETH_DBF_TEXT(trace, 3, "setmac");
5950
5951         if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
5952                 QETH_DBF_TEXT(trace, 3, "setmcINV");
5953                 return -EOPNOTSUPP;
5954         }
5955         card = (struct qeth_card *) dev->priv;
5956
5957         if (!card->options.layer2) {
5958                 PRINT_WARN("Setting MAC address on %s is not supported "
5959                            "in Layer 3 mode.\n", dev->name);
5960                 QETH_DBF_TEXT(trace, 3, "setmcLY3");
5961                 return -EOPNOTSUPP;
5962         }
5963         if (card->info.type == QETH_CARD_TYPE_OSN) {
5964                 PRINT_WARN("Setting MAC address on %s is not supported.\n",
5965                            dev->name);
5966                 QETH_DBF_TEXT(trace, 3, "setmcOSN");
5967                 return -EOPNOTSUPP;
5968         }
5969         QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
5970         QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
5971         rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
5972         if (!rc)
5973                 rc = qeth_layer2_send_setmac(card, addr->sa_data);
5974         return rc;
5975 }
5976
5977 static void
5978 qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
5979                         __u8 command, enum qeth_prot_versions prot)
5980 {
5981         memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
5982         cmd->hdr.command = command;
5983         cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
5984         cmd->hdr.seqno = card->seqno.ipa;
5985         cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
5986         cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
5987         if (card->options.layer2)
5988                 cmd->hdr.prim_version_no = 2;
5989         else
5990                 cmd->hdr.prim_version_no = 1;
5991         cmd->hdr.param_count = 1;
5992         cmd->hdr.prot_version = prot;
5993         cmd->hdr.ipa_supported = 0;
5994         cmd->hdr.ipa_enabled = 0;
5995 }
5996
5997 static struct qeth_cmd_buffer *
5998 qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
5999                        enum qeth_prot_versions prot)
6000 {
6001         struct qeth_cmd_buffer *iob;
6002         struct qeth_ipa_cmd *cmd;
6003
6004         iob = qeth_wait_for_buffer(&card->write);
6005         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6006         qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6007
6008         return iob;
6009 }
6010
6011 static int
6012 qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6013 {
6014         int rc;
6015         struct qeth_cmd_buffer *iob;
6016         struct qeth_ipa_cmd *cmd;
6017
6018         QETH_DBF_TEXT(trace,4,"setdelmc");
6019
6020         iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6021         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6022         memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6023         if (addr->proto == QETH_PROT_IPV6)
6024                 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6025                        sizeof(struct in6_addr));
6026         else
6027                 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6028
6029         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6030
6031         return rc;
6032 }
6033 static void
6034 qeth_fill_netmask(u8 *netmask, unsigned int len)
6035 {
6036         int i,j;
6037         for (i=0;i<16;i++) {
6038                 j=(len)-(i*8);
6039                 if (j >= 8)
6040                         netmask[i] = 0xff;
6041                 else if (j > 0)
6042                         netmask[i] = (u8)(0xFF00>>j);
6043                 else
6044                         netmask[i] = 0;
6045         }
6046 }
6047
6048 static int
6049 qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6050                    int ipacmd, unsigned int flags)
6051 {
6052         int rc;
6053         struct qeth_cmd_buffer *iob;
6054         struct qeth_ipa_cmd *cmd;
6055         __u8 netmask[16];
6056
6057         QETH_DBF_TEXT(trace,4,"setdelip");
6058         QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6059
6060         iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6061         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6062         if (addr->proto == QETH_PROT_IPV6) {
6063                 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6064                        sizeof(struct in6_addr));
6065                 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6066                 memcpy(cmd->data.setdelip6.mask, netmask,
6067                        sizeof(struct in6_addr));
6068                 cmd->data.setdelip6.flags = flags;
6069         } else {
6070                 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6071                 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6072                 cmd->data.setdelip4.flags = flags;
6073         }
6074
6075         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6076
6077         return rc;
6078 }
6079
6080 static int
6081 qeth_layer2_register_addr_entry(struct qeth_card *card,
6082                                 struct qeth_ipaddr *addr)
6083 {
6084         if (!addr->is_multicast)
6085                 return 0;
6086         QETH_DBF_TEXT(trace, 2, "setgmac");
6087         QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6088         return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6089 }
6090
6091 static int
6092 qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6093                                   struct qeth_ipaddr *addr)
6094 {
6095         if (!addr->is_multicast)
6096                 return 0;
6097         QETH_DBF_TEXT(trace, 2, "delgmac");
6098         QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6099         return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6100 }
6101
6102 static int
6103 qeth_layer3_register_addr_entry(struct qeth_card *card,
6104                                 struct qeth_ipaddr *addr)
6105 {
6106         char buf[50];
6107         int rc;
6108         int cnt = 3;
6109
6110         if (addr->proto == QETH_PROT_IPV4) {
6111                 QETH_DBF_TEXT(trace, 2,"setaddr4");
6112                 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6113         } else if (addr->proto == QETH_PROT_IPV6) {
6114                 QETH_DBF_TEXT(trace, 2, "setaddr6");
6115                 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6116                 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6117         } else {
6118                 QETH_DBF_TEXT(trace, 2, "setaddr?");
6119                 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6120         }
6121         do {
6122                 if (addr->is_multicast)
6123                         rc =  qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6124                 else
6125                         rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6126                                         addr->set_flags);
6127                 if (rc)
6128                         QETH_DBF_TEXT(trace, 2, "failed");
6129         } while ((--cnt > 0) && rc);
6130         if (rc){
6131                 QETH_DBF_TEXT(trace, 2, "FAILED");
6132                 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6133                 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6134                            buf, rc, rc);
6135         }
6136         return rc;
6137 }
6138
6139 static int
6140 qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6141                                   struct qeth_ipaddr *addr)
6142 {
6143         //char buf[50];
6144         int rc;
6145
6146         if (addr->proto == QETH_PROT_IPV4) {
6147                 QETH_DBF_TEXT(trace, 2,"deladdr4");
6148                 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6149         } else if (addr->proto == QETH_PROT_IPV6) {
6150                 QETH_DBF_TEXT(trace, 2, "deladdr6");
6151                 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6152                 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6153         } else {
6154                 QETH_DBF_TEXT(trace, 2, "deladdr?");
6155                 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6156         }
6157         if (addr->is_multicast)
6158                 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6159         else
6160                 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6161                                         addr->del_flags);
6162         if (rc) {
6163                 QETH_DBF_TEXT(trace, 2, "failed");
6164                 /* TODO: re-activate this warning as soon as we have a
6165                  * clean mirco code
6166                 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6167                 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6168                            buf, rc);
6169                 */
6170         }
6171         return rc;
6172 }
6173
6174 static int
6175 qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6176 {
6177         if (card->options.layer2)
6178                 return qeth_layer2_register_addr_entry(card, addr);
6179
6180         return qeth_layer3_register_addr_entry(card, addr);
6181 }
6182
6183 static int
6184 qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6185 {
6186         if (card->options.layer2)
6187                 return qeth_layer2_deregister_addr_entry(card, addr);
6188
6189         return qeth_layer3_deregister_addr_entry(card, addr);
6190 }
6191
6192 static u32
6193 qeth_ethtool_get_tx_csum(struct net_device *dev)
6194 {
6195         /* We may need to say that we support tx csum offload if
6196          * we do EDDP or TSO. There are discussions going on to
6197          * enforce rules in the stack and in ethtool that make
6198          * SG and TSO depend on HW_CSUM. At the moment there are
6199          * no such rules....
6200          * If we say yes here, we have to checksum outbound packets
6201          * any time. */
6202         return 0;
6203 }
6204
6205 static int
6206 qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6207 {
6208         return -EINVAL;
6209 }
6210
6211 static u32
6212 qeth_ethtool_get_rx_csum(struct net_device *dev)
6213 {
6214         struct qeth_card *card = (struct qeth_card *)dev->priv;
6215
6216         return (card->options.checksum_type == HW_CHECKSUMMING);
6217 }
6218
6219 static int
6220 qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6221 {
6222         struct qeth_card *card = (struct qeth_card *)dev->priv;
6223
6224         if ((card->state != CARD_STATE_DOWN) &&
6225             (card->state != CARD_STATE_RECOVER))
6226                 return -EPERM;
6227         if (data)
6228                 card->options.checksum_type = HW_CHECKSUMMING;
6229         else
6230                 card->options.checksum_type = SW_CHECKSUMMING;
6231         return 0;
6232 }
6233
6234 static u32
6235 qeth_ethtool_get_sg(struct net_device *dev)
6236 {
6237         struct qeth_card *card = (struct qeth_card *)dev->priv;
6238
6239         return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6240                 (dev->features & NETIF_F_SG));
6241 }
6242
6243 static int
6244 qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6245 {
6246         struct qeth_card *card = (struct qeth_card *)dev->priv;
6247
6248         if (data) {
6249                 if (card->options.large_send != QETH_LARGE_SEND_NO)
6250                         dev->features |= NETIF_F_SG;
6251                 else {
6252                         dev->features &= ~NETIF_F_SG;
6253                         return -EINVAL;
6254                 }
6255         } else
6256                 dev->features &= ~NETIF_F_SG;
6257         return 0;
6258 }
6259
6260 static u32
6261 qeth_ethtool_get_tso(struct net_device *dev)
6262 {
6263         struct qeth_card *card = (struct qeth_card *)dev->priv;
6264
6265         return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6266                 (dev->features & NETIF_F_TSO));
6267 }
6268
6269 static int
6270 qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6271 {
6272         struct qeth_card *card = (struct qeth_card *)dev->priv;
6273
6274         if (data) {
6275                 if (card->options.large_send != QETH_LARGE_SEND_NO)
6276                         dev->features |= NETIF_F_TSO;
6277                 else {
6278                         dev->features &= ~NETIF_F_TSO;
6279                         return -EINVAL;
6280                 }
6281         } else
6282                 dev->features &= ~NETIF_F_TSO;
6283         return 0;
6284 }
6285
6286 static struct ethtool_ops qeth_ethtool_ops = {
6287         .get_tx_csum = qeth_ethtool_get_tx_csum,
6288         .set_tx_csum = qeth_ethtool_set_tx_csum,
6289         .get_rx_csum = qeth_ethtool_get_rx_csum,
6290         .set_rx_csum = qeth_ethtool_set_rx_csum,
6291         .get_sg      = qeth_ethtool_get_sg,
6292         .set_sg      = qeth_ethtool_set_sg,
6293         .get_tso     = qeth_ethtool_get_tso,
6294         .set_tso     = qeth_ethtool_set_tso,
6295 };
6296
6297 static int
6298 qeth_hard_header_parse(struct sk_buff *skb, unsigned char *haddr)
6299 {
6300         struct qeth_card *card;
6301         struct ethhdr *eth;
6302
6303         card = qeth_get_card_from_dev(skb->dev);
6304         if (card->options.layer2)
6305                 goto haveheader;
6306 #ifdef CONFIG_QETH_IPV6
6307         /* cause of the manipulated arp constructor and the ARP
6308            flag for OSAE devices we have some nasty exceptions */
6309         if (card->info.type == QETH_CARD_TYPE_OSAE) {
6310                 if (!card->options.fake_ll) {
6311                         if ((skb->pkt_type==PACKET_OUTGOING) &&
6312                             (skb->protocol==ETH_P_IPV6))
6313                                 goto haveheader;
6314                         else
6315                                 return 0;
6316                 } else {
6317                         if ((skb->pkt_type==PACKET_OUTGOING) &&
6318                             (skb->protocol==ETH_P_IP))
6319                                 return 0;
6320                         else
6321                                 goto haveheader;
6322                 }
6323         }
6324 #endif
6325         if (!card->options.fake_ll)
6326                 return 0;
6327 haveheader:
6328         eth = eth_hdr(skb);
6329         memcpy(haddr, eth->h_source, ETH_ALEN);
6330         return ETH_ALEN;
6331 }
6332
6333 static int
6334 qeth_netdev_init(struct net_device *dev)
6335 {
6336         struct qeth_card *card;
6337
6338         card = (struct qeth_card *) dev->priv;
6339
6340         QETH_DBF_TEXT(trace,3,"initdev");
6341
6342         dev->tx_timeout = &qeth_tx_timeout;
6343         dev->watchdog_timeo = QETH_TX_TIMEOUT;
6344         dev->open = qeth_open;
6345         dev->stop = qeth_stop;
6346         dev->hard_start_xmit = qeth_hard_start_xmit;
6347         dev->do_ioctl = qeth_do_ioctl;
6348         dev->get_stats = qeth_get_stats;
6349         dev->change_mtu = qeth_change_mtu;
6350         dev->neigh_setup = qeth_neigh_setup;
6351         dev->set_multicast_list = qeth_set_multicast_list;
6352 #ifdef CONFIG_QETH_VLAN
6353         dev->vlan_rx_register = qeth_vlan_rx_register;
6354         dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6355         dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6356 #endif
6357         if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6358                 dev->rebuild_header = NULL;
6359                 dev->hard_header = NULL;
6360                 dev->header_cache_update = NULL;
6361                 dev->hard_header_cache = NULL;
6362         }
6363 #ifdef CONFIG_QETH_IPV6
6364         /*IPv6 address autoconfiguration stuff*/
6365         if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6366                 card->dev->dev_id = card->info.unique_id & 0xffff;
6367 #endif
6368         if (card->options.fake_ll &&
6369                 (qeth_get_netdev_flags(card) & IFF_NOARP))
6370                         dev->hard_header = qeth_fake_header;
6371         if (dev->type == ARPHRD_IEEE802_TR)
6372                 dev->hard_header_parse = NULL;
6373         else
6374                 dev->hard_header_parse = qeth_hard_header_parse;
6375         dev->set_mac_address = qeth_layer2_set_mac_address;
6376         dev->flags |= qeth_get_netdev_flags(card);
6377         if ((card->options.fake_broadcast) ||
6378             (card->info.broadcast_capable))
6379                 dev->flags |= IFF_BROADCAST;
6380         dev->hard_header_len =
6381                         qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6382         dev->addr_len = OSA_ADDR_LEN;
6383         dev->mtu = card->info.initial_mtu;
6384         if (card->info.type != QETH_CARD_TYPE_OSN)
6385                 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6386         SET_MODULE_OWNER(dev);
6387         return 0;
6388 }
6389
6390 static void
6391 qeth_init_func_level(struct qeth_card *card)
6392 {
6393         if (card->ipato.enabled) {
6394                 if (card->info.type == QETH_CARD_TYPE_IQD)
6395                                 card->info.func_level =
6396                                         QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6397                 else
6398                                 card->info.func_level =
6399                                         QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6400         } else {
6401                 if (card->info.type == QETH_CARD_TYPE_IQD)
6402                 /*FIXME:why do we have same values for  dis and ena for osae??? */
6403                         card->info.func_level =
6404                                 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6405                 else
6406                         card->info.func_level =
6407                                 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6408         }
6409 }
6410
6411 /**
6412  * hardsetup card, initialize MPC and QDIO stuff
6413  */
6414 static int
6415 qeth_hardsetup_card(struct qeth_card *card)
6416 {
6417         int retries = 3;
6418         int rc;
6419
6420         QETH_DBF_TEXT(setup, 2, "hrdsetup");
6421
6422 retry:
6423         if (retries < 3){
6424                 PRINT_WARN("Retrying to do IDX activates.\n");
6425                 ccw_device_set_offline(CARD_DDEV(card));
6426                 ccw_device_set_offline(CARD_WDEV(card));
6427                 ccw_device_set_offline(CARD_RDEV(card));
6428                 ccw_device_set_online(CARD_RDEV(card));
6429                 ccw_device_set_online(CARD_WDEV(card));
6430                 ccw_device_set_online(CARD_DDEV(card));
6431         }
6432         rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
6433         if (rc == -ERESTARTSYS) {
6434                 QETH_DBF_TEXT(setup, 2, "break1");
6435                 return rc;
6436         } else if (rc) {
6437                 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6438                 if (--retries < 0)
6439                         goto out;
6440                 else
6441                         goto retry;
6442         }
6443         if ((rc = qeth_get_unitaddr(card))){
6444                 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6445                 return rc;
6446         }
6447         qeth_init_tokens(card);
6448         qeth_init_func_level(card);
6449         rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6450         if (rc == -ERESTARTSYS) {
6451                 QETH_DBF_TEXT(setup, 2, "break2");
6452                 return rc;
6453         } else if (rc) {
6454                 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6455                 if (--retries < 0)
6456                         goto out;
6457                 else
6458                         goto retry;
6459         }
6460         rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6461         if (rc == -ERESTARTSYS) {
6462                 QETH_DBF_TEXT(setup, 2, "break3");
6463                 return rc;
6464         } else if (rc) {
6465                 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6466                 if (--retries < 0)
6467                         goto out;
6468                 else
6469                         goto retry;
6470         }
6471         if ((rc = qeth_mpc_initialize(card))){
6472                 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6473                 goto out;
6474         }
6475         /*network device will be recovered*/
6476         if (card->dev) {
6477                 card->dev->hard_header = card->orig_hard_header;
6478                 if (card->options.fake_ll &&
6479                     (qeth_get_netdev_flags(card) & IFF_NOARP))
6480                         card->dev->hard_header = qeth_fake_header;
6481                 return 0;
6482         }
6483         /* at first set_online allocate netdev */
6484         card->dev = qeth_get_netdevice(card->info.type,
6485                                        card->info.link_type);
6486         if (!card->dev){
6487                 qeth_qdio_clear_card(card, card->info.type !=
6488                                      QETH_CARD_TYPE_IQD);
6489                 rc = -ENODEV;
6490                 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6491                 goto out;
6492         }
6493         card->dev->priv = card;
6494         card->orig_hard_header = card->dev->hard_header;
6495         card->dev->type = qeth_get_arphdr_type(card->info.type,
6496                                                card->info.link_type);
6497         card->dev->init = qeth_netdev_init;
6498         return 0;
6499 out:
6500         PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6501         return rc;
6502 }
6503
6504 static int
6505 qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6506                             unsigned long data)
6507 {
6508         struct qeth_ipa_cmd *cmd;
6509
6510         QETH_DBF_TEXT(trace,4,"defadpcb");
6511
6512         cmd = (struct qeth_ipa_cmd *) data;
6513         if (cmd->hdr.return_code == 0){
6514                 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6515                 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6516                         card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6517 #ifdef CONFIG_QETH_IPV6
6518                 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6519                         card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6520 #endif
6521         }
6522         if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6523             cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6524                 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6525                 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6526         }
6527         return 0;
6528 }
6529
6530 static int
6531 qeth_default_setadapterparms_cb(struct qeth_card *card,
6532                                 struct qeth_reply *reply,
6533                                 unsigned long data)
6534 {
6535         struct qeth_ipa_cmd *cmd;
6536
6537         QETH_DBF_TEXT(trace,4,"defadpcb");
6538
6539         cmd = (struct qeth_ipa_cmd *) data;
6540         if (cmd->hdr.return_code == 0)
6541                 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6542         return 0;
6543 }
6544
6545
6546
6547 static int
6548 qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6549                               unsigned long data)
6550 {
6551         struct qeth_ipa_cmd *cmd;
6552
6553         QETH_DBF_TEXT(trace,3,"quyadpcb");
6554
6555         cmd = (struct qeth_ipa_cmd *) data;
6556         if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6557                 card->info.link_type =
6558                       cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6559         card->options.adp.supported_funcs =
6560                 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6561         return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6562 }
6563
6564 static int
6565 qeth_query_setadapterparms(struct qeth_card *card)
6566 {
6567         int rc;
6568         struct qeth_cmd_buffer *iob;
6569
6570         QETH_DBF_TEXT(trace,3,"queryadp");
6571         iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6572                                    sizeof(struct qeth_ipacmd_setadpparms));
6573         rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6574         return rc;
6575 }
6576
6577 static int
6578 qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6579                                    struct qeth_reply *reply,
6580                                    unsigned long data)
6581 {
6582         struct qeth_ipa_cmd *cmd;
6583
6584         QETH_DBF_TEXT(trace,4,"chgmaccb");
6585
6586         cmd = (struct qeth_ipa_cmd *) data;
6587         if (!card->options.layer2 || card->info.guestlan ||
6588             !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
6589                 memcpy(card->dev->dev_addr,
6590                        &cmd->data.setadapterparms.data.change_addr.addr,
6591                        OSA_ADDR_LEN);
6592                 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6593         }
6594         qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6595         return 0;
6596 }
6597
6598 static int
6599 qeth_setadpparms_change_macaddr(struct qeth_card *card)
6600 {
6601         int rc;
6602         struct qeth_cmd_buffer *iob;
6603         struct qeth_ipa_cmd *cmd;
6604
6605         QETH_DBF_TEXT(trace,4,"chgmac");
6606
6607         iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6608                                    sizeof(struct qeth_ipacmd_setadpparms));
6609         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6610         cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6611         cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6612         memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6613                card->dev->dev_addr, OSA_ADDR_LEN);
6614         rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6615                                NULL);
6616         return rc;
6617 }
6618
6619 static int
6620 qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6621 {
6622         int rc;
6623         struct qeth_cmd_buffer *iob;
6624         struct qeth_ipa_cmd *cmd;
6625
6626         QETH_DBF_TEXT(trace,4,"adpmode");
6627
6628         iob = qeth_get_adapter_cmd(card, command,
6629                                    sizeof(struct qeth_ipacmd_setadpparms));
6630         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6631         cmd->data.setadapterparms.data.mode = mode;
6632         rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6633                                NULL);
6634         return rc;
6635 }
6636
6637 static int
6638 qeth_setadapter_hstr(struct qeth_card *card)
6639 {
6640         int rc;
6641
6642         QETH_DBF_TEXT(trace,4,"adphstr");
6643
6644         if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6645                 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6646                                            card->options.broadcast_mode);
6647                 if (rc)
6648                         PRINT_WARN("couldn't set broadcast mode on "
6649                                    "device %s: x%x\n",
6650                                    CARD_BUS_ID(card), rc);
6651                 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6652                                            card->options.macaddr_mode);
6653                 if (rc)
6654                         PRINT_WARN("couldn't set macaddr mode on "
6655                                    "device %s: x%x\n", CARD_BUS_ID(card), rc);
6656                 return rc;
6657         }
6658         if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6659                 PRINT_WARN("set adapter parameters not available "
6660                            "to set broadcast mode, using ALLRINGS "
6661                            "on device %s:\n", CARD_BUS_ID(card));
6662         if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6663                 PRINT_WARN("set adapter parameters not available "
6664                            "to set macaddr mode, using NONCANONICAL "
6665                            "on device %s:\n", CARD_BUS_ID(card));
6666         return 0;
6667 }
6668
6669 static int
6670 qeth_setadapter_parms(struct qeth_card *card)
6671 {
6672         int rc;
6673
6674         QETH_DBF_TEXT(setup, 2, "setadprm");
6675
6676         if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6677                 PRINT_WARN("set adapter parameters not supported "
6678                            "on device %s.\n",
6679                            CARD_BUS_ID(card));
6680                 QETH_DBF_TEXT(setup, 2, " notsupp");
6681                 return 0;
6682         }
6683         rc = qeth_query_setadapterparms(card);
6684         if (rc) {
6685                 PRINT_WARN("couldn't set adapter parameters on device %s: "
6686                            "x%x\n", CARD_BUS_ID(card), rc);
6687                 return rc;
6688         }
6689         if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6690                 rc = qeth_setadpparms_change_macaddr(card);
6691                 if (rc)
6692                         PRINT_WARN("couldn't get MAC address on "
6693                                    "device %s: x%x\n",
6694                                    CARD_BUS_ID(card), rc);
6695         }
6696
6697         if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6698             (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6699                 rc = qeth_setadapter_hstr(card);
6700
6701         return rc;
6702 }
6703
6704 static int
6705 qeth_layer2_initialize(struct qeth_card *card)
6706 {
6707         int rc = 0;
6708
6709
6710         QETH_DBF_TEXT(setup, 2, "doL2init");
6711         QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6712
6713         rc = qeth_query_setadapterparms(card);
6714         if (rc) {
6715                 PRINT_WARN("could not query adapter parameters on device %s: "
6716                            "x%x\n", CARD_BUS_ID(card), rc);
6717         }
6718
6719         rc = qeth_setadpparms_change_macaddr(card);
6720         if (rc) {
6721                 PRINT_WARN("couldn't get MAC address on "
6722                            "device %s: x%x\n",
6723                            CARD_BUS_ID(card), rc);
6724                 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6725                 return rc;
6726         }
6727         QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6728
6729         rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6730         if (rc)
6731                 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6732         return 0;
6733 }
6734
6735
6736 static int
6737 qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6738                        enum qeth_prot_versions prot)
6739 {
6740         int rc;
6741         struct qeth_cmd_buffer *iob;
6742
6743         iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6744         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6745
6746         return rc;
6747 }
6748
6749 static int
6750 qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6751 {
6752         int rc;
6753
6754         QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6755
6756         rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6757         return rc;
6758 }
6759
6760 static int
6761 qeth_send_stoplan(struct qeth_card *card)
6762 {
6763         int rc = 0;
6764
6765         /*
6766          * TODO: according to the IPA format document page 14,
6767          * TCP/IP (we!) never issue a STOPLAN
6768          * is this right ?!?
6769          */
6770         QETH_DBF_TEXT(trace, 2, "stoplan");
6771
6772         rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6773         return rc;
6774 }
6775
6776 static int
6777 qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6778                         unsigned long data)
6779 {
6780         struct qeth_ipa_cmd *cmd;
6781
6782         QETH_DBF_TEXT(setup, 2, "qipasscb");
6783
6784         cmd = (struct qeth_ipa_cmd *) data;
6785         if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6786                 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6787                 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6788                 /* Disable IPV6 support hard coded for Hipersockets */
6789                 if(card->info.type == QETH_CARD_TYPE_IQD)
6790                         card->options.ipa4.supported_funcs &= ~IPA_IPV6;
6791         } else {
6792 #ifdef CONFIG_QETH_IPV6
6793                 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6794                 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6795 #endif
6796         }
6797         QETH_DBF_TEXT(setup, 2, "suppenbl");
6798         QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6799         QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6800         return 0;
6801 }
6802
6803 static int
6804 qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6805 {
6806         int rc;
6807         struct qeth_cmd_buffer *iob;
6808
6809         QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6810         if (card->options.layer2) {
6811                 QETH_DBF_TEXT(setup, 2, "noprmly2");
6812                 return -EPERM;
6813         }
6814
6815         iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6816         rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6817         return rc;
6818 }
6819
6820 static struct qeth_cmd_buffer *
6821 qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6822                          __u16 cmd_code, __u16 len,
6823                          enum qeth_prot_versions prot)
6824 {
6825         struct qeth_cmd_buffer *iob;
6826         struct qeth_ipa_cmd *cmd;
6827
6828         QETH_DBF_TEXT(trace,4,"getasscm");
6829         iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6830
6831         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6832         cmd->data.setassparms.hdr.assist_no = ipa_func;
6833         cmd->data.setassparms.hdr.length = 8 + len;
6834         cmd->data.setassparms.hdr.command_code = cmd_code;
6835         cmd->data.setassparms.hdr.return_code = 0;
6836         cmd->data.setassparms.hdr.seq_no = 0;
6837
6838         return iob;
6839 }
6840
6841 static int
6842 qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6843                       __u16 len, long data,
6844                       int (*reply_cb)
6845                       (struct qeth_card *,struct qeth_reply *,unsigned long),
6846                       void *reply_param)
6847 {
6848         int rc;
6849         struct qeth_ipa_cmd *cmd;
6850
6851         QETH_DBF_TEXT(trace,4,"sendassp");
6852
6853         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6854         if (len <= sizeof(__u32))
6855                 cmd->data.setassparms.data.flags_32bit = (__u32) data;
6856         else   /* (len > sizeof(__u32)) */
6857                 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6858
6859         rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6860         return rc;
6861 }
6862
6863 #ifdef CONFIG_QETH_IPV6
6864 static int
6865 qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6866                                   enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6867
6868 {
6869         int rc;
6870         struct qeth_cmd_buffer *iob;
6871
6872         QETH_DBF_TEXT(trace,4,"simassp6");
6873         iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6874                                        0, QETH_PROT_IPV6);
6875         rc = qeth_send_setassparms(card, iob, 0, 0,
6876                                    qeth_default_setassparms_cb, NULL);
6877         return rc;
6878 }
6879 #endif
6880
6881 static int
6882 qeth_send_simple_setassparms(struct qeth_card *card,
6883                              enum qeth_ipa_funcs ipa_func,
6884                              __u16 cmd_code, long data)
6885 {
6886         int rc;
6887         int length = 0;
6888         struct qeth_cmd_buffer *iob;
6889
6890         QETH_DBF_TEXT(trace,4,"simassp4");
6891         if (data)
6892                 length = sizeof(__u32);
6893         iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6894                                        length, QETH_PROT_IPV4);
6895         rc = qeth_send_setassparms(card, iob, length, data,
6896                                    qeth_default_setassparms_cb, NULL);
6897         return rc;
6898 }
6899
6900 static int
6901 qeth_start_ipa_arp_processing(struct qeth_card *card)
6902 {
6903         int rc;
6904
6905         QETH_DBF_TEXT(trace,3,"ipaarp");
6906
6907         if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6908                 PRINT_WARN("ARP processing not supported "
6909                            "on %s!\n", QETH_CARD_IFNAME(card));
6910                 return 0;
6911         }
6912         rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6913                                           IPA_CMD_ASS_START, 0);
6914         if (rc) {
6915                 PRINT_WARN("Could not start ARP processing "
6916                            "assist on %s: 0x%x\n",
6917                            QETH_CARD_IFNAME(card), rc);
6918         }
6919         return rc;
6920 }
6921
6922 static int
6923 qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6924 {
6925         int rc;
6926
6927         QETH_DBF_TEXT(trace,3,"ipaipfrg");
6928
6929         if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
6930                 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
6931                            QETH_CARD_IFNAME(card));
6932                 return  -EOPNOTSUPP;
6933         }
6934
6935         rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
6936                                           IPA_CMD_ASS_START, 0);
6937         if (rc) {
6938                 PRINT_WARN("Could not start Hardware IP fragmentation "
6939                            "assist on %s: 0x%x\n",
6940                            QETH_CARD_IFNAME(card), rc);
6941         } else
6942                 PRINT_INFO("Hardware IP fragmentation enabled \n");
6943         return rc;
6944 }
6945
6946 static int
6947 qeth_start_ipa_source_mac(struct qeth_card *card)
6948 {
6949         int rc;
6950
6951         QETH_DBF_TEXT(trace,3,"stsrcmac");
6952
6953         if (!card->options.fake_ll)
6954                 return -EOPNOTSUPP;
6955
6956         if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
6957                 PRINT_INFO("Inbound source address not "
6958                            "supported on %s\n", QETH_CARD_IFNAME(card));
6959                 return -EOPNOTSUPP;
6960         }
6961
6962         rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
6963                                           IPA_CMD_ASS_START, 0);
6964         if (rc)
6965                 PRINT_WARN("Could not start inbound source "
6966                            "assist on %s: 0x%x\n",
6967                            QETH_CARD_IFNAME(card), rc);
6968         return rc;
6969 }
6970
6971 static int
6972 qeth_start_ipa_vlan(struct qeth_card *card)
6973 {
6974         int rc = 0;
6975
6976         QETH_DBF_TEXT(trace,3,"strtvlan");
6977
6978 #ifdef CONFIG_QETH_VLAN
6979         if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
6980                 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
6981                 return -EOPNOTSUPP;
6982         }
6983
6984         rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
6985                                           IPA_CMD_ASS_START,0);
6986         if (rc) {
6987                 PRINT_WARN("Could not start vlan "
6988                            "assist on %s: 0x%x\n",
6989                            QETH_CARD_IFNAME(card), rc);
6990         } else {
6991                 PRINT_INFO("VLAN enabled \n");
6992                 card->dev->features |=
6993                         NETIF_F_HW_VLAN_FILTER |
6994                         NETIF_F_HW_VLAN_TX |
6995                         NETIF_F_HW_VLAN_RX;
6996         }
6997 #endif /* QETH_VLAN */
6998         return rc;
6999 }
7000
7001 static int
7002 qeth_start_ipa_multicast(struct qeth_card *card)
7003 {
7004         int rc;
7005
7006         QETH_DBF_TEXT(trace,3,"stmcast");
7007
7008         if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7009                 PRINT_WARN("Multicast not supported on %s\n",
7010                            QETH_CARD_IFNAME(card));
7011                 return -EOPNOTSUPP;
7012         }
7013
7014         rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7015                                           IPA_CMD_ASS_START,0);
7016         if (rc) {
7017                 PRINT_WARN("Could not start multicast "
7018                            "assist on %s: rc=%i\n",
7019                            QETH_CARD_IFNAME(card), rc);
7020         } else {
7021                 PRINT_INFO("Multicast enabled\n");
7022                 card->dev->flags |= IFF_MULTICAST;
7023         }
7024         return rc;
7025 }
7026
7027 #ifdef CONFIG_QETH_IPV6
7028 static int
7029 qeth_softsetup_ipv6(struct qeth_card *card)
7030 {
7031         int rc;
7032
7033         QETH_DBF_TEXT(trace,3,"softipv6");
7034
7035         rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7036         if (rc) {
7037                 PRINT_ERR("IPv6 startlan failed on %s\n",
7038                           QETH_CARD_IFNAME(card));
7039                 return rc;
7040         }
7041         rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7042         if (rc) {
7043                 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7044                           QETH_CARD_IFNAME(card));
7045                 return rc;
7046         }
7047         rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7048                                           IPA_CMD_ASS_START, 3);
7049         if (rc) {
7050                 PRINT_WARN("IPv6 start assist (version 4) failed "
7051                            "on %s: 0x%x\n",
7052                            QETH_CARD_IFNAME(card), rc);
7053                 return rc;
7054         }
7055         rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7056                                                IPA_CMD_ASS_START);
7057         if (rc) {
7058                 PRINT_WARN("IPV6 start assist (version 6) failed  "
7059                            "on %s: 0x%x\n",
7060                            QETH_CARD_IFNAME(card), rc);
7061                 return rc;
7062         }
7063         rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7064                                                IPA_CMD_ASS_START);
7065         if (rc) {
7066                 PRINT_WARN("Could not enable passthrough "
7067                            "on %s: 0x%x\n",
7068                            QETH_CARD_IFNAME(card), rc);
7069                 return rc;
7070         }
7071         PRINT_INFO("IPV6 enabled \n");
7072         return 0;
7073 }
7074
7075 #endif
7076
7077 static int
7078 qeth_start_ipa_ipv6(struct qeth_card *card)
7079 {
7080         int rc = 0;
7081 #ifdef CONFIG_QETH_IPV6
7082         QETH_DBF_TEXT(trace,3,"strtipv6");
7083
7084         if (!qeth_is_supported(card, IPA_IPV6)) {
7085                 PRINT_WARN("IPv6 not supported on %s\n",
7086                            QETH_CARD_IFNAME(card));
7087                 return 0;
7088         }
7089         rc = qeth_softsetup_ipv6(card);
7090 #endif
7091         return rc ;
7092 }
7093
7094 static int
7095 qeth_start_ipa_broadcast(struct qeth_card *card)
7096 {
7097         int rc;
7098
7099         QETH_DBF_TEXT(trace,3,"stbrdcst");
7100         card->info.broadcast_capable = 0;
7101         if (!qeth_is_supported(card, IPA_FILTERING)) {
7102                 PRINT_WARN("Broadcast not supported on %s\n",
7103                            QETH_CARD_IFNAME(card));
7104                 rc = -EOPNOTSUPP;
7105                 goto out;
7106         }
7107         rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7108                                           IPA_CMD_ASS_START, 0);
7109         if (rc) {
7110                 PRINT_WARN("Could not enable broadcasting filtering "
7111                            "on %s: 0x%x\n",
7112                            QETH_CARD_IFNAME(card), rc);
7113                 goto out;
7114         }
7115
7116         rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7117                                           IPA_CMD_ASS_CONFIGURE, 1);
7118         if (rc) {
7119                 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7120                            QETH_CARD_IFNAME(card), rc);
7121                 goto out;
7122         }
7123         card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7124         PRINT_INFO("Broadcast enabled \n");
7125         rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7126                                           IPA_CMD_ASS_ENABLE, 1);
7127         if (rc) {
7128                 PRINT_WARN("Could not set up broadcast echo filtering on "
7129                            "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7130                 goto out;
7131         }
7132         card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7133 out:
7134         if (card->info.broadcast_capable)
7135                 card->dev->flags |= IFF_BROADCAST;
7136         else
7137                 card->dev->flags &= ~IFF_BROADCAST;
7138         return rc;
7139 }
7140
7141 static int
7142 qeth_send_checksum_command(struct qeth_card *card)
7143 {
7144         int rc;
7145
7146         rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7147                                           IPA_CMD_ASS_START, 0);
7148         if (rc) {
7149                 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7150                            "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7151                            QETH_CARD_IFNAME(card), rc);
7152                 return rc;
7153         }
7154         rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7155                                           IPA_CMD_ASS_ENABLE,
7156                                           card->info.csum_mask);
7157         if (rc) {
7158                 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7159                            "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7160                            QETH_CARD_IFNAME(card), rc);
7161                 return rc;
7162         }
7163         return 0;
7164 }
7165
7166 static int
7167 qeth_start_ipa_checksum(struct qeth_card *card)
7168 {
7169         int rc = 0;
7170
7171         QETH_DBF_TEXT(trace,3,"strtcsum");
7172
7173         if (card->options.checksum_type == NO_CHECKSUMMING) {
7174                 PRINT_WARN("Using no checksumming on %s.\n",
7175                            QETH_CARD_IFNAME(card));
7176                 return 0;
7177         }
7178         if (card->options.checksum_type == SW_CHECKSUMMING) {
7179                 PRINT_WARN("Using SW checksumming on %s.\n",
7180                            QETH_CARD_IFNAME(card));
7181                 return 0;
7182         }
7183         if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7184                 PRINT_WARN("Inbound HW Checksumming not "
7185                            "supported on %s,\ncontinuing "
7186                            "using Inbound SW Checksumming\n",
7187                            QETH_CARD_IFNAME(card));
7188                 card->options.checksum_type = SW_CHECKSUMMING;
7189                 return 0;
7190         }
7191         rc = qeth_send_checksum_command(card);
7192         if (!rc) {
7193                 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7194         }
7195         return rc;
7196 }
7197
7198 static int
7199 qeth_start_ipa_tso(struct qeth_card *card)
7200 {
7201         int rc;
7202
7203         QETH_DBF_TEXT(trace,3,"sttso");
7204
7205         if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7206                 PRINT_WARN("Outbound TSO not supported on %s\n",
7207                            QETH_CARD_IFNAME(card));
7208                 rc = -EOPNOTSUPP;
7209         } else {
7210                 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7211                                                   IPA_CMD_ASS_START,0);
7212                 if (rc)
7213                         PRINT_WARN("Could not start outbound TSO "
7214                                    "assist on %s: rc=%i\n",
7215                                    QETH_CARD_IFNAME(card), rc);
7216                 else
7217                         PRINT_INFO("Outbound TSO enabled\n");
7218         }
7219         if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7220                 card->options.large_send = QETH_LARGE_SEND_NO;
7221                 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
7222         }
7223         return rc;
7224 }
7225
7226 static int
7227 qeth_start_ipassists(struct qeth_card *card)
7228 {
7229         QETH_DBF_TEXT(trace,3,"strtipas");
7230         qeth_start_ipa_arp_processing(card);    /* go on*/
7231         qeth_start_ipa_ip_fragmentation(card);  /* go on*/
7232         qeth_start_ipa_source_mac(card);        /* go on*/
7233         qeth_start_ipa_vlan(card);              /* go on*/
7234         qeth_start_ipa_multicast(card);         /* go on*/
7235         qeth_start_ipa_ipv6(card);              /* go on*/
7236         qeth_start_ipa_broadcast(card);         /* go on*/
7237         qeth_start_ipa_checksum(card);          /* go on*/
7238         qeth_start_ipa_tso(card);               /* go on*/
7239         return 0;
7240 }
7241
7242 static int
7243 qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7244                      enum qeth_prot_versions prot)
7245 {
7246         int rc;
7247         struct qeth_ipa_cmd *cmd;
7248         struct qeth_cmd_buffer *iob;
7249
7250         QETH_DBF_TEXT(trace,4,"setroutg");
7251         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7252         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7253         cmd->data.setrtg.type = (type);
7254         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7255
7256         return rc;
7257
7258 }
7259
7260 static void
7261 qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7262                         enum qeth_prot_versions prot)
7263 {
7264         if (card->info.type == QETH_CARD_TYPE_IQD) {
7265                 switch (*type) {
7266                 case NO_ROUTER:
7267                 case PRIMARY_CONNECTOR:
7268                 case SECONDARY_CONNECTOR:
7269                 case MULTICAST_ROUTER:
7270                         return;
7271                 default:
7272                         goto out_inval;
7273                 }
7274         } else {
7275                 switch (*type) {
7276                 case NO_ROUTER:
7277                 case PRIMARY_ROUTER:
7278                 case SECONDARY_ROUTER:
7279                         return;
7280                 case MULTICAST_ROUTER:
7281                         if (qeth_is_ipafunc_supported(card, prot,
7282                                                       IPA_OSA_MC_ROUTER))
7283                                 return;
7284                 default:
7285                         goto out_inval;
7286                 }
7287         }
7288 out_inval:
7289         PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7290                    "Router status set to 'no router'.\n",
7291                    ((*type == PRIMARY_ROUTER)? "primary router" :
7292                     (*type == SECONDARY_ROUTER)? "secondary router" :
7293                     (*type == PRIMARY_CONNECTOR)? "primary connector" :
7294                     (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7295                     (*type == MULTICAST_ROUTER)? "multicast router" :
7296                     "unknown"),
7297                    card->dev->name);
7298         *type = NO_ROUTER;
7299 }
7300
7301 int
7302 qeth_setrouting_v4(struct qeth_card *card)
7303 {
7304         int rc;
7305
7306         QETH_DBF_TEXT(trace,3,"setrtg4");
7307
7308         qeth_correct_routing_type(card, &card->options.route4.type,
7309                                   QETH_PROT_IPV4);
7310
7311         rc = qeth_send_setrouting(card, card->options.route4.type,
7312                                   QETH_PROT_IPV4);
7313         if (rc) {
7314                 card->options.route4.type = NO_ROUTER;
7315                 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7316                            "Type set to 'no router'.\n",
7317                            rc, QETH_CARD_IFNAME(card));
7318         }
7319         return rc;
7320 }
7321
7322 int
7323 qeth_setrouting_v6(struct qeth_card *card)
7324 {
7325         int rc = 0;
7326
7327         QETH_DBF_TEXT(trace,3,"setrtg6");
7328 #ifdef CONFIG_QETH_IPV6
7329
7330         if (!qeth_is_supported(card, IPA_IPV6))
7331                 return 0;
7332         qeth_correct_routing_type(card, &card->options.route6.type,
7333                                   QETH_PROT_IPV6);
7334
7335         rc = qeth_send_setrouting(card, card->options.route6.type,
7336                                   QETH_PROT_IPV6);
7337         if (rc) {
7338                 card->options.route6.type = NO_ROUTER;
7339                 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7340                            "Type set to 'no router'.\n",
7341                            rc, QETH_CARD_IFNAME(card));
7342         }
7343 #endif
7344         return rc;
7345 }
7346
7347 int
7348 qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
7349 {
7350         int rc = 0;
7351
7352         if (card->dev == NULL) {
7353                 card->options.large_send = type;
7354                 return 0;
7355         }
7356         if (card->state == CARD_STATE_UP)
7357                 netif_tx_disable(card->dev);
7358         card->options.large_send = type;
7359         switch (card->options.large_send) {
7360         case QETH_LARGE_SEND_EDDP:
7361                 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7362                 break;
7363         case QETH_LARGE_SEND_TSO:
7364                 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7365                         card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7366                 } else {
7367                         PRINT_WARN("TSO not supported on %s. "
7368                                    "large_send set to 'no'.\n",
7369                                    card->dev->name);
7370                         card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7371                         card->options.large_send = QETH_LARGE_SEND_NO;
7372                         rc = -EOPNOTSUPP;
7373                 }
7374                 break;
7375         default: /* includes QETH_LARGE_SEND_NO */
7376                 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7377                 break;
7378         }
7379         if (card->state == CARD_STATE_UP)
7380                 netif_wake_queue(card->dev);
7381         return rc;
7382 }
7383
7384 /*
7385  * softsetup card: init IPA stuff
7386  */
7387 static int
7388 qeth_softsetup_card(struct qeth_card *card)
7389 {
7390         int rc;
7391
7392         QETH_DBF_TEXT(setup, 2, "softsetp");
7393
7394         if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7395                 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7396                 if (rc == 0xe080){
7397                         PRINT_WARN("LAN on card %s if offline! "
7398                                    "Continuing softsetup.\n",
7399                                    CARD_BUS_ID(card));
7400                         card->lan_online = 0;
7401                 } else
7402                         return rc;
7403         } else
7404                 card->lan_online = 1;
7405         if (card->info.type==QETH_CARD_TYPE_OSN)
7406                 goto out;
7407         qeth_set_large_send(card, card->options.large_send);
7408         if (card->options.layer2) {
7409                 card->dev->features |=
7410                         NETIF_F_HW_VLAN_FILTER |
7411                         NETIF_F_HW_VLAN_TX |
7412                         NETIF_F_HW_VLAN_RX;
7413                 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7414                 card->info.broadcast_capable=1;
7415                 if ((rc = qeth_layer2_initialize(card))) {
7416                         QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7417                         return rc;
7418                 }
7419 #ifdef CONFIG_QETH_VLAN
7420                 qeth_layer2_process_vlans(card, 0);
7421 #endif
7422                 goto out;
7423         }
7424         if ((rc = qeth_setadapter_parms(card)))
7425                 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7426         if ((rc = qeth_start_ipassists(card)))
7427                 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7428         if ((rc = qeth_setrouting_v4(card)))
7429                 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7430         if ((rc = qeth_setrouting_v6(card)))
7431                 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7432 out:
7433         netif_tx_disable(card->dev);
7434         return 0;
7435 }
7436
7437 #ifdef CONFIG_QETH_IPV6
7438 static int
7439 qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7440                       unsigned long data)
7441 {
7442         struct qeth_ipa_cmd *cmd;
7443
7444         cmd = (struct qeth_ipa_cmd *) data;
7445         if (cmd->hdr.return_code == 0)
7446                 card->info.unique_id = *((__u16 *)
7447                                 &cmd->data.create_destroy_addr.unique_id[6]);
7448         else {
7449                 card->info.unique_id =  UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7450                                         UNIQUE_ID_NOT_BY_CARD;
7451                 PRINT_WARN("couldn't get a unique id from the card on device "
7452                            "%s (result=x%x), using default id. ipv6 "
7453                            "autoconfig on other lpars may lead to duplicate "
7454                            "ip addresses. please use manually "
7455                            "configured ones.\n",
7456                            CARD_BUS_ID(card), cmd->hdr.return_code);
7457         }
7458         return 0;
7459 }
7460 #endif
7461
7462 static int
7463 qeth_put_unique_id(struct qeth_card *card)
7464 {
7465
7466         int rc = 0;
7467 #ifdef CONFIG_QETH_IPV6
7468         struct qeth_cmd_buffer *iob;
7469         struct qeth_ipa_cmd *cmd;
7470
7471         QETH_DBF_TEXT(trace,2,"puniqeid");
7472
7473         if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7474                 UNIQUE_ID_NOT_BY_CARD)
7475                 return -1;
7476         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7477                                      QETH_PROT_IPV6);
7478         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7479         *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7480                             card->info.unique_id;
7481         memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7482                card->dev->dev_addr, OSA_ADDR_LEN);
7483         rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7484 #else
7485         card->info.unique_id =  UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7486                                 UNIQUE_ID_NOT_BY_CARD;
7487 #endif
7488         return rc;
7489 }
7490
7491 /**
7492  * Clear IP List
7493  */
7494 static void
7495 qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7496 {
7497         struct qeth_ipaddr *addr, *tmp;
7498         unsigned long flags;
7499
7500         QETH_DBF_TEXT(trace,4,"clearip");
7501         spin_lock_irqsave(&card->ip_lock, flags);
7502         /* clear todo list */
7503         list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7504                 list_del(&addr->entry);
7505                 kfree(addr);
7506         }
7507
7508         while (!list_empty(&card->ip_list)) {
7509                 addr = list_entry(card->ip_list.next,
7510                                   struct qeth_ipaddr, entry);
7511                 list_del_init(&addr->entry);
7512                 if (clean) {
7513                         spin_unlock_irqrestore(&card->ip_lock, flags);
7514                         qeth_deregister_addr_entry(card, addr);
7515                         spin_lock_irqsave(&card->ip_lock, flags);
7516                 }
7517                 if (!recover || addr->is_multicast) {
7518                         kfree(addr);
7519                         continue;
7520                 }
7521                 list_add_tail(&addr->entry, card->ip_tbd_list);
7522         }
7523         spin_unlock_irqrestore(&card->ip_lock, flags);
7524 }
7525
7526 static void
7527 qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7528                          int clear_start_mask)
7529 {
7530         unsigned long flags;
7531
7532         spin_lock_irqsave(&card->thread_mask_lock, flags);
7533         card->thread_allowed_mask = threads;
7534         if (clear_start_mask)
7535                 card->thread_start_mask &= threads;
7536         spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7537         wake_up(&card->wait_q);
7538 }
7539
7540 static int
7541 qeth_threads_running(struct qeth_card *card, unsigned long threads)
7542 {
7543         unsigned long flags;
7544         int rc = 0;
7545
7546         spin_lock_irqsave(&card->thread_mask_lock, flags);
7547         rc = (card->thread_running_mask & threads);
7548         spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7549         return rc;
7550 }
7551
7552 static int
7553 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7554 {
7555         return wait_event_interruptible(card->wait_q,
7556                         qeth_threads_running(card, threads) == 0);
7557 }
7558
7559 static int
7560 qeth_stop_card(struct qeth_card *card, int recovery_mode)
7561 {
7562         int rc = 0;
7563
7564         QETH_DBF_TEXT(setup ,2,"stopcard");
7565         QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7566
7567         qeth_set_allowed_threads(card, 0, 1);
7568         if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7569                 return -ERESTARTSYS;
7570         if (card->read.state == CH_STATE_UP &&
7571             card->write.state == CH_STATE_UP &&
7572             (card->state == CARD_STATE_UP)) {
7573                 if (recovery_mode &&
7574                     card->info.type != QETH_CARD_TYPE_OSN) {
7575                         qeth_stop(card->dev);
7576                 } else {
7577                         rtnl_lock();
7578                         dev_close(card->dev);
7579                         rtnl_unlock();
7580                 }
7581                 if (!card->use_hard_stop) {
7582                         __u8 *mac = &card->dev->dev_addr[0];
7583                         rc = qeth_layer2_send_delmac(card, mac);
7584                         QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7585                         if ((rc = qeth_send_stoplan(card)))
7586                                 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7587                 }
7588                 card->state = CARD_STATE_SOFTSETUP;
7589         }
7590         if (card->state == CARD_STATE_SOFTSETUP) {
7591 #ifdef CONFIG_QETH_VLAN
7592                 if (card->options.layer2)
7593                         qeth_layer2_process_vlans(card, 1);
7594 #endif
7595                 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7596                 qeth_clear_ipacmd_list(card);
7597                 card->state = CARD_STATE_HARDSETUP;
7598         }
7599         if (card->state == CARD_STATE_HARDSETUP) {
7600                 if ((!card->use_hard_stop) &&
7601                     (!card->options.layer2))
7602                         if ((rc = qeth_put_unique_id(card)))
7603                                 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7604                 qeth_qdio_clear_card(card, 0);
7605                 qeth_clear_qdio_buffers(card);
7606                 qeth_clear_working_pool_list(card);
7607                 card->state = CARD_STATE_DOWN;
7608         }
7609         if (card->state == CARD_STATE_DOWN) {
7610                 qeth_clear_cmd_buffers(&card->read);
7611                 qeth_clear_cmd_buffers(&card->write);
7612         }
7613         card->use_hard_stop = 0;
7614         return rc;
7615 }
7616
7617
7618 static int
7619 qeth_get_unique_id(struct qeth_card *card)
7620 {
7621         int rc = 0;
7622 #ifdef CONFIG_QETH_IPV6
7623         struct qeth_cmd_buffer *iob;
7624         struct qeth_ipa_cmd *cmd;
7625
7626         QETH_DBF_TEXT(setup, 2, "guniqeid");
7627
7628         if (!qeth_is_supported(card,IPA_IPV6)) {
7629                 card->info.unique_id =  UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7630                                         UNIQUE_ID_NOT_BY_CARD;
7631                 return 0;
7632         }
7633
7634         iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7635                                      QETH_PROT_IPV6);
7636         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7637         *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7638                             card->info.unique_id;
7639
7640         rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7641 #else
7642         card->info.unique_id =  UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7643                                 UNIQUE_ID_NOT_BY_CARD;
7644 #endif
7645         return rc;
7646 }
7647 static void
7648 qeth_print_status_with_portname(struct qeth_card *card)
7649 {
7650         char dbf_text[15];
7651         int i;
7652
7653         sprintf(dbf_text, "%s", card->info.portname + 1);
7654         for (i = 0; i < 8; i++)
7655                 dbf_text[i] =
7656                         (char) _ebcasc[(__u8) dbf_text[i]];
7657         dbf_text[8] = 0;
7658         printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7659                "with link type %s (portname: %s)\n",
7660                CARD_RDEV_ID(card),
7661                CARD_WDEV_ID(card),
7662                CARD_DDEV_ID(card),
7663                qeth_get_cardname(card),
7664                (card->info.mcl_level[0]) ? " (level: " : "",
7665                (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7666                (card->info.mcl_level[0]) ? ")" : "",
7667                qeth_get_cardname_short(card),
7668                dbf_text);
7669
7670 }
7671
7672 static void
7673 qeth_print_status_no_portname(struct qeth_card *card)
7674 {
7675         if (card->info.portname[0])
7676                 printk("qeth: Device %s/%s/%s is a%s "
7677                        "card%s%s%s\nwith link type %s "
7678                        "(no portname needed by interface).\n",
7679                        CARD_RDEV_ID(card),
7680                        CARD_WDEV_ID(card),
7681                        CARD_DDEV_ID(card),
7682                        qeth_get_cardname(card),
7683                        (card->info.mcl_level[0]) ? " (level: " : "",
7684                        (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7685                        (card->info.mcl_level[0]) ? ")" : "",
7686                        qeth_get_cardname_short(card));
7687         else
7688                 printk("qeth: Device %s/%s/%s is a%s "
7689                        "card%s%s%s\nwith link type %s.\n",
7690                        CARD_RDEV_ID(card),
7691                        CARD_WDEV_ID(card),
7692                        CARD_DDEV_ID(card),
7693                        qeth_get_cardname(card),
7694                        (card->info.mcl_level[0]) ? " (level: " : "",
7695                        (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7696                        (card->info.mcl_level[0]) ? ")" : "",
7697                        qeth_get_cardname_short(card));
7698 }
7699
7700 static void
7701 qeth_print_status_message(struct qeth_card *card)
7702 {
7703         switch (card->info.type) {
7704         case QETH_CARD_TYPE_OSAE:
7705                 /* VM will use a non-zero first character
7706                  * to indicate a HiperSockets like reporting
7707                  * of the level OSA sets the first character to zero
7708                  * */
7709                 if (!card->info.mcl_level[0]) {
7710                         sprintf(card->info.mcl_level,"%02x%02x",
7711                                 card->info.mcl_level[2],
7712                                 card->info.mcl_level[3]);
7713
7714                         card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7715                         break;
7716                 }
7717                 /* fallthrough */
7718         case QETH_CARD_TYPE_IQD:
7719                 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7720                         card->info.mcl_level[0]];
7721                 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7722                         card->info.mcl_level[1]];
7723                 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7724                         card->info.mcl_level[2]];
7725                 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7726                         card->info.mcl_level[3]];
7727                 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7728                 break;
7729         default:
7730                 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7731         }
7732         if (card->info.portname_required)
7733                 qeth_print_status_with_portname(card);
7734         else
7735                 qeth_print_status_no_portname(card);
7736 }
7737
7738 static int
7739 qeth_register_netdev(struct qeth_card *card)
7740 {
7741         QETH_DBF_TEXT(setup, 3, "regnetd");
7742         if (card->dev->reg_state != NETREG_UNINITIALIZED)
7743                 return 0;
7744         /* sysfs magic */
7745         SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7746         return register_netdev(card->dev);
7747 }
7748
7749 static void
7750 qeth_start_again(struct qeth_card *card, int recovery_mode)
7751 {
7752         QETH_DBF_TEXT(setup ,2, "startag");
7753
7754         if (recovery_mode &&
7755             card->info.type != QETH_CARD_TYPE_OSN) {
7756                 qeth_open(card->dev);
7757         } else {
7758                 rtnl_lock();
7759                 dev_open(card->dev);
7760                 rtnl_unlock();
7761         }
7762         /* this also sets saved unicast addresses */
7763         qeth_set_multicast_list(card->dev);
7764 }
7765
7766
7767 /* Layer 2 specific stuff */
7768 #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7769         if (card->options.option == value) { \
7770                 PRINT_ERR("%s not supported with layer 2 " \
7771                           "functionality, ignoring option on read" \
7772                           "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7773                 card->options.option = reset_value; \
7774         }
7775 #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7776         if (card->options.option != value) { \
7777                 PRINT_ERR("%s not supported with layer 2 " \
7778                           "functionality, ignoring option on read" \
7779                           "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7780                 card->options.option = reset_value; \
7781         }
7782
7783
7784 static void qeth_make_parameters_consistent(struct qeth_card *card)
7785 {
7786
7787         if (card->options.layer2 == 0)
7788                 return;
7789         if (card->info.type == QETH_CARD_TYPE_OSN)
7790                 return;
7791         if (card->info.type == QETH_CARD_TYPE_IQD) {
7792                 PRINT_ERR("Device %s does not support layer 2 functionality." \
7793                           " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7794                 card->options.layer2 = 0;
7795                 return;
7796         }
7797         IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7798                          "Routing options are");
7799 #ifdef CONFIG_QETH_IPV6
7800         IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7801                          "Routing options are");
7802 #endif
7803         IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7804                         QETH_CHECKSUM_DEFAULT,
7805                         "Checksumming options are");
7806         IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7807                          QETH_TR_BROADCAST_ALLRINGS,
7808                          "Broadcast mode options are");
7809         IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7810                          QETH_TR_MACADDR_NONCANONICAL,
7811                          "Canonical MAC addr options are");
7812         IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7813                          "Broadcast faking options are");
7814         IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7815                          DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7816         IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
7817 }
7818
7819
7820 static int
7821 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
7822 {
7823         struct qeth_card *card = gdev->dev.driver_data;
7824         int rc = 0;
7825         enum qeth_card_states recover_flag;
7826
7827         BUG_ON(!card);
7828         QETH_DBF_TEXT(setup ,2, "setonlin");
7829         QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7830
7831         qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7832         if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7833                 PRINT_WARN("set_online of card %s interrupted by user!\n",
7834                            CARD_BUS_ID(card));
7835                 return -ERESTARTSYS;
7836         }
7837
7838         recover_flag = card->state;
7839         if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7840             (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7841             (rc = ccw_device_set_online(CARD_DDEV(card)))){
7842                 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7843                 return -EIO;
7844         }
7845
7846         qeth_make_parameters_consistent(card);
7847
7848         if ((rc = qeth_hardsetup_card(card))){
7849                 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7850                 goto out_remove;
7851         }
7852         card->state = CARD_STATE_HARDSETUP;
7853
7854         if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7855                 rc = qeth_get_unique_id(card);
7856
7857         if (rc && card->options.layer2 == 0) {
7858                 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7859                 goto out_remove;
7860         }
7861         qeth_print_status_message(card);
7862         if ((rc = qeth_register_netdev(card))){
7863                 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7864                 goto out_remove;
7865         }
7866         if ((rc = qeth_softsetup_card(card))){
7867                 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7868                 goto out_remove;
7869         }
7870
7871         if ((rc = qeth_init_qdio_queues(card))){
7872                 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7873                 goto out_remove;
7874         }
7875         card->state = CARD_STATE_SOFTSETUP;
7876         netif_carrier_on(card->dev);
7877
7878         qeth_set_allowed_threads(card, 0xffffffff, 0);
7879         if (recover_flag == CARD_STATE_RECOVER)
7880                 qeth_start_again(card, recovery_mode);
7881         qeth_notify_processes();
7882         return 0;
7883 out_remove:
7884         card->use_hard_stop = 1;
7885         qeth_stop_card(card, 0);
7886         ccw_device_set_offline(CARD_DDEV(card));
7887         ccw_device_set_offline(CARD_WDEV(card));
7888         ccw_device_set_offline(CARD_RDEV(card));
7889         if (recover_flag == CARD_STATE_RECOVER)
7890                 card->state = CARD_STATE_RECOVER;
7891         else
7892                 card->state = CARD_STATE_DOWN;
7893         return -ENODEV;
7894 }
7895
7896 static int
7897 qeth_set_online(struct ccwgroup_device *gdev)
7898 {
7899         return __qeth_set_online(gdev, 0);
7900 }
7901
7902 static struct ccw_device_id qeth_ids[] = {
7903         {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
7904         {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
7905         {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
7906         {},
7907 };
7908 MODULE_DEVICE_TABLE(ccw, qeth_ids);
7909
7910 struct device *qeth_root_dev = NULL;
7911
7912 struct ccwgroup_driver qeth_ccwgroup_driver = {
7913         .owner = THIS_MODULE,
7914         .name = "qeth",
7915         .driver_id = 0xD8C5E3C8,
7916         .probe = qeth_probe_device,
7917         .remove = qeth_remove_device,
7918         .set_online = qeth_set_online,
7919         .set_offline = qeth_set_offline,
7920 };
7921
7922 struct ccw_driver qeth_ccw_driver = {
7923         .name = "qeth",
7924         .ids = qeth_ids,
7925         .probe = ccwgroup_probe_ccwdev,
7926         .remove = ccwgroup_remove_ccwdev,
7927 };
7928
7929
7930 static void
7931 qeth_unregister_dbf_views(void)
7932 {
7933         if (qeth_dbf_setup)
7934                 debug_unregister(qeth_dbf_setup);
7935         if (qeth_dbf_qerr)
7936                 debug_unregister(qeth_dbf_qerr);
7937         if (qeth_dbf_sense)
7938                 debug_unregister(qeth_dbf_sense);
7939         if (qeth_dbf_misc)
7940                 debug_unregister(qeth_dbf_misc);
7941         if (qeth_dbf_data)
7942                 debug_unregister(qeth_dbf_data);
7943         if (qeth_dbf_control)
7944                 debug_unregister(qeth_dbf_control);
7945         if (qeth_dbf_trace)
7946                 debug_unregister(qeth_dbf_trace);
7947 }
7948 static int
7949 qeth_register_dbf_views(void)
7950 {
7951         qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
7952                                         QETH_DBF_SETUP_PAGES,
7953                                         QETH_DBF_SETUP_NR_AREAS,
7954                                         QETH_DBF_SETUP_LEN);
7955         qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
7956                                        QETH_DBF_MISC_PAGES,
7957                                        QETH_DBF_MISC_NR_AREAS,
7958                                        QETH_DBF_MISC_LEN);
7959         qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
7960                                        QETH_DBF_DATA_PAGES,
7961                                        QETH_DBF_DATA_NR_AREAS,
7962                                        QETH_DBF_DATA_LEN);
7963         qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
7964                                           QETH_DBF_CONTROL_PAGES,
7965                                           QETH_DBF_CONTROL_NR_AREAS,
7966                                           QETH_DBF_CONTROL_LEN);
7967         qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
7968                                         QETH_DBF_SENSE_PAGES,
7969                                         QETH_DBF_SENSE_NR_AREAS,
7970                                         QETH_DBF_SENSE_LEN);
7971         qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
7972                                        QETH_DBF_QERR_PAGES,
7973                                        QETH_DBF_QERR_NR_AREAS,
7974                                        QETH_DBF_QERR_LEN);
7975         qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
7976                                         QETH_DBF_TRACE_PAGES,
7977                                         QETH_DBF_TRACE_NR_AREAS,
7978                                         QETH_DBF_TRACE_LEN);
7979
7980         if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL)    ||
7981             (qeth_dbf_data == NULL)  || (qeth_dbf_control == NULL) ||
7982             (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL)    ||
7983             (qeth_dbf_trace == NULL)) {
7984                 qeth_unregister_dbf_views();
7985                 return -ENOMEM;
7986         }
7987         debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
7988         debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
7989
7990         debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
7991         debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
7992
7993         debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
7994         debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
7995
7996         debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
7997         debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
7998
7999         debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
8000         debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8001
8002         debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8003         debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8004
8005         debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8006         debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8007
8008         return 0;
8009 }
8010
8011 #ifdef CONFIG_QETH_IPV6
8012 extern struct neigh_table arp_tbl;
8013 static struct neigh_ops *arp_direct_ops;
8014 static int (*qeth_old_arp_constructor) (struct neighbour *);
8015
8016 static struct neigh_ops arp_direct_ops_template = {
8017         .family = AF_INET,
8018         .solicit = NULL,
8019         .error_report = NULL,
8020         .output = dev_queue_xmit,
8021         .connected_output = dev_queue_xmit,
8022         .hh_output = dev_queue_xmit,
8023         .queue_xmit = dev_queue_xmit
8024 };
8025
8026 static int
8027 qeth_arp_constructor(struct neighbour *neigh)
8028 {
8029         struct net_device *dev = neigh->dev;
8030         struct in_device *in_dev;
8031         struct neigh_parms *parms;
8032         struct qeth_card *card;
8033
8034         card = qeth_get_card_from_dev(dev);
8035         if (card == NULL)
8036                 goto out;
8037         if((card->options.layer2) ||
8038            (card->dev->hard_header == qeth_fake_header))
8039                 goto out;
8040
8041         rcu_read_lock();
8042         in_dev = __in_dev_get_rcu(dev);
8043         if (in_dev == NULL) {
8044                 rcu_read_unlock();
8045                 return -EINVAL;
8046         }
8047
8048         parms = in_dev->arp_parms;
8049         __neigh_parms_put(neigh->parms);
8050         neigh->parms = neigh_parms_clone(parms);
8051         rcu_read_unlock();
8052
8053         neigh->type = inet_addr_type(*(__be32 *) neigh->primary_key);
8054         neigh->nud_state = NUD_NOARP;
8055         neigh->ops = arp_direct_ops;
8056         neigh->output = neigh->ops->queue_xmit;
8057         return 0;
8058 out:
8059         return qeth_old_arp_constructor(neigh);
8060 }
8061 #endif  /*CONFIG_QETH_IPV6*/
8062
8063 /*
8064  * IP address takeover related functions
8065  */
8066 static void
8067 qeth_clear_ipato_list(struct qeth_card *card)
8068 {
8069         struct qeth_ipato_entry *ipatoe, *tmp;
8070         unsigned long flags;
8071
8072         spin_lock_irqsave(&card->ip_lock, flags);
8073         list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8074                 list_del(&ipatoe->entry);
8075                 kfree(ipatoe);
8076         }
8077         spin_unlock_irqrestore(&card->ip_lock, flags);
8078 }
8079
8080 int
8081 qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8082 {
8083         struct qeth_ipato_entry *ipatoe;
8084         unsigned long flags;
8085         int rc = 0;
8086
8087         QETH_DBF_TEXT(trace, 2, "addipato");
8088         spin_lock_irqsave(&card->ip_lock, flags);
8089         list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8090                 if (ipatoe->proto != new->proto)
8091                         continue;
8092                 if (!memcmp(ipatoe->addr, new->addr,
8093                             (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8094                     (ipatoe->mask_bits == new->mask_bits)){
8095                         PRINT_WARN("ipato entry already exists!\n");
8096                         rc = -EEXIST;
8097                         break;
8098                 }
8099         }
8100         if (!rc) {
8101                 list_add_tail(&new->entry, &card->ipato.entries);
8102         }
8103         spin_unlock_irqrestore(&card->ip_lock, flags);
8104         return rc;
8105 }
8106
8107 void
8108 qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8109                      u8 *addr, int mask_bits)
8110 {
8111         struct qeth_ipato_entry *ipatoe, *tmp;
8112         unsigned long flags;
8113
8114         QETH_DBF_TEXT(trace, 2, "delipato");
8115         spin_lock_irqsave(&card->ip_lock, flags);
8116         list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8117                 if (ipatoe->proto != proto)
8118                         continue;
8119                 if (!memcmp(ipatoe->addr, addr,
8120                             (proto == QETH_PROT_IPV4)? 4:16) &&
8121                     (ipatoe->mask_bits == mask_bits)){
8122                         list_del(&ipatoe->entry);
8123                         kfree(ipatoe);
8124                 }
8125         }
8126         spin_unlock_irqrestore(&card->ip_lock, flags);
8127 }
8128
8129 static void
8130 qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8131 {
8132         int i, j;
8133         u8 octet;
8134
8135         for (i = 0; i < len; ++i){
8136                 octet = addr[i];
8137                 for (j = 7; j >= 0; --j){
8138                         bits[i*8 + j] = octet & 1;
8139                         octet >>= 1;
8140                 }
8141         }
8142 }
8143
8144 static int
8145 qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8146 {
8147         struct qeth_ipato_entry *ipatoe;
8148         u8 addr_bits[128] = {0, };
8149         u8 ipatoe_bits[128] = {0, };
8150         int rc = 0;
8151
8152         if (!card->ipato.enabled)
8153                 return 0;
8154
8155         qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8156                                   (addr->proto == QETH_PROT_IPV4)? 4:16);
8157         list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8158                 if (addr->proto != ipatoe->proto)
8159                         continue;
8160                 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8161                                           (ipatoe->proto==QETH_PROT_IPV4) ?
8162                                           4:16);
8163                 if (addr->proto == QETH_PROT_IPV4)
8164                         rc = !memcmp(addr_bits, ipatoe_bits,
8165                                      min(32, ipatoe->mask_bits));
8166                 else
8167                         rc = !memcmp(addr_bits, ipatoe_bits,
8168                                      min(128, ipatoe->mask_bits));
8169                 if (rc)
8170                         break;
8171         }
8172         /* invert? */
8173         if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8174                 rc = !rc;
8175         else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8176                 rc = !rc;
8177
8178         return rc;
8179 }
8180
8181 /*
8182  * VIPA related functions
8183  */
8184 int
8185 qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8186               const u8 *addr)
8187 {
8188         struct qeth_ipaddr *ipaddr;
8189         unsigned long flags;
8190         int rc = 0;
8191
8192         ipaddr = qeth_get_addr_buffer(proto);
8193         if (ipaddr){
8194                 if (proto == QETH_PROT_IPV4){
8195                         QETH_DBF_TEXT(trace, 2, "addvipa4");
8196                         memcpy(&ipaddr->u.a4.addr, addr, 4);
8197                         ipaddr->u.a4.mask = 0;
8198 #ifdef CONFIG_QETH_IPV6
8199                 } else if (proto == QETH_PROT_IPV6){
8200                         QETH_DBF_TEXT(trace, 2, "addvipa6");
8201                         memcpy(&ipaddr->u.a6.addr, addr, 16);
8202                         ipaddr->u.a6.pfxlen = 0;
8203 #endif
8204                 }
8205                 ipaddr->type = QETH_IP_TYPE_VIPA;
8206                 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8207                 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8208         } else
8209                 return -ENOMEM;
8210         spin_lock_irqsave(&card->ip_lock, flags);
8211         if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8212             __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8213                 rc = -EEXIST;
8214         spin_unlock_irqrestore(&card->ip_lock, flags);
8215         if (rc){
8216                 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8217                 return rc;
8218         }
8219         if (!qeth_add_ip(card, ipaddr))
8220                 kfree(ipaddr);
8221         qeth_set_ip_addr_list(card);
8222         return rc;
8223 }
8224
8225 void
8226 qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8227               const u8 *addr)
8228 {
8229         struct qeth_ipaddr *ipaddr;
8230
8231         ipaddr = qeth_get_addr_buffer(proto);
8232         if (ipaddr){
8233                 if (proto == QETH_PROT_IPV4){
8234                         QETH_DBF_TEXT(trace, 2, "delvipa4");
8235                         memcpy(&ipaddr->u.a4.addr, addr, 4);
8236                         ipaddr->u.a4.mask = 0;
8237 #ifdef CONFIG_QETH_IPV6
8238                 } else if (proto == QETH_PROT_IPV6){
8239                         QETH_DBF_TEXT(trace, 2, "delvipa6");
8240                         memcpy(&ipaddr->u.a6.addr, addr, 16);
8241                         ipaddr->u.a6.pfxlen = 0;
8242 #endif
8243                 }
8244                 ipaddr->type = QETH_IP_TYPE_VIPA;
8245         } else
8246                 return;
8247         if (!qeth_delete_ip(card, ipaddr))
8248                 kfree(ipaddr);
8249         qeth_set_ip_addr_list(card);
8250 }
8251
8252 /*
8253  * proxy ARP related functions
8254  */
8255 int
8256 qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8257               const u8 *addr)
8258 {
8259         struct qeth_ipaddr *ipaddr;
8260         unsigned long flags;
8261         int rc = 0;
8262
8263         ipaddr = qeth_get_addr_buffer(proto);
8264         if (ipaddr){
8265                 if (proto == QETH_PROT_IPV4){
8266                         QETH_DBF_TEXT(trace, 2, "addrxip4");
8267                         memcpy(&ipaddr->u.a4.addr, addr, 4);
8268                         ipaddr->u.a4.mask = 0;
8269 #ifdef CONFIG_QETH_IPV6
8270                 } else if (proto == QETH_PROT_IPV6){
8271                         QETH_DBF_TEXT(trace, 2, "addrxip6");
8272                         memcpy(&ipaddr->u.a6.addr, addr, 16);
8273                         ipaddr->u.a6.pfxlen = 0;
8274 #endif
8275                 }
8276                 ipaddr->type = QETH_IP_TYPE_RXIP;
8277                 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8278                 ipaddr->del_flags = 0;
8279         } else
8280                 return -ENOMEM;
8281         spin_lock_irqsave(&card->ip_lock, flags);
8282         if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8283             __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8284                 rc = -EEXIST;
8285         spin_unlock_irqrestore(&card->ip_lock, flags);
8286         if (rc){
8287                 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8288                 return rc;
8289         }
8290         if (!qeth_add_ip(card, ipaddr))
8291                 kfree(ipaddr);
8292         qeth_set_ip_addr_list(card);
8293         return 0;
8294 }
8295
8296 void
8297 qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8298               const u8 *addr)
8299 {
8300         struct qeth_ipaddr *ipaddr;
8301
8302         ipaddr = qeth_get_addr_buffer(proto);
8303         if (ipaddr){
8304                 if (proto == QETH_PROT_IPV4){
8305                         QETH_DBF_TEXT(trace, 2, "addrxip4");
8306                         memcpy(&ipaddr->u.a4.addr, addr, 4);
8307                         ipaddr->u.a4.mask = 0;
8308 #ifdef CONFIG_QETH_IPV6
8309                 } else if (proto == QETH_PROT_IPV6){
8310                         QETH_DBF_TEXT(trace, 2, "addrxip6");
8311                         memcpy(&ipaddr->u.a6.addr, addr, 16);
8312                         ipaddr->u.a6.pfxlen = 0;
8313 #endif
8314                 }
8315                 ipaddr->type = QETH_IP_TYPE_RXIP;
8316         } else
8317                 return;
8318         if (!qeth_delete_ip(card, ipaddr))
8319                 kfree(ipaddr);
8320         qeth_set_ip_addr_list(card);
8321 }
8322
8323 /**
8324  * IP event handler
8325  */
8326 static int
8327 qeth_ip_event(struct notifier_block *this,
8328               unsigned long event,void *ptr)
8329 {
8330         struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8331         struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8332         struct qeth_ipaddr *addr;
8333         struct qeth_card *card;
8334
8335         QETH_DBF_TEXT(trace,3,"ipevent");
8336         card = qeth_get_card_from_dev(dev);
8337         if (!card)
8338                 return NOTIFY_DONE;
8339         if (card->options.layer2)
8340                 return NOTIFY_DONE;
8341
8342         addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8343         if (addr != NULL) {
8344                 addr->u.a4.addr = ifa->ifa_address;
8345                 addr->u.a4.mask = ifa->ifa_mask;
8346                 addr->type = QETH_IP_TYPE_NORMAL;
8347         } else
8348                 goto out;
8349
8350         switch(event) {
8351         case NETDEV_UP:
8352                 if (!qeth_add_ip(card, addr))
8353                         kfree(addr);
8354                 break;
8355         case NETDEV_DOWN:
8356                 if (!qeth_delete_ip(card, addr))
8357                         kfree(addr);
8358                 break;
8359         default:
8360                 break;
8361         }
8362         qeth_set_ip_addr_list(card);
8363 out:
8364         return NOTIFY_DONE;
8365 }
8366
8367 static struct notifier_block qeth_ip_notifier = {
8368         qeth_ip_event,
8369         NULL,
8370 };
8371
8372 #ifdef CONFIG_QETH_IPV6
8373 /**
8374  * IPv6 event handler
8375  */
8376 static int
8377 qeth_ip6_event(struct notifier_block *this,
8378               unsigned long event,void *ptr)
8379 {
8380
8381         struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8382         struct net_device *dev = (struct net_device *)ifa->idev->dev;
8383         struct qeth_ipaddr *addr;
8384         struct qeth_card *card;
8385
8386         QETH_DBF_TEXT(trace,3,"ip6event");
8387
8388         card = qeth_get_card_from_dev(dev);
8389         if (!card)
8390                 return NOTIFY_DONE;
8391         if (!qeth_is_supported(card, IPA_IPV6))
8392                 return NOTIFY_DONE;
8393
8394         addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8395         if (addr != NULL) {
8396                 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8397                 addr->u.a6.pfxlen = ifa->prefix_len;
8398                 addr->type = QETH_IP_TYPE_NORMAL;
8399         } else
8400                 goto out;
8401
8402         switch(event) {
8403         case NETDEV_UP:
8404                 if (!qeth_add_ip(card, addr))
8405                         kfree(addr);
8406                 break;
8407         case NETDEV_DOWN:
8408                 if (!qeth_delete_ip(card, addr))
8409                         kfree(addr);
8410                 break;
8411         default:
8412                 break;
8413         }
8414         qeth_set_ip_addr_list(card);
8415 out:
8416         return NOTIFY_DONE;
8417 }
8418
8419 static struct notifier_block qeth_ip6_notifier = {
8420         qeth_ip6_event,
8421         NULL,
8422 };
8423 #endif
8424
8425 static int
8426 __qeth_reboot_event_card(struct device *dev, void *data)
8427 {
8428         struct qeth_card *card;
8429
8430         card = (struct qeth_card *) dev->driver_data;
8431         qeth_clear_ip_list(card, 0, 0);
8432         qeth_qdio_clear_card(card, 0);
8433         return 0;
8434 }
8435
8436 static int
8437 qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8438 {
8439         int ret;
8440
8441         ret = driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8442                                      __qeth_reboot_event_card);
8443         return ret ? NOTIFY_BAD : NOTIFY_DONE;
8444 }
8445
8446
8447 static struct notifier_block qeth_reboot_notifier = {
8448         qeth_reboot_event,
8449         NULL,
8450 };
8451
8452 static int
8453 qeth_register_notifiers(void)
8454 {
8455         int r;
8456
8457         QETH_DBF_TEXT(trace,5,"regnotif");
8458         if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8459                 return r;
8460         if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8461                 goto out_reboot;
8462 #ifdef CONFIG_QETH_IPV6
8463         if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8464                 goto out_ipv4;
8465 #endif
8466         return 0;
8467
8468 #ifdef CONFIG_QETH_IPV6
8469 out_ipv4:
8470         unregister_inetaddr_notifier(&qeth_ip_notifier);
8471 #endif
8472 out_reboot:
8473         unregister_reboot_notifier(&qeth_reboot_notifier);
8474         return r;
8475 }
8476
8477 /**
8478  * unregister all event notifiers
8479  */
8480 static void
8481 qeth_unregister_notifiers(void)
8482 {
8483
8484         QETH_DBF_TEXT(trace,5,"unregnot");
8485         BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8486         BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8487 #ifdef CONFIG_QETH_IPV6
8488         BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8489 #endif /* QETH_IPV6 */
8490
8491 }
8492
8493 #ifdef CONFIG_QETH_IPV6
8494 static int
8495 qeth_ipv6_init(void)
8496 {
8497         qeth_old_arp_constructor = arp_tbl.constructor;
8498         write_lock_bh(&arp_tbl.lock);
8499         arp_tbl.constructor = qeth_arp_constructor;
8500         write_unlock_bh(&arp_tbl.lock);
8501
8502         arp_direct_ops = (struct neigh_ops*)
8503                 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8504         if (!arp_direct_ops)
8505                 return -ENOMEM;
8506
8507         memcpy(arp_direct_ops, &arp_direct_ops_template,
8508                sizeof(struct neigh_ops));
8509
8510         return 0;
8511 }
8512
8513 static void
8514 qeth_ipv6_uninit(void)
8515 {
8516         write_lock_bh(&arp_tbl.lock);
8517         arp_tbl.constructor = qeth_old_arp_constructor;
8518         write_unlock_bh(&arp_tbl.lock);
8519         kfree(arp_direct_ops);
8520 }
8521 #endif /* CONFIG_QETH_IPV6 */
8522
8523 static void
8524 qeth_sysfs_unregister(void)
8525 {
8526         s390_root_dev_unregister(qeth_root_dev);
8527         qeth_remove_driver_attributes();
8528         ccw_driver_unregister(&qeth_ccw_driver);
8529         ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8530 }
8531
8532 /**
8533  * register qeth at sysfs
8534  */
8535 static int
8536 qeth_sysfs_register(void)
8537 {
8538         int rc;
8539
8540         rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8541         if (rc)
8542                 goto out;
8543
8544         rc = ccw_driver_register(&qeth_ccw_driver);
8545         if (rc)
8546                 goto out_ccw_driver;
8547
8548         rc = qeth_create_driver_attributes();
8549         if (rc)
8550                 goto out_qeth_attr;
8551
8552         qeth_root_dev = s390_root_dev_register("qeth");
8553         rc = IS_ERR(qeth_root_dev) ? PTR_ERR(qeth_root_dev) : 0;
8554         if (!rc)
8555                 goto out;
8556
8557         qeth_remove_driver_attributes();
8558 out_qeth_attr:
8559         ccw_driver_unregister(&qeth_ccw_driver);
8560 out_ccw_driver:
8561         ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8562 out:
8563         return rc;
8564 }
8565
8566 /***
8567  * init function
8568  */
8569 static int __init
8570 qeth_init(void)
8571 {
8572         int rc;
8573
8574         PRINT_INFO("loading %s\n", version);
8575
8576         INIT_LIST_HEAD(&qeth_card_list.list);
8577         INIT_LIST_HEAD(&qeth_notify_list);
8578         spin_lock_init(&qeth_notify_lock);
8579         rwlock_init(&qeth_card_list.rwlock);
8580
8581         rc = qeth_register_dbf_views();
8582         if (rc)
8583                 goto out_err;
8584
8585         rc = qeth_sysfs_register();
8586         if (rc)
8587                 goto out_dbf;
8588
8589 #ifdef CONFIG_QETH_IPV6
8590         rc = qeth_ipv6_init();
8591         if (rc) {
8592                 PRINT_ERR("Out of memory during ipv6 init code = %d\n", rc);
8593                 goto out_sysfs;
8594         }
8595 #endif /* QETH_IPV6 */
8596         rc = qeth_register_notifiers();
8597         if (rc)
8598                 goto out_ipv6;
8599         rc = qeth_create_procfs_entries();
8600         if (rc)
8601                 goto out_notifiers;
8602
8603         return rc;
8604
8605 out_notifiers:
8606         qeth_unregister_notifiers();
8607 out_ipv6:
8608 #ifdef CONFIG_QETH_IPV6
8609         qeth_ipv6_uninit();
8610 out_sysfs:
8611 #endif /* QETH_IPV6 */
8612         qeth_sysfs_unregister();
8613 out_dbf:
8614         qeth_unregister_dbf_views();
8615 out_err:
8616         PRINT_ERR("Initialization failed with code %d\n", rc);
8617         return rc;
8618 }
8619
8620 static void
8621 __exit qeth_exit(void)
8622 {
8623         struct qeth_card *card, *tmp;
8624         unsigned long flags;
8625
8626         QETH_DBF_TEXT(trace,1, "cleanup.");
8627
8628         /*
8629          * Weed would not need to clean up our devices here, because the
8630          * common device layer calls qeth_remove_device for each device
8631          * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8632          * But we do cleanup here so we can do a "soft" shutdown of our cards.
8633          * qeth_remove_device called by the common device layer would otherwise
8634          * do a "hard" shutdown (card->use_hard_stop is set to one in
8635          * qeth_remove_device).
8636          */
8637 again:
8638         read_lock_irqsave(&qeth_card_list.rwlock, flags);
8639         list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8640                 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8641                 qeth_set_offline(card->gdev);
8642                 qeth_remove_device(card->gdev);
8643                 goto again;
8644         }
8645         read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8646 #ifdef CONFIG_QETH_IPV6
8647         qeth_ipv6_uninit();
8648 #endif
8649         qeth_unregister_notifiers();
8650         qeth_remove_procfs_entries();
8651         qeth_sysfs_unregister();
8652         qeth_unregister_dbf_views();
8653         printk("qeth: removed\n");
8654 }
8655
8656 EXPORT_SYMBOL(qeth_osn_register);
8657 EXPORT_SYMBOL(qeth_osn_deregister);
8658 EXPORT_SYMBOL(qeth_osn_assist);
8659 module_init(qeth_init);
8660 module_exit(qeth_exit);
8661 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
8662 MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8663                                       "Copyright 2000,2003 IBM Corporation\n");
8664
8665 MODULE_LICENSE("GPL");