3 * linux/drivers/s390/net/qeth_main.c ($Revision: 1.242 $)
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)
12 * Frank Pavlic (fpavlic@de.ibm.com) and
13 * Thomas Spatzier <tspat@de.ibm.com>
15 * $Revision: 1.242 $ $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)
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.
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/string.h>
37 #include <linux/errno.h>
40 #include <linux/inetdevice.h>
41 #include <linux/netdevice.h>
42 #include <linux/sched.h>
43 #include <linux/workqueue.h>
44 #include <linux/kernel.h>
45 #include <linux/slab.h>
46 #include <linux/interrupt.h>
47 #include <linux/tcp.h>
48 #include <linux/icmp.h>
49 #include <linux/skbuff.h>
51 #include <linux/igmp.h>
52 #include <linux/init.h>
53 #include <linux/reboot.h>
54 #include <linux/mii.h>
55 #include <linux/rcupdate.h>
56 #include <linux/ethtool.h>
60 #include <net/route.h>
62 #include <asm/ebcdic.h>
65 #include <asm/timex.h>
66 #include <asm/semaphore.h>
67 #include <asm/uaccess.h>
72 #include "qeth_eddp.h"
75 #define VERSION_QETH_C "$Revision: 1.242 $"
76 static const char *version = "qeth S/390 OSA-Express driver";
79 * Debug Facility Stuff
81 static debug_info_t *qeth_dbf_setup = NULL;
82 static debug_info_t *qeth_dbf_data = NULL;
83 static debug_info_t *qeth_dbf_misc = NULL;
84 static debug_info_t *qeth_dbf_control = NULL;
85 debug_info_t *qeth_dbf_trace = NULL;
86 static debug_info_t *qeth_dbf_sense = NULL;
87 static debug_info_t *qeth_dbf_qerr = NULL;
89 DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
92 * some more definitions and declarations
94 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
96 /* list of our cards */
97 struct qeth_card_list_struct qeth_card_list;
98 /*process list want to be notified*/
99 spinlock_t qeth_notify_lock;
100 struct list_head qeth_notify_list;
102 static void qeth_send_control_data_cb(struct qeth_channel *,
103 struct qeth_cmd_buffer *);
106 * here we go with function implementation
109 qeth_init_qdio_info(struct qeth_card *card);
112 qeth_init_qdio_queues(struct qeth_card *card);
115 qeth_alloc_qdio_buffers(struct qeth_card *card);
118 qeth_free_qdio_buffers(struct qeth_card *);
121 qeth_clear_qdio_buffers(struct qeth_card *);
124 qeth_clear_ip_list(struct qeth_card *, int, int);
127 qeth_clear_ipacmd_list(struct qeth_card *);
130 qeth_qdio_clear_card(struct qeth_card *, int);
133 qeth_clear_working_pool_list(struct qeth_card *);
136 qeth_clear_cmd_buffers(struct qeth_channel *);
139 qeth_stop(struct net_device *);
142 qeth_clear_ipato_list(struct qeth_card *);
145 qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
148 qeth_irq_tasklet(unsigned long);
151 qeth_set_online(struct ccwgroup_device *);
154 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
156 static struct qeth_ipaddr *
157 qeth_get_addr_buffer(enum qeth_prot_versions);
160 qeth_set_multicast_list(struct net_device *);
163 qeth_setadp_promisc_mode(struct qeth_card *);
166 qeth_notify_processes(void)
168 /*notify all registered processes */
169 struct qeth_notify_list_struct *n_entry;
171 QETH_DBF_TEXT(trace,3,"procnoti");
172 spin_lock(&qeth_notify_lock);
173 list_for_each_entry(n_entry, &qeth_notify_list, list) {
174 send_sig(n_entry->signum, n_entry->task, 1);
176 spin_unlock(&qeth_notify_lock);
180 qeth_notifier_unregister(struct task_struct *p)
182 struct qeth_notify_list_struct *n_entry, *tmp;
184 QETH_DBF_TEXT(trace, 2, "notunreg");
185 spin_lock(&qeth_notify_lock);
186 list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
187 if (n_entry->task == p) {
188 list_del(&n_entry->list);
194 spin_unlock(&qeth_notify_lock);
198 qeth_notifier_register(struct task_struct *p, int signum)
200 struct qeth_notify_list_struct *n_entry;
202 /*check first if entry already exists*/
203 spin_lock(&qeth_notify_lock);
204 list_for_each_entry(n_entry, &qeth_notify_list, list) {
205 if (n_entry->task == p) {
206 n_entry->signum = signum;
207 spin_unlock(&qeth_notify_lock);
211 spin_unlock(&qeth_notify_lock);
213 n_entry = (struct qeth_notify_list_struct *)
214 kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL);
218 n_entry->signum = signum;
219 spin_lock(&qeth_notify_lock);
220 list_add(&n_entry->list,&qeth_notify_list);
221 spin_unlock(&qeth_notify_lock);
227 * free channel command buffers
230 qeth_clean_channel(struct qeth_channel *channel)
234 QETH_DBF_TEXT(setup, 2, "freech");
235 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
236 kfree(channel->iob[cnt].data);
243 qeth_free_card(struct qeth_card *card)
246 QETH_DBF_TEXT(setup, 2, "freecrd");
247 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
248 qeth_clean_channel(&card->read);
249 qeth_clean_channel(&card->write);
251 free_netdev(card->dev);
252 qeth_clear_ip_list(card, 0, 0);
253 qeth_clear_ipato_list(card);
254 kfree(card->ip_tbd_list);
255 qeth_free_qdio_buffers(card);
260 * alloc memory for command buffer per channel
263 qeth_setup_channel(struct qeth_channel *channel)
267 QETH_DBF_TEXT(setup, 2, "setupch");
268 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
269 channel->iob[cnt].data = (char *)
270 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
271 if (channel->iob[cnt].data == NULL)
273 channel->iob[cnt].state = BUF_STATE_FREE;
274 channel->iob[cnt].channel = channel;
275 channel->iob[cnt].callback = qeth_send_control_data_cb;
276 channel->iob[cnt].rc = 0;
278 if (cnt < QETH_CMD_BUFFER_NO) {
280 kfree(channel->iob[cnt].data);
284 channel->io_buf_no = 0;
285 atomic_set(&channel->irq_pending, 0);
286 spin_lock_init(&channel->iob_lock);
288 init_waitqueue_head(&channel->wait_q);
289 channel->irq_tasklet.data = (unsigned long) channel;
290 channel->irq_tasklet.func = qeth_irq_tasklet;
295 * alloc memory for card structure
297 static struct qeth_card *
298 qeth_alloc_card(void)
300 struct qeth_card *card;
302 QETH_DBF_TEXT(setup, 2, "alloccrd");
303 card = (struct qeth_card *) kmalloc(sizeof(struct qeth_card),
307 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
308 memset(card, 0, sizeof(struct qeth_card));
309 if (qeth_setup_channel(&card->read)) {
313 if (qeth_setup_channel(&card->write)) {
314 qeth_clean_channel(&card->read);
322 __qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb)
327 switch (PTR_ERR(irb)) {
329 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
330 QETH_DBF_TEXT(trace, 2, "ckirberr");
331 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
334 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
335 QETH_DBF_TEXT(trace, 2, "ckirberr");
336 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
339 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
341 QETH_DBF_TEXT(trace, 2, "ckirberr");
342 QETH_DBF_TEXT(trace, 2, " rc???");
348 qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
353 sense = (char *) irb->ecw;
354 cstat = irb->scsw.cstat;
355 dstat = irb->scsw.dstat;
357 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
358 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
359 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
360 QETH_DBF_TEXT(trace,2, "CGENCHK");
361 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
362 cdev->dev.bus_id, dstat, cstat);
363 HEXDUMP16(WARN, "irb: ", irb);
364 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
368 if (dstat & DEV_STAT_UNIT_CHECK) {
369 if (sense[SENSE_RESETTING_EVENT_BYTE] &
370 SENSE_RESETTING_EVENT_FLAG) {
371 QETH_DBF_TEXT(trace,2,"REVIND");
374 if (sense[SENSE_COMMAND_REJECT_BYTE] &
375 SENSE_COMMAND_REJECT_FLAG) {
376 QETH_DBF_TEXT(trace,2,"CMDREJi");
379 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
380 QETH_DBF_TEXT(trace,2,"AFFE");
383 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
384 QETH_DBF_TEXT(trace,2,"ZEROSEN");
387 QETH_DBF_TEXT(trace,2,"DGENCHK");
392 static int qeth_issue_next_read(struct qeth_card *);
398 qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
402 struct qeth_cmd_buffer *buffer;
403 struct qeth_channel *channel;
404 struct qeth_card *card;
406 QETH_DBF_TEXT(trace,5,"irq");
408 if (__qeth_check_irb_error(cdev, irb))
410 cstat = irb->scsw.cstat;
411 dstat = irb->scsw.dstat;
413 card = CARD_FROM_CDEV(cdev);
417 if (card->read.ccwdev == cdev){
418 channel = &card->read;
419 QETH_DBF_TEXT(trace,5,"read");
420 } else if (card->write.ccwdev == cdev) {
421 channel = &card->write;
422 QETH_DBF_TEXT(trace,5,"write");
424 channel = &card->data;
425 QETH_DBF_TEXT(trace,5,"data");
427 atomic_set(&channel->irq_pending, 0);
429 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
430 channel->state = CH_STATE_STOPPED;
432 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
433 channel->state = CH_STATE_HALTED;
435 /*let's wake up immediately on data channel*/
436 if ((channel == &card->data) && (intparm != 0))
439 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
440 QETH_DBF_TEXT(trace, 6, "clrchpar");
441 /* we don't have to handle this further */
444 if (intparm == QETH_HALT_CHANNEL_PARM) {
445 QETH_DBF_TEXT(trace, 6, "hltchpar");
446 /* we don't have to handle this further */
449 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
450 (dstat & DEV_STAT_UNIT_CHECK) ||
452 if (irb->esw.esw0.erw.cons) {
453 /* TODO: we should make this s390dbf */
454 PRINT_WARN("sense data available on channel %s.\n",
455 CHANNEL_ID(channel));
456 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
457 HEXDUMP16(WARN,"irb: ",irb);
458 HEXDUMP16(WARN,"sense data: ",irb->ecw);
460 rc = qeth_get_problem(cdev,irb);
462 qeth_schedule_recovery(card);
468 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
469 buffer->state = BUF_STATE_PROCESSED;
471 if (channel == &card->data)
474 if (channel == &card->read &&
475 channel->state == CH_STATE_UP)
476 qeth_issue_next_read(card);
478 tasklet_schedule(&channel->irq_tasklet);
481 wake_up(&card->wait_q);
485 * tasklet function scheduled from irq handler
488 qeth_irq_tasklet(unsigned long data)
490 struct qeth_card *card;
491 struct qeth_channel *channel;
492 struct qeth_cmd_buffer *iob;
495 QETH_DBF_TEXT(trace,5,"irqtlet");
496 channel = (struct qeth_channel *) data;
498 index = channel->buf_no;
499 card = CARD_FROM_CDEV(channel->ccwdev);
500 while (iob[index].state == BUF_STATE_PROCESSED) {
501 if (iob[index].callback !=NULL) {
502 iob[index].callback(channel,iob + index);
504 index = (index + 1) % QETH_CMD_BUFFER_NO;
506 channel->buf_no = index;
507 wake_up(&card->wait_q);
510 static int qeth_stop_card(struct qeth_card *, int);
513 __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
515 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
516 int rc = 0, rc2 = 0, rc3 = 0;
517 enum qeth_card_states recover_flag;
519 QETH_DBF_TEXT(setup, 3, "setoffl");
520 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
522 recover_flag = card->state;
523 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
524 PRINT_WARN("Stopping card %s interrupted by user!\n",
528 rc = ccw_device_set_offline(CARD_DDEV(card));
529 rc2 = ccw_device_set_offline(CARD_WDEV(card));
530 rc3 = ccw_device_set_offline(CARD_RDEV(card));
532 rc = (rc2) ? rc2 : rc3;
534 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
535 if (recover_flag == CARD_STATE_UP)
536 card->state = CARD_STATE_RECOVER;
537 qeth_notify_processes();
542 qeth_set_offline(struct ccwgroup_device *cgdev)
544 return __qeth_set_offline(cgdev, 0);
548 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads);
552 qeth_remove_device(struct ccwgroup_device *cgdev)
554 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
557 QETH_DBF_TEXT(setup, 3, "rmdev");
558 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
563 if (qeth_wait_for_threads(card, 0xffffffff))
566 if (cgdev->state == CCWGROUP_ONLINE){
567 card->use_hard_stop = 1;
568 qeth_set_offline(cgdev);
570 /* remove form our internal list */
571 write_lock_irqsave(&qeth_card_list.rwlock, flags);
572 list_del(&card->list);
573 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
575 unregister_netdev(card->dev);
576 qeth_remove_device_attributes(&cgdev->dev);
577 qeth_free_card(card);
578 cgdev->dev.driver_data = NULL;
579 put_device(&cgdev->dev);
583 qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
585 qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
588 * Add/remove address to/from card's ip list, i.e. try to add or remove
589 * reference to/from an IP address that is already registered on the card.
591 * 0 address was on card and its reference count has been adjusted,
592 * but is still > 0, so nothing has to be done
593 * also returns 0 if card was not on card and the todo was to delete
594 * the address -> there is also nothing to be done
595 * 1 address was not on card and the todo is to add it to the card's ip
597 * -1 address was on card and its reference count has been decremented
598 * to <= 0 by the todo -> address must be removed from card
601 __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
602 struct qeth_ipaddr **__addr)
604 struct qeth_ipaddr *addr;
607 list_for_each_entry(addr, &card->ip_list, entry) {
608 if (card->options.layer2) {
609 if ((addr->type == todo->type) &&
610 (memcmp(&addr->mac, &todo->mac,
611 OSA_ADDR_LEN) == 0)) {
617 if ((addr->proto == QETH_PROT_IPV4) &&
618 (todo->proto == QETH_PROT_IPV4) &&
619 (addr->type == todo->type) &&
620 (addr->u.a4.addr == todo->u.a4.addr) &&
621 (addr->u.a4.mask == todo->u.a4.mask)) {
625 if ((addr->proto == QETH_PROT_IPV6) &&
626 (todo->proto == QETH_PROT_IPV6) &&
627 (addr->type == todo->type) &&
628 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
629 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
630 sizeof(struct in6_addr)) == 0)) {
636 addr->users += todo->users;
637 if (addr->users <= 0){
641 /* for VIPA and RXIP limit refcount to 1 */
642 if (addr->type != QETH_IP_TYPE_NORMAL)
647 if (todo->users > 0) {
648 /* for VIPA and RXIP limit refcount to 1 */
649 if (todo->type != QETH_IP_TYPE_NORMAL)
657 __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
660 struct qeth_ipaddr *tmp;
662 list_for_each_entry(tmp, list, entry) {
663 if ((tmp->proto == QETH_PROT_IPV4) &&
664 (addr->proto == QETH_PROT_IPV4) &&
665 ((same_type && (tmp->type == addr->type)) ||
666 (!same_type && (tmp->type != addr->type)) ) &&
667 (tmp->u.a4.addr == addr->u.a4.addr) ){
670 if ((tmp->proto == QETH_PROT_IPV6) &&
671 (addr->proto == QETH_PROT_IPV6) &&
672 ((same_type && (tmp->type == addr->type)) ||
673 (!same_type && (tmp->type != addr->type)) ) &&
674 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
675 sizeof(struct in6_addr)) == 0) ) {
683 * Add IP to be added to todo list. If there is already an "add todo"
684 * in this list we just incremenent the reference count.
685 * Returns 0 if we just incremented reference count.
688 __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
690 struct qeth_ipaddr *tmp, *t;
693 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
694 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
695 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
697 if (card->options.layer2) {
698 if ((tmp->type == addr->type) &&
699 (tmp->is_multicast == addr->is_multicast) &&
700 (memcmp(&tmp->mac, &addr->mac,
701 OSA_ADDR_LEN) == 0)) {
707 if ((tmp->proto == QETH_PROT_IPV4) &&
708 (addr->proto == QETH_PROT_IPV4) &&
709 (tmp->type == addr->type) &&
710 (tmp->is_multicast == addr->is_multicast) &&
711 (tmp->u.a4.addr == addr->u.a4.addr) &&
712 (tmp->u.a4.mask == addr->u.a4.mask)) {
716 if ((tmp->proto == QETH_PROT_IPV6) &&
717 (addr->proto == QETH_PROT_IPV6) &&
718 (tmp->type == addr->type) &&
719 (tmp->is_multicast == addr->is_multicast) &&
720 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
721 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
722 sizeof(struct in6_addr)) == 0)) {
728 if (addr->users != 0)
729 tmp->users += addr->users;
731 tmp->users += add? 1:-1;
732 if (tmp->users == 0) {
733 list_del(&tmp->entry);
738 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
739 list_add(&addr->entry, card->ip_tbd_list);
741 if (addr->users == 0)
742 addr->users += add? 1:-1;
743 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
744 qeth_is_addr_covered_by_ipato(card, addr)){
745 QETH_DBF_TEXT(trace, 2, "tkovaddr");
746 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
748 list_add_tail(&addr->entry, card->ip_tbd_list);
755 * Remove IP address from list
758 qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
763 QETH_DBF_TEXT(trace, 4, "delip");
765 if (card->options.layer2)
766 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
767 else if (addr->proto == QETH_PROT_IPV4)
768 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
770 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
771 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
773 spin_lock_irqsave(&card->ip_lock, flags);
774 rc = __qeth_insert_ip_todo(card, addr, 0);
775 spin_unlock_irqrestore(&card->ip_lock, flags);
780 qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
785 QETH_DBF_TEXT(trace, 4, "addip");
786 if (card->options.layer2)
787 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
788 else if (addr->proto == QETH_PROT_IPV4)
789 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
791 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
792 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
794 spin_lock_irqsave(&card->ip_lock, flags);
795 rc = __qeth_insert_ip_todo(card, addr, 1);
796 spin_unlock_irqrestore(&card->ip_lock, flags);
801 __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
803 struct qeth_ipaddr *addr, *tmp;
806 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
807 if (addr->is_multicast) {
808 spin_unlock_irqrestore(&card->ip_lock, *flags);
809 rc = qeth_deregister_addr_entry(card, addr);
810 spin_lock_irqsave(&card->ip_lock, *flags);
812 list_del(&addr->entry);
821 qeth_set_ip_addr_list(struct qeth_card *card)
823 struct list_head *tbd_list;
824 struct qeth_ipaddr *todo, *addr;
828 QETH_DBF_TEXT(trace, 2, "sdiplist");
829 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
831 spin_lock_irqsave(&card->ip_lock, flags);
832 tbd_list = card->ip_tbd_list;
833 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
834 if (!card->ip_tbd_list) {
835 QETH_DBF_TEXT(trace, 0, "silnomem");
836 card->ip_tbd_list = tbd_list;
837 spin_unlock_irqrestore(&card->ip_lock, flags);
840 INIT_LIST_HEAD(card->ip_tbd_list);
842 while (!list_empty(tbd_list)){
843 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
844 list_del(&todo->entry);
845 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
846 __qeth_delete_all_mc(card, &flags);
850 rc = __qeth_ref_ip_on_card(card, todo, &addr);
852 /* nothing to be done; only adjusted refcount */
854 } else if (rc == 1) {
855 /* new entry to be added to on-card list */
856 spin_unlock_irqrestore(&card->ip_lock, flags);
857 rc = qeth_register_addr_entry(card, todo);
858 spin_lock_irqsave(&card->ip_lock, flags);
860 list_add_tail(&todo->entry, &card->ip_list);
863 } else if (rc == -1) {
864 /* on-card entry to be removed */
865 list_del_init(&addr->entry);
866 spin_unlock_irqrestore(&card->ip_lock, flags);
867 rc = qeth_deregister_addr_entry(card, addr);
868 spin_lock_irqsave(&card->ip_lock, flags);
872 list_add_tail(&addr->entry, &card->ip_list);
876 spin_unlock_irqrestore(&card->ip_lock, flags);
880 static void qeth_delete_mc_addresses(struct qeth_card *);
881 static void qeth_add_multicast_ipv4(struct qeth_card *);
882 static void qeth_layer2_add_multicast(struct qeth_card *);
883 #ifdef CONFIG_QETH_IPV6
884 static void qeth_add_multicast_ipv6(struct qeth_card *);
888 qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
892 spin_lock_irqsave(&card->thread_mask_lock, flags);
893 if ( !(card->thread_allowed_mask & thread) ||
894 (card->thread_start_mask & thread) ) {
895 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
898 card->thread_start_mask |= thread;
899 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
904 qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
908 spin_lock_irqsave(&card->thread_mask_lock, flags);
909 card->thread_start_mask &= ~thread;
910 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
911 wake_up(&card->wait_q);
915 qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
919 spin_lock_irqsave(&card->thread_mask_lock, flags);
920 card->thread_running_mask &= ~thread;
921 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
922 wake_up(&card->wait_q);
926 __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
931 spin_lock_irqsave(&card->thread_mask_lock, flags);
932 if (card->thread_start_mask & thread){
933 if ((card->thread_allowed_mask & thread) &&
934 !(card->thread_running_mask & thread)){
936 card->thread_start_mask &= ~thread;
937 card->thread_running_mask |= thread;
941 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
946 qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
950 wait_event(card->wait_q,
951 (rc = __qeth_do_run_thread(card, thread)) >= 0);
956 qeth_register_ip_addresses(void *ptr)
958 struct qeth_card *card;
960 card = (struct qeth_card *) ptr;
961 daemonize("qeth_reg_ip");
962 QETH_DBF_TEXT(trace,4,"regipth1");
963 if (!qeth_do_run_thread(card, QETH_SET_IP_THREAD))
965 QETH_DBF_TEXT(trace,4,"regipth2");
966 qeth_set_ip_addr_list(card);
967 qeth_clear_thread_running_bit(card, QETH_SET_IP_THREAD);
972 * Drive the SET_PROMISC_MODE thread
975 qeth_set_promisc_mode(void *ptr)
977 struct qeth_card *card = (struct qeth_card *) ptr;
979 daemonize("qeth_setprm");
980 QETH_DBF_TEXT(trace,4,"setprm1");
981 if (!qeth_do_run_thread(card, QETH_SET_PROMISC_MODE_THREAD))
983 QETH_DBF_TEXT(trace,4,"setprm2");
984 qeth_setadp_promisc_mode(card);
985 qeth_clear_thread_running_bit(card, QETH_SET_PROMISC_MODE_THREAD);
990 qeth_recover(void *ptr)
992 struct qeth_card *card;
995 card = (struct qeth_card *) ptr;
996 daemonize("qeth_recover");
997 QETH_DBF_TEXT(trace,2,"recover1");
998 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
999 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1001 QETH_DBF_TEXT(trace,2,"recover2");
1002 PRINT_WARN("Recovery of device %s started ...\n",
1004 card->use_hard_stop = 1;
1005 __qeth_set_offline(card->gdev,1);
1006 rc = __qeth_set_online(card->gdev,1);
1008 PRINT_INFO("Device %s successfully recovered!\n",
1011 PRINT_INFO("Device %s could not be recovered!\n",
1013 /* don't run another scheduled recovery */
1014 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1015 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1020 qeth_schedule_recovery(struct qeth_card *card)
1022 QETH_DBF_TEXT(trace,2,"startrec");
1024 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
1025 schedule_work(&card->kernel_thread_starter);
1029 qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1031 unsigned long flags;
1034 spin_lock_irqsave(&card->thread_mask_lock, flags);
1035 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
1036 (u8) card->thread_start_mask,
1037 (u8) card->thread_allowed_mask,
1038 (u8) card->thread_running_mask);
1039 rc = (card->thread_start_mask & thread);
1040 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1045 qeth_start_kernel_thread(struct qeth_card *card)
1047 QETH_DBF_TEXT(trace , 2, "strthrd");
1049 if (card->read.state != CH_STATE_UP &&
1050 card->write.state != CH_STATE_UP)
1053 if (qeth_do_start_thread(card, QETH_SET_IP_THREAD))
1054 kernel_thread(qeth_register_ip_addresses, (void *)card,SIGCHLD);
1055 if (qeth_do_start_thread(card, QETH_SET_PROMISC_MODE_THREAD))
1056 kernel_thread(qeth_set_promisc_mode, (void *)card, SIGCHLD);
1057 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1058 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1063 qeth_set_intial_options(struct qeth_card *card)
1065 card->options.route4.type = NO_ROUTER;
1066 #ifdef CONFIG_QETH_IPV6
1067 card->options.route6.type = NO_ROUTER;
1068 #endif /* QETH_IPV6 */
1069 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1070 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1071 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1072 card->options.fake_broadcast = 0;
1073 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1074 card->options.fake_ll = 0;
1075 if (card->info.type == QETH_CARD_TYPE_OSN)
1076 card->options.layer2 = 1;
1078 card->options.layer2 = 0;
1082 * initialize channels ,card and all state machines
1085 qeth_setup_card(struct qeth_card *card)
1088 QETH_DBF_TEXT(setup, 2, "setupcrd");
1089 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1091 card->read.state = CH_STATE_DOWN;
1092 card->write.state = CH_STATE_DOWN;
1093 card->data.state = CH_STATE_DOWN;
1094 card->state = CARD_STATE_DOWN;
1095 card->lan_online = 0;
1096 card->use_hard_stop = 0;
1098 #ifdef CONFIG_QETH_VLAN
1099 spin_lock_init(&card->vlanlock);
1100 card->vlangrp = NULL;
1102 spin_lock_init(&card->lock);
1103 spin_lock_init(&card->ip_lock);
1104 spin_lock_init(&card->thread_mask_lock);
1105 card->thread_start_mask = 0;
1106 card->thread_allowed_mask = 0;
1107 card->thread_running_mask = 0;
1108 INIT_WORK(&card->kernel_thread_starter,
1109 (void *)qeth_start_kernel_thread,card);
1110 INIT_LIST_HEAD(&card->ip_list);
1111 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1112 if (!card->ip_tbd_list) {
1113 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1116 INIT_LIST_HEAD(card->ip_tbd_list);
1117 INIT_LIST_HEAD(&card->cmd_waiter_list);
1118 init_waitqueue_head(&card->wait_q);
1119 /* intial options */
1120 qeth_set_intial_options(card);
1121 /* IP address takeover */
1122 INIT_LIST_HEAD(&card->ipato.entries);
1123 card->ipato.enabled = 0;
1124 card->ipato.invert4 = 0;
1125 card->ipato.invert6 = 0;
1126 /* init QDIO stuff */
1127 qeth_init_qdio_info(card);
1132 is_1920_device (struct qeth_card *card)
1134 int single_queue = 0;
1135 struct ccw_device *ccwdev;
1136 struct channelPath_dsc {
1147 QETH_DBF_TEXT(setup, 2, "chk_1920");
1149 ccwdev = card->data.ccwdev;
1150 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1151 if (chp_dsc != NULL) {
1152 /* CHPP field bit 6 == 1 -> single queue */
1153 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1156 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1157 return single_queue;
1161 qeth_determine_card_type(struct qeth_card *card)
1165 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1167 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1168 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1169 while (known_devices[i][4]) {
1170 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1171 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1172 card->info.type = known_devices[i][4];
1173 card->qdio.no_out_queues = known_devices[i][8];
1174 card->info.is_multicast_different = known_devices[i][9];
1175 if (is_1920_device(card)) {
1176 PRINT_INFO("Priority Queueing not able "
1177 "due to hardware limitations!\n");
1178 card->qdio.no_out_queues = 1;
1179 card->qdio.default_out_queue = 0;
1185 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1186 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1191 qeth_probe_device(struct ccwgroup_device *gdev)
1193 struct qeth_card *card;
1195 unsigned long flags;
1198 QETH_DBF_TEXT(setup, 2, "probedev");
1201 if (!get_device(dev))
1204 QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
1206 card = qeth_alloc_card();
1209 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1212 card->read.ccwdev = gdev->cdev[0];
1213 card->write.ccwdev = gdev->cdev[1];
1214 card->data.ccwdev = gdev->cdev[2];
1215 gdev->dev.driver_data = card;
1217 gdev->cdev[0]->handler = qeth_irq;
1218 gdev->cdev[1]->handler = qeth_irq;
1219 gdev->cdev[2]->handler = qeth_irq;
1221 if ((rc = qeth_determine_card_type(card))){
1222 PRINT_WARN("%s: not a valid card type\n", __func__);
1223 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1225 qeth_free_card(card);
1228 if ((rc = qeth_setup_card(card))){
1229 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1231 qeth_free_card(card);
1234 rc = qeth_create_device_attributes(dev);
1237 qeth_free_card(card);
1240 /* insert into our internal list */
1241 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1242 list_add_tail(&card->list, &qeth_card_list.list);
1243 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1249 qeth_get_unitaddr(struct qeth_card *card)
1255 QETH_DBF_TEXT(setup, 2, "getunit");
1256 rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length);
1258 PRINT_ERR("read_conf_data for device %s returned %i\n",
1259 CARD_DDEV_ID(card), rc);
1262 card->info.chpid = prcd[30];
1263 card->info.unit_addr2 = prcd[31];
1264 card->info.cula = prcd[63];
1265 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1266 (prcd[0x11] == _ascebc['M']));
1271 qeth_init_tokens(struct qeth_card *card)
1273 card->token.issuer_rm_w = 0x00010103UL;
1274 card->token.cm_filter_w = 0x00010108UL;
1275 card->token.cm_connection_w = 0x0001010aUL;
1276 card->token.ulp_filter_w = 0x0001010bUL;
1277 card->token.ulp_connection_w = 0x0001010dUL;
1281 raw_devno_from_bus_id(char *id)
1283 id += (strlen(id) - 4);
1284 return (__u16) simple_strtoul(id, &id, 16);
1290 qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1292 struct qeth_card *card;
1294 QETH_DBF_TEXT(trace, 4, "setupccw");
1295 card = CARD_FROM_CDEV(channel->ccwdev);
1296 if (channel == &card->read)
1297 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1299 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1300 channel->ccw.count = len;
1301 channel->ccw.cda = (__u32) __pa(iob);
1305 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1307 static struct qeth_cmd_buffer *
1308 __qeth_get_buffer(struct qeth_channel *channel)
1312 QETH_DBF_TEXT(trace, 6, "getbuff");
1313 index = channel->io_buf_no;
1315 if (channel->iob[index].state == BUF_STATE_FREE) {
1316 channel->iob[index].state = BUF_STATE_LOCKED;
1317 channel->io_buf_no = (channel->io_buf_no + 1) %
1319 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1320 return channel->iob + index;
1322 index = (index + 1) % QETH_CMD_BUFFER_NO;
1323 } while(index != channel->io_buf_no);
1329 * release command buffer
1332 qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1334 unsigned long flags;
1336 QETH_DBF_TEXT(trace, 6, "relbuff");
1337 spin_lock_irqsave(&channel->iob_lock, flags);
1338 memset(iob->data, 0, QETH_BUFSIZE);
1339 iob->state = BUF_STATE_FREE;
1340 iob->callback = qeth_send_control_data_cb;
1342 spin_unlock_irqrestore(&channel->iob_lock, flags);
1345 static struct qeth_cmd_buffer *
1346 qeth_get_buffer(struct qeth_channel *channel)
1348 struct qeth_cmd_buffer *buffer = NULL;
1349 unsigned long flags;
1351 spin_lock_irqsave(&channel->iob_lock, flags);
1352 buffer = __qeth_get_buffer(channel);
1353 spin_unlock_irqrestore(&channel->iob_lock, flags);
1357 static struct qeth_cmd_buffer *
1358 qeth_wait_for_buffer(struct qeth_channel *channel)
1360 struct qeth_cmd_buffer *buffer;
1361 wait_event(channel->wait_q,
1362 ((buffer = qeth_get_buffer(channel)) != NULL));
1367 qeth_clear_cmd_buffers(struct qeth_channel *channel)
1371 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1372 qeth_release_buffer(channel,&channel->iob[cnt]);
1373 channel->buf_no = 0;
1374 channel->io_buf_no = 0;
1378 * start IDX for read and write channel
1381 qeth_idx_activate_get_answer(struct qeth_channel *channel,
1382 void (*idx_reply_cb)(struct qeth_channel *,
1383 struct qeth_cmd_buffer *))
1385 struct qeth_cmd_buffer *iob;
1386 unsigned long flags;
1388 struct qeth_card *card;
1390 QETH_DBF_TEXT(setup, 2, "idxanswr");
1391 card = CARD_FROM_CDEV(channel->ccwdev);
1392 iob = qeth_get_buffer(channel);
1393 iob->callback = idx_reply_cb;
1394 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1395 channel->ccw.count = QETH_BUFSIZE;
1396 channel->ccw.cda = (__u32) __pa(iob->data);
1398 wait_event(card->wait_q,
1399 atomic_compare_and_swap(0,1,&channel->irq_pending) == 0);
1400 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1401 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1402 rc = ccw_device_start(channel->ccwdev,
1403 &channel->ccw,(addr_t) iob, 0, 0);
1404 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1407 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1408 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1409 atomic_set(&channel->irq_pending, 0);
1410 wake_up(&card->wait_q);
1413 rc = wait_event_interruptible_timeout(card->wait_q,
1414 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1415 if (rc == -ERESTARTSYS)
1417 if (channel->state != CH_STATE_UP){
1419 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1420 qeth_clear_cmd_buffers(channel);
1427 qeth_idx_activate_channel(struct qeth_channel *channel,
1428 void (*idx_reply_cb)(struct qeth_channel *,
1429 struct qeth_cmd_buffer *))
1431 struct qeth_card *card;
1432 struct qeth_cmd_buffer *iob;
1433 unsigned long flags;
1437 card = CARD_FROM_CDEV(channel->ccwdev);
1439 QETH_DBF_TEXT(setup, 2, "idxactch");
1441 iob = qeth_get_buffer(channel);
1442 iob->callback = idx_reply_cb;
1443 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1444 channel->ccw.count = IDX_ACTIVATE_SIZE;
1445 channel->ccw.cda = (__u32) __pa(iob->data);
1446 if (channel == &card->write) {
1447 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1448 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1449 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1450 card->seqno.trans_hdr++;
1452 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1453 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1454 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1456 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1457 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1458 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1459 &card->info.func_level,sizeof(__u16));
1460 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1461 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1462 temp = (card->info.cula << 8) + card->info.unit_addr2;
1463 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1465 wait_event(card->wait_q,
1466 atomic_compare_and_swap(0,1,&channel->irq_pending) == 0);
1467 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1468 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1469 rc = ccw_device_start(channel->ccwdev,
1470 &channel->ccw,(addr_t) iob, 0, 0);
1471 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1474 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1475 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1476 atomic_set(&channel->irq_pending, 0);
1477 wake_up(&card->wait_q);
1480 rc = wait_event_interruptible_timeout(card->wait_q,
1481 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1482 if (rc == -ERESTARTSYS)
1484 if (channel->state != CH_STATE_ACTIVATING) {
1485 PRINT_WARN("qeth: IDX activate timed out!\n");
1486 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1487 qeth_clear_cmd_buffers(channel);
1490 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1494 qeth_peer_func_level(int level)
1496 if ((level & 0xff) == 8)
1497 return (level & 0xff) + 0x400;
1498 if (((level >> 8) & 3) == 1)
1499 return (level & 0xff) + 0x200;
1504 qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1506 struct qeth_card *card;
1509 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1511 if (channel->state == CH_STATE_DOWN) {
1512 channel->state = CH_STATE_ACTIVATING;
1515 card = CARD_FROM_CDEV(channel->ccwdev);
1517 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1518 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1519 "reply\n", CARD_WDEV_ID(card));
1522 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1523 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1524 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1525 "function level mismatch "
1526 "(sent: 0x%x, received: 0x%x)\n",
1527 CARD_WDEV_ID(card), card->info.func_level, temp);
1530 channel->state = CH_STATE_UP;
1532 qeth_release_buffer(channel, iob);
1536 qeth_check_idx_response(unsigned char *buffer)
1541 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1542 if ((buffer[2] & 0xc0) == 0xc0) {
1543 PRINT_WARN("received an IDX TERMINATE "
1544 "with cause code 0x%02x%s\n",
1546 ((buffer[4] == 0x22) ?
1547 " -- try another portname" : ""));
1548 QETH_DBF_TEXT(trace, 2, "ckidxres");
1549 QETH_DBF_TEXT(trace, 2, " idxterm");
1550 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1557 qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1559 struct qeth_card *card;
1562 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1563 if (channel->state == CH_STATE_DOWN) {
1564 channel->state = CH_STATE_ACTIVATING;
1568 card = CARD_FROM_CDEV(channel->ccwdev);
1569 if (qeth_check_idx_response(iob->data)) {
1572 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1573 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1574 "reply\n", CARD_RDEV_ID(card));
1579 * temporary fix for microcode bug
1580 * to revert it,replace OR by AND
1582 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1583 (card->info.type == QETH_CARD_TYPE_OSAE) )
1584 card->info.portname_required = 1;
1586 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1587 if (temp != qeth_peer_func_level(card->info.func_level)) {
1588 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1589 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1590 CARD_RDEV_ID(card), card->info.func_level, temp);
1593 memcpy(&card->token.issuer_rm_r,
1594 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1595 QETH_MPC_TOKEN_LENGTH);
1596 memcpy(&card->info.mcl_level[0],
1597 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1598 channel->state = CH_STATE_UP;
1600 qeth_release_buffer(channel,iob);
1604 qeth_issue_next_read(struct qeth_card *card)
1607 struct qeth_cmd_buffer *iob;
1609 QETH_DBF_TEXT(trace,5,"issnxrd");
1610 if (card->read.state != CH_STATE_UP)
1612 iob = qeth_get_buffer(&card->read);
1614 PRINT_WARN("issue_next_read failed: no iob available!\n");
1617 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1618 wait_event(card->wait_q,
1619 atomic_compare_and_swap(0,1,&card->read.irq_pending) == 0);
1620 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1621 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1622 (addr_t) iob, 0, 0);
1624 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1625 atomic_set(&card->read.irq_pending, 0);
1626 qeth_schedule_recovery(card);
1627 wake_up(&card->wait_q);
1632 static struct qeth_reply *
1633 qeth_alloc_reply(struct qeth_card *card)
1635 struct qeth_reply *reply;
1637 reply = kmalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1639 memset(reply, 0, sizeof(struct qeth_reply));
1640 atomic_set(&reply->refcnt, 1);
1647 qeth_get_reply(struct qeth_reply *reply)
1649 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1650 atomic_inc(&reply->refcnt);
1654 qeth_put_reply(struct qeth_reply *reply)
1656 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1657 if (atomic_dec_and_test(&reply->refcnt))
1662 qeth_cmd_timeout(unsigned long data)
1664 struct qeth_reply *reply, *list_reply, *r;
1665 unsigned long flags;
1667 reply = (struct qeth_reply *) data;
1668 spin_lock_irqsave(&reply->card->lock, flags);
1669 list_for_each_entry_safe(list_reply, r,
1670 &reply->card->cmd_waiter_list, list) {
1671 if (reply == list_reply){
1672 qeth_get_reply(reply);
1673 list_del_init(&reply->list);
1674 spin_unlock_irqrestore(&reply->card->lock, flags);
1676 reply->received = 1;
1677 wake_up(&reply->wait_q);
1678 qeth_put_reply(reply);
1682 spin_unlock_irqrestore(&reply->card->lock, flags);
1685 static struct qeth_ipa_cmd *
1686 qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1688 struct qeth_ipa_cmd *cmd = NULL;
1690 QETH_DBF_TEXT(trace,5,"chkipad");
1691 if (IS_IPA(iob->data)){
1692 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1693 if (IS_IPA_REPLY(cmd))
1696 switch (cmd->hdr.command) {
1697 case IPA_CMD_STOPLAN:
1698 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1699 "there is a network problem or "
1700 "someone pulled the cable or "
1701 "disabled the port.\n",
1702 QETH_CARD_IFNAME(card),
1704 card->lan_online = 0;
1705 netif_carrier_off(card->dev);
1707 case IPA_CMD_STARTLAN:
1708 PRINT_INFO("Link reestablished on %s "
1709 "(CHPID 0x%X). Scheduling "
1710 "IP address reset.\n",
1711 QETH_CARD_IFNAME(card),
1713 netif_carrier_on(card->dev);
1714 qeth_schedule_recovery(card);
1716 case IPA_CMD_MODCCID:
1718 case IPA_CMD_REGISTER_LOCAL_ADDR:
1719 QETH_DBF_TEXT(trace,3, "irla");
1721 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1722 QETH_DBF_TEXT(trace,3, "urla");
1725 PRINT_WARN("Received data is IPA "
1726 "but not a reply!\n");
1735 * wake all waiting ipa commands
1738 qeth_clear_ipacmd_list(struct qeth_card *card)
1740 struct qeth_reply *reply, *r;
1741 unsigned long flags;
1743 QETH_DBF_TEXT(trace, 4, "clipalst");
1745 spin_lock_irqsave(&card->lock, flags);
1746 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1747 qeth_get_reply(reply);
1749 reply->received = 1;
1750 list_del_init(&reply->list);
1751 wake_up(&reply->wait_q);
1752 qeth_put_reply(reply);
1754 spin_unlock_irqrestore(&card->lock, flags);
1758 qeth_send_control_data_cb(struct qeth_channel *channel,
1759 struct qeth_cmd_buffer *iob)
1761 struct qeth_card *card;
1762 struct qeth_reply *reply, *r;
1763 struct qeth_ipa_cmd *cmd;
1764 unsigned long flags;
1767 QETH_DBF_TEXT(trace,4,"sndctlcb");
1769 card = CARD_FROM_CDEV(channel->ccwdev);
1770 if (qeth_check_idx_response(iob->data)) {
1771 qeth_clear_ipacmd_list(card);
1772 qeth_schedule_recovery(card);
1776 cmd = qeth_check_ipa_data(card, iob);
1777 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1779 /*in case of OSN : check if cmd is set */
1780 if (card->info.type == QETH_CARD_TYPE_OSN &&
1782 cmd->hdr.command != IPA_CMD_STARTLAN &&
1783 card->osn_info.assist_cb != NULL) {
1784 card->osn_info.assist_cb(card->dev, cmd);
1788 spin_lock_irqsave(&card->lock, flags);
1789 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1790 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1791 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1792 qeth_get_reply(reply);
1793 list_del_init(&reply->list);
1794 spin_unlock_irqrestore(&card->lock, flags);
1796 if (reply->callback != NULL) {
1798 reply->offset = (__u16)((char*)cmd -
1800 keep_reply = reply->callback(card,
1802 (unsigned long)cmd);
1804 keep_reply = reply->callback(card,
1806 (unsigned long)iob);
1809 reply->rc = (u16) cmd->hdr.return_code;
1811 reply->rc = iob->rc;
1813 spin_lock_irqsave(&card->lock, flags);
1814 list_add_tail(&reply->list,
1815 &card->cmd_waiter_list);
1816 spin_unlock_irqrestore(&card->lock, flags);
1818 reply->received = 1;
1819 wake_up(&reply->wait_q);
1821 qeth_put_reply(reply);
1825 spin_unlock_irqrestore(&card->lock, flags);
1827 memcpy(&card->seqno.pdu_hdr_ack,
1828 QETH_PDU_HEADER_SEQ_NO(iob->data),
1829 QETH_SEQ_NO_LENGTH);
1830 qeth_release_buffer(channel,iob);
1834 qeth_prepare_control_data(struct qeth_card *card, int len,
1835 struct qeth_cmd_buffer *iob)
1837 qeth_setup_ccw(&card->write,iob->data,len);
1838 iob->callback = qeth_release_buffer;
1840 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1841 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1842 card->seqno.trans_hdr++;
1843 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1844 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1845 card->seqno.pdu_hdr++;
1846 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1847 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1848 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1852 qeth_send_control_data(struct qeth_card *card, int len,
1853 struct qeth_cmd_buffer *iob,
1855 (struct qeth_card *, struct qeth_reply*, unsigned long),
1860 unsigned long flags;
1861 struct qeth_reply *reply = NULL;
1862 struct timer_list timer;
1864 QETH_DBF_TEXT(trace, 2, "sendctl");
1866 reply = qeth_alloc_reply(card);
1868 PRINT_WARN("Could no alloc qeth_reply!\n");
1871 reply->callback = reply_cb;
1872 reply->param = reply_param;
1873 if (card->state == CARD_STATE_DOWN)
1874 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1876 reply->seqno = card->seqno.ipa++;
1878 timer.function = qeth_cmd_timeout;
1879 timer.data = (unsigned long) reply;
1880 init_waitqueue_head(&reply->wait_q);
1881 spin_lock_irqsave(&card->lock, flags);
1882 list_add_tail(&reply->list, &card->cmd_waiter_list);
1883 spin_unlock_irqrestore(&card->lock, flags);
1884 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1885 wait_event(card->wait_q,
1886 atomic_compare_and_swap(0,1,&card->write.irq_pending) == 0);
1887 qeth_prepare_control_data(card, len, iob);
1888 if (IS_IPA(iob->data))
1889 timer.expires = jiffies + QETH_IPA_TIMEOUT;
1891 timer.expires = jiffies + QETH_TIMEOUT;
1892 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1893 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1894 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1895 (addr_t) iob, 0, 0);
1896 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1898 PRINT_WARN("qeth_send_control_data: "
1899 "ccw_device_start rc = %i\n", rc);
1900 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1901 spin_lock_irqsave(&card->lock, flags);
1902 list_del_init(&reply->list);
1903 qeth_put_reply(reply);
1904 spin_unlock_irqrestore(&card->lock, flags);
1905 qeth_release_buffer(iob->channel, iob);
1906 atomic_set(&card->write.irq_pending, 0);
1907 wake_up(&card->wait_q);
1911 wait_event(reply->wait_q, reply->received);
1912 del_timer_sync(&timer);
1914 qeth_put_reply(reply);
1919 qeth_osn_send_control_data(struct qeth_card *card, int len,
1920 struct qeth_cmd_buffer *iob)
1922 unsigned long flags;
1925 QETH_DBF_TEXT(trace, 5, "osndctrd");
1927 wait_event(card->wait_q,
1928 atomic_compare_and_swap(0,1,&card->write.irq_pending) == 0);
1929 qeth_prepare_control_data(card, len, iob);
1930 QETH_DBF_TEXT(trace, 6, "osnoirqp");
1931 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1932 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1933 (addr_t) iob, 0, 0);
1934 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1936 PRINT_WARN("qeth_osn_send_control_data: "
1937 "ccw_device_start rc = %i\n", rc);
1938 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1939 qeth_release_buffer(iob->channel, iob);
1940 atomic_set(&card->write.irq_pending, 0);
1941 wake_up(&card->wait_q);
1947 qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1950 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1951 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1952 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1953 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1957 qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1962 QETH_DBF_TEXT(trace,4,"osndipa");
1964 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1965 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1967 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1968 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1969 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1970 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1971 return qeth_osn_send_control_data(card, s1, iob);
1975 qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1977 (struct qeth_card *,struct qeth_reply*, unsigned long),
1983 QETH_DBF_TEXT(trace,4,"sendipa");
1985 if (card->options.layer2)
1986 if (card->info.type == QETH_CARD_TYPE_OSN)
1987 prot_type = QETH_PROT_OSN2;
1989 prot_type = QETH_PROT_LAYER2;
1991 prot_type = QETH_PROT_TCPIP;
1992 qeth_prepare_ipa_cmd(card,iob,prot_type);
1993 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
1994 reply_cb, reply_param);
2000 qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2003 struct qeth_cmd_buffer *iob;
2005 QETH_DBF_TEXT(setup, 2, "cmenblcb");
2007 iob = (struct qeth_cmd_buffer *) data;
2008 memcpy(&card->token.cm_filter_r,
2009 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2010 QETH_MPC_TOKEN_LENGTH);
2011 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2016 qeth_cm_enable(struct qeth_card *card)
2019 struct qeth_cmd_buffer *iob;
2021 QETH_DBF_TEXT(setup,2,"cmenable");
2023 iob = qeth_wait_for_buffer(&card->write);
2024 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2025 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2026 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2027 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2028 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2030 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2031 qeth_cm_enable_cb, NULL);
2036 qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2040 struct qeth_cmd_buffer *iob;
2042 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
2044 iob = (struct qeth_cmd_buffer *) data;
2045 memcpy(&card->token.cm_connection_r,
2046 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2047 QETH_MPC_TOKEN_LENGTH);
2048 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2053 qeth_cm_setup(struct qeth_card *card)
2056 struct qeth_cmd_buffer *iob;
2058 QETH_DBF_TEXT(setup,2,"cmsetup");
2060 iob = qeth_wait_for_buffer(&card->write);
2061 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2062 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2063 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2064 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2065 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2066 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2067 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2068 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2069 qeth_cm_setup_cb, NULL);
2075 qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2079 __u16 mtu, framesize;
2082 struct qeth_cmd_buffer *iob;
2084 QETH_DBF_TEXT(setup, 2, "ulpenacb");
2086 iob = (struct qeth_cmd_buffer *) data;
2087 memcpy(&card->token.ulp_filter_r,
2088 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2089 QETH_MPC_TOKEN_LENGTH);
2090 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
2091 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2092 mtu = qeth_get_mtu_outof_framesize(framesize);
2095 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2098 card->info.max_mtu = mtu;
2099 card->info.initial_mtu = mtu;
2100 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2102 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2103 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
2104 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2107 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2108 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2110 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2111 card->info.link_type = link_type;
2113 card->info.link_type = 0;
2114 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2119 qeth_ulp_enable(struct qeth_card *card)
2123 struct qeth_cmd_buffer *iob;
2125 /*FIXME: trace view callbacks*/
2126 QETH_DBF_TEXT(setup,2,"ulpenabl");
2128 iob = qeth_wait_for_buffer(&card->write);
2129 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2131 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2132 (__u8) card->info.portno;
2133 if (card->options.layer2)
2134 if (card->info.type == QETH_CARD_TYPE_OSN)
2135 prot_type = QETH_PROT_OSN2;
2137 prot_type = QETH_PROT_LAYER2;
2139 prot_type = QETH_PROT_TCPIP;
2141 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2142 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2143 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2144 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2145 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2146 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2147 card->info.portname, 9);
2148 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2149 qeth_ulp_enable_cb, NULL);
2155 __raw_devno_from_bus_id(char *id)
2157 id += (strlen(id) - 4);
2158 return (__u16) simple_strtoul(id, &id, 16);
2162 qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2165 struct qeth_cmd_buffer *iob;
2167 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2169 iob = (struct qeth_cmd_buffer *) data;
2170 memcpy(&card->token.ulp_connection_r,
2171 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2172 QETH_MPC_TOKEN_LENGTH);
2173 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2178 qeth_ulp_setup(struct qeth_card *card)
2182 struct qeth_cmd_buffer *iob;
2184 QETH_DBF_TEXT(setup,2,"ulpsetup");
2186 iob = qeth_wait_for_buffer(&card->write);
2187 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2189 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2190 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2191 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2192 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2193 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2194 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2196 temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card));
2197 memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2);
2198 temp = (card->info.cula << 8) + card->info.unit_addr2;
2199 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2200 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2201 qeth_ulp_setup_cb, NULL);
2206 qeth_check_for_inbound_error(struct qeth_qdio_buffer *buf,
2207 unsigned int qdio_error,
2208 unsigned int siga_error)
2212 if (qdio_error || siga_error) {
2213 QETH_DBF_TEXT(trace, 2, "qdinerr");
2214 QETH_DBF_TEXT(qerr, 2, "qdinerr");
2215 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
2216 buf->buffer->element[15].flags & 0xff);
2217 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
2218 buf->buffer->element[14].flags & 0xff);
2219 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2220 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
2226 static inline struct sk_buff *
2227 qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
2229 struct sk_buff* skb;
2233 if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2234 add_len = sizeof(struct qeth_hdr);
2235 #ifdef CONFIG_QETH_VLAN
2237 add_len = VLAN_HLEN;
2239 skb = dev_alloc_skb(length + add_len);
2241 skb_reserve(skb, add_len);
2245 static inline struct sk_buff *
2246 qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2247 struct qdio_buffer_element **__element, int *__offset,
2248 struct qeth_hdr **hdr)
2250 struct qdio_buffer_element *element = *__element;
2251 int offset = *__offset;
2252 struct sk_buff *skb = NULL;
2257 QETH_DBF_TEXT(trace,6,"nextskb");
2258 /* qeth_hdr must not cross element boundaries */
2259 if (element->length < offset + sizeof(struct qeth_hdr)){
2260 if (qeth_is_last_sbale(element))
2264 if (element->length < sizeof(struct qeth_hdr))
2267 *hdr = element->addr + offset;
2269 offset += sizeof(struct qeth_hdr);
2270 if (card->options.layer2)
2271 if (card->info.type == QETH_CARD_TYPE_OSN)
2272 skb_len = (*hdr)->hdr.osn.pdu_length;
2274 skb_len = (*hdr)->hdr.l2.pkt_length;
2276 skb_len = (*hdr)->hdr.l3.length;
2280 if (card->options.fake_ll){
2281 if(card->dev->type == ARPHRD_IEEE802_TR){
2282 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR, *hdr)))
2284 skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2286 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH, *hdr)))
2288 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2290 } else if (!(skb = qeth_get_skb(skb_len, *hdr)))
2292 data_ptr = element->addr + offset;
2294 data_len = min(skb_len, (int)(element->length - offset));
2296 memcpy(skb_put(skb, data_len), data_ptr, data_len);
2297 skb_len -= data_len;
2299 if (qeth_is_last_sbale(element)){
2300 QETH_DBF_TEXT(trace,4,"unexeob");
2301 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2302 QETH_DBF_TEXT(qerr,2,"unexeob");
2303 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2304 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2305 dev_kfree_skb_any(skb);
2306 card->stats.rx_errors++;
2311 data_ptr = element->addr;
2316 *__element = element;
2320 if (net_ratelimit()){
2321 PRINT_WARN("No memory for packet received on %s.\n",
2322 QETH_CARD_IFNAME(card));
2323 QETH_DBF_TEXT(trace,2,"noskbmem");
2324 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2326 card->stats.rx_dropped++;
2330 static inline __be16
2331 qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2333 struct qeth_card *card;
2336 QETH_DBF_TEXT(trace,6,"typtrans");
2338 card = (struct qeth_card *)dev->priv;
2340 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2341 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2342 return tr_type_trans(skb,dev);
2343 #endif /* CONFIG_TR */
2344 skb->mac.raw = skb->data;
2345 skb_pull(skb, ETH_HLEN );
2348 if (*eth->h_dest & 1) {
2349 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2350 skb->pkt_type = PACKET_BROADCAST;
2352 skb->pkt_type = PACKET_MULTICAST;
2353 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2354 skb->pkt_type = PACKET_OTHERHOST;
2356 if (ntohs(eth->h_proto) >= 1536)
2357 return eth->h_proto;
2358 if (*(unsigned short *) (skb->data) == 0xFFFF)
2359 return htons(ETH_P_802_3);
2360 return htons(ETH_P_802_2);
2364 qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2365 struct qeth_hdr *hdr)
2367 struct trh_hdr *fake_hdr;
2368 struct trllc *fake_llc;
2369 struct iphdr *ip_hdr;
2371 QETH_DBF_TEXT(trace,5,"skbfktr");
2372 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_TR;
2373 /* this is a fake ethernet header */
2374 fake_hdr = (struct trh_hdr *) skb->mac.raw;
2376 /* the destination MAC address */
2377 switch (skb->pkt_type){
2378 case PACKET_MULTICAST:
2379 switch (skb->protocol){
2380 #ifdef CONFIG_QETH_IPV6
2381 case __constant_htons(ETH_P_IPV6):
2382 ndisc_mc_map((struct in6_addr *)
2383 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2384 fake_hdr->daddr, card->dev, 0);
2386 #endif /* CONFIG_QETH_IPV6 */
2387 case __constant_htons(ETH_P_IP):
2388 ip_hdr = (struct iphdr *)skb->data;
2389 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2392 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2395 case PACKET_BROADCAST:
2396 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2399 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2401 /* the source MAC address */
2402 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2403 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2405 memset(fake_hdr->saddr, 0, TR_ALEN);
2407 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2408 fake_llc->dsap = EXTENDED_SAP;
2409 fake_llc->ssap = EXTENDED_SAP;
2410 fake_llc->llc = UI_CMD;
2411 fake_llc->protid[0] = 0;
2412 fake_llc->protid[1] = 0;
2413 fake_llc->protid[2] = 0;
2414 fake_llc->ethertype = ETH_P_IP;
2418 qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
2419 struct qeth_hdr *hdr)
2421 struct ethhdr *fake_hdr;
2422 struct iphdr *ip_hdr;
2424 QETH_DBF_TEXT(trace,5,"skbfketh");
2425 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_ETH;
2426 /* this is a fake ethernet header */
2427 fake_hdr = (struct ethhdr *) skb->mac.raw;
2429 /* the destination MAC address */
2430 switch (skb->pkt_type){
2431 case PACKET_MULTICAST:
2432 switch (skb->protocol){
2433 #ifdef CONFIG_QETH_IPV6
2434 case __constant_htons(ETH_P_IPV6):
2435 ndisc_mc_map((struct in6_addr *)
2436 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2437 fake_hdr->h_dest, card->dev, 0);
2439 #endif /* CONFIG_QETH_IPV6 */
2440 case __constant_htons(ETH_P_IP):
2441 ip_hdr = (struct iphdr *)skb->data;
2442 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
2445 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2448 case PACKET_BROADCAST:
2449 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2452 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2454 /* the source MAC address */
2455 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2456 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2458 memset(fake_hdr->h_source, 0, ETH_ALEN);
2460 fake_hdr->h_proto = skb->protocol;
2464 qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2465 struct qeth_hdr *hdr)
2467 if (card->dev->type == ARPHRD_IEEE802_TR)
2468 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2470 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2474 qeth_rebuild_skb_vlan(struct qeth_card *card, struct sk_buff *skb,
2475 struct qeth_hdr *hdr)
2477 #ifdef CONFIG_QETH_VLAN
2480 if (hdr->hdr.l3.ext_flags &
2481 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2482 vlan_tag = (u16 *) skb_push(skb, VLAN_HLEN);
2483 *vlan_tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2484 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2485 *(vlan_tag + 1) = skb->protocol;
2486 skb->protocol = __constant_htons(ETH_P_8021Q);
2488 #endif /* CONFIG_QETH_VLAN */
2492 qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2493 struct qeth_hdr *hdr)
2495 unsigned short vlan_id = 0;
2496 #ifdef CONFIG_QETH_VLAN
2497 struct vlan_hdr *vhdr;
2500 skb->pkt_type = PACKET_HOST;
2501 skb->protocol = qeth_type_trans(skb, skb->dev);
2502 if (card->options.checksum_type == NO_CHECKSUMMING)
2503 skb->ip_summed = CHECKSUM_UNNECESSARY;
2505 skb->ip_summed = CHECKSUM_NONE;
2506 #ifdef CONFIG_QETH_VLAN
2507 if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) {
2508 vhdr = (struct vlan_hdr *) skb->data;
2510 __constant_htons(vhdr->h_vlan_encapsulated_proto);
2511 vlan_id = hdr->hdr.l2.vlan_id;
2512 skb_pull(skb, VLAN_HLEN);
2515 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
2520 qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2521 struct qeth_hdr *hdr)
2523 #ifdef CONFIG_QETH_IPV6
2524 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2525 skb->pkt_type = PACKET_HOST;
2526 skb->protocol = qeth_type_trans(skb, card->dev);
2529 #endif /* CONFIG_QETH_IPV6 */
2530 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2532 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2533 case QETH_CAST_UNICAST:
2534 skb->pkt_type = PACKET_HOST;
2536 case QETH_CAST_MULTICAST:
2537 skb->pkt_type = PACKET_MULTICAST;
2538 card->stats.multicast++;
2540 case QETH_CAST_BROADCAST:
2541 skb->pkt_type = PACKET_BROADCAST;
2542 card->stats.multicast++;
2544 case QETH_CAST_ANYCAST:
2545 case QETH_CAST_NOCAST:
2547 skb->pkt_type = PACKET_HOST;
2549 qeth_rebuild_skb_vlan(card, skb, hdr);
2550 if (card->options.fake_ll)
2551 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2553 skb->mac.raw = skb->data;
2554 skb->ip_summed = card->options.checksum_type;
2555 if (card->options.checksum_type == HW_CHECKSUMMING){
2556 if ( (hdr->hdr.l3.ext_flags &
2557 (QETH_HDR_EXT_CSUM_HDR_REQ |
2558 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2559 (QETH_HDR_EXT_CSUM_HDR_REQ |
2560 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2561 skb->ip_summed = CHECKSUM_UNNECESSARY;
2563 skb->ip_summed = SW_CHECKSUMMING;
2568 qeth_process_inbound_buffer(struct qeth_card *card,
2569 struct qeth_qdio_buffer *buf, int index)
2571 struct qdio_buffer_element *element;
2572 struct sk_buff *skb;
2573 struct qeth_hdr *hdr;
2578 /* get first element of current buffer */
2579 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2581 #ifdef CONFIG_QETH_PERF_STATS
2582 card->perf_stats.bufs_rec++;
2584 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2586 skb->dev = card->dev;
2587 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2588 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr);
2589 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2590 qeth_rebuild_skb(card, skb, hdr);
2591 else { /*in case of OSN*/
2592 skb_push(skb, sizeof(struct qeth_hdr));
2593 memcpy(skb->data, hdr, sizeof(struct qeth_hdr));
2595 /* is device UP ? */
2596 if (!(card->dev->flags & IFF_UP)){
2597 dev_kfree_skb_any(skb);
2600 #ifdef CONFIG_QETH_VLAN
2602 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2605 if (card->info.type == QETH_CARD_TYPE_OSN)
2606 rxrc = card->osn_info.data_cb(skb);
2608 rxrc = netif_rx(skb);
2609 card->dev->last_rx = jiffies;
2610 card->stats.rx_packets++;
2611 card->stats.rx_bytes += skb->len;
2615 static inline struct qeth_buffer_pool_entry *
2616 qeth_get_buffer_pool_entry(struct qeth_card *card)
2618 struct qeth_buffer_pool_entry *entry;
2620 QETH_DBF_TEXT(trace, 6, "gtbfplen");
2621 if (!list_empty(&card->qdio.in_buf_pool.entry_list)) {
2622 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2623 struct qeth_buffer_pool_entry, list);
2624 list_del_init(&entry->list);
2631 qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2633 struct qeth_buffer_pool_entry *pool_entry;
2636 pool_entry = qeth_get_buffer_pool_entry(card);
2638 * since the buffer is accessed only from the input_tasklet
2639 * there shouldn't be a need to synchronize; also, since we use
2640 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2643 BUG_ON(!pool_entry);
2645 buf->pool_entry = pool_entry;
2646 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2647 buf->buffer->element[i].length = PAGE_SIZE;
2648 buf->buffer->element[i].addr = pool_entry->elements[i];
2649 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2650 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2652 buf->buffer->element[i].flags = 0;
2654 buf->state = QETH_QDIO_BUF_EMPTY;
2658 qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2659 struct qeth_qdio_out_buffer *buf)
2662 struct sk_buff *skb;
2664 /* is PCI flag set on buffer? */
2665 if (buf->buffer->element[0].flags & 0x40)
2666 atomic_dec(&queue->set_pci_flags_count);
2668 while ((skb = skb_dequeue(&buf->skb_list))){
2669 atomic_dec(&skb->users);
2670 dev_kfree_skb_any(skb);
2672 qeth_eddp_buf_release_contexts(buf);
2673 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2674 buf->buffer->element[i].length = 0;
2675 buf->buffer->element[i].addr = NULL;
2676 buf->buffer->element[i].flags = 0;
2678 buf->next_element_to_fill = 0;
2679 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2683 qeth_queue_input_buffer(struct qeth_card *card, int index)
2685 struct qeth_qdio_q *queue = card->qdio.in_q;
2690 QETH_DBF_TEXT(trace,6,"queinbuf");
2691 count = (index < queue->next_buf_to_init)?
2692 card->qdio.in_buf_pool.buf_count -
2693 (queue->next_buf_to_init - index) :
2694 card->qdio.in_buf_pool.buf_count -
2695 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2696 /* only requeue at a certain threshold to avoid SIGAs */
2697 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2698 for (i = queue->next_buf_to_init;
2699 i < queue->next_buf_to_init + count; ++i)
2700 qeth_init_input_buffer(card,
2701 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]);
2703 * according to old code it should be avoided to requeue all
2704 * 128 buffers in order to benefit from PCI avoidance.
2705 * this function keeps at least one buffer (the buffer at
2706 * 'index') un-requeued -> this buffer is the first buffer that
2707 * will be requeued the next time
2709 #ifdef CONFIG_QETH_PERF_STATS
2710 card->perf_stats.inbound_do_qdio_cnt++;
2711 card->perf_stats.inbound_do_qdio_start_time = qeth_get_micros();
2713 rc = do_QDIO(CARD_DDEV(card),
2714 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2715 0, queue->next_buf_to_init, count, NULL);
2716 #ifdef CONFIG_QETH_PERF_STATS
2717 card->perf_stats.inbound_do_qdio_time += qeth_get_micros() -
2718 card->perf_stats.inbound_do_qdio_start_time;
2721 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2722 "return %i (device %s).\n",
2723 rc, CARD_DDEV_ID(card));
2724 QETH_DBF_TEXT(trace,2,"qinberr");
2725 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2727 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2728 QDIO_MAX_BUFFERS_PER_Q;
2733 qeth_put_buffer_pool_entry(struct qeth_card *card,
2734 struct qeth_buffer_pool_entry *entry)
2736 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2737 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2741 qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2742 unsigned int qdio_err, unsigned int siga_err,
2743 unsigned int queue, int first_element, int count,
2744 unsigned long card_ptr)
2746 struct net_device *net_dev;
2747 struct qeth_card *card;
2748 struct qeth_qdio_buffer *buffer;
2752 QETH_DBF_TEXT(trace, 6, "qdinput");
2753 card = (struct qeth_card *) card_ptr;
2754 net_dev = card->dev;
2755 #ifdef CONFIG_QETH_PERF_STATS
2756 card->perf_stats.inbound_cnt++;
2757 card->perf_stats.inbound_start_time = qeth_get_micros();
2759 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2760 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2761 QETH_DBF_TEXT(trace, 1,"qdinchk");
2762 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2763 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2764 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2765 qeth_schedule_recovery(card);
2769 for (i = first_element; i < (first_element + count); ++i) {
2770 index = i % QDIO_MAX_BUFFERS_PER_Q;
2771 buffer = &card->qdio.in_q->bufs[index];
2772 if (!((status == QDIO_STATUS_LOOK_FOR_ERROR) &&
2773 qeth_check_for_inbound_error(buffer, qdio_err, siga_err)))
2774 qeth_process_inbound_buffer(card, buffer, index);
2775 /* clear buffer and give back to hardware */
2776 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2777 qeth_queue_input_buffer(card, index);
2779 #ifdef CONFIG_QETH_PERF_STATS
2780 card->perf_stats.inbound_time += qeth_get_micros() -
2781 card->perf_stats.inbound_start_time;
2786 qeth_handle_send_error(struct qeth_card *card,
2787 struct qeth_qdio_out_buffer *buffer,
2788 int qdio_err, int siga_err)
2790 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2791 int cc = siga_err & 3;
2793 QETH_DBF_TEXT(trace, 6, "hdsnderr");
2797 QETH_DBF_TEXT(trace, 1,"lnkfail");
2798 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2799 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2800 (u16)qdio_err, (u8)sbalf15);
2801 return QETH_SEND_ERROR_LINK_FAILURE;
2803 return QETH_SEND_ERROR_NONE;
2805 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2806 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2807 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2808 return QETH_SEND_ERROR_KICK_IT;
2810 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2811 return QETH_SEND_ERROR_RETRY;
2812 return QETH_SEND_ERROR_LINK_FAILURE;
2813 /* look at qdio_error and sbalf 15 */
2815 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2816 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2817 return QETH_SEND_ERROR_LINK_FAILURE;
2819 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2820 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2821 return QETH_SEND_ERROR_KICK_IT;
2823 return QETH_SEND_ERROR_LINK_FAILURE;
2827 qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2828 int index, int count)
2830 struct qeth_qdio_out_buffer *buf;
2834 QETH_DBF_TEXT(trace, 6, "flushbuf");
2836 for (i = index; i < index + count; ++i) {
2837 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2838 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2839 SBAL_FLAGS_LAST_ENTRY;
2841 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2844 if (!queue->do_pack){
2845 if ((atomic_read(&queue->used_buffers) >=
2846 (QETH_HIGH_WATERMARK_PACK -
2847 QETH_WATERMARK_PACK_FUZZ)) &&
2848 !atomic_read(&queue->set_pci_flags_count)){
2849 /* it's likely that we'll go to packing
2851 atomic_inc(&queue->set_pci_flags_count);
2852 buf->buffer->element[0].flags |= 0x40;
2855 if (!atomic_read(&queue->set_pci_flags_count)){
2857 * there's no outstanding PCI any more, so we
2858 * have to request a PCI to be sure the the PCI
2859 * will wake at some time in the future then we
2860 * can flush packed buffers that might still be
2861 * hanging around, which can happen if no
2862 * further send was requested by the stack
2864 atomic_inc(&queue->set_pci_flags_count);
2865 buf->buffer->element[0].flags |= 0x40;
2870 queue->card->dev->trans_start = jiffies;
2871 #ifdef CONFIG_QETH_PERF_STATS
2872 queue->card->perf_stats.outbound_do_qdio_cnt++;
2873 queue->card->perf_stats.outbound_do_qdio_start_time = qeth_get_micros();
2876 rc = do_QDIO(CARD_DDEV(queue->card),
2877 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT,
2878 queue->queue_no, index, count, NULL);
2880 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT,
2881 queue->queue_no, index, count, NULL);
2882 #ifdef CONFIG_QETH_PERF_STATS
2883 queue->card->perf_stats.outbound_do_qdio_time += qeth_get_micros() -
2884 queue->card->perf_stats.outbound_do_qdio_start_time;
2887 QETH_DBF_TEXT(trace, 2, "flushbuf");
2888 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
2889 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
2890 queue->card->stats.tx_errors += count;
2891 /* this must not happen under normal circumstances. if it
2892 * happens something is really wrong -> recover */
2893 qeth_schedule_recovery(queue->card);
2896 atomic_add(count, &queue->used_buffers);
2897 #ifdef CONFIG_QETH_PERF_STATS
2898 queue->card->perf_stats.bufs_sent += count;
2903 * Switched to packing state if the number of used buffers on a queue
2904 * reaches a certain limit.
2907 qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2909 if (!queue->do_pack) {
2910 if (atomic_read(&queue->used_buffers)
2911 >= QETH_HIGH_WATERMARK_PACK){
2912 /* switch non-PACKING -> PACKING */
2913 QETH_DBF_TEXT(trace, 6, "np->pack");
2914 #ifdef CONFIG_QETH_PERF_STATS
2915 queue->card->perf_stats.sc_dp_p++;
2923 * Switches from packing to non-packing mode. If there is a packing
2924 * buffer on the queue this buffer will be prepared to be flushed.
2925 * In that case 1 is returned to inform the caller. If no buffer
2926 * has to be flushed, zero is returned.
2929 qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2931 struct qeth_qdio_out_buffer *buffer;
2932 int flush_count = 0;
2934 if (queue->do_pack) {
2935 if (atomic_read(&queue->used_buffers)
2936 <= QETH_LOW_WATERMARK_PACK) {
2937 /* switch PACKING -> non-PACKING */
2938 QETH_DBF_TEXT(trace, 6, "pack->np");
2939 #ifdef CONFIG_QETH_PERF_STATS
2940 queue->card->perf_stats.sc_p_dp++;
2943 /* flush packing buffers */
2944 buffer = &queue->bufs[queue->next_buf_to_fill];
2945 if ((atomic_read(&buffer->state) ==
2946 QETH_QDIO_BUF_EMPTY) &&
2947 (buffer->next_element_to_fill > 0)) {
2948 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
2950 queue->next_buf_to_fill =
2951 (queue->next_buf_to_fill + 1) %
2952 QDIO_MAX_BUFFERS_PER_Q;
2960 * Called to flush a packing buffer if no more pci flags are on the queue.
2961 * Checks if there is a packing buffer and prepares it to be flushed.
2962 * In that case returns 1, otherwise zero.
2965 qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2967 struct qeth_qdio_out_buffer *buffer;
2969 buffer = &queue->bufs[queue->next_buf_to_fill];
2970 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2971 (buffer->next_element_to_fill > 0)){
2972 /* it's a packing buffer */
2973 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2974 queue->next_buf_to_fill =
2975 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2982 qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2986 int q_was_packing = 0;
2989 * check if weed have to switch to non-packing mode or if
2990 * we have to get a pci flag out on the queue
2992 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2993 !atomic_read(&queue->set_pci_flags_count)){
2994 if (atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2995 QETH_OUT_Q_UNLOCKED) {
2997 * If we get in here, there was no action in
2998 * do_send_packet. So, we check if there is a
2999 * packing buffer to be flushed here.
3001 netif_stop_queue(queue->card->dev);
3002 index = queue->next_buf_to_fill;
3003 q_was_packing = queue->do_pack;
3004 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
3006 !atomic_read(&queue->set_pci_flags_count))
3008 qeth_flush_buffers_on_no_pci(queue);
3009 #ifdef CONFIG_QETH_PERF_STATS
3011 queue->card->perf_stats.bufs_sent_pack +=
3015 qeth_flush_buffers(queue, 1, index, flush_cnt);
3016 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3022 qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3023 unsigned int qdio_error, unsigned int siga_error,
3024 unsigned int __queue, int first_element, int count,
3025 unsigned long card_ptr)
3027 struct qeth_card *card = (struct qeth_card *) card_ptr;
3028 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3029 struct qeth_qdio_out_buffer *buffer;
3032 QETH_DBF_TEXT(trace, 6, "qdouhdl");
3033 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
3034 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
3035 QETH_DBF_TEXT(trace, 2, "achkcond");
3036 QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
3037 QETH_DBF_TEXT_(trace, 2, "%08x", status);
3038 netif_stop_queue(card->dev);
3039 qeth_schedule_recovery(card);
3043 #ifdef CONFIG_QETH_PERF_STATS
3044 card->perf_stats.outbound_handler_cnt++;
3045 card->perf_stats.outbound_handler_start_time = qeth_get_micros();
3047 for(i = first_element; i < (first_element + count); ++i){
3048 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
3049 /*we only handle the KICK_IT error by doing a recovery */
3050 if (qeth_handle_send_error(card, buffer, qdio_error, siga_error)
3051 == QETH_SEND_ERROR_KICK_IT){
3052 netif_stop_queue(card->dev);
3053 qeth_schedule_recovery(card);
3056 qeth_clear_output_buffer(queue, buffer);
3058 atomic_sub(count, &queue->used_buffers);
3059 /* check if we need to do something on this outbound queue */
3060 if (card->info.type != QETH_CARD_TYPE_IQD)
3061 qeth_check_outbound_queue(queue);
3063 netif_wake_queue(queue->card->dev);
3064 #ifdef CONFIG_QETH_PERF_STATS
3065 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3066 card->perf_stats.outbound_handler_start_time;
3071 qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
3074 param_field[0] = _ascebc['P'];
3075 param_field[1] = _ascebc['C'];
3076 param_field[2] = _ascebc['I'];
3077 param_field[3] = _ascebc['T'];
3078 *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card);
3079 *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card);
3080 *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card);
3084 qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
3086 param_field[16] = _ascebc['B'];
3087 param_field[17] = _ascebc['L'];
3088 param_field[18] = _ascebc['K'];
3089 param_field[19] = _ascebc['T'];
3090 *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total;
3091 *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet;
3092 *((unsigned int *) (¶m_field[28])) = card->info.blkt.inter_packet_jumbo;
3096 qeth_initialize_working_pool_list(struct qeth_card *card)
3098 struct qeth_buffer_pool_entry *entry;
3100 QETH_DBF_TEXT(trace,5,"inwrklst");
3102 list_for_each_entry(entry,
3103 &card->qdio.init_pool.entry_list, init_list) {
3104 qeth_put_buffer_pool_entry(card,entry);
3109 qeth_clear_working_pool_list(struct qeth_card *card)
3111 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3113 QETH_DBF_TEXT(trace,5,"clwrklst");
3114 list_for_each_entry_safe(pool_entry, tmp,
3115 &card->qdio.in_buf_pool.entry_list, list){
3116 list_del(&pool_entry->list);
3121 qeth_free_buffer_pool(struct qeth_card *card)
3123 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3125 QETH_DBF_TEXT(trace,5,"freepool");
3126 list_for_each_entry_safe(pool_entry, tmp,
3127 &card->qdio.init_pool.entry_list, init_list){
3128 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3129 free_page((unsigned long)pool_entry->elements[i]);
3130 list_del(&pool_entry->init_list);
3136 qeth_alloc_buffer_pool(struct qeth_card *card)
3138 struct qeth_buffer_pool_entry *pool_entry;
3142 QETH_DBF_TEXT(trace,5,"alocpool");
3143 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3144 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3146 qeth_free_buffer_pool(card);
3149 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
3150 ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
3153 free_page((unsigned long)
3154 pool_entry->elements[--j]);
3156 qeth_free_buffer_pool(card);
3159 pool_entry->elements[j] = ptr;
3161 list_add(&pool_entry->init_list,
3162 &card->qdio.init_pool.entry_list);
3168 qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3170 QETH_DBF_TEXT(trace, 2, "realcbp");
3172 if ((card->state != CARD_STATE_DOWN) &&
3173 (card->state != CARD_STATE_RECOVER))
3176 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3177 qeth_clear_working_pool_list(card);
3178 qeth_free_buffer_pool(card);
3179 card->qdio.in_buf_pool.buf_count = bufcnt;
3180 card->qdio.init_pool.buf_count = bufcnt;
3181 return qeth_alloc_buffer_pool(card);
3185 qeth_alloc_qdio_buffers(struct qeth_card *card)
3189 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3191 if (card->qdio.state == QETH_QDIO_ALLOCATED)
3194 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3195 GFP_KERNEL|GFP_DMA);
3196 if (!card->qdio.in_q)
3198 QETH_DBF_TEXT(setup, 2, "inq");
3199 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3200 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3201 /* give inbound qeth_qdio_buffers their qdio_buffers */
3202 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3203 card->qdio.in_q->bufs[i].buffer =
3204 &card->qdio.in_q->qdio_bufs[i];
3205 /* inbound buffer pool */
3206 if (qeth_alloc_buffer_pool(card)){
3207 kfree(card->qdio.in_q);
3212 kmalloc(card->qdio.no_out_queues *
3213 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3214 if (!card->qdio.out_qs){
3215 qeth_free_buffer_pool(card);
3218 for (i = 0; i < card->qdio.no_out_queues; ++i){
3219 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3220 GFP_KERNEL|GFP_DMA);
3221 if (!card->qdio.out_qs[i]){
3223 kfree(card->qdio.out_qs[--i]);
3224 kfree(card->qdio.out_qs);
3227 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3228 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3229 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3230 card->qdio.out_qs[i]->queue_no = i;
3231 /* give outbound qeth_qdio_buffers their qdio_buffers */
3232 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3233 card->qdio.out_qs[i]->bufs[j].buffer =
3234 &card->qdio.out_qs[i]->qdio_bufs[j];
3235 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3237 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3240 card->qdio.state = QETH_QDIO_ALLOCATED;
3245 qeth_free_qdio_buffers(struct qeth_card *card)
3249 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3250 if (card->qdio.state == QETH_QDIO_UNINITIALIZED)
3252 kfree(card->qdio.in_q);
3253 /* inbound buffer pool */
3254 qeth_free_buffer_pool(card);
3255 /* free outbound qdio_qs */
3256 for (i = 0; i < card->qdio.no_out_queues; ++i){
3257 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3258 qeth_clear_output_buffer(card->qdio.out_qs[i],
3259 &card->qdio.out_qs[i]->bufs[j]);
3260 kfree(card->qdio.out_qs[i]);
3262 kfree(card->qdio.out_qs);
3263 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3267 qeth_clear_qdio_buffers(struct qeth_card *card)
3271 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3272 /* clear outbound buffers to free skbs */
3273 for (i = 0; i < card->qdio.no_out_queues; ++i)
3274 if (card->qdio.out_qs[i]){
3275 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3276 qeth_clear_output_buffer(card->qdio.out_qs[i],
3277 &card->qdio.out_qs[i]->bufs[j]);
3282 qeth_init_qdio_info(struct qeth_card *card)
3284 QETH_DBF_TEXT(setup, 4, "intqdinf");
3285 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3287 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3288 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3289 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3290 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3291 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3296 qeth_init_qdio_queues(struct qeth_card *card)
3301 QETH_DBF_TEXT(setup, 2, "initqdqs");
3304 memset(card->qdio.in_q->qdio_bufs, 0,
3305 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3306 qeth_initialize_working_pool_list(card);
3307 /*give only as many buffers to hardware as we have buffer pool entries*/
3308 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3309 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3310 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3311 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3312 card->qdio.in_buf_pool.buf_count - 1, NULL);
3314 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3317 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3319 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3322 /* outbound queue */
3323 for (i = 0; i < card->qdio.no_out_queues; ++i){
3324 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3325 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3326 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3327 qeth_clear_output_buffer(card->qdio.out_qs[i],
3328 &card->qdio.out_qs[i]->bufs[j]);
3330 card->qdio.out_qs[i]->card = card;
3331 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3332 card->qdio.out_qs[i]->do_pack = 0;
3333 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3334 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3335 atomic_set(&card->qdio.out_qs[i]->state,
3336 QETH_OUT_Q_UNLOCKED);
3342 qeth_qdio_establish(struct qeth_card *card)
3344 struct qdio_initialize init_data;
3345 char *qib_param_field;
3346 struct qdio_buffer **in_sbal_ptrs;
3347 struct qdio_buffer **out_sbal_ptrs;
3351 QETH_DBF_TEXT(setup, 2, "qdioest");
3353 qib_param_field = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3355 if (!qib_param_field)
3358 memset(qib_param_field, 0, QDIO_MAX_BUFFERS_PER_Q * sizeof(char));
3360 qeth_create_qib_param_field(card, qib_param_field);
3361 qeth_create_qib_param_field_blkt(card, qib_param_field);
3363 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3365 if (!in_sbal_ptrs) {
3366 kfree(qib_param_field);
3369 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3370 in_sbal_ptrs[i] = (struct qdio_buffer *)
3371 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3374 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3375 sizeof(void *), GFP_KERNEL);
3376 if (!out_sbal_ptrs) {
3377 kfree(in_sbal_ptrs);
3378 kfree(qib_param_field);
3381 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3382 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3383 out_sbal_ptrs[k] = (struct qdio_buffer *)
3384 virt_to_phys(card->qdio.out_qs[i]->
3388 memset(&init_data, 0, sizeof(struct qdio_initialize));
3389 init_data.cdev = CARD_DDEV(card);
3390 init_data.q_format = qeth_get_qdio_q_format(card);
3391 init_data.qib_param_field_format = 0;
3392 init_data.qib_param_field = qib_param_field;
3393 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3394 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3395 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3396 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3397 init_data.no_input_qs = 1;
3398 init_data.no_output_qs = card->qdio.no_out_queues;
3399 init_data.input_handler = (qdio_handler_t *)
3400 qeth_qdio_input_handler;
3401 init_data.output_handler = (qdio_handler_t *)
3402 qeth_qdio_output_handler;
3403 init_data.int_parm = (unsigned long) card;
3404 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3405 QDIO_OUTBOUND_0COPY_SBALS |
3406 QDIO_USE_OUTBOUND_PCIS;
3407 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3408 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3410 if (!(rc = qdio_initialize(&init_data)))
3411 card->qdio.state = QETH_QDIO_ESTABLISHED;
3413 kfree(out_sbal_ptrs);
3414 kfree(in_sbal_ptrs);
3415 kfree(qib_param_field);
3420 qeth_qdio_activate(struct qeth_card *card)
3422 QETH_DBF_TEXT(setup,3,"qdioact");
3423 return qdio_activate(CARD_DDEV(card), 0);
3427 qeth_clear_channel(struct qeth_channel *channel)
3429 unsigned long flags;
3430 struct qeth_card *card;
3433 QETH_DBF_TEXT(trace,3,"clearch");
3434 card = CARD_FROM_CDEV(channel->ccwdev);
3435 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3436 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3437 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3441 rc = wait_event_interruptible_timeout(card->wait_q,
3442 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3443 if (rc == -ERESTARTSYS)
3445 if (channel->state != CH_STATE_STOPPED)
3447 channel->state = CH_STATE_DOWN;
3452 qeth_halt_channel(struct qeth_channel *channel)
3454 unsigned long flags;
3455 struct qeth_card *card;
3458 QETH_DBF_TEXT(trace,3,"haltch");
3459 card = CARD_FROM_CDEV(channel->ccwdev);
3460 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3461 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3462 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3466 rc = wait_event_interruptible_timeout(card->wait_q,
3467 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3468 if (rc == -ERESTARTSYS)
3470 if (channel->state != CH_STATE_HALTED)
3476 qeth_halt_channels(struct qeth_card *card)
3478 int rc1 = 0, rc2=0, rc3 = 0;
3480 QETH_DBF_TEXT(trace,3,"haltchs");
3481 rc1 = qeth_halt_channel(&card->read);
3482 rc2 = qeth_halt_channel(&card->write);
3483 rc3 = qeth_halt_channel(&card->data);
3491 qeth_clear_channels(struct qeth_card *card)
3493 int rc1 = 0, rc2=0, rc3 = 0;
3495 QETH_DBF_TEXT(trace,3,"clearchs");
3496 rc1 = qeth_clear_channel(&card->read);
3497 rc2 = qeth_clear_channel(&card->write);
3498 rc3 = qeth_clear_channel(&card->data);
3507 qeth_clear_halt_card(struct qeth_card *card, int halt)
3511 QETH_DBF_TEXT(trace,3,"clhacrd");
3512 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3515 rc = qeth_halt_channels(card);
3518 return qeth_clear_channels(card);
3522 qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3526 QETH_DBF_TEXT(trace,3,"qdioclr");
3527 if (card->qdio.state == QETH_QDIO_ESTABLISHED){
3528 if ((rc = qdio_cleanup(CARD_DDEV(card),
3529 (card->info.type == QETH_CARD_TYPE_IQD) ?
3530 QDIO_FLAG_CLEANUP_USING_HALT :
3531 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3532 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3533 card->qdio.state = QETH_QDIO_ALLOCATED;
3535 if ((rc = qeth_clear_halt_card(card, use_halt)))
3536 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3537 card->state = CARD_STATE_DOWN;
3542 qeth_dm_act(struct qeth_card *card)
3545 struct qeth_cmd_buffer *iob;
3547 QETH_DBF_TEXT(setup,2,"dmact");
3549 iob = qeth_wait_for_buffer(&card->write);
3550 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3552 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3553 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3554 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3555 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3556 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3561 qeth_mpc_initialize(struct qeth_card *card)
3565 QETH_DBF_TEXT(setup,2,"mpcinit");
3567 if ((rc = qeth_issue_next_read(card))){
3568 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3571 if ((rc = qeth_cm_enable(card))){
3572 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3575 if ((rc = qeth_cm_setup(card))){
3576 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3579 if ((rc = qeth_ulp_enable(card))){
3580 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3583 if ((rc = qeth_ulp_setup(card))){
3584 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3587 if ((rc = qeth_alloc_qdio_buffers(card))){
3588 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3591 if ((rc = qeth_qdio_establish(card))){
3592 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3593 qeth_free_qdio_buffers(card);
3596 if ((rc = qeth_qdio_activate(card))){
3597 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3600 if ((rc = qeth_dm_act(card))){
3601 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3607 qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
3611 static struct net_device *
3612 qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3614 struct net_device *dev = NULL;
3617 case QETH_CARD_TYPE_OSAE:
3619 case QETH_LINK_TYPE_LANE_TR:
3620 case QETH_LINK_TYPE_HSTR:
3622 dev = alloc_trdev(0);
3623 #endif /* CONFIG_TR */
3626 dev = alloc_etherdev(0);
3629 case QETH_CARD_TYPE_IQD:
3630 dev = alloc_netdev(0, "hsi%d", ether_setup);
3632 case QETH_CARD_TYPE_OSN:
3633 dev = alloc_netdev(0, "osn%d", ether_setup);
3636 dev = alloc_etherdev(0);
3641 /*hard_header fake function; used in case fake_ll is set */
3643 qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3644 unsigned short type, void *daddr, void *saddr,
3647 if(dev->type == ARPHRD_IEEE802_TR){
3648 struct trh_hdr *hdr;
3649 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3650 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3651 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3652 return QETH_FAKE_LL_LEN_TR;
3656 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3657 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3658 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3659 if (type != ETH_P_802_3)
3660 hdr->h_proto = htons(type);
3662 hdr->h_proto = htons(len);
3663 return QETH_FAKE_LL_LEN_ETH;
3669 qeth_send_packet(struct qeth_card *, struct sk_buff *);
3672 qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3675 struct qeth_card *card;
3677 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3678 card = (struct qeth_card *)dev->priv;
3680 card->stats.tx_dropped++;
3681 card->stats.tx_errors++;
3682 /* return OK; otherwise ksoftirqd goes to 100% */
3683 return NETDEV_TX_OK;
3685 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3686 card->stats.tx_dropped++;
3687 card->stats.tx_errors++;
3688 card->stats.tx_carrier_errors++;
3689 dev_kfree_skb_any(skb);
3690 /* return OK; otherwise ksoftirqd goes to 100% */
3691 return NETDEV_TX_OK;
3693 #ifdef CONFIG_QETH_PERF_STATS
3694 card->perf_stats.outbound_cnt++;
3695 card->perf_stats.outbound_start_time = qeth_get_micros();
3697 netif_stop_queue(dev);
3698 if ((rc = qeth_send_packet(card, skb))) {
3700 return NETDEV_TX_BUSY;
3702 card->stats.tx_errors++;
3703 card->stats.tx_dropped++;
3704 dev_kfree_skb_any(skb);
3705 /*set to OK; otherwise ksoftirqd goes to 100% */
3709 netif_wake_queue(dev);
3710 #ifdef CONFIG_QETH_PERF_STATS
3711 card->perf_stats.outbound_time += qeth_get_micros() -
3712 card->perf_stats.outbound_start_time;
3718 qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3721 #ifdef CONFIG_QETH_VLAN
3722 struct vlan_group *vg;
3725 if (!(vg = card->vlangrp))
3728 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3729 if (vg->vlan_devices[i] == dev){
3730 rc = QETH_VLAN_CARD;
3739 qeth_verify_dev(struct net_device *dev)
3741 struct qeth_card *card;
3742 unsigned long flags;
3745 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3746 list_for_each_entry(card, &qeth_card_list.list, list){
3747 if (card->dev == dev){
3748 rc = QETH_REAL_CARD;
3751 rc = qeth_verify_vlan_dev(dev, card);
3755 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3760 static struct qeth_card *
3761 qeth_get_card_from_dev(struct net_device *dev)
3763 struct qeth_card *card = NULL;
3766 rc = qeth_verify_dev(dev);
3767 if (rc == QETH_REAL_CARD)
3768 card = (struct qeth_card *)dev->priv;
3769 else if (rc == QETH_VLAN_CARD)
3770 card = (struct qeth_card *)
3771 VLAN_DEV_INFO(dev)->real_dev->priv;
3773 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3778 qeth_tx_timeout(struct net_device *dev)
3780 struct qeth_card *card;
3782 card = (struct qeth_card *) dev->priv;
3783 card->stats.tx_errors++;
3784 qeth_schedule_recovery(card);
3788 qeth_open(struct net_device *dev)
3790 struct qeth_card *card;
3792 QETH_DBF_TEXT(trace, 4, "qethopen");
3794 card = (struct qeth_card *) dev->priv;
3796 if (card->state != CARD_STATE_SOFTSETUP)
3799 if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3800 (card->options.layer2) &&
3801 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
3802 QETH_DBF_TEXT(trace,4,"nomacadr");
3805 card->dev->flags |= IFF_UP;
3806 netif_start_queue(dev);
3807 card->data.state = CH_STATE_UP;
3808 card->state = CARD_STATE_UP;
3810 if (!card->lan_online){
3811 if (netif_carrier_ok(dev))
3812 netif_carrier_off(dev);
3818 qeth_stop(struct net_device *dev)
3820 struct qeth_card *card;
3822 QETH_DBF_TEXT(trace, 4, "qethstop");
3824 card = (struct qeth_card *) dev->priv;
3826 netif_stop_queue(dev);
3827 card->dev->flags &= ~IFF_UP;
3828 if (card->state == CARD_STATE_UP)
3829 card->state = CARD_STATE_SOFTSETUP;
3834 qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3836 int cast_type = RTN_UNSPEC;
3838 if (card->info.type == QETH_CARD_TYPE_OSN)
3841 if (skb->dst && skb->dst->neighbour){
3842 cast_type = skb->dst->neighbour->type;
3843 if ((cast_type == RTN_BROADCAST) ||
3844 (cast_type == RTN_MULTICAST) ||
3845 (cast_type == RTN_ANYCAST))
3850 /* try something else */
3851 if (skb->protocol == ETH_P_IPV6)
3852 return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0;
3853 else if (skb->protocol == ETH_P_IP)
3854 return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0;
3856 if (!memcmp(skb->data, skb->dev->broadcast, 6))
3857 return RTN_BROADCAST;
3861 hdr_mac = *((u16 *)skb->data);
3863 switch (card->info.link_type) {
3864 case QETH_LINK_TYPE_HSTR:
3865 case QETH_LINK_TYPE_LANE_TR:
3866 if ((hdr_mac == QETH_TR_MAC_NC) ||
3867 (hdr_mac == QETH_TR_MAC_C))
3868 return RTN_MULTICAST;
3869 /* eth or so multicast? */
3871 if ((hdr_mac == QETH_ETH_MAC_V4) ||
3872 (hdr_mac == QETH_ETH_MAC_V6))
3873 return RTN_MULTICAST;
3880 qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3881 int ipv, int cast_type)
3883 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3884 return card->qdio.default_out_queue;
3885 switch (card->qdio.no_out_queues) {
3887 if (cast_type && card->info.is_multicast_different)
3888 return card->info.is_multicast_different &
3889 (card->qdio.no_out_queues - 1);
3890 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3891 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
3892 if (skb->nh.iph->tos & IP_TOS_NOTIMPORTANT)
3894 if (skb->nh.iph->tos & IP_TOS_HIGHRELIABILITY)
3896 if (skb->nh.iph->tos & IP_TOS_HIGHTHROUGHPUT)
3898 if (skb->nh.iph->tos & IP_TOS_LOWDELAY)
3901 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
3902 return 3 - (skb->nh.iph->tos >> 6);
3903 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3906 return card->qdio.default_out_queue;
3907 case 1: /* fallthrough for single-out-queue 1920-device */
3909 return card->qdio.default_out_queue;
3914 qeth_get_ip_version(struct sk_buff *skb)
3916 switch (skb->protocol) {
3927 qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb,
3928 struct qeth_hdr **hdr, int ipv)
3931 #ifdef CONFIG_QETH_VLAN
3935 QETH_DBF_TEXT(trace, 6, "prepskb");
3936 if (card->info.type == QETH_CARD_TYPE_OSN) {
3937 *hdr = (struct qeth_hdr *)(*skb)->data;
3940 rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3943 #ifdef CONFIG_QETH_VLAN
3944 if (card->vlangrp && vlan_tx_tag_present(*skb) &&
3945 ((ipv == 6) || card->options.layer2) ) {
3947 * Move the mac addresses (6 bytes src, 6 bytes dest)
3948 * to the beginning of the new header. We are using three
3949 * memcpys instead of one memmove to save cycles.
3951 skb_push(*skb, VLAN_HLEN);
3952 memcpy((*skb)->data, (*skb)->data + 4, 4);
3953 memcpy((*skb)->data + 4, (*skb)->data + 8, 4);
3954 memcpy((*skb)->data + 8, (*skb)->data + 12, 4);
3955 tag = (u16 *)((*skb)->data + 12);
3957 * first two bytes = ETH_P_8021Q (0x8100)
3958 * second two bytes = VLANID
3960 *tag = __constant_htons(ETH_P_8021Q);
3961 *(tag + 1) = htons(vlan_tx_tag_get(*skb));
3964 *hdr = (struct qeth_hdr *)
3965 qeth_push_skb(card, skb, sizeof(struct qeth_hdr));
3972 qeth_get_qeth_hdr_flags4(int cast_type)
3974 if (cast_type == RTN_MULTICAST)
3975 return QETH_CAST_MULTICAST;
3976 if (cast_type == RTN_BROADCAST)
3977 return QETH_CAST_BROADCAST;
3978 return QETH_CAST_UNICAST;
3982 qeth_get_qeth_hdr_flags6(int cast_type)
3984 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
3985 if (cast_type == RTN_MULTICAST)
3986 return ct | QETH_CAST_MULTICAST;
3987 if (cast_type == RTN_ANYCAST)
3988 return ct | QETH_CAST_ANYCAST;
3989 if (cast_type == RTN_BROADCAST)
3990 return ct | QETH_CAST_BROADCAST;
3991 return ct | QETH_CAST_UNICAST;
3995 qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
3996 struct sk_buff *skb)
4000 if (!memcmp(skb->data+QETH_HEADER_SIZE,
4001 skb->dev->broadcast,6)) { /* broadcast? */
4002 *(__u32 *)hdr->hdr.l2.flags |=
4003 QETH_LAYER2_FLAG_BROADCAST << 8;
4006 hdr_mac=*((__u16*)skb->data);
4008 switch (card->info.link_type) {
4009 case QETH_LINK_TYPE_HSTR:
4010 case QETH_LINK_TYPE_LANE_TR:
4011 if ((hdr_mac == QETH_TR_MAC_NC) ||
4012 (hdr_mac == QETH_TR_MAC_C) )
4013 *(__u32 *)hdr->hdr.l2.flags |=
4014 QETH_LAYER2_FLAG_MULTICAST << 8;
4016 *(__u32 *)hdr->hdr.l2.flags |=
4017 QETH_LAYER2_FLAG_UNICAST << 8;
4019 /* eth or so multicast? */
4021 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
4022 (hdr_mac==QETH_ETH_MAC_V6) )
4023 *(__u32 *)hdr->hdr.l2.flags |=
4024 QETH_LAYER2_FLAG_MULTICAST << 8;
4026 *(__u32 *)hdr->hdr.l2.flags |=
4027 QETH_LAYER2_FLAG_UNICAST << 8;
4032 qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4033 struct sk_buff *skb, int cast_type)
4035 memset(hdr, 0, sizeof(struct qeth_hdr));
4036 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
4038 /* set byte 0 to "0x02" and byte 3 to casting flags */
4039 if (cast_type==RTN_MULTICAST)
4040 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
4041 else if (cast_type==RTN_BROADCAST)
4042 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
4044 qeth_layer2_get_packet_type(card, hdr, skb);
4046 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
4047 #ifdef CONFIG_QETH_VLAN
4048 /* VSWITCH relies on the VLAN
4049 * information to be present in
4050 * the QDIO header */
4051 if ((card->vlangrp != NULL) &&
4052 vlan_tx_tag_present(skb)) {
4053 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
4054 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
4060 qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4061 struct sk_buff *skb, int ipv, int cast_type)
4063 QETH_DBF_TEXT(trace, 6, "fillhdr");
4065 memset(hdr, 0, sizeof(struct qeth_hdr));
4066 if (card->options.layer2) {
4067 qeth_layer2_fill_header(card, hdr, skb, cast_type);
4070 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
4071 hdr->hdr.l3.ext_flags = 0;
4072 #ifdef CONFIG_QETH_VLAN
4074 * before we're going to overwrite this location with next hop ip.
4075 * v6 uses passthrough, v4 sets the tag in the QDIO header.
4077 if (card->vlangrp && vlan_tx_tag_present(skb)) {
4078 hdr->hdr.l3.ext_flags = (ipv == 4) ?
4079 QETH_HDR_EXT_VLAN_FRAME :
4080 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
4081 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
4083 #endif /* CONFIG_QETH_VLAN */
4084 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
4085 if (ipv == 4) { /* IPv4 */
4086 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
4087 memset(hdr->hdr.l3.dest_addr, 0, 12);
4088 if ((skb->dst) && (skb->dst->neighbour)) {
4089 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
4090 *((u32 *) skb->dst->neighbour->primary_key);
4092 /* fill in destination address used in ip header */
4093 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = skb->nh.iph->daddr;
4095 } else if (ipv == 6) { /* IPv6 or passthru */
4096 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
4097 if ((skb->dst) && (skb->dst->neighbour)) {
4098 memcpy(hdr->hdr.l3.dest_addr,
4099 skb->dst->neighbour->primary_key, 16);
4101 /* fill in destination address used in ip header */
4102 memcpy(hdr->hdr.l3.dest_addr, &skb->nh.ipv6h->daddr, 16);
4104 } else { /* passthrough */
4105 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
4106 !memcmp(skb->data + sizeof(struct qeth_hdr) +
4107 sizeof(__u16), skb->dev->broadcast, 6)) {
4108 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4110 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
4111 skb->dev->broadcast, 6)) { /* broadcast? */
4112 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4115 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
4116 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
4117 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
4123 __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
4124 int is_tso, int *next_element_to_fill)
4126 int length = skb->len;
4132 element = *next_element_to_fill;
4134 first_lap = (is_tso == 0 ? 1 : 0);
4136 while (length > 0) {
4137 /* length_here is the remaining amount of data in this page */
4138 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4139 if (length < length_here)
4140 length_here = length;
4142 buffer->element[element].addr = data;
4143 buffer->element[element].length = length_here;
4144 length -= length_here;
4147 buffer->element[element].flags = 0;
4149 buffer->element[element].flags =
4150 SBAL_FLAGS_LAST_FRAG;
4153 buffer->element[element].flags =
4154 SBAL_FLAGS_FIRST_FRAG;
4156 buffer->element[element].flags =
4157 SBAL_FLAGS_MIDDLE_FRAG;
4159 data += length_here;
4163 *next_element_to_fill = element;
4167 qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4168 struct qeth_qdio_out_buffer *buf,
4169 struct sk_buff *skb)
4171 struct qdio_buffer *buffer;
4172 struct qeth_hdr_tso *hdr;
4173 int flush_cnt = 0, hdr_len, large_send = 0;
4175 QETH_DBF_TEXT(trace, 6, "qdfillbf");
4177 buffer = buf->buffer;
4178 atomic_inc(&skb->users);
4179 skb_queue_tail(&buf->skb_list, skb);
4181 hdr = (struct qeth_hdr_tso *) skb->data;
4182 /*check first on TSO ....*/
4183 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4184 int element = buf->next_element_to_fill;
4186 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4187 /*fill first buffer entry only with header information */
4188 buffer->element[element].addr = skb->data;
4189 buffer->element[element].length = hdr_len;
4190 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4191 buf->next_element_to_fill++;
4192 skb->data += hdr_len;
4193 skb->len -= hdr_len;
4196 if (skb_shinfo(skb)->nr_frags == 0)
4197 __qeth_fill_buffer(skb, buffer, large_send,
4198 (int *)&buf->next_element_to_fill);
4200 __qeth_fill_buffer_frag(skb, buffer, large_send,
4201 (int *)&buf->next_element_to_fill);
4203 if (!queue->do_pack) {
4204 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4205 /* set state to PRIMED -> will be flushed */
4206 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4209 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4210 #ifdef CONFIG_QETH_PERF_STATS
4211 queue->card->perf_stats.skbs_sent_pack++;
4213 if (buf->next_element_to_fill >=
4214 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4216 * packed buffer if full -> set state PRIMED
4217 * -> will be flushed
4219 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4227 qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4228 struct sk_buff *skb, struct qeth_hdr *hdr,
4229 int elements_needed,
4230 struct qeth_eddp_context *ctx)
4232 struct qeth_qdio_out_buffer *buffer;
4233 int buffers_needed = 0;
4237 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4239 /* spin until we get the queue ... */
4240 while (atomic_compare_and_swap(QETH_OUT_Q_UNLOCKED,
4243 /* ... now we've got the queue */
4244 index = queue->next_buf_to_fill;
4245 buffer = &queue->bufs[queue->next_buf_to_fill];
4247 * check if buffer is empty to make sure that we do not 'overtake'
4248 * ourselves and try to fill a buffer that is already primed
4250 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4251 card->stats.tx_dropped++;
4252 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4256 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4257 QDIO_MAX_BUFFERS_PER_Q;
4259 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4260 if (buffers_needed < 0) {
4261 card->stats.tx_dropped++;
4262 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4265 queue->next_buf_to_fill =
4266 (queue->next_buf_to_fill + buffers_needed) %
4267 QDIO_MAX_BUFFERS_PER_Q;
4269 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4271 qeth_fill_buffer(queue, buffer, skb);
4272 qeth_flush_buffers(queue, 0, index, 1);
4274 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4275 WARN_ON(buffers_needed != flush_cnt);
4276 qeth_flush_buffers(queue, 0, index, flush_cnt);
4282 qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4283 struct sk_buff *skb, struct qeth_hdr *hdr,
4284 int elements_needed, struct qeth_eddp_context *ctx)
4286 struct qeth_qdio_out_buffer *buffer;
4288 int flush_count = 0;
4293 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4295 /* spin until we get the queue ... */
4296 while (atomic_compare_and_swap(QETH_OUT_Q_UNLOCKED,
4299 start_index = queue->next_buf_to_fill;
4300 buffer = &queue->bufs[queue->next_buf_to_fill];
4302 * check if buffer is empty to make sure that we do not 'overtake'
4303 * ourselves and try to fill a buffer that is already primed
4305 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY){
4306 card->stats.tx_dropped++;
4307 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4310 /* check if we need to switch packing state of this queue */
4311 qeth_switch_to_packing_if_needed(queue);
4312 if (queue->do_pack){
4315 /* does packet fit in current buffer? */
4316 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4317 buffer->next_element_to_fill) < elements_needed){
4318 /* ... no -> set state PRIMED */
4319 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4321 queue->next_buf_to_fill =
4322 (queue->next_buf_to_fill + 1) %
4323 QDIO_MAX_BUFFERS_PER_Q;
4324 buffer = &queue->bufs[queue->next_buf_to_fill];
4325 /* we did a step forward, so check buffer state
4327 if (atomic_read(&buffer->state) !=
4328 QETH_QDIO_BUF_EMPTY){
4329 card->stats.tx_dropped++;
4330 qeth_flush_buffers(queue, 0, start_index, flush_count);
4331 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4336 /* check if we have enough elements (including following
4337 * free buffers) to handle eddp context */
4338 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4339 printk("eddp tx_dropped 1\n");
4340 card->stats.tx_dropped++;
4347 tmp = qeth_fill_buffer(queue, buffer, skb);
4349 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4351 printk("eddp tx_dropped 2\n");
4352 card->stats.tx_dropped++;
4357 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4358 QDIO_MAX_BUFFERS_PER_Q;
4362 qeth_flush_buffers(queue, 0, start_index, flush_count);
4363 else if (!atomic_read(&queue->set_pci_flags_count))
4364 atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
4366 * queue->state will go from LOCKED -> UNLOCKED or from
4367 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4368 * (switch packing state or flush buffer to get another pci flag out).
4369 * In that case we will enter this loop
4371 while (atomic_dec_return(&queue->state)){
4373 start_index = queue->next_buf_to_fill;
4374 /* check if we can go back to non-packing state */
4375 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4377 * check if we need to flush a packing buffer to get a pci
4378 * flag out on the queue
4380 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4381 flush_count += qeth_flush_buffers_on_no_pci(queue);
4383 qeth_flush_buffers(queue, 0, start_index, flush_count);
4385 /* at this point the queue is UNLOCKED again */
4386 #ifdef CONFIG_QETH_PERF_STATS
4388 queue->card->perf_stats.bufs_sent_pack += flush_count;
4389 #endif /* CONFIG_QETH_PERF_STATS */
4395 qeth_get_elements_no(struct qeth_card *card, void *hdr,
4396 struct sk_buff *skb, int elems)
4398 int elements_needed = 0;
4400 if (skb_shinfo(skb)->nr_frags > 0) {
4401 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4403 if (elements_needed == 0 )
4404 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4405 + skb->len) >> PAGE_SHIFT);
4406 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4407 PRINT_ERR("qeth_do_send_packet: invalid size of "
4408 "IP packet (Number=%d / Length=%d). Discarded.\n",
4409 (elements_needed+elems), skb->len);
4412 return elements_needed;
4416 qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4420 struct qeth_qdio_out_q *queue;
4421 struct qeth_hdr *hdr = NULL;
4422 int elements_needed = 0;
4423 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4424 struct qeth_eddp_context *ctx = NULL;
4427 QETH_DBF_TEXT(trace, 6, "sendpkt");
4429 if (!card->options.layer2) {
4430 ipv = qeth_get_ip_version(skb);
4431 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4432 if ((skb = qeth_pskb_unshare(skb,GFP_ATOMIC)) == NULL) {
4433 card->stats.tx_dropped++;
4434 dev_kfree_skb_irq(skb);
4437 if(card->dev->type == ARPHRD_IEEE802_TR){
4438 skb_pull(skb, QETH_FAKE_LL_LEN_TR);
4440 skb_pull(skb, QETH_FAKE_LL_LEN_ETH);
4444 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4445 (skb->protocol == htons(ETH_P_IPV6))) {
4446 dev_kfree_skb_any(skb);
4449 cast_type = qeth_get_cast_type(card, skb);
4450 if ((cast_type == RTN_BROADCAST) &&
4451 (card->info.broadcast_capable == 0)){
4452 card->stats.tx_dropped++;
4453 card->stats.tx_errors++;
4454 dev_kfree_skb_any(skb);
4455 return NETDEV_TX_OK;
4457 queue = card->qdio.out_qs
4458 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4460 if (skb_shinfo(skb)->tso_size)
4461 large_send = card->options.large_send;
4463 /*are we able to do TSO ? If so ,prepare and send it from here */
4464 if ((large_send == QETH_LARGE_SEND_TSO) &&
4465 (cast_type == RTN_UNSPEC)) {
4466 rc = qeth_tso_prepare_packet(card, skb, ipv, cast_type);
4468 card->stats.tx_dropped++;
4469 card->stats.tx_errors++;
4470 dev_kfree_skb_any(skb);
4471 return NETDEV_TX_OK;
4475 if ((rc = qeth_prepare_skb(card, &skb, &hdr, ipv))) {
4476 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc);
4479 if (card->info.type != QETH_CARD_TYPE_OSN)
4480 qeth_fill_header(card, hdr, skb, ipv, cast_type);
4483 if (large_send == QETH_LARGE_SEND_EDDP) {
4484 ctx = qeth_eddp_create_context(card, skb, hdr);
4486 PRINT_WARN("could not create eddp context\n");
4490 int elems = qeth_get_elements_no(card,(void*) hdr, skb,
4494 elements_needed += elems;
4497 if (card->info.type != QETH_CARD_TYPE_IQD)
4498 rc = qeth_do_send_packet(card, queue, skb, hdr,
4499 elements_needed, ctx);
4501 rc = qeth_do_send_packet_fast(card, queue, skb, hdr,
4502 elements_needed, ctx);
4504 card->stats.tx_packets++;
4505 card->stats.tx_bytes += skb->len;
4506 #ifdef CONFIG_QETH_PERF_STATS
4507 if (skb_shinfo(skb)->tso_size &&
4508 !(large_send == QETH_LARGE_SEND_NO)) {
4509 card->perf_stats.large_send_bytes += skb->len;
4510 card->perf_stats.large_send_cnt++;
4512 if (skb_shinfo(skb)->nr_frags > 0){
4513 card->perf_stats.sg_skbs_sent++;
4514 /* nr_frags + skb->data */
4515 card->perf_stats.sg_frags_sent +=
4516 skb_shinfo(skb)->nr_frags + 1;
4518 #endif /* CONFIG_QETH_PERF_STATS */
4521 /* drop creator's reference */
4522 qeth_eddp_put_context(ctx);
4523 /* free skb; it's not referenced by a buffer */
4525 dev_kfree_skb_any(skb);
4532 qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4534 struct qeth_card *card = (struct qeth_card *) dev->priv;
4538 case MII_BMCR: /* Basic mode control register */
4540 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4541 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4542 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4543 rc |= BMCR_SPEED100;
4545 case MII_BMSR: /* Basic mode status register */
4546 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4547 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4550 case MII_PHYSID1: /* PHYS ID 1 */
4551 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4553 rc = (rc >> 5) & 0xFFFF;
4555 case MII_PHYSID2: /* PHYS ID 2 */
4556 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4558 case MII_ADVERTISE: /* Advertisement control reg */
4561 case MII_LPA: /* Link partner ability reg */
4562 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4563 LPA_100BASE4 | LPA_LPACK;
4565 case MII_EXPANSION: /* Expansion register */
4567 case MII_DCOUNTER: /* disconnect counter */
4569 case MII_FCSCOUNTER: /* false carrier counter */
4571 case MII_NWAYTEST: /* N-way auto-neg test register */
4573 case MII_RERRCOUNTER: /* rx error counter */
4574 rc = card->stats.rx_errors;
4576 case MII_SREVISION: /* silicon revision */
4578 case MII_RESV1: /* reserved 1 */
4580 case MII_LBRERROR: /* loopback, rx, bypass error */
4582 case MII_PHYADDR: /* physical address */
4584 case MII_RESV2: /* reserved 2 */
4586 case MII_TPISTATUS: /* TPI status for 10mbps */
4588 case MII_NCONFIG: /* network interface config */
4598 qeth_mdio_write(struct net_device *dev, int phy_id, int regnum, int value)
4601 case MII_BMCR: /* Basic mode control register */
4602 case MII_BMSR: /* Basic mode status register */
4603 case MII_PHYSID1: /* PHYS ID 1 */
4604 case MII_PHYSID2: /* PHYS ID 2 */
4605 case MII_ADVERTISE: /* Advertisement control reg */
4606 case MII_LPA: /* Link partner ability reg */
4607 case MII_EXPANSION: /* Expansion register */
4608 case MII_DCOUNTER: /* disconnect counter */
4609 case MII_FCSCOUNTER: /* false carrier counter */
4610 case MII_NWAYTEST: /* N-way auto-neg test register */
4611 case MII_RERRCOUNTER: /* rx error counter */
4612 case MII_SREVISION: /* silicon revision */
4613 case MII_RESV1: /* reserved 1 */
4614 case MII_LBRERROR: /* loopback, rx, bypass error */
4615 case MII_PHYADDR: /* physical address */
4616 case MII_RESV2: /* reserved 2 */
4617 case MII_TPISTATUS: /* TPI status for 10mbps */
4618 case MII_NCONFIG: /* network interface config */
4624 static inline const char *
4625 qeth_arp_get_error_cause(int *rc)
4628 case QETH_IPA_ARP_RC_FAILED:
4630 return "operation failed";
4631 case QETH_IPA_ARP_RC_NOTSUPP:
4633 return "operation not supported";
4634 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4636 return "argument out of range";
4637 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4639 return "query operation not supported";
4640 case QETH_IPA_ARP_RC_Q_NO_DATA:
4642 return "no query data available";
4644 return "unknown error";
4649 qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4653 qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4658 QETH_DBF_TEXT(trace,3,"arpstnoe");
4661 * currently GuestLAN only supports the ARP assist function
4662 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4663 * thus we say EOPNOTSUPP for this ARP function
4665 if (card->info.guestlan)
4667 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4668 PRINT_WARN("ARP processing not supported "
4669 "on %s!\n", QETH_CARD_IFNAME(card));
4672 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4673 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4677 PRINT_WARN("Could not set number of ARP entries on %s: "
4679 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4686 qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4687 struct qeth_arp_query_data *qdata,
4688 int entry_size, int uentry_size)
4694 entry_ptr = (char *)&qdata->data;
4695 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4696 for (i = 0; i < qdata->no_entries; ++i){
4697 /* strip off 32 bytes "media specific information" */
4698 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4699 entry_ptr += entry_size;
4700 uentry_ptr += uentry_size;
4705 qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4708 struct qeth_ipa_cmd *cmd;
4709 struct qeth_arp_query_data *qdata;
4710 struct qeth_arp_query_info *qinfo;
4715 QETH_DBF_TEXT(trace,4,"arpquecb");
4717 qinfo = (struct qeth_arp_query_info *) reply->param;
4718 cmd = (struct qeth_ipa_cmd *) data;
4719 if (cmd->hdr.return_code) {
4720 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4723 if (cmd->data.setassparms.hdr.return_code) {
4724 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4725 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4728 qdata = &cmd->data.setassparms.data.query_arp;
4729 switch(qdata->reply_bits){
4731 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4732 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4733 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4736 /* fall through to default */
4738 /* tr is the same as eth -> entry7 */
4739 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4740 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4741 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4744 /* check if there is enough room in userspace */
4745 if ((qinfo->udata_len - qinfo->udata_offset) <
4746 qdata->no_entries * uentry_size){
4747 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4748 cmd->hdr.return_code = -ENOMEM;
4749 PRINT_WARN("query ARP user space buffer is too small for "
4750 "the returned number of ARP entries. "
4751 "Aborting query!\n");
4754 QETH_DBF_TEXT_(trace, 4, "anore%i",
4755 cmd->data.setassparms.hdr.number_of_replies);
4756 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4757 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4759 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4760 /* strip off "media specific information" */
4761 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4764 /*copy entries to user buffer*/
4765 memcpy(qinfo->udata + qinfo->udata_offset,
4766 (char *)&qdata->data, qdata->no_entries*uentry_size);
4768 qinfo->no_entries += qdata->no_entries;
4769 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4770 /* check if all replies received ... */
4771 if (cmd->data.setassparms.hdr.seq_no <
4772 cmd->data.setassparms.hdr.number_of_replies)
4774 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4775 /* keep STRIP_ENTRIES flag so the user program can distinguish
4776 * stripped entries from normal ones */
4777 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4778 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4779 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4783 memcpy(qinfo->udata, &i, 4);
4788 qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4789 int len, int (*reply_cb)(struct qeth_card *,
4790 struct qeth_reply *,
4794 QETH_DBF_TEXT(trace,4,"sendarp");
4796 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4797 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4798 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4799 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4800 reply_cb, reply_param);
4804 qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4805 int len, int (*reply_cb)(struct qeth_card *,
4806 struct qeth_reply *,
4812 QETH_DBF_TEXT(trace,4,"sendsnmp");
4814 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4815 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4816 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4817 /* adjust PDU length fields in IPA_PDU_HEADER */
4818 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4820 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4821 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4822 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4823 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4824 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4825 reply_cb, reply_param);
4828 static struct qeth_cmd_buffer *
4829 qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4830 __u16, __u16, enum qeth_prot_versions);
4832 qeth_arp_query(struct qeth_card *card, char *udata)
4834 struct qeth_cmd_buffer *iob;
4835 struct qeth_arp_query_info qinfo = {0, };
4839 QETH_DBF_TEXT(trace,3,"arpquery");
4841 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4842 IPA_ARP_PROCESSING)) {
4843 PRINT_WARN("ARP processing not supported "
4844 "on %s!\n", QETH_CARD_IFNAME(card));
4847 /* get size of userspace buffer and mask_bits -> 6 bytes */
4848 if (copy_from_user(&qinfo, udata, 6))
4850 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL)))
4852 memset(qinfo.udata, 0, qinfo.udata_len);
4853 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4854 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4855 IPA_CMD_ASS_ARP_QUERY_INFO,
4856 sizeof(int),QETH_PROT_IPV4);
4858 rc = qeth_send_ipa_arp_cmd(card, iob,
4859 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4860 qeth_arp_query_cb, (void *)&qinfo);
4863 PRINT_WARN("Error while querying ARP cache on %s: %s "
4865 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4867 copy_to_user(udata, qinfo.udata, 4);
4869 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4876 * SNMP command callback
4879 qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4880 unsigned long sdata)
4882 struct qeth_ipa_cmd *cmd;
4883 struct qeth_arp_query_info *qinfo;
4884 struct qeth_snmp_cmd *snmp;
4885 unsigned char *data;
4888 QETH_DBF_TEXT(trace,3,"snpcmdcb");
4890 cmd = (struct qeth_ipa_cmd *) sdata;
4891 data = (unsigned char *)((char *)cmd - reply->offset);
4892 qinfo = (struct qeth_arp_query_info *) reply->param;
4893 snmp = &cmd->data.setadapterparms.data.snmp;
4895 if (cmd->hdr.return_code) {
4896 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4899 if (cmd->data.setadapterparms.hdr.return_code) {
4900 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4901 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4904 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4905 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4906 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4908 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4910 /* check if there is enough room in userspace */
4911 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4912 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4913 cmd->hdr.return_code = -ENOMEM;
4916 QETH_DBF_TEXT_(trace, 4, "snore%i",
4917 cmd->data.setadapterparms.hdr.used_total);
4918 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4919 /*copy entries to user buffer*/
4920 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4921 memcpy(qinfo->udata + qinfo->udata_offset,
4923 data_len + offsetof(struct qeth_snmp_cmd,data));
4924 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4926 memcpy(qinfo->udata + qinfo->udata_offset,
4927 (char *)&snmp->request, data_len);
4929 qinfo->udata_offset += data_len;
4930 /* check if all replies received ... */
4931 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4932 cmd->data.setadapterparms.hdr.used_total);
4933 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4934 cmd->data.setadapterparms.hdr.seq_no);
4935 if (cmd->data.setadapterparms.hdr.seq_no <
4936 cmd->data.setadapterparms.hdr.used_total)
4941 static struct qeth_cmd_buffer *
4942 qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4943 enum qeth_prot_versions );
4945 static struct qeth_cmd_buffer *
4946 qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4948 struct qeth_cmd_buffer *iob;
4949 struct qeth_ipa_cmd *cmd;
4951 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4953 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4954 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4955 cmd->data.setadapterparms.hdr.command_code = command;
4956 cmd->data.setadapterparms.hdr.used_total = 1;
4957 cmd->data.setadapterparms.hdr.seq_no = 1;
4963 * function to send SNMP commands to OSA-E card
4966 qeth_snmp_command(struct qeth_card *card, char *udata)
4968 struct qeth_cmd_buffer *iob;
4969 struct qeth_ipa_cmd *cmd;
4970 struct qeth_snmp_ureq *ureq;
4972 struct qeth_arp_query_info qinfo = {0, };
4975 QETH_DBF_TEXT(trace,3,"snmpcmd");
4977 if (card->info.guestlan)
4980 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4981 (!card->options.layer2) ) {
4982 PRINT_WARN("SNMP Query MIBS not supported "
4983 "on %s!\n", QETH_CARD_IFNAME(card));
4986 /* skip 4 bytes (data_len struct member) to get req_len */
4987 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4989 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4991 QETH_DBF_TEXT(trace, 2, "snmpnome");
4994 if (copy_from_user(ureq, udata,
4995 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
4999 qinfo.udata_len = ureq->hdr.data_len;
5000 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL))){
5004 memset(qinfo.udata, 0, qinfo.udata_len);
5005 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
5007 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
5008 QETH_SNMP_SETADP_CMDLENGTH + req_len);
5009 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5010 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
5011 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
5012 qeth_snmp_command_cb, (void *)&qinfo);
5014 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
5015 QETH_CARD_IFNAME(card), rc);
5017 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
5025 qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
5029 qeth_default_setadapterparms_cb(struct qeth_card *card,
5030 struct qeth_reply *reply,
5031 unsigned long data);
5033 qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
5036 (struct qeth_card *, struct qeth_reply *, unsigned long),
5040 qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5042 struct qeth_cmd_buffer *iob;
5047 QETH_DBF_TEXT(trace,3,"arpadent");
5050 * currently GuestLAN only supports the ARP assist function
5051 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
5052 * thus we say EOPNOTSUPP for this ARP function
5054 if (card->info.guestlan)
5056 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5057 PRINT_WARN("ARP processing not supported "
5058 "on %s!\n", QETH_CARD_IFNAME(card));
5062 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5063 IPA_CMD_ASS_ARP_ADD_ENTRY,
5064 sizeof(struct qeth_arp_cache_entry),
5066 rc = qeth_send_setassparms(card, iob,
5067 sizeof(struct qeth_arp_cache_entry),
5068 (unsigned long) entry,
5069 qeth_default_setassparms_cb, NULL);
5072 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5073 PRINT_WARN("Could not add ARP entry for address %s on %s: "
5075 buf, QETH_CARD_IFNAME(card),
5076 qeth_arp_get_error_cause(&rc), tmp, tmp);
5082 qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5084 struct qeth_cmd_buffer *iob;
5085 char buf[16] = {0, };
5089 QETH_DBF_TEXT(trace,3,"arprment");
5092 * currently GuestLAN only supports the ARP assist function
5093 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5094 * thus we say EOPNOTSUPP for this ARP function
5096 if (card->info.guestlan)
5098 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5099 PRINT_WARN("ARP processing not supported "
5100 "on %s!\n", QETH_CARD_IFNAME(card));
5103 memcpy(buf, entry, 12);
5104 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5105 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5108 rc = qeth_send_setassparms(card, iob,
5109 12, (unsigned long)buf,
5110 qeth_default_setassparms_cb, NULL);
5114 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5115 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5117 buf, QETH_CARD_IFNAME(card),
5118 qeth_arp_get_error_cause(&rc), tmp, tmp);
5124 qeth_arp_flush_cache(struct qeth_card *card)
5129 QETH_DBF_TEXT(trace,3,"arpflush");
5132 * currently GuestLAN only supports the ARP assist function
5133 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5134 * thus we say EOPNOTSUPP for this ARP function
5136 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5138 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5139 PRINT_WARN("ARP processing not supported "
5140 "on %s!\n", QETH_CARD_IFNAME(card));
5143 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5144 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5147 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5148 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5155 qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5157 struct qeth_card *card = (struct qeth_card *)dev->priv;
5158 struct qeth_arp_cache_entry arp_entry;
5159 struct mii_ioctl_data *mii_data;
5165 if ((card->state != CARD_STATE_UP) &&
5166 (card->state != CARD_STATE_SOFTSETUP))
5169 if (card->info.type == QETH_CARD_TYPE_OSN)
5173 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5174 if ( !capable(CAP_NET_ADMIN) ||
5175 (card->options.layer2) ) {
5179 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5181 case SIOC_QETH_ARP_QUERY_INFO:
5182 if ( !capable(CAP_NET_ADMIN) ||
5183 (card->options.layer2) ) {
5187 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5189 case SIOC_QETH_ARP_ADD_ENTRY:
5190 if ( !capable(CAP_NET_ADMIN) ||
5191 (card->options.layer2) ) {
5195 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5196 sizeof(struct qeth_arp_cache_entry)))
5199 rc = qeth_arp_add_entry(card, &arp_entry);
5201 case SIOC_QETH_ARP_REMOVE_ENTRY:
5202 if ( !capable(CAP_NET_ADMIN) ||
5203 (card->options.layer2) ) {
5207 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5208 sizeof(struct qeth_arp_cache_entry)))
5211 rc = qeth_arp_remove_entry(card, &arp_entry);
5213 case SIOC_QETH_ARP_FLUSH_CACHE:
5214 if ( !capable(CAP_NET_ADMIN) ||
5215 (card->options.layer2) ) {
5219 rc = qeth_arp_flush_cache(card);
5221 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5222 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5224 case SIOC_QETH_GET_CARD_TYPE:
5225 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5226 !card->info.guestlan)
5231 mii_data = if_mii(rq);
5232 mii_data->phy_id = 0;
5235 mii_data = if_mii(rq);
5236 if (mii_data->phy_id != 0)
5239 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5245 /* TODO: remove return if qeth_mdio_write does something */
5246 if (!capable(CAP_NET_ADMIN)){
5250 mii_data = if_mii(rq);
5251 if (mii_data->phy_id != 0)
5254 qeth_mdio_write(dev, mii_data->phy_id, mii_data->reg_num,
5261 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5265 static struct net_device_stats *
5266 qeth_get_stats(struct net_device *dev)
5268 struct qeth_card *card;
5270 card = (struct qeth_card *) (dev->priv);
5272 QETH_DBF_TEXT(trace,5,"getstat");
5274 return &card->stats;
5278 qeth_change_mtu(struct net_device *dev, int new_mtu)
5280 struct qeth_card *card;
5283 card = (struct qeth_card *) (dev->priv);
5285 QETH_DBF_TEXT(trace,4,"chgmtu");
5286 sprintf(dbf_text, "%8x", new_mtu);
5287 QETH_DBF_TEXT(trace,4,dbf_text);
5291 if (new_mtu > 65535)
5293 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5294 (!qeth_mtu_is_valid(card, new_mtu)))
5300 #ifdef CONFIG_QETH_VLAN
5302 qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5304 struct qeth_card *card;
5305 unsigned long flags;
5307 QETH_DBF_TEXT(trace,4,"vlanreg");
5309 card = (struct qeth_card *) dev->priv;
5310 spin_lock_irqsave(&card->vlanlock, flags);
5311 card->vlangrp = grp;
5312 spin_unlock_irqrestore(&card->vlanlock, flags);
5316 qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5320 struct sk_buff *skb;
5321 struct sk_buff_head tmp_list;
5323 skb_queue_head_init(&tmp_list);
5324 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5325 while ((skb = skb_dequeue(&buf->skb_list))){
5326 if (vlan_tx_tag_present(skb) &&
5327 (vlan_tx_tag_get(skb) == vid)) {
5328 atomic_dec(&skb->users);
5331 skb_queue_tail(&tmp_list, skb);
5334 while ((skb = skb_dequeue(&tmp_list)))
5335 skb_queue_tail(&buf->skb_list, skb);
5339 qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5343 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5344 for (i = 0; i < card->qdio.no_out_queues; ++i){
5345 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5346 qeth_free_vlan_buffer(card, &card->qdio.
5347 out_qs[i]->bufs[j], vid);
5352 qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5354 struct in_device *in_dev;
5355 struct in_ifaddr *ifa;
5356 struct qeth_ipaddr *addr;
5358 QETH_DBF_TEXT(trace, 4, "frvaddr4");
5361 in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]);
5364 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5365 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5367 addr->u.a4.addr = ifa->ifa_address;
5368 addr->u.a4.mask = ifa->ifa_mask;
5369 addr->type = QETH_IP_TYPE_NORMAL;
5370 if (!qeth_delete_ip(card, addr))
5379 qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5381 #ifdef CONFIG_QETH_IPV6
5382 struct inet6_dev *in6_dev;
5383 struct inet6_ifaddr *ifa;
5384 struct qeth_ipaddr *addr;
5386 QETH_DBF_TEXT(trace, 4, "frvaddr6");
5388 in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]);
5391 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5392 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5394 memcpy(&addr->u.a6.addr, &ifa->addr,
5395 sizeof(struct in6_addr));
5396 addr->u.a6.pfxlen = ifa->prefix_len;
5397 addr->type = QETH_IP_TYPE_NORMAL;
5398 if (!qeth_delete_ip(card, addr))
5402 in6_dev_put(in6_dev);
5403 #endif /* CONFIG_QETH_IPV6 */
5407 qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5409 if (card->options.layer2 || !card->vlangrp)
5411 qeth_free_vlan_addresses4(card, vid);
5412 qeth_free_vlan_addresses6(card, vid);
5416 qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5417 struct qeth_reply *reply,
5420 struct qeth_ipa_cmd *cmd;
5422 QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5423 cmd = (struct qeth_ipa_cmd *) data;
5424 if (cmd->hdr.return_code) {
5425 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5426 "Continuing\n",cmd->data.setdelvlan.vlan_id,
5427 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5428 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5429 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5430 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5436 qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5437 enum qeth_ipa_cmds ipacmd)
5439 struct qeth_ipa_cmd *cmd;
5440 struct qeth_cmd_buffer *iob;
5442 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5443 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5444 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5445 cmd->data.setdelvlan.vlan_id = i;
5446 return qeth_send_ipa_cmd(card, iob,
5447 qeth_layer2_send_setdelvlan_cb, NULL);
5451 qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5455 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5459 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5460 if (card->vlangrp->vlan_devices[i] == NULL)
5463 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5465 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5469 /*add_vid is layer 2 used only ....*/
5471 qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5473 struct qeth_card *card;
5475 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5477 card = (struct qeth_card *) dev->priv;
5478 if (!card->options.layer2)
5480 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5483 /*... kill_vid used for both modes*/
5485 qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5487 struct qeth_card *card;
5488 unsigned long flags;
5490 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5492 card = (struct qeth_card *) dev->priv;
5493 /* free all skbs for the vlan device */
5494 qeth_free_vlan_skbs(card, vid);
5495 spin_lock_irqsave(&card->vlanlock, flags);
5496 /* unregister IP addresses of vlan device */
5497 qeth_free_vlan_addresses(card, vid);
5499 card->vlangrp->vlan_devices[vid] = NULL;
5500 spin_unlock_irqrestore(&card->vlanlock, flags);
5501 if (card->options.layer2)
5502 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5503 qeth_set_multicast_list(card->dev);
5507 * Examine hardware response to SET_PROMISC_MODE
5510 qeth_setadp_promisc_mode_cb(struct qeth_card *card,
5511 struct qeth_reply *reply,
5514 struct qeth_ipa_cmd *cmd;
5515 struct qeth_ipacmd_setadpparms *setparms;
5517 QETH_DBF_TEXT(trace,4,"prmadpcb");
5519 cmd = (struct qeth_ipa_cmd *) data;
5520 setparms = &(cmd->data.setadapterparms);
5522 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
5523 if (cmd->hdr.return_code) {
5524 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
5525 setparms->data.mode = SET_PROMISC_MODE_OFF;
5527 card->info.promisc_mode = setparms->data.mode;
5531 * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5534 qeth_setadp_promisc_mode(struct qeth_card *card)
5536 enum qeth_ipa_promisc_modes mode;
5537 struct net_device *dev = card->dev;
5538 struct qeth_cmd_buffer *iob;
5539 struct qeth_ipa_cmd *cmd;
5541 QETH_DBF_TEXT(trace, 4, "setprom");
5543 if (((dev->flags & IFF_PROMISC) &&
5544 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5545 (!(dev->flags & IFF_PROMISC) &&
5546 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5548 mode = SET_PROMISC_MODE_OFF;
5549 if (dev->flags & IFF_PROMISC)
5550 mode = SET_PROMISC_MODE_ON;
5551 QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5553 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5554 sizeof(struct qeth_ipacmd_setadpparms));
5555 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5556 cmd->data.setadapterparms.data.mode = mode;
5557 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5561 * set multicast address on card
5564 qeth_set_multicast_list(struct net_device *dev)
5566 struct qeth_card *card = (struct qeth_card *) dev->priv;
5568 if (card->info.type == QETH_CARD_TYPE_OSN)
5571 QETH_DBF_TEXT(trace,3,"setmulti");
5572 qeth_delete_mc_addresses(card);
5573 if (card->options.layer2) {
5574 qeth_layer2_add_multicast(card);
5577 qeth_add_multicast_ipv4(card);
5578 #ifdef CONFIG_QETH_IPV6
5579 qeth_add_multicast_ipv6(card);
5582 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
5583 schedule_work(&card->kernel_thread_starter);
5584 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5586 if (qeth_set_thread_start_bit(card, QETH_SET_PROMISC_MODE_THREAD)==0)
5587 schedule_work(&card->kernel_thread_starter);
5592 qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5598 qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5600 if (dev->type == ARPHRD_IEEE802_TR)
5601 ip_tr_mc_map(ipm, mac);
5603 ip_eth_mc_map(ipm, mac);
5606 static struct qeth_ipaddr *
5607 qeth_get_addr_buffer(enum qeth_prot_versions prot)
5609 struct qeth_ipaddr *addr;
5611 addr = kmalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5613 PRINT_WARN("Not enough memory to add address\n");
5616 memset(addr,0,sizeof(struct qeth_ipaddr));
5617 addr->type = QETH_IP_TYPE_NORMAL;
5623 qeth_osn_assist(struct net_device *dev,
5627 struct qeth_cmd_buffer *iob;
5628 struct qeth_card *card;
5631 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5634 card = (struct qeth_card *)dev->priv;
5637 if ((card->state != CARD_STATE_UP) &&
5638 (card->state != CARD_STATE_SOFTSETUP))
5640 iob = qeth_wait_for_buffer(&card->write);
5641 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5642 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5646 static struct net_device *
5647 qeth_netdev_by_devno(unsigned char *read_dev_no)
5649 struct qeth_card *card;
5650 struct net_device *ndev;
5651 unsigned char *readno;
5652 __u16 temp_dev_no, card_dev_no;
5654 unsigned long flags;
5657 memcpy(&temp_dev_no, read_dev_no, 2);
5658 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5659 list_for_each_entry(card, &qeth_card_list.list, list) {
5660 readno = CARD_RDEV_ID(card);
5661 readno += (strlen(readno) - 4);
5662 card_dev_no = simple_strtoul(readno, &endp, 16);
5663 if (card_dev_no == temp_dev_no) {
5668 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5673 qeth_osn_register(unsigned char *read_dev_no,
5674 struct net_device **dev,
5675 int (*assist_cb)(struct net_device *, void *),
5676 int (*data_cb)(struct sk_buff *))
5678 struct qeth_card * card;
5680 QETH_DBF_TEXT(trace, 2, "osnreg");
5681 *dev = qeth_netdev_by_devno(read_dev_no);
5684 card = (struct qeth_card *)(*dev)->priv;
5687 if ((assist_cb == NULL) || (data_cb == NULL))
5689 card->osn_info.assist_cb = assist_cb;
5690 card->osn_info.data_cb = data_cb;
5695 qeth_osn_deregister(struct net_device * dev)
5697 struct qeth_card *card;
5699 QETH_DBF_TEXT(trace, 2, "osndereg");
5702 card = (struct qeth_card *)dev->priv;
5705 card->osn_info.assist_cb = NULL;
5706 card->osn_info.data_cb = NULL;
5711 qeth_delete_mc_addresses(struct qeth_card *card)
5713 struct qeth_ipaddr *iptodo;
5714 unsigned long flags;
5716 QETH_DBF_TEXT(trace,4,"delmc");
5717 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5719 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5722 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5723 spin_lock_irqsave(&card->ip_lock, flags);
5724 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5726 spin_unlock_irqrestore(&card->ip_lock, flags);
5730 qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5732 struct qeth_ipaddr *ipm;
5733 struct ip_mc_list *im4;
5734 char buf[MAX_ADDR_LEN];
5736 QETH_DBF_TEXT(trace,4,"addmc");
5737 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5738 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5739 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5742 ipm->u.a4.addr = im4->multiaddr;
5743 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5744 ipm->is_multicast = 1;
5745 if (!qeth_add_ip(card,ipm))
5751 qeth_add_vlan_mc(struct qeth_card *card)
5753 #ifdef CONFIG_QETH_VLAN
5754 struct in_device *in_dev;
5755 struct vlan_group *vg;
5758 QETH_DBF_TEXT(trace,4,"addmcvl");
5759 if ( ((card->options.layer2 == 0) &&
5760 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5761 (card->vlangrp == NULL) )
5765 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5766 if (vg->vlan_devices[i] == NULL ||
5767 !(vg->vlan_devices[i]->flags & IFF_UP))
5769 in_dev = in_dev_get(vg->vlan_devices[i]);
5772 read_lock(&in_dev->mc_list_lock);
5773 qeth_add_mc(card,in_dev);
5774 read_unlock(&in_dev->mc_list_lock);
5781 qeth_add_multicast_ipv4(struct qeth_card *card)
5783 struct in_device *in4_dev;
5785 QETH_DBF_TEXT(trace,4,"chkmcv4");
5786 in4_dev = in_dev_get(card->dev);
5787 if (in4_dev == NULL)
5789 read_lock(&in4_dev->mc_list_lock);
5790 qeth_add_mc(card, in4_dev);
5791 qeth_add_vlan_mc(card);
5792 read_unlock(&in4_dev->mc_list_lock);
5793 in_dev_put(in4_dev);
5797 qeth_layer2_add_multicast(struct qeth_card *card)
5799 struct qeth_ipaddr *ipm;
5800 struct dev_mc_list *dm;
5802 QETH_DBF_TEXT(trace,4,"L2addmc");
5803 for (dm = card->dev->mc_list; dm; dm = dm->next) {
5804 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5807 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5808 ipm->is_multicast = 1;
5809 if (!qeth_add_ip(card, ipm))
5814 #ifdef CONFIG_QETH_IPV6
5816 qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5818 struct qeth_ipaddr *ipm;
5819 struct ifmcaddr6 *im6;
5820 char buf[MAX_ADDR_LEN];
5822 QETH_DBF_TEXT(trace,4,"addmc6");
5823 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5824 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5825 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5828 ipm->is_multicast = 1;
5829 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5830 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5831 sizeof(struct in6_addr));
5832 if (!qeth_add_ip(card,ipm))
5838 qeth_add_vlan_mc6(struct qeth_card *card)
5840 #ifdef CONFIG_QETH_VLAN
5841 struct inet6_dev *in_dev;
5842 struct vlan_group *vg;
5845 QETH_DBF_TEXT(trace,4,"admc6vl");
5846 if ( ((card->options.layer2 == 0) &&
5847 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5848 (card->vlangrp == NULL))
5852 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5853 if (vg->vlan_devices[i] == NULL ||
5854 !(vg->vlan_devices[i]->flags & IFF_UP))
5856 in_dev = in6_dev_get(vg->vlan_devices[i]);
5859 read_lock(&in_dev->lock);
5860 qeth_add_mc6(card,in_dev);
5861 read_unlock(&in_dev->lock);
5862 in6_dev_put(in_dev);
5864 #endif /* CONFIG_QETH_VLAN */
5868 qeth_add_multicast_ipv6(struct qeth_card *card)
5870 struct inet6_dev *in6_dev;
5872 QETH_DBF_TEXT(trace,4,"chkmcv6");
5873 if ((card->options.layer2 == 0) &&
5874 (!qeth_is_supported(card, IPA_IPV6)) )
5877 in6_dev = in6_dev_get(card->dev);
5878 if (in6_dev == NULL)
5880 read_lock(&in6_dev->lock);
5881 qeth_add_mc6(card, in6_dev);
5882 qeth_add_vlan_mc6(card);
5883 read_unlock(&in6_dev->lock);
5884 in6_dev_put(in6_dev);
5886 #endif /* CONFIG_QETH_IPV6 */
5889 qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5890 enum qeth_ipa_cmds ipacmd,
5891 int (*reply_cb) (struct qeth_card *,
5895 struct qeth_ipa_cmd *cmd;
5896 struct qeth_cmd_buffer *iob;
5898 QETH_DBF_TEXT(trace, 2, "L2sdmac");
5899 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5900 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5901 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5902 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5903 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5907 qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5908 struct qeth_reply *reply,
5911 struct qeth_ipa_cmd *cmd;
5914 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5915 cmd = (struct qeth_ipa_cmd *) data;
5916 mac = &cmd->data.setdelmac.mac[0];
5917 /* MAC already registered, needed in couple/uncouple case */
5918 if (cmd->hdr.return_code == 0x2005) {
5919 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5920 "already existing on %s \n",
5921 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5922 QETH_CARD_IFNAME(card));
5923 cmd->hdr.return_code = 0;
5925 if (cmd->hdr.return_code)
5926 PRINT_ERR("Could not set group MAC " \
5927 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5928 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5929 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5934 qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5936 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5937 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5938 qeth_layer2_send_setgroupmac_cb);
5942 qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5943 struct qeth_reply *reply,
5946 struct qeth_ipa_cmd *cmd;
5949 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5950 cmd = (struct qeth_ipa_cmd *) data;
5951 mac = &cmd->data.setdelmac.mac[0];
5952 if (cmd->hdr.return_code)
5953 PRINT_ERR("Could not delete group MAC " \
5954 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5955 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5956 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5961 qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5963 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5964 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5965 qeth_layer2_send_delgroupmac_cb);
5969 qeth_layer2_send_setmac_cb(struct qeth_card *card,
5970 struct qeth_reply *reply,
5973 struct qeth_ipa_cmd *cmd;
5975 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5976 cmd = (struct qeth_ipa_cmd *) data;
5977 if (cmd->hdr.return_code) {
5978 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5979 PRINT_WARN("Error in registering MAC address on " \
5980 "device %s: x%x\n", CARD_BUS_ID(card),
5981 cmd->hdr.return_code);
5982 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
5983 cmd->hdr.return_code = -EIO;
5985 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
5986 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5988 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5989 "successfully registered on device %s\n",
5990 card->dev->dev_addr[0], card->dev->dev_addr[1],
5991 card->dev->dev_addr[2], card->dev->dev_addr[3],
5992 card->dev->dev_addr[4], card->dev->dev_addr[5],
5999 qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
6001 QETH_DBF_TEXT(trace, 2, "L2Setmac");
6002 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
6003 qeth_layer2_send_setmac_cb);
6007 qeth_layer2_send_delmac_cb(struct qeth_card *card,
6008 struct qeth_reply *reply,
6011 struct qeth_ipa_cmd *cmd;
6013 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
6014 cmd = (struct qeth_ipa_cmd *) data;
6015 if (cmd->hdr.return_code) {
6016 PRINT_WARN("Error in deregistering MAC address on " \
6017 "device %s: x%x\n", CARD_BUS_ID(card),
6018 cmd->hdr.return_code);
6019 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
6020 cmd->hdr.return_code = -EIO;
6023 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
6028 qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
6030 QETH_DBF_TEXT(trace, 2, "L2Delmac");
6031 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
6033 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
6034 qeth_layer2_send_delmac_cb);
6038 qeth_layer2_set_mac_address(struct net_device *dev, void *p)
6040 struct sockaddr *addr = p;
6041 struct qeth_card *card;
6044 QETH_DBF_TEXT(trace, 3, "setmac");
6046 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
6047 QETH_DBF_TEXT(trace, 3, "setmcINV");
6050 card = (struct qeth_card *) dev->priv;
6052 if (!card->options.layer2) {
6053 PRINT_WARN("Setting MAC address on %s is not supported "
6054 "in Layer 3 mode.\n", dev->name);
6055 QETH_DBF_TEXT(trace, 3, "setmcLY3");
6058 if (card->info.type == QETH_CARD_TYPE_OSN) {
6059 PRINT_WARN("Setting MAC address on %s is not supported.\n",
6061 QETH_DBF_TEXT(trace, 3, "setmcOSN");
6064 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
6065 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
6066 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
6068 rc = qeth_layer2_send_setmac(card, addr->sa_data);
6073 qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
6074 __u8 command, enum qeth_prot_versions prot)
6076 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
6077 cmd->hdr.command = command;
6078 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
6079 cmd->hdr.seqno = card->seqno.ipa;
6080 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
6081 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
6082 if (card->options.layer2)
6083 cmd->hdr.prim_version_no = 2;
6085 cmd->hdr.prim_version_no = 1;
6086 cmd->hdr.param_count = 1;
6087 cmd->hdr.prot_version = prot;
6088 cmd->hdr.ipa_supported = 0;
6089 cmd->hdr.ipa_enabled = 0;
6092 static struct qeth_cmd_buffer *
6093 qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6094 enum qeth_prot_versions prot)
6096 struct qeth_cmd_buffer *iob;
6097 struct qeth_ipa_cmd *cmd;
6099 iob = qeth_wait_for_buffer(&card->write);
6100 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6101 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6107 qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6110 struct qeth_cmd_buffer *iob;
6111 struct qeth_ipa_cmd *cmd;
6113 QETH_DBF_TEXT(trace,4,"setdelmc");
6115 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6116 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6117 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6118 if (addr->proto == QETH_PROT_IPV6)
6119 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6120 sizeof(struct in6_addr));
6122 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6124 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6129 qeth_fill_netmask(u8 *netmask, unsigned int len)
6132 for (i=0;i<16;i++) {
6137 netmask[i] = (u8)(0xFF00>>j);
6144 qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6145 int ipacmd, unsigned int flags)
6148 struct qeth_cmd_buffer *iob;
6149 struct qeth_ipa_cmd *cmd;
6152 QETH_DBF_TEXT(trace,4,"setdelip");
6153 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6155 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6156 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6157 if (addr->proto == QETH_PROT_IPV6) {
6158 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6159 sizeof(struct in6_addr));
6160 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6161 memcpy(cmd->data.setdelip6.mask, netmask,
6162 sizeof(struct in6_addr));
6163 cmd->data.setdelip6.flags = flags;
6165 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6166 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6167 cmd->data.setdelip4.flags = flags;
6170 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6176 qeth_layer2_register_addr_entry(struct qeth_card *card,
6177 struct qeth_ipaddr *addr)
6179 if (!addr->is_multicast)
6181 QETH_DBF_TEXT(trace, 2, "setgmac");
6182 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6183 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6187 qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6188 struct qeth_ipaddr *addr)
6190 if (!addr->is_multicast)
6192 QETH_DBF_TEXT(trace, 2, "delgmac");
6193 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6194 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6198 qeth_layer3_register_addr_entry(struct qeth_card *card,
6199 struct qeth_ipaddr *addr)
6205 if (addr->proto == QETH_PROT_IPV4) {
6206 QETH_DBF_TEXT(trace, 2,"setaddr4");
6207 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6208 } else if (addr->proto == QETH_PROT_IPV6) {
6209 QETH_DBF_TEXT(trace, 2, "setaddr6");
6210 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6211 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6213 QETH_DBF_TEXT(trace, 2, "setaddr?");
6214 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6217 if (addr->is_multicast)
6218 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6220 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6223 QETH_DBF_TEXT(trace, 2, "failed");
6224 } while ((--cnt > 0) && rc);
6226 QETH_DBF_TEXT(trace, 2, "FAILED");
6227 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6228 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6235 qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6236 struct qeth_ipaddr *addr)
6241 if (addr->proto == QETH_PROT_IPV4) {
6242 QETH_DBF_TEXT(trace, 2,"deladdr4");
6243 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6244 } else if (addr->proto == QETH_PROT_IPV6) {
6245 QETH_DBF_TEXT(trace, 2, "deladdr6");
6246 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6247 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6249 QETH_DBF_TEXT(trace, 2, "deladdr?");
6250 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6252 if (addr->is_multicast)
6253 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6255 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6258 QETH_DBF_TEXT(trace, 2, "failed");
6259 /* TODO: re-activate this warning as soon as we have a
6261 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6262 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6270 qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6272 if (card->options.layer2)
6273 return qeth_layer2_register_addr_entry(card, addr);
6275 return qeth_layer3_register_addr_entry(card, addr);
6279 qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6281 if (card->options.layer2)
6282 return qeth_layer2_deregister_addr_entry(card, addr);
6284 return qeth_layer3_deregister_addr_entry(card, addr);
6288 qeth_ethtool_get_tx_csum(struct net_device *dev)
6290 /* We may need to say that we support tx csum offload if
6291 * we do EDDP or TSO. There are discussions going on to
6292 * enforce rules in the stack and in ethtool that make
6293 * SG and TSO depend on HW_CSUM. At the moment there are
6295 * If we say yes here, we have to checksum outbound packets
6301 qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6307 qeth_ethtool_get_rx_csum(struct net_device *dev)
6309 struct qeth_card *card = (struct qeth_card *)dev->priv;
6311 return (card->options.checksum_type == HW_CHECKSUMMING);
6315 qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6317 struct qeth_card *card = (struct qeth_card *)dev->priv;
6319 if ((card->state != CARD_STATE_DOWN) &&
6320 (card->state != CARD_STATE_RECOVER))
6323 card->options.checksum_type = HW_CHECKSUMMING;
6325 card->options.checksum_type = SW_CHECKSUMMING;
6330 qeth_ethtool_get_sg(struct net_device *dev)
6332 struct qeth_card *card = (struct qeth_card *)dev->priv;
6334 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6335 (dev->features & NETIF_F_SG));
6339 qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6341 struct qeth_card *card = (struct qeth_card *)dev->priv;
6344 if (card->options.large_send != QETH_LARGE_SEND_NO)
6345 dev->features |= NETIF_F_SG;
6347 dev->features &= ~NETIF_F_SG;
6351 dev->features &= ~NETIF_F_SG;
6356 qeth_ethtool_get_tso(struct net_device *dev)
6358 struct qeth_card *card = (struct qeth_card *)dev->priv;
6360 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6361 (dev->features & NETIF_F_TSO));
6365 qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6367 struct qeth_card *card = (struct qeth_card *)dev->priv;
6370 if (card->options.large_send != QETH_LARGE_SEND_NO)
6371 dev->features |= NETIF_F_TSO;
6373 dev->features &= ~NETIF_F_TSO;
6377 dev->features &= ~NETIF_F_TSO;
6381 static struct ethtool_ops qeth_ethtool_ops = {
6382 .get_tx_csum = qeth_ethtool_get_tx_csum,
6383 .set_tx_csum = qeth_ethtool_set_tx_csum,
6384 .get_rx_csum = qeth_ethtool_get_rx_csum,
6385 .set_rx_csum = qeth_ethtool_set_rx_csum,
6386 .get_sg = qeth_ethtool_get_sg,
6387 .set_sg = qeth_ethtool_set_sg,
6388 .get_tso = qeth_ethtool_get_tso,
6389 .set_tso = qeth_ethtool_set_tso,
6393 qeth_netdev_init(struct net_device *dev)
6395 struct qeth_card *card;
6397 card = (struct qeth_card *) dev->priv;
6399 QETH_DBF_TEXT(trace,3,"initdev");
6401 dev->tx_timeout = &qeth_tx_timeout;
6402 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6403 dev->open = qeth_open;
6404 dev->stop = qeth_stop;
6405 dev->hard_start_xmit = qeth_hard_start_xmit;
6406 dev->do_ioctl = qeth_do_ioctl;
6407 dev->get_stats = qeth_get_stats;
6408 dev->change_mtu = qeth_change_mtu;
6409 dev->neigh_setup = qeth_neigh_setup;
6410 dev->set_multicast_list = qeth_set_multicast_list;
6411 #ifdef CONFIG_QETH_VLAN
6412 dev->vlan_rx_register = qeth_vlan_rx_register;
6413 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6414 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6416 dev->hard_header = card->orig_hard_header;
6417 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6418 dev->rebuild_header = NULL;
6419 dev->hard_header = NULL;
6420 if (card->options.fake_ll)
6421 dev->hard_header = qeth_fake_header;
6422 dev->header_cache_update = NULL;
6423 dev->hard_header_cache = NULL;
6425 #ifdef CONFIG_QETH_IPV6
6426 /*IPv6 address autoconfiguration stuff*/
6427 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6428 card->dev->dev_id = card->info.unique_id & 0xffff;
6430 dev->hard_header_parse = NULL;
6431 dev->set_mac_address = qeth_layer2_set_mac_address;
6432 dev->flags |= qeth_get_netdev_flags(card);
6433 if ((card->options.fake_broadcast) ||
6434 (card->info.broadcast_capable))
6435 dev->flags |= IFF_BROADCAST;
6436 dev->hard_header_len =
6437 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6438 dev->addr_len = OSA_ADDR_LEN;
6439 dev->mtu = card->info.initial_mtu;
6440 if (card->info.type != QETH_CARD_TYPE_OSN)
6441 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6442 SET_MODULE_OWNER(dev);
6447 qeth_init_func_level(struct qeth_card *card)
6449 if (card->ipato.enabled) {
6450 if (card->info.type == QETH_CARD_TYPE_IQD)
6451 card->info.func_level =
6452 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6454 card->info.func_level =
6455 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6457 if (card->info.type == QETH_CARD_TYPE_IQD)
6458 /*FIXME:why do we have same values for dis and ena for osae??? */
6459 card->info.func_level =
6460 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6462 card->info.func_level =
6463 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6468 * hardsetup card, initialize MPC and QDIO stuff
6471 qeth_hardsetup_card(struct qeth_card *card)
6476 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6480 PRINT_WARN("Retrying to do IDX activates.\n");
6481 ccw_device_set_offline(CARD_DDEV(card));
6482 ccw_device_set_offline(CARD_WDEV(card));
6483 ccw_device_set_offline(CARD_RDEV(card));
6484 ccw_device_set_online(CARD_RDEV(card));
6485 ccw_device_set_online(CARD_WDEV(card));
6486 ccw_device_set_online(CARD_DDEV(card));
6488 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
6489 if (rc == -ERESTARTSYS) {
6490 QETH_DBF_TEXT(setup, 2, "break1");
6493 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6499 if ((rc = qeth_get_unitaddr(card))){
6500 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6503 qeth_init_tokens(card);
6504 qeth_init_func_level(card);
6505 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6506 if (rc == -ERESTARTSYS) {
6507 QETH_DBF_TEXT(setup, 2, "break2");
6510 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6516 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6517 if (rc == -ERESTARTSYS) {
6518 QETH_DBF_TEXT(setup, 2, "break3");
6521 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6527 if ((rc = qeth_mpc_initialize(card))){
6528 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6531 /*network device will be recovered*/
6533 card->dev->hard_header = card->orig_hard_header;
6536 /* at first set_online allocate netdev */
6537 card->dev = qeth_get_netdevice(card->info.type,
6538 card->info.link_type);
6540 qeth_qdio_clear_card(card, card->info.type !=
6541 QETH_CARD_TYPE_IQD);
6543 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6546 card->dev->priv = card;
6547 card->orig_hard_header = card->dev->hard_header;
6548 card->dev->type = qeth_get_arphdr_type(card->info.type,
6549 card->info.link_type);
6550 card->dev->init = qeth_netdev_init;
6553 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6558 qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6561 struct qeth_ipa_cmd *cmd;
6563 QETH_DBF_TEXT(trace,4,"defadpcb");
6565 cmd = (struct qeth_ipa_cmd *) data;
6566 if (cmd->hdr.return_code == 0){
6567 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6568 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6569 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6570 #ifdef CONFIG_QETH_IPV6
6571 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6572 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6575 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6576 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6577 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6578 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6584 qeth_default_setadapterparms_cb(struct qeth_card *card,
6585 struct qeth_reply *reply,
6588 struct qeth_ipa_cmd *cmd;
6590 QETH_DBF_TEXT(trace,4,"defadpcb");
6592 cmd = (struct qeth_ipa_cmd *) data;
6593 if (cmd->hdr.return_code == 0)
6594 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6601 qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6604 struct qeth_ipa_cmd *cmd;
6606 QETH_DBF_TEXT(trace,3,"quyadpcb");
6608 cmd = (struct qeth_ipa_cmd *) data;
6609 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6610 card->info.link_type =
6611 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6612 card->options.adp.supported_funcs =
6613 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6614 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6618 qeth_query_setadapterparms(struct qeth_card *card)
6621 struct qeth_cmd_buffer *iob;
6623 QETH_DBF_TEXT(trace,3,"queryadp");
6624 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6625 sizeof(struct qeth_ipacmd_setadpparms));
6626 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6631 qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6632 struct qeth_reply *reply,
6635 struct qeth_ipa_cmd *cmd;
6637 QETH_DBF_TEXT(trace,4,"chgmaccb");
6639 cmd = (struct qeth_ipa_cmd *) data;
6640 if (!card->options.layer2 || card->info.guestlan ||
6641 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
6642 memcpy(card->dev->dev_addr,
6643 &cmd->data.setadapterparms.data.change_addr.addr,
6645 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6647 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6652 qeth_setadpparms_change_macaddr(struct qeth_card *card)
6655 struct qeth_cmd_buffer *iob;
6656 struct qeth_ipa_cmd *cmd;
6658 QETH_DBF_TEXT(trace,4,"chgmac");
6660 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6661 sizeof(struct qeth_ipacmd_setadpparms));
6662 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6663 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6664 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6665 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6666 card->dev->dev_addr, OSA_ADDR_LEN);
6667 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6673 qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6676 struct qeth_cmd_buffer *iob;
6677 struct qeth_ipa_cmd *cmd;
6679 QETH_DBF_TEXT(trace,4,"adpmode");
6681 iob = qeth_get_adapter_cmd(card, command,
6682 sizeof(struct qeth_ipacmd_setadpparms));
6683 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6684 cmd->data.setadapterparms.data.mode = mode;
6685 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6691 qeth_setadapter_hstr(struct qeth_card *card)
6695 QETH_DBF_TEXT(trace,4,"adphstr");
6697 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6698 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6699 card->options.broadcast_mode);
6701 PRINT_WARN("couldn't set broadcast mode on "
6703 CARD_BUS_ID(card), rc);
6704 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6705 card->options.macaddr_mode);
6707 PRINT_WARN("couldn't set macaddr mode on "
6708 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6711 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6712 PRINT_WARN("set adapter parameters not available "
6713 "to set broadcast mode, using ALLRINGS "
6714 "on device %s:\n", CARD_BUS_ID(card));
6715 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6716 PRINT_WARN("set adapter parameters not available "
6717 "to set macaddr mode, using NONCANONICAL "
6718 "on device %s:\n", CARD_BUS_ID(card));
6723 qeth_setadapter_parms(struct qeth_card *card)
6727 QETH_DBF_TEXT(setup, 2, "setadprm");
6729 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6730 PRINT_WARN("set adapter parameters not supported "
6733 QETH_DBF_TEXT(setup, 2, " notsupp");
6736 rc = qeth_query_setadapterparms(card);
6738 PRINT_WARN("couldn't set adapter parameters on device %s: "
6739 "x%x\n", CARD_BUS_ID(card), rc);
6742 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6743 rc = qeth_setadpparms_change_macaddr(card);
6745 PRINT_WARN("couldn't get MAC address on "
6747 CARD_BUS_ID(card), rc);
6750 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6751 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6752 rc = qeth_setadapter_hstr(card);
6758 qeth_layer2_initialize(struct qeth_card *card)
6763 QETH_DBF_TEXT(setup, 2, "doL2init");
6764 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6766 rc = qeth_query_setadapterparms(card);
6768 PRINT_WARN("could not query adapter parameters on device %s: "
6769 "x%x\n", CARD_BUS_ID(card), rc);
6772 rc = qeth_setadpparms_change_macaddr(card);
6774 PRINT_WARN("couldn't get MAC address on "
6776 CARD_BUS_ID(card), rc);
6777 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6780 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6782 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6784 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6790 qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6791 enum qeth_prot_versions prot)
6794 struct qeth_cmd_buffer *iob;
6796 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6797 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6803 qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6807 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6809 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6814 qeth_send_stoplan(struct qeth_card *card)
6819 * TODO: according to the IPA format document page 14,
6820 * TCP/IP (we!) never issue a STOPLAN
6823 QETH_DBF_TEXT(trace, 2, "stoplan");
6825 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6830 qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6833 struct qeth_ipa_cmd *cmd;
6835 QETH_DBF_TEXT(setup, 2, "qipasscb");
6837 cmd = (struct qeth_ipa_cmd *) data;
6838 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6839 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6840 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6841 /* Disable IPV6 support hard coded for Hipersockets */
6842 if(card->info.type == QETH_CARD_TYPE_IQD)
6843 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
6845 #ifdef CONFIG_QETH_IPV6
6846 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6847 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6850 QETH_DBF_TEXT(setup, 2, "suppenbl");
6851 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6852 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6857 qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6860 struct qeth_cmd_buffer *iob;
6862 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6863 if (card->options.layer2) {
6864 QETH_DBF_TEXT(setup, 2, "noprmly2");
6868 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6869 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6873 static struct qeth_cmd_buffer *
6874 qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6875 __u16 cmd_code, __u16 len,
6876 enum qeth_prot_versions prot)
6878 struct qeth_cmd_buffer *iob;
6879 struct qeth_ipa_cmd *cmd;
6881 QETH_DBF_TEXT(trace,4,"getasscm");
6882 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6884 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6885 cmd->data.setassparms.hdr.assist_no = ipa_func;
6886 cmd->data.setassparms.hdr.length = 8 + len;
6887 cmd->data.setassparms.hdr.command_code = cmd_code;
6888 cmd->data.setassparms.hdr.return_code = 0;
6889 cmd->data.setassparms.hdr.seq_no = 0;
6895 qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6896 __u16 len, long data,
6898 (struct qeth_card *,struct qeth_reply *,unsigned long),
6902 struct qeth_ipa_cmd *cmd;
6904 QETH_DBF_TEXT(trace,4,"sendassp");
6906 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6907 if (len <= sizeof(__u32))
6908 cmd->data.setassparms.data.flags_32bit = (__u32) data;
6909 else if (len > sizeof(__u32))
6910 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6912 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6916 #ifdef CONFIG_QETH_IPV6
6918 qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6919 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6923 struct qeth_cmd_buffer *iob;
6925 QETH_DBF_TEXT(trace,4,"simassp6");
6926 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6928 rc = qeth_send_setassparms(card, iob, 0, 0,
6929 qeth_default_setassparms_cb, NULL);
6935 qeth_send_simple_setassparms(struct qeth_card *card,
6936 enum qeth_ipa_funcs ipa_func,
6937 __u16 cmd_code, long data)
6941 struct qeth_cmd_buffer *iob;
6943 QETH_DBF_TEXT(trace,4,"simassp4");
6945 length = sizeof(__u32);
6946 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6947 length, QETH_PROT_IPV4);
6948 rc = qeth_send_setassparms(card, iob, length, data,
6949 qeth_default_setassparms_cb, NULL);
6954 qeth_start_ipa_arp_processing(struct qeth_card *card)
6958 QETH_DBF_TEXT(trace,3,"ipaarp");
6960 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6961 PRINT_WARN("ARP processing not supported "
6962 "on %s!\n", QETH_CARD_IFNAME(card));
6965 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6966 IPA_CMD_ASS_START, 0);
6968 PRINT_WARN("Could not start ARP processing "
6969 "assist on %s: 0x%x\n",
6970 QETH_CARD_IFNAME(card), rc);
6976 qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6980 QETH_DBF_TEXT(trace,3,"ipaipfrg");
6982 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
6983 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
6984 QETH_CARD_IFNAME(card));
6988 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
6989 IPA_CMD_ASS_START, 0);
6991 PRINT_WARN("Could not start Hardware IP fragmentation "
6992 "assist on %s: 0x%x\n",
6993 QETH_CARD_IFNAME(card), rc);
6995 PRINT_INFO("Hardware IP fragmentation enabled \n");
7000 qeth_start_ipa_source_mac(struct qeth_card *card)
7004 QETH_DBF_TEXT(trace,3,"stsrcmac");
7006 if (!card->options.fake_ll)
7009 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
7010 PRINT_INFO("Inbound source address not "
7011 "supported on %s\n", QETH_CARD_IFNAME(card));
7015 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
7016 IPA_CMD_ASS_START, 0);
7018 PRINT_WARN("Could not start inbound source "
7019 "assist on %s: 0x%x\n",
7020 QETH_CARD_IFNAME(card), rc);
7025 qeth_start_ipa_vlan(struct qeth_card *card)
7029 QETH_DBF_TEXT(trace,3,"strtvlan");
7031 #ifdef CONFIG_QETH_VLAN
7032 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
7033 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
7037 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
7038 IPA_CMD_ASS_START,0);
7040 PRINT_WARN("Could not start vlan "
7041 "assist on %s: 0x%x\n",
7042 QETH_CARD_IFNAME(card), rc);
7044 PRINT_INFO("VLAN enabled \n");
7045 card->dev->features |=
7046 NETIF_F_HW_VLAN_FILTER |
7047 NETIF_F_HW_VLAN_TX |
7050 #endif /* QETH_VLAN */
7055 qeth_start_ipa_multicast(struct qeth_card *card)
7059 QETH_DBF_TEXT(trace,3,"stmcast");
7061 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7062 PRINT_WARN("Multicast not supported on %s\n",
7063 QETH_CARD_IFNAME(card));
7067 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7068 IPA_CMD_ASS_START,0);
7070 PRINT_WARN("Could not start multicast "
7071 "assist on %s: rc=%i\n",
7072 QETH_CARD_IFNAME(card), rc);
7074 PRINT_INFO("Multicast enabled\n");
7075 card->dev->flags |= IFF_MULTICAST;
7080 #ifdef CONFIG_QETH_IPV6
7082 qeth_softsetup_ipv6(struct qeth_card *card)
7086 QETH_DBF_TEXT(trace,3,"softipv6");
7088 netif_stop_queue(card->dev);
7089 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7091 PRINT_ERR("IPv6 startlan failed on %s\n",
7092 QETH_CARD_IFNAME(card));
7095 netif_wake_queue(card->dev);
7096 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7098 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7099 QETH_CARD_IFNAME(card));
7102 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7103 IPA_CMD_ASS_START, 3);
7105 PRINT_WARN("IPv6 start assist (version 4) failed "
7107 QETH_CARD_IFNAME(card), rc);
7110 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7113 PRINT_WARN("IPV6 start assist (version 6) failed "
7115 QETH_CARD_IFNAME(card), rc);
7118 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7121 PRINT_WARN("Could not enable passthrough "
7123 QETH_CARD_IFNAME(card), rc);
7126 PRINT_INFO("IPV6 enabled \n");
7133 qeth_start_ipa_ipv6(struct qeth_card *card)
7136 #ifdef CONFIG_QETH_IPV6
7137 QETH_DBF_TEXT(trace,3,"strtipv6");
7139 if (!qeth_is_supported(card, IPA_IPV6)) {
7140 PRINT_WARN("IPv6 not supported on %s\n",
7141 QETH_CARD_IFNAME(card));
7144 rc = qeth_softsetup_ipv6(card);
7150 qeth_start_ipa_broadcast(struct qeth_card *card)
7154 QETH_DBF_TEXT(trace,3,"stbrdcst");
7155 card->info.broadcast_capable = 0;
7156 if (!qeth_is_supported(card, IPA_FILTERING)) {
7157 PRINT_WARN("Broadcast not supported on %s\n",
7158 QETH_CARD_IFNAME(card));
7162 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7163 IPA_CMD_ASS_START, 0);
7165 PRINT_WARN("Could not enable broadcasting filtering "
7167 QETH_CARD_IFNAME(card), rc);
7171 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7172 IPA_CMD_ASS_CONFIGURE, 1);
7174 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7175 QETH_CARD_IFNAME(card), rc);
7178 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7179 PRINT_INFO("Broadcast enabled \n");
7180 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7181 IPA_CMD_ASS_ENABLE, 1);
7183 PRINT_WARN("Could not set up broadcast echo filtering on "
7184 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7187 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7189 if (card->info.broadcast_capable)
7190 card->dev->flags |= IFF_BROADCAST;
7192 card->dev->flags &= ~IFF_BROADCAST;
7197 qeth_send_checksum_command(struct qeth_card *card)
7201 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7202 IPA_CMD_ASS_START, 0);
7204 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7205 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7206 QETH_CARD_IFNAME(card), rc);
7209 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7211 card->info.csum_mask);
7213 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7214 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7215 QETH_CARD_IFNAME(card), rc);
7222 qeth_start_ipa_checksum(struct qeth_card *card)
7226 QETH_DBF_TEXT(trace,3,"strtcsum");
7228 if (card->options.checksum_type == NO_CHECKSUMMING) {
7229 PRINT_WARN("Using no checksumming on %s.\n",
7230 QETH_CARD_IFNAME(card));
7233 if (card->options.checksum_type == SW_CHECKSUMMING) {
7234 PRINT_WARN("Using SW checksumming on %s.\n",
7235 QETH_CARD_IFNAME(card));
7238 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7239 PRINT_WARN("Inbound HW Checksumming not "
7240 "supported on %s,\ncontinuing "
7241 "using Inbound SW Checksumming\n",
7242 QETH_CARD_IFNAME(card));
7243 card->options.checksum_type = SW_CHECKSUMMING;
7246 rc = qeth_send_checksum_command(card);
7248 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7254 qeth_start_ipa_tso(struct qeth_card *card)
7258 QETH_DBF_TEXT(trace,3,"sttso");
7260 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7261 PRINT_WARN("Outbound TSO not supported on %s\n",
7262 QETH_CARD_IFNAME(card));
7265 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7266 IPA_CMD_ASS_START,0);
7268 PRINT_WARN("Could not start outbound TSO "
7269 "assist on %s: rc=%i\n",
7270 QETH_CARD_IFNAME(card), rc);
7272 PRINT_INFO("Outbound TSO enabled\n");
7274 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7275 card->options.large_send = QETH_LARGE_SEND_NO;
7276 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
7282 qeth_start_ipassists(struct qeth_card *card)
7284 QETH_DBF_TEXT(trace,3,"strtipas");
7285 qeth_start_ipa_arp_processing(card); /* go on*/
7286 qeth_start_ipa_ip_fragmentation(card); /* go on*/
7287 qeth_start_ipa_source_mac(card); /* go on*/
7288 qeth_start_ipa_vlan(card); /* go on*/
7289 qeth_start_ipa_multicast(card); /* go on*/
7290 qeth_start_ipa_ipv6(card); /* go on*/
7291 qeth_start_ipa_broadcast(card); /* go on*/
7292 qeth_start_ipa_checksum(card); /* go on*/
7293 qeth_start_ipa_tso(card); /* go on*/
7298 qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7299 enum qeth_prot_versions prot)
7302 struct qeth_ipa_cmd *cmd;
7303 struct qeth_cmd_buffer *iob;
7305 QETH_DBF_TEXT(trace,4,"setroutg");
7306 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7307 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7308 cmd->data.setrtg.type = (type);
7309 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7316 qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7317 enum qeth_prot_versions prot)
7319 if (card->info.type == QETH_CARD_TYPE_IQD) {
7322 case PRIMARY_CONNECTOR:
7323 case SECONDARY_CONNECTOR:
7324 case MULTICAST_ROUTER:
7332 case PRIMARY_ROUTER:
7333 case SECONDARY_ROUTER:
7335 case MULTICAST_ROUTER:
7336 if (qeth_is_ipafunc_supported(card, prot,
7344 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7345 "Router status set to 'no router'.\n",
7346 ((*type == PRIMARY_ROUTER)? "primary router" :
7347 (*type == SECONDARY_ROUTER)? "secondary router" :
7348 (*type == PRIMARY_CONNECTOR)? "primary connector" :
7349 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7350 (*type == MULTICAST_ROUTER)? "multicast router" :
7357 qeth_setrouting_v4(struct qeth_card *card)
7361 QETH_DBF_TEXT(trace,3,"setrtg4");
7363 qeth_correct_routing_type(card, &card->options.route4.type,
7366 rc = qeth_send_setrouting(card, card->options.route4.type,
7369 card->options.route4.type = NO_ROUTER;
7370 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7371 "Type set to 'no router'.\n",
7372 rc, QETH_CARD_IFNAME(card));
7378 qeth_setrouting_v6(struct qeth_card *card)
7382 QETH_DBF_TEXT(trace,3,"setrtg6");
7383 #ifdef CONFIG_QETH_IPV6
7385 qeth_correct_routing_type(card, &card->options.route6.type,
7388 if ((card->options.route6.type == NO_ROUTER) ||
7389 ((card->info.type == QETH_CARD_TYPE_OSAE) &&
7390 (card->options.route6.type == MULTICAST_ROUTER) &&
7391 !qeth_is_supported6(card,IPA_OSA_MC_ROUTER)))
7393 rc = qeth_send_setrouting(card, card->options.route6.type,
7396 card->options.route6.type = NO_ROUTER;
7397 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7398 "Type set to 'no router'.\n",
7399 rc, QETH_CARD_IFNAME(card));
7406 qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
7410 if (card->dev == NULL) {
7411 card->options.large_send = type;
7414 netif_stop_queue(card->dev);
7415 card->options.large_send = type;
7416 switch (card->options.large_send) {
7417 case QETH_LARGE_SEND_EDDP:
7418 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7420 case QETH_LARGE_SEND_TSO:
7421 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7422 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7424 PRINT_WARN("TSO not supported on %s. "
7425 "large_send set to 'no'.\n",
7427 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7428 card->options.large_send = QETH_LARGE_SEND_NO;
7432 default: /* includes QETH_LARGE_SEND_NO */
7433 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7436 netif_wake_queue(card->dev);
7441 * softsetup card: init IPA stuff
7444 qeth_softsetup_card(struct qeth_card *card)
7448 QETH_DBF_TEXT(setup, 2, "softsetp");
7450 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7451 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7453 PRINT_WARN("LAN on card %s if offline! "
7454 "Continuing softsetup.\n",
7456 card->lan_online = 0;
7460 card->lan_online = 1;
7461 if (card->info.type==QETH_CARD_TYPE_OSN)
7463 if (card->options.layer2) {
7464 card->dev->features |=
7465 NETIF_F_HW_VLAN_FILTER |
7466 NETIF_F_HW_VLAN_TX |
7468 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7469 card->info.broadcast_capable=1;
7470 if ((rc = qeth_layer2_initialize(card))) {
7471 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7474 #ifdef CONFIG_QETH_VLAN
7475 qeth_layer2_process_vlans(card, 0);
7479 if ((card->options.large_send == QETH_LARGE_SEND_EDDP) ||
7480 (card->options.large_send == QETH_LARGE_SEND_TSO))
7481 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7483 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7485 if ((rc = qeth_setadapter_parms(card)))
7486 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7487 if ((rc = qeth_start_ipassists(card)))
7488 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7489 if ((rc = qeth_setrouting_v4(card)))
7490 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7491 if ((rc = qeth_setrouting_v6(card)))
7492 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7494 netif_stop_queue(card->dev);
7498 #ifdef CONFIG_QETH_IPV6
7500 qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7503 struct qeth_ipa_cmd *cmd;
7505 cmd = (struct qeth_ipa_cmd *) data;
7506 if (cmd->hdr.return_code == 0)
7507 card->info.unique_id = *((__u16 *)
7508 &cmd->data.create_destroy_addr.unique_id[6]);
7510 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7511 UNIQUE_ID_NOT_BY_CARD;
7512 PRINT_WARN("couldn't get a unique id from the card on device "
7513 "%s (result=x%x), using default id. ipv6 "
7514 "autoconfig on other lpars may lead to duplicate "
7515 "ip addresses. please use manually "
7516 "configured ones.\n",
7517 CARD_BUS_ID(card), cmd->hdr.return_code);
7524 qeth_put_unique_id(struct qeth_card *card)
7528 #ifdef CONFIG_QETH_IPV6
7529 struct qeth_cmd_buffer *iob;
7530 struct qeth_ipa_cmd *cmd;
7532 QETH_DBF_TEXT(trace,2,"puniqeid");
7534 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7535 UNIQUE_ID_NOT_BY_CARD)
7537 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7539 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7540 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7541 card->info.unique_id;
7542 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7543 card->dev->dev_addr, OSA_ADDR_LEN);
7544 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7546 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7547 UNIQUE_ID_NOT_BY_CARD;
7556 qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7558 struct qeth_ipaddr *addr, *tmp;
7559 unsigned long flags;
7561 QETH_DBF_TEXT(trace,4,"clearip");
7562 spin_lock_irqsave(&card->ip_lock, flags);
7563 /* clear todo list */
7564 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7565 list_del(&addr->entry);
7569 while (!list_empty(&card->ip_list)) {
7570 addr = list_entry(card->ip_list.next,
7571 struct qeth_ipaddr, entry);
7572 list_del_init(&addr->entry);
7574 spin_unlock_irqrestore(&card->ip_lock, flags);
7575 qeth_deregister_addr_entry(card, addr);
7576 spin_lock_irqsave(&card->ip_lock, flags);
7578 if (!recover || addr->is_multicast) {
7582 list_add_tail(&addr->entry, card->ip_tbd_list);
7584 spin_unlock_irqrestore(&card->ip_lock, flags);
7588 qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7589 int clear_start_mask)
7591 unsigned long flags;
7593 spin_lock_irqsave(&card->thread_mask_lock, flags);
7594 card->thread_allowed_mask = threads;
7595 if (clear_start_mask)
7596 card->thread_start_mask &= threads;
7597 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7598 wake_up(&card->wait_q);
7602 qeth_threads_running(struct qeth_card *card, unsigned long threads)
7604 unsigned long flags;
7607 spin_lock_irqsave(&card->thread_mask_lock, flags);
7608 rc = (card->thread_running_mask & threads);
7609 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7614 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7616 return wait_event_interruptible(card->wait_q,
7617 qeth_threads_running(card, threads) == 0);
7621 qeth_stop_card(struct qeth_card *card, int recovery_mode)
7625 QETH_DBF_TEXT(setup ,2,"stopcard");
7626 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7628 qeth_set_allowed_threads(card, 0, 1);
7629 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7630 return -ERESTARTSYS;
7631 if (card->read.state == CH_STATE_UP &&
7632 card->write.state == CH_STATE_UP &&
7633 (card->state == CARD_STATE_UP)) {
7634 if (recovery_mode &&
7635 card->info.type != QETH_CARD_TYPE_OSN) {
7636 qeth_stop(card->dev);
7639 dev_close(card->dev);
7642 if (!card->use_hard_stop) {
7643 __u8 *mac = &card->dev->dev_addr[0];
7644 rc = qeth_layer2_send_delmac(card, mac);
7645 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7646 if ((rc = qeth_send_stoplan(card)))
7647 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7649 card->state = CARD_STATE_SOFTSETUP;
7651 if (card->state == CARD_STATE_SOFTSETUP) {
7652 #ifdef CONFIG_QETH_VLAN
7653 if (card->options.layer2)
7654 qeth_layer2_process_vlans(card, 1);
7656 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7657 qeth_clear_ipacmd_list(card);
7658 card->state = CARD_STATE_HARDSETUP;
7660 if (card->state == CARD_STATE_HARDSETUP) {
7661 if ((!card->use_hard_stop) &&
7662 (!card->options.layer2))
7663 if ((rc = qeth_put_unique_id(card)))
7664 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7665 qeth_qdio_clear_card(card, 0);
7666 qeth_clear_qdio_buffers(card);
7667 qeth_clear_working_pool_list(card);
7668 card->state = CARD_STATE_DOWN;
7670 if (card->state == CARD_STATE_DOWN) {
7671 qeth_clear_cmd_buffers(&card->read);
7672 qeth_clear_cmd_buffers(&card->write);
7674 card->use_hard_stop = 0;
7680 qeth_get_unique_id(struct qeth_card *card)
7683 #ifdef CONFIG_QETH_IPV6
7684 struct qeth_cmd_buffer *iob;
7685 struct qeth_ipa_cmd *cmd;
7687 QETH_DBF_TEXT(setup, 2, "guniqeid");
7689 if (!qeth_is_supported(card,IPA_IPV6)) {
7690 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7691 UNIQUE_ID_NOT_BY_CARD;
7695 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7697 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7698 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7699 card->info.unique_id;
7701 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7703 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7704 UNIQUE_ID_NOT_BY_CARD;
7709 qeth_print_status_with_portname(struct qeth_card *card)
7714 sprintf(dbf_text, "%s", card->info.portname + 1);
7715 for (i = 0; i < 8; i++)
7717 (char) _ebcasc[(__u8) dbf_text[i]];
7719 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7720 "with link type %s (portname: %s)\n",
7724 qeth_get_cardname(card),
7725 (card->info.mcl_level[0]) ? " (level: " : "",
7726 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7727 (card->info.mcl_level[0]) ? ")" : "",
7728 qeth_get_cardname_short(card),
7734 qeth_print_status_no_portname(struct qeth_card *card)
7736 if (card->info.portname[0])
7737 printk("qeth: Device %s/%s/%s is a%s "
7738 "card%s%s%s\nwith link type %s "
7739 "(no portname needed by interface).\n",
7743 qeth_get_cardname(card),
7744 (card->info.mcl_level[0]) ? " (level: " : "",
7745 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7746 (card->info.mcl_level[0]) ? ")" : "",
7747 qeth_get_cardname_short(card));
7749 printk("qeth: Device %s/%s/%s is a%s "
7750 "card%s%s%s\nwith link type %s.\n",
7754 qeth_get_cardname(card),
7755 (card->info.mcl_level[0]) ? " (level: " : "",
7756 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7757 (card->info.mcl_level[0]) ? ")" : "",
7758 qeth_get_cardname_short(card));
7762 qeth_print_status_message(struct qeth_card *card)
7764 switch (card->info.type) {
7765 case QETH_CARD_TYPE_OSAE:
7766 /* VM will use a non-zero first character
7767 * to indicate a HiperSockets like reporting
7768 * of the level OSA sets the first character to zero
7770 if (!card->info.mcl_level[0]) {
7771 sprintf(card->info.mcl_level,"%02x%02x",
7772 card->info.mcl_level[2],
7773 card->info.mcl_level[3]);
7775 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7779 case QETH_CARD_TYPE_IQD:
7780 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7781 card->info.mcl_level[0]];
7782 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7783 card->info.mcl_level[1]];
7784 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7785 card->info.mcl_level[2]];
7786 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7787 card->info.mcl_level[3]];
7788 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7791 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7793 if (card->info.portname_required)
7794 qeth_print_status_with_portname(card);
7796 qeth_print_status_no_portname(card);
7800 qeth_register_netdev(struct qeth_card *card)
7802 QETH_DBF_TEXT(setup, 3, "regnetd");
7803 if (card->dev->reg_state != NETREG_UNINITIALIZED) {
7804 qeth_netdev_init(card->dev);
7808 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7809 return register_netdev(card->dev);
7813 qeth_start_again(struct qeth_card *card, int recovery_mode)
7815 QETH_DBF_TEXT(setup ,2, "startag");
7817 if (recovery_mode &&
7818 card->info.type != QETH_CARD_TYPE_OSN) {
7819 qeth_open(card->dev);
7822 dev_open(card->dev);
7825 /* this also sets saved unicast addresses */
7826 qeth_set_multicast_list(card->dev);
7830 /* Layer 2 specific stuff */
7831 #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7832 if (card->options.option == value) { \
7833 PRINT_ERR("%s not supported with layer 2 " \
7834 "functionality, ignoring option on read" \
7835 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7836 card->options.option = reset_value; \
7838 #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7839 if (card->options.option != value) { \
7840 PRINT_ERR("%s not supported with layer 2 " \
7841 "functionality, ignoring option on read" \
7842 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7843 card->options.option = reset_value; \
7847 static void qeth_make_parameters_consistent(struct qeth_card *card)
7850 if (card->options.layer2 == 0)
7852 if (card->info.type == QETH_CARD_TYPE_OSN)
7854 if (card->info.type == QETH_CARD_TYPE_IQD) {
7855 PRINT_ERR("Device %s does not support layer 2 functionality." \
7856 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7857 card->options.layer2 = 0;
7860 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7861 "Routing options are");
7862 #ifdef CONFIG_QETH_IPV6
7863 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7864 "Routing options are");
7866 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7867 QETH_CHECKSUM_DEFAULT,
7868 "Checksumming options are");
7869 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7870 QETH_TR_BROADCAST_ALLRINGS,
7871 "Broadcast mode options are");
7872 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7873 QETH_TR_MACADDR_NONCANONICAL,
7874 "Canonical MAC addr options are");
7875 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7876 "Broadcast faking options are");
7877 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7878 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7879 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
7884 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
7886 struct qeth_card *card = gdev->dev.driver_data;
7888 enum qeth_card_states recover_flag;
7891 QETH_DBF_TEXT(setup ,2, "setonlin");
7892 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7894 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7895 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7896 PRINT_WARN("set_online of card %s interrupted by user!\n",
7898 return -ERESTARTSYS;
7901 recover_flag = card->state;
7902 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7903 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7904 (rc = ccw_device_set_online(CARD_DDEV(card)))){
7905 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7909 qeth_make_parameters_consistent(card);
7911 if ((rc = qeth_hardsetup_card(card))){
7912 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7915 card->state = CARD_STATE_HARDSETUP;
7917 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7918 rc = qeth_get_unique_id(card);
7920 if (rc && card->options.layer2 == 0) {
7921 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7924 qeth_print_status_message(card);
7925 if ((rc = qeth_register_netdev(card))){
7926 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7929 if ((rc = qeth_softsetup_card(card))){
7930 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7933 card->state = CARD_STATE_SOFTSETUP;
7935 if ((rc = qeth_init_qdio_queues(card))){
7936 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7939 /*maybe it was set offline without ifconfig down
7940 * we can also use this state for recovery purposes*/
7941 qeth_set_allowed_threads(card, 0xffffffff, 0);
7942 if (recover_flag == CARD_STATE_RECOVER)
7943 qeth_start_again(card, recovery_mode);
7944 qeth_notify_processes();
7947 card->use_hard_stop = 1;
7948 qeth_stop_card(card, 0);
7949 ccw_device_set_offline(CARD_DDEV(card));
7950 ccw_device_set_offline(CARD_WDEV(card));
7951 ccw_device_set_offline(CARD_RDEV(card));
7952 if (recover_flag == CARD_STATE_RECOVER)
7953 card->state = CARD_STATE_RECOVER;
7955 card->state = CARD_STATE_DOWN;
7960 qeth_set_online(struct ccwgroup_device *gdev)
7962 return __qeth_set_online(gdev, 0);
7965 static struct ccw_device_id qeth_ids[] = {
7966 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE},
7967 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD},
7968 {CCW_DEVICE(0x1731, 0x06), driver_info:QETH_CARD_TYPE_OSN},
7971 MODULE_DEVICE_TABLE(ccw, qeth_ids);
7973 struct device *qeth_root_dev = NULL;
7975 struct ccwgroup_driver qeth_ccwgroup_driver = {
7976 .owner = THIS_MODULE,
7978 .driver_id = 0xD8C5E3C8,
7979 .probe = qeth_probe_device,
7980 .remove = qeth_remove_device,
7981 .set_online = qeth_set_online,
7982 .set_offline = qeth_set_offline,
7985 struct ccw_driver qeth_ccw_driver = {
7988 .probe = ccwgroup_probe_ccwdev,
7989 .remove = ccwgroup_remove_ccwdev,
7994 qeth_unregister_dbf_views(void)
7997 debug_unregister(qeth_dbf_setup);
7999 debug_unregister(qeth_dbf_qerr);
8001 debug_unregister(qeth_dbf_sense);
8003 debug_unregister(qeth_dbf_misc);
8005 debug_unregister(qeth_dbf_data);
8006 if (qeth_dbf_control)
8007 debug_unregister(qeth_dbf_control);
8009 debug_unregister(qeth_dbf_trace);
8012 qeth_register_dbf_views(void)
8014 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
8015 QETH_DBF_SETUP_PAGES,
8016 QETH_DBF_SETUP_NR_AREAS,
8017 QETH_DBF_SETUP_LEN);
8018 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
8019 QETH_DBF_MISC_PAGES,
8020 QETH_DBF_MISC_NR_AREAS,
8022 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
8023 QETH_DBF_DATA_PAGES,
8024 QETH_DBF_DATA_NR_AREAS,
8026 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
8027 QETH_DBF_CONTROL_PAGES,
8028 QETH_DBF_CONTROL_NR_AREAS,
8029 QETH_DBF_CONTROL_LEN);
8030 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
8031 QETH_DBF_SENSE_PAGES,
8032 QETH_DBF_SENSE_NR_AREAS,
8033 QETH_DBF_SENSE_LEN);
8034 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
8035 QETH_DBF_QERR_PAGES,
8036 QETH_DBF_QERR_NR_AREAS,
8038 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
8039 QETH_DBF_TRACE_PAGES,
8040 QETH_DBF_TRACE_NR_AREAS,
8041 QETH_DBF_TRACE_LEN);
8043 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
8044 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
8045 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
8046 (qeth_dbf_trace == NULL)) {
8047 qeth_unregister_dbf_views();
8050 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
8051 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
8053 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
8054 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
8056 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
8057 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
8059 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
8060 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
8062 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
8063 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8065 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8066 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8068 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8069 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8074 #ifdef CONFIG_QETH_IPV6
8075 extern struct neigh_table arp_tbl;
8076 static struct neigh_ops *arp_direct_ops;
8077 static int (*qeth_old_arp_constructor) (struct neighbour *);
8079 static struct neigh_ops arp_direct_ops_template = {
8083 .error_report = NULL,
8084 .output = dev_queue_xmit,
8085 .connected_output = dev_queue_xmit,
8086 .hh_output = dev_queue_xmit,
8087 .queue_xmit = dev_queue_xmit
8091 qeth_arp_constructor(struct neighbour *neigh)
8093 struct net_device *dev = neigh->dev;
8094 struct in_device *in_dev;
8095 struct neigh_parms *parms;
8096 struct qeth_card *card;
8098 card = qeth_get_card_from_dev(dev);
8101 if((card->options.layer2) ||
8102 (card->dev->hard_header == qeth_fake_header))
8106 in_dev = __in_dev_get_rcu(dev);
8107 if (in_dev == NULL) {
8112 parms = in_dev->arp_parms;
8113 __neigh_parms_put(neigh->parms);
8114 neigh->parms = neigh_parms_clone(parms);
8117 neigh->type = inet_addr_type(*(u32 *) neigh->primary_key);
8118 neigh->nud_state = NUD_NOARP;
8119 neigh->ops = arp_direct_ops;
8120 neigh->output = neigh->ops->queue_xmit;
8123 return qeth_old_arp_constructor(neigh);
8125 #endif /*CONFIG_QETH_IPV6*/
8128 * IP address takeover related functions
8131 qeth_clear_ipato_list(struct qeth_card *card)
8133 struct qeth_ipato_entry *ipatoe, *tmp;
8134 unsigned long flags;
8136 spin_lock_irqsave(&card->ip_lock, flags);
8137 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8138 list_del(&ipatoe->entry);
8141 spin_unlock_irqrestore(&card->ip_lock, flags);
8145 qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8147 struct qeth_ipato_entry *ipatoe;
8148 unsigned long flags;
8151 QETH_DBF_TEXT(trace, 2, "addipato");
8152 spin_lock_irqsave(&card->ip_lock, flags);
8153 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8154 if (ipatoe->proto != new->proto)
8156 if (!memcmp(ipatoe->addr, new->addr,
8157 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8158 (ipatoe->mask_bits == new->mask_bits)){
8159 PRINT_WARN("ipato entry already exists!\n");
8165 list_add_tail(&new->entry, &card->ipato.entries);
8167 spin_unlock_irqrestore(&card->ip_lock, flags);
8172 qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8173 u8 *addr, int mask_bits)
8175 struct qeth_ipato_entry *ipatoe, *tmp;
8176 unsigned long flags;
8178 QETH_DBF_TEXT(trace, 2, "delipato");
8179 spin_lock_irqsave(&card->ip_lock, flags);
8180 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8181 if (ipatoe->proto != proto)
8183 if (!memcmp(ipatoe->addr, addr,
8184 (proto == QETH_PROT_IPV4)? 4:16) &&
8185 (ipatoe->mask_bits == mask_bits)){
8186 list_del(&ipatoe->entry);
8190 spin_unlock_irqrestore(&card->ip_lock, flags);
8194 qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8199 for (i = 0; i < len; ++i){
8201 for (j = 7; j >= 0; --j){
8202 bits[i*8 + j] = octet & 1;
8209 qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8211 struct qeth_ipato_entry *ipatoe;
8212 u8 addr_bits[128] = {0, };
8213 u8 ipatoe_bits[128] = {0, };
8216 if (!card->ipato.enabled)
8219 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8220 (addr->proto == QETH_PROT_IPV4)? 4:16);
8221 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8222 if (addr->proto != ipatoe->proto)
8224 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8225 (ipatoe->proto==QETH_PROT_IPV4) ?
8227 if (addr->proto == QETH_PROT_IPV4)
8228 rc = !memcmp(addr_bits, ipatoe_bits,
8229 min(32, ipatoe->mask_bits));
8231 rc = !memcmp(addr_bits, ipatoe_bits,
8232 min(128, ipatoe->mask_bits));
8237 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8239 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8246 * VIPA related functions
8249 qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8252 struct qeth_ipaddr *ipaddr;
8253 unsigned long flags;
8256 ipaddr = qeth_get_addr_buffer(proto);
8258 if (proto == QETH_PROT_IPV4){
8259 QETH_DBF_TEXT(trace, 2, "addvipa4");
8260 memcpy(&ipaddr->u.a4.addr, addr, 4);
8261 ipaddr->u.a4.mask = 0;
8262 #ifdef CONFIG_QETH_IPV6
8263 } else if (proto == QETH_PROT_IPV6){
8264 QETH_DBF_TEXT(trace, 2, "addvipa6");
8265 memcpy(&ipaddr->u.a6.addr, addr, 16);
8266 ipaddr->u.a6.pfxlen = 0;
8269 ipaddr->type = QETH_IP_TYPE_VIPA;
8270 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8271 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8274 spin_lock_irqsave(&card->ip_lock, flags);
8275 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8276 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8278 spin_unlock_irqrestore(&card->ip_lock, flags);
8280 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8283 if (!qeth_add_ip(card, ipaddr))
8285 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8286 schedule_work(&card->kernel_thread_starter);
8291 qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8294 struct qeth_ipaddr *ipaddr;
8296 ipaddr = qeth_get_addr_buffer(proto);
8298 if (proto == QETH_PROT_IPV4){
8299 QETH_DBF_TEXT(trace, 2, "delvipa4");
8300 memcpy(&ipaddr->u.a4.addr, addr, 4);
8301 ipaddr->u.a4.mask = 0;
8302 #ifdef CONFIG_QETH_IPV6
8303 } else if (proto == QETH_PROT_IPV6){
8304 QETH_DBF_TEXT(trace, 2, "delvipa6");
8305 memcpy(&ipaddr->u.a6.addr, addr, 16);
8306 ipaddr->u.a6.pfxlen = 0;
8309 ipaddr->type = QETH_IP_TYPE_VIPA;
8312 if (!qeth_delete_ip(card, ipaddr))
8314 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8315 schedule_work(&card->kernel_thread_starter);
8319 * proxy ARP related functions
8322 qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8325 struct qeth_ipaddr *ipaddr;
8326 unsigned long flags;
8329 ipaddr = qeth_get_addr_buffer(proto);
8331 if (proto == QETH_PROT_IPV4){
8332 QETH_DBF_TEXT(trace, 2, "addrxip4");
8333 memcpy(&ipaddr->u.a4.addr, addr, 4);
8334 ipaddr->u.a4.mask = 0;
8335 #ifdef CONFIG_QETH_IPV6
8336 } else if (proto == QETH_PROT_IPV6){
8337 QETH_DBF_TEXT(trace, 2, "addrxip6");
8338 memcpy(&ipaddr->u.a6.addr, addr, 16);
8339 ipaddr->u.a6.pfxlen = 0;
8342 ipaddr->type = QETH_IP_TYPE_RXIP;
8343 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8344 ipaddr->del_flags = 0;
8347 spin_lock_irqsave(&card->ip_lock, flags);
8348 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8349 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8351 spin_unlock_irqrestore(&card->ip_lock, flags);
8353 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8356 if (!qeth_add_ip(card, ipaddr))
8358 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8359 schedule_work(&card->kernel_thread_starter);
8364 qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8367 struct qeth_ipaddr *ipaddr;
8369 ipaddr = qeth_get_addr_buffer(proto);
8371 if (proto == QETH_PROT_IPV4){
8372 QETH_DBF_TEXT(trace, 2, "addrxip4");
8373 memcpy(&ipaddr->u.a4.addr, addr, 4);
8374 ipaddr->u.a4.mask = 0;
8375 #ifdef CONFIG_QETH_IPV6
8376 } else if (proto == QETH_PROT_IPV6){
8377 QETH_DBF_TEXT(trace, 2, "addrxip6");
8378 memcpy(&ipaddr->u.a6.addr, addr, 16);
8379 ipaddr->u.a6.pfxlen = 0;
8382 ipaddr->type = QETH_IP_TYPE_RXIP;
8385 if (!qeth_delete_ip(card, ipaddr))
8387 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8388 schedule_work(&card->kernel_thread_starter);
8395 qeth_ip_event(struct notifier_block *this,
8396 unsigned long event,void *ptr)
8398 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8399 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8400 struct qeth_ipaddr *addr;
8401 struct qeth_card *card;
8403 QETH_DBF_TEXT(trace,3,"ipevent");
8404 card = qeth_get_card_from_dev(dev);
8407 if (card->options.layer2)
8410 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8412 addr->u.a4.addr = ifa->ifa_address;
8413 addr->u.a4.mask = ifa->ifa_mask;
8414 addr->type = QETH_IP_TYPE_NORMAL;
8420 if (!qeth_add_ip(card, addr))
8424 if (!qeth_delete_ip(card, addr))
8430 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8431 schedule_work(&card->kernel_thread_starter);
8436 static struct notifier_block qeth_ip_notifier = {
8441 #ifdef CONFIG_QETH_IPV6
8443 * IPv6 event handler
8446 qeth_ip6_event(struct notifier_block *this,
8447 unsigned long event,void *ptr)
8450 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8451 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8452 struct qeth_ipaddr *addr;
8453 struct qeth_card *card;
8455 QETH_DBF_TEXT(trace,3,"ip6event");
8457 card = qeth_get_card_from_dev(dev);
8460 if (!qeth_is_supported(card, IPA_IPV6))
8463 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8465 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8466 addr->u.a6.pfxlen = ifa->prefix_len;
8467 addr->type = QETH_IP_TYPE_NORMAL;
8473 if (!qeth_add_ip(card, addr))
8477 if (!qeth_delete_ip(card, addr))
8483 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8484 schedule_work(&card->kernel_thread_starter);
8489 static struct notifier_block qeth_ip6_notifier = {
8496 __qeth_reboot_event_card(struct device *dev, void *data)
8498 struct qeth_card *card;
8500 card = (struct qeth_card *) dev->driver_data;
8501 qeth_clear_ip_list(card, 0, 0);
8502 qeth_qdio_clear_card(card, 0);
8507 qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8510 driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8511 __qeth_reboot_event_card);
8516 static struct notifier_block qeth_reboot_notifier = {
8522 qeth_register_notifiers(void)
8526 QETH_DBF_TEXT(trace,5,"regnotif");
8527 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8529 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8531 #ifdef CONFIG_QETH_IPV6
8532 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8537 #ifdef CONFIG_QETH_IPV6
8539 unregister_inetaddr_notifier(&qeth_ip_notifier);
8542 unregister_reboot_notifier(&qeth_reboot_notifier);
8547 * unregister all event notifiers
8550 qeth_unregister_notifiers(void)
8553 QETH_DBF_TEXT(trace,5,"unregnot");
8554 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8555 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8556 #ifdef CONFIG_QETH_IPV6
8557 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8558 #endif /* QETH_IPV6 */
8562 #ifdef CONFIG_QETH_IPV6
8564 qeth_ipv6_init(void)
8566 qeth_old_arp_constructor = arp_tbl.constructor;
8567 write_lock(&arp_tbl.lock);
8568 arp_tbl.constructor = qeth_arp_constructor;
8569 write_unlock(&arp_tbl.lock);
8571 arp_direct_ops = (struct neigh_ops*)
8572 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8573 if (!arp_direct_ops)
8576 memcpy(arp_direct_ops, &arp_direct_ops_template,
8577 sizeof(struct neigh_ops));
8583 qeth_ipv6_uninit(void)
8585 write_lock(&arp_tbl.lock);
8586 arp_tbl.constructor = qeth_old_arp_constructor;
8587 write_unlock(&arp_tbl.lock);
8588 kfree(arp_direct_ops);
8590 #endif /* CONFIG_QETH_IPV6 */
8593 qeth_sysfs_unregister(void)
8595 qeth_remove_driver_attributes();
8596 ccw_driver_unregister(&qeth_ccw_driver);
8597 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8598 s390_root_dev_unregister(qeth_root_dev);
8601 * register qeth at sysfs
8604 qeth_sysfs_register(void)
8608 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8611 rc = ccw_driver_register(&qeth_ccw_driver);
8614 rc = qeth_create_driver_attributes();
8617 qeth_root_dev = s390_root_dev_register("qeth");
8618 if (IS_ERR(qeth_root_dev)) {
8619 rc = PTR_ERR(qeth_root_dev);
8633 PRINT_INFO("loading %s (%s/%s/%s/%s/%s/%s/%s %s %s)\n",
8634 version, VERSION_QETH_C, VERSION_QETH_H,
8635 VERSION_QETH_MPC_H, VERSION_QETH_MPC_C,
8636 VERSION_QETH_FS_H, VERSION_QETH_PROC_C,
8637 VERSION_QETH_SYS_C, QETH_VERSION_IPV6,
8640 INIT_LIST_HEAD(&qeth_card_list.list);
8641 INIT_LIST_HEAD(&qeth_notify_list);
8642 spin_lock_init(&qeth_notify_lock);
8643 rwlock_init(&qeth_card_list.rwlock);
8645 if (qeth_register_dbf_views())
8647 if (qeth_sysfs_register())
8650 #ifdef CONFIG_QETH_IPV6
8651 if (qeth_ipv6_init()) {
8652 PRINT_ERR("Out of memory during ipv6 init.\n");
8655 #endif /* QETH_IPV6 */
8656 if (qeth_register_notifiers())
8658 if (qeth_create_procfs_entries())
8664 qeth_unregister_notifiers();
8666 #ifdef CONFIG_QETH_IPV6
8668 #endif /* QETH_IPV6 */
8670 qeth_sysfs_unregister();
8671 qeth_unregister_dbf_views();
8673 PRINT_ERR("Initialization failed");
8678 __exit qeth_exit(void)
8680 struct qeth_card *card, *tmp;
8681 unsigned long flags;
8683 QETH_DBF_TEXT(trace,1, "cleanup.");
8686 * Weed would not need to clean up our devices here, because the
8687 * common device layer calls qeth_remove_device for each device
8688 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8689 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8690 * qeth_remove_device called by the common device layer would otherwise
8691 * do a "hard" shutdown (card->use_hard_stop is set to one in
8692 * qeth_remove_device).
8695 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8696 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8697 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8698 qeth_set_offline(card->gdev);
8699 qeth_remove_device(card->gdev);
8702 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8703 #ifdef CONFIG_QETH_IPV6
8706 qeth_unregister_notifiers();
8707 qeth_remove_procfs_entries();
8708 qeth_sysfs_unregister();
8709 qeth_unregister_dbf_views();
8710 printk("qeth: removed\n");
8713 EXPORT_SYMBOL(qeth_osn_register);
8714 EXPORT_SYMBOL(qeth_osn_deregister);
8715 EXPORT_SYMBOL(qeth_osn_assist);
8716 module_init(qeth_init);
8717 module_exit(qeth_exit);
8718 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
8719 MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8720 "Copyright 2000,2003 IBM Corporation\n");
8722 MODULE_LICENSE("GPL");