[PATCH] s390: TSO related fixes in qeth driver
[linux-2.6/sactl.git] / drivers / s390 / net / qeth_main.c
blob6f784c3f43d5febd8469ba6b1638c656cade811e
1 /*
3 * linux/drivers/s390/net/qeth_main.c ($Revision: 1.219 $)
5 * Linux on zSeries OSA Express and HiperSockets support
7 * Copyright 2000,2003 IBM Corporation
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>
15 * $Revision: 1.219 $ $Date: 2005/05/04 20:19:18 $
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.
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.
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.
32 /***
33 * eye catcher; just for debugging purposes
35 void volatile
36 qeth_eyecatcher(void)
38 return;
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>
66 #include <net/arp.h>
67 #include <net/ip.h>
68 #include <net/route.h>
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>
77 #include "qeth.h"
78 #include "qeth_mpc.h"
79 #include "qeth_fs.h"
80 #include "qeth_eddp.h"
81 #include "qeth_tso.h"
83 #define VERSION_QETH_C "$Revision: 1.219 $"
84 static const char *version = "qeth S/390 OSA-Express driver";
86 /**
87 * Debug Facility Stuff
89 static debug_info_t *qeth_dbf_setup = NULL;
90 static debug_info_t *qeth_dbf_data = NULL;
91 static debug_info_t *qeth_dbf_misc = NULL;
92 static debug_info_t *qeth_dbf_control = NULL;
93 debug_info_t *qeth_dbf_trace = NULL;
94 static debug_info_t *qeth_dbf_sense = NULL;
95 static debug_info_t *qeth_dbf_qerr = NULL;
97 DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
99 /**
100 * some more definitions and declarations
102 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
104 /* list of our cards */
105 struct qeth_card_list_struct qeth_card_list;
106 /*process list want to be notified*/
107 spinlock_t qeth_notify_lock;
108 struct list_head qeth_notify_list;
110 static void qeth_send_control_data_cb(struct qeth_channel *,
111 struct qeth_cmd_buffer *);
114 * here we go with function implementation
116 static void
117 qeth_init_qdio_info(struct qeth_card *card);
119 static int
120 qeth_init_qdio_queues(struct qeth_card *card);
122 static int
123 qeth_alloc_qdio_buffers(struct qeth_card *card);
125 static void
126 qeth_free_qdio_buffers(struct qeth_card *);
128 static void
129 qeth_clear_qdio_buffers(struct qeth_card *);
131 static void
132 qeth_clear_ip_list(struct qeth_card *, int, int);
134 static void
135 qeth_clear_ipacmd_list(struct qeth_card *);
137 static int
138 qeth_qdio_clear_card(struct qeth_card *, int);
140 static void
141 qeth_clear_working_pool_list(struct qeth_card *);
143 static void
144 qeth_clear_cmd_buffers(struct qeth_channel *);
146 static int
147 qeth_stop(struct net_device *);
149 static void
150 qeth_clear_ipato_list(struct qeth_card *);
152 static int
153 qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
155 static void
156 qeth_irq_tasklet(unsigned long);
158 static int
159 qeth_set_online(struct ccwgroup_device *);
161 static int
162 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
164 static struct qeth_ipaddr *
165 qeth_get_addr_buffer(enum qeth_prot_versions);
167 static void
168 qeth_set_multicast_list(struct net_device *);
170 static void
171 qeth_notify_processes(void)
173 /*notify all registered processes */
174 struct qeth_notify_list_struct *n_entry;
176 QETH_DBF_TEXT(trace,3,"procnoti");
177 spin_lock(&qeth_notify_lock);
178 list_for_each_entry(n_entry, &qeth_notify_list, list) {
179 send_sig(n_entry->signum, n_entry->task, 1);
181 spin_unlock(&qeth_notify_lock);
185 qeth_notifier_unregister(struct task_struct *p)
187 struct qeth_notify_list_struct *n_entry, *tmp;
189 QETH_DBF_TEXT(trace, 2, "notunreg");
190 spin_lock(&qeth_notify_lock);
191 list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
192 if (n_entry->task == p) {
193 list_del(&n_entry->list);
194 kfree(n_entry);
195 goto out;
198 out:
199 spin_unlock(&qeth_notify_lock);
200 return 0;
203 qeth_notifier_register(struct task_struct *p, int signum)
205 struct qeth_notify_list_struct *n_entry;
208 /*check first if entry already exists*/
209 spin_lock(&qeth_notify_lock);
210 list_for_each_entry(n_entry, &qeth_notify_list, list) {
211 if (n_entry->task == p) {
212 n_entry->signum = signum;
213 spin_unlock(&qeth_notify_lock);
214 return 0;
217 spin_unlock(&qeth_notify_lock);
219 n_entry = (struct qeth_notify_list_struct *)
220 kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL);
221 if (!n_entry)
222 return -ENOMEM;
223 n_entry->task = p;
224 n_entry->signum = signum;
225 spin_lock(&qeth_notify_lock);
226 list_add(&n_entry->list,&qeth_notify_list);
227 spin_unlock(&qeth_notify_lock);
228 return 0;
233 * free channel command buffers
235 static void
236 qeth_clean_channel(struct qeth_channel *channel)
238 int cnt;
240 QETH_DBF_TEXT(setup, 2, "freech");
241 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
242 kfree(channel->iob[cnt].data);
246 * free card
248 static void
249 qeth_free_card(struct qeth_card *card)
252 QETH_DBF_TEXT(setup, 2, "freecrd");
253 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
254 qeth_clean_channel(&card->read);
255 qeth_clean_channel(&card->write);
256 if (card->dev)
257 free_netdev(card->dev);
258 qeth_clear_ip_list(card, 0, 0);
259 qeth_clear_ipato_list(card);
260 kfree(card->ip_tbd_list);
261 qeth_free_qdio_buffers(card);
262 kfree(card);
266 * alloc memory for command buffer per channel
268 static int
269 qeth_setup_channel(struct qeth_channel *channel)
271 int cnt;
273 QETH_DBF_TEXT(setup, 2, "setupch");
274 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
275 channel->iob[cnt].data = (char *)
276 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
277 if (channel->iob[cnt].data == NULL)
278 break;
279 channel->iob[cnt].state = BUF_STATE_FREE;
280 channel->iob[cnt].channel = channel;
281 channel->iob[cnt].callback = qeth_send_control_data_cb;
282 channel->iob[cnt].rc = 0;
284 if (cnt < QETH_CMD_BUFFER_NO) {
285 while (cnt-- > 0)
286 kfree(channel->iob[cnt].data);
287 return -ENOMEM;
289 channel->buf_no = 0;
290 channel->io_buf_no = 0;
291 atomic_set(&channel->irq_pending, 0);
292 spin_lock_init(&channel->iob_lock);
294 init_waitqueue_head(&channel->wait_q);
295 channel->irq_tasklet.data = (unsigned long) channel;
296 channel->irq_tasklet.func = qeth_irq_tasklet;
297 return 0;
301 * alloc memory for card structure
303 static struct qeth_card *
304 qeth_alloc_card(void)
306 struct qeth_card *card;
308 QETH_DBF_TEXT(setup, 2, "alloccrd");
309 card = (struct qeth_card *) kmalloc(sizeof(struct qeth_card),
310 GFP_DMA|GFP_KERNEL);
311 if (!card)
312 return NULL;
313 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
314 memset(card, 0, sizeof(struct qeth_card));
315 if (qeth_setup_channel(&card->read)) {
316 kfree(card);
317 return NULL;
319 if (qeth_setup_channel(&card->write)) {
320 qeth_clean_channel(&card->read);
321 kfree(card);
322 return NULL;
324 return card;
327 static long
328 __qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb)
330 if (!IS_ERR(irb))
331 return 0;
333 switch (PTR_ERR(irb)) {
334 case -EIO:
335 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
336 QETH_DBF_TEXT(trace, 2, "ckirberr");
337 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
338 break;
339 case -ETIMEDOUT:
340 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
341 QETH_DBF_TEXT(trace, 2, "ckirberr");
342 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
343 break;
344 default:
345 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
346 cdev->dev.bus_id);
347 QETH_DBF_TEXT(trace, 2, "ckirberr");
348 QETH_DBF_TEXT(trace, 2, " rc???");
350 return PTR_ERR(irb);
353 static int
354 qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
356 int dstat,cstat;
357 char *sense;
359 sense = (char *) irb->ecw;
360 cstat = irb->scsw.cstat;
361 dstat = irb->scsw.dstat;
363 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
364 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
365 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
366 QETH_DBF_TEXT(trace,2, "CGENCHK");
367 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
368 cdev->dev.bus_id, dstat, cstat);
369 HEXDUMP16(WARN, "irb: ", irb);
370 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
371 return 1;
374 if (dstat & DEV_STAT_UNIT_CHECK) {
375 if (sense[SENSE_RESETTING_EVENT_BYTE] &
376 SENSE_RESETTING_EVENT_FLAG) {
377 QETH_DBF_TEXT(trace,2,"REVIND");
378 return 1;
380 if (sense[SENSE_COMMAND_REJECT_BYTE] &
381 SENSE_COMMAND_REJECT_FLAG) {
382 QETH_DBF_TEXT(trace,2,"CMDREJi");
383 return 0;
385 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
386 QETH_DBF_TEXT(trace,2,"AFFE");
387 return 1;
389 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
390 QETH_DBF_TEXT(trace,2,"ZEROSEN");
391 return 0;
393 QETH_DBF_TEXT(trace,2,"DGENCHK");
394 return 1;
396 return 0;
398 static int qeth_issue_next_read(struct qeth_card *);
401 * interrupt handler
403 static void
404 qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
406 int rc;
407 int cstat,dstat;
408 struct qeth_cmd_buffer *buffer;
409 struct qeth_channel *channel;
410 struct qeth_card *card;
412 QETH_DBF_TEXT(trace,5,"irq");
414 if (__qeth_check_irb_error(cdev, irb))
415 return;
416 cstat = irb->scsw.cstat;
417 dstat = irb->scsw.dstat;
419 card = CARD_FROM_CDEV(cdev);
420 if (!card)
421 return;
423 if (card->read.ccwdev == cdev){
424 channel = &card->read;
425 QETH_DBF_TEXT(trace,5,"read");
426 } else if (card->write.ccwdev == cdev) {
427 channel = &card->write;
428 QETH_DBF_TEXT(trace,5,"write");
429 } else {
430 channel = &card->data;
431 QETH_DBF_TEXT(trace,5,"data");
433 atomic_set(&channel->irq_pending, 0);
435 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
436 channel->state = CH_STATE_STOPPED;
438 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
439 channel->state = CH_STATE_HALTED;
441 /*let's wake up immediately on data channel*/
442 if ((channel == &card->data) && (intparm != 0))
443 goto out;
445 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
446 QETH_DBF_TEXT(trace, 6, "clrchpar");
447 /* we don't have to handle this further */
448 intparm = 0;
450 if (intparm == QETH_HALT_CHANNEL_PARM) {
451 QETH_DBF_TEXT(trace, 6, "hltchpar");
452 /* we don't have to handle this further */
453 intparm = 0;
455 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
456 (dstat & DEV_STAT_UNIT_CHECK) ||
457 (cstat)) {
458 if (irb->esw.esw0.erw.cons) {
459 /* TODO: we should make this s390dbf */
460 PRINT_WARN("sense data available on channel %s.\n",
461 CHANNEL_ID(channel));
462 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
463 HEXDUMP16(WARN,"irb: ",irb);
464 HEXDUMP16(WARN,"sense data: ",irb->ecw);
466 rc = qeth_get_problem(cdev,irb);
467 if (rc) {
468 qeth_schedule_recovery(card);
469 goto out;
473 if (intparm) {
474 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
475 buffer->state = BUF_STATE_PROCESSED;
477 if (channel == &card->data)
478 return;
480 if (channel == &card->read &&
481 channel->state == CH_STATE_UP)
482 qeth_issue_next_read(card);
484 tasklet_schedule(&channel->irq_tasklet);
485 return;
486 out:
487 wake_up(&card->wait_q);
491 * tasklet function scheduled from irq handler
493 static void
494 qeth_irq_tasklet(unsigned long data)
496 struct qeth_card *card;
497 struct qeth_channel *channel;
498 struct qeth_cmd_buffer *iob;
499 __u8 index;
501 QETH_DBF_TEXT(trace,5,"irqtlet");
502 channel = (struct qeth_channel *) data;
503 iob = channel->iob;
504 index = channel->buf_no;
505 card = CARD_FROM_CDEV(channel->ccwdev);
506 while (iob[index].state == BUF_STATE_PROCESSED) {
507 if (iob[index].callback !=NULL) {
508 iob[index].callback(channel,iob + index);
510 index = (index + 1) % QETH_CMD_BUFFER_NO;
512 channel->buf_no = index;
513 wake_up(&card->wait_q);
516 static int qeth_stop_card(struct qeth_card *, int);
518 static int
519 __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
521 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
522 int rc = 0;
523 enum qeth_card_states recover_flag;
525 QETH_DBF_TEXT(setup, 3, "setoffl");
526 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
528 recover_flag = card->state;
529 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
530 PRINT_WARN("Stopping card %s interrupted by user!\n",
531 CARD_BUS_ID(card));
532 return -ERESTARTSYS;
534 if ((rc = ccw_device_set_offline(CARD_DDEV(card))) ||
535 (rc = ccw_device_set_offline(CARD_WDEV(card))) ||
536 (rc = ccw_device_set_offline(CARD_RDEV(card)))) {
537 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
539 if (recover_flag == CARD_STATE_UP)
540 card->state = CARD_STATE_RECOVER;
541 qeth_notify_processes();
542 return 0;
545 static int
546 qeth_set_offline(struct ccwgroup_device *cgdev)
548 return __qeth_set_offline(cgdev, 0);
551 static int
552 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads);
555 static void
556 qeth_remove_device(struct ccwgroup_device *cgdev)
558 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
559 unsigned long flags;
561 QETH_DBF_TEXT(setup, 3, "rmdev");
562 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
564 if (!card)
565 return;
567 if (qeth_wait_for_threads(card, 0xffffffff))
568 return;
570 if (cgdev->state == CCWGROUP_ONLINE){
571 card->use_hard_stop = 1;
572 qeth_set_offline(cgdev);
574 /* remove form our internal list */
575 write_lock_irqsave(&qeth_card_list.rwlock, flags);
576 list_del(&card->list);
577 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
578 if (card->dev)
579 unregister_netdev(card->dev);
580 qeth_remove_device_attributes(&cgdev->dev);
581 qeth_free_card(card);
582 cgdev->dev.driver_data = NULL;
583 put_device(&cgdev->dev);
586 static int
587 qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
588 static int
589 qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
592 * Add/remove address to/from card's ip list, i.e. try to add or remove
593 * reference to/from an IP address that is already registered on the card.
594 * Returns:
595 * 0 address was on card and its reference count has been adjusted,
596 * but is still > 0, so nothing has to be done
597 * also returns 0 if card was not on card and the todo was to delete
598 * the address -> there is also nothing to be done
599 * 1 address was not on card and the todo is to add it to the card's ip
600 * list
601 * -1 address was on card and its reference count has been decremented
602 * to <= 0 by the todo -> address must be removed from card
604 static int
605 __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
606 struct qeth_ipaddr **__addr)
608 struct qeth_ipaddr *addr;
609 int found = 0;
611 list_for_each_entry(addr, &card->ip_list, entry) {
612 if ((addr->proto == QETH_PROT_IPV4) &&
613 (todo->proto == QETH_PROT_IPV4) &&
614 (addr->type == todo->type) &&
615 (addr->u.a4.addr == todo->u.a4.addr) &&
616 (addr->u.a4.mask == todo->u.a4.mask) ){
617 found = 1;
618 break;
620 if ((addr->proto == QETH_PROT_IPV6) &&
621 (todo->proto == QETH_PROT_IPV6) &&
622 (addr->type == todo->type) &&
623 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
624 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
625 sizeof(struct in6_addr)) == 0)) {
626 found = 1;
627 break;
630 if (found){
631 addr->users += todo->users;
632 if (addr->users <= 0){
633 *__addr = addr;
634 return -1;
635 } else {
636 /* for VIPA and RXIP limit refcount to 1 */
637 if (addr->type != QETH_IP_TYPE_NORMAL)
638 addr->users = 1;
639 return 0;
642 if (todo->users > 0){
643 /* for VIPA and RXIP limit refcount to 1 */
644 if (todo->type != QETH_IP_TYPE_NORMAL)
645 todo->users = 1;
646 return 1;
647 } else
648 return 0;
651 static inline int
652 __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
653 int same_type)
655 struct qeth_ipaddr *tmp;
657 list_for_each_entry(tmp, list, entry) {
658 if ((tmp->proto == QETH_PROT_IPV4) &&
659 (addr->proto == QETH_PROT_IPV4) &&
660 ((same_type && (tmp->type == addr->type)) ||
661 (!same_type && (tmp->type != addr->type)) ) &&
662 (tmp->u.a4.addr == addr->u.a4.addr) ){
663 return 1;
665 if ((tmp->proto == QETH_PROT_IPV6) &&
666 (addr->proto == QETH_PROT_IPV6) &&
667 ((same_type && (tmp->type == addr->type)) ||
668 (!same_type && (tmp->type != addr->type)) ) &&
669 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
670 sizeof(struct in6_addr)) == 0) ) {
671 return 1;
674 return 0;
678 * Add IP to be added to todo list. If there is already an "add todo"
679 * in this list we just incremenent the reference count.
680 * Returns 0 if we just incremented reference count.
682 static int
683 __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
685 struct qeth_ipaddr *tmp, *t;
686 int found = 0;
688 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
689 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
690 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
691 return 0;
692 if ((tmp->proto == QETH_PROT_IPV4) &&
693 (addr->proto == QETH_PROT_IPV4) &&
694 (tmp->type == addr->type) &&
695 (tmp->is_multicast == addr->is_multicast) &&
696 (tmp->u.a4.addr == addr->u.a4.addr) &&
697 (tmp->u.a4.mask == addr->u.a4.mask) ){
698 found = 1;
699 break;
701 if ((tmp->proto == QETH_PROT_IPV6) &&
702 (addr->proto == QETH_PROT_IPV6) &&
703 (tmp->type == addr->type) &&
704 (tmp->is_multicast == addr->is_multicast) &&
705 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
706 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
707 sizeof(struct in6_addr)) == 0) ){
708 found = 1;
709 break;
712 if (found){
713 if (addr->users != 0)
714 tmp->users += addr->users;
715 else
716 tmp->users += add? 1:-1;
717 if (tmp->users == 0){
718 list_del(&tmp->entry);
719 kfree(tmp);
721 return 0;
722 } else {
723 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
724 list_add(&addr->entry, card->ip_tbd_list);
725 else {
726 if (addr->users == 0)
727 addr->users += add? 1:-1;
728 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
729 qeth_is_addr_covered_by_ipato(card, addr)){
730 QETH_DBF_TEXT(trace, 2, "tkovaddr");
731 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
733 list_add_tail(&addr->entry, card->ip_tbd_list);
735 return 1;
740 * Remove IP address from list
742 static int
743 qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
745 unsigned long flags;
746 int rc = 0;
748 QETH_DBF_TEXT(trace,4,"delip");
749 if (addr->proto == QETH_PROT_IPV4)
750 QETH_DBF_HEX(trace,4,&addr->u.a4.addr,4);
751 else {
752 QETH_DBF_HEX(trace,4,&addr->u.a6.addr,8);
753 QETH_DBF_HEX(trace,4,((char *)&addr->u.a6.addr)+8,8);
755 spin_lock_irqsave(&card->ip_lock, flags);
756 rc = __qeth_insert_ip_todo(card, addr, 0);
757 spin_unlock_irqrestore(&card->ip_lock, flags);
758 return rc;
761 static int
762 qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
764 unsigned long flags;
765 int rc = 0;
767 QETH_DBF_TEXT(trace,4,"addip");
768 if (addr->proto == QETH_PROT_IPV4)
769 QETH_DBF_HEX(trace,4,&addr->u.a4.addr,4);
770 else {
771 QETH_DBF_HEX(trace,4,&addr->u.a6.addr,8);
772 QETH_DBF_HEX(trace,4,((char *)&addr->u.a6.addr)+8,8);
774 spin_lock_irqsave(&card->ip_lock, flags);
775 rc = __qeth_insert_ip_todo(card, addr, 1);
776 spin_unlock_irqrestore(&card->ip_lock, flags);
777 return rc;
780 static inline void
781 __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
783 struct qeth_ipaddr *addr, *tmp;
784 int rc;
786 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
787 if (addr->is_multicast) {
788 spin_unlock_irqrestore(&card->ip_lock, *flags);
789 rc = qeth_deregister_addr_entry(card, addr);
790 spin_lock_irqsave(&card->ip_lock, *flags);
791 if (!rc) {
792 list_del(&addr->entry);
793 kfree(addr);
799 static void
800 qeth_set_ip_addr_list(struct qeth_card *card)
802 struct list_head *tbd_list;
803 struct qeth_ipaddr *todo, *addr;
804 unsigned long flags;
805 int rc;
807 QETH_DBF_TEXT(trace, 2, "sdiplist");
808 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
810 spin_lock_irqsave(&card->ip_lock, flags);
811 tbd_list = card->ip_tbd_list;
812 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
813 if (!card->ip_tbd_list) {
814 QETH_DBF_TEXT(trace, 0, "silnomem");
815 card->ip_tbd_list = tbd_list;
816 spin_unlock_irqrestore(&card->ip_lock, flags);
817 return;
818 } else
819 INIT_LIST_HEAD(card->ip_tbd_list);
821 while (!list_empty(tbd_list)){
822 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
823 list_del(&todo->entry);
824 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
825 __qeth_delete_all_mc(card, &flags);
826 kfree(todo);
827 continue;
829 rc = __qeth_ref_ip_on_card(card, todo, &addr);
830 if (rc == 0) {
831 /* nothing to be done; only adjusted refcount */
832 kfree(todo);
833 } else if (rc == 1) {
834 /* new entry to be added to on-card list */
835 spin_unlock_irqrestore(&card->ip_lock, flags);
836 rc = qeth_register_addr_entry(card, todo);
837 spin_lock_irqsave(&card->ip_lock, flags);
838 if (!rc)
839 list_add_tail(&todo->entry, &card->ip_list);
840 else
841 kfree(todo);
842 } else if (rc == -1) {
843 /* on-card entry to be removed */
844 list_del_init(&addr->entry);
845 spin_unlock_irqrestore(&card->ip_lock, flags);
846 rc = qeth_deregister_addr_entry(card, addr);
847 spin_lock_irqsave(&card->ip_lock, flags);
848 if (!rc)
849 kfree(addr);
850 else
851 list_add_tail(&addr->entry, &card->ip_list);
852 kfree(todo);
855 spin_unlock_irqrestore(&card->ip_lock, flags);
856 kfree(tbd_list);
859 static void qeth_delete_mc_addresses(struct qeth_card *);
860 static void qeth_add_multicast_ipv4(struct qeth_card *);
861 #ifdef CONFIG_QETH_IPV6
862 static void qeth_add_multicast_ipv6(struct qeth_card *);
863 #endif
865 static inline int
866 qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
868 unsigned long flags;
870 spin_lock_irqsave(&card->thread_mask_lock, flags);
871 if ( !(card->thread_allowed_mask & thread) ||
872 (card->thread_start_mask & thread) ) {
873 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
874 return -EPERM;
876 card->thread_start_mask |= thread;
877 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
878 return 0;
881 static void
882 qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
884 unsigned long flags;
886 spin_lock_irqsave(&card->thread_mask_lock, flags);
887 card->thread_start_mask &= ~thread;
888 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
889 wake_up(&card->wait_q);
892 static void
893 qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
895 unsigned long flags;
897 spin_lock_irqsave(&card->thread_mask_lock, flags);
898 card->thread_running_mask &= ~thread;
899 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
900 wake_up(&card->wait_q);
903 static inline int
904 __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
906 unsigned long flags;
907 int rc = 0;
909 spin_lock_irqsave(&card->thread_mask_lock, flags);
910 if (card->thread_start_mask & thread){
911 if ((card->thread_allowed_mask & thread) &&
912 !(card->thread_running_mask & thread)){
913 rc = 1;
914 card->thread_start_mask &= ~thread;
915 card->thread_running_mask |= thread;
916 } else
917 rc = -EPERM;
919 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
920 return rc;
923 static int
924 qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
926 int rc = 0;
928 wait_event(card->wait_q,
929 (rc = __qeth_do_run_thread(card, thread)) >= 0);
930 return rc;
933 static int
934 qeth_register_ip_addresses(void *ptr)
936 struct qeth_card *card;
938 card = (struct qeth_card *) ptr;
939 daemonize("qeth_reg_ip");
940 QETH_DBF_TEXT(trace,4,"regipth1");
941 if (!qeth_do_run_thread(card, QETH_SET_IP_THREAD))
942 return 0;
943 QETH_DBF_TEXT(trace,4,"regipth2");
944 qeth_set_ip_addr_list(card);
945 qeth_clear_thread_running_bit(card, QETH_SET_IP_THREAD);
946 return 0;
949 static int
950 qeth_recover(void *ptr)
952 struct qeth_card *card;
953 int rc = 0;
955 card = (struct qeth_card *) ptr;
956 daemonize("qeth_recover");
957 QETH_DBF_TEXT(trace,2,"recover1");
958 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
959 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
960 return 0;
961 QETH_DBF_TEXT(trace,2,"recover2");
962 PRINT_WARN("Recovery of device %s started ...\n",
963 CARD_BUS_ID(card));
964 card->use_hard_stop = 1;
965 __qeth_set_offline(card->gdev,1);
966 rc = __qeth_set_online(card->gdev,1);
967 if (!rc)
968 PRINT_INFO("Device %s successfully recovered!\n",
969 CARD_BUS_ID(card));
970 else
971 PRINT_INFO("Device %s could not be recovered!\n",
972 CARD_BUS_ID(card));
973 /* don't run another scheduled recovery */
974 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
975 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
976 return 0;
979 void
980 qeth_schedule_recovery(struct qeth_card *card)
982 QETH_DBF_TEXT(trace,2,"startrec");
984 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
985 schedule_work(&card->kernel_thread_starter);
988 static int
989 qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
991 unsigned long flags;
992 int rc = 0;
994 spin_lock_irqsave(&card->thread_mask_lock, flags);
995 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
996 (u8) card->thread_start_mask,
997 (u8) card->thread_allowed_mask,
998 (u8) card->thread_running_mask);
999 rc = (card->thread_start_mask & thread);
1000 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1001 return rc;
1004 static void
1005 qeth_start_kernel_thread(struct qeth_card *card)
1007 QETH_DBF_TEXT(trace , 2, "strthrd");
1009 if (card->read.state != CH_STATE_UP &&
1010 card->write.state != CH_STATE_UP)
1011 return;
1013 if (qeth_do_start_thread(card, QETH_SET_IP_THREAD))
1014 kernel_thread(qeth_register_ip_addresses, (void *)card,SIGCHLD);
1015 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1016 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1020 static void
1021 qeth_set_intial_options(struct qeth_card *card)
1023 card->options.route4.type = NO_ROUTER;
1024 #ifdef CONFIG_QETH_IPV6
1025 card->options.route6.type = NO_ROUTER;
1026 #endif /* QETH_IPV6 */
1027 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1028 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1029 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1030 card->options.fake_broadcast = 0;
1031 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1032 card->options.fake_ll = 0;
1033 card->options.layer2 = 0;
1037 * initialize channels ,card and all state machines
1039 static int
1040 qeth_setup_card(struct qeth_card *card)
1043 QETH_DBF_TEXT(setup, 2, "setupcrd");
1044 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1046 card->read.state = CH_STATE_DOWN;
1047 card->write.state = CH_STATE_DOWN;
1048 card->data.state = CH_STATE_DOWN;
1049 card->state = CARD_STATE_DOWN;
1050 card->lan_online = 0;
1051 card->use_hard_stop = 0;
1052 card->dev = NULL;
1053 #ifdef CONFIG_QETH_VLAN
1054 spin_lock_init(&card->vlanlock);
1055 card->vlangrp = NULL;
1056 #endif
1057 spin_lock_init(&card->ip_lock);
1058 spin_lock_init(&card->thread_mask_lock);
1059 card->thread_start_mask = 0;
1060 card->thread_allowed_mask = 0;
1061 card->thread_running_mask = 0;
1062 INIT_WORK(&card->kernel_thread_starter,
1063 (void *)qeth_start_kernel_thread,card);
1064 INIT_LIST_HEAD(&card->ip_list);
1065 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1066 if (!card->ip_tbd_list) {
1067 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1068 return -ENOMEM;
1070 INIT_LIST_HEAD(card->ip_tbd_list);
1071 INIT_LIST_HEAD(&card->cmd_waiter_list);
1072 init_waitqueue_head(&card->wait_q);
1073 /* intial options */
1074 qeth_set_intial_options(card);
1075 /* IP address takeover */
1076 INIT_LIST_HEAD(&card->ipato.entries);
1077 card->ipato.enabled = 0;
1078 card->ipato.invert4 = 0;
1079 card->ipato.invert6 = 0;
1080 /* init QDIO stuff */
1081 qeth_init_qdio_info(card);
1082 return 0;
1085 static int
1086 is_1920_device (struct qeth_card *card)
1088 int single_queue = 0;
1089 struct ccw_device *ccwdev;
1090 struct channelPath_dsc {
1091 u8 flags;
1092 u8 lsn;
1093 u8 desc;
1094 u8 chpid;
1095 u8 swla;
1096 u8 zeroes;
1097 u8 chla;
1098 u8 chpp;
1099 } *chp_dsc;
1101 QETH_DBF_TEXT(setup, 2, "chk_1920");
1103 ccwdev = card->data.ccwdev;
1104 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1105 if (chp_dsc != NULL) {
1106 /* CHPP field bit 6 == 1 -> single queue */
1107 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1108 kfree(chp_dsc);
1110 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1111 return single_queue;
1114 static int
1115 qeth_determine_card_type(struct qeth_card *card)
1117 int i = 0;
1119 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1121 while (known_devices[i][4]) {
1122 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1123 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1124 card->info.type = known_devices[i][4];
1125 if (is_1920_device(card)) {
1126 PRINT_INFO("Priority Queueing not able "
1127 "due to hardware limitations!\n");
1128 card->qdio.no_out_queues = 1;
1129 card->qdio.default_out_queue = 0;
1130 } else {
1131 card->qdio.no_out_queues = known_devices[i][8];
1133 card->info.is_multicast_different = known_devices[i][9];
1134 return 0;
1136 i++;
1138 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1139 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1140 return -ENOENT;
1143 static int
1144 qeth_probe_device(struct ccwgroup_device *gdev)
1146 struct qeth_card *card;
1147 struct device *dev;
1148 unsigned long flags;
1149 int rc;
1151 QETH_DBF_TEXT(setup, 2, "probedev");
1153 dev = &gdev->dev;
1154 if (!get_device(dev))
1155 return -ENODEV;
1157 card = qeth_alloc_card();
1158 if (!card) {
1159 put_device(dev);
1160 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1161 return -ENOMEM;
1163 card->read.ccwdev = gdev->cdev[0];
1164 card->write.ccwdev = gdev->cdev[1];
1165 card->data.ccwdev = gdev->cdev[2];
1167 if ((rc = qeth_setup_card(card))){
1168 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1169 put_device(dev);
1170 qeth_free_card(card);
1171 return rc;
1173 gdev->dev.driver_data = card;
1174 card->gdev = gdev;
1175 gdev->cdev[0]->handler = qeth_irq;
1176 gdev->cdev[1]->handler = qeth_irq;
1177 gdev->cdev[2]->handler = qeth_irq;
1179 rc = qeth_create_device_attributes(dev);
1180 if (rc) {
1181 put_device(dev);
1182 qeth_free_card(card);
1183 return rc;
1185 if ((rc = qeth_determine_card_type(card))){
1186 PRINT_WARN("%s: not a valid card type\n", __func__);
1187 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1188 put_device(dev);
1189 qeth_free_card(card);
1190 return rc;
1192 /* insert into our internal list */
1193 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1194 list_add_tail(&card->list, &qeth_card_list.list);
1195 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1196 return rc;
1200 static int
1201 qeth_get_unitaddr(struct qeth_card *card)
1203 int length;
1204 char *prcd;
1205 int rc;
1207 QETH_DBF_TEXT(setup, 2, "getunit");
1208 rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length);
1209 if (rc) {
1210 PRINT_ERR("read_conf_data for device %s returned %i\n",
1211 CARD_DDEV_ID(card), rc);
1212 return rc;
1214 card->info.chpid = prcd[30];
1215 card->info.unit_addr2 = prcd[31];
1216 card->info.cula = prcd[63];
1217 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1218 (prcd[0x11] == _ascebc['M']));
1219 return 0;
1222 static void
1223 qeth_init_tokens(struct qeth_card *card)
1225 card->token.issuer_rm_w = 0x00010103UL;
1226 card->token.cm_filter_w = 0x00010108UL;
1227 card->token.cm_connection_w = 0x0001010aUL;
1228 card->token.ulp_filter_w = 0x0001010bUL;
1229 card->token.ulp_connection_w = 0x0001010dUL;
1232 static inline __u16
1233 raw_devno_from_bus_id(char *id)
1235 id += (strlen(id) - 4);
1236 return (__u16) simple_strtoul(id, &id, 16);
1239 * setup channel
1241 static void
1242 qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1244 struct qeth_card *card;
1246 QETH_DBF_TEXT(trace, 4, "setupccw");
1247 card = CARD_FROM_CDEV(channel->ccwdev);
1248 if (channel == &card->read)
1249 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1250 else
1251 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1252 channel->ccw.count = len;
1253 channel->ccw.cda = (__u32) __pa(iob);
1257 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1259 static struct qeth_cmd_buffer *
1260 __qeth_get_buffer(struct qeth_channel *channel)
1262 __u8 index;
1264 QETH_DBF_TEXT(trace, 6, "getbuff");
1265 index = channel->io_buf_no;
1266 do {
1267 if (channel->iob[index].state == BUF_STATE_FREE) {
1268 channel->iob[index].state = BUF_STATE_LOCKED;
1269 channel->io_buf_no = (channel->io_buf_no + 1) %
1270 QETH_CMD_BUFFER_NO;
1271 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1272 return channel->iob + index;
1274 index = (index + 1) % QETH_CMD_BUFFER_NO;
1275 } while(index != channel->io_buf_no);
1277 return NULL;
1281 * release command buffer
1283 static void
1284 qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1286 unsigned long flags;
1288 QETH_DBF_TEXT(trace, 6, "relbuff");
1289 spin_lock_irqsave(&channel->iob_lock, flags);
1290 memset(iob->data, 0, QETH_BUFSIZE);
1291 iob->state = BUF_STATE_FREE;
1292 iob->callback = qeth_send_control_data_cb;
1293 iob->rc = 0;
1294 spin_unlock_irqrestore(&channel->iob_lock, flags);
1297 static struct qeth_cmd_buffer *
1298 qeth_get_buffer(struct qeth_channel *channel)
1300 struct qeth_cmd_buffer *buffer = NULL;
1301 unsigned long flags;
1303 spin_lock_irqsave(&channel->iob_lock, flags);
1304 buffer = __qeth_get_buffer(channel);
1305 spin_unlock_irqrestore(&channel->iob_lock, flags);
1306 return buffer;
1309 static struct qeth_cmd_buffer *
1310 qeth_wait_for_buffer(struct qeth_channel *channel)
1312 struct qeth_cmd_buffer *buffer;
1313 wait_event(channel->wait_q,
1314 ((buffer = qeth_get_buffer(channel)) != NULL));
1315 return buffer;
1318 static void
1319 qeth_clear_cmd_buffers(struct qeth_channel *channel)
1321 int cnt = 0;
1323 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1324 qeth_release_buffer(channel,&channel->iob[cnt]);
1325 channel->buf_no = 0;
1326 channel->io_buf_no = 0;
1330 * start IDX for read and write channel
1332 static int
1333 qeth_idx_activate_get_answer(struct qeth_channel *channel,
1334 void (*idx_reply_cb)(struct qeth_channel *,
1335 struct qeth_cmd_buffer *))
1337 struct qeth_cmd_buffer *iob;
1338 unsigned long flags;
1339 int rc;
1340 struct qeth_card *card;
1342 QETH_DBF_TEXT(setup, 2, "idxanswr");
1343 card = CARD_FROM_CDEV(channel->ccwdev);
1344 iob = qeth_get_buffer(channel);
1345 iob->callback = idx_reply_cb;
1346 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1347 channel->ccw.count = QETH_BUFSIZE;
1348 channel->ccw.cda = (__u32) __pa(iob->data);
1350 wait_event(card->wait_q,
1351 atomic_compare_and_swap(0,1,&channel->irq_pending) == 0);
1352 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1353 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1354 rc = ccw_device_start(channel->ccwdev,
1355 &channel->ccw,(addr_t) iob, 0, 0);
1356 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1358 if (rc) {
1359 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1360 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1361 atomic_set(&channel->irq_pending, 0);
1362 wake_up(&card->wait_q);
1363 return rc;
1365 rc = wait_event_interruptible_timeout(card->wait_q,
1366 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1367 if (rc == -ERESTARTSYS)
1368 return rc;
1369 if (channel->state != CH_STATE_UP){
1370 rc = -ETIME;
1371 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1372 qeth_clear_cmd_buffers(channel);
1373 } else
1374 rc = 0;
1375 return rc;
1378 static int
1379 qeth_idx_activate_channel(struct qeth_channel *channel,
1380 void (*idx_reply_cb)(struct qeth_channel *,
1381 struct qeth_cmd_buffer *))
1383 struct qeth_card *card;
1384 struct qeth_cmd_buffer *iob;
1385 unsigned long flags;
1386 __u16 temp;
1387 int rc;
1389 card = CARD_FROM_CDEV(channel->ccwdev);
1391 QETH_DBF_TEXT(setup, 2, "idxactch");
1393 iob = qeth_get_buffer(channel);
1394 iob->callback = idx_reply_cb;
1395 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1396 channel->ccw.count = IDX_ACTIVATE_SIZE;
1397 channel->ccw.cda = (__u32) __pa(iob->data);
1398 if (channel == &card->write) {
1399 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1400 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1401 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1402 card->seqno.trans_hdr++;
1403 } else {
1404 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1405 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1406 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1408 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1409 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1410 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1411 &card->info.func_level,sizeof(__u16));
1412 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1413 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1414 temp = (card->info.cula << 8) + card->info.unit_addr2;
1415 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1417 wait_event(card->wait_q,
1418 atomic_compare_and_swap(0,1,&channel->irq_pending) == 0);
1419 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1420 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1421 rc = ccw_device_start(channel->ccwdev,
1422 &channel->ccw,(addr_t) iob, 0, 0);
1423 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1425 if (rc) {
1426 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1427 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1428 atomic_set(&channel->irq_pending, 0);
1429 wake_up(&card->wait_q);
1430 return rc;
1432 rc = wait_event_interruptible_timeout(card->wait_q,
1433 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1434 if (rc == -ERESTARTSYS)
1435 return rc;
1436 if (channel->state != CH_STATE_ACTIVATING) {
1437 PRINT_WARN("qeth: IDX activate timed out!\n");
1438 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1439 qeth_clear_cmd_buffers(channel);
1440 return -ETIME;
1442 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1445 static int
1446 qeth_peer_func_level(int level)
1448 if ((level & 0xff) == 8)
1449 return (level & 0xff) + 0x400;
1450 if (((level >> 8) & 3) == 1)
1451 return (level & 0xff) + 0x200;
1452 return level;
1455 static void
1456 qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1458 struct qeth_card *card;
1459 __u16 temp;
1461 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1463 if (channel->state == CH_STATE_DOWN) {
1464 channel->state = CH_STATE_ACTIVATING;
1465 goto out;
1467 card = CARD_FROM_CDEV(channel->ccwdev);
1469 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1470 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1471 "reply\n", CARD_WDEV_ID(card));
1472 goto out;
1474 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1475 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1476 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1477 "function level mismatch "
1478 "(sent: 0x%x, received: 0x%x)\n",
1479 CARD_WDEV_ID(card), card->info.func_level, temp);
1480 goto out;
1482 channel->state = CH_STATE_UP;
1483 out:
1484 qeth_release_buffer(channel, iob);
1487 static int
1488 qeth_check_idx_response(unsigned char *buffer)
1490 if (!buffer)
1491 return 0;
1493 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1494 if ((buffer[2] & 0xc0) == 0xc0) {
1495 PRINT_WARN("received an IDX TERMINATE "
1496 "with cause code 0x%02x%s\n",
1497 buffer[4],
1498 ((buffer[4] == 0x22) ?
1499 " -- try another portname" : ""));
1500 QETH_DBF_TEXT(trace, 2, "ckidxres");
1501 QETH_DBF_TEXT(trace, 2, " idxterm");
1502 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1503 return -EIO;
1505 return 0;
1508 static void
1509 qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1511 struct qeth_card *card;
1512 __u16 temp;
1514 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1515 if (channel->state == CH_STATE_DOWN) {
1516 channel->state = CH_STATE_ACTIVATING;
1517 goto out;
1520 card = CARD_FROM_CDEV(channel->ccwdev);
1521 if (qeth_check_idx_response(iob->data)) {
1522 goto out;
1524 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1525 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1526 "reply\n", CARD_RDEV_ID(card));
1527 goto out;
1531 * temporary fix for microcode bug
1532 * to revert it,replace OR by AND
1534 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1535 (card->info.type == QETH_CARD_TYPE_OSAE) )
1536 card->info.portname_required = 1;
1538 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1539 if (temp != qeth_peer_func_level(card->info.func_level)) {
1540 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1541 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1542 CARD_RDEV_ID(card), card->info.func_level, temp);
1543 goto out;
1545 memcpy(&card->token.issuer_rm_r,
1546 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1547 QETH_MPC_TOKEN_LENGTH);
1548 memcpy(&card->info.mcl_level[0],
1549 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1550 channel->state = CH_STATE_UP;
1551 out:
1552 qeth_release_buffer(channel,iob);
1555 static int
1556 qeth_issue_next_read(struct qeth_card *card)
1558 int rc;
1559 struct qeth_cmd_buffer *iob;
1561 QETH_DBF_TEXT(trace,5,"issnxrd");
1562 if (card->read.state != CH_STATE_UP)
1563 return -EIO;
1564 iob = qeth_get_buffer(&card->read);
1565 if (!iob) {
1566 PRINT_WARN("issue_next_read failed: no iob available!\n");
1567 return -ENOMEM;
1569 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1570 wait_event(card->wait_q,
1571 atomic_compare_and_swap(0,1,&card->read.irq_pending) == 0);
1572 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1573 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1574 (addr_t) iob, 0, 0);
1575 if (rc) {
1576 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1577 atomic_set(&card->read.irq_pending, 0);
1578 qeth_schedule_recovery(card);
1579 wake_up(&card->wait_q);
1581 return rc;
1584 static struct qeth_reply *
1585 qeth_alloc_reply(struct qeth_card *card)
1587 struct qeth_reply *reply;
1589 reply = kmalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1590 if (reply){
1591 memset(reply, 0, sizeof(struct qeth_reply));
1592 atomic_set(&reply->refcnt, 1);
1593 reply->card = card;
1595 return reply;
1598 static void
1599 qeth_get_reply(struct qeth_reply *reply)
1601 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1602 atomic_inc(&reply->refcnt);
1605 static void
1606 qeth_put_reply(struct qeth_reply *reply)
1608 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1609 if (atomic_dec_and_test(&reply->refcnt))
1610 kfree(reply);
1613 static void
1614 qeth_cmd_timeout(unsigned long data)
1616 struct qeth_reply *reply, *list_reply, *r;
1617 unsigned long flags;
1619 reply = (struct qeth_reply *) data;
1620 spin_lock_irqsave(&reply->card->lock, flags);
1621 list_for_each_entry_safe(list_reply, r,
1622 &reply->card->cmd_waiter_list, list) {
1623 if (reply == list_reply){
1624 qeth_get_reply(reply);
1625 list_del_init(&reply->list);
1626 spin_unlock_irqrestore(&reply->card->lock, flags);
1627 reply->rc = -ETIME;
1628 reply->received = 1;
1629 wake_up(&reply->wait_q);
1630 qeth_put_reply(reply);
1631 return;
1634 spin_unlock_irqrestore(&reply->card->lock, flags);
1637 static void
1638 qeth_reset_ip_addresses(struct qeth_card *card)
1640 QETH_DBF_TEXT(trace, 2, "rstipadd");
1642 qeth_clear_ip_list(card, 0, 1);
1643 /* this function will also schedule the SET_IP_THREAD */
1644 qeth_set_multicast_list(card->dev);
1647 static struct qeth_ipa_cmd *
1648 qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1650 struct qeth_ipa_cmd *cmd = NULL;
1652 QETH_DBF_TEXT(trace,5,"chkipad");
1653 if (IS_IPA(iob->data)){
1654 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1655 if (IS_IPA_REPLY(cmd))
1656 return cmd;
1657 else {
1658 switch (cmd->hdr.command) {
1659 case IPA_CMD_STOPLAN:
1660 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1661 "there is a network problem or "
1662 "someone pulled the cable or "
1663 "disabled the port.\n",
1664 QETH_CARD_IFNAME(card),
1665 card->info.chpid);
1666 card->lan_online = 0;
1667 netif_carrier_off(card->dev);
1668 return NULL;
1669 case IPA_CMD_STARTLAN:
1670 PRINT_INFO("Link reestablished on %s "
1671 "(CHPID 0x%X). Scheduling "
1672 "IP address reset.\n",
1673 QETH_CARD_IFNAME(card),
1674 card->info.chpid);
1675 card->lan_online = 1;
1676 netif_carrier_on(card->dev);
1677 qeth_reset_ip_addresses(card);
1678 return NULL;
1679 case IPA_CMD_REGISTER_LOCAL_ADDR:
1680 QETH_DBF_TEXT(trace,3, "irla");
1681 break;
1682 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1683 QETH_DBF_TEXT(trace,3, "urla");
1684 break;
1685 default:
1686 PRINT_WARN("Received data is IPA "
1687 "but not a reply!\n");
1688 break;
1692 return cmd;
1696 * wake all waiting ipa commands
1698 static void
1699 qeth_clear_ipacmd_list(struct qeth_card *card)
1701 struct qeth_reply *reply, *r;
1702 unsigned long flags;
1704 QETH_DBF_TEXT(trace, 4, "clipalst");
1706 spin_lock_irqsave(&card->lock, flags);
1707 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1708 qeth_get_reply(reply);
1709 reply->rc = -EIO;
1710 reply->received = 1;
1711 list_del_init(&reply->list);
1712 wake_up(&reply->wait_q);
1713 qeth_put_reply(reply);
1715 spin_unlock_irqrestore(&card->lock, flags);
1718 static void
1719 qeth_send_control_data_cb(struct qeth_channel *channel,
1720 struct qeth_cmd_buffer *iob)
1722 struct qeth_card *card;
1723 struct qeth_reply *reply, *r;
1724 struct qeth_ipa_cmd *cmd;
1725 unsigned long flags;
1726 int keep_reply;
1728 QETH_DBF_TEXT(trace,4,"sndctlcb");
1730 card = CARD_FROM_CDEV(channel->ccwdev);
1731 if (qeth_check_idx_response(iob->data)) {
1732 qeth_clear_ipacmd_list(card);
1733 qeth_schedule_recovery(card);
1734 goto out;
1737 cmd = qeth_check_ipa_data(card, iob);
1738 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1739 goto out;
1741 spin_lock_irqsave(&card->lock, flags);
1742 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1743 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1744 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1745 qeth_get_reply(reply);
1746 list_del_init(&reply->list);
1747 spin_unlock_irqrestore(&card->lock, flags);
1748 keep_reply = 0;
1749 if (reply->callback != NULL) {
1750 if (cmd) {
1751 reply->offset = (__u16)((char*)cmd -
1752 (char *)iob->data);
1753 keep_reply = reply->callback(card,
1754 reply,
1755 (unsigned long)cmd);
1757 else
1758 keep_reply = reply->callback(card,
1759 reply,
1760 (unsigned long)iob);
1762 if (cmd)
1763 reply->rc = (u16) cmd->hdr.return_code;
1764 else if (iob->rc)
1765 reply->rc = iob->rc;
1766 if (keep_reply) {
1767 spin_lock_irqsave(&card->lock, flags);
1768 list_add_tail(&reply->list,
1769 &card->cmd_waiter_list);
1770 spin_unlock_irqrestore(&card->lock, flags);
1771 } else {
1772 reply->received = 1;
1773 wake_up(&reply->wait_q);
1775 qeth_put_reply(reply);
1776 goto out;
1779 spin_unlock_irqrestore(&card->lock, flags);
1780 out:
1781 memcpy(&card->seqno.pdu_hdr_ack,
1782 QETH_PDU_HEADER_SEQ_NO(iob->data),
1783 QETH_SEQ_NO_LENGTH);
1784 qeth_release_buffer(channel,iob);
1787 static int
1788 qeth_send_control_data(struct qeth_card *card, int len,
1789 struct qeth_cmd_buffer *iob,
1790 int (*reply_cb)
1791 (struct qeth_card *, struct qeth_reply*, unsigned long),
1792 void *reply_param)
1795 int rc;
1796 unsigned long flags;
1797 struct qeth_reply *reply;
1798 struct timer_list timer;
1800 QETH_DBF_TEXT(trace, 2, "sendctl");
1802 qeth_setup_ccw(&card->write,iob->data,len);
1804 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1805 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1806 card->seqno.trans_hdr++;
1808 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1809 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1810 card->seqno.pdu_hdr++;
1811 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1812 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1813 iob->callback = qeth_release_buffer;
1815 reply = qeth_alloc_reply(card);
1816 if (!reply) {
1817 PRINT_WARN("Could no alloc qeth_reply!\n");
1818 return -ENOMEM;
1820 reply->callback = reply_cb;
1821 reply->param = reply_param;
1822 if (card->state == CARD_STATE_DOWN)
1823 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1824 else
1825 reply->seqno = card->seqno.ipa++;
1826 init_timer(&timer);
1827 timer.function = qeth_cmd_timeout;
1828 timer.data = (unsigned long) reply;
1829 if (IS_IPA(iob->data))
1830 timer.expires = jiffies + QETH_IPA_TIMEOUT;
1831 else
1832 timer.expires = jiffies + QETH_TIMEOUT;
1833 init_waitqueue_head(&reply->wait_q);
1834 spin_lock_irqsave(&card->lock, flags);
1835 list_add_tail(&reply->list, &card->cmd_waiter_list);
1836 spin_unlock_irqrestore(&card->lock, flags);
1837 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1838 wait_event(card->wait_q,
1839 atomic_compare_and_swap(0,1,&card->write.irq_pending) == 0);
1840 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1841 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1842 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1843 (addr_t) iob, 0, 0);
1844 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1845 if (rc){
1846 PRINT_WARN("qeth_send_control_data: "
1847 "ccw_device_start rc = %i\n", rc);
1848 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1849 spin_lock_irqsave(&card->lock, flags);
1850 list_del_init(&reply->list);
1851 qeth_put_reply(reply);
1852 spin_unlock_irqrestore(&card->lock, flags);
1853 qeth_release_buffer(iob->channel, iob);
1854 atomic_set(&card->write.irq_pending, 0);
1855 wake_up(&card->wait_q);
1856 return rc;
1858 add_timer(&timer);
1859 wait_event(reply->wait_q, reply->received);
1860 del_timer_sync(&timer);
1861 rc = reply->rc;
1862 qeth_put_reply(reply);
1863 return rc;
1866 static int
1867 qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1868 int (*reply_cb)
1869 (struct qeth_card *,struct qeth_reply*, unsigned long),
1870 void *reply_param)
1872 int rc;
1873 char prot_type;
1875 QETH_DBF_TEXT(trace,4,"sendipa");
1877 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1879 if (card->options.layer2)
1880 prot_type = QETH_PROT_LAYER2;
1881 else
1882 prot_type = QETH_PROT_TCPIP;
1884 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1885 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1886 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1888 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
1889 reply_cb, reply_param);
1890 return rc;
1894 static int
1895 qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1896 unsigned long data)
1898 struct qeth_cmd_buffer *iob;
1900 QETH_DBF_TEXT(setup, 2, "cmenblcb");
1902 iob = (struct qeth_cmd_buffer *) data;
1903 memcpy(&card->token.cm_filter_r,
1904 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
1905 QETH_MPC_TOKEN_LENGTH);
1906 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
1907 return 0;
1910 static int
1911 qeth_cm_enable(struct qeth_card *card)
1913 int rc;
1914 struct qeth_cmd_buffer *iob;
1916 QETH_DBF_TEXT(setup,2,"cmenable");
1918 iob = qeth_wait_for_buffer(&card->write);
1919 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
1920 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
1921 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1922 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
1923 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
1925 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
1926 qeth_cm_enable_cb, NULL);
1927 return rc;
1930 static int
1931 qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
1932 unsigned long data)
1935 struct qeth_cmd_buffer *iob;
1937 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
1939 iob = (struct qeth_cmd_buffer *) data;
1940 memcpy(&card->token.cm_connection_r,
1941 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
1942 QETH_MPC_TOKEN_LENGTH);
1943 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
1944 return 0;
1947 static int
1948 qeth_cm_setup(struct qeth_card *card)
1950 int rc;
1951 struct qeth_cmd_buffer *iob;
1953 QETH_DBF_TEXT(setup,2,"cmsetup");
1955 iob = qeth_wait_for_buffer(&card->write);
1956 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
1957 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
1958 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1959 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
1960 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
1961 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
1962 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
1963 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
1964 qeth_cm_setup_cb, NULL);
1965 return rc;
1969 static int
1970 qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1971 unsigned long data)
1974 __u16 mtu, framesize;
1975 __u16 len;
1976 __u8 link_type;
1977 struct qeth_cmd_buffer *iob;
1979 QETH_DBF_TEXT(setup, 2, "ulpenacb");
1981 iob = (struct qeth_cmd_buffer *) data;
1982 memcpy(&card->token.ulp_filter_r,
1983 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
1984 QETH_MPC_TOKEN_LENGTH);
1985 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
1986 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
1987 mtu = qeth_get_mtu_outof_framesize(framesize);
1988 if (!mtu) {
1989 iob->rc = -EINVAL;
1990 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
1991 return 0;
1993 card->info.max_mtu = mtu;
1994 card->info.initial_mtu = mtu;
1995 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
1996 } else {
1997 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
1998 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
1999 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2002 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2003 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2004 memcpy(&link_type,
2005 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2006 card->info.link_type = link_type;
2007 } else
2008 card->info.link_type = 0;
2009 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2010 return 0;
2013 static int
2014 qeth_ulp_enable(struct qeth_card *card)
2016 int rc;
2017 char prot_type;
2018 struct qeth_cmd_buffer *iob;
2020 /*FIXME: trace view callbacks*/
2021 QETH_DBF_TEXT(setup,2,"ulpenabl");
2023 iob = qeth_wait_for_buffer(&card->write);
2024 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2026 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2027 (__u8) card->info.portno;
2028 if (card->options.layer2)
2029 prot_type = QETH_PROT_LAYER2;
2030 else
2031 prot_type = QETH_PROT_TCPIP;
2033 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2034 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2035 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2036 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2037 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2038 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2039 card->info.portname, 9);
2040 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2041 qeth_ulp_enable_cb, NULL);
2042 return rc;
2046 static inline __u16
2047 __raw_devno_from_bus_id(char *id)
2049 id += (strlen(id) - 4);
2050 return (__u16) simple_strtoul(id, &id, 16);
2053 static int
2054 qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2055 unsigned long data)
2057 struct qeth_cmd_buffer *iob;
2059 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2061 iob = (struct qeth_cmd_buffer *) data;
2062 memcpy(&card->token.ulp_connection_r,
2063 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2064 QETH_MPC_TOKEN_LENGTH);
2065 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2066 return 0;
2069 static int
2070 qeth_ulp_setup(struct qeth_card *card)
2072 int rc;
2073 __u16 temp;
2074 struct qeth_cmd_buffer *iob;
2076 QETH_DBF_TEXT(setup,2,"ulpsetup");
2078 iob = qeth_wait_for_buffer(&card->write);
2079 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2081 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2082 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2083 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2084 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2085 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2086 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2088 temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card));
2089 memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2);
2090 temp = (card->info.cula << 8) + card->info.unit_addr2;
2091 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2092 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2093 qeth_ulp_setup_cb, NULL);
2094 return rc;
2097 static inline int
2098 qeth_check_for_inbound_error(struct qeth_qdio_buffer *buf,
2099 unsigned int qdio_error,
2100 unsigned int siga_error)
2102 int rc = 0;
2104 if (qdio_error || siga_error) {
2105 QETH_DBF_TEXT(trace, 2, "qdinerr");
2106 QETH_DBF_TEXT(qerr, 2, "qdinerr");
2107 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
2108 buf->buffer->element[15].flags & 0xff);
2109 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
2110 buf->buffer->element[14].flags & 0xff);
2111 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2112 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
2113 rc = 1;
2115 return rc;
2118 static inline struct sk_buff *
2119 qeth_get_skb(unsigned int length)
2121 struct sk_buff* skb;
2122 #ifdef CONFIG_QETH_VLAN
2123 if ((skb = dev_alloc_skb(length + VLAN_HLEN)))
2124 skb_reserve(skb, VLAN_HLEN);
2125 #else
2126 skb = dev_alloc_skb(length);
2127 #endif
2128 return skb;
2131 static inline struct sk_buff *
2132 qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2133 struct qdio_buffer_element **__element, int *__offset,
2134 struct qeth_hdr **hdr)
2136 struct qdio_buffer_element *element = *__element;
2137 int offset = *__offset;
2138 struct sk_buff *skb = NULL;
2139 int skb_len;
2140 void *data_ptr;
2141 int data_len;
2143 QETH_DBF_TEXT(trace,6,"nextskb");
2144 /* qeth_hdr must not cross element boundaries */
2145 if (element->length < offset + sizeof(struct qeth_hdr)){
2146 if (qeth_is_last_sbale(element))
2147 return NULL;
2148 element++;
2149 offset = 0;
2150 if (element->length < sizeof(struct qeth_hdr))
2151 return NULL;
2153 *hdr = element->addr + offset;
2155 offset += sizeof(struct qeth_hdr);
2156 if (card->options.layer2)
2157 skb_len = (*hdr)->hdr.l2.pkt_length;
2158 else
2159 skb_len = (*hdr)->hdr.l3.length;
2161 if (!skb_len)
2162 return NULL;
2163 if (card->options.fake_ll){
2164 if(card->dev->type == ARPHRD_IEEE802_TR){
2165 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR)))
2166 goto no_mem;
2167 skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2168 } else {
2169 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH)))
2170 goto no_mem;
2171 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2173 } else if (!(skb = qeth_get_skb(skb_len)))
2174 goto no_mem;
2175 data_ptr = element->addr + offset;
2176 while (skb_len) {
2177 data_len = min(skb_len, (int)(element->length - offset));
2178 if (data_len)
2179 memcpy(skb_put(skb, data_len), data_ptr, data_len);
2180 skb_len -= data_len;
2181 if (skb_len){
2182 if (qeth_is_last_sbale(element)){
2183 QETH_DBF_TEXT(trace,4,"unexeob");
2184 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2185 QETH_DBF_TEXT(qerr,2,"unexeob");
2186 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2187 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2188 dev_kfree_skb_any(skb);
2189 card->stats.rx_errors++;
2190 return NULL;
2192 element++;
2193 offset = 0;
2194 data_ptr = element->addr;
2195 } else {
2196 offset += data_len;
2199 *__element = element;
2200 *__offset = offset;
2201 return skb;
2202 no_mem:
2203 if (net_ratelimit()){
2204 PRINT_WARN("No memory for packet received on %s.\n",
2205 QETH_CARD_IFNAME(card));
2206 QETH_DBF_TEXT(trace,2,"noskbmem");
2207 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2209 card->stats.rx_dropped++;
2210 return NULL;
2213 static inline __be16
2214 qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2216 struct qeth_card *card;
2217 struct ethhdr *eth;
2219 QETH_DBF_TEXT(trace,6,"typtrans");
2221 card = (struct qeth_card *)dev->priv;
2222 #ifdef CONFIG_TR
2223 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2224 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2225 return tr_type_trans(skb,dev);
2226 #endif /* CONFIG_TR */
2227 skb->mac.raw = skb->data;
2228 skb_pull(skb, ETH_HLEN );
2229 eth = eth_hdr(skb);
2231 if (*eth->h_dest & 1) {
2232 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2233 skb->pkt_type = PACKET_BROADCAST;
2234 else
2235 skb->pkt_type = PACKET_MULTICAST;
2236 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2237 skb->pkt_type = PACKET_OTHERHOST;
2239 if (ntohs(eth->h_proto) >= 1536)
2240 return eth->h_proto;
2241 if (*(unsigned short *) (skb->data) == 0xFFFF)
2242 return htons(ETH_P_802_3);
2243 return htons(ETH_P_802_2);
2246 static inline void
2247 qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2248 struct qeth_hdr *hdr)
2250 struct trh_hdr *fake_hdr;
2251 struct trllc *fake_llc;
2252 struct iphdr *ip_hdr;
2254 QETH_DBF_TEXT(trace,5,"skbfktr");
2255 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_TR;
2256 /* this is a fake ethernet header */
2257 fake_hdr = (struct trh_hdr *) skb->mac.raw;
2259 /* the destination MAC address */
2260 switch (skb->pkt_type){
2261 case PACKET_MULTICAST:
2262 switch (skb->protocol){
2263 #ifdef CONFIG_QETH_IPV6
2264 case __constant_htons(ETH_P_IPV6):
2265 ndisc_mc_map((struct in6_addr *)
2266 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2267 fake_hdr->daddr, card->dev, 0);
2268 break;
2269 #endif /* CONFIG_QETH_IPV6 */
2270 case __constant_htons(ETH_P_IP):
2271 ip_hdr = (struct iphdr *)skb->data;
2272 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2273 break;
2274 default:
2275 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2277 break;
2278 case PACKET_BROADCAST:
2279 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2280 break;
2281 default:
2282 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2284 /* the source MAC address */
2285 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2286 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2287 else
2288 memset(fake_hdr->saddr, 0, TR_ALEN);
2289 fake_hdr->rcf=0;
2290 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2291 fake_llc->dsap = EXTENDED_SAP;
2292 fake_llc->ssap = EXTENDED_SAP;
2293 fake_llc->llc = UI_CMD;
2294 fake_llc->protid[0] = 0;
2295 fake_llc->protid[1] = 0;
2296 fake_llc->protid[2] = 0;
2297 fake_llc->ethertype = ETH_P_IP;
2300 static inline void
2301 qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
2302 struct qeth_hdr *hdr)
2304 struct ethhdr *fake_hdr;
2305 struct iphdr *ip_hdr;
2307 QETH_DBF_TEXT(trace,5,"skbfketh");
2308 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_ETH;
2309 /* this is a fake ethernet header */
2310 fake_hdr = (struct ethhdr *) skb->mac.raw;
2312 /* the destination MAC address */
2313 switch (skb->pkt_type){
2314 case PACKET_MULTICAST:
2315 switch (skb->protocol){
2316 #ifdef CONFIG_QETH_IPV6
2317 case __constant_htons(ETH_P_IPV6):
2318 ndisc_mc_map((struct in6_addr *)
2319 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2320 fake_hdr->h_dest, card->dev, 0);
2321 break;
2322 #endif /* CONFIG_QETH_IPV6 */
2323 case __constant_htons(ETH_P_IP):
2324 ip_hdr = (struct iphdr *)skb->data;
2325 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
2326 break;
2327 default:
2328 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2330 break;
2331 case PACKET_BROADCAST:
2332 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2333 break;
2334 default:
2335 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2337 /* the source MAC address */
2338 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2339 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2340 else
2341 memset(fake_hdr->h_source, 0, ETH_ALEN);
2342 /* the protocol */
2343 fake_hdr->h_proto = skb->protocol;
2346 static inline void
2347 qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2348 struct qeth_hdr *hdr)
2350 if (card->dev->type == ARPHRD_IEEE802_TR)
2351 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2352 else
2353 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2356 static inline void
2357 qeth_rebuild_skb_vlan(struct qeth_card *card, struct sk_buff *skb,
2358 struct qeth_hdr *hdr)
2360 #ifdef CONFIG_QETH_VLAN
2361 u16 *vlan_tag;
2363 if (hdr->hdr.l3.ext_flags &
2364 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2365 vlan_tag = (u16 *) skb_push(skb, VLAN_HLEN);
2366 *vlan_tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2367 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2368 *(vlan_tag + 1) = skb->protocol;
2369 skb->protocol = __constant_htons(ETH_P_8021Q);
2371 #endif /* CONFIG_QETH_VLAN */
2374 static inline __u16
2375 qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2376 struct qeth_hdr *hdr)
2378 unsigned short vlan_id = 0;
2379 #ifdef CONFIG_QETH_VLAN
2380 struct vlan_hdr *vhdr;
2381 #endif
2383 skb->pkt_type = PACKET_HOST;
2384 skb->protocol = qeth_type_trans(skb, skb->dev);
2385 if (card->options.checksum_type == NO_CHECKSUMMING)
2386 skb->ip_summed = CHECKSUM_UNNECESSARY;
2387 else
2388 skb->ip_summed = CHECKSUM_NONE;
2389 #ifdef CONFIG_QETH_VLAN
2390 if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) {
2391 vhdr = (struct vlan_hdr *) skb->data;
2392 skb->protocol =
2393 __constant_htons(vhdr->h_vlan_encapsulated_proto);
2394 vlan_id = hdr->hdr.l2.vlan_id;
2395 skb_pull(skb, VLAN_HLEN);
2397 #endif
2398 return vlan_id;
2401 static inline void
2402 qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2403 struct qeth_hdr *hdr)
2405 #ifdef CONFIG_QETH_IPV6
2406 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2407 skb->pkt_type = PACKET_HOST;
2408 skb->protocol = qeth_type_trans(skb, card->dev);
2409 return;
2411 #endif /* CONFIG_QETH_IPV6 */
2412 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2413 ETH_P_IP);
2414 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2415 case QETH_CAST_UNICAST:
2416 skb->pkt_type = PACKET_HOST;
2417 break;
2418 case QETH_CAST_MULTICAST:
2419 skb->pkt_type = PACKET_MULTICAST;
2420 card->stats.multicast++;
2421 break;
2422 case QETH_CAST_BROADCAST:
2423 skb->pkt_type = PACKET_BROADCAST;
2424 card->stats.multicast++;
2425 break;
2426 case QETH_CAST_ANYCAST:
2427 case QETH_CAST_NOCAST:
2428 default:
2429 skb->pkt_type = PACKET_HOST;
2431 qeth_rebuild_skb_vlan(card, skb, hdr);
2432 if (card->options.fake_ll)
2433 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2434 else
2435 skb->mac.raw = skb->data;
2436 skb->ip_summed = card->options.checksum_type;
2437 if (card->options.checksum_type == HW_CHECKSUMMING){
2438 if ( (hdr->hdr.l3.ext_flags &
2439 (QETH_HDR_EXT_CSUM_HDR_REQ |
2440 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2441 (QETH_HDR_EXT_CSUM_HDR_REQ |
2442 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2443 skb->ip_summed = CHECKSUM_UNNECESSARY;
2444 else
2445 skb->ip_summed = SW_CHECKSUMMING;
2449 static inline void
2450 qeth_process_inbound_buffer(struct qeth_card *card,
2451 struct qeth_qdio_buffer *buf, int index)
2453 struct qdio_buffer_element *element;
2454 struct sk_buff *skb;
2455 struct qeth_hdr *hdr;
2456 int offset;
2457 int rxrc;
2458 __u16 vlan_tag = 0;
2460 /* get first element of current buffer */
2461 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2462 offset = 0;
2463 #ifdef CONFIG_QETH_PERF_STATS
2464 card->perf_stats.bufs_rec++;
2465 #endif
2466 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2467 &offset, &hdr))) {
2468 skb->dev = card->dev;
2469 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2470 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr);
2471 else
2472 qeth_rebuild_skb(card, skb, hdr);
2473 /* is device UP ? */
2474 if (!(card->dev->flags & IFF_UP)){
2475 dev_kfree_skb_any(skb);
2476 continue;
2478 #ifdef CONFIG_QETH_VLAN
2479 if (vlan_tag)
2480 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2481 else
2482 #endif
2483 rxrc = netif_rx(skb);
2484 card->dev->last_rx = jiffies;
2485 card->stats.rx_packets++;
2486 card->stats.rx_bytes += skb->len;
2490 static inline struct qeth_buffer_pool_entry *
2491 qeth_get_buffer_pool_entry(struct qeth_card *card)
2493 struct qeth_buffer_pool_entry *entry;
2495 QETH_DBF_TEXT(trace, 6, "gtbfplen");
2496 if (!list_empty(&card->qdio.in_buf_pool.entry_list)) {
2497 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2498 struct qeth_buffer_pool_entry, list);
2499 list_del_init(&entry->list);
2500 return entry;
2502 return NULL;
2505 static inline void
2506 qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2508 struct qeth_buffer_pool_entry *pool_entry;
2509 int i;
2511 pool_entry = qeth_get_buffer_pool_entry(card);
2513 * since the buffer is accessed only from the input_tasklet
2514 * there shouldn't be a need to synchronize; also, since we use
2515 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2516 * buffers
2518 BUG_ON(!pool_entry);
2520 buf->pool_entry = pool_entry;
2521 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2522 buf->buffer->element[i].length = PAGE_SIZE;
2523 buf->buffer->element[i].addr = pool_entry->elements[i];
2524 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2525 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2526 else
2527 buf->buffer->element[i].flags = 0;
2529 buf->state = QETH_QDIO_BUF_EMPTY;
2532 static inline void
2533 qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2534 struct qeth_qdio_out_buffer *buf)
2536 int i;
2537 struct sk_buff *skb;
2539 /* is PCI flag set on buffer? */
2540 if (buf->buffer->element[0].flags & 0x40)
2541 atomic_dec(&queue->set_pci_flags_count);
2543 while ((skb = skb_dequeue(&buf->skb_list))){
2544 atomic_dec(&skb->users);
2545 dev_kfree_skb_any(skb);
2547 qeth_eddp_buf_release_contexts(buf);
2548 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2549 buf->buffer->element[i].length = 0;
2550 buf->buffer->element[i].addr = NULL;
2551 buf->buffer->element[i].flags = 0;
2553 buf->next_element_to_fill = 0;
2554 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2557 static inline void
2558 qeth_queue_input_buffer(struct qeth_card *card, int index)
2560 struct qeth_qdio_q *queue = card->qdio.in_q;
2561 int count;
2562 int i;
2563 int rc;
2565 QETH_DBF_TEXT(trace,6,"queinbuf");
2566 count = (index < queue->next_buf_to_init)?
2567 card->qdio.in_buf_pool.buf_count -
2568 (queue->next_buf_to_init - index) :
2569 card->qdio.in_buf_pool.buf_count -
2570 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2571 /* only requeue at a certain threshold to avoid SIGAs */
2572 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2573 for (i = queue->next_buf_to_init;
2574 i < queue->next_buf_to_init + count; ++i)
2575 qeth_init_input_buffer(card,
2576 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]);
2578 * according to old code it should be avoided to requeue all
2579 * 128 buffers in order to benefit from PCI avoidance.
2580 * this function keeps at least one buffer (the buffer at
2581 * 'index') un-requeued -> this buffer is the first buffer that
2582 * will be requeued the next time
2584 #ifdef CONFIG_QETH_PERF_STATS
2585 card->perf_stats.inbound_do_qdio_cnt++;
2586 card->perf_stats.inbound_do_qdio_start_time = qeth_get_micros();
2587 #endif
2588 rc = do_QDIO(CARD_DDEV(card),
2589 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2590 0, queue->next_buf_to_init, count, NULL);
2591 #ifdef CONFIG_QETH_PERF_STATS
2592 card->perf_stats.inbound_do_qdio_time += qeth_get_micros() -
2593 card->perf_stats.inbound_do_qdio_start_time;
2594 #endif
2595 if (rc){
2596 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2597 "return %i (device %s).\n",
2598 rc, CARD_DDEV_ID(card));
2599 QETH_DBF_TEXT(trace,2,"qinberr");
2600 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2602 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2603 QDIO_MAX_BUFFERS_PER_Q;
2607 static inline void
2608 qeth_put_buffer_pool_entry(struct qeth_card *card,
2609 struct qeth_buffer_pool_entry *entry)
2611 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2612 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2615 static void
2616 qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2617 unsigned int qdio_err, unsigned int siga_err,
2618 unsigned int queue, int first_element, int count,
2619 unsigned long card_ptr)
2621 struct net_device *net_dev;
2622 struct qeth_card *card;
2623 struct qeth_qdio_buffer *buffer;
2624 int index;
2625 int i;
2627 QETH_DBF_TEXT(trace, 6, "qdinput");
2628 card = (struct qeth_card *) card_ptr;
2629 net_dev = card->dev;
2630 #ifdef CONFIG_QETH_PERF_STATS
2631 card->perf_stats.inbound_cnt++;
2632 card->perf_stats.inbound_start_time = qeth_get_micros();
2633 #endif
2634 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2635 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2636 QETH_DBF_TEXT(trace, 1,"qdinchk");
2637 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2638 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2639 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2640 qeth_schedule_recovery(card);
2641 return;
2644 for (i = first_element; i < (first_element + count); ++i) {
2645 index = i % QDIO_MAX_BUFFERS_PER_Q;
2646 buffer = &card->qdio.in_q->bufs[index];
2647 if (!((status == QDIO_STATUS_LOOK_FOR_ERROR) &&
2648 qeth_check_for_inbound_error(buffer, qdio_err, siga_err)))
2649 qeth_process_inbound_buffer(card, buffer, index);
2650 /* clear buffer and give back to hardware */
2651 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2652 qeth_queue_input_buffer(card, index);
2654 #ifdef CONFIG_QETH_PERF_STATS
2655 card->perf_stats.inbound_time += qeth_get_micros() -
2656 card->perf_stats.inbound_start_time;
2657 #endif
2660 static inline int
2661 qeth_handle_send_error(struct qeth_card *card,
2662 struct qeth_qdio_out_buffer *buffer,
2663 int qdio_err, int siga_err)
2665 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2666 int cc = siga_err & 3;
2668 QETH_DBF_TEXT(trace, 6, "hdsnderr");
2669 switch (cc) {
2670 case 0:
2671 if (qdio_err){
2672 QETH_DBF_TEXT(trace, 1,"lnkfail");
2673 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2674 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2675 (u16)qdio_err, (u8)sbalf15);
2676 return QETH_SEND_ERROR_LINK_FAILURE;
2678 return QETH_SEND_ERROR_NONE;
2679 case 2:
2680 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2681 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2682 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2683 return QETH_SEND_ERROR_KICK_IT;
2685 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2686 return QETH_SEND_ERROR_RETRY;
2687 return QETH_SEND_ERROR_LINK_FAILURE;
2688 /* look at qdio_error and sbalf 15 */
2689 case 1:
2690 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2691 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2692 return QETH_SEND_ERROR_LINK_FAILURE;
2693 case 3:
2694 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2695 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2696 return QETH_SEND_ERROR_KICK_IT;
2698 return QETH_SEND_ERROR_LINK_FAILURE;
2701 void
2702 qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2703 int index, int count)
2705 struct qeth_qdio_out_buffer *buf;
2706 int rc;
2707 int i;
2709 QETH_DBF_TEXT(trace, 6, "flushbuf");
2711 for (i = index; i < index + count; ++i) {
2712 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2713 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2714 SBAL_FLAGS_LAST_ENTRY;
2716 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2717 continue;
2719 if (!queue->do_pack){
2720 if ((atomic_read(&queue->used_buffers) >=
2721 (QETH_HIGH_WATERMARK_PACK -
2722 QETH_WATERMARK_PACK_FUZZ)) &&
2723 !atomic_read(&queue->set_pci_flags_count)){
2724 /* it's likely that we'll go to packing
2725 * mode soon */
2726 atomic_inc(&queue->set_pci_flags_count);
2727 buf->buffer->element[0].flags |= 0x40;
2729 } else {
2730 if (!atomic_read(&queue->set_pci_flags_count)){
2732 * there's no outstanding PCI any more, so we
2733 * have to request a PCI to be sure the the PCI
2734 * will wake at some time in the future then we
2735 * can flush packed buffers that might still be
2736 * hanging around, which can happen if no
2737 * further send was requested by the stack
2739 atomic_inc(&queue->set_pci_flags_count);
2740 buf->buffer->element[0].flags |= 0x40;
2745 queue->card->dev->trans_start = jiffies;
2746 #ifdef CONFIG_QETH_PERF_STATS
2747 queue->card->perf_stats.outbound_do_qdio_cnt++;
2748 queue->card->perf_stats.outbound_do_qdio_start_time = qeth_get_micros();
2749 #endif
2750 if (under_int)
2751 rc = do_QDIO(CARD_DDEV(queue->card),
2752 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT,
2753 queue->queue_no, index, count, NULL);
2754 else
2755 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT,
2756 queue->queue_no, index, count, NULL);
2757 #ifdef CONFIG_QETH_PERF_STATS
2758 queue->card->perf_stats.outbound_do_qdio_time += qeth_get_micros() -
2759 queue->card->perf_stats.outbound_do_qdio_start_time;
2760 #endif
2761 if (rc){
2762 QETH_DBF_SPRINTF(trace, 0, "qeth_flush_buffers: do_QDIO "
2763 "returned error (%i) on device %s.",
2764 rc, CARD_DDEV_ID(queue->card));
2765 QETH_DBF_TEXT(trace, 2, "flushbuf");
2766 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
2767 queue->card->stats.tx_errors += count;
2768 /* this must not happen under normal circumstances. if it
2769 * happens something is really wrong -> recover */
2770 qeth_schedule_recovery(queue->card);
2771 return;
2773 atomic_add(count, &queue->used_buffers);
2774 #ifdef CONFIG_QETH_PERF_STATS
2775 queue->card->perf_stats.bufs_sent += count;
2776 #endif
2780 * Switched to packing state if the number of used buffers on a queue
2781 * reaches a certain limit.
2783 static inline void
2784 qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2786 if (!queue->do_pack) {
2787 if (atomic_read(&queue->used_buffers)
2788 >= QETH_HIGH_WATERMARK_PACK){
2789 /* switch non-PACKING -> PACKING */
2790 QETH_DBF_TEXT(trace, 6, "np->pack");
2791 #ifdef CONFIG_QETH_PERF_STATS
2792 queue->card->perf_stats.sc_dp_p++;
2793 #endif
2794 queue->do_pack = 1;
2800 * Switches from packing to non-packing mode. If there is a packing
2801 * buffer on the queue this buffer will be prepared to be flushed.
2802 * In that case 1 is returned to inform the caller. If no buffer
2803 * has to be flushed, zero is returned.
2805 static inline int
2806 qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2808 struct qeth_qdio_out_buffer *buffer;
2809 int flush_count = 0;
2811 if (queue->do_pack) {
2812 if (atomic_read(&queue->used_buffers)
2813 <= QETH_LOW_WATERMARK_PACK) {
2814 /* switch PACKING -> non-PACKING */
2815 QETH_DBF_TEXT(trace, 6, "pack->np");
2816 #ifdef CONFIG_QETH_PERF_STATS
2817 queue->card->perf_stats.sc_p_dp++;
2818 #endif
2819 queue->do_pack = 0;
2820 /* flush packing buffers */
2821 buffer = &queue->bufs[queue->next_buf_to_fill];
2822 if ((atomic_read(&buffer->state) ==
2823 QETH_QDIO_BUF_EMPTY) &&
2824 (buffer->next_element_to_fill > 0)) {
2825 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
2826 flush_count++;
2827 queue->next_buf_to_fill =
2828 (queue->next_buf_to_fill + 1) %
2829 QDIO_MAX_BUFFERS_PER_Q;
2833 return flush_count;
2837 * Called to flush a packing buffer if no more pci flags are on the queue.
2838 * Checks if there is a packing buffer and prepares it to be flushed.
2839 * In that case returns 1, otherwise zero.
2841 static inline int
2842 qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2844 struct qeth_qdio_out_buffer *buffer;
2846 buffer = &queue->bufs[queue->next_buf_to_fill];
2847 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2848 (buffer->next_element_to_fill > 0)){
2849 /* it's a packing buffer */
2850 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2851 queue->next_buf_to_fill =
2852 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2853 return 1;
2855 return 0;
2858 static inline void
2859 qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2861 int index;
2862 int flush_cnt = 0;
2863 int q_was_packing = 0;
2866 * check if weed have to switch to non-packing mode or if
2867 * we have to get a pci flag out on the queue
2869 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2870 !atomic_read(&queue->set_pci_flags_count)){
2871 if (atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2872 QETH_OUT_Q_UNLOCKED) {
2874 * If we get in here, there was no action in
2875 * do_send_packet. So, we check if there is a
2876 * packing buffer to be flushed here.
2878 netif_stop_queue(queue->card->dev);
2879 index = queue->next_buf_to_fill;
2880 q_was_packing = queue->do_pack;
2881 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
2882 if (!flush_cnt &&
2883 !atomic_read(&queue->set_pci_flags_count))
2884 flush_cnt +=
2885 qeth_flush_buffers_on_no_pci(queue);
2886 #ifdef CONFIG_QETH_PERF_STATS
2887 if (q_was_packing)
2888 queue->card->perf_stats.bufs_sent_pack +=
2889 flush_cnt;
2890 #endif
2891 if (flush_cnt)
2892 qeth_flush_buffers(queue, 1, index, flush_cnt);
2893 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
2898 static void
2899 qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
2900 unsigned int qdio_error, unsigned int siga_error,
2901 unsigned int __queue, int first_element, int count,
2902 unsigned long card_ptr)
2904 struct qeth_card *card = (struct qeth_card *) card_ptr;
2905 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
2906 struct qeth_qdio_out_buffer *buffer;
2907 int i;
2909 QETH_DBF_TEXT(trace, 6, "qdouhdl");
2910 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2911 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2912 QETH_DBF_SPRINTF(trace, 2, "On device %s: "
2913 "received active check "
2914 "condition (0x%08x).",
2915 CARD_BUS_ID(card), status);
2916 QETH_DBF_TEXT(trace, 2, "chkcond");
2917 QETH_DBF_TEXT_(trace, 2, "%08x", status);
2918 netif_stop_queue(card->dev);
2919 qeth_schedule_recovery(card);
2920 return;
2923 #ifdef CONFIG_QETH_PERF_STATS
2924 card->perf_stats.outbound_handler_cnt++;
2925 card->perf_stats.outbound_handler_start_time = qeth_get_micros();
2926 #endif
2927 for(i = first_element; i < (first_element + count); ++i){
2928 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2929 /*we only handle the KICK_IT error by doing a recovery */
2930 if (qeth_handle_send_error(card, buffer, qdio_error, siga_error)
2931 == QETH_SEND_ERROR_KICK_IT){
2932 netif_stop_queue(card->dev);
2933 qeth_schedule_recovery(card);
2934 return;
2936 qeth_clear_output_buffer(queue, buffer);
2938 atomic_sub(count, &queue->used_buffers);
2939 /* check if we need to do something on this outbound queue */
2940 if (card->info.type != QETH_CARD_TYPE_IQD)
2941 qeth_check_outbound_queue(queue);
2943 netif_wake_queue(queue->card->dev);
2944 #ifdef CONFIG_QETH_PERF_STATS
2945 card->perf_stats.outbound_handler_time += qeth_get_micros() -
2946 card->perf_stats.outbound_handler_start_time;
2947 #endif
2950 static void
2951 qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
2954 param_field[0] = _ascebc['P'];
2955 param_field[1] = _ascebc['C'];
2956 param_field[2] = _ascebc['I'];
2957 param_field[3] = _ascebc['T'];
2958 *((unsigned int *) (&param_field[4])) = QETH_PCI_THRESHOLD_A(card);
2959 *((unsigned int *) (&param_field[8])) = QETH_PCI_THRESHOLD_B(card);
2960 *((unsigned int *) (&param_field[12])) = QETH_PCI_TIMER_VALUE(card);
2963 static void
2964 qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
2966 param_field[16] = _ascebc['B'];
2967 param_field[17] = _ascebc['L'];
2968 param_field[18] = _ascebc['K'];
2969 param_field[19] = _ascebc['T'];
2970 *((unsigned int *) (&param_field[20])) = card->info.blkt.time_total;
2971 *((unsigned int *) (&param_field[24])) = card->info.blkt.inter_packet;
2972 *((unsigned int *) (&param_field[28])) = card->info.blkt.inter_packet_jumbo;
2975 static void
2976 qeth_initialize_working_pool_list(struct qeth_card *card)
2978 struct qeth_buffer_pool_entry *entry;
2980 QETH_DBF_TEXT(trace,5,"inwrklst");
2982 list_for_each_entry(entry,
2983 &card->qdio.init_pool.entry_list, init_list) {
2984 qeth_put_buffer_pool_entry(card,entry);
2988 static void
2989 qeth_clear_working_pool_list(struct qeth_card *card)
2991 struct qeth_buffer_pool_entry *pool_entry, *tmp;
2993 QETH_DBF_TEXT(trace,5,"clwrklst");
2994 list_for_each_entry_safe(pool_entry, tmp,
2995 &card->qdio.in_buf_pool.entry_list, list){
2996 list_del(&pool_entry->list);
3000 static void
3001 qeth_free_buffer_pool(struct qeth_card *card)
3003 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3004 int i=0;
3005 QETH_DBF_TEXT(trace,5,"freepool");
3006 list_for_each_entry_safe(pool_entry, tmp,
3007 &card->qdio.init_pool.entry_list, init_list){
3008 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3009 free_page((unsigned long)pool_entry->elements[i]);
3010 list_del(&pool_entry->init_list);
3011 kfree(pool_entry);
3015 static int
3016 qeth_alloc_buffer_pool(struct qeth_card *card)
3018 struct qeth_buffer_pool_entry *pool_entry;
3019 void *ptr;
3020 int i, j;
3022 QETH_DBF_TEXT(trace,5,"alocpool");
3023 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3024 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3025 if (!pool_entry){
3026 qeth_free_buffer_pool(card);
3027 return -ENOMEM;
3029 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
3030 ptr = (void *) __get_free_page(GFP_KERNEL);
3031 if (!ptr) {
3032 while (j > 0)
3033 free_page((unsigned long)
3034 pool_entry->elements[--j]);
3035 kfree(pool_entry);
3036 qeth_free_buffer_pool(card);
3037 return -ENOMEM;
3039 pool_entry->elements[j] = ptr;
3041 list_add(&pool_entry->init_list,
3042 &card->qdio.init_pool.entry_list);
3044 return 0;
3048 qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3050 QETH_DBF_TEXT(trace, 2, "realcbp");
3052 if ((card->state != CARD_STATE_DOWN) &&
3053 (card->state != CARD_STATE_RECOVER))
3054 return -EPERM;
3056 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3057 qeth_clear_working_pool_list(card);
3058 qeth_free_buffer_pool(card);
3059 card->qdio.in_buf_pool.buf_count = bufcnt;
3060 card->qdio.init_pool.buf_count = bufcnt;
3061 return qeth_alloc_buffer_pool(card);
3064 static int
3065 qeth_alloc_qdio_buffers(struct qeth_card *card)
3067 int i, j;
3069 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3071 if (card->qdio.state == QETH_QDIO_ALLOCATED)
3072 return 0;
3074 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q), GFP_KERNEL);
3075 if (!card->qdio.in_q)
3076 return - ENOMEM;
3077 QETH_DBF_TEXT(setup, 2, "inq");
3078 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3079 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3080 /* give inbound qeth_qdio_buffers their qdio_buffers */
3081 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3082 card->qdio.in_q->bufs[i].buffer =
3083 &card->qdio.in_q->qdio_bufs[i];
3084 /* inbound buffer pool */
3085 if (qeth_alloc_buffer_pool(card)){
3086 kfree(card->qdio.in_q);
3087 return -ENOMEM;
3089 /* outbound */
3090 card->qdio.out_qs =
3091 kmalloc(card->qdio.no_out_queues *
3092 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3093 if (!card->qdio.out_qs){
3094 qeth_free_buffer_pool(card);
3095 return -ENOMEM;
3097 for (i = 0; i < card->qdio.no_out_queues; ++i){
3098 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3099 GFP_KERNEL);
3100 if (!card->qdio.out_qs[i]){
3101 while (i > 0)
3102 kfree(card->qdio.out_qs[--i]);
3103 kfree(card->qdio.out_qs);
3104 return -ENOMEM;
3106 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3107 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3108 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3109 card->qdio.out_qs[i]->queue_no = i;
3110 /* give outbound qeth_qdio_buffers their qdio_buffers */
3111 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3112 card->qdio.out_qs[i]->bufs[j].buffer =
3113 &card->qdio.out_qs[i]->qdio_bufs[j];
3114 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3115 skb_list);
3116 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3119 card->qdio.state = QETH_QDIO_ALLOCATED;
3120 return 0;
3123 static void
3124 qeth_free_qdio_buffers(struct qeth_card *card)
3126 int i, j;
3128 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3129 if (card->qdio.state == QETH_QDIO_UNINITIALIZED)
3130 return;
3131 kfree(card->qdio.in_q);
3132 /* inbound buffer pool */
3133 qeth_free_buffer_pool(card);
3134 /* free outbound qdio_qs */
3135 for (i = 0; i < card->qdio.no_out_queues; ++i){
3136 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3137 qeth_clear_output_buffer(card->qdio.out_qs[i],
3138 &card->qdio.out_qs[i]->bufs[j]);
3139 kfree(card->qdio.out_qs[i]);
3141 kfree(card->qdio.out_qs);
3142 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3145 static void
3146 qeth_clear_qdio_buffers(struct qeth_card *card)
3148 int i, j;
3150 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3151 /* clear outbound buffers to free skbs */
3152 for (i = 0; i < card->qdio.no_out_queues; ++i)
3153 if (card->qdio.out_qs[i]){
3154 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3155 qeth_clear_output_buffer(card->qdio.out_qs[i],
3156 &card->qdio.out_qs[i]->bufs[j]);
3160 static void
3161 qeth_init_qdio_info(struct qeth_card *card)
3163 QETH_DBF_TEXT(setup, 4, "intqdinf");
3164 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3165 /* inbound */
3166 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3167 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3168 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3169 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3170 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3171 /* outbound */
3172 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
3173 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
3176 static int
3177 qeth_init_qdio_queues(struct qeth_card *card)
3179 int i, j;
3180 int rc;
3182 QETH_DBF_TEXT(setup, 2, "initqdqs");
3184 /* inbound queue */
3185 memset(card->qdio.in_q->qdio_bufs, 0,
3186 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3187 qeth_initialize_working_pool_list(card);
3188 /*give only as many buffers to hardware as we have buffer pool entries*/
3189 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3190 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3191 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3192 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3193 card->qdio.in_buf_pool.buf_count - 1, NULL);
3194 if (rc) {
3195 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3196 return rc;
3198 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3199 if (rc) {
3200 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3201 return rc;
3203 /* outbound queue */
3204 for (i = 0; i < card->qdio.no_out_queues; ++i){
3205 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3206 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3207 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3208 qeth_clear_output_buffer(card->qdio.out_qs[i],
3209 &card->qdio.out_qs[i]->bufs[j]);
3211 card->qdio.out_qs[i]->card = card;
3212 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3213 card->qdio.out_qs[i]->do_pack = 0;
3214 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3215 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3216 atomic_set(&card->qdio.out_qs[i]->state,
3217 QETH_OUT_Q_UNLOCKED);
3219 return 0;
3222 static int
3223 qeth_qdio_establish(struct qeth_card *card)
3225 struct qdio_initialize init_data;
3226 char *qib_param_field;
3227 struct qdio_buffer **in_sbal_ptrs;
3228 struct qdio_buffer **out_sbal_ptrs;
3229 int i, j, k;
3230 int rc;
3232 QETH_DBF_TEXT(setup, 2, "qdioest");
3234 qib_param_field = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3235 GFP_KERNEL);
3236 if (!qib_param_field)
3237 return -ENOMEM;
3239 memset(qib_param_field, 0, QDIO_MAX_BUFFERS_PER_Q * sizeof(char));
3241 qeth_create_qib_param_field(card, qib_param_field);
3242 qeth_create_qib_param_field_blkt(card, qib_param_field);
3244 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3245 GFP_KERNEL);
3246 if (!in_sbal_ptrs) {
3247 kfree(qib_param_field);
3248 return -ENOMEM;
3250 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3251 in_sbal_ptrs[i] = (struct qdio_buffer *)
3252 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3254 out_sbal_ptrs =
3255 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3256 sizeof(void *), GFP_KERNEL);
3257 if (!out_sbal_ptrs) {
3258 kfree(in_sbal_ptrs);
3259 kfree(qib_param_field);
3260 return -ENOMEM;
3262 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3263 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3264 out_sbal_ptrs[k] = (struct qdio_buffer *)
3265 virt_to_phys(card->qdio.out_qs[i]->
3266 bufs[j].buffer);
3269 memset(&init_data, 0, sizeof(struct qdio_initialize));
3270 init_data.cdev = CARD_DDEV(card);
3271 init_data.q_format = qeth_get_qdio_q_format(card);
3272 init_data.qib_param_field_format = 0;
3273 init_data.qib_param_field = qib_param_field;
3274 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3275 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3276 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3277 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3278 init_data.no_input_qs = 1;
3279 init_data.no_output_qs = card->qdio.no_out_queues;
3280 init_data.input_handler = (qdio_handler_t *)
3281 qeth_qdio_input_handler;
3282 init_data.output_handler = (qdio_handler_t *)
3283 qeth_qdio_output_handler;
3284 init_data.int_parm = (unsigned long) card;
3285 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3286 QDIO_OUTBOUND_0COPY_SBALS |
3287 QDIO_USE_OUTBOUND_PCIS;
3288 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3289 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3291 if (!(rc = qdio_initialize(&init_data)))
3292 card->qdio.state = QETH_QDIO_ESTABLISHED;
3294 kfree(out_sbal_ptrs);
3295 kfree(in_sbal_ptrs);
3296 kfree(qib_param_field);
3297 return rc;
3300 static int
3301 qeth_qdio_activate(struct qeth_card *card)
3303 QETH_DBF_TEXT(setup,3,"qdioact");
3304 return qdio_activate(CARD_DDEV(card), 0);
3307 static int
3308 qeth_clear_channel(struct qeth_channel *channel)
3310 unsigned long flags;
3311 struct qeth_card *card;
3312 int rc;
3314 QETH_DBF_TEXT(trace,3,"clearch");
3315 card = CARD_FROM_CDEV(channel->ccwdev);
3316 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3317 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3318 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3320 if (rc)
3321 return rc;
3322 rc = wait_event_interruptible_timeout(card->wait_q,
3323 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3324 if (rc == -ERESTARTSYS)
3325 return rc;
3326 if (channel->state != CH_STATE_STOPPED)
3327 return -ETIME;
3328 channel->state = CH_STATE_DOWN;
3329 return 0;
3332 static int
3333 qeth_halt_channel(struct qeth_channel *channel)
3335 unsigned long flags;
3336 struct qeth_card *card;
3337 int rc;
3339 QETH_DBF_TEXT(trace,3,"haltch");
3340 card = CARD_FROM_CDEV(channel->ccwdev);
3341 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3342 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3343 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3345 if (rc)
3346 return rc;
3347 rc = wait_event_interruptible_timeout(card->wait_q,
3348 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3349 if (rc == -ERESTARTSYS)
3350 return rc;
3351 if (channel->state != CH_STATE_HALTED)
3352 return -ETIME;
3353 return 0;
3356 static int
3357 qeth_halt_channels(struct qeth_card *card)
3359 int rc = 0;
3361 QETH_DBF_TEXT(trace,3,"haltchs");
3362 if ((rc = qeth_halt_channel(&card->read)))
3363 return rc;
3364 if ((rc = qeth_halt_channel(&card->write)))
3365 return rc;
3366 return qeth_halt_channel(&card->data);
3368 static int
3369 qeth_clear_channels(struct qeth_card *card)
3371 int rc = 0;
3373 QETH_DBF_TEXT(trace,3,"clearchs");
3374 if ((rc = qeth_clear_channel(&card->read)))
3375 return rc;
3376 if ((rc = qeth_clear_channel(&card->write)))
3377 return rc;
3378 return qeth_clear_channel(&card->data);
3381 static int
3382 qeth_clear_halt_card(struct qeth_card *card, int halt)
3384 int rc = 0;
3386 QETH_DBF_TEXT(trace,3,"clhacrd");
3387 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3389 if (halt)
3390 rc = qeth_halt_channels(card);
3391 if (rc)
3392 return rc;
3393 return qeth_clear_channels(card);
3396 static int
3397 qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3399 int rc = 0;
3401 QETH_DBF_TEXT(trace,3,"qdioclr");
3402 if (card->qdio.state == QETH_QDIO_ESTABLISHED){
3403 if ((rc = qdio_cleanup(CARD_DDEV(card),
3404 (card->info.type == QETH_CARD_TYPE_IQD) ?
3405 QDIO_FLAG_CLEANUP_USING_HALT :
3406 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3407 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3408 card->qdio.state = QETH_QDIO_ALLOCATED;
3410 if ((rc = qeth_clear_halt_card(card, use_halt)))
3411 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3412 card->state = CARD_STATE_DOWN;
3413 return rc;
3416 static int
3417 qeth_dm_act(struct qeth_card *card)
3419 int rc;
3420 struct qeth_cmd_buffer *iob;
3422 QETH_DBF_TEXT(setup,2,"dmact");
3424 iob = qeth_wait_for_buffer(&card->write);
3425 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3427 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3428 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3429 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3430 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3431 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3432 return rc;
3435 static int
3436 qeth_mpc_initialize(struct qeth_card *card)
3438 int rc;
3440 QETH_DBF_TEXT(setup,2,"mpcinit");
3442 if ((rc = qeth_issue_next_read(card))){
3443 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3444 return rc;
3446 if ((rc = qeth_cm_enable(card))){
3447 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3448 return rc;
3450 if ((rc = qeth_cm_setup(card))){
3451 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3452 return rc;
3454 if ((rc = qeth_ulp_enable(card))){
3455 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3456 return rc;
3458 if ((rc = qeth_ulp_setup(card))){
3459 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3460 return rc;
3462 if ((rc = qeth_alloc_qdio_buffers(card))){
3463 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3464 return rc;
3466 if ((rc = qeth_qdio_establish(card))){
3467 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3468 qeth_free_qdio_buffers(card);
3469 goto out_qdio;
3471 if ((rc = qeth_qdio_activate(card))){
3472 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3473 goto out_qdio;
3475 if ((rc = qeth_dm_act(card))){
3476 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3477 goto out_qdio;
3480 return 0;
3481 out_qdio:
3482 qeth_qdio_clear_card(card, card->info.type==QETH_CARD_TYPE_OSAE);
3483 return rc;
3486 static struct net_device *
3487 qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3489 struct net_device *dev = NULL;
3491 switch (type) {
3492 case QETH_CARD_TYPE_OSAE:
3493 switch (linktype) {
3494 case QETH_LINK_TYPE_LANE_TR:
3495 case QETH_LINK_TYPE_HSTR:
3496 #ifdef CONFIG_TR
3497 dev = alloc_trdev(0);
3498 #endif /* CONFIG_TR */
3499 break;
3500 default:
3501 dev = alloc_etherdev(0);
3503 break;
3504 case QETH_CARD_TYPE_IQD:
3505 dev = alloc_netdev(0, "hsi%d", ether_setup);
3506 break;
3507 default:
3508 dev = alloc_etherdev(0);
3510 return dev;
3513 /*hard_header fake function; used in case fake_ll is set */
3514 static int
3515 qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3516 unsigned short type, void *daddr, void *saddr,
3517 unsigned len)
3519 if(dev->type == ARPHRD_IEEE802_TR){
3520 struct trh_hdr *hdr;
3521 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3522 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3523 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3524 return QETH_FAKE_LL_LEN_TR;
3526 } else {
3527 struct ethhdr *hdr;
3528 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3529 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3530 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3531 if (type != ETH_P_802_3)
3532 hdr->h_proto = htons(type);
3533 else
3534 hdr->h_proto = htons(len);
3535 return QETH_FAKE_LL_LEN_ETH;
3540 static inline int
3541 qeth_send_packet(struct qeth_card *, struct sk_buff *);
3543 static int
3544 qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3546 int rc;
3547 struct qeth_card *card;
3549 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3550 card = (struct qeth_card *)dev->priv;
3551 if (skb==NULL) {
3552 card->stats.tx_dropped++;
3553 card->stats.tx_errors++;
3554 /* return OK; otherwise ksoftirqd goes to 100% */
3555 return NETDEV_TX_OK;
3557 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3558 card->stats.tx_dropped++;
3559 card->stats.tx_errors++;
3560 card->stats.tx_carrier_errors++;
3561 dev_kfree_skb_any(skb);
3562 /* return OK; otherwise ksoftirqd goes to 100% */
3563 return NETDEV_TX_OK;
3565 #ifdef CONFIG_QETH_PERF_STATS
3566 card->perf_stats.outbound_cnt++;
3567 card->perf_stats.outbound_start_time = qeth_get_micros();
3568 #endif
3569 netif_stop_queue(dev);
3570 if ((rc = qeth_send_packet(card, skb))) {
3571 if (rc == -EBUSY) {
3572 return NETDEV_TX_BUSY;
3573 } else {
3574 card->stats.tx_errors++;
3575 card->stats.tx_dropped++;
3576 dev_kfree_skb_any(skb);
3577 /*set to OK; otherwise ksoftirqd goes to 100% */
3578 rc = NETDEV_TX_OK;
3581 netif_wake_queue(dev);
3582 #ifdef CONFIG_QETH_PERF_STATS
3583 card->perf_stats.outbound_time += qeth_get_micros() -
3584 card->perf_stats.outbound_start_time;
3585 #endif
3586 return rc;
3589 static int
3590 qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3592 int rc = 0;
3593 #ifdef CONFIG_QETH_VLAN
3594 struct vlan_group *vg;
3595 int i;
3597 if (!(vg = card->vlangrp))
3598 return rc;
3600 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3601 if (vg->vlan_devices[i] == dev){
3602 rc = QETH_VLAN_CARD;
3603 break;
3606 #endif
3607 return rc;
3610 static int
3611 qeth_verify_dev(struct net_device *dev)
3613 struct qeth_card *card;
3614 unsigned long flags;
3615 int rc = 0;
3617 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3618 list_for_each_entry(card, &qeth_card_list.list, list){
3619 if (card->dev == dev){
3620 rc = QETH_REAL_CARD;
3621 break;
3623 rc = qeth_verify_vlan_dev(dev, card);
3624 if (rc)
3625 break;
3627 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3629 return rc;
3632 static struct qeth_card *
3633 qeth_get_card_from_dev(struct net_device *dev)
3635 struct qeth_card *card = NULL;
3636 int rc;
3638 rc = qeth_verify_dev(dev);
3639 if (rc == QETH_REAL_CARD)
3640 card = (struct qeth_card *)dev->priv;
3641 else if (rc == QETH_VLAN_CARD)
3642 card = (struct qeth_card *)
3643 VLAN_DEV_INFO(dev)->real_dev->priv;
3645 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3646 return card ;
3649 static void
3650 qeth_tx_timeout(struct net_device *dev)
3652 struct qeth_card *card;
3654 card = (struct qeth_card *) dev->priv;
3655 card->stats.tx_errors++;
3656 qeth_schedule_recovery(card);
3659 static int
3660 qeth_open(struct net_device *dev)
3662 struct qeth_card *card;
3664 QETH_DBF_TEXT(trace, 4, "qethopen");
3666 card = (struct qeth_card *) dev->priv;
3668 if (card->state != CARD_STATE_SOFTSETUP)
3669 return -ENODEV;
3671 if ( (card->options.layer2) &&
3672 (!card->info.layer2_mac_registered)) {
3673 QETH_DBF_TEXT(trace,4,"nomacadr");
3674 return -EPERM;
3676 card->dev->flags |= IFF_UP;
3677 netif_start_queue(dev);
3678 card->data.state = CH_STATE_UP;
3679 card->state = CARD_STATE_UP;
3681 if (!card->lan_online){
3682 if (netif_carrier_ok(dev))
3683 netif_carrier_off(dev);
3685 return 0;
3688 static int
3689 qeth_stop(struct net_device *dev)
3691 struct qeth_card *card;
3693 QETH_DBF_TEXT(trace, 4, "qethstop");
3695 card = (struct qeth_card *) dev->priv;
3697 netif_stop_queue(dev);
3698 card->dev->flags &= ~IFF_UP;
3699 if (card->state == CARD_STATE_UP)
3700 card->state = CARD_STATE_SOFTSETUP;
3701 return 0;
3704 static inline int
3705 qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3707 int cast_type = RTN_UNSPEC;
3709 if (skb->dst && skb->dst->neighbour){
3710 cast_type = skb->dst->neighbour->type;
3711 if ((cast_type == RTN_BROADCAST) ||
3712 (cast_type == RTN_MULTICAST) ||
3713 (cast_type == RTN_ANYCAST))
3714 return cast_type;
3715 else
3716 return RTN_UNSPEC;
3718 /* try something else */
3719 if (skb->protocol == ETH_P_IPV6)
3720 return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0;
3721 else if (skb->protocol == ETH_P_IP)
3722 return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0;
3723 /* ... */
3724 if (!memcmp(skb->data, skb->dev->broadcast, 6))
3725 return RTN_BROADCAST;
3726 else {
3727 u16 hdr_mac;
3729 hdr_mac = *((u16 *)skb->data);
3730 /* tr multicast? */
3731 switch (card->info.link_type) {
3732 case QETH_LINK_TYPE_HSTR:
3733 case QETH_LINK_TYPE_LANE_TR:
3734 if ((hdr_mac == QETH_TR_MAC_NC) ||
3735 (hdr_mac == QETH_TR_MAC_C))
3736 return RTN_MULTICAST;
3737 /* eth or so multicast? */
3738 default:
3739 if ((hdr_mac == QETH_ETH_MAC_V4) ||
3740 (hdr_mac == QETH_ETH_MAC_V6))
3741 return RTN_MULTICAST;
3744 return cast_type;
3747 static inline int
3748 qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3749 int ipv, int cast_type)
3751 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3752 return card->qdio.default_out_queue;
3753 switch (card->qdio.no_out_queues) {
3754 case 4:
3755 if (cast_type && card->info.is_multicast_different)
3756 return card->info.is_multicast_different &
3757 (card->qdio.no_out_queues - 1);
3758 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3759 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
3760 if (skb->nh.iph->tos & IP_TOS_NOTIMPORTANT)
3761 return 3;
3762 if (skb->nh.iph->tos & IP_TOS_HIGHRELIABILITY)
3763 return 2;
3764 if (skb->nh.iph->tos & IP_TOS_HIGHTHROUGHPUT)
3765 return 1;
3766 if (skb->nh.iph->tos & IP_TOS_LOWDELAY)
3767 return 0;
3769 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
3770 return 3 - (skb->nh.iph->tos >> 6);
3771 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3772 /* TODO: IPv6!!! */
3774 return card->qdio.default_out_queue;
3775 case 1: /* fallthrough for single-out-queue 1920-device */
3776 default:
3777 return card->qdio.default_out_queue;
3781 static inline int
3782 qeth_get_ip_version(struct sk_buff *skb)
3784 switch (skb->protocol) {
3785 case ETH_P_IPV6:
3786 return 6;
3787 case ETH_P_IP:
3788 return 4;
3789 default:
3790 return 0;
3794 static inline int
3795 qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb,
3796 struct qeth_hdr **hdr, int ipv)
3798 int rc;
3799 #ifdef CONFIG_QETH_VLAN
3800 u16 *tag;
3801 #endif
3803 QETH_DBF_TEXT(trace, 6, "prepskb");
3805 rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3806 if (rc)
3807 return rc;
3808 #ifdef CONFIG_QETH_VLAN
3809 if (card->vlangrp && vlan_tx_tag_present(*skb) &&
3810 ((ipv == 6) || card->options.layer2) ) {
3812 * Move the mac addresses (6 bytes src, 6 bytes dest)
3813 * to the beginning of the new header. We are using three
3814 * memcpys instead of one memmove to save cycles.
3816 skb_push(*skb, VLAN_HLEN);
3817 memcpy((*skb)->data, (*skb)->data + 4, 4);
3818 memcpy((*skb)->data + 4, (*skb)->data + 8, 4);
3819 memcpy((*skb)->data + 8, (*skb)->data + 12, 4);
3820 tag = (u16 *)((*skb)->data + 12);
3822 * first two bytes = ETH_P_8021Q (0x8100)
3823 * second two bytes = VLANID
3825 *tag = __constant_htons(ETH_P_8021Q);
3826 *(tag + 1) = htons(vlan_tx_tag_get(*skb));
3828 #endif
3829 *hdr = (struct qeth_hdr *)
3830 qeth_push_skb(card, skb, sizeof(struct qeth_hdr));
3831 if (hdr == NULL)
3832 return -EINVAL;
3833 return 0;
3836 static inline u8
3837 qeth_get_qeth_hdr_flags4(int cast_type)
3839 if (cast_type == RTN_MULTICAST)
3840 return QETH_CAST_MULTICAST;
3841 if (cast_type == RTN_BROADCAST)
3842 return QETH_CAST_BROADCAST;
3843 return QETH_CAST_UNICAST;
3846 static inline u8
3847 qeth_get_qeth_hdr_flags6(int cast_type)
3849 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
3850 if (cast_type == RTN_MULTICAST)
3851 return ct | QETH_CAST_MULTICAST;
3852 if (cast_type == RTN_ANYCAST)
3853 return ct | QETH_CAST_ANYCAST;
3854 if (cast_type == RTN_BROADCAST)
3855 return ct | QETH_CAST_BROADCAST;
3856 return ct | QETH_CAST_UNICAST;
3859 static inline void
3860 qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
3861 struct sk_buff *skb)
3863 __u16 hdr_mac;
3865 if (!memcmp(skb->data+QETH_HEADER_SIZE,
3866 skb->dev->broadcast,6)) { /* broadcast? */
3867 *(__u32 *)hdr->hdr.l2.flags |=
3868 QETH_LAYER2_FLAG_BROADCAST << 8;
3869 return;
3871 hdr_mac=*((__u16*)skb->data);
3872 /* tr multicast? */
3873 switch (card->info.link_type) {
3874 case QETH_LINK_TYPE_HSTR:
3875 case QETH_LINK_TYPE_LANE_TR:
3876 if ((hdr_mac == QETH_TR_MAC_NC) ||
3877 (hdr_mac == QETH_TR_MAC_C) )
3878 *(__u32 *)hdr->hdr.l2.flags |=
3879 QETH_LAYER2_FLAG_MULTICAST << 8;
3880 else
3881 *(__u32 *)hdr->hdr.l2.flags |=
3882 QETH_LAYER2_FLAG_UNICAST << 8;
3883 break;
3884 /* eth or so multicast? */
3885 default:
3886 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
3887 (hdr_mac==QETH_ETH_MAC_V6) )
3888 *(__u32 *)hdr->hdr.l2.flags |=
3889 QETH_LAYER2_FLAG_MULTICAST << 8;
3890 else
3891 *(__u32 *)hdr->hdr.l2.flags |=
3892 QETH_LAYER2_FLAG_UNICAST << 8;
3896 static inline void
3897 qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
3898 struct sk_buff *skb, int cast_type)
3900 memset(hdr, 0, sizeof(struct qeth_hdr));
3901 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
3903 /* set byte 0 to "0x02" and byte 3 to casting flags */
3904 if (cast_type==RTN_MULTICAST)
3905 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
3906 else if (cast_type==RTN_BROADCAST)
3907 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
3908 else
3909 qeth_layer2_get_packet_type(card, hdr, skb);
3911 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
3912 #ifdef CONFIG_QETH_VLAN
3913 /* VSWITCH relies on the VLAN
3914 * information to be present in
3915 * the QDIO header */
3916 if ((card->vlangrp != NULL) &&
3917 vlan_tx_tag_present(skb)) {
3918 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
3919 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
3921 #endif
3924 void
3925 qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
3926 struct sk_buff *skb, int ipv, int cast_type)
3928 QETH_DBF_TEXT(trace, 6, "fillhdr");
3930 memset(hdr, 0, sizeof(struct qeth_hdr));
3931 if (card->options.layer2) {
3932 qeth_layer2_fill_header(card, hdr, skb, cast_type);
3933 return;
3935 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
3936 hdr->hdr.l3.ext_flags = 0;
3937 #ifdef CONFIG_QETH_VLAN
3939 * before we're going to overwrite this location with next hop ip.
3940 * v6 uses passthrough, v4 sets the tag in the QDIO header.
3942 if (card->vlangrp && vlan_tx_tag_present(skb)) {
3943 hdr->hdr.l3.ext_flags = (ipv == 4) ?
3944 QETH_HDR_EXT_VLAN_FRAME :
3945 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
3946 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
3948 #endif /* CONFIG_QETH_VLAN */
3949 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
3950 if (ipv == 4) { /* IPv4 */
3951 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
3952 memset(hdr->hdr.l3.dest_addr, 0, 12);
3953 if ((skb->dst) && (skb->dst->neighbour)) {
3954 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
3955 *((u32 *) skb->dst->neighbour->primary_key);
3956 } else {
3957 /* fill in destination address used in ip header */
3958 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = skb->nh.iph->daddr;
3960 } else if (ipv == 6) { /* IPv6 or passthru */
3961 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
3962 if ((skb->dst) && (skb->dst->neighbour)) {
3963 memcpy(hdr->hdr.l3.dest_addr,
3964 skb->dst->neighbour->primary_key, 16);
3965 } else {
3966 /* fill in destination address used in ip header */
3967 memcpy(hdr->hdr.l3.dest_addr, &skb->nh.ipv6h->daddr, 16);
3969 } else { /* passthrough */
3970 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
3971 !memcmp(skb->data + sizeof(struct qeth_hdr) +
3972 sizeof(__u16), skb->dev->broadcast, 6)) {
3973 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
3974 QETH_HDR_PASSTHRU;
3975 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
3976 skb->dev->broadcast, 6)) { /* broadcast? */
3977 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
3978 QETH_HDR_PASSTHRU;
3979 } else {
3980 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
3981 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
3982 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
3987 static inline void
3988 __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
3989 int is_tso, int *next_element_to_fill)
3991 int length = skb->len;
3992 int length_here;
3993 int element;
3994 char *data;
3995 int first_lap ;
3997 element = *next_element_to_fill;
3998 data = skb->data;
3999 first_lap = (is_tso == 0 ? 1 : 0);
4001 while (length > 0) {
4002 /* length_here is the remaining amount of data in this page */
4003 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4004 if (length < length_here)
4005 length_here = length;
4007 buffer->element[element].addr = data;
4008 buffer->element[element].length = length_here;
4009 length -= length_here;
4010 if (!length) {
4011 if (first_lap)
4012 buffer->element[element].flags = 0;
4013 else
4014 buffer->element[element].flags =
4015 SBAL_FLAGS_LAST_FRAG;
4016 } else {
4017 if (first_lap)
4018 buffer->element[element].flags =
4019 SBAL_FLAGS_FIRST_FRAG;
4020 else
4021 buffer->element[element].flags =
4022 SBAL_FLAGS_MIDDLE_FRAG;
4024 data += length_here;
4025 element++;
4026 first_lap = 0;
4028 *next_element_to_fill = element;
4031 static inline int
4032 qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4033 struct qeth_qdio_out_buffer *buf,
4034 struct sk_buff *skb)
4036 struct qdio_buffer *buffer;
4037 struct qeth_hdr_tso *hdr;
4038 int flush_cnt = 0, hdr_len, large_send = 0;
4040 QETH_DBF_TEXT(trace, 6, "qdfillbf");
4042 buffer = buf->buffer;
4043 atomic_inc(&skb->users);
4044 skb_queue_tail(&buf->skb_list, skb);
4046 hdr = (struct qeth_hdr_tso *) skb->data;
4047 /*check first on TSO ....*/
4048 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4049 int element = buf->next_element_to_fill;
4051 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4052 /*fill first buffer entry only with header information */
4053 buffer->element[element].addr = skb->data;
4054 buffer->element[element].length = hdr_len;
4055 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4056 buf->next_element_to_fill++;
4057 skb->data += hdr_len;
4058 skb->len -= hdr_len;
4059 large_send = 1;
4061 if (skb_shinfo(skb)->nr_frags == 0)
4062 __qeth_fill_buffer(skb, buffer, large_send,
4063 (int *)&buf->next_element_to_fill);
4064 else
4065 __qeth_fill_buffer_frag(skb, buffer, large_send,
4066 (int *)&buf->next_element_to_fill);
4068 if (!queue->do_pack) {
4069 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4070 /* set state to PRIMED -> will be flushed */
4071 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4072 flush_cnt = 1;
4073 } else {
4074 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4075 #ifdef CONFIG_QETH_PERF_STATS
4076 queue->card->perf_stats.skbs_sent_pack++;
4077 #endif
4078 if (buf->next_element_to_fill >=
4079 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4081 * packed buffer if full -> set state PRIMED
4082 * -> will be flushed
4084 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4085 flush_cnt = 1;
4088 return flush_cnt;
4091 static inline int
4092 qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4093 struct sk_buff *skb, struct qeth_hdr *hdr,
4094 int elements_needed,
4095 struct qeth_eddp_context *ctx)
4097 struct qeth_qdio_out_buffer *buffer;
4098 int buffers_needed = 0;
4099 int flush_cnt = 0;
4100 int index;
4102 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4104 /* spin until we get the queue ... */
4105 while (atomic_compare_and_swap(QETH_OUT_Q_UNLOCKED,
4106 QETH_OUT_Q_LOCKED,
4107 &queue->state));
4108 /* ... now we've got the queue */
4109 index = queue->next_buf_to_fill;
4110 buffer = &queue->bufs[queue->next_buf_to_fill];
4112 * check if buffer is empty to make sure that we do not 'overtake'
4113 * ourselves and try to fill a buffer that is already primed
4115 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4116 card->stats.tx_dropped++;
4117 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4118 return -EBUSY;
4120 if (ctx == NULL)
4121 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4122 QDIO_MAX_BUFFERS_PER_Q;
4123 else {
4124 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4125 if (buffers_needed < 0) {
4126 card->stats.tx_dropped++;
4127 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4128 return -EBUSY;
4130 queue->next_buf_to_fill =
4131 (queue->next_buf_to_fill + buffers_needed) %
4132 QDIO_MAX_BUFFERS_PER_Q;
4134 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4135 if (ctx == NULL) {
4136 qeth_fill_buffer(queue, buffer, skb);
4137 qeth_flush_buffers(queue, 0, index, 1);
4138 } else {
4139 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4140 WARN_ON(buffers_needed != flush_cnt);
4141 qeth_flush_buffers(queue, 0, index, flush_cnt);
4143 return 0;
4146 static inline int
4147 qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4148 struct sk_buff *skb, struct qeth_hdr *hdr,
4149 int elements_needed, struct qeth_eddp_context *ctx)
4151 struct qeth_qdio_out_buffer *buffer;
4152 int start_index;
4153 int flush_count = 0;
4154 int do_pack = 0;
4155 int tmp;
4156 int rc = 0;
4158 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4160 /* spin until we get the queue ... */
4161 while (atomic_compare_and_swap(QETH_OUT_Q_UNLOCKED,
4162 QETH_OUT_Q_LOCKED,
4163 &queue->state));
4164 start_index = queue->next_buf_to_fill;
4165 buffer = &queue->bufs[queue->next_buf_to_fill];
4167 * check if buffer is empty to make sure that we do not 'overtake'
4168 * ourselves and try to fill a buffer that is already primed
4170 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY){
4171 card->stats.tx_dropped++;
4172 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4173 return -EBUSY;
4175 /* check if we need to switch packing state of this queue */
4176 qeth_switch_to_packing_if_needed(queue);
4177 if (queue->do_pack){
4178 do_pack = 1;
4179 if (ctx == NULL) {
4180 /* does packet fit in current buffer? */
4181 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4182 buffer->next_element_to_fill) < elements_needed){
4183 /* ... no -> set state PRIMED */
4184 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4185 flush_count++;
4186 queue->next_buf_to_fill =
4187 (queue->next_buf_to_fill + 1) %
4188 QDIO_MAX_BUFFERS_PER_Q;
4189 buffer = &queue->bufs[queue->next_buf_to_fill];
4190 /* we did a step forward, so check buffer state
4191 * again */
4192 if (atomic_read(&buffer->state) !=
4193 QETH_QDIO_BUF_EMPTY){
4194 card->stats.tx_dropped++;
4195 qeth_flush_buffers(queue, 0, start_index, flush_count);
4196 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4197 return -EBUSY;
4200 } else {
4201 /* check if we have enough elements (including following
4202 * free buffers) to handle eddp context */
4203 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4204 printk("eddp tx_dropped 1\n");
4205 card->stats.tx_dropped++;
4206 rc = -EBUSY;
4207 goto out;
4211 if (ctx == NULL)
4212 tmp = qeth_fill_buffer(queue, buffer, skb);
4213 else {
4214 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4215 if (tmp < 0) {
4216 printk("eddp tx_dropped 2\n");
4217 card->stats.tx_dropped++;
4218 rc = - EBUSY;
4219 goto out;
4222 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4223 QDIO_MAX_BUFFERS_PER_Q;
4224 flush_count += tmp;
4225 out:
4226 if (flush_count)
4227 qeth_flush_buffers(queue, 0, start_index, flush_count);
4229 * queue->state will go from LOCKED -> UNLOCKED or from
4230 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4231 * (switch packing state or flush buffer to get another pci flag out).
4232 * In that case we will enter this loop
4234 while (atomic_dec_return(&queue->state)){
4235 flush_count = 0;
4236 start_index = queue->next_buf_to_fill;
4237 /* check if we can go back to non-packing state */
4238 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4240 * check if we need to flush a packing buffer to get a pci
4241 * flag out on the queue
4243 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4244 flush_count += qeth_flush_buffers_on_no_pci(queue);
4245 if (flush_count)
4246 qeth_flush_buffers(queue, 0, start_index, flush_count);
4248 /* at this point the queue is UNLOCKED again */
4249 #ifdef CONFIG_QETH_PERF_STATS
4250 if (do_pack)
4251 queue->card->perf_stats.bufs_sent_pack += flush_count;
4252 #endif /* CONFIG_QETH_PERF_STATS */
4254 return rc;
4257 static inline int
4258 qeth_get_elements_no(struct qeth_card *card, void *hdr,
4259 struct sk_buff *skb, int elems)
4261 int elements_needed = 0;
4263 if (skb_shinfo(skb)->nr_frags > 0) {
4264 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4266 if (elements_needed == 0 )
4267 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4268 + skb->len) >> PAGE_SHIFT);
4269 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4270 PRINT_ERR("qeth_do_send_packet: invalid size of "
4271 "IP packet (Number=%d / Length=%d). Discarded.\n",
4272 (elements_needed+elems), skb->len);
4273 return 0;
4275 return elements_needed;
4278 static inline int
4279 qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4281 int ipv = 0;
4282 int cast_type;
4283 struct qeth_qdio_out_q *queue;
4284 struct qeth_hdr *hdr;
4285 int elements_needed = 0;
4286 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4287 struct qeth_eddp_context *ctx = NULL;
4288 int rc;
4290 QETH_DBF_TEXT(trace, 6, "sendpkt");
4292 if (!card->options.layer2) {
4293 ipv = qeth_get_ip_version(skb);
4294 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4295 if ((skb = qeth_pskb_unshare(skb,GFP_ATOMIC)) == NULL) {
4296 card->stats.tx_dropped++;
4297 dev_kfree_skb_irq(skb);
4298 return 0;
4300 if(card->dev->type == ARPHRD_IEEE802_TR){
4301 skb_pull(skb, QETH_FAKE_LL_LEN_TR);
4302 } else {
4303 skb_pull(skb, QETH_FAKE_LL_LEN_ETH);
4307 cast_type = qeth_get_cast_type(card, skb);
4308 if ((cast_type == RTN_BROADCAST) && (card->info.broadcast_capable == 0)){
4309 card->stats.tx_dropped++;
4310 card->stats.tx_errors++;
4311 dev_kfree_skb_any(skb);
4312 return NETDEV_TX_OK;
4314 queue = card->qdio.out_qs
4315 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4317 if (skb_shinfo(skb)->tso_size)
4318 large_send = card->options.large_send;
4320 /*are we able to do TSO ? If so ,prepare and send it from here */
4321 if ((large_send == QETH_LARGE_SEND_TSO) &&
4322 (cast_type == RTN_UNSPEC)) {
4323 rc = qeth_tso_prepare_packet(card, skb, ipv, cast_type);
4324 if (rc) {
4325 card->stats.tx_dropped++;
4326 card->stats.tx_errors++;
4327 dev_kfree_skb_any(skb);
4328 return NETDEV_TX_OK;
4330 elements_needed++;
4331 } else {
4332 if ((rc = qeth_prepare_skb(card, &skb, &hdr, ipv))) {
4333 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc);
4334 return rc;
4336 qeth_fill_header(card, hdr, skb, ipv, cast_type);
4339 if (large_send == QETH_LARGE_SEND_EDDP) {
4340 ctx = qeth_eddp_create_context(card, skb, hdr);
4341 if (ctx == NULL) {
4342 PRINT_WARN("could not create eddp context\n");
4343 return -EINVAL;
4345 } else {
4346 int elems = qeth_get_elements_no(card,(void*) hdr, skb,
4347 elements_needed);
4348 if (!elems)
4349 return -EINVAL;
4350 elements_needed += elems;
4353 if (card->info.type != QETH_CARD_TYPE_IQD)
4354 rc = qeth_do_send_packet(card, queue, skb, hdr,
4355 elements_needed, ctx);
4356 else
4357 rc = qeth_do_send_packet_fast(card, queue, skb, hdr,
4358 elements_needed, ctx);
4359 if (!rc){
4360 card->stats.tx_packets++;
4361 card->stats.tx_bytes += skb->len;
4362 #ifdef CONFIG_QETH_PERF_STATS
4363 if (skb_shinfo(skb)->tso_size &&
4364 !(large_send == QETH_LARGE_SEND_NO)) {
4365 card->perf_stats.large_send_bytes += skb->len;
4366 card->perf_stats.large_send_cnt++;
4368 if (skb_shinfo(skb)->nr_frags > 0){
4369 card->perf_stats.sg_skbs_sent++;
4370 /* nr_frags + skb->data */
4371 card->perf_stats.sg_frags_sent +=
4372 skb_shinfo(skb)->nr_frags + 1;
4374 #endif /* CONFIG_QETH_PERF_STATS */
4376 if (ctx != NULL) {
4377 /* drop creator's reference */
4378 qeth_eddp_put_context(ctx);
4379 /* free skb; it's not referenced by a buffer */
4380 if (rc == 0)
4381 dev_kfree_skb_any(skb);
4384 return rc;
4387 static int
4388 qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4390 struct qeth_card *card = (struct qeth_card *) dev->priv;
4391 int rc = 0;
4393 switch(regnum){
4394 case MII_BMCR: /* Basic mode control register */
4395 rc = BMCR_FULLDPLX;
4396 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4397 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4398 rc |= BMCR_SPEED100;
4399 break;
4400 case MII_BMSR: /* Basic mode status register */
4401 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4402 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4403 BMSR_100BASE4;
4404 break;
4405 case MII_PHYSID1: /* PHYS ID 1 */
4406 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4407 dev->dev_addr[2];
4408 rc = (rc >> 5) & 0xFFFF;
4409 break;
4410 case MII_PHYSID2: /* PHYS ID 2 */
4411 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4412 break;
4413 case MII_ADVERTISE: /* Advertisement control reg */
4414 rc = ADVERTISE_ALL;
4415 break;
4416 case MII_LPA: /* Link partner ability reg */
4417 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4418 LPA_100BASE4 | LPA_LPACK;
4419 break;
4420 case MII_EXPANSION: /* Expansion register */
4421 break;
4422 case MII_DCOUNTER: /* disconnect counter */
4423 break;
4424 case MII_FCSCOUNTER: /* false carrier counter */
4425 break;
4426 case MII_NWAYTEST: /* N-way auto-neg test register */
4427 break;
4428 case MII_RERRCOUNTER: /* rx error counter */
4429 rc = card->stats.rx_errors;
4430 break;
4431 case MII_SREVISION: /* silicon revision */
4432 break;
4433 case MII_RESV1: /* reserved 1 */
4434 break;
4435 case MII_LBRERROR: /* loopback, rx, bypass error */
4436 break;
4437 case MII_PHYADDR: /* physical address */
4438 break;
4439 case MII_RESV2: /* reserved 2 */
4440 break;
4441 case MII_TPISTATUS: /* TPI status for 10mbps */
4442 break;
4443 case MII_NCONFIG: /* network interface config */
4444 break;
4445 default:
4446 rc = 0;
4447 break;
4449 return rc;
4452 static void
4453 qeth_mdio_write(struct net_device *dev, int phy_id, int regnum, int value)
4455 switch(regnum){
4456 case MII_BMCR: /* Basic mode control register */
4457 case MII_BMSR: /* Basic mode status register */
4458 case MII_PHYSID1: /* PHYS ID 1 */
4459 case MII_PHYSID2: /* PHYS ID 2 */
4460 case MII_ADVERTISE: /* Advertisement control reg */
4461 case MII_LPA: /* Link partner ability reg */
4462 case MII_EXPANSION: /* Expansion register */
4463 case MII_DCOUNTER: /* disconnect counter */
4464 case MII_FCSCOUNTER: /* false carrier counter */
4465 case MII_NWAYTEST: /* N-way auto-neg test register */
4466 case MII_RERRCOUNTER: /* rx error counter */
4467 case MII_SREVISION: /* silicon revision */
4468 case MII_RESV1: /* reserved 1 */
4469 case MII_LBRERROR: /* loopback, rx, bypass error */
4470 case MII_PHYADDR: /* physical address */
4471 case MII_RESV2: /* reserved 2 */
4472 case MII_TPISTATUS: /* TPI status for 10mbps */
4473 case MII_NCONFIG: /* network interface config */
4474 default:
4475 break;
4479 static inline const char *
4480 qeth_arp_get_error_cause(int *rc)
4482 switch (*rc) {
4483 case QETH_IPA_ARP_RC_FAILED:
4484 *rc = -EIO;
4485 return "operation failed";
4486 case QETH_IPA_ARP_RC_NOTSUPP:
4487 *rc = -EOPNOTSUPP;
4488 return "operation not supported";
4489 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4490 *rc = -EINVAL;
4491 return "argument out of range";
4492 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4493 *rc = -EOPNOTSUPP;
4494 return "query operation not supported";
4495 case QETH_IPA_ARP_RC_Q_NO_DATA:
4496 *rc = -ENOENT;
4497 return "no query data available";
4498 default:
4499 return "unknown error";
4503 static int
4504 qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4505 __u16, long);
4507 static int
4508 qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4510 int tmp;
4511 int rc;
4513 QETH_DBF_TEXT(trace,3,"arpstnoe");
4515 /* TODO: really not supported by GuestLAN? */
4516 if (card->info.guestlan)
4517 return -EOPNOTSUPP;
4518 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4519 PRINT_WARN("ARP processing not supported "
4520 "on %s!\n", QETH_CARD_IFNAME(card));
4521 return -EOPNOTSUPP;
4523 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4524 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4525 no_entries);
4526 if (rc) {
4527 tmp = rc;
4528 PRINT_WARN("Could not set number of ARP entries on %s: "
4529 "%s (0x%x/%d)\n",
4530 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4531 tmp, tmp);
4533 return rc;
4536 static inline void
4537 qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4538 struct qeth_arp_query_data *qdata,
4539 int entry_size, int uentry_size)
4541 char *entry_ptr;
4542 char *uentry_ptr;
4543 int i;
4545 entry_ptr = (char *)&qdata->data;
4546 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4547 for (i = 0; i < qdata->no_entries; ++i){
4548 /* strip off 32 bytes "media specific information" */
4549 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4550 entry_ptr += entry_size;
4551 uentry_ptr += uentry_size;
4555 static int
4556 qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4557 unsigned long data)
4559 struct qeth_ipa_cmd *cmd;
4560 struct qeth_arp_query_data *qdata;
4561 struct qeth_arp_query_info *qinfo;
4562 int entry_size;
4563 int uentry_size;
4564 int i;
4566 QETH_DBF_TEXT(trace,4,"arpquecb");
4568 qinfo = (struct qeth_arp_query_info *) reply->param;
4569 cmd = (struct qeth_ipa_cmd *) data;
4570 if (cmd->hdr.return_code) {
4571 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4572 return 0;
4574 if (cmd->data.setassparms.hdr.return_code) {
4575 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4576 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4577 return 0;
4579 qdata = &cmd->data.setassparms.data.query_arp;
4580 switch(qdata->reply_bits){
4581 case 5:
4582 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4583 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4584 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4585 break;
4586 case 7:
4587 /* fall through to default */
4588 default:
4589 /* tr is the same as eth -> entry7 */
4590 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4591 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4592 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4593 break;
4595 /* check if there is enough room in userspace */
4596 if ((qinfo->udata_len - qinfo->udata_offset) <
4597 qdata->no_entries * uentry_size){
4598 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4599 cmd->hdr.return_code = -ENOMEM;
4600 PRINT_WARN("query ARP user space buffer is too small for "
4601 "the returned number of ARP entries. "
4602 "Aborting query!\n");
4603 goto out_error;
4605 QETH_DBF_TEXT_(trace, 4, "anore%i",
4606 cmd->data.setassparms.hdr.number_of_replies);
4607 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4608 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4610 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4611 /* strip off "media specific information" */
4612 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4613 uentry_size);
4614 } else
4615 /*copy entries to user buffer*/
4616 memcpy(qinfo->udata + qinfo->udata_offset,
4617 (char *)&qdata->data, qdata->no_entries*uentry_size);
4619 qinfo->no_entries += qdata->no_entries;
4620 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4621 /* check if all replies received ... */
4622 if (cmd->data.setassparms.hdr.seq_no <
4623 cmd->data.setassparms.hdr.number_of_replies)
4624 return 1;
4625 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4626 /* keep STRIP_ENTRIES flag so the user program can distinguish
4627 * stripped entries from normal ones */
4628 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4629 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4630 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4631 return 0;
4632 out_error:
4633 i = 0;
4634 memcpy(qinfo->udata, &i, 4);
4635 return 0;
4638 static int
4639 qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4640 int len, int (*reply_cb)(struct qeth_card *,
4641 struct qeth_reply *,
4642 unsigned long),
4643 void *reply_param)
4645 QETH_DBF_TEXT(trace,4,"sendarp");
4647 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4648 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4649 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4650 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4651 reply_cb, reply_param);
4654 static int
4655 qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4656 int len, int (*reply_cb)(struct qeth_card *,
4657 struct qeth_reply *,
4658 unsigned long),
4659 void *reply_param)
4661 u16 s1, s2;
4663 QETH_DBF_TEXT(trace,4,"sendsnmp");
4665 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4666 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4667 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4668 /* adjust PDU length fields in IPA_PDU_HEADER */
4669 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4670 s2 = (u32) len;
4671 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4672 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4673 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4674 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4675 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4676 reply_cb, reply_param);
4679 static struct qeth_cmd_buffer *
4680 qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4681 __u16, __u16, enum qeth_prot_versions);
4682 static int
4683 qeth_arp_query(struct qeth_card *card, char *udata)
4685 struct qeth_cmd_buffer *iob;
4686 struct qeth_arp_query_info qinfo = {0, };
4687 int tmp;
4688 int rc;
4690 QETH_DBF_TEXT(trace,3,"arpquery");
4693 * currently GuestLAN does only deliver all zeros on query arp,
4694 * even though arp processing is supported (according to IPA supp.
4695 * funcs flags); since all zeros is no valueable information,
4696 * we say EOPNOTSUPP for all ARP functions
4698 /*if (card->info.guestlan)
4699 return -EOPNOTSUPP; */
4700 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4701 IPA_ARP_PROCESSING)) {
4702 PRINT_WARN("ARP processing not supported "
4703 "on %s!\n", QETH_CARD_IFNAME(card));
4704 return -EOPNOTSUPP;
4706 /* get size of userspace buffer and mask_bits -> 6 bytes */
4707 if (copy_from_user(&qinfo, udata, 6))
4708 return -EFAULT;
4709 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL)))
4710 return -ENOMEM;
4711 memset(qinfo.udata, 0, qinfo.udata_len);
4712 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4713 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4714 IPA_CMD_ASS_ARP_QUERY_INFO,
4715 sizeof(int),QETH_PROT_IPV4);
4717 rc = qeth_send_ipa_arp_cmd(card, iob,
4718 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4719 qeth_arp_query_cb, (void *)&qinfo);
4720 if (rc) {
4721 tmp = rc;
4722 PRINT_WARN("Error while querying ARP cache on %s: %s "
4723 "(0x%x/%d)\n",
4724 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4725 tmp, tmp);
4726 copy_to_user(udata, qinfo.udata, 4);
4727 } else {
4728 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4730 kfree(qinfo.udata);
4731 return rc;
4735 * SNMP command callback
4737 static int
4738 qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4739 unsigned long sdata)
4741 struct qeth_ipa_cmd *cmd;
4742 struct qeth_arp_query_info *qinfo;
4743 struct qeth_snmp_cmd *snmp;
4744 unsigned char *data;
4745 __u16 data_len;
4747 QETH_DBF_TEXT(trace,3,"snpcmdcb");
4749 cmd = (struct qeth_ipa_cmd *) sdata;
4750 data = (unsigned char *)((char *)cmd - reply->offset);
4751 qinfo = (struct qeth_arp_query_info *) reply->param;
4752 snmp = &cmd->data.setadapterparms.data.snmp;
4754 if (cmd->hdr.return_code) {
4755 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4756 return 0;
4758 if (cmd->data.setadapterparms.hdr.return_code) {
4759 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4760 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4761 return 0;
4763 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4764 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4765 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4766 else
4767 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4769 /* check if there is enough room in userspace */
4770 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4771 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4772 cmd->hdr.return_code = -ENOMEM;
4773 return 0;
4775 QETH_DBF_TEXT_(trace, 4, "snore%i",
4776 cmd->data.setadapterparms.hdr.used_total);
4777 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4778 /*copy entries to user buffer*/
4779 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4780 memcpy(qinfo->udata + qinfo->udata_offset,
4781 (char *)snmp,
4782 data_len + offsetof(struct qeth_snmp_cmd,data));
4783 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4784 } else {
4785 memcpy(qinfo->udata + qinfo->udata_offset,
4786 (char *)&snmp->request, data_len);
4788 qinfo->udata_offset += data_len;
4789 /* check if all replies received ... */
4790 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4791 cmd->data.setadapterparms.hdr.used_total);
4792 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4793 cmd->data.setadapterparms.hdr.seq_no);
4794 if (cmd->data.setadapterparms.hdr.seq_no <
4795 cmd->data.setadapterparms.hdr.used_total)
4796 return 1;
4797 return 0;
4800 static struct qeth_cmd_buffer *
4801 qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4802 enum qeth_prot_versions );
4804 static struct qeth_cmd_buffer *
4805 qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4807 struct qeth_cmd_buffer *iob;
4808 struct qeth_ipa_cmd *cmd;
4810 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4811 QETH_PROT_IPV4);
4812 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4813 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4814 cmd->data.setadapterparms.hdr.command_code = command;
4815 cmd->data.setadapterparms.hdr.used_total = 1;
4816 cmd->data.setadapterparms.hdr.seq_no = 1;
4818 return iob;
4822 * function to send SNMP commands to OSA-E card
4824 static int
4825 qeth_snmp_command(struct qeth_card *card, char *udata)
4827 struct qeth_cmd_buffer *iob;
4828 struct qeth_ipa_cmd *cmd;
4829 struct qeth_snmp_ureq *ureq;
4830 int req_len;
4831 struct qeth_arp_query_info qinfo = {0, };
4832 int rc = 0;
4834 QETH_DBF_TEXT(trace,3,"snmpcmd");
4836 if (card->info.guestlan)
4837 return -EOPNOTSUPP;
4839 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4840 (!card->options.layer2) ) {
4841 PRINT_WARN("SNMP Query MIBS not supported "
4842 "on %s!\n", QETH_CARD_IFNAME(card));
4843 return -EOPNOTSUPP;
4845 /* skip 4 bytes (data_len struct member) to get req_len */
4846 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4847 return -EFAULT;
4848 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4849 if (!ureq) {
4850 QETH_DBF_TEXT(trace, 2, "snmpnome");
4851 return -ENOMEM;
4853 if (copy_from_user(ureq, udata,
4854 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
4855 kfree(ureq);
4856 return -EFAULT;
4858 qinfo.udata_len = ureq->hdr.data_len;
4859 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL))){
4860 kfree(ureq);
4861 return -ENOMEM;
4863 memset(qinfo.udata, 0, qinfo.udata_len);
4864 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4866 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
4867 QETH_SNMP_SETADP_CMDLENGTH + req_len);
4868 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4869 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
4870 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
4871 qeth_snmp_command_cb, (void *)&qinfo);
4872 if (rc)
4873 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
4874 QETH_CARD_IFNAME(card), rc);
4875 else
4876 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4878 kfree(ureq);
4879 kfree(qinfo.udata);
4880 return rc;
4883 static int
4884 qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
4885 unsigned long);
4887 static int
4888 qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
4889 __u16, long,
4890 int (*reply_cb)
4891 (struct qeth_card *, struct qeth_reply *, unsigned long),
4892 void *reply_param);
4894 static int
4895 qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
4897 struct qeth_cmd_buffer *iob;
4898 char buf[16];
4899 int tmp;
4900 int rc;
4902 QETH_DBF_TEXT(trace,3,"arpadent");
4905 * currently GuestLAN does only deliver all zeros on query arp,
4906 * even though arp processing is supported (according to IPA supp.
4907 * funcs flags); since all zeros is no valueable information,
4908 * we say EOPNOTSUPP for all ARP functions
4910 if (card->info.guestlan)
4911 return -EOPNOTSUPP;
4912 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4913 PRINT_WARN("ARP processing not supported "
4914 "on %s!\n", QETH_CARD_IFNAME(card));
4915 return -EOPNOTSUPP;
4918 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4919 IPA_CMD_ASS_ARP_ADD_ENTRY,
4920 sizeof(struct qeth_arp_cache_entry),
4921 QETH_PROT_IPV4);
4922 rc = qeth_send_setassparms(card, iob,
4923 sizeof(struct qeth_arp_cache_entry),
4924 (unsigned long) entry,
4925 qeth_default_setassparms_cb, NULL);
4926 if (rc) {
4927 tmp = rc;
4928 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
4929 PRINT_WARN("Could not add ARP entry for address %s on %s: "
4930 "%s (0x%x/%d)\n",
4931 buf, QETH_CARD_IFNAME(card),
4932 qeth_arp_get_error_cause(&rc), tmp, tmp);
4934 return rc;
4937 static int
4938 qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
4940 struct qeth_cmd_buffer *iob;
4941 char buf[16] = {0, };
4942 int tmp;
4943 int rc;
4945 QETH_DBF_TEXT(trace,3,"arprment");
4948 * currently GuestLAN does only deliver all zeros on query arp,
4949 * even though arp processing is supported (according to IPA supp.
4950 * funcs flags); since all zeros is no valueable information,
4951 * we say EOPNOTSUPP for all ARP functions
4953 if (card->info.guestlan)
4954 return -EOPNOTSUPP;
4955 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4956 PRINT_WARN("ARP processing not supported "
4957 "on %s!\n", QETH_CARD_IFNAME(card));
4958 return -EOPNOTSUPP;
4960 memcpy(buf, entry, 12);
4961 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4962 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
4964 QETH_PROT_IPV4);
4965 rc = qeth_send_setassparms(card, iob,
4966 12, (unsigned long)buf,
4967 qeth_default_setassparms_cb, NULL);
4968 if (rc) {
4969 tmp = rc;
4970 memset(buf, 0, 16);
4971 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
4972 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
4973 "%s (0x%x/%d)\n",
4974 buf, QETH_CARD_IFNAME(card),
4975 qeth_arp_get_error_cause(&rc), tmp, tmp);
4977 return rc;
4980 static int
4981 qeth_arp_flush_cache(struct qeth_card *card)
4983 int rc;
4984 int tmp;
4986 QETH_DBF_TEXT(trace,3,"arpflush");
4989 * currently GuestLAN does only deliver all zeros on query arp,
4990 * even though arp processing is supported (according to IPA supp.
4991 * funcs flags); since all zeros is no valueable information,
4992 * we say EOPNOTSUPP for all ARP functions
4994 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
4995 return -EOPNOTSUPP;
4996 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4997 PRINT_WARN("ARP processing not supported "
4998 "on %s!\n", QETH_CARD_IFNAME(card));
4999 return -EOPNOTSUPP;
5001 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5002 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5003 if (rc){
5004 tmp = rc;
5005 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5006 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5007 tmp, tmp);
5009 return rc;
5012 static int
5013 qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5015 struct qeth_card *card = (struct qeth_card *)dev->priv;
5016 struct qeth_arp_cache_entry arp_entry;
5017 struct mii_ioctl_data *mii_data;
5018 int rc = 0;
5020 if (!card)
5021 return -ENODEV;
5023 if ((card->state != CARD_STATE_UP) &&
5024 (card->state != CARD_STATE_SOFTSETUP))
5025 return -ENODEV;
5027 switch (cmd){
5028 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5029 if ( !capable(CAP_NET_ADMIN) ||
5030 (card->options.layer2) ) {
5031 rc = -EPERM;
5032 break;
5034 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5035 break;
5036 case SIOC_QETH_ARP_QUERY_INFO:
5037 if ( !capable(CAP_NET_ADMIN) ||
5038 (card->options.layer2) ) {
5039 rc = -EPERM;
5040 break;
5042 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5043 break;
5044 case SIOC_QETH_ARP_ADD_ENTRY:
5045 if ( !capable(CAP_NET_ADMIN) ||
5046 (card->options.layer2) ) {
5047 rc = -EPERM;
5048 break;
5050 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5051 sizeof(struct qeth_arp_cache_entry)))
5052 rc = -EFAULT;
5053 else
5054 rc = qeth_arp_add_entry(card, &arp_entry);
5055 break;
5056 case SIOC_QETH_ARP_REMOVE_ENTRY:
5057 if ( !capable(CAP_NET_ADMIN) ||
5058 (card->options.layer2) ) {
5059 rc = -EPERM;
5060 break;
5062 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5063 sizeof(struct qeth_arp_cache_entry)))
5064 rc = -EFAULT;
5065 else
5066 rc = qeth_arp_remove_entry(card, &arp_entry);
5067 break;
5068 case SIOC_QETH_ARP_FLUSH_CACHE:
5069 if ( !capable(CAP_NET_ADMIN) ||
5070 (card->options.layer2) ) {
5071 rc = -EPERM;
5072 break;
5074 rc = qeth_arp_flush_cache(card);
5075 break;
5076 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5077 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5078 break;
5079 case SIOC_QETH_GET_CARD_TYPE:
5080 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5081 !card->info.guestlan)
5082 return 1;
5083 return 0;
5084 break;
5085 case SIOCGMIIPHY:
5086 mii_data = if_mii(rq);
5087 mii_data->phy_id = 0;
5088 break;
5089 case SIOCGMIIREG:
5090 mii_data = if_mii(rq);
5091 if (mii_data->phy_id != 0)
5092 rc = -EINVAL;
5093 else
5094 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5095 mii_data->reg_num);
5096 break;
5097 case SIOCSMIIREG:
5098 rc = -EOPNOTSUPP;
5099 break;
5100 /* TODO: remove return if qeth_mdio_write does something */
5101 if (!capable(CAP_NET_ADMIN)){
5102 rc = -EPERM;
5103 break;
5105 mii_data = if_mii(rq);
5106 if (mii_data->phy_id != 0)
5107 rc = -EINVAL;
5108 else
5109 qeth_mdio_write(dev, mii_data->phy_id, mii_data->reg_num,
5110 mii_data->val_in);
5111 break;
5112 default:
5113 rc = -EOPNOTSUPP;
5115 if (rc)
5116 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5117 return rc;
5120 static struct net_device_stats *
5121 qeth_get_stats(struct net_device *dev)
5123 struct qeth_card *card;
5125 card = (struct qeth_card *) (dev->priv);
5127 QETH_DBF_TEXT(trace,5,"getstat");
5129 return &card->stats;
5132 static int
5133 qeth_change_mtu(struct net_device *dev, int new_mtu)
5135 struct qeth_card *card;
5136 char dbf_text[15];
5138 card = (struct qeth_card *) (dev->priv);
5140 QETH_DBF_TEXT(trace,4,"chgmtu");
5141 sprintf(dbf_text, "%8x", new_mtu);
5142 QETH_DBF_TEXT(trace,4,dbf_text);
5144 if (new_mtu < 64)
5145 return -EINVAL;
5146 if (new_mtu > 65535)
5147 return -EINVAL;
5148 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5149 (!qeth_mtu_is_valid(card, new_mtu)))
5150 return -EINVAL;
5151 dev->mtu = new_mtu;
5152 return 0;
5155 #ifdef CONFIG_QETH_VLAN
5156 static void
5157 qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5159 struct qeth_card *card;
5160 unsigned long flags;
5162 QETH_DBF_TEXT(trace,4,"vlanreg");
5164 card = (struct qeth_card *) dev->priv;
5165 spin_lock_irqsave(&card->vlanlock, flags);
5166 card->vlangrp = grp;
5167 spin_unlock_irqrestore(&card->vlanlock, flags);
5170 static inline void
5171 qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5172 unsigned short vid)
5174 int i;
5175 struct sk_buff *skb;
5176 struct sk_buff_head tmp_list;
5178 skb_queue_head_init(&tmp_list);
5179 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5180 while ((skb = skb_dequeue(&buf->skb_list))){
5181 if (vlan_tx_tag_present(skb) &&
5182 (vlan_tx_tag_get(skb) == vid)) {
5183 atomic_dec(&skb->users);
5184 dev_kfree_skb(skb);
5185 } else
5186 skb_queue_tail(&tmp_list, skb);
5189 while ((skb = skb_dequeue(&tmp_list)))
5190 skb_queue_tail(&buf->skb_list, skb);
5193 static void
5194 qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5196 int i, j;
5198 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5199 for (i = 0; i < card->qdio.no_out_queues; ++i){
5200 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5201 qeth_free_vlan_buffer(card, &card->qdio.
5202 out_qs[i]->bufs[j], vid);
5206 static void
5207 qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5209 struct in_device *in_dev;
5210 struct in_ifaddr *ifa;
5211 struct qeth_ipaddr *addr;
5213 QETH_DBF_TEXT(trace, 4, "frvaddr4");
5214 if (!card->vlangrp)
5215 return;
5216 rcu_read_lock();
5217 in_dev = __in_dev_get(card->vlangrp->vlan_devices[vid]);
5218 if (!in_dev)
5219 goto out;
5220 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5221 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5222 if (addr){
5223 addr->u.a4.addr = ifa->ifa_address;
5224 addr->u.a4.mask = ifa->ifa_mask;
5225 addr->type = QETH_IP_TYPE_NORMAL;
5226 if (!qeth_delete_ip(card, addr))
5227 kfree(addr);
5230 out:
5231 rcu_read_unlock();
5234 static void
5235 qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5237 #ifdef CONFIG_QETH_IPV6
5238 struct inet6_dev *in6_dev;
5239 struct inet6_ifaddr *ifa;
5240 struct qeth_ipaddr *addr;
5242 QETH_DBF_TEXT(trace, 4, "frvaddr6");
5243 if (!card->vlangrp)
5244 return;
5245 in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]);
5246 if (!in6_dev)
5247 return;
5248 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5249 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5250 if (addr){
5251 memcpy(&addr->u.a6.addr, &ifa->addr,
5252 sizeof(struct in6_addr));
5253 addr->u.a6.pfxlen = ifa->prefix_len;
5254 addr->type = QETH_IP_TYPE_NORMAL;
5255 if (!qeth_delete_ip(card, addr))
5256 kfree(addr);
5259 in6_dev_put(in6_dev);
5260 #endif /* CONFIG_QETH_IPV6 */
5263 static void
5264 qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5265 enum qeth_ipa_cmds ipacmd)
5267 int rc;
5268 struct qeth_ipa_cmd *cmd;
5269 struct qeth_cmd_buffer *iob;
5271 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5272 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5273 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5274 cmd->data.setdelvlan.vlan_id = i;
5276 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
5277 if (rc) {
5278 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5279 "Continuing\n",i, QETH_CARD_IFNAME(card), rc);
5280 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", ipacmd);
5281 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5282 QETH_DBF_TEXT_(trace, 2, "err%d", rc);
5286 static void
5287 qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5289 unsigned short i;
5291 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5293 if (!card->vlangrp)
5294 return;
5295 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5296 if (card->vlangrp->vlan_devices[i] == NULL)
5297 continue;
5298 if (clear)
5299 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5300 else
5301 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5305 /*add_vid is layer 2 used only ....*/
5306 static void
5307 qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5309 struct qeth_card *card;
5311 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5313 card = (struct qeth_card *) dev->priv;
5314 if (!card->options.layer2)
5315 return;
5316 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5319 /*... kill_vid used for both modes*/
5320 static void
5321 qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5323 struct qeth_card *card;
5324 unsigned long flags;
5326 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5328 card = (struct qeth_card *) dev->priv;
5329 /* free all skbs for the vlan device */
5330 qeth_free_vlan_skbs(card, vid);
5331 spin_lock_irqsave(&card->vlanlock, flags);
5332 /* unregister IP addresses of vlan device */
5333 qeth_free_vlan_addresses4(card, vid);
5334 qeth_free_vlan_addresses6(card, vid);
5335 if (card->vlangrp)
5336 card->vlangrp->vlan_devices[vid] = NULL;
5337 spin_unlock_irqrestore(&card->vlanlock, flags);
5338 if (card->options.layer2)
5339 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5340 qeth_set_multicast_list(card->dev);
5342 #endif
5345 * set multicast address on card
5347 static void
5348 qeth_set_multicast_list(struct net_device *dev)
5350 struct qeth_card *card = (struct qeth_card *) dev->priv;
5352 QETH_DBF_TEXT(trace,3,"setmulti");
5353 qeth_delete_mc_addresses(card);
5354 qeth_add_multicast_ipv4(card);
5355 #ifdef CONFIG_QETH_IPV6
5356 qeth_add_multicast_ipv6(card);
5357 #endif
5358 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
5359 schedule_work(&card->kernel_thread_starter);
5362 static int
5363 qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5365 return 0;
5368 static void
5369 qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5371 if (dev->type == ARPHRD_IEEE802_TR)
5372 ip_tr_mc_map(ipm, mac);
5373 else
5374 ip_eth_mc_map(ipm, mac);
5377 static struct qeth_ipaddr *
5378 qeth_get_addr_buffer(enum qeth_prot_versions prot)
5380 struct qeth_ipaddr *addr;
5382 addr = kmalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5383 if (addr == NULL) {
5384 PRINT_WARN("Not enough memory to add address\n");
5385 return NULL;
5387 memset(addr,0,sizeof(struct qeth_ipaddr));
5388 addr->type = QETH_IP_TYPE_NORMAL;
5389 addr->proto = prot;
5390 return addr;
5393 static void
5394 qeth_delete_mc_addresses(struct qeth_card *card)
5396 struct qeth_ipaddr *iptodo;
5397 unsigned long flags;
5399 QETH_DBF_TEXT(trace,4,"delmc");
5400 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5401 if (!iptodo) {
5402 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5403 return;
5405 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5406 spin_lock_irqsave(&card->ip_lock, flags);
5407 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5408 kfree(iptodo);
5409 spin_unlock_irqrestore(&card->ip_lock, flags);
5412 static inline void
5413 qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5415 struct qeth_ipaddr *ipm;
5416 struct ip_mc_list *im4;
5417 char buf[MAX_ADDR_LEN];
5419 QETH_DBF_TEXT(trace,4,"addmc");
5420 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5421 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5422 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5423 if (!ipm)
5424 continue;
5425 ipm->u.a4.addr = im4->multiaddr;
5426 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5427 ipm->is_multicast = 1;
5428 if (!qeth_add_ip(card,ipm))
5429 kfree(ipm);
5433 static inline void
5434 qeth_add_vlan_mc(struct qeth_card *card)
5436 #ifdef CONFIG_QETH_VLAN
5437 struct in_device *in_dev;
5438 struct vlan_group *vg;
5439 int i;
5441 QETH_DBF_TEXT(trace,4,"addmcvl");
5442 if ( ((card->options.layer2 == 0) &&
5443 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5444 (card->vlangrp == NULL) )
5445 return ;
5447 vg = card->vlangrp;
5448 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5449 if (vg->vlan_devices[i] == NULL ||
5450 !(vg->vlan_devices[i]->flags & IFF_UP))
5451 continue;
5452 in_dev = in_dev_get(vg->vlan_devices[i]);
5453 if (!in_dev)
5454 continue;
5455 read_lock(&in_dev->mc_list_lock);
5456 qeth_add_mc(card,in_dev);
5457 read_unlock(&in_dev->mc_list_lock);
5458 in_dev_put(in_dev);
5460 #endif
5463 static void
5464 qeth_add_multicast_ipv4(struct qeth_card *card)
5466 struct in_device *in4_dev;
5468 QETH_DBF_TEXT(trace,4,"chkmcv4");
5469 in4_dev = in_dev_get(card->dev);
5470 if (in4_dev == NULL)
5471 return;
5472 read_lock(&in4_dev->mc_list_lock);
5473 qeth_add_mc(card, in4_dev);
5474 qeth_add_vlan_mc(card);
5475 read_unlock(&in4_dev->mc_list_lock);
5476 in_dev_put(in4_dev);
5479 #ifdef CONFIG_QETH_IPV6
5480 static inline void
5481 qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5483 struct qeth_ipaddr *ipm;
5484 struct ifmcaddr6 *im6;
5485 char buf[MAX_ADDR_LEN];
5487 QETH_DBF_TEXT(trace,4,"addmc6");
5488 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5489 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5490 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5491 if (!ipm)
5492 continue;
5493 ipm->is_multicast = 1;
5494 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5495 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5496 sizeof(struct in6_addr));
5497 if (!qeth_add_ip(card,ipm))
5498 kfree(ipm);
5502 static inline void
5503 qeth_add_vlan_mc6(struct qeth_card *card)
5505 #ifdef CONFIG_QETH_VLAN
5506 struct inet6_dev *in_dev;
5507 struct vlan_group *vg;
5508 int i;
5510 QETH_DBF_TEXT(trace,4,"admc6vl");
5511 if ( ((card->options.layer2 == 0) &&
5512 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5513 (card->vlangrp == NULL))
5514 return ;
5516 vg = card->vlangrp;
5517 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5518 if (vg->vlan_devices[i] == NULL ||
5519 !(vg->vlan_devices[i]->flags & IFF_UP))
5520 continue;
5521 in_dev = in6_dev_get(vg->vlan_devices[i]);
5522 if (!in_dev)
5523 continue;
5524 read_lock(&in_dev->lock);
5525 qeth_add_mc6(card,in_dev);
5526 read_unlock(&in_dev->lock);
5527 in6_dev_put(in_dev);
5529 #endif /* CONFIG_QETH_VLAN */
5532 static void
5533 qeth_add_multicast_ipv6(struct qeth_card *card)
5535 struct inet6_dev *in6_dev;
5537 QETH_DBF_TEXT(trace,4,"chkmcv6");
5538 if ((card->options.layer2 == 0) &&
5539 (!qeth_is_supported(card, IPA_IPV6)) )
5540 return ;
5542 in6_dev = in6_dev_get(card->dev);
5543 if (in6_dev == NULL)
5544 return;
5545 read_lock(&in6_dev->lock);
5546 qeth_add_mc6(card, in6_dev);
5547 qeth_add_vlan_mc6(card);
5548 read_unlock(&in6_dev->lock);
5549 in6_dev_put(in6_dev);
5551 #endif /* CONFIG_QETH_IPV6 */
5553 static int
5554 qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5555 enum qeth_ipa_cmds ipacmd,
5556 int (*reply_cb) (struct qeth_card *,
5557 struct qeth_reply*,
5558 unsigned long))
5560 struct qeth_ipa_cmd *cmd;
5561 struct qeth_cmd_buffer *iob;
5563 QETH_DBF_TEXT(trace, 2, "L2sdmac");
5564 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5565 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5566 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5567 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5568 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5571 static int
5572 qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5573 struct qeth_reply *reply,
5574 unsigned long data)
5576 struct qeth_ipa_cmd *cmd;
5577 __u8 *mac;
5579 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5580 cmd = (struct qeth_ipa_cmd *) data;
5581 mac = &cmd->data.setdelmac.mac[0];
5582 /* MAC already registered, needed in couple/uncouple case */
5583 if (cmd->hdr.return_code == 0x2005) {
5584 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5585 "already existing on %s \n",
5586 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5587 QETH_CARD_IFNAME(card));
5588 cmd->hdr.return_code = 0;
5590 if (cmd->hdr.return_code)
5591 PRINT_ERR("Could not set group MAC " \
5592 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5593 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5594 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5595 return 0;
5598 static int
5599 qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5601 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5602 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5603 qeth_layer2_send_setgroupmac_cb);
5606 static int
5607 qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5608 struct qeth_reply *reply,
5609 unsigned long data)
5611 struct qeth_ipa_cmd *cmd;
5612 __u8 *mac;
5614 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5615 cmd = (struct qeth_ipa_cmd *) data;
5616 mac = &cmd->data.setdelmac.mac[0];
5617 if (cmd->hdr.return_code)
5618 PRINT_ERR("Could not delete group MAC " \
5619 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5620 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5621 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5622 return 0;
5625 static int
5626 qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5628 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5629 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5630 qeth_layer2_send_delgroupmac_cb);
5633 static int
5634 qeth_layer2_send_setmac_cb(struct qeth_card *card,
5635 struct qeth_reply *reply,
5636 unsigned long data)
5638 struct qeth_ipa_cmd *cmd;
5640 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5641 cmd = (struct qeth_ipa_cmd *) data;
5642 if (cmd->hdr.return_code) {
5643 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5644 PRINT_WARN("Error in registering MAC address on " \
5645 "device %s: x%x\n", CARD_BUS_ID(card),
5646 cmd->hdr.return_code);
5647 card->info.layer2_mac_registered = 0;
5648 cmd->hdr.return_code = -EIO;
5649 } else {
5650 card->info.layer2_mac_registered = 1;
5651 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5652 OSA_ADDR_LEN);
5653 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5654 "successfully registered on device %s\n",
5655 card->dev->dev_addr[0], card->dev->dev_addr[1],
5656 card->dev->dev_addr[2], card->dev->dev_addr[3],
5657 card->dev->dev_addr[4], card->dev->dev_addr[5],
5658 card->dev->name);
5660 return 0;
5663 static int
5664 qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
5666 QETH_DBF_TEXT(trace, 2, "L2Setmac");
5667 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
5668 qeth_layer2_send_setmac_cb);
5671 static int
5672 qeth_layer2_send_delmac_cb(struct qeth_card *card,
5673 struct qeth_reply *reply,
5674 unsigned long data)
5676 struct qeth_ipa_cmd *cmd;
5678 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
5679 cmd = (struct qeth_ipa_cmd *) data;
5680 if (cmd->hdr.return_code) {
5681 PRINT_WARN("Error in deregistering MAC address on " \
5682 "device %s: x%x\n", CARD_BUS_ID(card),
5683 cmd->hdr.return_code);
5684 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5685 cmd->hdr.return_code = -EIO;
5686 return 0;
5688 card->info.layer2_mac_registered = 0;
5690 return 0;
5692 static int
5693 qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
5695 QETH_DBF_TEXT(trace, 2, "L2Delmac");
5696 if (!card->info.layer2_mac_registered)
5697 return 0;
5698 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
5699 qeth_layer2_send_delmac_cb);
5702 static int
5703 qeth_layer2_set_mac_address(struct net_device *dev, void *p)
5705 struct sockaddr *addr = p;
5706 struct qeth_card *card;
5707 int rc = 0;
5709 QETH_DBF_TEXT(trace, 3, "setmac");
5711 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
5712 QETH_DBF_TEXT(trace, 3, "setmcINV");
5713 return -EOPNOTSUPP;
5715 card = (struct qeth_card *) dev->priv;
5717 if (!card->options.layer2) {
5718 PRINT_WARN("Setting MAC address on %s is not supported"
5719 "in Layer 3 mode.\n", dev->name);
5720 QETH_DBF_TEXT(trace, 3, "setmcLY3");
5721 return -EOPNOTSUPP;
5723 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
5724 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
5725 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
5726 if (!rc)
5727 rc = qeth_layer2_send_setmac(card, addr->sa_data);
5728 return rc;
5731 static void
5732 qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
5733 __u8 command, enum qeth_prot_versions prot)
5735 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
5736 cmd->hdr.command = command;
5737 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
5738 cmd->hdr.seqno = card->seqno.ipa;
5739 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
5740 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
5741 if (card->options.layer2)
5742 cmd->hdr.prim_version_no = 2;
5743 else
5744 cmd->hdr.prim_version_no = 1;
5745 cmd->hdr.param_count = 1;
5746 cmd->hdr.prot_version = prot;
5747 cmd->hdr.ipa_supported = 0;
5748 cmd->hdr.ipa_enabled = 0;
5751 static struct qeth_cmd_buffer *
5752 qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
5753 enum qeth_prot_versions prot)
5755 struct qeth_cmd_buffer *iob;
5756 struct qeth_ipa_cmd *cmd;
5758 iob = qeth_wait_for_buffer(&card->write);
5759 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5760 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
5762 return iob;
5765 static int
5766 qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
5768 int rc;
5769 struct qeth_cmd_buffer *iob;
5770 struct qeth_ipa_cmd *cmd;
5772 QETH_DBF_TEXT(trace,4,"setdelmc");
5774 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
5775 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5776 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
5777 if (addr->proto == QETH_PROT_IPV6)
5778 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
5779 sizeof(struct in6_addr));
5780 else
5781 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
5783 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
5785 return rc;
5787 static inline void
5788 qeth_fill_netmask(u8 *netmask, unsigned int len)
5790 int i,j;
5791 for (i=0;i<16;i++) {
5792 j=(len)-(i*8);
5793 if (j >= 8)
5794 netmask[i] = 0xff;
5795 else if (j > 0)
5796 netmask[i] = (u8)(0xFF00>>j);
5797 else
5798 netmask[i] = 0;
5802 static int
5803 qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
5804 int ipacmd, unsigned int flags)
5806 int rc;
5807 struct qeth_cmd_buffer *iob;
5808 struct qeth_ipa_cmd *cmd;
5809 __u8 netmask[16];
5811 QETH_DBF_TEXT(trace,4,"setdelip");
5812 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
5814 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
5815 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5816 if (addr->proto == QETH_PROT_IPV6) {
5817 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
5818 sizeof(struct in6_addr));
5819 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
5820 memcpy(cmd->data.setdelip6.mask, netmask,
5821 sizeof(struct in6_addr));
5822 cmd->data.setdelip6.flags = flags;
5823 } else {
5824 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
5825 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
5826 cmd->data.setdelip4.flags = flags;
5829 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
5831 return rc;
5834 static int
5835 qeth_layer2_register_addr_entry(struct qeth_card *card,
5836 struct qeth_ipaddr *addr)
5838 if (!addr->is_multicast)
5839 return 0;
5840 QETH_DBF_TEXT(trace, 2, "setgmac");
5841 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
5842 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
5845 static int
5846 qeth_layer2_deregister_addr_entry(struct qeth_card *card,
5847 struct qeth_ipaddr *addr)
5849 if (!addr->is_multicast)
5850 return 0;
5851 QETH_DBF_TEXT(trace, 2, "delgmac");
5852 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
5853 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
5856 static int
5857 qeth_layer3_register_addr_entry(struct qeth_card *card,
5858 struct qeth_ipaddr *addr)
5860 char buf[50];
5861 int rc;
5862 int cnt = 3;
5864 if (addr->proto == QETH_PROT_IPV4) {
5865 QETH_DBF_TEXT(trace, 2,"setaddr4");
5866 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
5867 } else if (addr->proto == QETH_PROT_IPV6) {
5868 QETH_DBF_TEXT(trace, 2, "setaddr6");
5869 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
5870 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
5871 } else {
5872 QETH_DBF_TEXT(trace, 2, "setaddr?");
5873 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
5875 do {
5876 if (addr->is_multicast)
5877 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
5878 else
5879 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
5880 addr->set_flags);
5881 if (rc)
5882 QETH_DBF_TEXT(trace, 2, "failed");
5883 } while ((--cnt > 0) && rc);
5884 if (rc){
5885 QETH_DBF_TEXT(trace, 2, "FAILED");
5886 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
5887 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
5888 buf, rc, rc);
5890 return rc;
5893 static int
5894 qeth_layer3_deregister_addr_entry(struct qeth_card *card,
5895 struct qeth_ipaddr *addr)
5897 //char buf[50];
5898 int rc;
5900 if (addr->proto == QETH_PROT_IPV4) {
5901 QETH_DBF_TEXT(trace, 2,"deladdr4");
5902 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
5903 } else if (addr->proto == QETH_PROT_IPV6) {
5904 QETH_DBF_TEXT(trace, 2, "deladdr6");
5905 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
5906 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
5907 } else {
5908 QETH_DBF_TEXT(trace, 2, "deladdr?");
5909 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
5911 if (addr->is_multicast)
5912 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
5913 else
5914 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
5915 addr->del_flags);
5916 if (rc) {
5917 QETH_DBF_TEXT(trace, 2, "failed");
5918 /* TODO: re-activate this warning as soon as we have a
5919 * clean mirco code
5920 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
5921 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
5922 buf, rc);
5925 return rc;
5928 static int
5929 qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
5931 if (card->options.layer2)
5932 return qeth_layer2_register_addr_entry(card, addr);
5934 return qeth_layer3_register_addr_entry(card, addr);
5937 static int
5938 qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
5940 if (card->options.layer2)
5941 return qeth_layer2_deregister_addr_entry(card, addr);
5943 return qeth_layer3_deregister_addr_entry(card, addr);
5946 static u32
5947 qeth_ethtool_get_tx_csum(struct net_device *dev)
5949 /* We may need to say that we support tx csum offload if
5950 * we do EDDP or TSO. There are discussions going on to
5951 * enforce rules in the stack and in ethtool that make
5952 * SG and TSO depend on HW_CSUM. At the moment there are
5953 * no such rules....
5954 * If we say yes here, we have to checksum outbound packets
5955 * any time. */
5956 return 0;
5959 static int
5960 qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
5962 return -EINVAL;
5965 static u32
5966 qeth_ethtool_get_rx_csum(struct net_device *dev)
5968 struct qeth_card *card = (struct qeth_card *)dev->priv;
5970 return (card->options.checksum_type == HW_CHECKSUMMING);
5973 static int
5974 qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
5976 struct qeth_card *card = (struct qeth_card *)dev->priv;
5978 if ((card->state != CARD_STATE_DOWN) &&
5979 (card->state != CARD_STATE_RECOVER))
5980 return -EPERM;
5981 if (data)
5982 card->options.checksum_type = HW_CHECKSUMMING;
5983 else
5984 card->options.checksum_type = SW_CHECKSUMMING;
5985 return 0;
5988 static u32
5989 qeth_ethtool_get_sg(struct net_device *dev)
5991 struct qeth_card *card = (struct qeth_card *)dev->priv;
5993 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
5994 (dev->features & NETIF_F_SG));
5997 static int
5998 qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6000 struct qeth_card *card = (struct qeth_card *)dev->priv;
6002 if (data) {
6003 if (card->options.large_send != QETH_LARGE_SEND_NO)
6004 dev->features |= NETIF_F_SG;
6005 else {
6006 dev->features &= ~NETIF_F_SG;
6007 return -EINVAL;
6009 } else
6010 dev->features &= ~NETIF_F_SG;
6011 return 0;
6014 static u32
6015 qeth_ethtool_get_tso(struct net_device *dev)
6017 struct qeth_card *card = (struct qeth_card *)dev->priv;
6019 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6020 (dev->features & NETIF_F_TSO));
6023 static int
6024 qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6026 struct qeth_card *card = (struct qeth_card *)dev->priv;
6028 if (data) {
6029 if (card->options.large_send != QETH_LARGE_SEND_NO)
6030 dev->features |= NETIF_F_TSO;
6031 else {
6032 dev->features &= ~NETIF_F_TSO;
6033 return -EINVAL;
6035 } else
6036 dev->features &= ~NETIF_F_TSO;
6037 return 0;
6040 static struct ethtool_ops qeth_ethtool_ops = {
6041 .get_tx_csum = qeth_ethtool_get_tx_csum,
6042 .set_tx_csum = qeth_ethtool_set_tx_csum,
6043 .get_rx_csum = qeth_ethtool_get_rx_csum,
6044 .set_rx_csum = qeth_ethtool_set_rx_csum,
6045 .get_sg = qeth_ethtool_get_sg,
6046 .set_sg = qeth_ethtool_set_sg,
6047 .get_tso = qeth_ethtool_get_tso,
6048 .set_tso = qeth_ethtool_set_tso,
6051 static int
6052 qeth_netdev_init(struct net_device *dev)
6054 struct qeth_card *card;
6056 card = (struct qeth_card *) dev->priv;
6058 QETH_DBF_TEXT(trace,3,"initdev");
6060 dev->tx_timeout = &qeth_tx_timeout;
6061 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6062 dev->open = qeth_open;
6063 dev->stop = qeth_stop;
6064 dev->hard_start_xmit = qeth_hard_start_xmit;
6065 dev->do_ioctl = qeth_do_ioctl;
6066 dev->get_stats = qeth_get_stats;
6067 dev->change_mtu = qeth_change_mtu;
6068 dev->neigh_setup = qeth_neigh_setup;
6069 dev->set_multicast_list = qeth_set_multicast_list;
6070 #ifdef CONFIG_QETH_VLAN
6071 dev->vlan_rx_register = qeth_vlan_rx_register;
6072 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6073 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6074 #endif
6075 dev->hard_header = card->orig_hard_header;
6076 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6077 dev->rebuild_header = NULL;
6078 dev->hard_header = NULL;
6079 if (card->options.fake_ll)
6080 dev->hard_header = qeth_fake_header;
6081 dev->header_cache_update = NULL;
6082 dev->hard_header_cache = NULL;
6084 #ifdef CONFIG_QETH_IPV6
6085 /*IPv6 address autoconfiguration stuff*/
6086 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6087 card->dev->dev_id = card->info.unique_id & 0xffff;
6088 #endif
6089 dev->hard_header_parse = NULL;
6090 dev->set_mac_address = qeth_layer2_set_mac_address;
6091 dev->flags |= qeth_get_netdev_flags(card);
6092 if ((card->options.fake_broadcast) ||
6093 (card->info.broadcast_capable))
6094 dev->flags |= IFF_BROADCAST;
6095 dev->hard_header_len =
6096 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6097 dev->addr_len = OSA_ADDR_LEN;
6098 dev->mtu = card->info.initial_mtu;
6100 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6102 SET_MODULE_OWNER(dev);
6103 return 0;
6106 static void
6107 qeth_init_func_level(struct qeth_card *card)
6109 if (card->ipato.enabled) {
6110 if (card->info.type == QETH_CARD_TYPE_IQD)
6111 card->info.func_level =
6112 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6113 else
6114 card->info.func_level =
6115 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6116 } else {
6117 if (card->info.type == QETH_CARD_TYPE_IQD)
6118 card->info.func_level =
6119 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6120 else
6121 card->info.func_level =
6122 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6127 * hardsetup card, initialize MPC and QDIO stuff
6129 static int
6130 qeth_hardsetup_card(struct qeth_card *card)
6132 int retries = 3;
6133 int rc;
6135 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6137 retry:
6138 if (retries < 3){
6139 PRINT_WARN("Retrying to do IDX activates.\n");
6140 ccw_device_set_offline(CARD_DDEV(card));
6141 ccw_device_set_offline(CARD_WDEV(card));
6142 ccw_device_set_offline(CARD_RDEV(card));
6143 ccw_device_set_online(CARD_RDEV(card));
6144 ccw_device_set_online(CARD_WDEV(card));
6145 ccw_device_set_online(CARD_DDEV(card));
6147 rc = qeth_qdio_clear_card(card,card->info.type==QETH_CARD_TYPE_OSAE);
6148 if (rc == -ERESTARTSYS) {
6149 QETH_DBF_TEXT(setup, 2, "break1");
6150 return rc;
6151 } else if (rc) {
6152 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6153 if (--retries < 0)
6154 goto out;
6155 else
6156 goto retry;
6158 if ((rc = qeth_get_unitaddr(card))){
6159 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6160 return rc;
6162 qeth_init_tokens(card);
6163 qeth_init_func_level(card);
6164 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6165 if (rc == -ERESTARTSYS) {
6166 QETH_DBF_TEXT(setup, 2, "break2");
6167 return rc;
6168 } else if (rc) {
6169 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6170 if (--retries < 0)
6171 goto out;
6172 else
6173 goto retry;
6175 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6176 if (rc == -ERESTARTSYS) {
6177 QETH_DBF_TEXT(setup, 2, "break3");
6178 return rc;
6179 } else if (rc) {
6180 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6181 if (--retries < 0)
6182 goto out;
6183 else
6184 goto retry;
6186 if ((rc = qeth_mpc_initialize(card))){
6187 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6188 goto out;
6190 /*network device will be recovered*/
6191 if (card->dev) {
6192 card->dev->hard_header = card->orig_hard_header;
6193 return 0;
6195 /* at first set_online allocate netdev */
6196 card->dev = qeth_get_netdevice(card->info.type,
6197 card->info.link_type);
6198 if (!card->dev){
6199 qeth_qdio_clear_card(card, card->info.type ==
6200 QETH_CARD_TYPE_OSAE);
6201 rc = -ENODEV;
6202 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6203 goto out;
6205 card->dev->priv = card;
6206 card->orig_hard_header = card->dev->hard_header;
6207 card->dev->type = qeth_get_arphdr_type(card->info.type,
6208 card->info.link_type);
6209 card->dev->init = qeth_netdev_init;
6210 return 0;
6211 out:
6212 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6213 return rc;
6216 static int
6217 qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6218 unsigned long data)
6220 struct qeth_ipa_cmd *cmd;
6222 QETH_DBF_TEXT(trace,4,"defadpcb");
6224 cmd = (struct qeth_ipa_cmd *) data;
6225 if (cmd->hdr.return_code == 0){
6226 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6227 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6228 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6229 #ifdef CONFIG_QETH_IPV6
6230 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6231 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6232 #endif
6234 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6235 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6236 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6237 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6239 return 0;
6242 static int
6243 qeth_default_setadapterparms_cb(struct qeth_card *card,
6244 struct qeth_reply *reply,
6245 unsigned long data)
6247 struct qeth_ipa_cmd *cmd;
6249 QETH_DBF_TEXT(trace,4,"defadpcb");
6251 cmd = (struct qeth_ipa_cmd *) data;
6252 if (cmd->hdr.return_code == 0)
6253 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6254 return 0;
6257 static int
6258 qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6259 unsigned long data)
6261 struct qeth_ipa_cmd *cmd;
6263 QETH_DBF_TEXT(trace,3,"quyadpcb");
6265 cmd = (struct qeth_ipa_cmd *) data;
6266 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6267 card->info.link_type =
6268 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6269 card->options.adp.supported_funcs =
6270 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6271 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6274 static int
6275 qeth_query_setadapterparms(struct qeth_card *card)
6277 int rc;
6278 struct qeth_cmd_buffer *iob;
6280 QETH_DBF_TEXT(trace,3,"queryadp");
6281 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6282 sizeof(struct qeth_ipacmd_setadpparms));
6283 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6284 return rc;
6287 static int
6288 qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6289 struct qeth_reply *reply,
6290 unsigned long data)
6292 struct qeth_ipa_cmd *cmd;
6294 QETH_DBF_TEXT(trace,4,"chgmaccb");
6296 cmd = (struct qeth_ipa_cmd *) data;
6297 memcpy(card->dev->dev_addr,
6298 &cmd->data.setadapterparms.data.change_addr.addr,OSA_ADDR_LEN);
6299 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6300 return 0;
6303 static int
6304 qeth_setadpparms_change_macaddr(struct qeth_card *card)
6306 int rc;
6307 struct qeth_cmd_buffer *iob;
6308 struct qeth_ipa_cmd *cmd;
6310 QETH_DBF_TEXT(trace,4,"chgmac");
6312 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6313 sizeof(struct qeth_ipacmd_setadpparms));
6314 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6315 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6316 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6317 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6318 card->dev->dev_addr, OSA_ADDR_LEN);
6319 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6320 NULL);
6321 return rc;
6324 static int
6325 qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6327 int rc;
6328 struct qeth_cmd_buffer *iob;
6329 struct qeth_ipa_cmd *cmd;
6331 QETH_DBF_TEXT(trace,4,"adpmode");
6333 iob = qeth_get_adapter_cmd(card, command,
6334 sizeof(struct qeth_ipacmd_setadpparms));
6335 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6336 cmd->data.setadapterparms.data.mode = mode;
6337 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6338 NULL);
6339 return rc;
6342 static inline int
6343 qeth_setadapter_hstr(struct qeth_card *card)
6345 int rc;
6347 QETH_DBF_TEXT(trace,4,"adphstr");
6349 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6350 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6351 card->options.broadcast_mode);
6352 if (rc)
6353 PRINT_WARN("couldn't set broadcast mode on "
6354 "device %s: x%x\n",
6355 CARD_BUS_ID(card), rc);
6356 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6357 card->options.macaddr_mode);
6358 if (rc)
6359 PRINT_WARN("couldn't set macaddr mode on "
6360 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6361 return rc;
6363 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6364 PRINT_WARN("set adapter parameters not available "
6365 "to set broadcast mode, using ALLRINGS "
6366 "on device %s:\n", CARD_BUS_ID(card));
6367 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6368 PRINT_WARN("set adapter parameters not available "
6369 "to set macaddr mode, using NONCANONICAL "
6370 "on device %s:\n", CARD_BUS_ID(card));
6371 return 0;
6374 static int
6375 qeth_setadapter_parms(struct qeth_card *card)
6377 int rc;
6379 QETH_DBF_TEXT(setup, 2, "setadprm");
6381 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6382 PRINT_WARN("set adapter parameters not supported "
6383 "on device %s.\n",
6384 CARD_BUS_ID(card));
6385 QETH_DBF_TEXT(setup, 2, " notsupp");
6386 return 0;
6388 rc = qeth_query_setadapterparms(card);
6389 if (rc) {
6390 PRINT_WARN("couldn't set adapter parameters on device %s: "
6391 "x%x\n", CARD_BUS_ID(card), rc);
6392 return rc;
6394 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6395 rc = qeth_setadpparms_change_macaddr(card);
6396 if (rc)
6397 PRINT_WARN("couldn't get MAC address on "
6398 "device %s: x%x\n",
6399 CARD_BUS_ID(card), rc);
6402 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6403 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6404 rc = qeth_setadapter_hstr(card);
6406 return rc;
6409 static int
6410 qeth_layer2_initialize(struct qeth_card *card)
6412 int rc = 0;
6415 QETH_DBF_TEXT(setup, 2, "doL2init");
6416 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6418 rc = qeth_setadpparms_change_macaddr(card);
6419 if (rc) {
6420 PRINT_WARN("couldn't get MAC address on "
6421 "device %s: x%x\n",
6422 CARD_BUS_ID(card), rc);
6423 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6424 return rc;
6426 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6428 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6429 if (rc)
6430 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6431 return 0;
6435 static int
6436 qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6437 enum qeth_prot_versions prot)
6439 int rc;
6440 struct qeth_cmd_buffer *iob;
6442 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6443 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6445 return rc;
6448 static int
6449 qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6451 int rc;
6453 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6455 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6456 return rc;
6459 static int
6460 qeth_send_stoplan(struct qeth_card *card)
6462 int rc = 0;
6465 * TODO: according to the IPA format document page 14,
6466 * TCP/IP (we!) never issue a STOPLAN
6467 * is this right ?!?
6469 QETH_DBF_TEXT(trace, 2, "stoplan");
6471 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6472 return rc;
6475 static int
6476 qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6477 unsigned long data)
6479 struct qeth_ipa_cmd *cmd;
6481 QETH_DBF_TEXT(setup, 2, "qipasscb");
6483 cmd = (struct qeth_ipa_cmd *) data;
6484 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6485 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6486 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6487 } else {
6488 #ifdef CONFIG_QETH_IPV6
6489 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6490 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6491 #endif
6493 QETH_DBF_TEXT(setup, 2, "suppenbl");
6494 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6495 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6496 return 0;
6499 static int
6500 qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6502 int rc;
6503 struct qeth_cmd_buffer *iob;
6505 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6506 if (card->options.layer2) {
6507 QETH_DBF_TEXT(setup, 2, "noprmly2");
6508 return -EPERM;
6511 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6512 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6513 return rc;
6516 static struct qeth_cmd_buffer *
6517 qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6518 __u16 cmd_code, __u16 len,
6519 enum qeth_prot_versions prot)
6521 struct qeth_cmd_buffer *iob;
6522 struct qeth_ipa_cmd *cmd;
6524 QETH_DBF_TEXT(trace,4,"getasscm");
6525 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6527 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6528 cmd->data.setassparms.hdr.assist_no = ipa_func;
6529 cmd->data.setassparms.hdr.length = 8 + len;
6530 cmd->data.setassparms.hdr.command_code = cmd_code;
6531 cmd->data.setassparms.hdr.return_code = 0;
6532 cmd->data.setassparms.hdr.seq_no = 0;
6534 return iob;
6537 static int
6538 qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6539 __u16 len, long data,
6540 int (*reply_cb)
6541 (struct qeth_card *,struct qeth_reply *,unsigned long),
6542 void *reply_param)
6544 int rc;
6545 struct qeth_ipa_cmd *cmd;
6547 QETH_DBF_TEXT(trace,4,"sendassp");
6549 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6550 if (len <= sizeof(__u32))
6551 cmd->data.setassparms.data.flags_32bit = (__u32) data;
6552 else if (len > sizeof(__u32))
6553 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6555 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6556 return rc;
6559 #ifdef CONFIG_QETH_IPV6
6560 static int
6561 qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6562 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6565 int rc;
6566 struct qeth_cmd_buffer *iob;
6568 QETH_DBF_TEXT(trace,4,"simassp6");
6569 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6570 0, QETH_PROT_IPV6);
6571 rc = qeth_send_setassparms(card, iob, 0, 0,
6572 qeth_default_setassparms_cb, NULL);
6573 return rc;
6575 #endif
6577 static int
6578 qeth_send_simple_setassparms(struct qeth_card *card,
6579 enum qeth_ipa_funcs ipa_func,
6580 __u16 cmd_code, long data)
6582 int rc;
6583 int length = 0;
6584 struct qeth_cmd_buffer *iob;
6586 QETH_DBF_TEXT(trace,4,"simassp4");
6587 if (data)
6588 length = sizeof(__u32);
6589 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6590 length, QETH_PROT_IPV4);
6591 rc = qeth_send_setassparms(card, iob, length, data,
6592 qeth_default_setassparms_cb, NULL);
6593 return rc;
6596 static inline int
6597 qeth_start_ipa_arp_processing(struct qeth_card *card)
6599 int rc;
6601 QETH_DBF_TEXT(trace,3,"ipaarp");
6603 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6604 PRINT_WARN("ARP processing not supported "
6605 "on %s!\n", QETH_CARD_IFNAME(card));
6606 return 0;
6608 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6609 IPA_CMD_ASS_START, 0);
6610 if (rc) {
6611 PRINT_WARN("Could not start ARP processing "
6612 "assist on %s: 0x%x\n",
6613 QETH_CARD_IFNAME(card), rc);
6615 return rc;
6618 static int
6619 qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6621 int rc;
6623 QETH_DBF_TEXT(trace,3,"ipaipfrg");
6625 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
6626 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
6627 QETH_CARD_IFNAME(card));
6628 return -EOPNOTSUPP;
6631 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
6632 IPA_CMD_ASS_START, 0);
6633 if (rc) {
6634 PRINT_WARN("Could not start Hardware IP fragmentation "
6635 "assist on %s: 0x%x\n",
6636 QETH_CARD_IFNAME(card), rc);
6637 } else
6638 PRINT_INFO("Hardware IP fragmentation enabled \n");
6639 return rc;
6642 static int
6643 qeth_start_ipa_source_mac(struct qeth_card *card)
6645 int rc;
6647 QETH_DBF_TEXT(trace,3,"stsrcmac");
6649 if (!card->options.fake_ll)
6650 return -EOPNOTSUPP;
6652 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
6653 PRINT_INFO("Inbound source address not "
6654 "supported on %s\n", QETH_CARD_IFNAME(card));
6655 return -EOPNOTSUPP;
6658 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
6659 IPA_CMD_ASS_START, 0);
6660 if (rc)
6661 PRINT_WARN("Could not start inbound source "
6662 "assist on %s: 0x%x\n",
6663 QETH_CARD_IFNAME(card), rc);
6664 return rc;
6667 static int
6668 qeth_start_ipa_vlan(struct qeth_card *card)
6670 int rc = 0;
6672 QETH_DBF_TEXT(trace,3,"strtvlan");
6674 #ifdef CONFIG_QETH_VLAN
6675 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
6676 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
6677 return -EOPNOTSUPP;
6680 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
6681 IPA_CMD_ASS_START,0);
6682 if (rc) {
6683 PRINT_WARN("Could not start vlan "
6684 "assist on %s: 0x%x\n",
6685 QETH_CARD_IFNAME(card), rc);
6686 } else {
6687 PRINT_INFO("VLAN enabled \n");
6688 card->dev->features |=
6689 NETIF_F_HW_VLAN_FILTER |
6690 NETIF_F_HW_VLAN_TX |
6691 NETIF_F_HW_VLAN_RX;
6693 #endif /* QETH_VLAN */
6694 return rc;
6697 static int
6698 qeth_start_ipa_multicast(struct qeth_card *card)
6700 int rc;
6702 QETH_DBF_TEXT(trace,3,"stmcast");
6704 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
6705 PRINT_WARN("Multicast not supported on %s\n",
6706 QETH_CARD_IFNAME(card));
6707 return -EOPNOTSUPP;
6710 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
6711 IPA_CMD_ASS_START,0);
6712 if (rc) {
6713 PRINT_WARN("Could not start multicast "
6714 "assist on %s: rc=%i\n",
6715 QETH_CARD_IFNAME(card), rc);
6716 } else {
6717 PRINT_INFO("Multicast enabled\n");
6718 card->dev->flags |= IFF_MULTICAST;
6720 return rc;
6723 #ifdef CONFIG_QETH_IPV6
6724 static int
6725 qeth_softsetup_ipv6(struct qeth_card *card)
6727 int rc;
6729 QETH_DBF_TEXT(trace,3,"softipv6");
6731 netif_stop_queue(card->dev);
6732 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
6733 if (rc) {
6734 PRINT_ERR("IPv6 startlan failed on %s\n",
6735 QETH_CARD_IFNAME(card));
6736 return rc;
6738 netif_wake_queue(card->dev);
6739 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
6740 if (rc) {
6741 PRINT_ERR("IPv6 query ipassist failed on %s\n",
6742 QETH_CARD_IFNAME(card));
6743 return rc;
6745 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
6746 IPA_CMD_ASS_START, 3);
6747 if (rc) {
6748 PRINT_WARN("IPv6 start assist (version 4) failed "
6749 "on %s: 0x%x\n",
6750 QETH_CARD_IFNAME(card), rc);
6751 return rc;
6753 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
6754 IPA_CMD_ASS_START);
6755 if (rc) {
6756 PRINT_WARN("IPV6 start assist (version 6) failed "
6757 "on %s: 0x%x\n",
6758 QETH_CARD_IFNAME(card), rc);
6759 return rc;
6761 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
6762 IPA_CMD_ASS_START);
6763 if (rc) {
6764 PRINT_WARN("Could not enable passthrough "
6765 "on %s: 0x%x\n",
6766 QETH_CARD_IFNAME(card), rc);
6767 return rc;
6769 PRINT_INFO("IPV6 enabled \n");
6770 return 0;
6773 #endif
6775 static int
6776 qeth_start_ipa_ipv6(struct qeth_card *card)
6778 int rc = 0;
6779 #ifdef CONFIG_QETH_IPV6
6780 QETH_DBF_TEXT(trace,3,"strtipv6");
6782 if (!qeth_is_supported(card, IPA_IPV6)) {
6783 PRINT_WARN("IPv6 not supported on %s\n",
6784 QETH_CARD_IFNAME(card));
6785 return 0;
6787 rc = qeth_softsetup_ipv6(card);
6788 #endif
6789 return rc ;
6792 static int
6793 qeth_start_ipa_broadcast(struct qeth_card *card)
6795 int rc;
6797 QETH_DBF_TEXT(trace,3,"stbrdcst");
6798 card->info.broadcast_capable = 0;
6799 if (!qeth_is_supported(card, IPA_FILTERING)) {
6800 PRINT_WARN("Broadcast not supported on %s\n",
6801 QETH_CARD_IFNAME(card));
6802 rc = -EOPNOTSUPP;
6803 goto out;
6805 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
6806 IPA_CMD_ASS_START, 0);
6807 if (rc) {
6808 PRINT_WARN("Could not enable broadcasting filtering "
6809 "on %s: 0x%x\n",
6810 QETH_CARD_IFNAME(card), rc);
6811 goto out;
6814 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
6815 IPA_CMD_ASS_CONFIGURE, 1);
6816 if (rc) {
6817 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
6818 QETH_CARD_IFNAME(card), rc);
6819 goto out;
6821 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
6822 PRINT_INFO("Broadcast enabled \n");
6823 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
6824 IPA_CMD_ASS_ENABLE, 1);
6825 if (rc) {
6826 PRINT_WARN("Could not set up broadcast echo filtering on "
6827 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
6828 goto out;
6830 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
6831 out:
6832 if (card->info.broadcast_capable)
6833 card->dev->flags |= IFF_BROADCAST;
6834 else
6835 card->dev->flags &= ~IFF_BROADCAST;
6836 return rc;
6839 static int
6840 qeth_send_checksum_command(struct qeth_card *card)
6842 int rc;
6844 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
6845 IPA_CMD_ASS_START, 0);
6846 if (rc) {
6847 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
6848 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
6849 QETH_CARD_IFNAME(card), rc);
6850 return rc;
6852 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
6853 IPA_CMD_ASS_ENABLE,
6854 card->info.csum_mask);
6855 if (rc) {
6856 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
6857 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
6858 QETH_CARD_IFNAME(card), rc);
6859 return rc;
6861 return 0;
6864 static int
6865 qeth_start_ipa_checksum(struct qeth_card *card)
6867 int rc = 0;
6869 QETH_DBF_TEXT(trace,3,"strtcsum");
6871 if (card->options.checksum_type == NO_CHECKSUMMING) {
6872 PRINT_WARN("Using no checksumming on %s.\n",
6873 QETH_CARD_IFNAME(card));
6874 return 0;
6876 if (card->options.checksum_type == SW_CHECKSUMMING) {
6877 PRINT_WARN("Using SW checksumming on %s.\n",
6878 QETH_CARD_IFNAME(card));
6879 return 0;
6881 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
6882 PRINT_WARN("Inbound HW Checksumming not "
6883 "supported on %s,\ncontinuing "
6884 "using Inbound SW Checksumming\n",
6885 QETH_CARD_IFNAME(card));
6886 card->options.checksum_type = SW_CHECKSUMMING;
6887 return 0;
6889 rc = qeth_send_checksum_command(card);
6890 if (!rc) {
6891 PRINT_INFO("HW Checksumming (inbound) enabled \n");
6893 return rc;
6896 static int
6897 qeth_start_ipa_tso(struct qeth_card *card)
6899 int rc;
6901 QETH_DBF_TEXT(trace,3,"sttso");
6903 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
6904 PRINT_WARN("Outbound TSO not supported on %s\n",
6905 QETH_CARD_IFNAME(card));
6906 rc = -EOPNOTSUPP;
6907 } else {
6908 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
6909 IPA_CMD_ASS_START,0);
6910 if (rc)
6911 PRINT_WARN("Could not start outbound TSO "
6912 "assist on %s: rc=%i\n",
6913 QETH_CARD_IFNAME(card), rc);
6914 else
6915 PRINT_INFO("Outbound TSO enabled\n");
6917 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
6918 card->options.large_send = QETH_LARGE_SEND_NO;
6919 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
6921 return rc;
6924 static int
6925 qeth_start_ipassists(struct qeth_card *card)
6927 QETH_DBF_TEXT(trace,3,"strtipas");
6928 qeth_start_ipa_arp_processing(card); /* go on*/
6929 qeth_start_ipa_ip_fragmentation(card); /* go on*/
6930 qeth_start_ipa_source_mac(card); /* go on*/
6931 qeth_start_ipa_vlan(card); /* go on*/
6932 qeth_start_ipa_multicast(card); /* go on*/
6933 qeth_start_ipa_ipv6(card); /* go on*/
6934 qeth_start_ipa_broadcast(card); /* go on*/
6935 qeth_start_ipa_checksum(card); /* go on*/
6936 qeth_start_ipa_tso(card); /* go on*/
6937 return 0;
6940 static int
6941 qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
6942 enum qeth_prot_versions prot)
6944 int rc;
6945 struct qeth_ipa_cmd *cmd;
6946 struct qeth_cmd_buffer *iob;
6948 QETH_DBF_TEXT(trace,4,"setroutg");
6949 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
6950 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6951 cmd->data.setrtg.type = (type);
6952 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6954 return rc;
6958 static void
6959 qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
6960 enum qeth_prot_versions prot)
6962 if (card->info.type == QETH_CARD_TYPE_IQD) {
6963 switch (*type) {
6964 case NO_ROUTER:
6965 case PRIMARY_CONNECTOR:
6966 case SECONDARY_CONNECTOR:
6967 case MULTICAST_ROUTER:
6968 return;
6969 default:
6970 goto out_inval;
6972 } else {
6973 switch (*type) {
6974 case NO_ROUTER:
6975 case PRIMARY_ROUTER:
6976 case SECONDARY_ROUTER:
6977 return;
6978 case MULTICAST_ROUTER:
6979 if (qeth_is_ipafunc_supported(card, prot,
6980 IPA_OSA_MC_ROUTER))
6981 return;
6982 default:
6983 goto out_inval;
6986 out_inval:
6987 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
6988 "Router status set to 'no router'.\n",
6989 ((*type == PRIMARY_ROUTER)? "primary router" :
6990 (*type == SECONDARY_ROUTER)? "secondary router" :
6991 (*type == PRIMARY_CONNECTOR)? "primary connector" :
6992 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
6993 (*type == MULTICAST_ROUTER)? "multicast router" :
6994 "unknown"),
6995 card->dev->name);
6996 *type = NO_ROUTER;
7000 qeth_setrouting_v4(struct qeth_card *card)
7002 int rc;
7004 QETH_DBF_TEXT(trace,3,"setrtg4");
7006 qeth_correct_routing_type(card, &card->options.route4.type,
7007 QETH_PROT_IPV4);
7009 rc = qeth_send_setrouting(card, card->options.route4.type,
7010 QETH_PROT_IPV4);
7011 if (rc) {
7012 card->options.route4.type = NO_ROUTER;
7013 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7014 "Type set to 'no router'.\n",
7015 rc, QETH_CARD_IFNAME(card));
7017 return rc;
7021 qeth_setrouting_v6(struct qeth_card *card)
7023 int rc = 0;
7025 QETH_DBF_TEXT(trace,3,"setrtg6");
7026 #ifdef CONFIG_QETH_IPV6
7028 qeth_correct_routing_type(card, &card->options.route6.type,
7029 QETH_PROT_IPV6);
7031 if ((card->options.route6.type == NO_ROUTER) ||
7032 ((card->info.type == QETH_CARD_TYPE_OSAE) &&
7033 (card->options.route6.type == MULTICAST_ROUTER) &&
7034 !qeth_is_supported6(card,IPA_OSA_MC_ROUTER)))
7035 return 0;
7036 rc = qeth_send_setrouting(card, card->options.route6.type,
7037 QETH_PROT_IPV6);
7038 if (rc) {
7039 card->options.route6.type = NO_ROUTER;
7040 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7041 "Type set to 'no router'.\n",
7042 rc, QETH_CARD_IFNAME(card));
7044 #endif
7045 return rc;
7049 qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
7051 int rc = 0;
7053 if (card->dev == NULL) {
7054 card->options.large_send = type;
7055 return 0;
7057 netif_stop_queue(card->dev);
7058 card->options.large_send = type;
7059 switch (card->options.large_send) {
7060 case QETH_LARGE_SEND_EDDP:
7061 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7062 break;
7063 case QETH_LARGE_SEND_TSO:
7064 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7065 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7066 } else {
7067 PRINT_WARN("TSO not supported on %s. "
7068 "large_send set to 'no'.\n",
7069 card->dev->name);
7070 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7071 card->options.large_send = QETH_LARGE_SEND_NO;
7072 rc = -EOPNOTSUPP;
7074 break;
7075 default: /* includes QETH_LARGE_SEND_NO */
7076 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7077 break;
7079 netif_wake_queue(card->dev);
7080 return rc;
7084 * softsetup card: init IPA stuff
7086 static int
7087 qeth_softsetup_card(struct qeth_card *card)
7089 int rc;
7091 QETH_DBF_TEXT(setup, 2, "softsetp");
7093 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7094 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7095 if (rc == 0xe080){
7096 PRINT_WARN("LAN on card %s if offline! "
7097 "Continuing softsetup.\n",
7098 CARD_BUS_ID(card));
7099 card->lan_online = 0;
7100 } else
7101 return rc;
7102 } else
7103 card->lan_online = 1;
7104 if (card->options.layer2) {
7105 card->dev->features |=
7106 NETIF_F_HW_VLAN_FILTER |
7107 NETIF_F_HW_VLAN_TX |
7108 NETIF_F_HW_VLAN_RX;
7109 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7110 card->info.broadcast_capable=1;
7111 if ((rc = qeth_layer2_initialize(card))) {
7112 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7113 return rc;
7115 #ifdef CONFIG_QETH_VLAN
7116 qeth_layer2_process_vlans(card, 0);
7117 #endif
7118 goto out;
7120 if ((card->options.large_send == QETH_LARGE_SEND_EDDP) ||
7121 (card->options.large_send == QETH_LARGE_SEND_TSO))
7122 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7123 else
7124 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7126 if ((rc = qeth_setadapter_parms(card)))
7127 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7128 if ((rc = qeth_start_ipassists(card)))
7129 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7130 if ((rc = qeth_setrouting_v4(card)))
7131 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7132 if ((rc = qeth_setrouting_v6(card)))
7133 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7134 out:
7135 netif_stop_queue(card->dev);
7136 return 0;
7139 #ifdef CONFIG_QETH_IPV6
7140 static int
7141 qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7142 unsigned long data)
7144 struct qeth_ipa_cmd *cmd;
7146 cmd = (struct qeth_ipa_cmd *) data;
7147 if (cmd->hdr.return_code == 0)
7148 card->info.unique_id = *((__u16 *)
7149 &cmd->data.create_destroy_addr.unique_id[6]);
7150 else {
7151 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7152 UNIQUE_ID_NOT_BY_CARD;
7153 PRINT_WARN("couldn't get a unique id from the card on device "
7154 "%s (result=x%x), using default id. ipv6 "
7155 "autoconfig on other lpars may lead to duplicate "
7156 "ip addresses. please use manually "
7157 "configured ones.\n",
7158 CARD_BUS_ID(card), cmd->hdr.return_code);
7160 return 0;
7162 #endif
7164 static int
7165 qeth_put_unique_id(struct qeth_card *card)
7168 int rc = 0;
7169 #ifdef CONFIG_QETH_IPV6
7170 struct qeth_cmd_buffer *iob;
7171 struct qeth_ipa_cmd *cmd;
7173 QETH_DBF_TEXT(trace,2,"puniqeid");
7175 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7176 UNIQUE_ID_NOT_BY_CARD)
7177 return -1;
7178 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7179 QETH_PROT_IPV6);
7180 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7181 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7182 card->info.unique_id;
7183 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7184 card->dev->dev_addr, OSA_ADDR_LEN);
7185 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7186 #else
7187 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7188 UNIQUE_ID_NOT_BY_CARD;
7189 #endif
7190 return rc;
7194 * Clear IP List
7196 static void
7197 qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7199 struct qeth_ipaddr *addr, *tmp;
7200 unsigned long flags;
7202 QETH_DBF_TEXT(trace,4,"clearip");
7203 spin_lock_irqsave(&card->ip_lock, flags);
7204 /* clear todo list */
7205 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7206 list_del(&addr->entry);
7207 kfree(addr);
7210 while (!list_empty(&card->ip_list)) {
7211 addr = list_entry(card->ip_list.next,
7212 struct qeth_ipaddr, entry);
7213 list_del_init(&addr->entry);
7214 if (clean) {
7215 spin_unlock_irqrestore(&card->ip_lock, flags);
7216 qeth_deregister_addr_entry(card, addr);
7217 spin_lock_irqsave(&card->ip_lock, flags);
7219 if (!recover || addr->is_multicast) {
7220 kfree(addr);
7221 continue;
7223 list_add_tail(&addr->entry, card->ip_tbd_list);
7225 spin_unlock_irqrestore(&card->ip_lock, flags);
7228 static void
7229 qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7230 int clear_start_mask)
7232 unsigned long flags;
7234 spin_lock_irqsave(&card->thread_mask_lock, flags);
7235 card->thread_allowed_mask = threads;
7236 if (clear_start_mask)
7237 card->thread_start_mask &= threads;
7238 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7239 wake_up(&card->wait_q);
7242 static inline int
7243 qeth_threads_running(struct qeth_card *card, unsigned long threads)
7245 unsigned long flags;
7246 int rc = 0;
7248 spin_lock_irqsave(&card->thread_mask_lock, flags);
7249 rc = (card->thread_running_mask & threads);
7250 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7251 return rc;
7254 static int
7255 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7257 return wait_event_interruptible(card->wait_q,
7258 qeth_threads_running(card, threads) == 0);
7261 static int
7262 qeth_stop_card(struct qeth_card *card, int recovery_mode)
7264 int rc = 0;
7266 QETH_DBF_TEXT(setup ,2,"stopcard");
7267 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7269 qeth_set_allowed_threads(card, 0, 1);
7270 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7271 return -ERESTARTSYS;
7272 if (card->read.state == CH_STATE_UP &&
7273 card->write.state == CH_STATE_UP &&
7274 (card->state == CARD_STATE_UP)) {
7275 if(recovery_mode) {
7276 qeth_stop(card->dev);
7277 } else {
7278 rtnl_lock();
7279 dev_close(card->dev);
7280 rtnl_unlock();
7282 if (!card->use_hard_stop) {
7283 __u8 *mac = &card->dev->dev_addr[0];
7284 rc = qeth_layer2_send_delmac(card, mac);
7285 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7286 if ((rc = qeth_send_stoplan(card)))
7287 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7289 card->state = CARD_STATE_SOFTSETUP;
7291 if (card->state == CARD_STATE_SOFTSETUP) {
7292 #ifdef CONFIG_QETH_VLAN
7293 if (card->options.layer2)
7294 qeth_layer2_process_vlans(card, 1);
7295 #endif
7296 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7297 qeth_clear_ipacmd_list(card);
7298 card->state = CARD_STATE_HARDSETUP;
7300 if (card->state == CARD_STATE_HARDSETUP) {
7301 if ((!card->use_hard_stop) &&
7302 (!card->options.layer2))
7303 if ((rc = qeth_put_unique_id(card)))
7304 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7305 qeth_qdio_clear_card(card, 0);
7306 qeth_clear_qdio_buffers(card);
7307 qeth_clear_working_pool_list(card);
7308 card->state = CARD_STATE_DOWN;
7310 if (card->state == CARD_STATE_DOWN) {
7311 qeth_clear_cmd_buffers(&card->read);
7312 qeth_clear_cmd_buffers(&card->write);
7314 card->use_hard_stop = 0;
7315 return rc;
7319 static int
7320 qeth_get_unique_id(struct qeth_card *card)
7322 int rc = 0;
7323 #ifdef CONFIG_QETH_IPV6
7324 struct qeth_cmd_buffer *iob;
7325 struct qeth_ipa_cmd *cmd;
7327 QETH_DBF_TEXT(setup, 2, "guniqeid");
7329 if (!qeth_is_supported(card,IPA_IPV6)) {
7330 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7331 UNIQUE_ID_NOT_BY_CARD;
7332 return 0;
7335 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7336 QETH_PROT_IPV6);
7337 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7338 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7339 card->info.unique_id;
7341 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7342 #else
7343 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7344 UNIQUE_ID_NOT_BY_CARD;
7345 #endif
7346 return rc;
7348 static void
7349 qeth_print_status_with_portname(struct qeth_card *card)
7351 char dbf_text[15];
7352 int i;
7354 sprintf(dbf_text, "%s", card->info.portname + 1);
7355 for (i = 0; i < 8; i++)
7356 dbf_text[i] =
7357 (char) _ebcasc[(__u8) dbf_text[i]];
7358 dbf_text[8] = 0;
7359 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7360 "with link type %s (portname: %s)\n",
7361 CARD_RDEV_ID(card),
7362 CARD_WDEV_ID(card),
7363 CARD_DDEV_ID(card),
7364 qeth_get_cardname(card),
7365 (card->info.mcl_level[0]) ? " (level: " : "",
7366 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7367 (card->info.mcl_level[0]) ? ")" : "",
7368 qeth_get_cardname_short(card),
7369 dbf_text);
7373 static void
7374 qeth_print_status_no_portname(struct qeth_card *card)
7376 if (card->info.portname[0])
7377 printk("qeth: Device %s/%s/%s is a%s "
7378 "card%s%s%s\nwith link type %s "
7379 "(no portname needed by interface).\n",
7380 CARD_RDEV_ID(card),
7381 CARD_WDEV_ID(card),
7382 CARD_DDEV_ID(card),
7383 qeth_get_cardname(card),
7384 (card->info.mcl_level[0]) ? " (level: " : "",
7385 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7386 (card->info.mcl_level[0]) ? ")" : "",
7387 qeth_get_cardname_short(card));
7388 else
7389 printk("qeth: Device %s/%s/%s is a%s "
7390 "card%s%s%s\nwith link type %s.\n",
7391 CARD_RDEV_ID(card),
7392 CARD_WDEV_ID(card),
7393 CARD_DDEV_ID(card),
7394 qeth_get_cardname(card),
7395 (card->info.mcl_level[0]) ? " (level: " : "",
7396 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7397 (card->info.mcl_level[0]) ? ")" : "",
7398 qeth_get_cardname_short(card));
7401 static void
7402 qeth_print_status_message(struct qeth_card *card)
7404 switch (card->info.type) {
7405 case QETH_CARD_TYPE_OSAE:
7406 /* VM will use a non-zero first character
7407 * to indicate a HiperSockets like reporting
7408 * of the level OSA sets the first character to zero
7409 * */
7410 if (!card->info.mcl_level[0]) {
7411 sprintf(card->info.mcl_level,"%02x%02x",
7412 card->info.mcl_level[2],
7413 card->info.mcl_level[3]);
7415 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7416 break;
7418 /* fallthrough */
7419 case QETH_CARD_TYPE_IQD:
7420 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7421 card->info.mcl_level[0]];
7422 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7423 card->info.mcl_level[1]];
7424 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7425 card->info.mcl_level[2]];
7426 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7427 card->info.mcl_level[3]];
7428 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7429 break;
7430 default:
7431 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7433 if (card->info.portname_required)
7434 qeth_print_status_with_portname(card);
7435 else
7436 qeth_print_status_no_portname(card);
7439 static int
7440 qeth_register_netdev(struct qeth_card *card)
7442 QETH_DBF_TEXT(setup, 3, "regnetd");
7443 if (card->dev->reg_state != NETREG_UNINITIALIZED) {
7444 qeth_netdev_init(card->dev);
7445 return 0;
7447 /* sysfs magic */
7448 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7449 return register_netdev(card->dev);
7452 static void
7453 qeth_start_again(struct qeth_card *card, int recovery_mode)
7455 QETH_DBF_TEXT(setup ,2, "startag");
7457 if(recovery_mode) {
7458 qeth_open(card->dev);
7459 } else {
7460 rtnl_lock();
7461 dev_open(card->dev);
7462 rtnl_unlock();
7464 /* this also sets saved unicast addresses */
7465 qeth_set_multicast_list(card->dev);
7469 /* Layer 2 specific stuff */
7470 #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7471 if (card->options.option == value) { \
7472 PRINT_ERR("%s not supported with layer 2 " \
7473 "functionality, ignoring option on read" \
7474 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7475 card->options.option = reset_value; \
7477 #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7478 if (card->options.option != value) { \
7479 PRINT_ERR("%s not supported with layer 2 " \
7480 "functionality, ignoring option on read" \
7481 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7482 card->options.option = reset_value; \
7486 static void qeth_make_parameters_consistent(struct qeth_card *card)
7489 if (card->options.layer2) {
7490 if (card->info.type == QETH_CARD_TYPE_IQD) {
7491 PRINT_ERR("Device %s does not support " \
7492 "layer 2 functionality. " \
7493 "Ignoring layer2 option.\n",CARD_BUS_ID(card));
7495 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7496 "Routing options are");
7497 #ifdef CONFIG_QETH_IPV6
7498 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7499 "Routing options are");
7500 #endif
7501 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7502 QETH_CHECKSUM_DEFAULT,
7503 "Checksumming options are");
7504 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7505 QETH_TR_BROADCAST_ALLRINGS,
7506 "Broadcast mode options are");
7507 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7508 QETH_TR_MACADDR_NONCANONICAL,
7509 "Canonical MAC addr options are");
7510 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7511 "Broadcast faking options are");
7512 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7513 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7514 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
7519 static int
7520 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
7522 struct qeth_card *card = gdev->dev.driver_data;
7523 int rc = 0;
7524 enum qeth_card_states recover_flag;
7526 BUG_ON(!card);
7527 QETH_DBF_TEXT(setup ,2, "setonlin");
7528 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7530 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7531 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7532 PRINT_WARN("set_online of card %s interrupted by user!\n",
7533 CARD_BUS_ID(card));
7534 return -ERESTARTSYS;
7537 recover_flag = card->state;
7538 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7539 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7540 (rc = ccw_device_set_online(CARD_DDEV(card)))){
7541 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7542 return -EIO;
7545 if (card->options.layer2)
7546 qeth_make_parameters_consistent(card);
7548 if ((rc = qeth_hardsetup_card(card))){
7549 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7550 goto out_remove;
7552 card->state = CARD_STATE_HARDSETUP;
7554 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7555 rc = qeth_get_unique_id(card);
7557 if (rc && card->options.layer2 == 0) {
7558 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7559 goto out_remove;
7561 qeth_print_status_message(card);
7562 if ((rc = qeth_register_netdev(card))){
7563 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7564 goto out_remove;
7566 if ((rc = qeth_softsetup_card(card))){
7567 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7568 goto out_remove;
7570 card->state = CARD_STATE_SOFTSETUP;
7572 if ((rc = qeth_init_qdio_queues(card))){
7573 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7574 goto out_remove;
7576 /*maybe it was set offline without ifconfig down
7577 * we can also use this state for recovery purposes*/
7578 qeth_set_allowed_threads(card, 0xffffffff, 0);
7579 if (recover_flag == CARD_STATE_RECOVER)
7580 qeth_start_again(card, recovery_mode);
7581 qeth_notify_processes();
7582 return 0;
7583 out_remove:
7584 card->use_hard_stop = 1;
7585 qeth_stop_card(card, 0);
7586 ccw_device_set_offline(CARD_DDEV(card));
7587 ccw_device_set_offline(CARD_WDEV(card));
7588 ccw_device_set_offline(CARD_RDEV(card));
7589 if (recover_flag == CARD_STATE_RECOVER)
7590 card->state = CARD_STATE_RECOVER;
7591 else
7592 card->state = CARD_STATE_DOWN;
7593 return -ENODEV;
7596 static int
7597 qeth_set_online(struct ccwgroup_device *gdev)
7599 return __qeth_set_online(gdev, 0);
7602 static struct ccw_device_id qeth_ids[] = {
7603 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE},
7604 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD},
7607 MODULE_DEVICE_TABLE(ccw, qeth_ids);
7609 struct device *qeth_root_dev = NULL;
7611 struct ccwgroup_driver qeth_ccwgroup_driver = {
7612 .owner = THIS_MODULE,
7613 .name = "qeth",
7614 .driver_id = 0xD8C5E3C8,
7615 .probe = qeth_probe_device,
7616 .remove = qeth_remove_device,
7617 .set_online = qeth_set_online,
7618 .set_offline = qeth_set_offline,
7621 struct ccw_driver qeth_ccw_driver = {
7622 .name = "qeth",
7623 .ids = qeth_ids,
7624 .probe = ccwgroup_probe_ccwdev,
7625 .remove = ccwgroup_remove_ccwdev,
7629 static void
7630 qeth_unregister_dbf_views(void)
7632 if (qeth_dbf_setup)
7633 debug_unregister(qeth_dbf_setup);
7634 if (qeth_dbf_qerr)
7635 debug_unregister(qeth_dbf_qerr);
7636 if (qeth_dbf_sense)
7637 debug_unregister(qeth_dbf_sense);
7638 if (qeth_dbf_misc)
7639 debug_unregister(qeth_dbf_misc);
7640 if (qeth_dbf_data)
7641 debug_unregister(qeth_dbf_data);
7642 if (qeth_dbf_control)
7643 debug_unregister(qeth_dbf_control);
7644 if (qeth_dbf_trace)
7645 debug_unregister(qeth_dbf_trace);
7647 static int
7648 qeth_register_dbf_views(void)
7650 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
7651 QETH_DBF_SETUP_PAGES,
7652 QETH_DBF_SETUP_NR_AREAS,
7653 QETH_DBF_SETUP_LEN);
7654 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
7655 QETH_DBF_MISC_PAGES,
7656 QETH_DBF_MISC_NR_AREAS,
7657 QETH_DBF_MISC_LEN);
7658 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
7659 QETH_DBF_DATA_PAGES,
7660 QETH_DBF_DATA_NR_AREAS,
7661 QETH_DBF_DATA_LEN);
7662 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
7663 QETH_DBF_CONTROL_PAGES,
7664 QETH_DBF_CONTROL_NR_AREAS,
7665 QETH_DBF_CONTROL_LEN);
7666 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
7667 QETH_DBF_SENSE_PAGES,
7668 QETH_DBF_SENSE_NR_AREAS,
7669 QETH_DBF_SENSE_LEN);
7670 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
7671 QETH_DBF_QERR_PAGES,
7672 QETH_DBF_QERR_NR_AREAS,
7673 QETH_DBF_QERR_LEN);
7674 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
7675 QETH_DBF_TRACE_PAGES,
7676 QETH_DBF_TRACE_NR_AREAS,
7677 QETH_DBF_TRACE_LEN);
7679 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
7680 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
7681 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
7682 (qeth_dbf_trace == NULL)) {
7683 qeth_unregister_dbf_views();
7684 return -ENOMEM;
7686 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
7687 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
7689 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
7690 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
7692 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
7693 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
7695 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
7696 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
7698 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
7699 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
7701 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
7702 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
7704 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
7705 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
7707 return 0;
7710 #ifdef CONFIG_QETH_IPV6
7711 extern struct neigh_table arp_tbl;
7712 static struct neigh_ops *arp_direct_ops;
7713 static int (*qeth_old_arp_constructor) (struct neighbour *);
7715 static struct neigh_ops arp_direct_ops_template = {
7716 .family = AF_INET,
7717 .destructor = NULL,
7718 .solicit = NULL,
7719 .error_report = NULL,
7720 .output = dev_queue_xmit,
7721 .connected_output = dev_queue_xmit,
7722 .hh_output = dev_queue_xmit,
7723 .queue_xmit = dev_queue_xmit
7726 static int
7727 qeth_arp_constructor(struct neighbour *neigh)
7729 struct net_device *dev = neigh->dev;
7730 struct in_device *in_dev;
7731 struct neigh_parms *parms;
7732 struct qeth_card *card;
7734 card = qeth_get_card_from_dev(dev);
7735 if (card == NULL)
7736 goto out;
7737 if((card->options.layer2) ||
7738 (card->dev->hard_header == qeth_fake_header))
7739 goto out;
7741 rcu_read_lock();
7742 in_dev = rcu_dereference(__in_dev_get(dev));
7743 if (in_dev == NULL) {
7744 rcu_read_unlock();
7745 return -EINVAL;
7748 parms = in_dev->arp_parms;
7749 __neigh_parms_put(neigh->parms);
7750 neigh->parms = neigh_parms_clone(parms);
7751 rcu_read_unlock();
7753 neigh->type = inet_addr_type(*(u32 *) neigh->primary_key);
7754 neigh->nud_state = NUD_NOARP;
7755 neigh->ops = arp_direct_ops;
7756 neigh->output = neigh->ops->queue_xmit;
7757 return 0;
7758 out:
7759 return qeth_old_arp_constructor(neigh);
7761 #endif /*CONFIG_QETH_IPV6*/
7764 * IP address takeover related functions
7766 static void
7767 qeth_clear_ipato_list(struct qeth_card *card)
7769 struct qeth_ipato_entry *ipatoe, *tmp;
7770 unsigned long flags;
7772 spin_lock_irqsave(&card->ip_lock, flags);
7773 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
7774 list_del(&ipatoe->entry);
7775 kfree(ipatoe);
7777 spin_unlock_irqrestore(&card->ip_lock, flags);
7781 qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
7783 struct qeth_ipato_entry *ipatoe;
7784 unsigned long flags;
7785 int rc = 0;
7787 QETH_DBF_TEXT(trace, 2, "addipato");
7788 spin_lock_irqsave(&card->ip_lock, flags);
7789 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
7790 if (ipatoe->proto != new->proto)
7791 continue;
7792 if (!memcmp(ipatoe->addr, new->addr,
7793 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
7794 (ipatoe->mask_bits == new->mask_bits)){
7795 PRINT_WARN("ipato entry already exists!\n");
7796 rc = -EEXIST;
7797 break;
7800 if (!rc) {
7801 list_add_tail(&new->entry, &card->ipato.entries);
7803 spin_unlock_irqrestore(&card->ip_lock, flags);
7804 return rc;
7807 void
7808 qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
7809 u8 *addr, int mask_bits)
7811 struct qeth_ipato_entry *ipatoe, *tmp;
7812 unsigned long flags;
7814 QETH_DBF_TEXT(trace, 2, "delipato");
7815 spin_lock_irqsave(&card->ip_lock, flags);
7816 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
7817 if (ipatoe->proto != proto)
7818 continue;
7819 if (!memcmp(ipatoe->addr, addr,
7820 (proto == QETH_PROT_IPV4)? 4:16) &&
7821 (ipatoe->mask_bits == mask_bits)){
7822 list_del(&ipatoe->entry);
7823 kfree(ipatoe);
7826 spin_unlock_irqrestore(&card->ip_lock, flags);
7829 static inline void
7830 qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
7832 int i, j;
7833 u8 octet;
7835 for (i = 0; i < len; ++i){
7836 octet = addr[i];
7837 for (j = 7; j >= 0; --j){
7838 bits[i*8 + j] = octet & 1;
7839 octet >>= 1;
7844 static int
7845 qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
7847 struct qeth_ipato_entry *ipatoe;
7848 u8 addr_bits[128] = {0, };
7849 u8 ipatoe_bits[128] = {0, };
7850 int rc = 0;
7852 if (!card->ipato.enabled)
7853 return 0;
7855 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
7856 (addr->proto == QETH_PROT_IPV4)? 4:16);
7857 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
7858 if (addr->proto != ipatoe->proto)
7859 continue;
7860 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
7861 (ipatoe->proto==QETH_PROT_IPV4) ?
7862 4:16);
7863 if (addr->proto == QETH_PROT_IPV4)
7864 rc = !memcmp(addr_bits, ipatoe_bits,
7865 min(32, ipatoe->mask_bits));
7866 else
7867 rc = !memcmp(addr_bits, ipatoe_bits,
7868 min(128, ipatoe->mask_bits));
7869 if (rc)
7870 break;
7872 /* invert? */
7873 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
7874 rc = !rc;
7875 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
7876 rc = !rc;
7878 return rc;
7882 * VIPA related functions
7885 qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
7886 const u8 *addr)
7888 struct qeth_ipaddr *ipaddr;
7889 unsigned long flags;
7890 int rc = 0;
7892 ipaddr = qeth_get_addr_buffer(proto);
7893 if (ipaddr){
7894 if (proto == QETH_PROT_IPV4){
7895 QETH_DBF_TEXT(trace, 2, "addvipa4");
7896 memcpy(&ipaddr->u.a4.addr, addr, 4);
7897 ipaddr->u.a4.mask = 0;
7898 #ifdef CONFIG_QETH_IPV6
7899 } else if (proto == QETH_PROT_IPV6){
7900 QETH_DBF_TEXT(trace, 2, "addvipa6");
7901 memcpy(&ipaddr->u.a6.addr, addr, 16);
7902 ipaddr->u.a6.pfxlen = 0;
7903 #endif
7905 ipaddr->type = QETH_IP_TYPE_VIPA;
7906 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
7907 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
7908 } else
7909 return -ENOMEM;
7910 spin_lock_irqsave(&card->ip_lock, flags);
7911 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
7912 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
7913 rc = -EEXIST;
7914 spin_unlock_irqrestore(&card->ip_lock, flags);
7915 if (rc){
7916 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
7917 return rc;
7919 if (!qeth_add_ip(card, ipaddr))
7920 kfree(ipaddr);
7921 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
7922 schedule_work(&card->kernel_thread_starter);
7923 return rc;
7926 void
7927 qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
7928 const u8 *addr)
7930 struct qeth_ipaddr *ipaddr;
7932 ipaddr = qeth_get_addr_buffer(proto);
7933 if (ipaddr){
7934 if (proto == QETH_PROT_IPV4){
7935 QETH_DBF_TEXT(trace, 2, "delvipa4");
7936 memcpy(&ipaddr->u.a4.addr, addr, 4);
7937 ipaddr->u.a4.mask = 0;
7938 #ifdef CONFIG_QETH_IPV6
7939 } else if (proto == QETH_PROT_IPV6){
7940 QETH_DBF_TEXT(trace, 2, "delvipa6");
7941 memcpy(&ipaddr->u.a6.addr, addr, 16);
7942 ipaddr->u.a6.pfxlen = 0;
7943 #endif
7945 ipaddr->type = QETH_IP_TYPE_VIPA;
7946 } else
7947 return;
7948 if (!qeth_delete_ip(card, ipaddr))
7949 kfree(ipaddr);
7950 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
7951 schedule_work(&card->kernel_thread_starter);
7955 * proxy ARP related functions
7958 qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
7959 const u8 *addr)
7961 struct qeth_ipaddr *ipaddr;
7962 unsigned long flags;
7963 int rc = 0;
7965 ipaddr = qeth_get_addr_buffer(proto);
7966 if (ipaddr){
7967 if (proto == QETH_PROT_IPV4){
7968 QETH_DBF_TEXT(trace, 2, "addrxip4");
7969 memcpy(&ipaddr->u.a4.addr, addr, 4);
7970 ipaddr->u.a4.mask = 0;
7971 #ifdef CONFIG_QETH_IPV6
7972 } else if (proto == QETH_PROT_IPV6){
7973 QETH_DBF_TEXT(trace, 2, "addrxip6");
7974 memcpy(&ipaddr->u.a6.addr, addr, 16);
7975 ipaddr->u.a6.pfxlen = 0;
7976 #endif
7978 ipaddr->type = QETH_IP_TYPE_RXIP;
7979 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
7980 ipaddr->del_flags = 0;
7981 } else
7982 return -ENOMEM;
7983 spin_lock_irqsave(&card->ip_lock, flags);
7984 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
7985 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
7986 rc = -EEXIST;
7987 spin_unlock_irqrestore(&card->ip_lock, flags);
7988 if (rc){
7989 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
7990 return rc;
7992 if (!qeth_add_ip(card, ipaddr))
7993 kfree(ipaddr);
7994 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
7995 schedule_work(&card->kernel_thread_starter);
7996 return 0;
7999 void
8000 qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8001 const u8 *addr)
8003 struct qeth_ipaddr *ipaddr;
8005 ipaddr = qeth_get_addr_buffer(proto);
8006 if (ipaddr){
8007 if (proto == QETH_PROT_IPV4){
8008 QETH_DBF_TEXT(trace, 2, "addrxip4");
8009 memcpy(&ipaddr->u.a4.addr, addr, 4);
8010 ipaddr->u.a4.mask = 0;
8011 #ifdef CONFIG_QETH_IPV6
8012 } else if (proto == QETH_PROT_IPV6){
8013 QETH_DBF_TEXT(trace, 2, "addrxip6");
8014 memcpy(&ipaddr->u.a6.addr, addr, 16);
8015 ipaddr->u.a6.pfxlen = 0;
8016 #endif
8018 ipaddr->type = QETH_IP_TYPE_RXIP;
8019 } else
8020 return;
8021 if (!qeth_delete_ip(card, ipaddr))
8022 kfree(ipaddr);
8023 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8024 schedule_work(&card->kernel_thread_starter);
8028 * IP event handler
8030 static int
8031 qeth_ip_event(struct notifier_block *this,
8032 unsigned long event,void *ptr)
8034 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8035 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8036 struct qeth_ipaddr *addr;
8037 struct qeth_card *card;
8039 QETH_DBF_TEXT(trace,3,"ipevent");
8040 card = qeth_get_card_from_dev(dev);
8041 if (!card)
8042 return NOTIFY_DONE;
8043 if (card->options.layer2)
8044 return NOTIFY_DONE;
8046 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8047 if (addr != NULL) {
8048 addr->u.a4.addr = ifa->ifa_address;
8049 addr->u.a4.mask = ifa->ifa_mask;
8050 addr->type = QETH_IP_TYPE_NORMAL;
8051 } else
8052 goto out;
8054 switch(event) {
8055 case NETDEV_UP:
8056 if (!qeth_add_ip(card, addr))
8057 kfree(addr);
8058 break;
8059 case NETDEV_DOWN:
8060 if (!qeth_delete_ip(card, addr))
8061 kfree(addr);
8062 break;
8063 default:
8064 break;
8066 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8067 schedule_work(&card->kernel_thread_starter);
8068 out:
8069 return NOTIFY_DONE;
8072 static struct notifier_block qeth_ip_notifier = {
8073 qeth_ip_event,
8077 #ifdef CONFIG_QETH_IPV6
8079 * IPv6 event handler
8081 static int
8082 qeth_ip6_event(struct notifier_block *this,
8083 unsigned long event,void *ptr)
8086 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8087 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8088 struct qeth_ipaddr *addr;
8089 struct qeth_card *card;
8091 QETH_DBF_TEXT(trace,3,"ip6event");
8093 card = qeth_get_card_from_dev(dev);
8094 if (!card)
8095 return NOTIFY_DONE;
8096 if (!qeth_is_supported(card, IPA_IPV6))
8097 return NOTIFY_DONE;
8099 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8100 if (addr != NULL) {
8101 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8102 addr->u.a6.pfxlen = ifa->prefix_len;
8103 addr->type = QETH_IP_TYPE_NORMAL;
8104 } else
8105 goto out;
8107 switch(event) {
8108 case NETDEV_UP:
8109 if (!qeth_add_ip(card, addr))
8110 kfree(addr);
8111 break;
8112 case NETDEV_DOWN:
8113 if (!qeth_delete_ip(card, addr))
8114 kfree(addr);
8115 break;
8116 default:
8117 break;
8119 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8120 schedule_work(&card->kernel_thread_starter);
8121 out:
8122 return NOTIFY_DONE;
8125 static struct notifier_block qeth_ip6_notifier = {
8126 qeth_ip6_event,
8129 #endif
8131 static int
8132 __qeth_reboot_event_card(struct device *dev, void *data)
8134 struct qeth_card *card;
8136 card = (struct qeth_card *) dev->driver_data;
8137 qeth_clear_ip_list(card, 0, 0);
8138 qeth_qdio_clear_card(card, 0);
8139 return 0;
8142 static int
8143 qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8146 driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8147 __qeth_reboot_event_card);
8148 return NOTIFY_DONE;
8152 static struct notifier_block qeth_reboot_notifier = {
8153 qeth_reboot_event,
8157 static int
8158 qeth_register_notifiers(void)
8160 int r;
8162 QETH_DBF_TEXT(trace,5,"regnotif");
8163 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8164 return r;
8165 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8166 goto out_reboot;
8167 #ifdef CONFIG_QETH_IPV6
8168 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8169 goto out_ipv4;
8170 #endif
8171 return 0;
8173 #ifdef CONFIG_QETH_IPV6
8174 out_ipv4:
8175 unregister_inetaddr_notifier(&qeth_ip_notifier);
8176 #endif
8177 out_reboot:
8178 unregister_reboot_notifier(&qeth_reboot_notifier);
8179 return r;
8183 * unregister all event notifiers
8185 static void
8186 qeth_unregister_notifiers(void)
8189 QETH_DBF_TEXT(trace,5,"unregnot");
8190 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8191 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8192 #ifdef CONFIG_QETH_IPV6
8193 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8194 #endif /* QETH_IPV6 */
8198 #ifdef CONFIG_QETH_IPV6
8199 static int
8200 qeth_ipv6_init(void)
8202 qeth_old_arp_constructor = arp_tbl.constructor;
8203 write_lock(&arp_tbl.lock);
8204 arp_tbl.constructor = qeth_arp_constructor;
8205 write_unlock(&arp_tbl.lock);
8207 arp_direct_ops = (struct neigh_ops*)
8208 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8209 if (!arp_direct_ops)
8210 return -ENOMEM;
8212 memcpy(arp_direct_ops, &arp_direct_ops_template,
8213 sizeof(struct neigh_ops));
8215 return 0;
8218 static void
8219 qeth_ipv6_uninit(void)
8221 write_lock(&arp_tbl.lock);
8222 arp_tbl.constructor = qeth_old_arp_constructor;
8223 write_unlock(&arp_tbl.lock);
8224 kfree(arp_direct_ops);
8226 #endif /* CONFIG_QETH_IPV6 */
8228 static void
8229 qeth_sysfs_unregister(void)
8231 qeth_remove_driver_attributes();
8232 ccw_driver_unregister(&qeth_ccw_driver);
8233 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8234 s390_root_dev_unregister(qeth_root_dev);
8237 * register qeth at sysfs
8239 static int
8240 qeth_sysfs_register(void)
8242 int rc=0;
8244 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8245 if (rc)
8246 return rc;
8247 rc = ccw_driver_register(&qeth_ccw_driver);
8248 if (rc)
8249 return rc;
8250 rc = qeth_create_driver_attributes();
8251 if (rc)
8252 return rc;
8253 qeth_root_dev = s390_root_dev_register("qeth");
8254 if (IS_ERR(qeth_root_dev)) {
8255 rc = PTR_ERR(qeth_root_dev);
8256 return rc;
8258 return 0;
8261 /***
8262 * init function
8264 static int __init
8265 qeth_init(void)
8267 int rc=0;
8269 qeth_eyecatcher();
8270 PRINT_INFO("loading %s (%s/%s/%s/%s/%s/%s/%s %s %s)\n",
8271 version, VERSION_QETH_C, VERSION_QETH_H,
8272 VERSION_QETH_MPC_H, VERSION_QETH_MPC_C,
8273 VERSION_QETH_FS_H, VERSION_QETH_PROC_C,
8274 VERSION_QETH_SYS_C, QETH_VERSION_IPV6,
8275 QETH_VERSION_VLAN);
8277 INIT_LIST_HEAD(&qeth_card_list.list);
8278 INIT_LIST_HEAD(&qeth_notify_list);
8279 spin_lock_init(&qeth_notify_lock);
8280 rwlock_init(&qeth_card_list.rwlock);
8282 if (qeth_register_dbf_views())
8283 goto out_err;
8284 if (qeth_sysfs_register())
8285 goto out_sysfs;
8287 #ifdef CONFIG_QETH_IPV6
8288 if (qeth_ipv6_init()) {
8289 PRINT_ERR("Out of memory during ipv6 init.\n");
8290 goto out_sysfs;
8292 #endif /* QETH_IPV6 */
8293 if (qeth_register_notifiers())
8294 goto out_ipv6;
8295 if (qeth_create_procfs_entries())
8296 goto out_notifiers;
8298 return rc;
8300 out_notifiers:
8301 qeth_unregister_notifiers();
8302 out_ipv6:
8303 #ifdef CONFIG_QETH_IPV6
8304 qeth_ipv6_uninit();
8305 #endif /* QETH_IPV6 */
8306 out_sysfs:
8307 qeth_sysfs_unregister();
8308 qeth_unregister_dbf_views();
8309 out_err:
8310 PRINT_ERR("Initialization failed");
8311 return rc;
8314 static void
8315 __exit qeth_exit(void)
8317 struct qeth_card *card, *tmp;
8318 unsigned long flags;
8320 QETH_DBF_TEXT(trace,1, "cleanup.");
8323 * Weed would not need to clean up our devices here, because the
8324 * common device layer calls qeth_remove_device for each device
8325 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8326 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8327 * qeth_remove_device called by the common device layer would otherwise
8328 * do a "hard" shutdown (card->use_hard_stop is set to one in
8329 * qeth_remove_device).
8331 again:
8332 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8333 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8334 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8335 qeth_set_offline(card->gdev);
8336 qeth_remove_device(card->gdev);
8337 goto again;
8339 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8340 #ifdef CONFIG_QETH_IPV6
8341 qeth_ipv6_uninit();
8342 #endif
8343 qeth_unregister_notifiers();
8344 qeth_remove_procfs_entries();
8345 qeth_sysfs_unregister();
8346 qeth_unregister_dbf_views();
8347 printk("qeth: removed\n");
8350 EXPORT_SYMBOL(qeth_eyecatcher);
8351 module_init(qeth_init);
8352 module_exit(qeth_exit);
8353 MODULE_AUTHOR("Frank Pavlic <pavlic@de.ibm.com>");
8354 MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8355 "Copyright 2000,2003 IBM Corporation\n");
8357 MODULE_LICENSE("GPL");