2 * linux/drivers/s390/net/qeth_main.c
4 * Linux on zSeries OSA Express and HiperSockets support
6 * Copyright 2000,2003 IBM Corporation
8 * Author(s): Original Code written by
9 * Utz Bacher (utz.bacher@de.ibm.com)
11 * Frank Pavlic (fpavlic@de.ibm.com) and
12 * Thomas Spatzier <tspat@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <linux/module.h>
31 #include <linux/moduleparam.h>
32 #include <linux/string.h>
33 #include <linux/errno.h>
36 #include <linux/inetdevice.h>
37 #include <linux/netdevice.h>
38 #include <linux/sched.h>
39 #include <linux/workqueue.h>
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/interrupt.h>
43 #include <linux/tcp.h>
44 #include <linux/icmp.h>
45 #include <linux/skbuff.h>
47 #include <linux/igmp.h>
48 #include <linux/init.h>
49 #include <linux/reboot.h>
50 #include <linux/mii.h>
51 #include <linux/rcupdate.h>
52 #include <linux/ethtool.h>
56 #include <net/route.h>
58 #include <asm/ebcdic.h>
61 #include <asm/timex.h>
62 #include <asm/semaphore.h>
63 #include <asm/uaccess.h>
64 #include <asm/s390_rdev.h>
69 #include "qeth_eddp.h"
72 static const char *version = "qeth S/390 OSA-Express driver";
75 * Debug Facility Stuff
77 static debug_info_t *qeth_dbf_setup = NULL;
78 static debug_info_t *qeth_dbf_data = NULL;
79 static debug_info_t *qeth_dbf_misc = NULL;
80 static debug_info_t *qeth_dbf_control = NULL;
81 debug_info_t *qeth_dbf_trace = NULL;
82 static debug_info_t *qeth_dbf_sense = NULL;
83 static debug_info_t *qeth_dbf_qerr = NULL;
85 DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
87 static struct lock_class_key qdio_out_skb_queue_key;
90 * some more definitions and declarations
92 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
94 /* list of our cards */
95 struct qeth_card_list_struct qeth_card_list;
96 /*process list want to be notified*/
97 spinlock_t qeth_notify_lock;
98 struct list_head qeth_notify_list;
100 static void qeth_send_control_data_cb(struct qeth_channel *,
101 struct qeth_cmd_buffer *);
104 * here we go with function implementation
107 qeth_init_qdio_info(struct qeth_card *card);
110 qeth_init_qdio_queues(struct qeth_card *card);
113 qeth_alloc_qdio_buffers(struct qeth_card *card);
116 qeth_free_qdio_buffers(struct qeth_card *);
119 qeth_clear_qdio_buffers(struct qeth_card *);
122 qeth_clear_ip_list(struct qeth_card *, int, int);
125 qeth_clear_ipacmd_list(struct qeth_card *);
128 qeth_qdio_clear_card(struct qeth_card *, int);
131 qeth_clear_working_pool_list(struct qeth_card *);
134 qeth_clear_cmd_buffers(struct qeth_channel *);
137 qeth_stop(struct net_device *);
140 qeth_clear_ipato_list(struct qeth_card *);
143 qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
146 qeth_irq_tasklet(unsigned long);
149 qeth_set_online(struct ccwgroup_device *);
152 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
154 static struct qeth_ipaddr *
155 qeth_get_addr_buffer(enum qeth_prot_versions);
158 qeth_set_multicast_list(struct net_device *);
161 qeth_setadp_promisc_mode(struct qeth_card *);
164 qeth_notify_processes(void)
166 /*notify all registered processes */
167 struct qeth_notify_list_struct *n_entry;
169 QETH_DBF_TEXT(trace,3,"procnoti");
170 spin_lock(&qeth_notify_lock);
171 list_for_each_entry(n_entry, &qeth_notify_list, list) {
172 send_sig(n_entry->signum, n_entry->task, 1);
174 spin_unlock(&qeth_notify_lock);
178 qeth_notifier_unregister(struct task_struct *p)
180 struct qeth_notify_list_struct *n_entry, *tmp;
182 QETH_DBF_TEXT(trace, 2, "notunreg");
183 spin_lock(&qeth_notify_lock);
184 list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
185 if (n_entry->task == p) {
186 list_del(&n_entry->list);
192 spin_unlock(&qeth_notify_lock);
196 qeth_notifier_register(struct task_struct *p, int signum)
198 struct qeth_notify_list_struct *n_entry;
200 /*check first if entry already exists*/
201 spin_lock(&qeth_notify_lock);
202 list_for_each_entry(n_entry, &qeth_notify_list, list) {
203 if (n_entry->task == p) {
204 n_entry->signum = signum;
205 spin_unlock(&qeth_notify_lock);
209 spin_unlock(&qeth_notify_lock);
211 n_entry = (struct qeth_notify_list_struct *)
212 kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL);
216 n_entry->signum = signum;
217 spin_lock(&qeth_notify_lock);
218 list_add(&n_entry->list,&qeth_notify_list);
219 spin_unlock(&qeth_notify_lock);
225 * free channel command buffers
228 qeth_clean_channel(struct qeth_channel *channel)
232 QETH_DBF_TEXT(setup, 2, "freech");
233 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
234 kfree(channel->iob[cnt].data);
241 qeth_free_card(struct qeth_card *card)
244 QETH_DBF_TEXT(setup, 2, "freecrd");
245 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
246 qeth_clean_channel(&card->read);
247 qeth_clean_channel(&card->write);
249 free_netdev(card->dev);
250 qeth_clear_ip_list(card, 0, 0);
251 qeth_clear_ipato_list(card);
252 kfree(card->ip_tbd_list);
253 qeth_free_qdio_buffers(card);
258 * alloc memory for command buffer per channel
261 qeth_setup_channel(struct qeth_channel *channel)
265 QETH_DBF_TEXT(setup, 2, "setupch");
266 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
267 channel->iob[cnt].data = (char *)
268 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
269 if (channel->iob[cnt].data == NULL)
271 channel->iob[cnt].state = BUF_STATE_FREE;
272 channel->iob[cnt].channel = channel;
273 channel->iob[cnt].callback = qeth_send_control_data_cb;
274 channel->iob[cnt].rc = 0;
276 if (cnt < QETH_CMD_BUFFER_NO) {
278 kfree(channel->iob[cnt].data);
282 channel->io_buf_no = 0;
283 atomic_set(&channel->irq_pending, 0);
284 spin_lock_init(&channel->iob_lock);
286 init_waitqueue_head(&channel->wait_q);
287 channel->irq_tasklet.data = (unsigned long) channel;
288 channel->irq_tasklet.func = qeth_irq_tasklet;
293 * alloc memory for card structure
295 static struct qeth_card *
296 qeth_alloc_card(void)
298 struct qeth_card *card;
300 QETH_DBF_TEXT(setup, 2, "alloccrd");
301 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
304 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
305 if (qeth_setup_channel(&card->read)) {
309 if (qeth_setup_channel(&card->write)) {
310 qeth_clean_channel(&card->read);
318 __qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb)
323 switch (PTR_ERR(irb)) {
325 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
326 QETH_DBF_TEXT(trace, 2, "ckirberr");
327 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
330 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
331 QETH_DBF_TEXT(trace, 2, "ckirberr");
332 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
335 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
337 QETH_DBF_TEXT(trace, 2, "ckirberr");
338 QETH_DBF_TEXT(trace, 2, " rc???");
344 qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
349 sense = (char *) irb->ecw;
350 cstat = irb->scsw.cstat;
351 dstat = irb->scsw.dstat;
353 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
354 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
355 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
356 QETH_DBF_TEXT(trace,2, "CGENCHK");
357 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
358 cdev->dev.bus_id, dstat, cstat);
359 HEXDUMP16(WARN, "irb: ", irb);
360 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
364 if (dstat & DEV_STAT_UNIT_CHECK) {
365 if (sense[SENSE_RESETTING_EVENT_BYTE] &
366 SENSE_RESETTING_EVENT_FLAG) {
367 QETH_DBF_TEXT(trace,2,"REVIND");
370 if (sense[SENSE_COMMAND_REJECT_BYTE] &
371 SENSE_COMMAND_REJECT_FLAG) {
372 QETH_DBF_TEXT(trace,2,"CMDREJi");
375 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
376 QETH_DBF_TEXT(trace,2,"AFFE");
379 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
380 QETH_DBF_TEXT(trace,2,"ZEROSEN");
383 QETH_DBF_TEXT(trace,2,"DGENCHK");
388 static int qeth_issue_next_read(struct qeth_card *);
394 qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
398 struct qeth_cmd_buffer *buffer;
399 struct qeth_channel *channel;
400 struct qeth_card *card;
402 QETH_DBF_TEXT(trace,5,"irq");
404 if (__qeth_check_irb_error(cdev, irb))
406 cstat = irb->scsw.cstat;
407 dstat = irb->scsw.dstat;
409 card = CARD_FROM_CDEV(cdev);
413 if (card->read.ccwdev == cdev){
414 channel = &card->read;
415 QETH_DBF_TEXT(trace,5,"read");
416 } else if (card->write.ccwdev == cdev) {
417 channel = &card->write;
418 QETH_DBF_TEXT(trace,5,"write");
420 channel = &card->data;
421 QETH_DBF_TEXT(trace,5,"data");
423 atomic_set(&channel->irq_pending, 0);
425 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
426 channel->state = CH_STATE_STOPPED;
428 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
429 channel->state = CH_STATE_HALTED;
431 /*let's wake up immediately on data channel*/
432 if ((channel == &card->data) && (intparm != 0))
435 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
436 QETH_DBF_TEXT(trace, 6, "clrchpar");
437 /* we don't have to handle this further */
440 if (intparm == QETH_HALT_CHANNEL_PARM) {
441 QETH_DBF_TEXT(trace, 6, "hltchpar");
442 /* we don't have to handle this further */
445 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
446 (dstat & DEV_STAT_UNIT_CHECK) ||
448 if (irb->esw.esw0.erw.cons) {
449 /* TODO: we should make this s390dbf */
450 PRINT_WARN("sense data available on channel %s.\n",
451 CHANNEL_ID(channel));
452 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
453 HEXDUMP16(WARN,"irb: ",irb);
454 HEXDUMP16(WARN,"sense data: ",irb->ecw);
456 rc = qeth_get_problem(cdev,irb);
458 qeth_schedule_recovery(card);
464 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
465 buffer->state = BUF_STATE_PROCESSED;
467 if (channel == &card->data)
470 if (channel == &card->read &&
471 channel->state == CH_STATE_UP)
472 qeth_issue_next_read(card);
474 tasklet_schedule(&channel->irq_tasklet);
477 wake_up(&card->wait_q);
481 * tasklet function scheduled from irq handler
484 qeth_irq_tasklet(unsigned long data)
486 struct qeth_card *card;
487 struct qeth_channel *channel;
488 struct qeth_cmd_buffer *iob;
491 QETH_DBF_TEXT(trace,5,"irqtlet");
492 channel = (struct qeth_channel *) data;
494 index = channel->buf_no;
495 card = CARD_FROM_CDEV(channel->ccwdev);
496 while (iob[index].state == BUF_STATE_PROCESSED) {
497 if (iob[index].callback !=NULL) {
498 iob[index].callback(channel,iob + index);
500 index = (index + 1) % QETH_CMD_BUFFER_NO;
502 channel->buf_no = index;
503 wake_up(&card->wait_q);
506 static int qeth_stop_card(struct qeth_card *, int);
509 __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
511 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
512 int rc = 0, rc2 = 0, rc3 = 0;
513 enum qeth_card_states recover_flag;
515 QETH_DBF_TEXT(setup, 3, "setoffl");
516 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
518 if (card->dev && netif_carrier_ok(card->dev))
519 netif_carrier_off(card->dev);
520 recover_flag = card->state;
521 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
522 PRINT_WARN("Stopping card %s interrupted by user!\n",
526 rc = ccw_device_set_offline(CARD_DDEV(card));
527 rc2 = ccw_device_set_offline(CARD_WDEV(card));
528 rc3 = ccw_device_set_offline(CARD_RDEV(card));
530 rc = (rc2) ? rc2 : rc3;
532 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
533 if (recover_flag == CARD_STATE_UP)
534 card->state = CARD_STATE_RECOVER;
535 qeth_notify_processes();
540 qeth_set_offline(struct ccwgroup_device *cgdev)
542 return __qeth_set_offline(cgdev, 0);
546 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads);
550 qeth_remove_device(struct ccwgroup_device *cgdev)
552 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
555 QETH_DBF_TEXT(setup, 3, "rmdev");
556 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
561 if (qeth_wait_for_threads(card, 0xffffffff))
564 if (cgdev->state == CCWGROUP_ONLINE){
565 card->use_hard_stop = 1;
566 qeth_set_offline(cgdev);
568 /* remove form our internal list */
569 write_lock_irqsave(&qeth_card_list.rwlock, flags);
570 list_del(&card->list);
571 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
573 unregister_netdev(card->dev);
574 qeth_remove_device_attributes(&cgdev->dev);
575 qeth_free_card(card);
576 cgdev->dev.driver_data = NULL;
577 put_device(&cgdev->dev);
581 qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
583 qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
586 * Add/remove address to/from card's ip list, i.e. try to add or remove
587 * reference to/from an IP address that is already registered on the card.
589 * 0 address was on card and its reference count has been adjusted,
590 * but is still > 0, so nothing has to be done
591 * also returns 0 if card was not on card and the todo was to delete
592 * the address -> there is also nothing to be done
593 * 1 address was not on card and the todo is to add it to the card's ip
595 * -1 address was on card and its reference count has been decremented
596 * to <= 0 by the todo -> address must be removed from card
599 __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
600 struct qeth_ipaddr **__addr)
602 struct qeth_ipaddr *addr;
605 list_for_each_entry(addr, &card->ip_list, entry) {
606 if (card->options.layer2) {
607 if ((addr->type == todo->type) &&
608 (memcmp(&addr->mac, &todo->mac,
609 OSA_ADDR_LEN) == 0)) {
615 if ((addr->proto == QETH_PROT_IPV4) &&
616 (todo->proto == QETH_PROT_IPV4) &&
617 (addr->type == todo->type) &&
618 (addr->u.a4.addr == todo->u.a4.addr) &&
619 (addr->u.a4.mask == todo->u.a4.mask)) {
623 if ((addr->proto == QETH_PROT_IPV6) &&
624 (todo->proto == QETH_PROT_IPV6) &&
625 (addr->type == todo->type) &&
626 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
627 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
628 sizeof(struct in6_addr)) == 0)) {
634 addr->users += todo->users;
635 if (addr->users <= 0){
639 /* for VIPA and RXIP limit refcount to 1 */
640 if (addr->type != QETH_IP_TYPE_NORMAL)
645 if (todo->users > 0) {
646 /* for VIPA and RXIP limit refcount to 1 */
647 if (todo->type != QETH_IP_TYPE_NORMAL)
655 __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
658 struct qeth_ipaddr *tmp;
660 list_for_each_entry(tmp, list, entry) {
661 if ((tmp->proto == QETH_PROT_IPV4) &&
662 (addr->proto == QETH_PROT_IPV4) &&
663 ((same_type && (tmp->type == addr->type)) ||
664 (!same_type && (tmp->type != addr->type)) ) &&
665 (tmp->u.a4.addr == addr->u.a4.addr) ){
668 if ((tmp->proto == QETH_PROT_IPV6) &&
669 (addr->proto == QETH_PROT_IPV6) &&
670 ((same_type && (tmp->type == addr->type)) ||
671 (!same_type && (tmp->type != addr->type)) ) &&
672 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
673 sizeof(struct in6_addr)) == 0) ) {
681 * Add IP to be added to todo list. If there is already an "add todo"
682 * in this list we just incremenent the reference count.
683 * Returns 0 if we just incremented reference count.
686 __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
688 struct qeth_ipaddr *tmp, *t;
691 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
692 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
693 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
695 if (card->options.layer2) {
696 if ((tmp->type == addr->type) &&
697 (tmp->is_multicast == addr->is_multicast) &&
698 (memcmp(&tmp->mac, &addr->mac,
699 OSA_ADDR_LEN) == 0)) {
705 if ((tmp->proto == QETH_PROT_IPV4) &&
706 (addr->proto == QETH_PROT_IPV4) &&
707 (tmp->type == addr->type) &&
708 (tmp->is_multicast == addr->is_multicast) &&
709 (tmp->u.a4.addr == addr->u.a4.addr) &&
710 (tmp->u.a4.mask == addr->u.a4.mask)) {
714 if ((tmp->proto == QETH_PROT_IPV6) &&
715 (addr->proto == QETH_PROT_IPV6) &&
716 (tmp->type == addr->type) &&
717 (tmp->is_multicast == addr->is_multicast) &&
718 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
719 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
720 sizeof(struct in6_addr)) == 0)) {
726 if (addr->users != 0)
727 tmp->users += addr->users;
729 tmp->users += add? 1:-1;
730 if (tmp->users == 0) {
731 list_del(&tmp->entry);
736 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
737 list_add(&addr->entry, card->ip_tbd_list);
739 if (addr->users == 0)
740 addr->users += add? 1:-1;
741 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
742 qeth_is_addr_covered_by_ipato(card, addr)){
743 QETH_DBF_TEXT(trace, 2, "tkovaddr");
744 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
746 list_add_tail(&addr->entry, card->ip_tbd_list);
753 * Remove IP address from list
756 qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
761 QETH_DBF_TEXT(trace, 4, "delip");
763 if (card->options.layer2)
764 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
765 else if (addr->proto == QETH_PROT_IPV4)
766 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
768 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
769 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
771 spin_lock_irqsave(&card->ip_lock, flags);
772 rc = __qeth_insert_ip_todo(card, addr, 0);
773 spin_unlock_irqrestore(&card->ip_lock, flags);
778 qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
783 QETH_DBF_TEXT(trace, 4, "addip");
784 if (card->options.layer2)
785 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
786 else if (addr->proto == QETH_PROT_IPV4)
787 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
789 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
790 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
792 spin_lock_irqsave(&card->ip_lock, flags);
793 rc = __qeth_insert_ip_todo(card, addr, 1);
794 spin_unlock_irqrestore(&card->ip_lock, flags);
799 __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
801 struct qeth_ipaddr *addr, *tmp;
804 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
805 if (addr->is_multicast) {
806 spin_unlock_irqrestore(&card->ip_lock, *flags);
807 rc = qeth_deregister_addr_entry(card, addr);
808 spin_lock_irqsave(&card->ip_lock, *flags);
810 list_del(&addr->entry);
819 qeth_set_ip_addr_list(struct qeth_card *card)
821 struct list_head *tbd_list;
822 struct qeth_ipaddr *todo, *addr;
826 QETH_DBF_TEXT(trace, 2, "sdiplist");
827 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
829 spin_lock_irqsave(&card->ip_lock, flags);
830 tbd_list = card->ip_tbd_list;
831 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
832 if (!card->ip_tbd_list) {
833 QETH_DBF_TEXT(trace, 0, "silnomem");
834 card->ip_tbd_list = tbd_list;
835 spin_unlock_irqrestore(&card->ip_lock, flags);
838 INIT_LIST_HEAD(card->ip_tbd_list);
840 while (!list_empty(tbd_list)){
841 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
842 list_del(&todo->entry);
843 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
844 __qeth_delete_all_mc(card, &flags);
848 rc = __qeth_ref_ip_on_card(card, todo, &addr);
850 /* nothing to be done; only adjusted refcount */
852 } else if (rc == 1) {
853 /* new entry to be added to on-card list */
854 spin_unlock_irqrestore(&card->ip_lock, flags);
855 rc = qeth_register_addr_entry(card, todo);
856 spin_lock_irqsave(&card->ip_lock, flags);
858 list_add_tail(&todo->entry, &card->ip_list);
861 } else if (rc == -1) {
862 /* on-card entry to be removed */
863 list_del_init(&addr->entry);
864 spin_unlock_irqrestore(&card->ip_lock, flags);
865 rc = qeth_deregister_addr_entry(card, addr);
866 spin_lock_irqsave(&card->ip_lock, flags);
870 list_add_tail(&addr->entry, &card->ip_list);
874 spin_unlock_irqrestore(&card->ip_lock, flags);
878 static void qeth_delete_mc_addresses(struct qeth_card *);
879 static void qeth_add_multicast_ipv4(struct qeth_card *);
880 static void qeth_layer2_add_multicast(struct qeth_card *);
881 #ifdef CONFIG_QETH_IPV6
882 static void qeth_add_multicast_ipv6(struct qeth_card *);
886 qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
890 spin_lock_irqsave(&card->thread_mask_lock, flags);
891 if ( !(card->thread_allowed_mask & thread) ||
892 (card->thread_start_mask & thread) ) {
893 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
896 card->thread_start_mask |= thread;
897 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
902 qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
906 spin_lock_irqsave(&card->thread_mask_lock, flags);
907 card->thread_start_mask &= ~thread;
908 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
909 wake_up(&card->wait_q);
913 qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
917 spin_lock_irqsave(&card->thread_mask_lock, flags);
918 card->thread_running_mask &= ~thread;
919 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
920 wake_up(&card->wait_q);
924 __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
929 spin_lock_irqsave(&card->thread_mask_lock, flags);
930 if (card->thread_start_mask & thread){
931 if ((card->thread_allowed_mask & thread) &&
932 !(card->thread_running_mask & thread)){
934 card->thread_start_mask &= ~thread;
935 card->thread_running_mask |= thread;
939 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
944 qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
948 wait_event(card->wait_q,
949 (rc = __qeth_do_run_thread(card, thread)) >= 0);
954 qeth_register_ip_addresses(void *ptr)
956 struct qeth_card *card;
958 card = (struct qeth_card *) ptr;
959 daemonize("qeth_reg_ip");
960 QETH_DBF_TEXT(trace,4,"regipth1");
961 if (!qeth_do_run_thread(card, QETH_SET_IP_THREAD))
963 QETH_DBF_TEXT(trace,4,"regipth2");
964 qeth_set_ip_addr_list(card);
965 qeth_clear_thread_running_bit(card, QETH_SET_IP_THREAD);
970 * Drive the SET_PROMISC_MODE thread
973 qeth_set_promisc_mode(void *ptr)
975 struct qeth_card *card = (struct qeth_card *) ptr;
977 daemonize("qeth_setprm");
978 QETH_DBF_TEXT(trace,4,"setprm1");
979 if (!qeth_do_run_thread(card, QETH_SET_PROMISC_MODE_THREAD))
981 QETH_DBF_TEXT(trace,4,"setprm2");
982 qeth_setadp_promisc_mode(card);
983 qeth_clear_thread_running_bit(card, QETH_SET_PROMISC_MODE_THREAD);
988 qeth_recover(void *ptr)
990 struct qeth_card *card;
993 card = (struct qeth_card *) ptr;
994 daemonize("qeth_recover");
995 QETH_DBF_TEXT(trace,2,"recover1");
996 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
997 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
999 QETH_DBF_TEXT(trace,2,"recover2");
1000 PRINT_WARN("Recovery of device %s started ...\n",
1002 card->use_hard_stop = 1;
1003 __qeth_set_offline(card->gdev,1);
1004 rc = __qeth_set_online(card->gdev,1);
1006 PRINT_INFO("Device %s successfully recovered!\n",
1009 PRINT_INFO("Device %s could not be recovered!\n",
1011 /* don't run another scheduled recovery */
1012 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1013 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1018 qeth_schedule_recovery(struct qeth_card *card)
1020 QETH_DBF_TEXT(trace,2,"startrec");
1021 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
1022 schedule_work(&card->kernel_thread_starter);
1026 qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1028 unsigned long flags;
1031 spin_lock_irqsave(&card->thread_mask_lock, flags);
1032 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
1033 (u8) card->thread_start_mask,
1034 (u8) card->thread_allowed_mask,
1035 (u8) card->thread_running_mask);
1036 rc = (card->thread_start_mask & thread);
1037 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1042 qeth_start_kernel_thread(struct qeth_card *card)
1044 QETH_DBF_TEXT(trace , 2, "strthrd");
1046 if (card->read.state != CH_STATE_UP &&
1047 card->write.state != CH_STATE_UP)
1050 if (qeth_do_start_thread(card, QETH_SET_IP_THREAD))
1051 kernel_thread(qeth_register_ip_addresses, (void *)card,SIGCHLD);
1052 if (qeth_do_start_thread(card, QETH_SET_PROMISC_MODE_THREAD))
1053 kernel_thread(qeth_set_promisc_mode, (void *)card, SIGCHLD);
1054 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1055 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1060 qeth_set_intial_options(struct qeth_card *card)
1062 card->options.route4.type = NO_ROUTER;
1063 #ifdef CONFIG_QETH_IPV6
1064 card->options.route6.type = NO_ROUTER;
1065 #endif /* QETH_IPV6 */
1066 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1067 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1068 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1069 card->options.fake_broadcast = 0;
1070 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1071 card->options.fake_ll = 0;
1072 if (card->info.type == QETH_CARD_TYPE_OSN)
1073 card->options.layer2 = 1;
1075 card->options.layer2 = 0;
1076 card->options.performance_stats = 1;
1080 * initialize channels ,card and all state machines
1083 qeth_setup_card(struct qeth_card *card)
1086 QETH_DBF_TEXT(setup, 2, "setupcrd");
1087 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1089 card->read.state = CH_STATE_DOWN;
1090 card->write.state = CH_STATE_DOWN;
1091 card->data.state = CH_STATE_DOWN;
1092 card->state = CARD_STATE_DOWN;
1093 card->lan_online = 0;
1094 card->use_hard_stop = 0;
1096 #ifdef CONFIG_QETH_VLAN
1097 spin_lock_init(&card->vlanlock);
1098 card->vlangrp = NULL;
1100 spin_lock_init(&card->lock);
1101 spin_lock_init(&card->ip_lock);
1102 spin_lock_init(&card->thread_mask_lock);
1103 card->thread_start_mask = 0;
1104 card->thread_allowed_mask = 0;
1105 card->thread_running_mask = 0;
1106 INIT_WORK(&card->kernel_thread_starter,
1107 (void *)qeth_start_kernel_thread,card);
1108 INIT_LIST_HEAD(&card->ip_list);
1109 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1110 if (!card->ip_tbd_list) {
1111 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1114 INIT_LIST_HEAD(card->ip_tbd_list);
1115 INIT_LIST_HEAD(&card->cmd_waiter_list);
1116 init_waitqueue_head(&card->wait_q);
1117 /* intial options */
1118 qeth_set_intial_options(card);
1119 /* IP address takeover */
1120 INIT_LIST_HEAD(&card->ipato.entries);
1121 card->ipato.enabled = 0;
1122 card->ipato.invert4 = 0;
1123 card->ipato.invert6 = 0;
1124 /* init QDIO stuff */
1125 qeth_init_qdio_info(card);
1130 is_1920_device (struct qeth_card *card)
1132 int single_queue = 0;
1133 struct ccw_device *ccwdev;
1134 struct channelPath_dsc {
1145 QETH_DBF_TEXT(setup, 2, "chk_1920");
1147 ccwdev = card->data.ccwdev;
1148 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1149 if (chp_dsc != NULL) {
1150 /* CHPP field bit 6 == 1 -> single queue */
1151 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1154 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1155 return single_queue;
1159 qeth_determine_card_type(struct qeth_card *card)
1163 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1165 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1166 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1167 while (known_devices[i][4]) {
1168 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1169 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1170 card->info.type = known_devices[i][4];
1171 card->qdio.no_out_queues = known_devices[i][8];
1172 card->info.is_multicast_different = known_devices[i][9];
1173 if (is_1920_device(card)) {
1174 PRINT_INFO("Priority Queueing not able "
1175 "due to hardware limitations!\n");
1176 card->qdio.no_out_queues = 1;
1177 card->qdio.default_out_queue = 0;
1183 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1184 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1189 qeth_probe_device(struct ccwgroup_device *gdev)
1191 struct qeth_card *card;
1193 unsigned long flags;
1196 QETH_DBF_TEXT(setup, 2, "probedev");
1199 if (!get_device(dev))
1202 QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
1204 card = qeth_alloc_card();
1207 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1210 card->read.ccwdev = gdev->cdev[0];
1211 card->write.ccwdev = gdev->cdev[1];
1212 card->data.ccwdev = gdev->cdev[2];
1213 gdev->dev.driver_data = card;
1215 gdev->cdev[0]->handler = qeth_irq;
1216 gdev->cdev[1]->handler = qeth_irq;
1217 gdev->cdev[2]->handler = qeth_irq;
1219 if ((rc = qeth_determine_card_type(card))){
1220 PRINT_WARN("%s: not a valid card type\n", __func__);
1221 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1223 qeth_free_card(card);
1226 if ((rc = qeth_setup_card(card))){
1227 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1229 qeth_free_card(card);
1232 rc = qeth_create_device_attributes(dev);
1235 qeth_free_card(card);
1238 /* insert into our internal list */
1239 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1240 list_add_tail(&card->list, &qeth_card_list.list);
1241 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1247 qeth_get_unitaddr(struct qeth_card *card)
1253 QETH_DBF_TEXT(setup, 2, "getunit");
1254 rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length);
1256 PRINT_ERR("read_conf_data for device %s returned %i\n",
1257 CARD_DDEV_ID(card), rc);
1260 card->info.chpid = prcd[30];
1261 card->info.unit_addr2 = prcd[31];
1262 card->info.cula = prcd[63];
1263 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1264 (prcd[0x11] == _ascebc['M']));
1269 qeth_init_tokens(struct qeth_card *card)
1271 card->token.issuer_rm_w = 0x00010103UL;
1272 card->token.cm_filter_w = 0x00010108UL;
1273 card->token.cm_connection_w = 0x0001010aUL;
1274 card->token.ulp_filter_w = 0x0001010bUL;
1275 card->token.ulp_connection_w = 0x0001010dUL;
1279 raw_devno_from_bus_id(char *id)
1281 id += (strlen(id) - 4);
1282 return (__u16) simple_strtoul(id, &id, 16);
1288 qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1290 struct qeth_card *card;
1292 QETH_DBF_TEXT(trace, 4, "setupccw");
1293 card = CARD_FROM_CDEV(channel->ccwdev);
1294 if (channel == &card->read)
1295 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1297 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1298 channel->ccw.count = len;
1299 channel->ccw.cda = (__u32) __pa(iob);
1303 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1305 static struct qeth_cmd_buffer *
1306 __qeth_get_buffer(struct qeth_channel *channel)
1310 QETH_DBF_TEXT(trace, 6, "getbuff");
1311 index = channel->io_buf_no;
1313 if (channel->iob[index].state == BUF_STATE_FREE) {
1314 channel->iob[index].state = BUF_STATE_LOCKED;
1315 channel->io_buf_no = (channel->io_buf_no + 1) %
1317 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1318 return channel->iob + index;
1320 index = (index + 1) % QETH_CMD_BUFFER_NO;
1321 } while(index != channel->io_buf_no);
1327 * release command buffer
1330 qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1332 unsigned long flags;
1334 QETH_DBF_TEXT(trace, 6, "relbuff");
1335 spin_lock_irqsave(&channel->iob_lock, flags);
1336 memset(iob->data, 0, QETH_BUFSIZE);
1337 iob->state = BUF_STATE_FREE;
1338 iob->callback = qeth_send_control_data_cb;
1340 spin_unlock_irqrestore(&channel->iob_lock, flags);
1343 static struct qeth_cmd_buffer *
1344 qeth_get_buffer(struct qeth_channel *channel)
1346 struct qeth_cmd_buffer *buffer = NULL;
1347 unsigned long flags;
1349 spin_lock_irqsave(&channel->iob_lock, flags);
1350 buffer = __qeth_get_buffer(channel);
1351 spin_unlock_irqrestore(&channel->iob_lock, flags);
1355 static struct qeth_cmd_buffer *
1356 qeth_wait_for_buffer(struct qeth_channel *channel)
1358 struct qeth_cmd_buffer *buffer;
1359 wait_event(channel->wait_q,
1360 ((buffer = qeth_get_buffer(channel)) != NULL));
1365 qeth_clear_cmd_buffers(struct qeth_channel *channel)
1369 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1370 qeth_release_buffer(channel,&channel->iob[cnt]);
1371 channel->buf_no = 0;
1372 channel->io_buf_no = 0;
1376 * start IDX for read and write channel
1379 qeth_idx_activate_get_answer(struct qeth_channel *channel,
1380 void (*idx_reply_cb)(struct qeth_channel *,
1381 struct qeth_cmd_buffer *))
1383 struct qeth_cmd_buffer *iob;
1384 unsigned long flags;
1386 struct qeth_card *card;
1388 QETH_DBF_TEXT(setup, 2, "idxanswr");
1389 card = CARD_FROM_CDEV(channel->ccwdev);
1390 iob = qeth_get_buffer(channel);
1391 iob->callback = idx_reply_cb;
1392 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1393 channel->ccw.count = QETH_BUFSIZE;
1394 channel->ccw.cda = (__u32) __pa(iob->data);
1396 wait_event(card->wait_q,
1397 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1398 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1399 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1400 rc = ccw_device_start(channel->ccwdev,
1401 &channel->ccw,(addr_t) iob, 0, 0);
1402 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1405 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1406 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1407 atomic_set(&channel->irq_pending, 0);
1408 wake_up(&card->wait_q);
1411 rc = wait_event_interruptible_timeout(card->wait_q,
1412 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1413 if (rc == -ERESTARTSYS)
1415 if (channel->state != CH_STATE_UP){
1417 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1418 qeth_clear_cmd_buffers(channel);
1425 qeth_idx_activate_channel(struct qeth_channel *channel,
1426 void (*idx_reply_cb)(struct qeth_channel *,
1427 struct qeth_cmd_buffer *))
1429 struct qeth_card *card;
1430 struct qeth_cmd_buffer *iob;
1431 unsigned long flags;
1435 card = CARD_FROM_CDEV(channel->ccwdev);
1437 QETH_DBF_TEXT(setup, 2, "idxactch");
1439 iob = qeth_get_buffer(channel);
1440 iob->callback = idx_reply_cb;
1441 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1442 channel->ccw.count = IDX_ACTIVATE_SIZE;
1443 channel->ccw.cda = (__u32) __pa(iob->data);
1444 if (channel == &card->write) {
1445 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1446 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1447 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1448 card->seqno.trans_hdr++;
1450 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1451 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1452 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1454 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1455 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1456 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1457 &card->info.func_level,sizeof(__u16));
1458 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1459 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1460 temp = (card->info.cula << 8) + card->info.unit_addr2;
1461 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1463 wait_event(card->wait_q,
1464 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1465 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1466 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1467 rc = ccw_device_start(channel->ccwdev,
1468 &channel->ccw,(addr_t) iob, 0, 0);
1469 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1472 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1473 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1474 atomic_set(&channel->irq_pending, 0);
1475 wake_up(&card->wait_q);
1478 rc = wait_event_interruptible_timeout(card->wait_q,
1479 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1480 if (rc == -ERESTARTSYS)
1482 if (channel->state != CH_STATE_ACTIVATING) {
1483 PRINT_WARN("qeth: IDX activate timed out!\n");
1484 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1485 qeth_clear_cmd_buffers(channel);
1488 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1492 qeth_peer_func_level(int level)
1494 if ((level & 0xff) == 8)
1495 return (level & 0xff) + 0x400;
1496 if (((level >> 8) & 3) == 1)
1497 return (level & 0xff) + 0x200;
1502 qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1504 struct qeth_card *card;
1507 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1509 if (channel->state == CH_STATE_DOWN) {
1510 channel->state = CH_STATE_ACTIVATING;
1513 card = CARD_FROM_CDEV(channel->ccwdev);
1515 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1516 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1517 "reply\n", CARD_WDEV_ID(card));
1520 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1521 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1522 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1523 "function level mismatch "
1524 "(sent: 0x%x, received: 0x%x)\n",
1525 CARD_WDEV_ID(card), card->info.func_level, temp);
1528 channel->state = CH_STATE_UP;
1530 qeth_release_buffer(channel, iob);
1534 qeth_check_idx_response(unsigned char *buffer)
1539 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1540 if ((buffer[2] & 0xc0) == 0xc0) {
1541 PRINT_WARN("received an IDX TERMINATE "
1542 "with cause code 0x%02x%s\n",
1544 ((buffer[4] == 0x22) ?
1545 " -- try another portname" : ""));
1546 QETH_DBF_TEXT(trace, 2, "ckidxres");
1547 QETH_DBF_TEXT(trace, 2, " idxterm");
1548 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1555 qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1557 struct qeth_card *card;
1560 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1561 if (channel->state == CH_STATE_DOWN) {
1562 channel->state = CH_STATE_ACTIVATING;
1566 card = CARD_FROM_CDEV(channel->ccwdev);
1567 if (qeth_check_idx_response(iob->data)) {
1570 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1571 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1572 "reply\n", CARD_RDEV_ID(card));
1577 * temporary fix for microcode bug
1578 * to revert it,replace OR by AND
1580 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1581 (card->info.type == QETH_CARD_TYPE_OSAE) )
1582 card->info.portname_required = 1;
1584 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1585 if (temp != qeth_peer_func_level(card->info.func_level)) {
1586 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1587 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1588 CARD_RDEV_ID(card), card->info.func_level, temp);
1591 memcpy(&card->token.issuer_rm_r,
1592 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1593 QETH_MPC_TOKEN_LENGTH);
1594 memcpy(&card->info.mcl_level[0],
1595 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1596 channel->state = CH_STATE_UP;
1598 qeth_release_buffer(channel,iob);
1602 qeth_issue_next_read(struct qeth_card *card)
1605 struct qeth_cmd_buffer *iob;
1607 QETH_DBF_TEXT(trace,5,"issnxrd");
1608 if (card->read.state != CH_STATE_UP)
1610 iob = qeth_get_buffer(&card->read);
1612 PRINT_WARN("issue_next_read failed: no iob available!\n");
1615 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1616 wait_event(card->wait_q,
1617 atomic_cmpxchg(&card->read.irq_pending, 0, 1) == 0);
1618 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1619 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1620 (addr_t) iob, 0, 0);
1622 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1623 atomic_set(&card->read.irq_pending, 0);
1624 qeth_schedule_recovery(card);
1625 wake_up(&card->wait_q);
1630 static struct qeth_reply *
1631 qeth_alloc_reply(struct qeth_card *card)
1633 struct qeth_reply *reply;
1635 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1637 atomic_set(&reply->refcnt, 1);
1644 qeth_get_reply(struct qeth_reply *reply)
1646 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1647 atomic_inc(&reply->refcnt);
1651 qeth_put_reply(struct qeth_reply *reply)
1653 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1654 if (atomic_dec_and_test(&reply->refcnt))
1659 qeth_cmd_timeout(unsigned long data)
1661 struct qeth_reply *reply, *list_reply, *r;
1662 unsigned long flags;
1664 reply = (struct qeth_reply *) data;
1665 spin_lock_irqsave(&reply->card->lock, flags);
1666 list_for_each_entry_safe(list_reply, r,
1667 &reply->card->cmd_waiter_list, list) {
1668 if (reply == list_reply){
1669 qeth_get_reply(reply);
1670 list_del_init(&reply->list);
1671 spin_unlock_irqrestore(&reply->card->lock, flags);
1673 reply->received = 1;
1674 wake_up(&reply->wait_q);
1675 qeth_put_reply(reply);
1679 spin_unlock_irqrestore(&reply->card->lock, flags);
1683 static struct qeth_ipa_cmd *
1684 qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1686 struct qeth_ipa_cmd *cmd = NULL;
1688 QETH_DBF_TEXT(trace,5,"chkipad");
1689 if (IS_IPA(iob->data)){
1690 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1691 if (IS_IPA_REPLY(cmd))
1694 switch (cmd->hdr.command) {
1695 case IPA_CMD_STOPLAN:
1696 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1697 "there is a network problem or "
1698 "someone pulled the cable or "
1699 "disabled the port.\n",
1700 QETH_CARD_IFNAME(card),
1702 card->lan_online = 0;
1703 if (card->dev && netif_carrier_ok(card->dev))
1704 netif_carrier_off(card->dev);
1706 case IPA_CMD_STARTLAN:
1707 PRINT_INFO("Link reestablished on %s "
1708 "(CHPID 0x%X). Scheduling "
1709 "IP address reset.\n",
1710 QETH_CARD_IFNAME(card),
1712 netif_carrier_on(card->dev);
1713 qeth_schedule_recovery(card);
1715 case IPA_CMD_MODCCID:
1717 case IPA_CMD_REGISTER_LOCAL_ADDR:
1718 QETH_DBF_TEXT(trace,3, "irla");
1720 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1721 QETH_DBF_TEXT(trace,3, "urla");
1724 PRINT_WARN("Received data is IPA "
1725 "but not a reply!\n");
1734 * wake all waiting ipa commands
1737 qeth_clear_ipacmd_list(struct qeth_card *card)
1739 struct qeth_reply *reply, *r;
1740 unsigned long flags;
1742 QETH_DBF_TEXT(trace, 4, "clipalst");
1744 spin_lock_irqsave(&card->lock, flags);
1745 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1746 qeth_get_reply(reply);
1748 reply->received = 1;
1749 list_del_init(&reply->list);
1750 wake_up(&reply->wait_q);
1751 qeth_put_reply(reply);
1753 spin_unlock_irqrestore(&card->lock, flags);
1757 qeth_send_control_data_cb(struct qeth_channel *channel,
1758 struct qeth_cmd_buffer *iob)
1760 struct qeth_card *card;
1761 struct qeth_reply *reply, *r;
1762 struct qeth_ipa_cmd *cmd;
1763 unsigned long flags;
1766 QETH_DBF_TEXT(trace,4,"sndctlcb");
1768 card = CARD_FROM_CDEV(channel->ccwdev);
1769 if (qeth_check_idx_response(iob->data)) {
1770 qeth_clear_ipacmd_list(card);
1771 qeth_schedule_recovery(card);
1775 cmd = qeth_check_ipa_data(card, iob);
1776 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1778 /*in case of OSN : check if cmd is set */
1779 if (card->info.type == QETH_CARD_TYPE_OSN &&
1781 cmd->hdr.command != IPA_CMD_STARTLAN &&
1782 card->osn_info.assist_cb != NULL) {
1783 card->osn_info.assist_cb(card->dev, cmd);
1787 spin_lock_irqsave(&card->lock, flags);
1788 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1789 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1790 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1791 qeth_get_reply(reply);
1792 list_del_init(&reply->list);
1793 spin_unlock_irqrestore(&card->lock, flags);
1795 if (reply->callback != NULL) {
1797 reply->offset = (__u16)((char*)cmd -
1799 keep_reply = reply->callback(card,
1801 (unsigned long)cmd);
1803 keep_reply = reply->callback(card,
1805 (unsigned long)iob);
1808 reply->rc = (u16) cmd->hdr.return_code;
1810 reply->rc = iob->rc;
1812 spin_lock_irqsave(&card->lock, flags);
1813 list_add_tail(&reply->list,
1814 &card->cmd_waiter_list);
1815 spin_unlock_irqrestore(&card->lock, flags);
1817 reply->received = 1;
1818 wake_up(&reply->wait_q);
1820 qeth_put_reply(reply);
1824 spin_unlock_irqrestore(&card->lock, flags);
1826 memcpy(&card->seqno.pdu_hdr_ack,
1827 QETH_PDU_HEADER_SEQ_NO(iob->data),
1828 QETH_SEQ_NO_LENGTH);
1829 qeth_release_buffer(channel,iob);
1833 qeth_prepare_control_data(struct qeth_card *card, int len,
1834 struct qeth_cmd_buffer *iob)
1836 qeth_setup_ccw(&card->write,iob->data,len);
1837 iob->callback = qeth_release_buffer;
1839 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1840 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1841 card->seqno.trans_hdr++;
1842 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1843 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1844 card->seqno.pdu_hdr++;
1845 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1846 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1847 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1851 qeth_send_control_data(struct qeth_card *card, int len,
1852 struct qeth_cmd_buffer *iob,
1854 (struct qeth_card *, struct qeth_reply*, unsigned long),
1859 unsigned long flags;
1860 struct qeth_reply *reply = NULL;
1861 struct timer_list timer;
1863 QETH_DBF_TEXT(trace, 2, "sendctl");
1865 reply = qeth_alloc_reply(card);
1867 PRINT_WARN("Could no alloc qeth_reply!\n");
1870 reply->callback = reply_cb;
1871 reply->param = reply_param;
1872 if (card->state == CARD_STATE_DOWN)
1873 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1875 reply->seqno = card->seqno.ipa++;
1877 timer.function = qeth_cmd_timeout;
1878 timer.data = (unsigned long) reply;
1879 init_waitqueue_head(&reply->wait_q);
1880 spin_lock_irqsave(&card->lock, flags);
1881 list_add_tail(&reply->list, &card->cmd_waiter_list);
1882 spin_unlock_irqrestore(&card->lock, flags);
1883 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1884 wait_event(card->wait_q,
1885 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1886 qeth_prepare_control_data(card, len, iob);
1887 if (IS_IPA(iob->data))
1888 timer.expires = jiffies + QETH_IPA_TIMEOUT;
1890 timer.expires = jiffies + QETH_TIMEOUT;
1891 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1892 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1893 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1894 (addr_t) iob, 0, 0);
1895 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1897 PRINT_WARN("qeth_send_control_data: "
1898 "ccw_device_start rc = %i\n", rc);
1899 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1900 spin_lock_irqsave(&card->lock, flags);
1901 list_del_init(&reply->list);
1902 qeth_put_reply(reply);
1903 spin_unlock_irqrestore(&card->lock, flags);
1904 qeth_release_buffer(iob->channel, iob);
1905 atomic_set(&card->write.irq_pending, 0);
1906 wake_up(&card->wait_q);
1910 wait_event(reply->wait_q, reply->received);
1911 del_timer_sync(&timer);
1913 qeth_put_reply(reply);
1918 qeth_osn_send_control_data(struct qeth_card *card, int len,
1919 struct qeth_cmd_buffer *iob)
1921 unsigned long flags;
1924 QETH_DBF_TEXT(trace, 5, "osndctrd");
1926 wait_event(card->wait_q,
1927 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1928 qeth_prepare_control_data(card, len, iob);
1929 QETH_DBF_TEXT(trace, 6, "osnoirqp");
1930 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1931 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1932 (addr_t) iob, 0, 0);
1933 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1935 PRINT_WARN("qeth_osn_send_control_data: "
1936 "ccw_device_start rc = %i\n", rc);
1937 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1938 qeth_release_buffer(iob->channel, iob);
1939 atomic_set(&card->write.irq_pending, 0);
1940 wake_up(&card->wait_q);
1946 qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1949 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1950 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1951 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1952 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1956 qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1961 QETH_DBF_TEXT(trace,4,"osndipa");
1963 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1964 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1966 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1967 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1968 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1969 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1970 return qeth_osn_send_control_data(card, s1, iob);
1974 qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1976 (struct qeth_card *,struct qeth_reply*, unsigned long),
1982 QETH_DBF_TEXT(trace,4,"sendipa");
1984 if (card->options.layer2)
1985 if (card->info.type == QETH_CARD_TYPE_OSN)
1986 prot_type = QETH_PROT_OSN2;
1988 prot_type = QETH_PROT_LAYER2;
1990 prot_type = QETH_PROT_TCPIP;
1991 qeth_prepare_ipa_cmd(card,iob,prot_type);
1992 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
1993 reply_cb, reply_param);
1999 qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2002 struct qeth_cmd_buffer *iob;
2004 QETH_DBF_TEXT(setup, 2, "cmenblcb");
2006 iob = (struct qeth_cmd_buffer *) data;
2007 memcpy(&card->token.cm_filter_r,
2008 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2009 QETH_MPC_TOKEN_LENGTH);
2010 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2015 qeth_cm_enable(struct qeth_card *card)
2018 struct qeth_cmd_buffer *iob;
2020 QETH_DBF_TEXT(setup,2,"cmenable");
2022 iob = qeth_wait_for_buffer(&card->write);
2023 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2024 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2025 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2026 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2027 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2029 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2030 qeth_cm_enable_cb, NULL);
2035 qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2039 struct qeth_cmd_buffer *iob;
2041 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
2043 iob = (struct qeth_cmd_buffer *) data;
2044 memcpy(&card->token.cm_connection_r,
2045 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2046 QETH_MPC_TOKEN_LENGTH);
2047 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2052 qeth_cm_setup(struct qeth_card *card)
2055 struct qeth_cmd_buffer *iob;
2057 QETH_DBF_TEXT(setup,2,"cmsetup");
2059 iob = qeth_wait_for_buffer(&card->write);
2060 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2061 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2062 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2063 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2064 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2065 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2066 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2067 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2068 qeth_cm_setup_cb, NULL);
2074 qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2078 __u16 mtu, framesize;
2081 struct qeth_cmd_buffer *iob;
2083 QETH_DBF_TEXT(setup, 2, "ulpenacb");
2085 iob = (struct qeth_cmd_buffer *) data;
2086 memcpy(&card->token.ulp_filter_r,
2087 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2088 QETH_MPC_TOKEN_LENGTH);
2089 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
2090 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2091 mtu = qeth_get_mtu_outof_framesize(framesize);
2094 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2097 card->info.max_mtu = mtu;
2098 card->info.initial_mtu = mtu;
2099 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2101 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2102 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
2103 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2106 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2107 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2109 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2110 card->info.link_type = link_type;
2112 card->info.link_type = 0;
2113 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2118 qeth_ulp_enable(struct qeth_card *card)
2122 struct qeth_cmd_buffer *iob;
2124 /*FIXME: trace view callbacks*/
2125 QETH_DBF_TEXT(setup,2,"ulpenabl");
2127 iob = qeth_wait_for_buffer(&card->write);
2128 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2130 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2131 (__u8) card->info.portno;
2132 if (card->options.layer2)
2133 if (card->info.type == QETH_CARD_TYPE_OSN)
2134 prot_type = QETH_PROT_OSN2;
2136 prot_type = QETH_PROT_LAYER2;
2138 prot_type = QETH_PROT_TCPIP;
2140 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2141 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2142 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2143 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2144 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2145 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2146 card->info.portname, 9);
2147 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2148 qeth_ulp_enable_cb, NULL);
2154 __raw_devno_from_bus_id(char *id)
2156 id += (strlen(id) - 4);
2157 return (__u16) simple_strtoul(id, &id, 16);
2161 qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2164 struct qeth_cmd_buffer *iob;
2166 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2168 iob = (struct qeth_cmd_buffer *) data;
2169 memcpy(&card->token.ulp_connection_r,
2170 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2171 QETH_MPC_TOKEN_LENGTH);
2172 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2177 qeth_ulp_setup(struct qeth_card *card)
2181 struct qeth_cmd_buffer *iob;
2183 QETH_DBF_TEXT(setup,2,"ulpsetup");
2185 iob = qeth_wait_for_buffer(&card->write);
2186 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2188 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2189 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2190 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2191 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2192 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2193 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2195 temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card));
2196 memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2);
2197 temp = (card->info.cula << 8) + card->info.unit_addr2;
2198 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2199 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2200 qeth_ulp_setup_cb, NULL);
2205 qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2206 unsigned int siga_error, const char *dbftext)
2208 if (qdio_error || siga_error) {
2209 QETH_DBF_TEXT(trace, 2, dbftext);
2210 QETH_DBF_TEXT(qerr, 2, dbftext);
2211 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
2212 buf->element[15].flags & 0xff);
2213 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
2214 buf->element[14].flags & 0xff);
2215 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2216 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
2222 static inline struct sk_buff *
2223 qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
2225 struct sk_buff* skb;
2229 if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2230 add_len = sizeof(struct qeth_hdr);
2231 #ifdef CONFIG_QETH_VLAN
2233 add_len = VLAN_HLEN;
2235 skb = dev_alloc_skb(length + add_len);
2237 skb_reserve(skb, add_len);
2241 static inline struct sk_buff *
2242 qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2243 struct qdio_buffer_element **__element, int *__offset,
2244 struct qeth_hdr **hdr)
2246 struct qdio_buffer_element *element = *__element;
2247 int offset = *__offset;
2248 struct sk_buff *skb = NULL;
2253 QETH_DBF_TEXT(trace,6,"nextskb");
2254 /* qeth_hdr must not cross element boundaries */
2255 if (element->length < offset + sizeof(struct qeth_hdr)){
2256 if (qeth_is_last_sbale(element))
2260 if (element->length < sizeof(struct qeth_hdr))
2263 *hdr = element->addr + offset;
2265 offset += sizeof(struct qeth_hdr);
2266 if (card->options.layer2)
2267 if (card->info.type == QETH_CARD_TYPE_OSN)
2268 skb_len = (*hdr)->hdr.osn.pdu_length;
2270 skb_len = (*hdr)->hdr.l2.pkt_length;
2272 skb_len = (*hdr)->hdr.l3.length;
2276 if (card->options.fake_ll){
2277 if(card->dev->type == ARPHRD_IEEE802_TR){
2278 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR, *hdr)))
2280 skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2282 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH, *hdr)))
2284 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2286 } else if (!(skb = qeth_get_skb(skb_len, *hdr)))
2288 data_ptr = element->addr + offset;
2290 data_len = min(skb_len, (int)(element->length - offset));
2292 memcpy(skb_put(skb, data_len), data_ptr, data_len);
2293 skb_len -= data_len;
2295 if (qeth_is_last_sbale(element)){
2296 QETH_DBF_TEXT(trace,4,"unexeob");
2297 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2298 QETH_DBF_TEXT(qerr,2,"unexeob");
2299 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2300 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2301 dev_kfree_skb_any(skb);
2302 card->stats.rx_errors++;
2307 data_ptr = element->addr;
2312 *__element = element;
2316 if (net_ratelimit()){
2317 PRINT_WARN("No memory for packet received on %s.\n",
2318 QETH_CARD_IFNAME(card));
2319 QETH_DBF_TEXT(trace,2,"noskbmem");
2320 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2322 card->stats.rx_dropped++;
2326 static inline __be16
2327 qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2329 struct qeth_card *card;
2332 QETH_DBF_TEXT(trace,6,"typtrans");
2334 card = (struct qeth_card *)dev->priv;
2336 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2337 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2338 return tr_type_trans(skb,dev);
2339 #endif /* CONFIG_TR */
2340 skb->mac.raw = skb->data;
2341 skb_pull(skb, ETH_HLEN );
2344 if (*eth->h_dest & 1) {
2345 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2346 skb->pkt_type = PACKET_BROADCAST;
2348 skb->pkt_type = PACKET_MULTICAST;
2349 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2350 skb->pkt_type = PACKET_OTHERHOST;
2352 if (ntohs(eth->h_proto) >= 1536)
2353 return eth->h_proto;
2354 if (*(unsigned short *) (skb->data) == 0xFFFF)
2355 return htons(ETH_P_802_3);
2356 return htons(ETH_P_802_2);
2360 qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2361 struct qeth_hdr *hdr)
2363 struct trh_hdr *fake_hdr;
2364 struct trllc *fake_llc;
2365 struct iphdr *ip_hdr;
2367 QETH_DBF_TEXT(trace,5,"skbfktr");
2368 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_TR;
2369 /* this is a fake ethernet header */
2370 fake_hdr = (struct trh_hdr *) skb->mac.raw;
2372 /* the destination MAC address */
2373 switch (skb->pkt_type){
2374 case PACKET_MULTICAST:
2375 switch (skb->protocol){
2376 #ifdef CONFIG_QETH_IPV6
2377 case __constant_htons(ETH_P_IPV6):
2378 ndisc_mc_map((struct in6_addr *)
2379 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2380 fake_hdr->daddr, card->dev, 0);
2382 #endif /* CONFIG_QETH_IPV6 */
2383 case __constant_htons(ETH_P_IP):
2384 ip_hdr = (struct iphdr *)skb->data;
2385 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2388 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2391 case PACKET_BROADCAST:
2392 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2395 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2397 /* the source MAC address */
2398 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2399 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2401 memset(fake_hdr->saddr, 0, TR_ALEN);
2403 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2404 fake_llc->dsap = EXTENDED_SAP;
2405 fake_llc->ssap = EXTENDED_SAP;
2406 fake_llc->llc = UI_CMD;
2407 fake_llc->protid[0] = 0;
2408 fake_llc->protid[1] = 0;
2409 fake_llc->protid[2] = 0;
2410 fake_llc->ethertype = ETH_P_IP;
2414 qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
2415 struct qeth_hdr *hdr)
2417 struct ethhdr *fake_hdr;
2418 struct iphdr *ip_hdr;
2420 QETH_DBF_TEXT(trace,5,"skbfketh");
2421 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_ETH;
2422 /* this is a fake ethernet header */
2423 fake_hdr = (struct ethhdr *) skb->mac.raw;
2425 /* the destination MAC address */
2426 switch (skb->pkt_type){
2427 case PACKET_MULTICAST:
2428 switch (skb->protocol){
2429 #ifdef CONFIG_QETH_IPV6
2430 case __constant_htons(ETH_P_IPV6):
2431 ndisc_mc_map((struct in6_addr *)
2432 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2433 fake_hdr->h_dest, card->dev, 0);
2435 #endif /* CONFIG_QETH_IPV6 */
2436 case __constant_htons(ETH_P_IP):
2437 ip_hdr = (struct iphdr *)skb->data;
2438 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
2441 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2444 case PACKET_BROADCAST:
2445 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2448 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2450 /* the source MAC address */
2451 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2452 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2454 memset(fake_hdr->h_source, 0, ETH_ALEN);
2456 fake_hdr->h_proto = skb->protocol;
2460 qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2461 struct qeth_hdr *hdr)
2463 if (card->dev->type == ARPHRD_IEEE802_TR)
2464 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2466 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2470 qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2471 struct qeth_hdr *hdr)
2473 unsigned short vlan_id = 0;
2474 #ifdef CONFIG_QETH_VLAN
2475 struct vlan_hdr *vhdr;
2478 skb->pkt_type = PACKET_HOST;
2479 skb->protocol = qeth_type_trans(skb, skb->dev);
2480 if (card->options.checksum_type == NO_CHECKSUMMING)
2481 skb->ip_summed = CHECKSUM_UNNECESSARY;
2483 skb->ip_summed = CHECKSUM_NONE;
2484 #ifdef CONFIG_QETH_VLAN
2485 if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) {
2486 vhdr = (struct vlan_hdr *) skb->data;
2488 __constant_htons(vhdr->h_vlan_encapsulated_proto);
2489 vlan_id = hdr->hdr.l2.vlan_id;
2490 skb_pull(skb, VLAN_HLEN);
2493 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
2498 qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2499 struct qeth_hdr *hdr)
2501 unsigned short vlan_id = 0;
2502 #ifdef CONFIG_QETH_IPV6
2503 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2504 skb->pkt_type = PACKET_HOST;
2505 skb->protocol = qeth_type_trans(skb, card->dev);
2508 #endif /* CONFIG_QETH_IPV6 */
2509 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2511 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2512 case QETH_CAST_UNICAST:
2513 skb->pkt_type = PACKET_HOST;
2515 case QETH_CAST_MULTICAST:
2516 skb->pkt_type = PACKET_MULTICAST;
2517 card->stats.multicast++;
2519 case QETH_CAST_BROADCAST:
2520 skb->pkt_type = PACKET_BROADCAST;
2521 card->stats.multicast++;
2523 case QETH_CAST_ANYCAST:
2524 case QETH_CAST_NOCAST:
2526 skb->pkt_type = PACKET_HOST;
2529 if (hdr->hdr.l3.ext_flags &
2530 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2531 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2532 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2535 if (card->options.fake_ll)
2536 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2538 skb->mac.raw = skb->data;
2539 skb->ip_summed = card->options.checksum_type;
2540 if (card->options.checksum_type == HW_CHECKSUMMING){
2541 if ( (hdr->hdr.l3.ext_flags &
2542 (QETH_HDR_EXT_CSUM_HDR_REQ |
2543 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2544 (QETH_HDR_EXT_CSUM_HDR_REQ |
2545 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2546 skb->ip_summed = CHECKSUM_UNNECESSARY;
2548 skb->ip_summed = SW_CHECKSUMMING;
2554 qeth_process_inbound_buffer(struct qeth_card *card,
2555 struct qeth_qdio_buffer *buf, int index)
2557 struct qdio_buffer_element *element;
2558 struct sk_buff *skb;
2559 struct qeth_hdr *hdr;
2565 /* get first element of current buffer */
2566 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2568 if (card->options.performance_stats)
2569 card->perf_stats.bufs_rec++;
2570 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2572 skb->dev = card->dev;
2573 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2574 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr);
2575 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2576 vlan_tag = qeth_rebuild_skb(card, skb, hdr);
2577 else { /*in case of OSN*/
2578 skb_push(skb, sizeof(struct qeth_hdr));
2579 memcpy(skb->data, hdr, sizeof(struct qeth_hdr));
2581 /* is device UP ? */
2582 if (!(card->dev->flags & IFF_UP)){
2583 dev_kfree_skb_any(skb);
2586 if (card->info.type == QETH_CARD_TYPE_OSN)
2587 rxrc = card->osn_info.data_cb(skb);
2589 #ifdef CONFIG_QETH_VLAN
2592 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2594 dev_kfree_skb_any(skb);
2599 rxrc = netif_rx(skb);
2600 card->dev->last_rx = jiffies;
2601 card->stats.rx_packets++;
2602 card->stats.rx_bytes += skb->len;
2606 static inline struct qeth_buffer_pool_entry *
2607 qeth_get_buffer_pool_entry(struct qeth_card *card)
2609 struct qeth_buffer_pool_entry *entry;
2611 QETH_DBF_TEXT(trace, 6, "gtbfplen");
2612 if (!list_empty(&card->qdio.in_buf_pool.entry_list)) {
2613 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2614 struct qeth_buffer_pool_entry, list);
2615 list_del_init(&entry->list);
2622 qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2624 struct qeth_buffer_pool_entry *pool_entry;
2627 pool_entry = qeth_get_buffer_pool_entry(card);
2629 * since the buffer is accessed only from the input_tasklet
2630 * there shouldn't be a need to synchronize; also, since we use
2631 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2634 BUG_ON(!pool_entry);
2636 buf->pool_entry = pool_entry;
2637 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2638 buf->buffer->element[i].length = PAGE_SIZE;
2639 buf->buffer->element[i].addr = pool_entry->elements[i];
2640 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2641 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2643 buf->buffer->element[i].flags = 0;
2645 buf->state = QETH_QDIO_BUF_EMPTY;
2649 qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2650 struct qeth_qdio_out_buffer *buf)
2653 struct sk_buff *skb;
2655 /* is PCI flag set on buffer? */
2656 if (buf->buffer->element[0].flags & 0x40)
2657 atomic_dec(&queue->set_pci_flags_count);
2659 while ((skb = skb_dequeue(&buf->skb_list))){
2660 atomic_dec(&skb->users);
2661 dev_kfree_skb_any(skb);
2663 qeth_eddp_buf_release_contexts(buf);
2664 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2665 buf->buffer->element[i].length = 0;
2666 buf->buffer->element[i].addr = NULL;
2667 buf->buffer->element[i].flags = 0;
2669 buf->next_element_to_fill = 0;
2670 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2674 qeth_queue_input_buffer(struct qeth_card *card, int index)
2676 struct qeth_qdio_q *queue = card->qdio.in_q;
2681 QETH_DBF_TEXT(trace,6,"queinbuf");
2682 count = (index < queue->next_buf_to_init)?
2683 card->qdio.in_buf_pool.buf_count -
2684 (queue->next_buf_to_init - index) :
2685 card->qdio.in_buf_pool.buf_count -
2686 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2687 /* only requeue at a certain threshold to avoid SIGAs */
2688 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2689 for (i = queue->next_buf_to_init;
2690 i < queue->next_buf_to_init + count; ++i)
2691 qeth_init_input_buffer(card,
2692 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]);
2694 * according to old code it should be avoided to requeue all
2695 * 128 buffers in order to benefit from PCI avoidance.
2696 * this function keeps at least one buffer (the buffer at
2697 * 'index') un-requeued -> this buffer is the first buffer that
2698 * will be requeued the next time
2700 if (card->options.performance_stats) {
2701 card->perf_stats.inbound_do_qdio_cnt++;
2702 card->perf_stats.inbound_do_qdio_start_time =
2705 rc = do_QDIO(CARD_DDEV(card),
2706 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2707 0, queue->next_buf_to_init, count, NULL);
2708 if (card->options.performance_stats)
2709 card->perf_stats.inbound_do_qdio_time +=
2711 card->perf_stats.inbound_do_qdio_start_time;
2713 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2714 "return %i (device %s).\n",
2715 rc, CARD_DDEV_ID(card));
2716 QETH_DBF_TEXT(trace,2,"qinberr");
2717 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2719 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2720 QDIO_MAX_BUFFERS_PER_Q;
2725 qeth_put_buffer_pool_entry(struct qeth_card *card,
2726 struct qeth_buffer_pool_entry *entry)
2728 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2729 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2733 qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2734 unsigned int qdio_err, unsigned int siga_err,
2735 unsigned int queue, int first_element, int count,
2736 unsigned long card_ptr)
2738 struct net_device *net_dev;
2739 struct qeth_card *card;
2740 struct qeth_qdio_buffer *buffer;
2744 QETH_DBF_TEXT(trace, 6, "qdinput");
2745 card = (struct qeth_card *) card_ptr;
2746 net_dev = card->dev;
2747 if (card->options.performance_stats) {
2748 card->perf_stats.inbound_cnt++;
2749 card->perf_stats.inbound_start_time = qeth_get_micros();
2751 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2752 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2753 QETH_DBF_TEXT(trace, 1,"qdinchk");
2754 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2755 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2756 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2757 qeth_schedule_recovery(card);
2761 for (i = first_element; i < (first_element + count); ++i) {
2762 index = i % QDIO_MAX_BUFFERS_PER_Q;
2763 buffer = &card->qdio.in_q->bufs[index];
2764 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
2765 qeth_check_qdio_errors(buffer->buffer,
2766 qdio_err, siga_err,"qinerr")))
2767 qeth_process_inbound_buffer(card, buffer, index);
2768 /* clear buffer and give back to hardware */
2769 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2770 qeth_queue_input_buffer(card, index);
2772 if (card->options.performance_stats)
2773 card->perf_stats.inbound_time += qeth_get_micros() -
2774 card->perf_stats.inbound_start_time;
2778 qeth_handle_send_error(struct qeth_card *card,
2779 struct qeth_qdio_out_buffer *buffer,
2780 unsigned int qdio_err, unsigned int siga_err)
2782 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2783 int cc = siga_err & 3;
2785 QETH_DBF_TEXT(trace, 6, "hdsnderr");
2786 qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr");
2790 QETH_DBF_TEXT(trace, 1,"lnkfail");
2791 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2792 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2793 (u16)qdio_err, (u8)sbalf15);
2794 return QETH_SEND_ERROR_LINK_FAILURE;
2796 return QETH_SEND_ERROR_NONE;
2798 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2799 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2800 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2801 return QETH_SEND_ERROR_KICK_IT;
2803 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2804 return QETH_SEND_ERROR_RETRY;
2805 return QETH_SEND_ERROR_LINK_FAILURE;
2806 /* look at qdio_error and sbalf 15 */
2808 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2809 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2810 return QETH_SEND_ERROR_LINK_FAILURE;
2813 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2814 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2815 return QETH_SEND_ERROR_KICK_IT;
2820 qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2821 int index, int count)
2823 struct qeth_qdio_out_buffer *buf;
2827 QETH_DBF_TEXT(trace, 6, "flushbuf");
2829 for (i = index; i < index + count; ++i) {
2830 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2831 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2832 SBAL_FLAGS_LAST_ENTRY;
2834 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2837 if (!queue->do_pack){
2838 if ((atomic_read(&queue->used_buffers) >=
2839 (QETH_HIGH_WATERMARK_PACK -
2840 QETH_WATERMARK_PACK_FUZZ)) &&
2841 !atomic_read(&queue->set_pci_flags_count)){
2842 /* it's likely that we'll go to packing
2844 atomic_inc(&queue->set_pci_flags_count);
2845 buf->buffer->element[0].flags |= 0x40;
2848 if (!atomic_read(&queue->set_pci_flags_count)){
2850 * there's no outstanding PCI any more, so we
2851 * have to request a PCI to be sure the the PCI
2852 * will wake at some time in the future then we
2853 * can flush packed buffers that might still be
2854 * hanging around, which can happen if no
2855 * further send was requested by the stack
2857 atomic_inc(&queue->set_pci_flags_count);
2858 buf->buffer->element[0].flags |= 0x40;
2863 queue->card->dev->trans_start = jiffies;
2864 if (queue->card->options.performance_stats) {
2865 queue->card->perf_stats.outbound_do_qdio_cnt++;
2866 queue->card->perf_stats.outbound_do_qdio_start_time =
2870 rc = do_QDIO(CARD_DDEV(queue->card),
2871 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT,
2872 queue->queue_no, index, count, NULL);
2874 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT,
2875 queue->queue_no, index, count, NULL);
2876 if (queue->card->options.performance_stats)
2877 queue->card->perf_stats.outbound_do_qdio_time +=
2879 queue->card->perf_stats.outbound_do_qdio_start_time;
2881 QETH_DBF_TEXT(trace, 2, "flushbuf");
2882 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
2883 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
2884 queue->card->stats.tx_errors += count;
2885 /* this must not happen under normal circumstances. if it
2886 * happens something is really wrong -> recover */
2887 qeth_schedule_recovery(queue->card);
2890 atomic_add(count, &queue->used_buffers);
2891 if (queue->card->options.performance_stats)
2892 queue->card->perf_stats.bufs_sent += count;
2896 * Switched to packing state if the number of used buffers on a queue
2897 * reaches a certain limit.
2900 qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2902 if (!queue->do_pack) {
2903 if (atomic_read(&queue->used_buffers)
2904 >= QETH_HIGH_WATERMARK_PACK){
2905 /* switch non-PACKING -> PACKING */
2906 QETH_DBF_TEXT(trace, 6, "np->pack");
2907 if (queue->card->options.performance_stats)
2908 queue->card->perf_stats.sc_dp_p++;
2915 * Switches from packing to non-packing mode. If there is a packing
2916 * buffer on the queue this buffer will be prepared to be flushed.
2917 * In that case 1 is returned to inform the caller. If no buffer
2918 * has to be flushed, zero is returned.
2921 qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2923 struct qeth_qdio_out_buffer *buffer;
2924 int flush_count = 0;
2926 if (queue->do_pack) {
2927 if (atomic_read(&queue->used_buffers)
2928 <= QETH_LOW_WATERMARK_PACK) {
2929 /* switch PACKING -> non-PACKING */
2930 QETH_DBF_TEXT(trace, 6, "pack->np");
2931 if (queue->card->options.performance_stats)
2932 queue->card->perf_stats.sc_p_dp++;
2934 /* flush packing buffers */
2935 buffer = &queue->bufs[queue->next_buf_to_fill];
2936 if ((atomic_read(&buffer->state) ==
2937 QETH_QDIO_BUF_EMPTY) &&
2938 (buffer->next_element_to_fill > 0)) {
2939 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
2941 queue->next_buf_to_fill =
2942 (queue->next_buf_to_fill + 1) %
2943 QDIO_MAX_BUFFERS_PER_Q;
2951 * Called to flush a packing buffer if no more pci flags are on the queue.
2952 * Checks if there is a packing buffer and prepares it to be flushed.
2953 * In that case returns 1, otherwise zero.
2956 qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2958 struct qeth_qdio_out_buffer *buffer;
2960 buffer = &queue->bufs[queue->next_buf_to_fill];
2961 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2962 (buffer->next_element_to_fill > 0)){
2963 /* it's a packing buffer */
2964 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2965 queue->next_buf_to_fill =
2966 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2973 qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2977 int q_was_packing = 0;
2980 * check if weed have to switch to non-packing mode or if
2981 * we have to get a pci flag out on the queue
2983 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2984 !atomic_read(&queue->set_pci_flags_count)){
2985 if (atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2986 QETH_OUT_Q_UNLOCKED) {
2988 * If we get in here, there was no action in
2989 * do_send_packet. So, we check if there is a
2990 * packing buffer to be flushed here.
2992 netif_stop_queue(queue->card->dev);
2993 index = queue->next_buf_to_fill;
2994 q_was_packing = queue->do_pack;
2995 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
2997 !atomic_read(&queue->set_pci_flags_count))
2999 qeth_flush_buffers_on_no_pci(queue);
3000 if (queue->card->options.performance_stats &&
3002 queue->card->perf_stats.bufs_sent_pack +=
3005 qeth_flush_buffers(queue, 1, index, flush_cnt);
3006 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3012 qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3013 unsigned int qdio_error, unsigned int siga_error,
3014 unsigned int __queue, int first_element, int count,
3015 unsigned long card_ptr)
3017 struct qeth_card *card = (struct qeth_card *) card_ptr;
3018 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3019 struct qeth_qdio_out_buffer *buffer;
3022 QETH_DBF_TEXT(trace, 6, "qdouhdl");
3023 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
3024 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
3025 QETH_DBF_TEXT(trace, 2, "achkcond");
3026 QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
3027 QETH_DBF_TEXT_(trace, 2, "%08x", status);
3028 netif_stop_queue(card->dev);
3029 qeth_schedule_recovery(card);
3033 if (card->options.performance_stats) {
3034 card->perf_stats.outbound_handler_cnt++;
3035 card->perf_stats.outbound_handler_start_time =
3038 for(i = first_element; i < (first_element + count); ++i){
3039 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
3040 /*we only handle the KICK_IT error by doing a recovery */
3041 if (qeth_handle_send_error(card, buffer,
3042 qdio_error, siga_error)
3043 == QETH_SEND_ERROR_KICK_IT){
3044 netif_stop_queue(card->dev);
3045 qeth_schedule_recovery(card);
3048 qeth_clear_output_buffer(queue, buffer);
3050 atomic_sub(count, &queue->used_buffers);
3051 /* check if we need to do something on this outbound queue */
3052 if (card->info.type != QETH_CARD_TYPE_IQD)
3053 qeth_check_outbound_queue(queue);
3055 netif_wake_queue(queue->card->dev);
3056 if (card->options.performance_stats)
3057 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3058 card->perf_stats.outbound_handler_start_time;
3062 qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
3065 param_field[0] = _ascebc['P'];
3066 param_field[1] = _ascebc['C'];
3067 param_field[2] = _ascebc['I'];
3068 param_field[3] = _ascebc['T'];
3069 *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card);
3070 *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card);
3071 *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card);
3075 qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
3077 param_field[16] = _ascebc['B'];
3078 param_field[17] = _ascebc['L'];
3079 param_field[18] = _ascebc['K'];
3080 param_field[19] = _ascebc['T'];
3081 *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total;
3082 *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet;
3083 *((unsigned int *) (¶m_field[28])) = card->info.blkt.inter_packet_jumbo;
3087 qeth_initialize_working_pool_list(struct qeth_card *card)
3089 struct qeth_buffer_pool_entry *entry;
3091 QETH_DBF_TEXT(trace,5,"inwrklst");
3093 list_for_each_entry(entry,
3094 &card->qdio.init_pool.entry_list, init_list) {
3095 qeth_put_buffer_pool_entry(card,entry);
3100 qeth_clear_working_pool_list(struct qeth_card *card)
3102 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3104 QETH_DBF_TEXT(trace,5,"clwrklst");
3105 list_for_each_entry_safe(pool_entry, tmp,
3106 &card->qdio.in_buf_pool.entry_list, list){
3107 list_del(&pool_entry->list);
3112 qeth_free_buffer_pool(struct qeth_card *card)
3114 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3116 QETH_DBF_TEXT(trace,5,"freepool");
3117 list_for_each_entry_safe(pool_entry, tmp,
3118 &card->qdio.init_pool.entry_list, init_list){
3119 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3120 free_page((unsigned long)pool_entry->elements[i]);
3121 list_del(&pool_entry->init_list);
3127 qeth_alloc_buffer_pool(struct qeth_card *card)
3129 struct qeth_buffer_pool_entry *pool_entry;
3133 QETH_DBF_TEXT(trace,5,"alocpool");
3134 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3135 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3137 qeth_free_buffer_pool(card);
3140 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
3141 ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
3144 free_page((unsigned long)
3145 pool_entry->elements[--j]);
3147 qeth_free_buffer_pool(card);
3150 pool_entry->elements[j] = ptr;
3152 list_add(&pool_entry->init_list,
3153 &card->qdio.init_pool.entry_list);
3159 qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3161 QETH_DBF_TEXT(trace, 2, "realcbp");
3163 if ((card->state != CARD_STATE_DOWN) &&
3164 (card->state != CARD_STATE_RECOVER))
3167 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3168 qeth_clear_working_pool_list(card);
3169 qeth_free_buffer_pool(card);
3170 card->qdio.in_buf_pool.buf_count = bufcnt;
3171 card->qdio.init_pool.buf_count = bufcnt;
3172 return qeth_alloc_buffer_pool(card);
3176 qeth_alloc_qdio_buffers(struct qeth_card *card)
3180 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3182 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
3183 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
3186 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3187 GFP_KERNEL|GFP_DMA);
3188 if (!card->qdio.in_q)
3190 QETH_DBF_TEXT(setup, 2, "inq");
3191 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3192 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3193 /* give inbound qeth_qdio_buffers their qdio_buffers */
3194 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3195 card->qdio.in_q->bufs[i].buffer =
3196 &card->qdio.in_q->qdio_bufs[i];
3197 /* inbound buffer pool */
3198 if (qeth_alloc_buffer_pool(card))
3202 kmalloc(card->qdio.no_out_queues *
3203 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3204 if (!card->qdio.out_qs)
3206 for (i = 0; i < card->qdio.no_out_queues; ++i) {
3207 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3208 GFP_KERNEL|GFP_DMA);
3209 if (!card->qdio.out_qs[i])
3211 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3212 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3213 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3214 card->qdio.out_qs[i]->queue_no = i;
3215 /* give outbound qeth_qdio_buffers their qdio_buffers */
3216 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3217 card->qdio.out_qs[i]->bufs[j].buffer =
3218 &card->qdio.out_qs[i]->qdio_bufs[j];
3219 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3222 &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
3223 &qdio_out_skb_queue_key);
3224 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3231 kfree(card->qdio.out_qs[--i]);
3232 kfree(card->qdio.out_qs);
3234 qeth_free_buffer_pool(card);
3236 kfree(card->qdio.in_q);
3238 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3243 qeth_free_qdio_buffers(struct qeth_card *card)
3247 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3248 if (atomic_swap(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
3249 QETH_QDIO_UNINITIALIZED)
3251 kfree(card->qdio.in_q);
3252 /* inbound buffer pool */
3253 qeth_free_buffer_pool(card);
3254 /* free outbound qdio_qs */
3255 for (i = 0; i < card->qdio.no_out_queues; ++i){
3256 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3257 qeth_clear_output_buffer(card->qdio.out_qs[i],
3258 &card->qdio.out_qs[i]->bufs[j]);
3259 kfree(card->qdio.out_qs[i]);
3261 kfree(card->qdio.out_qs);
3265 qeth_clear_qdio_buffers(struct qeth_card *card)
3269 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3270 /* clear outbound buffers to free skbs */
3271 for (i = 0; i < card->qdio.no_out_queues; ++i)
3272 if (card->qdio.out_qs[i]){
3273 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3274 qeth_clear_output_buffer(card->qdio.out_qs[i],
3275 &card->qdio.out_qs[i]->bufs[j]);
3280 qeth_init_qdio_info(struct qeth_card *card)
3282 QETH_DBF_TEXT(setup, 4, "intqdinf");
3283 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3285 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3286 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3287 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3288 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3289 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3293 qeth_init_qdio_queues(struct qeth_card *card)
3298 QETH_DBF_TEXT(setup, 2, "initqdqs");
3301 memset(card->qdio.in_q->qdio_bufs, 0,
3302 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3303 qeth_initialize_working_pool_list(card);
3304 /*give only as many buffers to hardware as we have buffer pool entries*/
3305 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3306 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3307 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3308 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3309 card->qdio.in_buf_pool.buf_count - 1, NULL);
3311 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3314 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3316 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3319 /* outbound queue */
3320 for (i = 0; i < card->qdio.no_out_queues; ++i){
3321 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3322 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3323 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3324 qeth_clear_output_buffer(card->qdio.out_qs[i],
3325 &card->qdio.out_qs[i]->bufs[j]);
3327 card->qdio.out_qs[i]->card = card;
3328 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3329 card->qdio.out_qs[i]->do_pack = 0;
3330 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3331 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3332 atomic_set(&card->qdio.out_qs[i]->state,
3333 QETH_OUT_Q_UNLOCKED);
3339 qeth_qdio_establish(struct qeth_card *card)
3341 struct qdio_initialize init_data;
3342 char *qib_param_field;
3343 struct qdio_buffer **in_sbal_ptrs;
3344 struct qdio_buffer **out_sbal_ptrs;
3348 QETH_DBF_TEXT(setup, 2, "qdioest");
3350 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3352 if (!qib_param_field)
3355 qeth_create_qib_param_field(card, qib_param_field);
3356 qeth_create_qib_param_field_blkt(card, qib_param_field);
3358 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3360 if (!in_sbal_ptrs) {
3361 kfree(qib_param_field);
3364 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3365 in_sbal_ptrs[i] = (struct qdio_buffer *)
3366 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3369 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3370 sizeof(void *), GFP_KERNEL);
3371 if (!out_sbal_ptrs) {
3372 kfree(in_sbal_ptrs);
3373 kfree(qib_param_field);
3376 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3377 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3378 out_sbal_ptrs[k] = (struct qdio_buffer *)
3379 virt_to_phys(card->qdio.out_qs[i]->
3383 memset(&init_data, 0, sizeof(struct qdio_initialize));
3384 init_data.cdev = CARD_DDEV(card);
3385 init_data.q_format = qeth_get_qdio_q_format(card);
3386 init_data.qib_param_field_format = 0;
3387 init_data.qib_param_field = qib_param_field;
3388 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3389 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3390 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3391 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3392 init_data.no_input_qs = 1;
3393 init_data.no_output_qs = card->qdio.no_out_queues;
3394 init_data.input_handler = (qdio_handler_t *)
3395 qeth_qdio_input_handler;
3396 init_data.output_handler = (qdio_handler_t *)
3397 qeth_qdio_output_handler;
3398 init_data.int_parm = (unsigned long) card;
3399 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3400 QDIO_OUTBOUND_0COPY_SBALS |
3401 QDIO_USE_OUTBOUND_PCIS;
3402 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3403 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3405 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3406 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED)
3407 if ((rc = qdio_initialize(&init_data)))
3408 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3410 kfree(out_sbal_ptrs);
3411 kfree(in_sbal_ptrs);
3412 kfree(qib_param_field);
3417 qeth_qdio_activate(struct qeth_card *card)
3419 QETH_DBF_TEXT(setup,3,"qdioact");
3420 return qdio_activate(CARD_DDEV(card), 0);
3424 qeth_clear_channel(struct qeth_channel *channel)
3426 unsigned long flags;
3427 struct qeth_card *card;
3430 QETH_DBF_TEXT(trace,3,"clearch");
3431 card = CARD_FROM_CDEV(channel->ccwdev);
3432 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3433 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3434 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3438 rc = wait_event_interruptible_timeout(card->wait_q,
3439 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3440 if (rc == -ERESTARTSYS)
3442 if (channel->state != CH_STATE_STOPPED)
3444 channel->state = CH_STATE_DOWN;
3449 qeth_halt_channel(struct qeth_channel *channel)
3451 unsigned long flags;
3452 struct qeth_card *card;
3455 QETH_DBF_TEXT(trace,3,"haltch");
3456 card = CARD_FROM_CDEV(channel->ccwdev);
3457 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3458 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3459 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3463 rc = wait_event_interruptible_timeout(card->wait_q,
3464 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3465 if (rc == -ERESTARTSYS)
3467 if (channel->state != CH_STATE_HALTED)
3473 qeth_halt_channels(struct qeth_card *card)
3475 int rc1 = 0, rc2=0, rc3 = 0;
3477 QETH_DBF_TEXT(trace,3,"haltchs");
3478 rc1 = qeth_halt_channel(&card->read);
3479 rc2 = qeth_halt_channel(&card->write);
3480 rc3 = qeth_halt_channel(&card->data);
3488 qeth_clear_channels(struct qeth_card *card)
3490 int rc1 = 0, rc2=0, rc3 = 0;
3492 QETH_DBF_TEXT(trace,3,"clearchs");
3493 rc1 = qeth_clear_channel(&card->read);
3494 rc2 = qeth_clear_channel(&card->write);
3495 rc3 = qeth_clear_channel(&card->data);
3504 qeth_clear_halt_card(struct qeth_card *card, int halt)
3508 QETH_DBF_TEXT(trace,3,"clhacrd");
3509 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3512 rc = qeth_halt_channels(card);
3515 return qeth_clear_channels(card);
3519 qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3523 QETH_DBF_TEXT(trace,3,"qdioclr");
3524 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
3525 QETH_QDIO_CLEANING)) {
3526 case QETH_QDIO_ESTABLISHED:
3527 if ((rc = qdio_cleanup(CARD_DDEV(card),
3528 (card->info.type == QETH_CARD_TYPE_IQD) ?
3529 QDIO_FLAG_CLEANUP_USING_HALT :
3530 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3531 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3532 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3534 case QETH_QDIO_CLEANING:
3539 if ((rc = qeth_clear_halt_card(card, use_halt)))
3540 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3541 card->state = CARD_STATE_DOWN;
3546 qeth_dm_act(struct qeth_card *card)
3549 struct qeth_cmd_buffer *iob;
3551 QETH_DBF_TEXT(setup,2,"dmact");
3553 iob = qeth_wait_for_buffer(&card->write);
3554 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3556 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3557 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3558 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3559 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3560 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3565 qeth_mpc_initialize(struct qeth_card *card)
3569 QETH_DBF_TEXT(setup,2,"mpcinit");
3571 if ((rc = qeth_issue_next_read(card))){
3572 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3575 if ((rc = qeth_cm_enable(card))){
3576 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3579 if ((rc = qeth_cm_setup(card))){
3580 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3583 if ((rc = qeth_ulp_enable(card))){
3584 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3587 if ((rc = qeth_ulp_setup(card))){
3588 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3591 if ((rc = qeth_alloc_qdio_buffers(card))){
3592 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3595 if ((rc = qeth_qdio_establish(card))){
3596 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3597 qeth_free_qdio_buffers(card);
3600 if ((rc = qeth_qdio_activate(card))){
3601 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3604 if ((rc = qeth_dm_act(card))){
3605 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3611 qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
3615 static struct net_device *
3616 qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3618 struct net_device *dev = NULL;
3621 case QETH_CARD_TYPE_OSAE:
3623 case QETH_LINK_TYPE_LANE_TR:
3624 case QETH_LINK_TYPE_HSTR:
3626 dev = alloc_trdev(0);
3627 #endif /* CONFIG_TR */
3630 dev = alloc_etherdev(0);
3633 case QETH_CARD_TYPE_IQD:
3634 dev = alloc_netdev(0, "hsi%d", ether_setup);
3636 case QETH_CARD_TYPE_OSN:
3637 dev = alloc_netdev(0, "osn%d", ether_setup);
3640 dev = alloc_etherdev(0);
3645 /*hard_header fake function; used in case fake_ll is set */
3647 qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3648 unsigned short type, void *daddr, void *saddr,
3651 if(dev->type == ARPHRD_IEEE802_TR){
3652 struct trh_hdr *hdr;
3653 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3654 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3655 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3656 return QETH_FAKE_LL_LEN_TR;
3660 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3661 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3662 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3663 if (type != ETH_P_802_3)
3664 hdr->h_proto = htons(type);
3666 hdr->h_proto = htons(len);
3667 return QETH_FAKE_LL_LEN_ETH;
3673 qeth_send_packet(struct qeth_card *, struct sk_buff *);
3676 qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3679 struct qeth_card *card;
3681 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3682 card = (struct qeth_card *)dev->priv;
3684 card->stats.tx_dropped++;
3685 card->stats.tx_errors++;
3686 /* return OK; otherwise ksoftirqd goes to 100% */
3687 return NETDEV_TX_OK;
3689 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3690 card->stats.tx_dropped++;
3691 card->stats.tx_errors++;
3692 card->stats.tx_carrier_errors++;
3693 dev_kfree_skb_any(skb);
3694 /* return OK; otherwise ksoftirqd goes to 100% */
3695 return NETDEV_TX_OK;
3697 if (card->options.performance_stats) {
3698 card->perf_stats.outbound_cnt++;
3699 card->perf_stats.outbound_start_time = qeth_get_micros();
3701 netif_stop_queue(dev);
3702 if ((rc = qeth_send_packet(card, skb))) {
3704 return NETDEV_TX_BUSY;
3706 card->stats.tx_errors++;
3707 card->stats.tx_dropped++;
3708 dev_kfree_skb_any(skb);
3709 /*set to OK; otherwise ksoftirqd goes to 100% */
3713 netif_wake_queue(dev);
3714 if (card->options.performance_stats)
3715 card->perf_stats.outbound_time += qeth_get_micros() -
3716 card->perf_stats.outbound_start_time;
3721 qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3724 #ifdef CONFIG_QETH_VLAN
3725 struct vlan_group *vg;
3728 if (!(vg = card->vlangrp))
3731 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3732 if (vg->vlan_devices[i] == dev){
3733 rc = QETH_VLAN_CARD;
3737 if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card))
3745 qeth_verify_dev(struct net_device *dev)
3747 struct qeth_card *card;
3748 unsigned long flags;
3751 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3752 list_for_each_entry(card, &qeth_card_list.list, list){
3753 if (card->dev == dev){
3754 rc = QETH_REAL_CARD;
3757 rc = qeth_verify_vlan_dev(dev, card);
3761 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3766 static struct qeth_card *
3767 qeth_get_card_from_dev(struct net_device *dev)
3769 struct qeth_card *card = NULL;
3772 rc = qeth_verify_dev(dev);
3773 if (rc == QETH_REAL_CARD)
3774 card = (struct qeth_card *)dev->priv;
3775 else if (rc == QETH_VLAN_CARD)
3776 card = (struct qeth_card *)
3777 VLAN_DEV_INFO(dev)->real_dev->priv;
3779 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3784 qeth_tx_timeout(struct net_device *dev)
3786 struct qeth_card *card;
3788 card = (struct qeth_card *) dev->priv;
3789 card->stats.tx_errors++;
3790 qeth_schedule_recovery(card);
3794 qeth_open(struct net_device *dev)
3796 struct qeth_card *card;
3798 QETH_DBF_TEXT(trace, 4, "qethopen");
3800 card = (struct qeth_card *) dev->priv;
3802 if (card->state != CARD_STATE_SOFTSETUP)
3805 if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3806 (card->options.layer2) &&
3807 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
3808 QETH_DBF_TEXT(trace,4,"nomacadr");
3811 card->data.state = CH_STATE_UP;
3812 card->state = CARD_STATE_UP;
3813 card->dev->flags |= IFF_UP;
3814 netif_start_queue(dev);
3816 if (!card->lan_online && netif_carrier_ok(dev))
3817 netif_carrier_off(dev);
3822 qeth_stop(struct net_device *dev)
3824 struct qeth_card *card;
3826 QETH_DBF_TEXT(trace, 4, "qethstop");
3828 card = (struct qeth_card *) dev->priv;
3830 netif_tx_disable(dev);
3831 card->dev->flags &= ~IFF_UP;
3832 if (card->state == CARD_STATE_UP)
3833 card->state = CARD_STATE_SOFTSETUP;
3838 qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3840 int cast_type = RTN_UNSPEC;
3842 if (card->info.type == QETH_CARD_TYPE_OSN)
3845 if (skb->dst && skb->dst->neighbour){
3846 cast_type = skb->dst->neighbour->type;
3847 if ((cast_type == RTN_BROADCAST) ||
3848 (cast_type == RTN_MULTICAST) ||
3849 (cast_type == RTN_ANYCAST))
3854 /* try something else */
3855 if (skb->protocol == ETH_P_IPV6)
3856 return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0;
3857 else if (skb->protocol == ETH_P_IP)
3858 return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0;
3860 if (!memcmp(skb->data, skb->dev->broadcast, 6))
3861 return RTN_BROADCAST;
3865 hdr_mac = *((u16 *)skb->data);
3867 switch (card->info.link_type) {
3868 case QETH_LINK_TYPE_HSTR:
3869 case QETH_LINK_TYPE_LANE_TR:
3870 if ((hdr_mac == QETH_TR_MAC_NC) ||
3871 (hdr_mac == QETH_TR_MAC_C))
3872 return RTN_MULTICAST;
3874 /* eth or so multicast? */
3876 if ((hdr_mac == QETH_ETH_MAC_V4) ||
3877 (hdr_mac == QETH_ETH_MAC_V6))
3878 return RTN_MULTICAST;
3885 qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3886 int ipv, int cast_type)
3888 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3889 return card->qdio.default_out_queue;
3890 switch (card->qdio.no_out_queues) {
3892 if (cast_type && card->info.is_multicast_different)
3893 return card->info.is_multicast_different &
3894 (card->qdio.no_out_queues - 1);
3895 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3896 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
3897 if (skb->nh.iph->tos & IP_TOS_NOTIMPORTANT)
3899 if (skb->nh.iph->tos & IP_TOS_HIGHRELIABILITY)
3901 if (skb->nh.iph->tos & IP_TOS_HIGHTHROUGHPUT)
3903 if (skb->nh.iph->tos & IP_TOS_LOWDELAY)
3906 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
3907 return 3 - (skb->nh.iph->tos >> 6);
3908 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3911 return card->qdio.default_out_queue;
3912 case 1: /* fallthrough for single-out-queue 1920-device */
3914 return card->qdio.default_out_queue;
3919 qeth_get_ip_version(struct sk_buff *skb)
3921 switch (skb->protocol) {
3931 static inline struct qeth_hdr *
3932 __qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, int ipv)
3934 #ifdef CONFIG_QETH_VLAN
3936 if (card->vlangrp && vlan_tx_tag_present(skb) &&
3937 ((ipv == 6) || card->options.layer2) ) {
3939 * Move the mac addresses (6 bytes src, 6 bytes dest)
3940 * to the beginning of the new header. We are using three
3941 * memcpys instead of one memmove to save cycles.
3943 skb_push(skb, VLAN_HLEN);
3944 memcpy(skb->data, skb->data + 4, 4);
3945 memcpy(skb->data + 4, skb->data + 8, 4);
3946 memcpy(skb->data + 8, skb->data + 12, 4);
3947 tag = (u16 *)(skb->data + 12);
3949 * first two bytes = ETH_P_8021Q (0x8100)
3950 * second two bytes = VLANID
3952 *tag = __constant_htons(ETH_P_8021Q);
3953 *(tag + 1) = htons(vlan_tx_tag_get(skb));
3956 return ((struct qeth_hdr *)
3957 qeth_push_skb(card, skb, sizeof(struct qeth_hdr)));
3961 __qeth_free_new_skb(struct sk_buff *orig_skb, struct sk_buff *new_skb)
3963 if (orig_skb != new_skb)
3964 dev_kfree_skb_any(new_skb);
3967 static inline struct sk_buff *
3968 qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb,
3969 struct qeth_hdr **hdr, int ipv)
3971 struct sk_buff *new_skb;
3973 QETH_DBF_TEXT(trace, 6, "prepskb");
3975 new_skb = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3976 if (new_skb == NULL)
3978 *hdr = __qeth_prepare_skb(card, new_skb, ipv);
3980 __qeth_free_new_skb(skb, new_skb);
3987 qeth_get_qeth_hdr_flags4(int cast_type)
3989 if (cast_type == RTN_MULTICAST)
3990 return QETH_CAST_MULTICAST;
3991 if (cast_type == RTN_BROADCAST)
3992 return QETH_CAST_BROADCAST;
3993 return QETH_CAST_UNICAST;
3997 qeth_get_qeth_hdr_flags6(int cast_type)
3999 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
4000 if (cast_type == RTN_MULTICAST)
4001 return ct | QETH_CAST_MULTICAST;
4002 if (cast_type == RTN_ANYCAST)
4003 return ct | QETH_CAST_ANYCAST;
4004 if (cast_type == RTN_BROADCAST)
4005 return ct | QETH_CAST_BROADCAST;
4006 return ct | QETH_CAST_UNICAST;
4010 qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
4011 struct sk_buff *skb)
4015 if (!memcmp(skb->data+QETH_HEADER_SIZE,
4016 skb->dev->broadcast,6)) { /* broadcast? */
4017 *(__u32 *)hdr->hdr.l2.flags |=
4018 QETH_LAYER2_FLAG_BROADCAST << 8;
4021 hdr_mac=*((__u16*)skb->data);
4023 switch (card->info.link_type) {
4024 case QETH_LINK_TYPE_HSTR:
4025 case QETH_LINK_TYPE_LANE_TR:
4026 if ((hdr_mac == QETH_TR_MAC_NC) ||
4027 (hdr_mac == QETH_TR_MAC_C) )
4028 *(__u32 *)hdr->hdr.l2.flags |=
4029 QETH_LAYER2_FLAG_MULTICAST << 8;
4031 *(__u32 *)hdr->hdr.l2.flags |=
4032 QETH_LAYER2_FLAG_UNICAST << 8;
4034 /* eth or so multicast? */
4036 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
4037 (hdr_mac==QETH_ETH_MAC_V6) )
4038 *(__u32 *)hdr->hdr.l2.flags |=
4039 QETH_LAYER2_FLAG_MULTICAST << 8;
4041 *(__u32 *)hdr->hdr.l2.flags |=
4042 QETH_LAYER2_FLAG_UNICAST << 8;
4047 qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4048 struct sk_buff *skb, int cast_type)
4050 memset(hdr, 0, sizeof(struct qeth_hdr));
4051 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
4053 /* set byte 0 to "0x02" and byte 3 to casting flags */
4054 if (cast_type==RTN_MULTICAST)
4055 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
4056 else if (cast_type==RTN_BROADCAST)
4057 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
4059 qeth_layer2_get_packet_type(card, hdr, skb);
4061 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
4062 #ifdef CONFIG_QETH_VLAN
4063 /* VSWITCH relies on the VLAN
4064 * information to be present in
4065 * the QDIO header */
4066 if ((card->vlangrp != NULL) &&
4067 vlan_tx_tag_present(skb)) {
4068 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
4069 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
4075 qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4076 struct sk_buff *skb, int ipv, int cast_type)
4078 QETH_DBF_TEXT(trace, 6, "fillhdr");
4080 memset(hdr, 0, sizeof(struct qeth_hdr));
4081 if (card->options.layer2) {
4082 qeth_layer2_fill_header(card, hdr, skb, cast_type);
4085 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
4086 hdr->hdr.l3.ext_flags = 0;
4087 #ifdef CONFIG_QETH_VLAN
4089 * before we're going to overwrite this location with next hop ip.
4090 * v6 uses passthrough, v4 sets the tag in the QDIO header.
4092 if (card->vlangrp && vlan_tx_tag_present(skb)) {
4093 hdr->hdr.l3.ext_flags = (ipv == 4) ?
4094 QETH_HDR_EXT_VLAN_FRAME :
4095 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
4096 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
4098 #endif /* CONFIG_QETH_VLAN */
4099 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
4100 if (ipv == 4) { /* IPv4 */
4101 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
4102 memset(hdr->hdr.l3.dest_addr, 0, 12);
4103 if ((skb->dst) && (skb->dst->neighbour)) {
4104 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
4105 *((u32 *) skb->dst->neighbour->primary_key);
4107 /* fill in destination address used in ip header */
4108 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = skb->nh.iph->daddr;
4110 } else if (ipv == 6) { /* IPv6 or passthru */
4111 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
4112 if ((skb->dst) && (skb->dst->neighbour)) {
4113 memcpy(hdr->hdr.l3.dest_addr,
4114 skb->dst->neighbour->primary_key, 16);
4116 /* fill in destination address used in ip header */
4117 memcpy(hdr->hdr.l3.dest_addr, &skb->nh.ipv6h->daddr, 16);
4119 } else { /* passthrough */
4120 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
4121 !memcmp(skb->data + sizeof(struct qeth_hdr) +
4122 sizeof(__u16), skb->dev->broadcast, 6)) {
4123 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4125 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
4126 skb->dev->broadcast, 6)) { /* broadcast? */
4127 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4130 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
4131 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
4132 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
4138 __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
4139 int is_tso, int *next_element_to_fill)
4141 int length = skb->len;
4147 element = *next_element_to_fill;
4149 first_lap = (is_tso == 0 ? 1 : 0);
4151 while (length > 0) {
4152 /* length_here is the remaining amount of data in this page */
4153 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4154 if (length < length_here)
4155 length_here = length;
4157 buffer->element[element].addr = data;
4158 buffer->element[element].length = length_here;
4159 length -= length_here;
4162 buffer->element[element].flags = 0;
4164 buffer->element[element].flags =
4165 SBAL_FLAGS_LAST_FRAG;
4168 buffer->element[element].flags =
4169 SBAL_FLAGS_FIRST_FRAG;
4171 buffer->element[element].flags =
4172 SBAL_FLAGS_MIDDLE_FRAG;
4174 data += length_here;
4178 *next_element_to_fill = element;
4182 qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4183 struct qeth_qdio_out_buffer *buf,
4184 struct sk_buff *skb)
4186 struct qdio_buffer *buffer;
4187 struct qeth_hdr_tso *hdr;
4188 int flush_cnt = 0, hdr_len, large_send = 0;
4190 QETH_DBF_TEXT(trace, 6, "qdfillbf");
4192 buffer = buf->buffer;
4193 atomic_inc(&skb->users);
4194 skb_queue_tail(&buf->skb_list, skb);
4196 hdr = (struct qeth_hdr_tso *) skb->data;
4197 /*check first on TSO ....*/
4198 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4199 int element = buf->next_element_to_fill;
4201 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4202 /*fill first buffer entry only with header information */
4203 buffer->element[element].addr = skb->data;
4204 buffer->element[element].length = hdr_len;
4205 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4206 buf->next_element_to_fill++;
4207 skb->data += hdr_len;
4208 skb->len -= hdr_len;
4211 if (skb_shinfo(skb)->nr_frags == 0)
4212 __qeth_fill_buffer(skb, buffer, large_send,
4213 (int *)&buf->next_element_to_fill);
4215 __qeth_fill_buffer_frag(skb, buffer, large_send,
4216 (int *)&buf->next_element_to_fill);
4218 if (!queue->do_pack) {
4219 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4220 /* set state to PRIMED -> will be flushed */
4221 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4224 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4225 if (queue->card->options.performance_stats)
4226 queue->card->perf_stats.skbs_sent_pack++;
4227 if (buf->next_element_to_fill >=
4228 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4230 * packed buffer if full -> set state PRIMED
4231 * -> will be flushed
4233 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4241 qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4242 struct sk_buff *skb, struct qeth_hdr *hdr,
4243 int elements_needed,
4244 struct qeth_eddp_context *ctx)
4246 struct qeth_qdio_out_buffer *buffer;
4247 int buffers_needed = 0;
4251 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4253 /* spin until we get the queue ... */
4254 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4255 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4256 /* ... now we've got the queue */
4257 index = queue->next_buf_to_fill;
4258 buffer = &queue->bufs[queue->next_buf_to_fill];
4260 * check if buffer is empty to make sure that we do not 'overtake'
4261 * ourselves and try to fill a buffer that is already primed
4263 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4266 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4267 QDIO_MAX_BUFFERS_PER_Q;
4269 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4270 if (buffers_needed < 0)
4272 queue->next_buf_to_fill =
4273 (queue->next_buf_to_fill + buffers_needed) %
4274 QDIO_MAX_BUFFERS_PER_Q;
4276 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4278 qeth_fill_buffer(queue, buffer, skb);
4279 qeth_flush_buffers(queue, 0, index, 1);
4281 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4282 WARN_ON(buffers_needed != flush_cnt);
4283 qeth_flush_buffers(queue, 0, index, flush_cnt);
4287 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4292 qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4293 struct sk_buff *skb, struct qeth_hdr *hdr,
4294 int elements_needed, struct qeth_eddp_context *ctx)
4296 struct qeth_qdio_out_buffer *buffer;
4298 int flush_count = 0;
4303 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4305 /* spin until we get the queue ... */
4306 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4307 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4308 start_index = queue->next_buf_to_fill;
4309 buffer = &queue->bufs[queue->next_buf_to_fill];
4311 * check if buffer is empty to make sure that we do not 'overtake'
4312 * ourselves and try to fill a buffer that is already primed
4314 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4315 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4318 /* check if we need to switch packing state of this queue */
4319 qeth_switch_to_packing_if_needed(queue);
4320 if (queue->do_pack){
4323 /* does packet fit in current buffer? */
4324 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4325 buffer->next_element_to_fill) < elements_needed){
4326 /* ... no -> set state PRIMED */
4327 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4329 queue->next_buf_to_fill =
4330 (queue->next_buf_to_fill + 1) %
4331 QDIO_MAX_BUFFERS_PER_Q;
4332 buffer = &queue->bufs[queue->next_buf_to_fill];
4333 /* we did a step forward, so check buffer state
4335 if (atomic_read(&buffer->state) !=
4336 QETH_QDIO_BUF_EMPTY){
4337 qeth_flush_buffers(queue, 0, start_index, flush_count);
4338 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4343 /* check if we have enough elements (including following
4344 * free buffers) to handle eddp context */
4345 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4346 printk("eddp tx_dropped 1\n");
4353 tmp = qeth_fill_buffer(queue, buffer, skb);
4355 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4357 printk("eddp tx_dropped 2\n");
4362 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4363 QDIO_MAX_BUFFERS_PER_Q;
4367 qeth_flush_buffers(queue, 0, start_index, flush_count);
4368 else if (!atomic_read(&queue->set_pci_flags_count))
4369 atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
4371 * queue->state will go from LOCKED -> UNLOCKED or from
4372 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4373 * (switch packing state or flush buffer to get another pci flag out).
4374 * In that case we will enter this loop
4376 while (atomic_dec_return(&queue->state)){
4378 start_index = queue->next_buf_to_fill;
4379 /* check if we can go back to non-packing state */
4380 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4382 * check if we need to flush a packing buffer to get a pci
4383 * flag out on the queue
4385 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4386 flush_count += qeth_flush_buffers_on_no_pci(queue);
4388 qeth_flush_buffers(queue, 0, start_index, flush_count);
4390 /* at this point the queue is UNLOCKED again */
4391 if (queue->card->options.performance_stats && do_pack)
4392 queue->card->perf_stats.bufs_sent_pack += flush_count;
4398 qeth_get_elements_no(struct qeth_card *card, void *hdr,
4399 struct sk_buff *skb, int elems)
4401 int elements_needed = 0;
4403 if (skb_shinfo(skb)->nr_frags > 0)
4404 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4405 if (elements_needed == 0)
4406 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4407 + skb->len) >> PAGE_SHIFT);
4408 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4409 PRINT_ERR("Invalid size of IP packet "
4410 "(Number=%d / Length=%d). Discarded.\n",
4411 (elements_needed+elems), skb->len);
4414 return elements_needed;
4419 qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4423 struct qeth_qdio_out_q *queue;
4424 struct qeth_hdr *hdr = NULL;
4425 int elements_needed = 0;
4426 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4427 struct qeth_eddp_context *ctx = NULL;
4428 int tx_bytes = skb->len;
4429 unsigned short nr_frags = skb_shinfo(skb)->nr_frags;
4430 unsigned short tso_size = skb_shinfo(skb)->gso_size;
4431 struct sk_buff *new_skb, *new_skb2;
4434 QETH_DBF_TEXT(trace, 6, "sendpkt");
4437 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4438 (skb->protocol == htons(ETH_P_IPV6)))
4440 cast_type = qeth_get_cast_type(card, skb);
4441 if ((cast_type == RTN_BROADCAST) &&
4442 (card->info.broadcast_capable == 0))
4444 queue = card->qdio.out_qs
4445 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4446 if (!card->options.layer2) {
4447 ipv = qeth_get_ip_version(skb);
4448 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4449 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
4452 if(card->dev->type == ARPHRD_IEEE802_TR){
4453 skb_pull(new_skb, QETH_FAKE_LL_LEN_TR);
4455 skb_pull(new_skb, QETH_FAKE_LL_LEN_ETH);
4459 if (skb_is_gso(skb))
4460 large_send = card->options.large_send;
4461 /* check on OSN device*/
4462 if (card->info.type == QETH_CARD_TYPE_OSN)
4463 hdr = (struct qeth_hdr *)new_skb->data;
4464 /*are we able to do TSO ? */
4465 if ((large_send == QETH_LARGE_SEND_TSO) &&
4466 (cast_type == RTN_UNSPEC)) {
4467 rc = qeth_tso_prepare_packet(card, new_skb, ipv, cast_type);
4469 __qeth_free_new_skb(skb, new_skb);
4473 } else if (card->info.type != QETH_CARD_TYPE_OSN) {
4474 new_skb2 = qeth_prepare_skb(card, new_skb, &hdr, ipv);
4476 __qeth_free_new_skb(skb, new_skb);
4480 __qeth_free_new_skb(new_skb2, new_skb);
4482 qeth_fill_header(card, hdr, new_skb, ipv, cast_type);
4484 if (large_send == QETH_LARGE_SEND_EDDP) {
4485 ctx = qeth_eddp_create_context(card, new_skb, hdr);
4487 __qeth_free_new_skb(skb, new_skb);
4488 PRINT_WARN("could not create eddp context\n");
4492 int elems = qeth_get_elements_no(card,(void*) hdr, new_skb,
4495 __qeth_free_new_skb(skb, new_skb);
4498 elements_needed += elems;
4501 if (card->info.type != QETH_CARD_TYPE_IQD)
4502 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
4503 elements_needed, ctx);
4505 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
4506 elements_needed, ctx);
4508 card->stats.tx_packets++;
4509 card->stats.tx_bytes += tx_bytes;
4511 dev_kfree_skb_any(skb);
4512 if (card->options.performance_stats) {
4514 !(large_send == QETH_LARGE_SEND_NO)) {
4515 card->perf_stats.large_send_bytes += tx_bytes;
4516 card->perf_stats.large_send_cnt++;
4519 card->perf_stats.sg_skbs_sent++;
4520 /* nr_frags + skb->data */
4521 card->perf_stats.sg_frags_sent +=
4526 card->stats.tx_dropped++;
4527 __qeth_free_new_skb(skb, new_skb);
4530 /* drop creator's reference */
4531 qeth_eddp_put_context(ctx);
4532 /* free skb; it's not referenced by a buffer */
4534 dev_kfree_skb_any(new_skb);
4540 qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4542 struct qeth_card *card = (struct qeth_card *) dev->priv;
4546 case MII_BMCR: /* Basic mode control register */
4548 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4549 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4550 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4551 rc |= BMCR_SPEED100;
4553 case MII_BMSR: /* Basic mode status register */
4554 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4555 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4558 case MII_PHYSID1: /* PHYS ID 1 */
4559 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4561 rc = (rc >> 5) & 0xFFFF;
4563 case MII_PHYSID2: /* PHYS ID 2 */
4564 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4566 case MII_ADVERTISE: /* Advertisement control reg */
4569 case MII_LPA: /* Link partner ability reg */
4570 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4571 LPA_100BASE4 | LPA_LPACK;
4573 case MII_EXPANSION: /* Expansion register */
4575 case MII_DCOUNTER: /* disconnect counter */
4577 case MII_FCSCOUNTER: /* false carrier counter */
4579 case MII_NWAYTEST: /* N-way auto-neg test register */
4581 case MII_RERRCOUNTER: /* rx error counter */
4582 rc = card->stats.rx_errors;
4584 case MII_SREVISION: /* silicon revision */
4586 case MII_RESV1: /* reserved 1 */
4588 case MII_LBRERROR: /* loopback, rx, bypass error */
4590 case MII_PHYADDR: /* physical address */
4592 case MII_RESV2: /* reserved 2 */
4594 case MII_TPISTATUS: /* TPI status for 10mbps */
4596 case MII_NCONFIG: /* network interface config */
4605 static inline const char *
4606 qeth_arp_get_error_cause(int *rc)
4609 case QETH_IPA_ARP_RC_FAILED:
4611 return "operation failed";
4612 case QETH_IPA_ARP_RC_NOTSUPP:
4614 return "operation not supported";
4615 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4617 return "argument out of range";
4618 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4620 return "query operation not supported";
4621 case QETH_IPA_ARP_RC_Q_NO_DATA:
4623 return "no query data available";
4625 return "unknown error";
4630 qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4634 qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4639 QETH_DBF_TEXT(trace,3,"arpstnoe");
4642 * currently GuestLAN only supports the ARP assist function
4643 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4644 * thus we say EOPNOTSUPP for this ARP function
4646 if (card->info.guestlan)
4648 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4649 PRINT_WARN("ARP processing not supported "
4650 "on %s!\n", QETH_CARD_IFNAME(card));
4653 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4654 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4658 PRINT_WARN("Could not set number of ARP entries on %s: "
4660 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4667 qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4668 struct qeth_arp_query_data *qdata,
4669 int entry_size, int uentry_size)
4675 entry_ptr = (char *)&qdata->data;
4676 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4677 for (i = 0; i < qdata->no_entries; ++i){
4678 /* strip off 32 bytes "media specific information" */
4679 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4680 entry_ptr += entry_size;
4681 uentry_ptr += uentry_size;
4686 qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4689 struct qeth_ipa_cmd *cmd;
4690 struct qeth_arp_query_data *qdata;
4691 struct qeth_arp_query_info *qinfo;
4696 QETH_DBF_TEXT(trace,4,"arpquecb");
4698 qinfo = (struct qeth_arp_query_info *) reply->param;
4699 cmd = (struct qeth_ipa_cmd *) data;
4700 if (cmd->hdr.return_code) {
4701 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4704 if (cmd->data.setassparms.hdr.return_code) {
4705 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4706 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4709 qdata = &cmd->data.setassparms.data.query_arp;
4710 switch(qdata->reply_bits){
4712 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4713 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4714 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4717 /* fall through to default */
4719 /* tr is the same as eth -> entry7 */
4720 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4721 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4722 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4725 /* check if there is enough room in userspace */
4726 if ((qinfo->udata_len - qinfo->udata_offset) <
4727 qdata->no_entries * uentry_size){
4728 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4729 cmd->hdr.return_code = -ENOMEM;
4730 PRINT_WARN("query ARP user space buffer is too small for "
4731 "the returned number of ARP entries. "
4732 "Aborting query!\n");
4735 QETH_DBF_TEXT_(trace, 4, "anore%i",
4736 cmd->data.setassparms.hdr.number_of_replies);
4737 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4738 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4740 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4741 /* strip off "media specific information" */
4742 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4745 /*copy entries to user buffer*/
4746 memcpy(qinfo->udata + qinfo->udata_offset,
4747 (char *)&qdata->data, qdata->no_entries*uentry_size);
4749 qinfo->no_entries += qdata->no_entries;
4750 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4751 /* check if all replies received ... */
4752 if (cmd->data.setassparms.hdr.seq_no <
4753 cmd->data.setassparms.hdr.number_of_replies)
4755 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4756 /* keep STRIP_ENTRIES flag so the user program can distinguish
4757 * stripped entries from normal ones */
4758 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4759 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4760 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4764 memcpy(qinfo->udata, &i, 4);
4769 qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4770 int len, int (*reply_cb)(struct qeth_card *,
4771 struct qeth_reply *,
4775 QETH_DBF_TEXT(trace,4,"sendarp");
4777 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4778 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4779 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4780 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4781 reply_cb, reply_param);
4785 qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4786 int len, int (*reply_cb)(struct qeth_card *,
4787 struct qeth_reply *,
4793 QETH_DBF_TEXT(trace,4,"sendsnmp");
4795 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4796 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4797 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4798 /* adjust PDU length fields in IPA_PDU_HEADER */
4799 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4801 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4802 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4803 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4804 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4805 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4806 reply_cb, reply_param);
4809 static struct qeth_cmd_buffer *
4810 qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4811 __u16, __u16, enum qeth_prot_versions);
4813 qeth_arp_query(struct qeth_card *card, char __user *udata)
4815 struct qeth_cmd_buffer *iob;
4816 struct qeth_arp_query_info qinfo = {0, };
4820 QETH_DBF_TEXT(trace,3,"arpquery");
4822 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4823 IPA_ARP_PROCESSING)) {
4824 PRINT_WARN("ARP processing not supported "
4825 "on %s!\n", QETH_CARD_IFNAME(card));
4828 /* get size of userspace buffer and mask_bits -> 6 bytes */
4829 if (copy_from_user(&qinfo, udata, 6))
4831 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL)))
4833 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4834 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4835 IPA_CMD_ASS_ARP_QUERY_INFO,
4836 sizeof(int),QETH_PROT_IPV4);
4838 rc = qeth_send_ipa_arp_cmd(card, iob,
4839 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4840 qeth_arp_query_cb, (void *)&qinfo);
4843 PRINT_WARN("Error while querying ARP cache on %s: %s "
4845 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4847 copy_to_user(udata, qinfo.udata, 4);
4849 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4856 * SNMP command callback
4859 qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4860 unsigned long sdata)
4862 struct qeth_ipa_cmd *cmd;
4863 struct qeth_arp_query_info *qinfo;
4864 struct qeth_snmp_cmd *snmp;
4865 unsigned char *data;
4868 QETH_DBF_TEXT(trace,3,"snpcmdcb");
4870 cmd = (struct qeth_ipa_cmd *) sdata;
4871 data = (unsigned char *)((char *)cmd - reply->offset);
4872 qinfo = (struct qeth_arp_query_info *) reply->param;
4873 snmp = &cmd->data.setadapterparms.data.snmp;
4875 if (cmd->hdr.return_code) {
4876 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4879 if (cmd->data.setadapterparms.hdr.return_code) {
4880 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4881 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4884 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4885 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4886 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4888 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4890 /* check if there is enough room in userspace */
4891 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4892 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4893 cmd->hdr.return_code = -ENOMEM;
4896 QETH_DBF_TEXT_(trace, 4, "snore%i",
4897 cmd->data.setadapterparms.hdr.used_total);
4898 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4899 /*copy entries to user buffer*/
4900 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4901 memcpy(qinfo->udata + qinfo->udata_offset,
4903 data_len + offsetof(struct qeth_snmp_cmd,data));
4904 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4906 memcpy(qinfo->udata + qinfo->udata_offset,
4907 (char *)&snmp->request, data_len);
4909 qinfo->udata_offset += data_len;
4910 /* check if all replies received ... */
4911 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4912 cmd->data.setadapterparms.hdr.used_total);
4913 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4914 cmd->data.setadapterparms.hdr.seq_no);
4915 if (cmd->data.setadapterparms.hdr.seq_no <
4916 cmd->data.setadapterparms.hdr.used_total)
4921 static struct qeth_cmd_buffer *
4922 qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4923 enum qeth_prot_versions );
4925 static struct qeth_cmd_buffer *
4926 qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4928 struct qeth_cmd_buffer *iob;
4929 struct qeth_ipa_cmd *cmd;
4931 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4933 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4934 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4935 cmd->data.setadapterparms.hdr.command_code = command;
4936 cmd->data.setadapterparms.hdr.used_total = 1;
4937 cmd->data.setadapterparms.hdr.seq_no = 1;
4943 * function to send SNMP commands to OSA-E card
4946 qeth_snmp_command(struct qeth_card *card, char __user *udata)
4948 struct qeth_cmd_buffer *iob;
4949 struct qeth_ipa_cmd *cmd;
4950 struct qeth_snmp_ureq *ureq;
4952 struct qeth_arp_query_info qinfo = {0, };
4955 QETH_DBF_TEXT(trace,3,"snmpcmd");
4957 if (card->info.guestlan)
4960 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4961 (!card->options.layer2) ) {
4962 PRINT_WARN("SNMP Query MIBS not supported "
4963 "on %s!\n", QETH_CARD_IFNAME(card));
4966 /* skip 4 bytes (data_len struct member) to get req_len */
4967 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4969 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4971 QETH_DBF_TEXT(trace, 2, "snmpnome");
4974 if (copy_from_user(ureq, udata,
4975 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
4979 qinfo.udata_len = ureq->hdr.data_len;
4980 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){
4984 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4986 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
4987 QETH_SNMP_SETADP_CMDLENGTH + req_len);
4988 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4989 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
4990 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
4991 qeth_snmp_command_cb, (void *)&qinfo);
4993 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
4994 QETH_CARD_IFNAME(card), rc);
4996 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
5004 qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
5008 qeth_default_setadapterparms_cb(struct qeth_card *card,
5009 struct qeth_reply *reply,
5010 unsigned long data);
5012 qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
5015 (struct qeth_card *, struct qeth_reply *, unsigned long),
5019 qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5021 struct qeth_cmd_buffer *iob;
5026 QETH_DBF_TEXT(trace,3,"arpadent");
5029 * currently GuestLAN only supports the ARP assist function
5030 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
5031 * thus we say EOPNOTSUPP for this ARP function
5033 if (card->info.guestlan)
5035 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5036 PRINT_WARN("ARP processing not supported "
5037 "on %s!\n", QETH_CARD_IFNAME(card));
5041 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5042 IPA_CMD_ASS_ARP_ADD_ENTRY,
5043 sizeof(struct qeth_arp_cache_entry),
5045 rc = qeth_send_setassparms(card, iob,
5046 sizeof(struct qeth_arp_cache_entry),
5047 (unsigned long) entry,
5048 qeth_default_setassparms_cb, NULL);
5051 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5052 PRINT_WARN("Could not add ARP entry for address %s on %s: "
5054 buf, QETH_CARD_IFNAME(card),
5055 qeth_arp_get_error_cause(&rc), tmp, tmp);
5061 qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5063 struct qeth_cmd_buffer *iob;
5064 char buf[16] = {0, };
5068 QETH_DBF_TEXT(trace,3,"arprment");
5071 * currently GuestLAN only supports the ARP assist function
5072 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5073 * thus we say EOPNOTSUPP for this ARP function
5075 if (card->info.guestlan)
5077 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5078 PRINT_WARN("ARP processing not supported "
5079 "on %s!\n", QETH_CARD_IFNAME(card));
5082 memcpy(buf, entry, 12);
5083 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5084 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5087 rc = qeth_send_setassparms(card, iob,
5088 12, (unsigned long)buf,
5089 qeth_default_setassparms_cb, NULL);
5093 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5094 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5096 buf, QETH_CARD_IFNAME(card),
5097 qeth_arp_get_error_cause(&rc), tmp, tmp);
5103 qeth_arp_flush_cache(struct qeth_card *card)
5108 QETH_DBF_TEXT(trace,3,"arpflush");
5111 * currently GuestLAN only supports the ARP assist function
5112 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5113 * thus we say EOPNOTSUPP for this ARP function
5115 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5117 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5118 PRINT_WARN("ARP processing not supported "
5119 "on %s!\n", QETH_CARD_IFNAME(card));
5122 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5123 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5126 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5127 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5134 qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5136 struct qeth_card *card = (struct qeth_card *)dev->priv;
5137 struct qeth_arp_cache_entry arp_entry;
5138 struct mii_ioctl_data *mii_data;
5144 if ((card->state != CARD_STATE_UP) &&
5145 (card->state != CARD_STATE_SOFTSETUP))
5148 if (card->info.type == QETH_CARD_TYPE_OSN)
5152 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5153 if ( !capable(CAP_NET_ADMIN) ||
5154 (card->options.layer2) ) {
5158 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5160 case SIOC_QETH_ARP_QUERY_INFO:
5161 if ( !capable(CAP_NET_ADMIN) ||
5162 (card->options.layer2) ) {
5166 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5168 case SIOC_QETH_ARP_ADD_ENTRY:
5169 if ( !capable(CAP_NET_ADMIN) ||
5170 (card->options.layer2) ) {
5174 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5175 sizeof(struct qeth_arp_cache_entry)))
5178 rc = qeth_arp_add_entry(card, &arp_entry);
5180 case SIOC_QETH_ARP_REMOVE_ENTRY:
5181 if ( !capable(CAP_NET_ADMIN) ||
5182 (card->options.layer2) ) {
5186 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5187 sizeof(struct qeth_arp_cache_entry)))
5190 rc = qeth_arp_remove_entry(card, &arp_entry);
5192 case SIOC_QETH_ARP_FLUSH_CACHE:
5193 if ( !capable(CAP_NET_ADMIN) ||
5194 (card->options.layer2) ) {
5198 rc = qeth_arp_flush_cache(card);
5200 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5201 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5203 case SIOC_QETH_GET_CARD_TYPE:
5204 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5205 !card->info.guestlan)
5210 mii_data = if_mii(rq);
5211 mii_data->phy_id = 0;
5214 mii_data = if_mii(rq);
5215 if (mii_data->phy_id != 0)
5218 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5225 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5229 static struct net_device_stats *
5230 qeth_get_stats(struct net_device *dev)
5232 struct qeth_card *card;
5234 card = (struct qeth_card *) (dev->priv);
5236 QETH_DBF_TEXT(trace,5,"getstat");
5238 return &card->stats;
5242 qeth_change_mtu(struct net_device *dev, int new_mtu)
5244 struct qeth_card *card;
5247 card = (struct qeth_card *) (dev->priv);
5249 QETH_DBF_TEXT(trace,4,"chgmtu");
5250 sprintf(dbf_text, "%8x", new_mtu);
5251 QETH_DBF_TEXT(trace,4,dbf_text);
5255 if (new_mtu > 65535)
5257 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5258 (!qeth_mtu_is_valid(card, new_mtu)))
5264 #ifdef CONFIG_QETH_VLAN
5266 qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5268 struct qeth_card *card;
5269 unsigned long flags;
5271 QETH_DBF_TEXT(trace,4,"vlanreg");
5273 card = (struct qeth_card *) dev->priv;
5274 spin_lock_irqsave(&card->vlanlock, flags);
5275 card->vlangrp = grp;
5276 spin_unlock_irqrestore(&card->vlanlock, flags);
5280 qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5284 struct sk_buff *skb;
5285 struct sk_buff_head tmp_list;
5287 skb_queue_head_init(&tmp_list);
5288 lockdep_set_class(&tmp_list.lock, &qdio_out_skb_queue_key);
5289 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5290 while ((skb = skb_dequeue(&buf->skb_list))){
5291 if (vlan_tx_tag_present(skb) &&
5292 (vlan_tx_tag_get(skb) == vid)) {
5293 atomic_dec(&skb->users);
5296 skb_queue_tail(&tmp_list, skb);
5299 while ((skb = skb_dequeue(&tmp_list)))
5300 skb_queue_tail(&buf->skb_list, skb);
5304 qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5308 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5309 for (i = 0; i < card->qdio.no_out_queues; ++i){
5310 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5311 qeth_free_vlan_buffer(card, &card->qdio.
5312 out_qs[i]->bufs[j], vid);
5317 qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5319 struct in_device *in_dev;
5320 struct in_ifaddr *ifa;
5321 struct qeth_ipaddr *addr;
5323 QETH_DBF_TEXT(trace, 4, "frvaddr4");
5326 in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]);
5329 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5330 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5332 addr->u.a4.addr = ifa->ifa_address;
5333 addr->u.a4.mask = ifa->ifa_mask;
5334 addr->type = QETH_IP_TYPE_NORMAL;
5335 if (!qeth_delete_ip(card, addr))
5344 qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5346 #ifdef CONFIG_QETH_IPV6
5347 struct inet6_dev *in6_dev;
5348 struct inet6_ifaddr *ifa;
5349 struct qeth_ipaddr *addr;
5351 QETH_DBF_TEXT(trace, 4, "frvaddr6");
5353 in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]);
5356 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5357 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5359 memcpy(&addr->u.a6.addr, &ifa->addr,
5360 sizeof(struct in6_addr));
5361 addr->u.a6.pfxlen = ifa->prefix_len;
5362 addr->type = QETH_IP_TYPE_NORMAL;
5363 if (!qeth_delete_ip(card, addr))
5367 in6_dev_put(in6_dev);
5368 #endif /* CONFIG_QETH_IPV6 */
5372 qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5374 if (card->options.layer2 || !card->vlangrp)
5376 qeth_free_vlan_addresses4(card, vid);
5377 qeth_free_vlan_addresses6(card, vid);
5381 qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5382 struct qeth_reply *reply,
5385 struct qeth_ipa_cmd *cmd;
5387 QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5388 cmd = (struct qeth_ipa_cmd *) data;
5389 if (cmd->hdr.return_code) {
5390 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5391 "Continuing\n",cmd->data.setdelvlan.vlan_id,
5392 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5393 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5394 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5395 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5401 qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5402 enum qeth_ipa_cmds ipacmd)
5404 struct qeth_ipa_cmd *cmd;
5405 struct qeth_cmd_buffer *iob;
5407 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5408 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5409 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5410 cmd->data.setdelvlan.vlan_id = i;
5411 return qeth_send_ipa_cmd(card, iob,
5412 qeth_layer2_send_setdelvlan_cb, NULL);
5416 qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5420 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5424 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5425 if (card->vlangrp->vlan_devices[i] == NULL)
5428 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5430 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5434 /*add_vid is layer 2 used only ....*/
5436 qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5438 struct qeth_card *card;
5440 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5442 card = (struct qeth_card *) dev->priv;
5443 if (!card->options.layer2)
5445 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5448 /*... kill_vid used for both modes*/
5450 qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5452 struct qeth_card *card;
5453 unsigned long flags;
5455 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5457 card = (struct qeth_card *) dev->priv;
5458 /* free all skbs for the vlan device */
5459 qeth_free_vlan_skbs(card, vid);
5460 spin_lock_irqsave(&card->vlanlock, flags);
5461 /* unregister IP addresses of vlan device */
5462 qeth_free_vlan_addresses(card, vid);
5464 card->vlangrp->vlan_devices[vid] = NULL;
5465 spin_unlock_irqrestore(&card->vlanlock, flags);
5466 if (card->options.layer2)
5467 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5468 qeth_set_multicast_list(card->dev);
5472 * Examine hardware response to SET_PROMISC_MODE
5475 qeth_setadp_promisc_mode_cb(struct qeth_card *card,
5476 struct qeth_reply *reply,
5479 struct qeth_ipa_cmd *cmd;
5480 struct qeth_ipacmd_setadpparms *setparms;
5482 QETH_DBF_TEXT(trace,4,"prmadpcb");
5484 cmd = (struct qeth_ipa_cmd *) data;
5485 setparms = &(cmd->data.setadapterparms);
5487 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
5488 if (cmd->hdr.return_code) {
5489 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
5490 setparms->data.mode = SET_PROMISC_MODE_OFF;
5492 card->info.promisc_mode = setparms->data.mode;
5496 * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5499 qeth_setadp_promisc_mode(struct qeth_card *card)
5501 enum qeth_ipa_promisc_modes mode;
5502 struct net_device *dev = card->dev;
5503 struct qeth_cmd_buffer *iob;
5504 struct qeth_ipa_cmd *cmd;
5506 QETH_DBF_TEXT(trace, 4, "setprom");
5508 if (((dev->flags & IFF_PROMISC) &&
5509 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5510 (!(dev->flags & IFF_PROMISC) &&
5511 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5513 mode = SET_PROMISC_MODE_OFF;
5514 if (dev->flags & IFF_PROMISC)
5515 mode = SET_PROMISC_MODE_ON;
5516 QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5518 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5519 sizeof(struct qeth_ipacmd_setadpparms));
5520 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5521 cmd->data.setadapterparms.data.mode = mode;
5522 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5526 * set multicast address on card
5529 qeth_set_multicast_list(struct net_device *dev)
5531 struct qeth_card *card = (struct qeth_card *) dev->priv;
5533 if (card->info.type == QETH_CARD_TYPE_OSN)
5536 QETH_DBF_TEXT(trace, 3, "setmulti");
5537 qeth_delete_mc_addresses(card);
5538 if (card->options.layer2) {
5539 qeth_layer2_add_multicast(card);
5542 qeth_add_multicast_ipv4(card);
5543 #ifdef CONFIG_QETH_IPV6
5544 qeth_add_multicast_ipv6(card);
5547 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
5548 schedule_work(&card->kernel_thread_starter);
5549 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5551 if (qeth_set_thread_start_bit(card, QETH_SET_PROMISC_MODE_THREAD)==0)
5552 schedule_work(&card->kernel_thread_starter);
5556 qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5562 qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5564 if (dev->type == ARPHRD_IEEE802_TR)
5565 ip_tr_mc_map(ipm, mac);
5567 ip_eth_mc_map(ipm, mac);
5570 static struct qeth_ipaddr *
5571 qeth_get_addr_buffer(enum qeth_prot_versions prot)
5573 struct qeth_ipaddr *addr;
5575 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5577 PRINT_WARN("Not enough memory to add address\n");
5580 addr->type = QETH_IP_TYPE_NORMAL;
5586 qeth_osn_assist(struct net_device *dev,
5590 struct qeth_cmd_buffer *iob;
5591 struct qeth_card *card;
5594 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5597 card = (struct qeth_card *)dev->priv;
5600 if ((card->state != CARD_STATE_UP) &&
5601 (card->state != CARD_STATE_SOFTSETUP))
5603 iob = qeth_wait_for_buffer(&card->write);
5604 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5605 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5609 static struct net_device *
5610 qeth_netdev_by_devno(unsigned char *read_dev_no)
5612 struct qeth_card *card;
5613 struct net_device *ndev;
5614 unsigned char *readno;
5615 __u16 temp_dev_no, card_dev_no;
5617 unsigned long flags;
5620 memcpy(&temp_dev_no, read_dev_no, 2);
5621 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5622 list_for_each_entry(card, &qeth_card_list.list, list) {
5623 readno = CARD_RDEV_ID(card);
5624 readno += (strlen(readno) - 4);
5625 card_dev_no = simple_strtoul(readno, &endp, 16);
5626 if (card_dev_no == temp_dev_no) {
5631 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5636 qeth_osn_register(unsigned char *read_dev_no,
5637 struct net_device **dev,
5638 int (*assist_cb)(struct net_device *, void *),
5639 int (*data_cb)(struct sk_buff *))
5641 struct qeth_card * card;
5643 QETH_DBF_TEXT(trace, 2, "osnreg");
5644 *dev = qeth_netdev_by_devno(read_dev_no);
5647 card = (struct qeth_card *)(*dev)->priv;
5650 if ((assist_cb == NULL) || (data_cb == NULL))
5652 card->osn_info.assist_cb = assist_cb;
5653 card->osn_info.data_cb = data_cb;
5658 qeth_osn_deregister(struct net_device * dev)
5660 struct qeth_card *card;
5662 QETH_DBF_TEXT(trace, 2, "osndereg");
5665 card = (struct qeth_card *)dev->priv;
5668 card->osn_info.assist_cb = NULL;
5669 card->osn_info.data_cb = NULL;
5674 qeth_delete_mc_addresses(struct qeth_card *card)
5676 struct qeth_ipaddr *iptodo;
5677 unsigned long flags;
5679 QETH_DBF_TEXT(trace,4,"delmc");
5680 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5682 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5685 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5686 spin_lock_irqsave(&card->ip_lock, flags);
5687 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5689 spin_unlock_irqrestore(&card->ip_lock, flags);
5693 qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5695 struct qeth_ipaddr *ipm;
5696 struct ip_mc_list *im4;
5697 char buf[MAX_ADDR_LEN];
5699 QETH_DBF_TEXT(trace,4,"addmc");
5700 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5701 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5702 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5705 ipm->u.a4.addr = im4->multiaddr;
5706 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5707 ipm->is_multicast = 1;
5708 if (!qeth_add_ip(card,ipm))
5714 qeth_add_vlan_mc(struct qeth_card *card)
5716 #ifdef CONFIG_QETH_VLAN
5717 struct in_device *in_dev;
5718 struct vlan_group *vg;
5721 QETH_DBF_TEXT(trace,4,"addmcvl");
5722 if ( ((card->options.layer2 == 0) &&
5723 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5724 (card->vlangrp == NULL) )
5728 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5729 if (vg->vlan_devices[i] == NULL ||
5730 !(vg->vlan_devices[i]->flags & IFF_UP))
5732 in_dev = in_dev_get(vg->vlan_devices[i]);
5735 read_lock(&in_dev->mc_list_lock);
5736 qeth_add_mc(card,in_dev);
5737 read_unlock(&in_dev->mc_list_lock);
5744 qeth_add_multicast_ipv4(struct qeth_card *card)
5746 struct in_device *in4_dev;
5748 QETH_DBF_TEXT(trace,4,"chkmcv4");
5749 in4_dev = in_dev_get(card->dev);
5750 if (in4_dev == NULL)
5752 read_lock(&in4_dev->mc_list_lock);
5753 qeth_add_mc(card, in4_dev);
5754 qeth_add_vlan_mc(card);
5755 read_unlock(&in4_dev->mc_list_lock);
5756 in_dev_put(in4_dev);
5760 qeth_layer2_add_multicast(struct qeth_card *card)
5762 struct qeth_ipaddr *ipm;
5763 struct dev_mc_list *dm;
5765 QETH_DBF_TEXT(trace,4,"L2addmc");
5766 for (dm = card->dev->mc_list; dm; dm = dm->next) {
5767 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5770 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5771 ipm->is_multicast = 1;
5772 if (!qeth_add_ip(card, ipm))
5777 #ifdef CONFIG_QETH_IPV6
5779 qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5781 struct qeth_ipaddr *ipm;
5782 struct ifmcaddr6 *im6;
5783 char buf[MAX_ADDR_LEN];
5785 QETH_DBF_TEXT(trace,4,"addmc6");
5786 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5787 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5788 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5791 ipm->is_multicast = 1;
5792 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5793 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5794 sizeof(struct in6_addr));
5795 if (!qeth_add_ip(card,ipm))
5801 qeth_add_vlan_mc6(struct qeth_card *card)
5803 #ifdef CONFIG_QETH_VLAN
5804 struct inet6_dev *in_dev;
5805 struct vlan_group *vg;
5808 QETH_DBF_TEXT(trace,4,"admc6vl");
5809 if ( ((card->options.layer2 == 0) &&
5810 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5811 (card->vlangrp == NULL))
5815 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5816 if (vg->vlan_devices[i] == NULL ||
5817 !(vg->vlan_devices[i]->flags & IFF_UP))
5819 in_dev = in6_dev_get(vg->vlan_devices[i]);
5822 read_lock(&in_dev->lock);
5823 qeth_add_mc6(card,in_dev);
5824 read_unlock(&in_dev->lock);
5825 in6_dev_put(in_dev);
5827 #endif /* CONFIG_QETH_VLAN */
5831 qeth_add_multicast_ipv6(struct qeth_card *card)
5833 struct inet6_dev *in6_dev;
5835 QETH_DBF_TEXT(trace,4,"chkmcv6");
5836 if (!qeth_is_supported(card, IPA_IPV6))
5838 in6_dev = in6_dev_get(card->dev);
5839 if (in6_dev == NULL)
5841 read_lock(&in6_dev->lock);
5842 qeth_add_mc6(card, in6_dev);
5843 qeth_add_vlan_mc6(card);
5844 read_unlock(&in6_dev->lock);
5845 in6_dev_put(in6_dev);
5847 #endif /* CONFIG_QETH_IPV6 */
5850 qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5851 enum qeth_ipa_cmds ipacmd,
5852 int (*reply_cb) (struct qeth_card *,
5856 struct qeth_ipa_cmd *cmd;
5857 struct qeth_cmd_buffer *iob;
5859 QETH_DBF_TEXT(trace, 2, "L2sdmac");
5860 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5861 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5862 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5863 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5864 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5868 qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5869 struct qeth_reply *reply,
5872 struct qeth_ipa_cmd *cmd;
5875 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5876 cmd = (struct qeth_ipa_cmd *) data;
5877 mac = &cmd->data.setdelmac.mac[0];
5878 /* MAC already registered, needed in couple/uncouple case */
5879 if (cmd->hdr.return_code == 0x2005) {
5880 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5881 "already existing on %s \n",
5882 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5883 QETH_CARD_IFNAME(card));
5884 cmd->hdr.return_code = 0;
5886 if (cmd->hdr.return_code)
5887 PRINT_ERR("Could not set group MAC " \
5888 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5889 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5890 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5895 qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5897 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5898 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5899 qeth_layer2_send_setgroupmac_cb);
5903 qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5904 struct qeth_reply *reply,
5907 struct qeth_ipa_cmd *cmd;
5910 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5911 cmd = (struct qeth_ipa_cmd *) data;
5912 mac = &cmd->data.setdelmac.mac[0];
5913 if (cmd->hdr.return_code)
5914 PRINT_ERR("Could not delete group MAC " \
5915 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5916 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5917 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5922 qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5924 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5925 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5926 qeth_layer2_send_delgroupmac_cb);
5930 qeth_layer2_send_setmac_cb(struct qeth_card *card,
5931 struct qeth_reply *reply,
5934 struct qeth_ipa_cmd *cmd;
5936 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5937 cmd = (struct qeth_ipa_cmd *) data;
5938 if (cmd->hdr.return_code) {
5939 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5940 PRINT_WARN("Error in registering MAC address on " \
5941 "device %s: x%x\n", CARD_BUS_ID(card),
5942 cmd->hdr.return_code);
5943 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
5944 cmd->hdr.return_code = -EIO;
5946 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
5947 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5949 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5950 "successfully registered on device %s\n",
5951 card->dev->dev_addr[0], card->dev->dev_addr[1],
5952 card->dev->dev_addr[2], card->dev->dev_addr[3],
5953 card->dev->dev_addr[4], card->dev->dev_addr[5],
5960 qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
5962 QETH_DBF_TEXT(trace, 2, "L2Setmac");
5963 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
5964 qeth_layer2_send_setmac_cb);
5968 qeth_layer2_send_delmac_cb(struct qeth_card *card,
5969 struct qeth_reply *reply,
5972 struct qeth_ipa_cmd *cmd;
5974 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
5975 cmd = (struct qeth_ipa_cmd *) data;
5976 if (cmd->hdr.return_code) {
5977 PRINT_WARN("Error in deregistering MAC address on " \
5978 "device %s: x%x\n", CARD_BUS_ID(card),
5979 cmd->hdr.return_code);
5980 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5981 cmd->hdr.return_code = -EIO;
5984 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
5989 qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
5991 QETH_DBF_TEXT(trace, 2, "L2Delmac");
5992 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
5994 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
5995 qeth_layer2_send_delmac_cb);
5999 qeth_layer2_set_mac_address(struct net_device *dev, void *p)
6001 struct sockaddr *addr = p;
6002 struct qeth_card *card;
6005 QETH_DBF_TEXT(trace, 3, "setmac");
6007 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
6008 QETH_DBF_TEXT(trace, 3, "setmcINV");
6011 card = (struct qeth_card *) dev->priv;
6013 if (!card->options.layer2) {
6014 PRINT_WARN("Setting MAC address on %s is not supported "
6015 "in Layer 3 mode.\n", dev->name);
6016 QETH_DBF_TEXT(trace, 3, "setmcLY3");
6019 if (card->info.type == QETH_CARD_TYPE_OSN) {
6020 PRINT_WARN("Setting MAC address on %s is not supported.\n",
6022 QETH_DBF_TEXT(trace, 3, "setmcOSN");
6025 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
6026 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
6027 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
6029 rc = qeth_layer2_send_setmac(card, addr->sa_data);
6034 qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
6035 __u8 command, enum qeth_prot_versions prot)
6037 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
6038 cmd->hdr.command = command;
6039 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
6040 cmd->hdr.seqno = card->seqno.ipa;
6041 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
6042 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
6043 if (card->options.layer2)
6044 cmd->hdr.prim_version_no = 2;
6046 cmd->hdr.prim_version_no = 1;
6047 cmd->hdr.param_count = 1;
6048 cmd->hdr.prot_version = prot;
6049 cmd->hdr.ipa_supported = 0;
6050 cmd->hdr.ipa_enabled = 0;
6053 static struct qeth_cmd_buffer *
6054 qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6055 enum qeth_prot_versions prot)
6057 struct qeth_cmd_buffer *iob;
6058 struct qeth_ipa_cmd *cmd;
6060 iob = qeth_wait_for_buffer(&card->write);
6061 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6062 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6068 qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6071 struct qeth_cmd_buffer *iob;
6072 struct qeth_ipa_cmd *cmd;
6074 QETH_DBF_TEXT(trace,4,"setdelmc");
6076 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6077 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6078 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6079 if (addr->proto == QETH_PROT_IPV6)
6080 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6081 sizeof(struct in6_addr));
6083 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6085 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6090 qeth_fill_netmask(u8 *netmask, unsigned int len)
6093 for (i=0;i<16;i++) {
6098 netmask[i] = (u8)(0xFF00>>j);
6105 qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6106 int ipacmd, unsigned int flags)
6109 struct qeth_cmd_buffer *iob;
6110 struct qeth_ipa_cmd *cmd;
6113 QETH_DBF_TEXT(trace,4,"setdelip");
6114 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6116 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6117 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6118 if (addr->proto == QETH_PROT_IPV6) {
6119 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6120 sizeof(struct in6_addr));
6121 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6122 memcpy(cmd->data.setdelip6.mask, netmask,
6123 sizeof(struct in6_addr));
6124 cmd->data.setdelip6.flags = flags;
6126 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6127 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6128 cmd->data.setdelip4.flags = flags;
6131 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6137 qeth_layer2_register_addr_entry(struct qeth_card *card,
6138 struct qeth_ipaddr *addr)
6140 if (!addr->is_multicast)
6142 QETH_DBF_TEXT(trace, 2, "setgmac");
6143 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6144 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6148 qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6149 struct qeth_ipaddr *addr)
6151 if (!addr->is_multicast)
6153 QETH_DBF_TEXT(trace, 2, "delgmac");
6154 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6155 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6159 qeth_layer3_register_addr_entry(struct qeth_card *card,
6160 struct qeth_ipaddr *addr)
6166 if (addr->proto == QETH_PROT_IPV4) {
6167 QETH_DBF_TEXT(trace, 2,"setaddr4");
6168 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6169 } else if (addr->proto == QETH_PROT_IPV6) {
6170 QETH_DBF_TEXT(trace, 2, "setaddr6");
6171 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6172 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6174 QETH_DBF_TEXT(trace, 2, "setaddr?");
6175 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6178 if (addr->is_multicast)
6179 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6181 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6184 QETH_DBF_TEXT(trace, 2, "failed");
6185 } while ((--cnt > 0) && rc);
6187 QETH_DBF_TEXT(trace, 2, "FAILED");
6188 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6189 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6196 qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6197 struct qeth_ipaddr *addr)
6202 if (addr->proto == QETH_PROT_IPV4) {
6203 QETH_DBF_TEXT(trace, 2,"deladdr4");
6204 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6205 } else if (addr->proto == QETH_PROT_IPV6) {
6206 QETH_DBF_TEXT(trace, 2, "deladdr6");
6207 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6208 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6210 QETH_DBF_TEXT(trace, 2, "deladdr?");
6211 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6213 if (addr->is_multicast)
6214 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6216 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6219 QETH_DBF_TEXT(trace, 2, "failed");
6220 /* TODO: re-activate this warning as soon as we have a
6222 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6223 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6231 qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6233 if (card->options.layer2)
6234 return qeth_layer2_register_addr_entry(card, addr);
6236 return qeth_layer3_register_addr_entry(card, addr);
6240 qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6242 if (card->options.layer2)
6243 return qeth_layer2_deregister_addr_entry(card, addr);
6245 return qeth_layer3_deregister_addr_entry(card, addr);
6249 qeth_ethtool_get_tx_csum(struct net_device *dev)
6251 /* We may need to say that we support tx csum offload if
6252 * we do EDDP or TSO. There are discussions going on to
6253 * enforce rules in the stack and in ethtool that make
6254 * SG and TSO depend on HW_CSUM. At the moment there are
6256 * If we say yes here, we have to checksum outbound packets
6262 qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6268 qeth_ethtool_get_rx_csum(struct net_device *dev)
6270 struct qeth_card *card = (struct qeth_card *)dev->priv;
6272 return (card->options.checksum_type == HW_CHECKSUMMING);
6276 qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6278 struct qeth_card *card = (struct qeth_card *)dev->priv;
6280 if ((card->state != CARD_STATE_DOWN) &&
6281 (card->state != CARD_STATE_RECOVER))
6284 card->options.checksum_type = HW_CHECKSUMMING;
6286 card->options.checksum_type = SW_CHECKSUMMING;
6291 qeth_ethtool_get_sg(struct net_device *dev)
6293 struct qeth_card *card = (struct qeth_card *)dev->priv;
6295 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6296 (dev->features & NETIF_F_SG));
6300 qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6302 struct qeth_card *card = (struct qeth_card *)dev->priv;
6305 if (card->options.large_send != QETH_LARGE_SEND_NO)
6306 dev->features |= NETIF_F_SG;
6308 dev->features &= ~NETIF_F_SG;
6312 dev->features &= ~NETIF_F_SG;
6317 qeth_ethtool_get_tso(struct net_device *dev)
6319 struct qeth_card *card = (struct qeth_card *)dev->priv;
6321 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6322 (dev->features & NETIF_F_TSO));
6326 qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6328 struct qeth_card *card = (struct qeth_card *)dev->priv;
6331 if (card->options.large_send != QETH_LARGE_SEND_NO)
6332 dev->features |= NETIF_F_TSO;
6334 dev->features &= ~NETIF_F_TSO;
6338 dev->features &= ~NETIF_F_TSO;
6342 static struct ethtool_ops qeth_ethtool_ops = {
6343 .get_tx_csum = qeth_ethtool_get_tx_csum,
6344 .set_tx_csum = qeth_ethtool_set_tx_csum,
6345 .get_rx_csum = qeth_ethtool_get_rx_csum,
6346 .set_rx_csum = qeth_ethtool_set_rx_csum,
6347 .get_sg = qeth_ethtool_get_sg,
6348 .set_sg = qeth_ethtool_set_sg,
6349 .get_tso = qeth_ethtool_get_tso,
6350 .set_tso = qeth_ethtool_set_tso,
6354 qeth_netdev_init(struct net_device *dev)
6356 struct qeth_card *card;
6358 card = (struct qeth_card *) dev->priv;
6360 QETH_DBF_TEXT(trace,3,"initdev");
6362 dev->tx_timeout = &qeth_tx_timeout;
6363 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6364 dev->open = qeth_open;
6365 dev->stop = qeth_stop;
6366 dev->hard_start_xmit = qeth_hard_start_xmit;
6367 dev->do_ioctl = qeth_do_ioctl;
6368 dev->get_stats = qeth_get_stats;
6369 dev->change_mtu = qeth_change_mtu;
6370 dev->neigh_setup = qeth_neigh_setup;
6371 dev->set_multicast_list = qeth_set_multicast_list;
6372 #ifdef CONFIG_QETH_VLAN
6373 dev->vlan_rx_register = qeth_vlan_rx_register;
6374 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6375 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6377 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6378 dev->rebuild_header = NULL;
6379 dev->hard_header = NULL;
6380 dev->header_cache_update = NULL;
6381 dev->hard_header_cache = NULL;
6383 #ifdef CONFIG_QETH_IPV6
6384 /*IPv6 address autoconfiguration stuff*/
6385 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6386 card->dev->dev_id = card->info.unique_id & 0xffff;
6388 if (card->options.fake_ll &&
6389 (qeth_get_netdev_flags(card) & IFF_NOARP))
6390 dev->hard_header = qeth_fake_header;
6391 dev->hard_header_parse = NULL;
6392 dev->set_mac_address = qeth_layer2_set_mac_address;
6393 dev->flags |= qeth_get_netdev_flags(card);
6394 if ((card->options.fake_broadcast) ||
6395 (card->info.broadcast_capable))
6396 dev->flags |= IFF_BROADCAST;
6397 dev->hard_header_len =
6398 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6399 dev->addr_len = OSA_ADDR_LEN;
6400 dev->mtu = card->info.initial_mtu;
6401 if (card->info.type != QETH_CARD_TYPE_OSN)
6402 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6403 SET_MODULE_OWNER(dev);
6408 qeth_init_func_level(struct qeth_card *card)
6410 if (card->ipato.enabled) {
6411 if (card->info.type == QETH_CARD_TYPE_IQD)
6412 card->info.func_level =
6413 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6415 card->info.func_level =
6416 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6418 if (card->info.type == QETH_CARD_TYPE_IQD)
6419 /*FIXME:why do we have same values for dis and ena for osae??? */
6420 card->info.func_level =
6421 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6423 card->info.func_level =
6424 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6429 * hardsetup card, initialize MPC and QDIO stuff
6432 qeth_hardsetup_card(struct qeth_card *card)
6437 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6441 PRINT_WARN("Retrying to do IDX activates.\n");
6442 ccw_device_set_offline(CARD_DDEV(card));
6443 ccw_device_set_offline(CARD_WDEV(card));
6444 ccw_device_set_offline(CARD_RDEV(card));
6445 ccw_device_set_online(CARD_RDEV(card));
6446 ccw_device_set_online(CARD_WDEV(card));
6447 ccw_device_set_online(CARD_DDEV(card));
6449 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
6450 if (rc == -ERESTARTSYS) {
6451 QETH_DBF_TEXT(setup, 2, "break1");
6454 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6460 if ((rc = qeth_get_unitaddr(card))){
6461 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6464 qeth_init_tokens(card);
6465 qeth_init_func_level(card);
6466 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6467 if (rc == -ERESTARTSYS) {
6468 QETH_DBF_TEXT(setup, 2, "break2");
6471 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6477 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6478 if (rc == -ERESTARTSYS) {
6479 QETH_DBF_TEXT(setup, 2, "break3");
6482 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6488 if ((rc = qeth_mpc_initialize(card))){
6489 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6492 /*network device will be recovered*/
6494 card->dev->hard_header = card->orig_hard_header;
6495 if (card->options.fake_ll &&
6496 (qeth_get_netdev_flags(card) & IFF_NOARP))
6497 card->dev->hard_header = qeth_fake_header;
6500 /* at first set_online allocate netdev */
6501 card->dev = qeth_get_netdevice(card->info.type,
6502 card->info.link_type);
6504 qeth_qdio_clear_card(card, card->info.type !=
6505 QETH_CARD_TYPE_IQD);
6507 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6510 card->dev->priv = card;
6511 card->orig_hard_header = card->dev->hard_header;
6512 card->dev->type = qeth_get_arphdr_type(card->info.type,
6513 card->info.link_type);
6514 card->dev->init = qeth_netdev_init;
6517 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6522 qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6525 struct qeth_ipa_cmd *cmd;
6527 QETH_DBF_TEXT(trace,4,"defadpcb");
6529 cmd = (struct qeth_ipa_cmd *) data;
6530 if (cmd->hdr.return_code == 0){
6531 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6532 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6533 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6534 #ifdef CONFIG_QETH_IPV6
6535 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6536 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6539 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6540 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6541 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6542 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6548 qeth_default_setadapterparms_cb(struct qeth_card *card,
6549 struct qeth_reply *reply,
6552 struct qeth_ipa_cmd *cmd;
6554 QETH_DBF_TEXT(trace,4,"defadpcb");
6556 cmd = (struct qeth_ipa_cmd *) data;
6557 if (cmd->hdr.return_code == 0)
6558 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6565 qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6568 struct qeth_ipa_cmd *cmd;
6570 QETH_DBF_TEXT(trace,3,"quyadpcb");
6572 cmd = (struct qeth_ipa_cmd *) data;
6573 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6574 card->info.link_type =
6575 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6576 card->options.adp.supported_funcs =
6577 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6578 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6582 qeth_query_setadapterparms(struct qeth_card *card)
6585 struct qeth_cmd_buffer *iob;
6587 QETH_DBF_TEXT(trace,3,"queryadp");
6588 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6589 sizeof(struct qeth_ipacmd_setadpparms));
6590 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6595 qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6596 struct qeth_reply *reply,
6599 struct qeth_ipa_cmd *cmd;
6601 QETH_DBF_TEXT(trace,4,"chgmaccb");
6603 cmd = (struct qeth_ipa_cmd *) data;
6604 if (!card->options.layer2 || card->info.guestlan ||
6605 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
6606 memcpy(card->dev->dev_addr,
6607 &cmd->data.setadapterparms.data.change_addr.addr,
6609 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6611 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6616 qeth_setadpparms_change_macaddr(struct qeth_card *card)
6619 struct qeth_cmd_buffer *iob;
6620 struct qeth_ipa_cmd *cmd;
6622 QETH_DBF_TEXT(trace,4,"chgmac");
6624 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6625 sizeof(struct qeth_ipacmd_setadpparms));
6626 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6627 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6628 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6629 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6630 card->dev->dev_addr, OSA_ADDR_LEN);
6631 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6637 qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6640 struct qeth_cmd_buffer *iob;
6641 struct qeth_ipa_cmd *cmd;
6643 QETH_DBF_TEXT(trace,4,"adpmode");
6645 iob = qeth_get_adapter_cmd(card, command,
6646 sizeof(struct qeth_ipacmd_setadpparms));
6647 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6648 cmd->data.setadapterparms.data.mode = mode;
6649 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6655 qeth_setadapter_hstr(struct qeth_card *card)
6659 QETH_DBF_TEXT(trace,4,"adphstr");
6661 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6662 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6663 card->options.broadcast_mode);
6665 PRINT_WARN("couldn't set broadcast mode on "
6667 CARD_BUS_ID(card), rc);
6668 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6669 card->options.macaddr_mode);
6671 PRINT_WARN("couldn't set macaddr mode on "
6672 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6675 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6676 PRINT_WARN("set adapter parameters not available "
6677 "to set broadcast mode, using ALLRINGS "
6678 "on device %s:\n", CARD_BUS_ID(card));
6679 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6680 PRINT_WARN("set adapter parameters not available "
6681 "to set macaddr mode, using NONCANONICAL "
6682 "on device %s:\n", CARD_BUS_ID(card));
6687 qeth_setadapter_parms(struct qeth_card *card)
6691 QETH_DBF_TEXT(setup, 2, "setadprm");
6693 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6694 PRINT_WARN("set adapter parameters not supported "
6697 QETH_DBF_TEXT(setup, 2, " notsupp");
6700 rc = qeth_query_setadapterparms(card);
6702 PRINT_WARN("couldn't set adapter parameters on device %s: "
6703 "x%x\n", CARD_BUS_ID(card), rc);
6706 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6707 rc = qeth_setadpparms_change_macaddr(card);
6709 PRINT_WARN("couldn't get MAC address on "
6711 CARD_BUS_ID(card), rc);
6714 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6715 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6716 rc = qeth_setadapter_hstr(card);
6722 qeth_layer2_initialize(struct qeth_card *card)
6727 QETH_DBF_TEXT(setup, 2, "doL2init");
6728 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6730 rc = qeth_query_setadapterparms(card);
6732 PRINT_WARN("could not query adapter parameters on device %s: "
6733 "x%x\n", CARD_BUS_ID(card), rc);
6736 rc = qeth_setadpparms_change_macaddr(card);
6738 PRINT_WARN("couldn't get MAC address on "
6740 CARD_BUS_ID(card), rc);
6741 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6744 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6746 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6748 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6754 qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6755 enum qeth_prot_versions prot)
6758 struct qeth_cmd_buffer *iob;
6760 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6761 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6767 qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6771 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6773 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6778 qeth_send_stoplan(struct qeth_card *card)
6783 * TODO: according to the IPA format document page 14,
6784 * TCP/IP (we!) never issue a STOPLAN
6787 QETH_DBF_TEXT(trace, 2, "stoplan");
6789 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6794 qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6797 struct qeth_ipa_cmd *cmd;
6799 QETH_DBF_TEXT(setup, 2, "qipasscb");
6801 cmd = (struct qeth_ipa_cmd *) data;
6802 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6803 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6804 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6805 /* Disable IPV6 support hard coded for Hipersockets */
6806 if(card->info.type == QETH_CARD_TYPE_IQD)
6807 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
6809 #ifdef CONFIG_QETH_IPV6
6810 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6811 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6814 QETH_DBF_TEXT(setup, 2, "suppenbl");
6815 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6816 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6821 qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6824 struct qeth_cmd_buffer *iob;
6826 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6827 if (card->options.layer2) {
6828 QETH_DBF_TEXT(setup, 2, "noprmly2");
6832 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6833 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6837 static struct qeth_cmd_buffer *
6838 qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6839 __u16 cmd_code, __u16 len,
6840 enum qeth_prot_versions prot)
6842 struct qeth_cmd_buffer *iob;
6843 struct qeth_ipa_cmd *cmd;
6845 QETH_DBF_TEXT(trace,4,"getasscm");
6846 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6848 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6849 cmd->data.setassparms.hdr.assist_no = ipa_func;
6850 cmd->data.setassparms.hdr.length = 8 + len;
6851 cmd->data.setassparms.hdr.command_code = cmd_code;
6852 cmd->data.setassparms.hdr.return_code = 0;
6853 cmd->data.setassparms.hdr.seq_no = 0;
6859 qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6860 __u16 len, long data,
6862 (struct qeth_card *,struct qeth_reply *,unsigned long),
6866 struct qeth_ipa_cmd *cmd;
6868 QETH_DBF_TEXT(trace,4,"sendassp");
6870 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6871 if (len <= sizeof(__u32))
6872 cmd->data.setassparms.data.flags_32bit = (__u32) data;
6873 else /* (len > sizeof(__u32)) */
6874 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6876 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6880 #ifdef CONFIG_QETH_IPV6
6882 qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6883 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6887 struct qeth_cmd_buffer *iob;
6889 QETH_DBF_TEXT(trace,4,"simassp6");
6890 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6892 rc = qeth_send_setassparms(card, iob, 0, 0,
6893 qeth_default_setassparms_cb, NULL);
6899 qeth_send_simple_setassparms(struct qeth_card *card,
6900 enum qeth_ipa_funcs ipa_func,
6901 __u16 cmd_code, long data)
6905 struct qeth_cmd_buffer *iob;
6907 QETH_DBF_TEXT(trace,4,"simassp4");
6909 length = sizeof(__u32);
6910 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6911 length, QETH_PROT_IPV4);
6912 rc = qeth_send_setassparms(card, iob, length, data,
6913 qeth_default_setassparms_cb, NULL);
6918 qeth_start_ipa_arp_processing(struct qeth_card *card)
6922 QETH_DBF_TEXT(trace,3,"ipaarp");
6924 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6925 PRINT_WARN("ARP processing not supported "
6926 "on %s!\n", QETH_CARD_IFNAME(card));
6929 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6930 IPA_CMD_ASS_START, 0);
6932 PRINT_WARN("Could not start ARP processing "
6933 "assist on %s: 0x%x\n",
6934 QETH_CARD_IFNAME(card), rc);
6940 qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6944 QETH_DBF_TEXT(trace,3,"ipaipfrg");
6946 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
6947 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
6948 QETH_CARD_IFNAME(card));
6952 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
6953 IPA_CMD_ASS_START, 0);
6955 PRINT_WARN("Could not start Hardware IP fragmentation "
6956 "assist on %s: 0x%x\n",
6957 QETH_CARD_IFNAME(card), rc);
6959 PRINT_INFO("Hardware IP fragmentation enabled \n");
6964 qeth_start_ipa_source_mac(struct qeth_card *card)
6968 QETH_DBF_TEXT(trace,3,"stsrcmac");
6970 if (!card->options.fake_ll)
6973 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
6974 PRINT_INFO("Inbound source address not "
6975 "supported on %s\n", QETH_CARD_IFNAME(card));
6979 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
6980 IPA_CMD_ASS_START, 0);
6982 PRINT_WARN("Could not start inbound source "
6983 "assist on %s: 0x%x\n",
6984 QETH_CARD_IFNAME(card), rc);
6989 qeth_start_ipa_vlan(struct qeth_card *card)
6993 QETH_DBF_TEXT(trace,3,"strtvlan");
6995 #ifdef CONFIG_QETH_VLAN
6996 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
6997 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
7001 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
7002 IPA_CMD_ASS_START,0);
7004 PRINT_WARN("Could not start vlan "
7005 "assist on %s: 0x%x\n",
7006 QETH_CARD_IFNAME(card), rc);
7008 PRINT_INFO("VLAN enabled \n");
7009 card->dev->features |=
7010 NETIF_F_HW_VLAN_FILTER |
7011 NETIF_F_HW_VLAN_TX |
7014 #endif /* QETH_VLAN */
7019 qeth_start_ipa_multicast(struct qeth_card *card)
7023 QETH_DBF_TEXT(trace,3,"stmcast");
7025 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7026 PRINT_WARN("Multicast not supported on %s\n",
7027 QETH_CARD_IFNAME(card));
7031 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7032 IPA_CMD_ASS_START,0);
7034 PRINT_WARN("Could not start multicast "
7035 "assist on %s: rc=%i\n",
7036 QETH_CARD_IFNAME(card), rc);
7038 PRINT_INFO("Multicast enabled\n");
7039 card->dev->flags |= IFF_MULTICAST;
7044 #ifdef CONFIG_QETH_IPV6
7046 qeth_softsetup_ipv6(struct qeth_card *card)
7050 QETH_DBF_TEXT(trace,3,"softipv6");
7052 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7054 PRINT_ERR("IPv6 startlan failed on %s\n",
7055 QETH_CARD_IFNAME(card));
7058 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7060 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7061 QETH_CARD_IFNAME(card));
7064 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7065 IPA_CMD_ASS_START, 3);
7067 PRINT_WARN("IPv6 start assist (version 4) failed "
7069 QETH_CARD_IFNAME(card), rc);
7072 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7075 PRINT_WARN("IPV6 start assist (version 6) failed "
7077 QETH_CARD_IFNAME(card), rc);
7080 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7083 PRINT_WARN("Could not enable passthrough "
7085 QETH_CARD_IFNAME(card), rc);
7088 PRINT_INFO("IPV6 enabled \n");
7095 qeth_start_ipa_ipv6(struct qeth_card *card)
7098 #ifdef CONFIG_QETH_IPV6
7099 QETH_DBF_TEXT(trace,3,"strtipv6");
7101 if (!qeth_is_supported(card, IPA_IPV6)) {
7102 PRINT_WARN("IPv6 not supported on %s\n",
7103 QETH_CARD_IFNAME(card));
7106 rc = qeth_softsetup_ipv6(card);
7112 qeth_start_ipa_broadcast(struct qeth_card *card)
7116 QETH_DBF_TEXT(trace,3,"stbrdcst");
7117 card->info.broadcast_capable = 0;
7118 if (!qeth_is_supported(card, IPA_FILTERING)) {
7119 PRINT_WARN("Broadcast not supported on %s\n",
7120 QETH_CARD_IFNAME(card));
7124 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7125 IPA_CMD_ASS_START, 0);
7127 PRINT_WARN("Could not enable broadcasting filtering "
7129 QETH_CARD_IFNAME(card), rc);
7133 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7134 IPA_CMD_ASS_CONFIGURE, 1);
7136 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7137 QETH_CARD_IFNAME(card), rc);
7140 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7141 PRINT_INFO("Broadcast enabled \n");
7142 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7143 IPA_CMD_ASS_ENABLE, 1);
7145 PRINT_WARN("Could not set up broadcast echo filtering on "
7146 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7149 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7151 if (card->info.broadcast_capable)
7152 card->dev->flags |= IFF_BROADCAST;
7154 card->dev->flags &= ~IFF_BROADCAST;
7159 qeth_send_checksum_command(struct qeth_card *card)
7163 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7164 IPA_CMD_ASS_START, 0);
7166 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7167 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7168 QETH_CARD_IFNAME(card), rc);
7171 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7173 card->info.csum_mask);
7175 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7176 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7177 QETH_CARD_IFNAME(card), rc);
7184 qeth_start_ipa_checksum(struct qeth_card *card)
7188 QETH_DBF_TEXT(trace,3,"strtcsum");
7190 if (card->options.checksum_type == NO_CHECKSUMMING) {
7191 PRINT_WARN("Using no checksumming on %s.\n",
7192 QETH_CARD_IFNAME(card));
7195 if (card->options.checksum_type == SW_CHECKSUMMING) {
7196 PRINT_WARN("Using SW checksumming on %s.\n",
7197 QETH_CARD_IFNAME(card));
7200 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7201 PRINT_WARN("Inbound HW Checksumming not "
7202 "supported on %s,\ncontinuing "
7203 "using Inbound SW Checksumming\n",
7204 QETH_CARD_IFNAME(card));
7205 card->options.checksum_type = SW_CHECKSUMMING;
7208 rc = qeth_send_checksum_command(card);
7210 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7216 qeth_start_ipa_tso(struct qeth_card *card)
7220 QETH_DBF_TEXT(trace,3,"sttso");
7222 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7223 PRINT_WARN("Outbound TSO not supported on %s\n",
7224 QETH_CARD_IFNAME(card));
7227 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7228 IPA_CMD_ASS_START,0);
7230 PRINT_WARN("Could not start outbound TSO "
7231 "assist on %s: rc=%i\n",
7232 QETH_CARD_IFNAME(card), rc);
7234 PRINT_INFO("Outbound TSO enabled\n");
7236 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7237 card->options.large_send = QETH_LARGE_SEND_NO;
7238 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
7244 qeth_start_ipassists(struct qeth_card *card)
7246 QETH_DBF_TEXT(trace,3,"strtipas");
7247 qeth_start_ipa_arp_processing(card); /* go on*/
7248 qeth_start_ipa_ip_fragmentation(card); /* go on*/
7249 qeth_start_ipa_source_mac(card); /* go on*/
7250 qeth_start_ipa_vlan(card); /* go on*/
7251 qeth_start_ipa_multicast(card); /* go on*/
7252 qeth_start_ipa_ipv6(card); /* go on*/
7253 qeth_start_ipa_broadcast(card); /* go on*/
7254 qeth_start_ipa_checksum(card); /* go on*/
7255 qeth_start_ipa_tso(card); /* go on*/
7260 qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7261 enum qeth_prot_versions prot)
7264 struct qeth_ipa_cmd *cmd;
7265 struct qeth_cmd_buffer *iob;
7267 QETH_DBF_TEXT(trace,4,"setroutg");
7268 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7269 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7270 cmd->data.setrtg.type = (type);
7271 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7278 qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7279 enum qeth_prot_versions prot)
7281 if (card->info.type == QETH_CARD_TYPE_IQD) {
7284 case PRIMARY_CONNECTOR:
7285 case SECONDARY_CONNECTOR:
7286 case MULTICAST_ROUTER:
7294 case PRIMARY_ROUTER:
7295 case SECONDARY_ROUTER:
7297 case MULTICAST_ROUTER:
7298 if (qeth_is_ipafunc_supported(card, prot,
7306 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7307 "Router status set to 'no router'.\n",
7308 ((*type == PRIMARY_ROUTER)? "primary router" :
7309 (*type == SECONDARY_ROUTER)? "secondary router" :
7310 (*type == PRIMARY_CONNECTOR)? "primary connector" :
7311 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7312 (*type == MULTICAST_ROUTER)? "multicast router" :
7319 qeth_setrouting_v4(struct qeth_card *card)
7323 QETH_DBF_TEXT(trace,3,"setrtg4");
7325 qeth_correct_routing_type(card, &card->options.route4.type,
7328 rc = qeth_send_setrouting(card, card->options.route4.type,
7331 card->options.route4.type = NO_ROUTER;
7332 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7333 "Type set to 'no router'.\n",
7334 rc, QETH_CARD_IFNAME(card));
7340 qeth_setrouting_v6(struct qeth_card *card)
7344 QETH_DBF_TEXT(trace,3,"setrtg6");
7345 #ifdef CONFIG_QETH_IPV6
7347 if (!qeth_is_supported(card, IPA_IPV6))
7349 qeth_correct_routing_type(card, &card->options.route6.type,
7352 rc = qeth_send_setrouting(card, card->options.route6.type,
7355 card->options.route6.type = NO_ROUTER;
7356 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7357 "Type set to 'no router'.\n",
7358 rc, QETH_CARD_IFNAME(card));
7365 qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
7369 if (card->dev == NULL) {
7370 card->options.large_send = type;
7373 if (card->state == CARD_STATE_UP)
7374 netif_tx_disable(card->dev);
7375 card->options.large_send = type;
7376 switch (card->options.large_send) {
7377 case QETH_LARGE_SEND_EDDP:
7378 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7380 case QETH_LARGE_SEND_TSO:
7381 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7382 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7384 PRINT_WARN("TSO not supported on %s. "
7385 "large_send set to 'no'.\n",
7387 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7388 card->options.large_send = QETH_LARGE_SEND_NO;
7392 default: /* includes QETH_LARGE_SEND_NO */
7393 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7396 if (card->state == CARD_STATE_UP)
7397 netif_wake_queue(card->dev);
7402 * softsetup card: init IPA stuff
7405 qeth_softsetup_card(struct qeth_card *card)
7409 QETH_DBF_TEXT(setup, 2, "softsetp");
7411 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7412 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7414 PRINT_WARN("LAN on card %s if offline! "
7415 "Continuing softsetup.\n",
7417 card->lan_online = 0;
7421 card->lan_online = 1;
7422 if (card->info.type==QETH_CARD_TYPE_OSN)
7424 qeth_set_large_send(card, card->options.large_send);
7425 if (card->options.layer2) {
7426 card->dev->features |=
7427 NETIF_F_HW_VLAN_FILTER |
7428 NETIF_F_HW_VLAN_TX |
7430 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7431 card->info.broadcast_capable=1;
7432 if ((rc = qeth_layer2_initialize(card))) {
7433 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7436 #ifdef CONFIG_QETH_VLAN
7437 qeth_layer2_process_vlans(card, 0);
7441 if ((rc = qeth_setadapter_parms(card)))
7442 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7443 if ((rc = qeth_start_ipassists(card)))
7444 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7445 if ((rc = qeth_setrouting_v4(card)))
7446 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7447 if ((rc = qeth_setrouting_v6(card)))
7448 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7450 netif_tx_disable(card->dev);
7454 #ifdef CONFIG_QETH_IPV6
7456 qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7459 struct qeth_ipa_cmd *cmd;
7461 cmd = (struct qeth_ipa_cmd *) data;
7462 if (cmd->hdr.return_code == 0)
7463 card->info.unique_id = *((__u16 *)
7464 &cmd->data.create_destroy_addr.unique_id[6]);
7466 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7467 UNIQUE_ID_NOT_BY_CARD;
7468 PRINT_WARN("couldn't get a unique id from the card on device "
7469 "%s (result=x%x), using default id. ipv6 "
7470 "autoconfig on other lpars may lead to duplicate "
7471 "ip addresses. please use manually "
7472 "configured ones.\n",
7473 CARD_BUS_ID(card), cmd->hdr.return_code);
7480 qeth_put_unique_id(struct qeth_card *card)
7484 #ifdef CONFIG_QETH_IPV6
7485 struct qeth_cmd_buffer *iob;
7486 struct qeth_ipa_cmd *cmd;
7488 QETH_DBF_TEXT(trace,2,"puniqeid");
7490 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7491 UNIQUE_ID_NOT_BY_CARD)
7493 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7495 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7496 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7497 card->info.unique_id;
7498 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7499 card->dev->dev_addr, OSA_ADDR_LEN);
7500 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7502 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7503 UNIQUE_ID_NOT_BY_CARD;
7512 qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7514 struct qeth_ipaddr *addr, *tmp;
7515 unsigned long flags;
7517 QETH_DBF_TEXT(trace,4,"clearip");
7518 spin_lock_irqsave(&card->ip_lock, flags);
7519 /* clear todo list */
7520 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7521 list_del(&addr->entry);
7525 while (!list_empty(&card->ip_list)) {
7526 addr = list_entry(card->ip_list.next,
7527 struct qeth_ipaddr, entry);
7528 list_del_init(&addr->entry);
7530 spin_unlock_irqrestore(&card->ip_lock, flags);
7531 qeth_deregister_addr_entry(card, addr);
7532 spin_lock_irqsave(&card->ip_lock, flags);
7534 if (!recover || addr->is_multicast) {
7538 list_add_tail(&addr->entry, card->ip_tbd_list);
7540 spin_unlock_irqrestore(&card->ip_lock, flags);
7544 qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7545 int clear_start_mask)
7547 unsigned long flags;
7549 spin_lock_irqsave(&card->thread_mask_lock, flags);
7550 card->thread_allowed_mask = threads;
7551 if (clear_start_mask)
7552 card->thread_start_mask &= threads;
7553 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7554 wake_up(&card->wait_q);
7558 qeth_threads_running(struct qeth_card *card, unsigned long threads)
7560 unsigned long flags;
7563 spin_lock_irqsave(&card->thread_mask_lock, flags);
7564 rc = (card->thread_running_mask & threads);
7565 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7570 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7572 return wait_event_interruptible(card->wait_q,
7573 qeth_threads_running(card, threads) == 0);
7577 qeth_stop_card(struct qeth_card *card, int recovery_mode)
7581 QETH_DBF_TEXT(setup ,2,"stopcard");
7582 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7584 qeth_set_allowed_threads(card, 0, 1);
7585 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7586 return -ERESTARTSYS;
7587 if (card->read.state == CH_STATE_UP &&
7588 card->write.state == CH_STATE_UP &&
7589 (card->state == CARD_STATE_UP)) {
7590 if (recovery_mode &&
7591 card->info.type != QETH_CARD_TYPE_OSN) {
7592 qeth_stop(card->dev);
7595 dev_close(card->dev);
7598 if (!card->use_hard_stop) {
7599 __u8 *mac = &card->dev->dev_addr[0];
7600 rc = qeth_layer2_send_delmac(card, mac);
7601 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7602 if ((rc = qeth_send_stoplan(card)))
7603 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7605 card->state = CARD_STATE_SOFTSETUP;
7607 if (card->state == CARD_STATE_SOFTSETUP) {
7608 #ifdef CONFIG_QETH_VLAN
7609 if (card->options.layer2)
7610 qeth_layer2_process_vlans(card, 1);
7612 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7613 qeth_clear_ipacmd_list(card);
7614 card->state = CARD_STATE_HARDSETUP;
7616 if (card->state == CARD_STATE_HARDSETUP) {
7617 if ((!card->use_hard_stop) &&
7618 (!card->options.layer2))
7619 if ((rc = qeth_put_unique_id(card)))
7620 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7621 qeth_qdio_clear_card(card, 0);
7622 qeth_clear_qdio_buffers(card);
7623 qeth_clear_working_pool_list(card);
7624 card->state = CARD_STATE_DOWN;
7626 if (card->state == CARD_STATE_DOWN) {
7627 qeth_clear_cmd_buffers(&card->read);
7628 qeth_clear_cmd_buffers(&card->write);
7630 card->use_hard_stop = 0;
7636 qeth_get_unique_id(struct qeth_card *card)
7639 #ifdef CONFIG_QETH_IPV6
7640 struct qeth_cmd_buffer *iob;
7641 struct qeth_ipa_cmd *cmd;
7643 QETH_DBF_TEXT(setup, 2, "guniqeid");
7645 if (!qeth_is_supported(card,IPA_IPV6)) {
7646 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7647 UNIQUE_ID_NOT_BY_CARD;
7651 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7653 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7654 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7655 card->info.unique_id;
7657 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7659 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7660 UNIQUE_ID_NOT_BY_CARD;
7665 qeth_print_status_with_portname(struct qeth_card *card)
7670 sprintf(dbf_text, "%s", card->info.portname + 1);
7671 for (i = 0; i < 8; i++)
7673 (char) _ebcasc[(__u8) dbf_text[i]];
7675 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7676 "with link type %s (portname: %s)\n",
7680 qeth_get_cardname(card),
7681 (card->info.mcl_level[0]) ? " (level: " : "",
7682 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7683 (card->info.mcl_level[0]) ? ")" : "",
7684 qeth_get_cardname_short(card),
7690 qeth_print_status_no_portname(struct qeth_card *card)
7692 if (card->info.portname[0])
7693 printk("qeth: Device %s/%s/%s is a%s "
7694 "card%s%s%s\nwith link type %s "
7695 "(no portname needed by interface).\n",
7699 qeth_get_cardname(card),
7700 (card->info.mcl_level[0]) ? " (level: " : "",
7701 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7702 (card->info.mcl_level[0]) ? ")" : "",
7703 qeth_get_cardname_short(card));
7705 printk("qeth: Device %s/%s/%s is a%s "
7706 "card%s%s%s\nwith link type %s.\n",
7710 qeth_get_cardname(card),
7711 (card->info.mcl_level[0]) ? " (level: " : "",
7712 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7713 (card->info.mcl_level[0]) ? ")" : "",
7714 qeth_get_cardname_short(card));
7718 qeth_print_status_message(struct qeth_card *card)
7720 switch (card->info.type) {
7721 case QETH_CARD_TYPE_OSAE:
7722 /* VM will use a non-zero first character
7723 * to indicate a HiperSockets like reporting
7724 * of the level OSA sets the first character to zero
7726 if (!card->info.mcl_level[0]) {
7727 sprintf(card->info.mcl_level,"%02x%02x",
7728 card->info.mcl_level[2],
7729 card->info.mcl_level[3]);
7731 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7735 case QETH_CARD_TYPE_IQD:
7736 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7737 card->info.mcl_level[0]];
7738 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7739 card->info.mcl_level[1]];
7740 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7741 card->info.mcl_level[2]];
7742 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7743 card->info.mcl_level[3]];
7744 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7747 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7749 if (card->info.portname_required)
7750 qeth_print_status_with_portname(card);
7752 qeth_print_status_no_portname(card);
7756 qeth_register_netdev(struct qeth_card *card)
7758 QETH_DBF_TEXT(setup, 3, "regnetd");
7759 if (card->dev->reg_state != NETREG_UNINITIALIZED)
7762 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7763 return register_netdev(card->dev);
7767 qeth_start_again(struct qeth_card *card, int recovery_mode)
7769 QETH_DBF_TEXT(setup ,2, "startag");
7771 if (recovery_mode &&
7772 card->info.type != QETH_CARD_TYPE_OSN) {
7773 qeth_open(card->dev);
7776 dev_open(card->dev);
7779 /* this also sets saved unicast addresses */
7780 qeth_set_multicast_list(card->dev);
7784 /* Layer 2 specific stuff */
7785 #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7786 if (card->options.option == value) { \
7787 PRINT_ERR("%s not supported with layer 2 " \
7788 "functionality, ignoring option on read" \
7789 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7790 card->options.option = reset_value; \
7792 #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7793 if (card->options.option != value) { \
7794 PRINT_ERR("%s not supported with layer 2 " \
7795 "functionality, ignoring option on read" \
7796 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7797 card->options.option = reset_value; \
7801 static void qeth_make_parameters_consistent(struct qeth_card *card)
7804 if (card->options.layer2 == 0)
7806 if (card->info.type == QETH_CARD_TYPE_OSN)
7808 if (card->info.type == QETH_CARD_TYPE_IQD) {
7809 PRINT_ERR("Device %s does not support layer 2 functionality." \
7810 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7811 card->options.layer2 = 0;
7814 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7815 "Routing options are");
7816 #ifdef CONFIG_QETH_IPV6
7817 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7818 "Routing options are");
7820 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7821 QETH_CHECKSUM_DEFAULT,
7822 "Checksumming options are");
7823 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7824 QETH_TR_BROADCAST_ALLRINGS,
7825 "Broadcast mode options are");
7826 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7827 QETH_TR_MACADDR_NONCANONICAL,
7828 "Canonical MAC addr options are");
7829 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7830 "Broadcast faking options are");
7831 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7832 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7833 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
7838 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
7840 struct qeth_card *card = gdev->dev.driver_data;
7842 enum qeth_card_states recover_flag;
7845 QETH_DBF_TEXT(setup ,2, "setonlin");
7846 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7848 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7849 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7850 PRINT_WARN("set_online of card %s interrupted by user!\n",
7852 return -ERESTARTSYS;
7855 recover_flag = card->state;
7856 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7857 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7858 (rc = ccw_device_set_online(CARD_DDEV(card)))){
7859 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7863 qeth_make_parameters_consistent(card);
7865 if ((rc = qeth_hardsetup_card(card))){
7866 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7869 card->state = CARD_STATE_HARDSETUP;
7871 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7872 rc = qeth_get_unique_id(card);
7874 if (rc && card->options.layer2 == 0) {
7875 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7878 qeth_print_status_message(card);
7879 if ((rc = qeth_register_netdev(card))){
7880 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7883 if ((rc = qeth_softsetup_card(card))){
7884 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7888 if ((rc = qeth_init_qdio_queues(card))){
7889 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7892 card->state = CARD_STATE_SOFTSETUP;
7893 netif_carrier_on(card->dev);
7895 qeth_set_allowed_threads(card, 0xffffffff, 0);
7896 if (recover_flag == CARD_STATE_RECOVER)
7897 qeth_start_again(card, recovery_mode);
7898 qeth_notify_processes();
7901 card->use_hard_stop = 1;
7902 qeth_stop_card(card, 0);
7903 ccw_device_set_offline(CARD_DDEV(card));
7904 ccw_device_set_offline(CARD_WDEV(card));
7905 ccw_device_set_offline(CARD_RDEV(card));
7906 if (recover_flag == CARD_STATE_RECOVER)
7907 card->state = CARD_STATE_RECOVER;
7909 card->state = CARD_STATE_DOWN;
7914 qeth_set_online(struct ccwgroup_device *gdev)
7916 return __qeth_set_online(gdev, 0);
7919 static struct ccw_device_id qeth_ids[] = {
7920 {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
7921 {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
7922 {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
7925 MODULE_DEVICE_TABLE(ccw, qeth_ids);
7927 struct device *qeth_root_dev = NULL;
7929 struct ccwgroup_driver qeth_ccwgroup_driver = {
7930 .owner = THIS_MODULE,
7932 .driver_id = 0xD8C5E3C8,
7933 .probe = qeth_probe_device,
7934 .remove = qeth_remove_device,
7935 .set_online = qeth_set_online,
7936 .set_offline = qeth_set_offline,
7939 struct ccw_driver qeth_ccw_driver = {
7942 .probe = ccwgroup_probe_ccwdev,
7943 .remove = ccwgroup_remove_ccwdev,
7948 qeth_unregister_dbf_views(void)
7951 debug_unregister(qeth_dbf_setup);
7953 debug_unregister(qeth_dbf_qerr);
7955 debug_unregister(qeth_dbf_sense);
7957 debug_unregister(qeth_dbf_misc);
7959 debug_unregister(qeth_dbf_data);
7960 if (qeth_dbf_control)
7961 debug_unregister(qeth_dbf_control);
7963 debug_unregister(qeth_dbf_trace);
7966 qeth_register_dbf_views(void)
7968 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
7969 QETH_DBF_SETUP_PAGES,
7970 QETH_DBF_SETUP_NR_AREAS,
7971 QETH_DBF_SETUP_LEN);
7972 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
7973 QETH_DBF_MISC_PAGES,
7974 QETH_DBF_MISC_NR_AREAS,
7976 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
7977 QETH_DBF_DATA_PAGES,
7978 QETH_DBF_DATA_NR_AREAS,
7980 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
7981 QETH_DBF_CONTROL_PAGES,
7982 QETH_DBF_CONTROL_NR_AREAS,
7983 QETH_DBF_CONTROL_LEN);
7984 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
7985 QETH_DBF_SENSE_PAGES,
7986 QETH_DBF_SENSE_NR_AREAS,
7987 QETH_DBF_SENSE_LEN);
7988 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
7989 QETH_DBF_QERR_PAGES,
7990 QETH_DBF_QERR_NR_AREAS,
7992 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
7993 QETH_DBF_TRACE_PAGES,
7994 QETH_DBF_TRACE_NR_AREAS,
7995 QETH_DBF_TRACE_LEN);
7997 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
7998 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
7999 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
8000 (qeth_dbf_trace == NULL)) {
8001 qeth_unregister_dbf_views();
8004 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
8005 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
8007 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
8008 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
8010 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
8011 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
8013 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
8014 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
8016 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
8017 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8019 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8020 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8022 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8023 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8028 #ifdef CONFIG_QETH_IPV6
8029 extern struct neigh_table arp_tbl;
8030 static struct neigh_ops *arp_direct_ops;
8031 static int (*qeth_old_arp_constructor) (struct neighbour *);
8033 static struct neigh_ops arp_direct_ops_template = {
8036 .error_report = NULL,
8037 .output = dev_queue_xmit,
8038 .connected_output = dev_queue_xmit,
8039 .hh_output = dev_queue_xmit,
8040 .queue_xmit = dev_queue_xmit
8044 qeth_arp_constructor(struct neighbour *neigh)
8046 struct net_device *dev = neigh->dev;
8047 struct in_device *in_dev;
8048 struct neigh_parms *parms;
8049 struct qeth_card *card;
8051 card = qeth_get_card_from_dev(dev);
8054 if((card->options.layer2) ||
8055 (card->dev->hard_header == qeth_fake_header))
8059 in_dev = __in_dev_get_rcu(dev);
8060 if (in_dev == NULL) {
8065 parms = in_dev->arp_parms;
8066 __neigh_parms_put(neigh->parms);
8067 neigh->parms = neigh_parms_clone(parms);
8070 neigh->type = inet_addr_type(*(u32 *) neigh->primary_key);
8071 neigh->nud_state = NUD_NOARP;
8072 neigh->ops = arp_direct_ops;
8073 neigh->output = neigh->ops->queue_xmit;
8076 return qeth_old_arp_constructor(neigh);
8078 #endif /*CONFIG_QETH_IPV6*/
8081 * IP address takeover related functions
8084 qeth_clear_ipato_list(struct qeth_card *card)
8086 struct qeth_ipato_entry *ipatoe, *tmp;
8087 unsigned long flags;
8089 spin_lock_irqsave(&card->ip_lock, flags);
8090 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8091 list_del(&ipatoe->entry);
8094 spin_unlock_irqrestore(&card->ip_lock, flags);
8098 qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8100 struct qeth_ipato_entry *ipatoe;
8101 unsigned long flags;
8104 QETH_DBF_TEXT(trace, 2, "addipato");
8105 spin_lock_irqsave(&card->ip_lock, flags);
8106 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8107 if (ipatoe->proto != new->proto)
8109 if (!memcmp(ipatoe->addr, new->addr,
8110 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8111 (ipatoe->mask_bits == new->mask_bits)){
8112 PRINT_WARN("ipato entry already exists!\n");
8118 list_add_tail(&new->entry, &card->ipato.entries);
8120 spin_unlock_irqrestore(&card->ip_lock, flags);
8125 qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8126 u8 *addr, int mask_bits)
8128 struct qeth_ipato_entry *ipatoe, *tmp;
8129 unsigned long flags;
8131 QETH_DBF_TEXT(trace, 2, "delipato");
8132 spin_lock_irqsave(&card->ip_lock, flags);
8133 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8134 if (ipatoe->proto != proto)
8136 if (!memcmp(ipatoe->addr, addr,
8137 (proto == QETH_PROT_IPV4)? 4:16) &&
8138 (ipatoe->mask_bits == mask_bits)){
8139 list_del(&ipatoe->entry);
8143 spin_unlock_irqrestore(&card->ip_lock, flags);
8147 qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8152 for (i = 0; i < len; ++i){
8154 for (j = 7; j >= 0; --j){
8155 bits[i*8 + j] = octet & 1;
8162 qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8164 struct qeth_ipato_entry *ipatoe;
8165 u8 addr_bits[128] = {0, };
8166 u8 ipatoe_bits[128] = {0, };
8169 if (!card->ipato.enabled)
8172 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8173 (addr->proto == QETH_PROT_IPV4)? 4:16);
8174 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8175 if (addr->proto != ipatoe->proto)
8177 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8178 (ipatoe->proto==QETH_PROT_IPV4) ?
8180 if (addr->proto == QETH_PROT_IPV4)
8181 rc = !memcmp(addr_bits, ipatoe_bits,
8182 min(32, ipatoe->mask_bits));
8184 rc = !memcmp(addr_bits, ipatoe_bits,
8185 min(128, ipatoe->mask_bits));
8190 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8192 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8199 * VIPA related functions
8202 qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8205 struct qeth_ipaddr *ipaddr;
8206 unsigned long flags;
8209 ipaddr = qeth_get_addr_buffer(proto);
8211 if (proto == QETH_PROT_IPV4){
8212 QETH_DBF_TEXT(trace, 2, "addvipa4");
8213 memcpy(&ipaddr->u.a4.addr, addr, 4);
8214 ipaddr->u.a4.mask = 0;
8215 #ifdef CONFIG_QETH_IPV6
8216 } else if (proto == QETH_PROT_IPV6){
8217 QETH_DBF_TEXT(trace, 2, "addvipa6");
8218 memcpy(&ipaddr->u.a6.addr, addr, 16);
8219 ipaddr->u.a6.pfxlen = 0;
8222 ipaddr->type = QETH_IP_TYPE_VIPA;
8223 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8224 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8227 spin_lock_irqsave(&card->ip_lock, flags);
8228 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8229 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8231 spin_unlock_irqrestore(&card->ip_lock, flags);
8233 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8236 if (!qeth_add_ip(card, ipaddr))
8238 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8239 schedule_work(&card->kernel_thread_starter);
8244 qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8247 struct qeth_ipaddr *ipaddr;
8249 ipaddr = qeth_get_addr_buffer(proto);
8251 if (proto == QETH_PROT_IPV4){
8252 QETH_DBF_TEXT(trace, 2, "delvipa4");
8253 memcpy(&ipaddr->u.a4.addr, addr, 4);
8254 ipaddr->u.a4.mask = 0;
8255 #ifdef CONFIG_QETH_IPV6
8256 } else if (proto == QETH_PROT_IPV6){
8257 QETH_DBF_TEXT(trace, 2, "delvipa6");
8258 memcpy(&ipaddr->u.a6.addr, addr, 16);
8259 ipaddr->u.a6.pfxlen = 0;
8262 ipaddr->type = QETH_IP_TYPE_VIPA;
8265 if (!qeth_delete_ip(card, ipaddr))
8267 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8268 schedule_work(&card->kernel_thread_starter);
8272 * proxy ARP related functions
8275 qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8278 struct qeth_ipaddr *ipaddr;
8279 unsigned long flags;
8282 ipaddr = qeth_get_addr_buffer(proto);
8284 if (proto == QETH_PROT_IPV4){
8285 QETH_DBF_TEXT(trace, 2, "addrxip4");
8286 memcpy(&ipaddr->u.a4.addr, addr, 4);
8287 ipaddr->u.a4.mask = 0;
8288 #ifdef CONFIG_QETH_IPV6
8289 } else if (proto == QETH_PROT_IPV6){
8290 QETH_DBF_TEXT(trace, 2, "addrxip6");
8291 memcpy(&ipaddr->u.a6.addr, addr, 16);
8292 ipaddr->u.a6.pfxlen = 0;
8295 ipaddr->type = QETH_IP_TYPE_RXIP;
8296 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8297 ipaddr->del_flags = 0;
8300 spin_lock_irqsave(&card->ip_lock, flags);
8301 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8302 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8304 spin_unlock_irqrestore(&card->ip_lock, flags);
8306 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8309 if (!qeth_add_ip(card, ipaddr))
8311 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8312 schedule_work(&card->kernel_thread_starter);
8317 qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8320 struct qeth_ipaddr *ipaddr;
8322 ipaddr = qeth_get_addr_buffer(proto);
8324 if (proto == QETH_PROT_IPV4){
8325 QETH_DBF_TEXT(trace, 2, "addrxip4");
8326 memcpy(&ipaddr->u.a4.addr, addr, 4);
8327 ipaddr->u.a4.mask = 0;
8328 #ifdef CONFIG_QETH_IPV6
8329 } else if (proto == QETH_PROT_IPV6){
8330 QETH_DBF_TEXT(trace, 2, "addrxip6");
8331 memcpy(&ipaddr->u.a6.addr, addr, 16);
8332 ipaddr->u.a6.pfxlen = 0;
8335 ipaddr->type = QETH_IP_TYPE_RXIP;
8338 if (!qeth_delete_ip(card, ipaddr))
8340 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8341 schedule_work(&card->kernel_thread_starter);
8348 qeth_ip_event(struct notifier_block *this,
8349 unsigned long event,void *ptr)
8351 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8352 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8353 struct qeth_ipaddr *addr;
8354 struct qeth_card *card;
8356 QETH_DBF_TEXT(trace,3,"ipevent");
8357 card = qeth_get_card_from_dev(dev);
8360 if (card->options.layer2)
8363 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8365 addr->u.a4.addr = ifa->ifa_address;
8366 addr->u.a4.mask = ifa->ifa_mask;
8367 addr->type = QETH_IP_TYPE_NORMAL;
8373 if (!qeth_add_ip(card, addr))
8377 if (!qeth_delete_ip(card, addr))
8383 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8384 schedule_work(&card->kernel_thread_starter);
8389 static struct notifier_block qeth_ip_notifier = {
8394 #ifdef CONFIG_QETH_IPV6
8396 * IPv6 event handler
8399 qeth_ip6_event(struct notifier_block *this,
8400 unsigned long event,void *ptr)
8403 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8404 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8405 struct qeth_ipaddr *addr;
8406 struct qeth_card *card;
8408 QETH_DBF_TEXT(trace,3,"ip6event");
8410 card = qeth_get_card_from_dev(dev);
8413 if (!qeth_is_supported(card, IPA_IPV6))
8416 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8418 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8419 addr->u.a6.pfxlen = ifa->prefix_len;
8420 addr->type = QETH_IP_TYPE_NORMAL;
8426 if (!qeth_add_ip(card, addr))
8430 if (!qeth_delete_ip(card, addr))
8436 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8437 schedule_work(&card->kernel_thread_starter);
8442 static struct notifier_block qeth_ip6_notifier = {
8449 __qeth_reboot_event_card(struct device *dev, void *data)
8451 struct qeth_card *card;
8453 card = (struct qeth_card *) dev->driver_data;
8454 qeth_clear_ip_list(card, 0, 0);
8455 qeth_qdio_clear_card(card, 0);
8460 qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8464 ret = driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8465 __qeth_reboot_event_card);
8466 return ret ? NOTIFY_BAD : NOTIFY_DONE;
8470 static struct notifier_block qeth_reboot_notifier = {
8476 qeth_register_notifiers(void)
8480 QETH_DBF_TEXT(trace,5,"regnotif");
8481 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8483 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8485 #ifdef CONFIG_QETH_IPV6
8486 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8491 #ifdef CONFIG_QETH_IPV6
8493 unregister_inetaddr_notifier(&qeth_ip_notifier);
8496 unregister_reboot_notifier(&qeth_reboot_notifier);
8501 * unregister all event notifiers
8504 qeth_unregister_notifiers(void)
8507 QETH_DBF_TEXT(trace,5,"unregnot");
8508 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8509 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8510 #ifdef CONFIG_QETH_IPV6
8511 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8512 #endif /* QETH_IPV6 */
8516 #ifdef CONFIG_QETH_IPV6
8518 qeth_ipv6_init(void)
8520 qeth_old_arp_constructor = arp_tbl.constructor;
8521 write_lock_bh(&arp_tbl.lock);
8522 arp_tbl.constructor = qeth_arp_constructor;
8523 write_unlock_bh(&arp_tbl.lock);
8525 arp_direct_ops = (struct neigh_ops*)
8526 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8527 if (!arp_direct_ops)
8530 memcpy(arp_direct_ops, &arp_direct_ops_template,
8531 sizeof(struct neigh_ops));
8537 qeth_ipv6_uninit(void)
8539 write_lock_bh(&arp_tbl.lock);
8540 arp_tbl.constructor = qeth_old_arp_constructor;
8541 write_unlock_bh(&arp_tbl.lock);
8542 kfree(arp_direct_ops);
8544 #endif /* CONFIG_QETH_IPV6 */
8547 qeth_sysfs_unregister(void)
8549 s390_root_dev_unregister(qeth_root_dev);
8550 qeth_remove_driver_attributes();
8551 ccw_driver_unregister(&qeth_ccw_driver);
8552 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8556 * register qeth at sysfs
8559 qeth_sysfs_register(void)
8563 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8567 rc = ccw_driver_register(&qeth_ccw_driver);
8569 goto out_ccw_driver;
8571 rc = qeth_create_driver_attributes();
8575 qeth_root_dev = s390_root_dev_register("qeth");
8576 rc = IS_ERR(qeth_root_dev) ? PTR_ERR(qeth_root_dev) : 0;
8580 qeth_remove_driver_attributes();
8582 ccw_driver_unregister(&qeth_ccw_driver);
8584 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8597 PRINT_INFO("loading %s\n", version);
8599 INIT_LIST_HEAD(&qeth_card_list.list);
8600 INIT_LIST_HEAD(&qeth_notify_list);
8601 spin_lock_init(&qeth_notify_lock);
8602 rwlock_init(&qeth_card_list.rwlock);
8604 rc = qeth_register_dbf_views();
8608 rc = qeth_sysfs_register();
8612 #ifdef CONFIG_QETH_IPV6
8613 rc = qeth_ipv6_init();
8615 PRINT_ERR("Out of memory during ipv6 init code = %d\n", rc);
8618 #endif /* QETH_IPV6 */
8619 rc = qeth_register_notifiers();
8622 rc = qeth_create_procfs_entries();
8629 qeth_unregister_notifiers();
8631 #ifdef CONFIG_QETH_IPV6
8634 #endif /* QETH_IPV6 */
8635 qeth_sysfs_unregister();
8637 qeth_unregister_dbf_views();
8639 PRINT_ERR("Initialization failed with code %d\n", rc);
8644 __exit qeth_exit(void)
8646 struct qeth_card *card, *tmp;
8647 unsigned long flags;
8649 QETH_DBF_TEXT(trace,1, "cleanup.");
8652 * Weed would not need to clean up our devices here, because the
8653 * common device layer calls qeth_remove_device for each device
8654 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8655 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8656 * qeth_remove_device called by the common device layer would otherwise
8657 * do a "hard" shutdown (card->use_hard_stop is set to one in
8658 * qeth_remove_device).
8661 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8662 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8663 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8664 qeth_set_offline(card->gdev);
8665 qeth_remove_device(card->gdev);
8668 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8669 #ifdef CONFIG_QETH_IPV6
8672 qeth_unregister_notifiers();
8673 qeth_remove_procfs_entries();
8674 qeth_sysfs_unregister();
8675 qeth_unregister_dbf_views();
8676 printk("qeth: removed\n");
8679 EXPORT_SYMBOL(qeth_osn_register);
8680 EXPORT_SYMBOL(qeth_osn_deregister);
8681 EXPORT_SYMBOL(qeth_osn_assist);
8682 module_init(qeth_init);
8683 module_exit(qeth_exit);
8684 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
8685 MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8686 "Copyright 2000,2003 IBM Corporation\n");
8688 MODULE_LICENSE("GPL");