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