3 * linux/drivers/s390/net/qeth_main.c ($Revision: 1.251 $)
5 * Linux on zSeries OSA Express and HiperSockets support
7 * Copyright 2000,2003 IBM Corporation
9 * Author(s): Original Code written by
10 * Utz Bacher (utz.bacher@de.ibm.com)
12 * Frank Pavlic (fpavlic@de.ibm.com) and
13 * Thomas Spatzier <tspat@de.ibm.com>
15 * $Revision: 1.251 $ $Date: 2005/05/04 20:19:18 $
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/string.h>
37 #include <linux/errno.h>
40 #include <linux/inetdevice.h>
41 #include <linux/netdevice.h>
42 #include <linux/sched.h>
43 #include <linux/workqueue.h>
44 #include <linux/kernel.h>
45 #include <linux/slab.h>
46 #include <linux/interrupt.h>
47 #include <linux/tcp.h>
48 #include <linux/icmp.h>
49 #include <linux/skbuff.h>
51 #include <linux/igmp.h>
52 #include <linux/init.h>
53 #include <linux/reboot.h>
54 #include <linux/mii.h>
55 #include <linux/rcupdate.h>
56 #include <linux/ethtool.h>
60 #include <net/route.h>
62 #include <asm/ebcdic.h>
65 #include <asm/timex.h>
66 #include <asm/semaphore.h>
67 #include <asm/uaccess.h>
68 #include <asm/s390_rdev.h>
73 #include "qeth_eddp.h"
76 #define VERSION_QETH_C "$Revision: 1.251 $"
77 static const char *version = "qeth S/390 OSA-Express driver";
80 * Debug Facility Stuff
82 static debug_info_t *qeth_dbf_setup = NULL;
83 static debug_info_t *qeth_dbf_data = NULL;
84 static debug_info_t *qeth_dbf_misc = NULL;
85 static debug_info_t *qeth_dbf_control = NULL;
86 debug_info_t *qeth_dbf_trace = NULL;
87 static debug_info_t *qeth_dbf_sense = NULL;
88 static debug_info_t *qeth_dbf_qerr = NULL;
90 DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
93 * some more definitions and declarations
95 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
97 /* list of our cards */
98 struct qeth_card_list_struct qeth_card_list;
99 /*process list want to be notified*/
100 spinlock_t qeth_notify_lock;
101 struct list_head qeth_notify_list;
103 static void qeth_send_control_data_cb(struct qeth_channel *,
104 struct qeth_cmd_buffer *);
107 * here we go with function implementation
110 qeth_init_qdio_info(struct qeth_card *card);
113 qeth_init_qdio_queues(struct qeth_card *card);
116 qeth_alloc_qdio_buffers(struct qeth_card *card);
119 qeth_free_qdio_buffers(struct qeth_card *);
122 qeth_clear_qdio_buffers(struct qeth_card *);
125 qeth_clear_ip_list(struct qeth_card *, int, int);
128 qeth_clear_ipacmd_list(struct qeth_card *);
131 qeth_qdio_clear_card(struct qeth_card *, int);
134 qeth_clear_working_pool_list(struct qeth_card *);
137 qeth_clear_cmd_buffers(struct qeth_channel *);
140 qeth_stop(struct net_device *);
143 qeth_clear_ipato_list(struct qeth_card *);
146 qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
149 qeth_irq_tasklet(unsigned long);
152 qeth_set_online(struct ccwgroup_device *);
155 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
157 static struct qeth_ipaddr *
158 qeth_get_addr_buffer(enum qeth_prot_versions);
161 qeth_set_multicast_list(struct net_device *);
164 qeth_setadp_promisc_mode(struct qeth_card *);
167 qeth_notify_processes(void)
169 /*notify all registered processes */
170 struct qeth_notify_list_struct *n_entry;
172 QETH_DBF_TEXT(trace,3,"procnoti");
173 spin_lock(&qeth_notify_lock);
174 list_for_each_entry(n_entry, &qeth_notify_list, list) {
175 send_sig(n_entry->signum, n_entry->task, 1);
177 spin_unlock(&qeth_notify_lock);
181 qeth_notifier_unregister(struct task_struct *p)
183 struct qeth_notify_list_struct *n_entry, *tmp;
185 QETH_DBF_TEXT(trace, 2, "notunreg");
186 spin_lock(&qeth_notify_lock);
187 list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
188 if (n_entry->task == p) {
189 list_del(&n_entry->list);
195 spin_unlock(&qeth_notify_lock);
199 qeth_notifier_register(struct task_struct *p, int signum)
201 struct qeth_notify_list_struct *n_entry;
203 /*check first if entry already exists*/
204 spin_lock(&qeth_notify_lock);
205 list_for_each_entry(n_entry, &qeth_notify_list, list) {
206 if (n_entry->task == p) {
207 n_entry->signum = signum;
208 spin_unlock(&qeth_notify_lock);
212 spin_unlock(&qeth_notify_lock);
214 n_entry = (struct qeth_notify_list_struct *)
215 kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL);
219 n_entry->signum = signum;
220 spin_lock(&qeth_notify_lock);
221 list_add(&n_entry->list,&qeth_notify_list);
222 spin_unlock(&qeth_notify_lock);
228 * free channel command buffers
231 qeth_clean_channel(struct qeth_channel *channel)
235 QETH_DBF_TEXT(setup, 2, "freech");
236 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
237 kfree(channel->iob[cnt].data);
244 qeth_free_card(struct qeth_card *card)
247 QETH_DBF_TEXT(setup, 2, "freecrd");
248 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
249 qeth_clean_channel(&card->read);
250 qeth_clean_channel(&card->write);
252 free_netdev(card->dev);
253 qeth_clear_ip_list(card, 0, 0);
254 qeth_clear_ipato_list(card);
255 kfree(card->ip_tbd_list);
256 qeth_free_qdio_buffers(card);
261 * alloc memory for command buffer per channel
264 qeth_setup_channel(struct qeth_channel *channel)
268 QETH_DBF_TEXT(setup, 2, "setupch");
269 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
270 channel->iob[cnt].data = (char *)
271 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
272 if (channel->iob[cnt].data == NULL)
274 channel->iob[cnt].state = BUF_STATE_FREE;
275 channel->iob[cnt].channel = channel;
276 channel->iob[cnt].callback = qeth_send_control_data_cb;
277 channel->iob[cnt].rc = 0;
279 if (cnt < QETH_CMD_BUFFER_NO) {
281 kfree(channel->iob[cnt].data);
285 channel->io_buf_no = 0;
286 atomic_set(&channel->irq_pending, 0);
287 spin_lock_init(&channel->iob_lock);
289 init_waitqueue_head(&channel->wait_q);
290 channel->irq_tasklet.data = (unsigned long) channel;
291 channel->irq_tasklet.func = qeth_irq_tasklet;
296 * alloc memory for card structure
298 static struct qeth_card *
299 qeth_alloc_card(void)
301 struct qeth_card *card;
303 QETH_DBF_TEXT(setup, 2, "alloccrd");
304 card = (struct qeth_card *) kmalloc(sizeof(struct qeth_card),
308 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
309 memset(card, 0, sizeof(struct qeth_card));
310 if (qeth_setup_channel(&card->read)) {
314 if (qeth_setup_channel(&card->write)) {
315 qeth_clean_channel(&card->read);
323 __qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb)
328 switch (PTR_ERR(irb)) {
330 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
331 QETH_DBF_TEXT(trace, 2, "ckirberr");
332 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
335 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
336 QETH_DBF_TEXT(trace, 2, "ckirberr");
337 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
340 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
342 QETH_DBF_TEXT(trace, 2, "ckirberr");
343 QETH_DBF_TEXT(trace, 2, " rc???");
349 qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
354 sense = (char *) irb->ecw;
355 cstat = irb->scsw.cstat;
356 dstat = irb->scsw.dstat;
358 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
359 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
360 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
361 QETH_DBF_TEXT(trace,2, "CGENCHK");
362 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
363 cdev->dev.bus_id, dstat, cstat);
364 HEXDUMP16(WARN, "irb: ", irb);
365 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
369 if (dstat & DEV_STAT_UNIT_CHECK) {
370 if (sense[SENSE_RESETTING_EVENT_BYTE] &
371 SENSE_RESETTING_EVENT_FLAG) {
372 QETH_DBF_TEXT(trace,2,"REVIND");
375 if (sense[SENSE_COMMAND_REJECT_BYTE] &
376 SENSE_COMMAND_REJECT_FLAG) {
377 QETH_DBF_TEXT(trace,2,"CMDREJi");
380 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
381 QETH_DBF_TEXT(trace,2,"AFFE");
384 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
385 QETH_DBF_TEXT(trace,2,"ZEROSEN");
388 QETH_DBF_TEXT(trace,2,"DGENCHK");
393 static int qeth_issue_next_read(struct qeth_card *);
399 qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
403 struct qeth_cmd_buffer *buffer;
404 struct qeth_channel *channel;
405 struct qeth_card *card;
407 QETH_DBF_TEXT(trace,5,"irq");
409 if (__qeth_check_irb_error(cdev, irb))
411 cstat = irb->scsw.cstat;
412 dstat = irb->scsw.dstat;
414 card = CARD_FROM_CDEV(cdev);
418 if (card->read.ccwdev == cdev){
419 channel = &card->read;
420 QETH_DBF_TEXT(trace,5,"read");
421 } else if (card->write.ccwdev == cdev) {
422 channel = &card->write;
423 QETH_DBF_TEXT(trace,5,"write");
425 channel = &card->data;
426 QETH_DBF_TEXT(trace,5,"data");
428 atomic_set(&channel->irq_pending, 0);
430 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
431 channel->state = CH_STATE_STOPPED;
433 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
434 channel->state = CH_STATE_HALTED;
436 /*let's wake up immediately on data channel*/
437 if ((channel == &card->data) && (intparm != 0))
440 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
441 QETH_DBF_TEXT(trace, 6, "clrchpar");
442 /* we don't have to handle this further */
445 if (intparm == QETH_HALT_CHANNEL_PARM) {
446 QETH_DBF_TEXT(trace, 6, "hltchpar");
447 /* we don't have to handle this further */
450 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
451 (dstat & DEV_STAT_UNIT_CHECK) ||
453 if (irb->esw.esw0.erw.cons) {
454 /* TODO: we should make this s390dbf */
455 PRINT_WARN("sense data available on channel %s.\n",
456 CHANNEL_ID(channel));
457 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
458 HEXDUMP16(WARN,"irb: ",irb);
459 HEXDUMP16(WARN,"sense data: ",irb->ecw);
461 rc = qeth_get_problem(cdev,irb);
463 qeth_schedule_recovery(card);
469 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
470 buffer->state = BUF_STATE_PROCESSED;
472 if (channel == &card->data)
475 if (channel == &card->read &&
476 channel->state == CH_STATE_UP)
477 qeth_issue_next_read(card);
479 tasklet_schedule(&channel->irq_tasklet);
482 wake_up(&card->wait_q);
486 * tasklet function scheduled from irq handler
489 qeth_irq_tasklet(unsigned long data)
491 struct qeth_card *card;
492 struct qeth_channel *channel;
493 struct qeth_cmd_buffer *iob;
496 QETH_DBF_TEXT(trace,5,"irqtlet");
497 channel = (struct qeth_channel *) data;
499 index = channel->buf_no;
500 card = CARD_FROM_CDEV(channel->ccwdev);
501 while (iob[index].state == BUF_STATE_PROCESSED) {
502 if (iob[index].callback !=NULL) {
503 iob[index].callback(channel,iob + index);
505 index = (index + 1) % QETH_CMD_BUFFER_NO;
507 channel->buf_no = index;
508 wake_up(&card->wait_q);
511 static int qeth_stop_card(struct qeth_card *, int);
514 __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
516 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
517 int rc = 0, rc2 = 0, rc3 = 0;
518 enum qeth_card_states recover_flag;
520 QETH_DBF_TEXT(setup, 3, "setoffl");
521 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
523 netif_carrier_off(card->dev);
524 recover_flag = card->state;
525 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
526 PRINT_WARN("Stopping card %s interrupted by user!\n",
530 rc = ccw_device_set_offline(CARD_DDEV(card));
531 rc2 = ccw_device_set_offline(CARD_WDEV(card));
532 rc3 = ccw_device_set_offline(CARD_RDEV(card));
534 rc = (rc2) ? rc2 : rc3;
536 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
537 if (recover_flag == CARD_STATE_UP)
538 card->state = CARD_STATE_RECOVER;
539 qeth_notify_processes();
544 qeth_set_offline(struct ccwgroup_device *cgdev)
546 return __qeth_set_offline(cgdev, 0);
550 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads);
554 qeth_remove_device(struct ccwgroup_device *cgdev)
556 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
559 QETH_DBF_TEXT(setup, 3, "rmdev");
560 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
565 if (qeth_wait_for_threads(card, 0xffffffff))
568 if (cgdev->state == CCWGROUP_ONLINE){
569 card->use_hard_stop = 1;
570 qeth_set_offline(cgdev);
572 /* remove form our internal list */
573 write_lock_irqsave(&qeth_card_list.rwlock, flags);
574 list_del(&card->list);
575 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
577 unregister_netdev(card->dev);
578 qeth_remove_device_attributes(&cgdev->dev);
579 qeth_free_card(card);
580 cgdev->dev.driver_data = NULL;
581 put_device(&cgdev->dev);
585 qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
587 qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
590 * Add/remove address to/from card's ip list, i.e. try to add or remove
591 * reference to/from an IP address that is already registered on the card.
593 * 0 address was on card and its reference count has been adjusted,
594 * but is still > 0, so nothing has to be done
595 * also returns 0 if card was not on card and the todo was to delete
596 * the address -> there is also nothing to be done
597 * 1 address was not on card and the todo is to add it to the card's ip
599 * -1 address was on card and its reference count has been decremented
600 * to <= 0 by the todo -> address must be removed from card
603 __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
604 struct qeth_ipaddr **__addr)
606 struct qeth_ipaddr *addr;
609 list_for_each_entry(addr, &card->ip_list, entry) {
610 if (card->options.layer2) {
611 if ((addr->type == todo->type) &&
612 (memcmp(&addr->mac, &todo->mac,
613 OSA_ADDR_LEN) == 0)) {
619 if ((addr->proto == QETH_PROT_IPV4) &&
620 (todo->proto == QETH_PROT_IPV4) &&
621 (addr->type == todo->type) &&
622 (addr->u.a4.addr == todo->u.a4.addr) &&
623 (addr->u.a4.mask == todo->u.a4.mask)) {
627 if ((addr->proto == QETH_PROT_IPV6) &&
628 (todo->proto == QETH_PROT_IPV6) &&
629 (addr->type == todo->type) &&
630 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
631 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
632 sizeof(struct in6_addr)) == 0)) {
638 addr->users += todo->users;
639 if (addr->users <= 0){
643 /* for VIPA and RXIP limit refcount to 1 */
644 if (addr->type != QETH_IP_TYPE_NORMAL)
649 if (todo->users > 0) {
650 /* for VIPA and RXIP limit refcount to 1 */
651 if (todo->type != QETH_IP_TYPE_NORMAL)
659 __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
662 struct qeth_ipaddr *tmp;
664 list_for_each_entry(tmp, list, entry) {
665 if ((tmp->proto == QETH_PROT_IPV4) &&
666 (addr->proto == QETH_PROT_IPV4) &&
667 ((same_type && (tmp->type == addr->type)) ||
668 (!same_type && (tmp->type != addr->type)) ) &&
669 (tmp->u.a4.addr == addr->u.a4.addr) ){
672 if ((tmp->proto == QETH_PROT_IPV6) &&
673 (addr->proto == QETH_PROT_IPV6) &&
674 ((same_type && (tmp->type == addr->type)) ||
675 (!same_type && (tmp->type != addr->type)) ) &&
676 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
677 sizeof(struct in6_addr)) == 0) ) {
685 * Add IP to be added to todo list. If there is already an "add todo"
686 * in this list we just incremenent the reference count.
687 * Returns 0 if we just incremented reference count.
690 __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
692 struct qeth_ipaddr *tmp, *t;
695 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
696 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
697 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
699 if (card->options.layer2) {
700 if ((tmp->type == addr->type) &&
701 (tmp->is_multicast == addr->is_multicast) &&
702 (memcmp(&tmp->mac, &addr->mac,
703 OSA_ADDR_LEN) == 0)) {
709 if ((tmp->proto == QETH_PROT_IPV4) &&
710 (addr->proto == QETH_PROT_IPV4) &&
711 (tmp->type == addr->type) &&
712 (tmp->is_multicast == addr->is_multicast) &&
713 (tmp->u.a4.addr == addr->u.a4.addr) &&
714 (tmp->u.a4.mask == addr->u.a4.mask)) {
718 if ((tmp->proto == QETH_PROT_IPV6) &&
719 (addr->proto == QETH_PROT_IPV6) &&
720 (tmp->type == addr->type) &&
721 (tmp->is_multicast == addr->is_multicast) &&
722 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
723 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
724 sizeof(struct in6_addr)) == 0)) {
730 if (addr->users != 0)
731 tmp->users += addr->users;
733 tmp->users += add? 1:-1;
734 if (tmp->users == 0) {
735 list_del(&tmp->entry);
740 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
741 list_add(&addr->entry, card->ip_tbd_list);
743 if (addr->users == 0)
744 addr->users += add? 1:-1;
745 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
746 qeth_is_addr_covered_by_ipato(card, addr)){
747 QETH_DBF_TEXT(trace, 2, "tkovaddr");
748 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
750 list_add_tail(&addr->entry, card->ip_tbd_list);
757 * Remove IP address from list
760 qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
765 QETH_DBF_TEXT(trace, 4, "delip");
767 if (card->options.layer2)
768 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
769 else if (addr->proto == QETH_PROT_IPV4)
770 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
772 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
773 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
775 spin_lock_irqsave(&card->ip_lock, flags);
776 rc = __qeth_insert_ip_todo(card, addr, 0);
777 spin_unlock_irqrestore(&card->ip_lock, flags);
782 qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
787 QETH_DBF_TEXT(trace, 4, "addip");
788 if (card->options.layer2)
789 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
790 else if (addr->proto == QETH_PROT_IPV4)
791 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
793 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
794 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
796 spin_lock_irqsave(&card->ip_lock, flags);
797 rc = __qeth_insert_ip_todo(card, addr, 1);
798 spin_unlock_irqrestore(&card->ip_lock, flags);
803 __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
805 struct qeth_ipaddr *addr, *tmp;
808 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
809 if (addr->is_multicast) {
810 spin_unlock_irqrestore(&card->ip_lock, *flags);
811 rc = qeth_deregister_addr_entry(card, addr);
812 spin_lock_irqsave(&card->ip_lock, *flags);
814 list_del(&addr->entry);
823 qeth_set_ip_addr_list(struct qeth_card *card)
825 struct list_head *tbd_list;
826 struct qeth_ipaddr *todo, *addr;
830 QETH_DBF_TEXT(trace, 2, "sdiplist");
831 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
833 spin_lock_irqsave(&card->ip_lock, flags);
834 tbd_list = card->ip_tbd_list;
835 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
836 if (!card->ip_tbd_list) {
837 QETH_DBF_TEXT(trace, 0, "silnomem");
838 card->ip_tbd_list = tbd_list;
839 spin_unlock_irqrestore(&card->ip_lock, flags);
842 INIT_LIST_HEAD(card->ip_tbd_list);
844 while (!list_empty(tbd_list)){
845 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
846 list_del(&todo->entry);
847 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
848 __qeth_delete_all_mc(card, &flags);
852 rc = __qeth_ref_ip_on_card(card, todo, &addr);
854 /* nothing to be done; only adjusted refcount */
856 } else if (rc == 1) {
857 /* new entry to be added to on-card list */
858 spin_unlock_irqrestore(&card->ip_lock, flags);
859 rc = qeth_register_addr_entry(card, todo);
860 spin_lock_irqsave(&card->ip_lock, flags);
862 list_add_tail(&todo->entry, &card->ip_list);
865 } else if (rc == -1) {
866 /* on-card entry to be removed */
867 list_del_init(&addr->entry);
868 spin_unlock_irqrestore(&card->ip_lock, flags);
869 rc = qeth_deregister_addr_entry(card, addr);
870 spin_lock_irqsave(&card->ip_lock, flags);
874 list_add_tail(&addr->entry, &card->ip_list);
878 spin_unlock_irqrestore(&card->ip_lock, flags);
882 static void qeth_delete_mc_addresses(struct qeth_card *);
883 static void qeth_add_multicast_ipv4(struct qeth_card *);
884 static void qeth_layer2_add_multicast(struct qeth_card *);
885 #ifdef CONFIG_QETH_IPV6
886 static void qeth_add_multicast_ipv6(struct qeth_card *);
890 qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
894 spin_lock_irqsave(&card->thread_mask_lock, flags);
895 if ( !(card->thread_allowed_mask & thread) ||
896 (card->thread_start_mask & thread) ) {
897 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
900 card->thread_start_mask |= thread;
901 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
906 qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
910 spin_lock_irqsave(&card->thread_mask_lock, flags);
911 card->thread_start_mask &= ~thread;
912 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
913 wake_up(&card->wait_q);
917 qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
921 spin_lock_irqsave(&card->thread_mask_lock, flags);
922 card->thread_running_mask &= ~thread;
923 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
924 wake_up(&card->wait_q);
928 __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
933 spin_lock_irqsave(&card->thread_mask_lock, flags);
934 if (card->thread_start_mask & thread){
935 if ((card->thread_allowed_mask & thread) &&
936 !(card->thread_running_mask & thread)){
938 card->thread_start_mask &= ~thread;
939 card->thread_running_mask |= thread;
943 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
948 qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
952 wait_event(card->wait_q,
953 (rc = __qeth_do_run_thread(card, thread)) >= 0);
958 qeth_register_ip_addresses(void *ptr)
960 struct qeth_card *card;
962 card = (struct qeth_card *) ptr;
963 daemonize("qeth_reg_ip");
964 QETH_DBF_TEXT(trace,4,"regipth1");
965 if (!qeth_do_run_thread(card, QETH_SET_IP_THREAD))
967 QETH_DBF_TEXT(trace,4,"regipth2");
968 qeth_set_ip_addr_list(card);
969 qeth_clear_thread_running_bit(card, QETH_SET_IP_THREAD);
974 * Drive the SET_PROMISC_MODE thread
977 qeth_set_promisc_mode(void *ptr)
979 struct qeth_card *card = (struct qeth_card *) ptr;
981 daemonize("qeth_setprm");
982 QETH_DBF_TEXT(trace,4,"setprm1");
983 if (!qeth_do_run_thread(card, QETH_SET_PROMISC_MODE_THREAD))
985 QETH_DBF_TEXT(trace,4,"setprm2");
986 qeth_setadp_promisc_mode(card);
987 qeth_clear_thread_running_bit(card, QETH_SET_PROMISC_MODE_THREAD);
992 qeth_recover(void *ptr)
994 struct qeth_card *card;
997 card = (struct qeth_card *) ptr;
998 daemonize("qeth_recover");
999 QETH_DBF_TEXT(trace,2,"recover1");
1000 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
1001 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1003 QETH_DBF_TEXT(trace,2,"recover2");
1004 PRINT_WARN("Recovery of device %s started ...\n",
1006 card->use_hard_stop = 1;
1007 __qeth_set_offline(card->gdev,1);
1008 rc = __qeth_set_online(card->gdev,1);
1010 PRINT_INFO("Device %s successfully recovered!\n",
1013 PRINT_INFO("Device %s could not be recovered!\n",
1015 /* don't run another scheduled recovery */
1016 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1017 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1022 qeth_schedule_recovery(struct qeth_card *card)
1024 QETH_DBF_TEXT(trace,2,"startrec");
1025 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
1026 schedule_work(&card->kernel_thread_starter);
1030 qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1032 unsigned long flags;
1035 spin_lock_irqsave(&card->thread_mask_lock, flags);
1036 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
1037 (u8) card->thread_start_mask,
1038 (u8) card->thread_allowed_mask,
1039 (u8) card->thread_running_mask);
1040 rc = (card->thread_start_mask & thread);
1041 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1046 qeth_start_kernel_thread(struct qeth_card *card)
1048 QETH_DBF_TEXT(trace , 2, "strthrd");
1050 if (card->read.state != CH_STATE_UP &&
1051 card->write.state != CH_STATE_UP)
1054 if (qeth_do_start_thread(card, QETH_SET_IP_THREAD))
1055 kernel_thread(qeth_register_ip_addresses, (void *)card,SIGCHLD);
1056 if (qeth_do_start_thread(card, QETH_SET_PROMISC_MODE_THREAD))
1057 kernel_thread(qeth_set_promisc_mode, (void *)card, SIGCHLD);
1058 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1059 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1064 qeth_set_intial_options(struct qeth_card *card)
1066 card->options.route4.type = NO_ROUTER;
1067 #ifdef CONFIG_QETH_IPV6
1068 card->options.route6.type = NO_ROUTER;
1069 #endif /* QETH_IPV6 */
1070 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1071 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1072 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1073 card->options.fake_broadcast = 0;
1074 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1075 card->options.fake_ll = 0;
1076 if (card->info.type == QETH_CARD_TYPE_OSN)
1077 card->options.layer2 = 1;
1079 card->options.layer2 = 0;
1083 * initialize channels ,card and all state machines
1086 qeth_setup_card(struct qeth_card *card)
1089 QETH_DBF_TEXT(setup, 2, "setupcrd");
1090 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1092 card->read.state = CH_STATE_DOWN;
1093 card->write.state = CH_STATE_DOWN;
1094 card->data.state = CH_STATE_DOWN;
1095 card->state = CARD_STATE_DOWN;
1096 card->lan_online = 0;
1097 card->use_hard_stop = 0;
1099 #ifdef CONFIG_QETH_VLAN
1100 spin_lock_init(&card->vlanlock);
1101 card->vlangrp = NULL;
1103 spin_lock_init(&card->lock);
1104 spin_lock_init(&card->ip_lock);
1105 spin_lock_init(&card->thread_mask_lock);
1106 card->thread_start_mask = 0;
1107 card->thread_allowed_mask = 0;
1108 card->thread_running_mask = 0;
1109 INIT_WORK(&card->kernel_thread_starter,
1110 (void *)qeth_start_kernel_thread,card);
1111 INIT_LIST_HEAD(&card->ip_list);
1112 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1113 if (!card->ip_tbd_list) {
1114 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1117 INIT_LIST_HEAD(card->ip_tbd_list);
1118 INIT_LIST_HEAD(&card->cmd_waiter_list);
1119 init_waitqueue_head(&card->wait_q);
1120 /* intial options */
1121 qeth_set_intial_options(card);
1122 /* IP address takeover */
1123 INIT_LIST_HEAD(&card->ipato.entries);
1124 card->ipato.enabled = 0;
1125 card->ipato.invert4 = 0;
1126 card->ipato.invert6 = 0;
1127 /* init QDIO stuff */
1128 qeth_init_qdio_info(card);
1133 is_1920_device (struct qeth_card *card)
1135 int single_queue = 0;
1136 struct ccw_device *ccwdev;
1137 struct channelPath_dsc {
1148 QETH_DBF_TEXT(setup, 2, "chk_1920");
1150 ccwdev = card->data.ccwdev;
1151 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1152 if (chp_dsc != NULL) {
1153 /* CHPP field bit 6 == 1 -> single queue */
1154 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1157 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1158 return single_queue;
1162 qeth_determine_card_type(struct qeth_card *card)
1166 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1168 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1169 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1170 while (known_devices[i][4]) {
1171 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1172 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1173 card->info.type = known_devices[i][4];
1174 card->qdio.no_out_queues = known_devices[i][8];
1175 card->info.is_multicast_different = known_devices[i][9];
1176 if (is_1920_device(card)) {
1177 PRINT_INFO("Priority Queueing not able "
1178 "due to hardware limitations!\n");
1179 card->qdio.no_out_queues = 1;
1180 card->qdio.default_out_queue = 0;
1186 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1187 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1192 qeth_probe_device(struct ccwgroup_device *gdev)
1194 struct qeth_card *card;
1196 unsigned long flags;
1199 QETH_DBF_TEXT(setup, 2, "probedev");
1202 if (!get_device(dev))
1205 QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
1207 card = qeth_alloc_card();
1210 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1213 card->read.ccwdev = gdev->cdev[0];
1214 card->write.ccwdev = gdev->cdev[1];
1215 card->data.ccwdev = gdev->cdev[2];
1216 gdev->dev.driver_data = card;
1218 gdev->cdev[0]->handler = qeth_irq;
1219 gdev->cdev[1]->handler = qeth_irq;
1220 gdev->cdev[2]->handler = qeth_irq;
1222 if ((rc = qeth_determine_card_type(card))){
1223 PRINT_WARN("%s: not a valid card type\n", __func__);
1224 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1226 qeth_free_card(card);
1229 if ((rc = qeth_setup_card(card))){
1230 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1232 qeth_free_card(card);
1235 rc = qeth_create_device_attributes(dev);
1238 qeth_free_card(card);
1241 /* insert into our internal list */
1242 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1243 list_add_tail(&card->list, &qeth_card_list.list);
1244 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1250 qeth_get_unitaddr(struct qeth_card *card)
1256 QETH_DBF_TEXT(setup, 2, "getunit");
1257 rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length);
1259 PRINT_ERR("read_conf_data for device %s returned %i\n",
1260 CARD_DDEV_ID(card), rc);
1263 card->info.chpid = prcd[30];
1264 card->info.unit_addr2 = prcd[31];
1265 card->info.cula = prcd[63];
1266 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1267 (prcd[0x11] == _ascebc['M']));
1272 qeth_init_tokens(struct qeth_card *card)
1274 card->token.issuer_rm_w = 0x00010103UL;
1275 card->token.cm_filter_w = 0x00010108UL;
1276 card->token.cm_connection_w = 0x0001010aUL;
1277 card->token.ulp_filter_w = 0x0001010bUL;
1278 card->token.ulp_connection_w = 0x0001010dUL;
1282 raw_devno_from_bus_id(char *id)
1284 id += (strlen(id) - 4);
1285 return (__u16) simple_strtoul(id, &id, 16);
1291 qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1293 struct qeth_card *card;
1295 QETH_DBF_TEXT(trace, 4, "setupccw");
1296 card = CARD_FROM_CDEV(channel->ccwdev);
1297 if (channel == &card->read)
1298 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1300 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1301 channel->ccw.count = len;
1302 channel->ccw.cda = (__u32) __pa(iob);
1306 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1308 static struct qeth_cmd_buffer *
1309 __qeth_get_buffer(struct qeth_channel *channel)
1313 QETH_DBF_TEXT(trace, 6, "getbuff");
1314 index = channel->io_buf_no;
1316 if (channel->iob[index].state == BUF_STATE_FREE) {
1317 channel->iob[index].state = BUF_STATE_LOCKED;
1318 channel->io_buf_no = (channel->io_buf_no + 1) %
1320 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1321 return channel->iob + index;
1323 index = (index + 1) % QETH_CMD_BUFFER_NO;
1324 } while(index != channel->io_buf_no);
1330 * release command buffer
1333 qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1335 unsigned long flags;
1337 QETH_DBF_TEXT(trace, 6, "relbuff");
1338 spin_lock_irqsave(&channel->iob_lock, flags);
1339 memset(iob->data, 0, QETH_BUFSIZE);
1340 iob->state = BUF_STATE_FREE;
1341 iob->callback = qeth_send_control_data_cb;
1343 spin_unlock_irqrestore(&channel->iob_lock, flags);
1346 static struct qeth_cmd_buffer *
1347 qeth_get_buffer(struct qeth_channel *channel)
1349 struct qeth_cmd_buffer *buffer = NULL;
1350 unsigned long flags;
1352 spin_lock_irqsave(&channel->iob_lock, flags);
1353 buffer = __qeth_get_buffer(channel);
1354 spin_unlock_irqrestore(&channel->iob_lock, flags);
1358 static struct qeth_cmd_buffer *
1359 qeth_wait_for_buffer(struct qeth_channel *channel)
1361 struct qeth_cmd_buffer *buffer;
1362 wait_event(channel->wait_q,
1363 ((buffer = qeth_get_buffer(channel)) != NULL));
1368 qeth_clear_cmd_buffers(struct qeth_channel *channel)
1372 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1373 qeth_release_buffer(channel,&channel->iob[cnt]);
1374 channel->buf_no = 0;
1375 channel->io_buf_no = 0;
1379 * start IDX for read and write channel
1382 qeth_idx_activate_get_answer(struct qeth_channel *channel,
1383 void (*idx_reply_cb)(struct qeth_channel *,
1384 struct qeth_cmd_buffer *))
1386 struct qeth_cmd_buffer *iob;
1387 unsigned long flags;
1389 struct qeth_card *card;
1391 QETH_DBF_TEXT(setup, 2, "idxanswr");
1392 card = CARD_FROM_CDEV(channel->ccwdev);
1393 iob = qeth_get_buffer(channel);
1394 iob->callback = idx_reply_cb;
1395 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1396 channel->ccw.count = QETH_BUFSIZE;
1397 channel->ccw.cda = (__u32) __pa(iob->data);
1399 wait_event(card->wait_q,
1400 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1401 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1402 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1403 rc = ccw_device_start(channel->ccwdev,
1404 &channel->ccw,(addr_t) iob, 0, 0);
1405 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1408 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1409 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1410 atomic_set(&channel->irq_pending, 0);
1411 wake_up(&card->wait_q);
1414 rc = wait_event_interruptible_timeout(card->wait_q,
1415 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1416 if (rc == -ERESTARTSYS)
1418 if (channel->state != CH_STATE_UP){
1420 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1421 qeth_clear_cmd_buffers(channel);
1428 qeth_idx_activate_channel(struct qeth_channel *channel,
1429 void (*idx_reply_cb)(struct qeth_channel *,
1430 struct qeth_cmd_buffer *))
1432 struct qeth_card *card;
1433 struct qeth_cmd_buffer *iob;
1434 unsigned long flags;
1438 card = CARD_FROM_CDEV(channel->ccwdev);
1440 QETH_DBF_TEXT(setup, 2, "idxactch");
1442 iob = qeth_get_buffer(channel);
1443 iob->callback = idx_reply_cb;
1444 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1445 channel->ccw.count = IDX_ACTIVATE_SIZE;
1446 channel->ccw.cda = (__u32) __pa(iob->data);
1447 if (channel == &card->write) {
1448 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1449 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1450 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1451 card->seqno.trans_hdr++;
1453 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1454 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1455 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1457 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1458 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1459 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1460 &card->info.func_level,sizeof(__u16));
1461 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1462 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1463 temp = (card->info.cula << 8) + card->info.unit_addr2;
1464 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1466 wait_event(card->wait_q,
1467 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1468 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1469 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1470 rc = ccw_device_start(channel->ccwdev,
1471 &channel->ccw,(addr_t) iob, 0, 0);
1472 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1475 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1476 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1477 atomic_set(&channel->irq_pending, 0);
1478 wake_up(&card->wait_q);
1481 rc = wait_event_interruptible_timeout(card->wait_q,
1482 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1483 if (rc == -ERESTARTSYS)
1485 if (channel->state != CH_STATE_ACTIVATING) {
1486 PRINT_WARN("qeth: IDX activate timed out!\n");
1487 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1488 qeth_clear_cmd_buffers(channel);
1491 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1495 qeth_peer_func_level(int level)
1497 if ((level & 0xff) == 8)
1498 return (level & 0xff) + 0x400;
1499 if (((level >> 8) & 3) == 1)
1500 return (level & 0xff) + 0x200;
1505 qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1507 struct qeth_card *card;
1510 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1512 if (channel->state == CH_STATE_DOWN) {
1513 channel->state = CH_STATE_ACTIVATING;
1516 card = CARD_FROM_CDEV(channel->ccwdev);
1518 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1519 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1520 "reply\n", CARD_WDEV_ID(card));
1523 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1524 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1525 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1526 "function level mismatch "
1527 "(sent: 0x%x, received: 0x%x)\n",
1528 CARD_WDEV_ID(card), card->info.func_level, temp);
1531 channel->state = CH_STATE_UP;
1533 qeth_release_buffer(channel, iob);
1537 qeth_check_idx_response(unsigned char *buffer)
1542 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1543 if ((buffer[2] & 0xc0) == 0xc0) {
1544 PRINT_WARN("received an IDX TERMINATE "
1545 "with cause code 0x%02x%s\n",
1547 ((buffer[4] == 0x22) ?
1548 " -- try another portname" : ""));
1549 QETH_DBF_TEXT(trace, 2, "ckidxres");
1550 QETH_DBF_TEXT(trace, 2, " idxterm");
1551 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1558 qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1560 struct qeth_card *card;
1563 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1564 if (channel->state == CH_STATE_DOWN) {
1565 channel->state = CH_STATE_ACTIVATING;
1569 card = CARD_FROM_CDEV(channel->ccwdev);
1570 if (qeth_check_idx_response(iob->data)) {
1573 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1574 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1575 "reply\n", CARD_RDEV_ID(card));
1580 * temporary fix for microcode bug
1581 * to revert it,replace OR by AND
1583 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1584 (card->info.type == QETH_CARD_TYPE_OSAE) )
1585 card->info.portname_required = 1;
1587 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1588 if (temp != qeth_peer_func_level(card->info.func_level)) {
1589 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1590 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1591 CARD_RDEV_ID(card), card->info.func_level, temp);
1594 memcpy(&card->token.issuer_rm_r,
1595 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1596 QETH_MPC_TOKEN_LENGTH);
1597 memcpy(&card->info.mcl_level[0],
1598 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1599 channel->state = CH_STATE_UP;
1601 qeth_release_buffer(channel,iob);
1605 qeth_issue_next_read(struct qeth_card *card)
1608 struct qeth_cmd_buffer *iob;
1610 QETH_DBF_TEXT(trace,5,"issnxrd");
1611 if (card->read.state != CH_STATE_UP)
1613 iob = qeth_get_buffer(&card->read);
1615 PRINT_WARN("issue_next_read failed: no iob available!\n");
1618 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1619 wait_event(card->wait_q,
1620 atomic_cmpxchg(&card->read.irq_pending, 0, 1) == 0);
1621 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1622 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1623 (addr_t) iob, 0, 0);
1625 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1626 atomic_set(&card->read.irq_pending, 0);
1627 qeth_schedule_recovery(card);
1628 wake_up(&card->wait_q);
1633 static struct qeth_reply *
1634 qeth_alloc_reply(struct qeth_card *card)
1636 struct qeth_reply *reply;
1638 reply = kmalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1640 memset(reply, 0, sizeof(struct qeth_reply));
1641 atomic_set(&reply->refcnt, 1);
1648 qeth_get_reply(struct qeth_reply *reply)
1650 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1651 atomic_inc(&reply->refcnt);
1655 qeth_put_reply(struct qeth_reply *reply)
1657 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1658 if (atomic_dec_and_test(&reply->refcnt))
1663 qeth_cmd_timeout(unsigned long data)
1665 struct qeth_reply *reply, *list_reply, *r;
1666 unsigned long flags;
1668 reply = (struct qeth_reply *) data;
1669 spin_lock_irqsave(&reply->card->lock, flags);
1670 list_for_each_entry_safe(list_reply, r,
1671 &reply->card->cmd_waiter_list, list) {
1672 if (reply == list_reply){
1673 qeth_get_reply(reply);
1674 list_del_init(&reply->list);
1675 spin_unlock_irqrestore(&reply->card->lock, flags);
1677 reply->received = 1;
1678 wake_up(&reply->wait_q);
1679 qeth_put_reply(reply);
1683 spin_unlock_irqrestore(&reply->card->lock, flags);
1686 static struct qeth_ipa_cmd *
1687 qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1689 struct qeth_ipa_cmd *cmd = NULL;
1691 QETH_DBF_TEXT(trace,5,"chkipad");
1692 if (IS_IPA(iob->data)){
1693 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1694 if (IS_IPA_REPLY(cmd))
1697 switch (cmd->hdr.command) {
1698 case IPA_CMD_STOPLAN:
1699 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1700 "there is a network problem or "
1701 "someone pulled the cable or "
1702 "disabled the port.\n",
1703 QETH_CARD_IFNAME(card),
1705 card->lan_online = 0;
1706 netif_carrier_off(card->dev);
1708 case IPA_CMD_STARTLAN:
1709 PRINT_INFO("Link reestablished on %s "
1710 "(CHPID 0x%X). Scheduling "
1711 "IP address reset.\n",
1712 QETH_CARD_IFNAME(card),
1714 qeth_schedule_recovery(card);
1716 case IPA_CMD_MODCCID:
1718 case IPA_CMD_REGISTER_LOCAL_ADDR:
1719 QETH_DBF_TEXT(trace,3, "irla");
1721 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1722 QETH_DBF_TEXT(trace,3, "urla");
1725 PRINT_WARN("Received data is IPA "
1726 "but not a reply!\n");
1735 * wake all waiting ipa commands
1738 qeth_clear_ipacmd_list(struct qeth_card *card)
1740 struct qeth_reply *reply, *r;
1741 unsigned long flags;
1743 QETH_DBF_TEXT(trace, 4, "clipalst");
1745 spin_lock_irqsave(&card->lock, flags);
1746 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1747 qeth_get_reply(reply);
1749 reply->received = 1;
1750 list_del_init(&reply->list);
1751 wake_up(&reply->wait_q);
1752 qeth_put_reply(reply);
1754 spin_unlock_irqrestore(&card->lock, flags);
1758 qeth_send_control_data_cb(struct qeth_channel *channel,
1759 struct qeth_cmd_buffer *iob)
1761 struct qeth_card *card;
1762 struct qeth_reply *reply, *r;
1763 struct qeth_ipa_cmd *cmd;
1764 unsigned long flags;
1767 QETH_DBF_TEXT(trace,4,"sndctlcb");
1769 card = CARD_FROM_CDEV(channel->ccwdev);
1770 if (qeth_check_idx_response(iob->data)) {
1771 qeth_clear_ipacmd_list(card);
1772 qeth_schedule_recovery(card);
1776 cmd = qeth_check_ipa_data(card, iob);
1777 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1779 /*in case of OSN : check if cmd is set */
1780 if (card->info.type == QETH_CARD_TYPE_OSN &&
1782 cmd->hdr.command != IPA_CMD_STARTLAN &&
1783 card->osn_info.assist_cb != NULL) {
1784 card->osn_info.assist_cb(card->dev, cmd);
1788 spin_lock_irqsave(&card->lock, flags);
1789 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1790 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1791 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1792 qeth_get_reply(reply);
1793 list_del_init(&reply->list);
1794 spin_unlock_irqrestore(&card->lock, flags);
1796 if (reply->callback != NULL) {
1798 reply->offset = (__u16)((char*)cmd -
1800 keep_reply = reply->callback(card,
1802 (unsigned long)cmd);
1804 keep_reply = reply->callback(card,
1806 (unsigned long)iob);
1809 reply->rc = (u16) cmd->hdr.return_code;
1811 reply->rc = iob->rc;
1813 spin_lock_irqsave(&card->lock, flags);
1814 list_add_tail(&reply->list,
1815 &card->cmd_waiter_list);
1816 spin_unlock_irqrestore(&card->lock, flags);
1818 reply->received = 1;
1819 wake_up(&reply->wait_q);
1821 qeth_put_reply(reply);
1825 spin_unlock_irqrestore(&card->lock, flags);
1827 memcpy(&card->seqno.pdu_hdr_ack,
1828 QETH_PDU_HEADER_SEQ_NO(iob->data),
1829 QETH_SEQ_NO_LENGTH);
1830 qeth_release_buffer(channel,iob);
1834 qeth_prepare_control_data(struct qeth_card *card, int len,
1835 struct qeth_cmd_buffer *iob)
1837 qeth_setup_ccw(&card->write,iob->data,len);
1838 iob->callback = qeth_release_buffer;
1840 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1841 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1842 card->seqno.trans_hdr++;
1843 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1844 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1845 card->seqno.pdu_hdr++;
1846 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1847 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1848 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1852 qeth_send_control_data(struct qeth_card *card, int len,
1853 struct qeth_cmd_buffer *iob,
1855 (struct qeth_card *, struct qeth_reply*, unsigned long),
1860 unsigned long flags;
1861 struct qeth_reply *reply = NULL;
1862 struct timer_list timer;
1864 QETH_DBF_TEXT(trace, 2, "sendctl");
1866 reply = qeth_alloc_reply(card);
1868 PRINT_WARN("Could no alloc qeth_reply!\n");
1871 reply->callback = reply_cb;
1872 reply->param = reply_param;
1873 if (card->state == CARD_STATE_DOWN)
1874 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1876 reply->seqno = card->seqno.ipa++;
1878 timer.function = qeth_cmd_timeout;
1879 timer.data = (unsigned long) reply;
1880 init_waitqueue_head(&reply->wait_q);
1881 spin_lock_irqsave(&card->lock, flags);
1882 list_add_tail(&reply->list, &card->cmd_waiter_list);
1883 spin_unlock_irqrestore(&card->lock, flags);
1884 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1885 wait_event(card->wait_q,
1886 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1887 qeth_prepare_control_data(card, len, iob);
1888 if (IS_IPA(iob->data))
1889 timer.expires = jiffies + QETH_IPA_TIMEOUT;
1891 timer.expires = jiffies + QETH_TIMEOUT;
1892 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1893 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1894 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1895 (addr_t) iob, 0, 0);
1896 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1898 PRINT_WARN("qeth_send_control_data: "
1899 "ccw_device_start rc = %i\n", rc);
1900 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1901 spin_lock_irqsave(&card->lock, flags);
1902 list_del_init(&reply->list);
1903 qeth_put_reply(reply);
1904 spin_unlock_irqrestore(&card->lock, flags);
1905 qeth_release_buffer(iob->channel, iob);
1906 atomic_set(&card->write.irq_pending, 0);
1907 wake_up(&card->wait_q);
1911 wait_event(reply->wait_q, reply->received);
1912 del_timer_sync(&timer);
1914 qeth_put_reply(reply);
1919 qeth_osn_send_control_data(struct qeth_card *card, int len,
1920 struct qeth_cmd_buffer *iob)
1922 unsigned long flags;
1925 QETH_DBF_TEXT(trace, 5, "osndctrd");
1927 wait_event(card->wait_q,
1928 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1929 qeth_prepare_control_data(card, len, iob);
1930 QETH_DBF_TEXT(trace, 6, "osnoirqp");
1931 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1932 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1933 (addr_t) iob, 0, 0);
1934 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1936 PRINT_WARN("qeth_osn_send_control_data: "
1937 "ccw_device_start rc = %i\n", rc);
1938 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1939 qeth_release_buffer(iob->channel, iob);
1940 atomic_set(&card->write.irq_pending, 0);
1941 wake_up(&card->wait_q);
1947 qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1950 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1951 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1952 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1953 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1957 qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1962 QETH_DBF_TEXT(trace,4,"osndipa");
1964 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1965 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1967 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1968 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1969 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1970 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1971 return qeth_osn_send_control_data(card, s1, iob);
1975 qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1977 (struct qeth_card *,struct qeth_reply*, unsigned long),
1983 QETH_DBF_TEXT(trace,4,"sendipa");
1985 if (card->options.layer2)
1986 if (card->info.type == QETH_CARD_TYPE_OSN)
1987 prot_type = QETH_PROT_OSN2;
1989 prot_type = QETH_PROT_LAYER2;
1991 prot_type = QETH_PROT_TCPIP;
1992 qeth_prepare_ipa_cmd(card,iob,prot_type);
1993 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
1994 reply_cb, reply_param);
2000 qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2003 struct qeth_cmd_buffer *iob;
2005 QETH_DBF_TEXT(setup, 2, "cmenblcb");
2007 iob = (struct qeth_cmd_buffer *) data;
2008 memcpy(&card->token.cm_filter_r,
2009 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2010 QETH_MPC_TOKEN_LENGTH);
2011 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2016 qeth_cm_enable(struct qeth_card *card)
2019 struct qeth_cmd_buffer *iob;
2021 QETH_DBF_TEXT(setup,2,"cmenable");
2023 iob = qeth_wait_for_buffer(&card->write);
2024 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2025 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2026 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2027 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2028 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2030 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2031 qeth_cm_enable_cb, NULL);
2036 qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2040 struct qeth_cmd_buffer *iob;
2042 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
2044 iob = (struct qeth_cmd_buffer *) data;
2045 memcpy(&card->token.cm_connection_r,
2046 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2047 QETH_MPC_TOKEN_LENGTH);
2048 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2053 qeth_cm_setup(struct qeth_card *card)
2056 struct qeth_cmd_buffer *iob;
2058 QETH_DBF_TEXT(setup,2,"cmsetup");
2060 iob = qeth_wait_for_buffer(&card->write);
2061 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2062 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2063 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2064 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2065 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2066 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2067 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2068 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2069 qeth_cm_setup_cb, NULL);
2075 qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2079 __u16 mtu, framesize;
2082 struct qeth_cmd_buffer *iob;
2084 QETH_DBF_TEXT(setup, 2, "ulpenacb");
2086 iob = (struct qeth_cmd_buffer *) data;
2087 memcpy(&card->token.ulp_filter_r,
2088 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2089 QETH_MPC_TOKEN_LENGTH);
2090 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
2091 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2092 mtu = qeth_get_mtu_outof_framesize(framesize);
2095 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2098 card->info.max_mtu = mtu;
2099 card->info.initial_mtu = mtu;
2100 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2102 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2103 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
2104 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2107 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2108 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2110 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2111 card->info.link_type = link_type;
2113 card->info.link_type = 0;
2114 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2119 qeth_ulp_enable(struct qeth_card *card)
2123 struct qeth_cmd_buffer *iob;
2125 /*FIXME: trace view callbacks*/
2126 QETH_DBF_TEXT(setup,2,"ulpenabl");
2128 iob = qeth_wait_for_buffer(&card->write);
2129 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2131 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2132 (__u8) card->info.portno;
2133 if (card->options.layer2)
2134 if (card->info.type == QETH_CARD_TYPE_OSN)
2135 prot_type = QETH_PROT_OSN2;
2137 prot_type = QETH_PROT_LAYER2;
2139 prot_type = QETH_PROT_TCPIP;
2141 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2142 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2143 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2144 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2145 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2146 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2147 card->info.portname, 9);
2148 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2149 qeth_ulp_enable_cb, NULL);
2155 __raw_devno_from_bus_id(char *id)
2157 id += (strlen(id) - 4);
2158 return (__u16) simple_strtoul(id, &id, 16);
2162 qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2165 struct qeth_cmd_buffer *iob;
2167 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2169 iob = (struct qeth_cmd_buffer *) data;
2170 memcpy(&card->token.ulp_connection_r,
2171 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2172 QETH_MPC_TOKEN_LENGTH);
2173 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2178 qeth_ulp_setup(struct qeth_card *card)
2182 struct qeth_cmd_buffer *iob;
2184 QETH_DBF_TEXT(setup,2,"ulpsetup");
2186 iob = qeth_wait_for_buffer(&card->write);
2187 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2189 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2190 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2191 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2192 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2193 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2194 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2196 temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card));
2197 memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2);
2198 temp = (card->info.cula << 8) + card->info.unit_addr2;
2199 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2200 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2201 qeth_ulp_setup_cb, NULL);
2206 qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2207 unsigned int siga_error, const char *dbftext)
2209 if (qdio_error || siga_error) {
2210 QETH_DBF_TEXT(trace, 2, dbftext);
2211 QETH_DBF_TEXT(qerr, 2, dbftext);
2212 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
2213 buf->element[15].flags & 0xff);
2214 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
2215 buf->element[14].flags & 0xff);
2216 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2217 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
2223 static inline struct sk_buff *
2224 qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
2226 struct sk_buff* skb;
2230 if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2231 add_len = sizeof(struct qeth_hdr);
2232 #ifdef CONFIG_QETH_VLAN
2234 add_len = VLAN_HLEN;
2236 skb = dev_alloc_skb(length + add_len);
2238 skb_reserve(skb, add_len);
2242 static inline struct sk_buff *
2243 qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2244 struct qdio_buffer_element **__element, int *__offset,
2245 struct qeth_hdr **hdr)
2247 struct qdio_buffer_element *element = *__element;
2248 int offset = *__offset;
2249 struct sk_buff *skb = NULL;
2254 QETH_DBF_TEXT(trace,6,"nextskb");
2255 /* qeth_hdr must not cross element boundaries */
2256 if (element->length < offset + sizeof(struct qeth_hdr)){
2257 if (qeth_is_last_sbale(element))
2261 if (element->length < sizeof(struct qeth_hdr))
2264 *hdr = element->addr + offset;
2266 offset += sizeof(struct qeth_hdr);
2267 if (card->options.layer2)
2268 if (card->info.type == QETH_CARD_TYPE_OSN)
2269 skb_len = (*hdr)->hdr.osn.pdu_length;
2271 skb_len = (*hdr)->hdr.l2.pkt_length;
2273 skb_len = (*hdr)->hdr.l3.length;
2277 if (card->options.fake_ll){
2278 if(card->dev->type == ARPHRD_IEEE802_TR){
2279 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR, *hdr)))
2281 skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2283 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH, *hdr)))
2285 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2287 } else if (!(skb = qeth_get_skb(skb_len, *hdr)))
2289 data_ptr = element->addr + offset;
2291 data_len = min(skb_len, (int)(element->length - offset));
2293 memcpy(skb_put(skb, data_len), data_ptr, data_len);
2294 skb_len -= data_len;
2296 if (qeth_is_last_sbale(element)){
2297 QETH_DBF_TEXT(trace,4,"unexeob");
2298 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2299 QETH_DBF_TEXT(qerr,2,"unexeob");
2300 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2301 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2302 dev_kfree_skb_any(skb);
2303 card->stats.rx_errors++;
2308 data_ptr = element->addr;
2313 *__element = element;
2317 if (net_ratelimit()){
2318 PRINT_WARN("No memory for packet received on %s.\n",
2319 QETH_CARD_IFNAME(card));
2320 QETH_DBF_TEXT(trace,2,"noskbmem");
2321 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2323 card->stats.rx_dropped++;
2327 static inline __be16
2328 qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2330 struct qeth_card *card;
2333 QETH_DBF_TEXT(trace,6,"typtrans");
2335 card = (struct qeth_card *)dev->priv;
2337 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2338 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2339 return tr_type_trans(skb,dev);
2340 #endif /* CONFIG_TR */
2341 skb->mac.raw = skb->data;
2342 skb_pull(skb, ETH_HLEN );
2345 if (*eth->h_dest & 1) {
2346 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2347 skb->pkt_type = PACKET_BROADCAST;
2349 skb->pkt_type = PACKET_MULTICAST;
2350 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2351 skb->pkt_type = PACKET_OTHERHOST;
2353 if (ntohs(eth->h_proto) >= 1536)
2354 return eth->h_proto;
2355 if (*(unsigned short *) (skb->data) == 0xFFFF)
2356 return htons(ETH_P_802_3);
2357 return htons(ETH_P_802_2);
2361 qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2362 struct qeth_hdr *hdr)
2364 struct trh_hdr *fake_hdr;
2365 struct trllc *fake_llc;
2366 struct iphdr *ip_hdr;
2368 QETH_DBF_TEXT(trace,5,"skbfktr");
2369 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_TR;
2370 /* this is a fake ethernet header */
2371 fake_hdr = (struct trh_hdr *) skb->mac.raw;
2373 /* the destination MAC address */
2374 switch (skb->pkt_type){
2375 case PACKET_MULTICAST:
2376 switch (skb->protocol){
2377 #ifdef CONFIG_QETH_IPV6
2378 case __constant_htons(ETH_P_IPV6):
2379 ndisc_mc_map((struct in6_addr *)
2380 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2381 fake_hdr->daddr, card->dev, 0);
2383 #endif /* CONFIG_QETH_IPV6 */
2384 case __constant_htons(ETH_P_IP):
2385 ip_hdr = (struct iphdr *)skb->data;
2386 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2389 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2392 case PACKET_BROADCAST:
2393 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2396 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2398 /* the source MAC address */
2399 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2400 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2402 memset(fake_hdr->saddr, 0, TR_ALEN);
2404 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2405 fake_llc->dsap = EXTENDED_SAP;
2406 fake_llc->ssap = EXTENDED_SAP;
2407 fake_llc->llc = UI_CMD;
2408 fake_llc->protid[0] = 0;
2409 fake_llc->protid[1] = 0;
2410 fake_llc->protid[2] = 0;
2411 fake_llc->ethertype = ETH_P_IP;
2415 qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
2416 struct qeth_hdr *hdr)
2418 struct ethhdr *fake_hdr;
2419 struct iphdr *ip_hdr;
2421 QETH_DBF_TEXT(trace,5,"skbfketh");
2422 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_ETH;
2423 /* this is a fake ethernet header */
2424 fake_hdr = (struct ethhdr *) skb->mac.raw;
2426 /* the destination MAC address */
2427 switch (skb->pkt_type){
2428 case PACKET_MULTICAST:
2429 switch (skb->protocol){
2430 #ifdef CONFIG_QETH_IPV6
2431 case __constant_htons(ETH_P_IPV6):
2432 ndisc_mc_map((struct in6_addr *)
2433 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2434 fake_hdr->h_dest, card->dev, 0);
2436 #endif /* CONFIG_QETH_IPV6 */
2437 case __constant_htons(ETH_P_IP):
2438 ip_hdr = (struct iphdr *)skb->data;
2439 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
2442 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2445 case PACKET_BROADCAST:
2446 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2449 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2451 /* the source MAC address */
2452 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2453 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2455 memset(fake_hdr->h_source, 0, ETH_ALEN);
2457 fake_hdr->h_proto = skb->protocol;
2461 qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2462 struct qeth_hdr *hdr)
2464 if (card->dev->type == ARPHRD_IEEE802_TR)
2465 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2467 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2471 qeth_rebuild_skb_vlan(struct qeth_card *card, struct sk_buff *skb,
2472 struct qeth_hdr *hdr)
2474 #ifdef CONFIG_QETH_VLAN
2477 if (hdr->hdr.l3.ext_flags &
2478 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2479 vlan_tag = (u16 *) skb_push(skb, VLAN_HLEN);
2480 *vlan_tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2481 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2482 *(vlan_tag + 1) = skb->protocol;
2483 skb->protocol = __constant_htons(ETH_P_8021Q);
2485 #endif /* CONFIG_QETH_VLAN */
2489 qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2490 struct qeth_hdr *hdr)
2492 unsigned short vlan_id = 0;
2493 #ifdef CONFIG_QETH_VLAN
2494 struct vlan_hdr *vhdr;
2497 skb->pkt_type = PACKET_HOST;
2498 skb->protocol = qeth_type_trans(skb, skb->dev);
2499 if (card->options.checksum_type == NO_CHECKSUMMING)
2500 skb->ip_summed = CHECKSUM_UNNECESSARY;
2502 skb->ip_summed = CHECKSUM_NONE;
2503 #ifdef CONFIG_QETH_VLAN
2504 if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) {
2505 vhdr = (struct vlan_hdr *) skb->data;
2507 __constant_htons(vhdr->h_vlan_encapsulated_proto);
2508 vlan_id = hdr->hdr.l2.vlan_id;
2509 skb_pull(skb, VLAN_HLEN);
2512 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
2517 qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2518 struct qeth_hdr *hdr)
2520 #ifdef CONFIG_QETH_IPV6
2521 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2522 skb->pkt_type = PACKET_HOST;
2523 skb->protocol = qeth_type_trans(skb, card->dev);
2526 #endif /* CONFIG_QETH_IPV6 */
2527 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2529 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2530 case QETH_CAST_UNICAST:
2531 skb->pkt_type = PACKET_HOST;
2533 case QETH_CAST_MULTICAST:
2534 skb->pkt_type = PACKET_MULTICAST;
2535 card->stats.multicast++;
2537 case QETH_CAST_BROADCAST:
2538 skb->pkt_type = PACKET_BROADCAST;
2539 card->stats.multicast++;
2541 case QETH_CAST_ANYCAST:
2542 case QETH_CAST_NOCAST:
2544 skb->pkt_type = PACKET_HOST;
2546 qeth_rebuild_skb_vlan(card, skb, hdr);
2547 if (card->options.fake_ll)
2548 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2550 skb->mac.raw = skb->data;
2551 skb->ip_summed = card->options.checksum_type;
2552 if (card->options.checksum_type == HW_CHECKSUMMING){
2553 if ( (hdr->hdr.l3.ext_flags &
2554 (QETH_HDR_EXT_CSUM_HDR_REQ |
2555 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2556 (QETH_HDR_EXT_CSUM_HDR_REQ |
2557 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2558 skb->ip_summed = CHECKSUM_UNNECESSARY;
2560 skb->ip_summed = SW_CHECKSUMMING;
2565 qeth_process_inbound_buffer(struct qeth_card *card,
2566 struct qeth_qdio_buffer *buf, int index)
2568 struct qdio_buffer_element *element;
2569 struct sk_buff *skb;
2570 struct qeth_hdr *hdr;
2575 /* get first element of current buffer */
2576 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2578 #ifdef CONFIG_QETH_PERF_STATS
2579 card->perf_stats.bufs_rec++;
2581 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2583 skb->dev = card->dev;
2584 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2585 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr);
2586 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2587 qeth_rebuild_skb(card, skb, hdr);
2588 else { /*in case of OSN*/
2589 skb_push(skb, sizeof(struct qeth_hdr));
2590 memcpy(skb->data, hdr, sizeof(struct qeth_hdr));
2592 /* is device UP ? */
2593 if (!(card->dev->flags & IFF_UP)){
2594 dev_kfree_skb_any(skb);
2597 #ifdef CONFIG_QETH_VLAN
2599 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2602 if (card->info.type == QETH_CARD_TYPE_OSN)
2603 rxrc = card->osn_info.data_cb(skb);
2605 rxrc = netif_rx(skb);
2606 card->dev->last_rx = jiffies;
2607 card->stats.rx_packets++;
2608 card->stats.rx_bytes += skb->len;
2612 static inline struct qeth_buffer_pool_entry *
2613 qeth_get_buffer_pool_entry(struct qeth_card *card)
2615 struct qeth_buffer_pool_entry *entry;
2617 QETH_DBF_TEXT(trace, 6, "gtbfplen");
2618 if (!list_empty(&card->qdio.in_buf_pool.entry_list)) {
2619 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2620 struct qeth_buffer_pool_entry, list);
2621 list_del_init(&entry->list);
2628 qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2630 struct qeth_buffer_pool_entry *pool_entry;
2633 pool_entry = qeth_get_buffer_pool_entry(card);
2635 * since the buffer is accessed only from the input_tasklet
2636 * there shouldn't be a need to synchronize; also, since we use
2637 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2640 BUG_ON(!pool_entry);
2642 buf->pool_entry = pool_entry;
2643 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2644 buf->buffer->element[i].length = PAGE_SIZE;
2645 buf->buffer->element[i].addr = pool_entry->elements[i];
2646 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2647 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2649 buf->buffer->element[i].flags = 0;
2651 buf->state = QETH_QDIO_BUF_EMPTY;
2655 qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2656 struct qeth_qdio_out_buffer *buf)
2659 struct sk_buff *skb;
2661 /* is PCI flag set on buffer? */
2662 if (buf->buffer->element[0].flags & 0x40)
2663 atomic_dec(&queue->set_pci_flags_count);
2665 while ((skb = skb_dequeue(&buf->skb_list))){
2666 atomic_dec(&skb->users);
2667 dev_kfree_skb_any(skb);
2669 qeth_eddp_buf_release_contexts(buf);
2670 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2671 buf->buffer->element[i].length = 0;
2672 buf->buffer->element[i].addr = NULL;
2673 buf->buffer->element[i].flags = 0;
2675 buf->next_element_to_fill = 0;
2676 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2680 qeth_queue_input_buffer(struct qeth_card *card, int index)
2682 struct qeth_qdio_q *queue = card->qdio.in_q;
2687 QETH_DBF_TEXT(trace,6,"queinbuf");
2688 count = (index < queue->next_buf_to_init)?
2689 card->qdio.in_buf_pool.buf_count -
2690 (queue->next_buf_to_init - index) :
2691 card->qdio.in_buf_pool.buf_count -
2692 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2693 /* only requeue at a certain threshold to avoid SIGAs */
2694 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2695 for (i = queue->next_buf_to_init;
2696 i < queue->next_buf_to_init + count; ++i)
2697 qeth_init_input_buffer(card,
2698 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]);
2700 * according to old code it should be avoided to requeue all
2701 * 128 buffers in order to benefit from PCI avoidance.
2702 * this function keeps at least one buffer (the buffer at
2703 * 'index') un-requeued -> this buffer is the first buffer that
2704 * will be requeued the next time
2706 #ifdef CONFIG_QETH_PERF_STATS
2707 card->perf_stats.inbound_do_qdio_cnt++;
2708 card->perf_stats.inbound_do_qdio_start_time = qeth_get_micros();
2710 rc = do_QDIO(CARD_DDEV(card),
2711 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2712 0, queue->next_buf_to_init, count, NULL);
2713 #ifdef CONFIG_QETH_PERF_STATS
2714 card->perf_stats.inbound_do_qdio_time += qeth_get_micros() -
2715 card->perf_stats.inbound_do_qdio_start_time;
2718 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2719 "return %i (device %s).\n",
2720 rc, CARD_DDEV_ID(card));
2721 QETH_DBF_TEXT(trace,2,"qinberr");
2722 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2724 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2725 QDIO_MAX_BUFFERS_PER_Q;
2730 qeth_put_buffer_pool_entry(struct qeth_card *card,
2731 struct qeth_buffer_pool_entry *entry)
2733 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2734 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2738 qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2739 unsigned int qdio_err, unsigned int siga_err,
2740 unsigned int queue, int first_element, int count,
2741 unsigned long card_ptr)
2743 struct net_device *net_dev;
2744 struct qeth_card *card;
2745 struct qeth_qdio_buffer *buffer;
2749 QETH_DBF_TEXT(trace, 6, "qdinput");
2750 card = (struct qeth_card *) card_ptr;
2751 net_dev = card->dev;
2752 #ifdef CONFIG_QETH_PERF_STATS
2753 card->perf_stats.inbound_cnt++;
2754 card->perf_stats.inbound_start_time = qeth_get_micros();
2756 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2757 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2758 QETH_DBF_TEXT(trace, 1,"qdinchk");
2759 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2760 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2761 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2762 qeth_schedule_recovery(card);
2766 for (i = first_element; i < (first_element + count); ++i) {
2767 index = i % QDIO_MAX_BUFFERS_PER_Q;
2768 buffer = &card->qdio.in_q->bufs[index];
2769 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
2770 qeth_check_qdio_errors(buffer->buffer,
2771 qdio_err, siga_err,"qinerr")))
2772 qeth_process_inbound_buffer(card, buffer, index);
2773 /* clear buffer and give back to hardware */
2774 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2775 qeth_queue_input_buffer(card, index);
2777 #ifdef CONFIG_QETH_PERF_STATS
2778 card->perf_stats.inbound_time += qeth_get_micros() -
2779 card->perf_stats.inbound_start_time;
2784 qeth_handle_send_error(struct qeth_card *card,
2785 struct qeth_qdio_out_buffer *buffer,
2786 unsigned int qdio_err, unsigned int siga_err)
2788 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2789 int cc = siga_err & 3;
2791 QETH_DBF_TEXT(trace, 6, "hdsnderr");
2792 qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr");
2796 QETH_DBF_TEXT(trace, 1,"lnkfail");
2797 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2798 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2799 (u16)qdio_err, (u8)sbalf15);
2800 return QETH_SEND_ERROR_LINK_FAILURE;
2802 return QETH_SEND_ERROR_NONE;
2804 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2805 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2806 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2807 return QETH_SEND_ERROR_KICK_IT;
2809 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2810 return QETH_SEND_ERROR_RETRY;
2811 return QETH_SEND_ERROR_LINK_FAILURE;
2812 /* look at qdio_error and sbalf 15 */
2814 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2815 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2816 return QETH_SEND_ERROR_LINK_FAILURE;
2818 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2819 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2820 return QETH_SEND_ERROR_KICK_IT;
2822 return QETH_SEND_ERROR_LINK_FAILURE;
2826 qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2827 int index, int count)
2829 struct qeth_qdio_out_buffer *buf;
2833 QETH_DBF_TEXT(trace, 6, "flushbuf");
2835 for (i = index; i < index + count; ++i) {
2836 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2837 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2838 SBAL_FLAGS_LAST_ENTRY;
2840 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2843 if (!queue->do_pack){
2844 if ((atomic_read(&queue->used_buffers) >=
2845 (QETH_HIGH_WATERMARK_PACK -
2846 QETH_WATERMARK_PACK_FUZZ)) &&
2847 !atomic_read(&queue->set_pci_flags_count)){
2848 /* it's likely that we'll go to packing
2850 atomic_inc(&queue->set_pci_flags_count);
2851 buf->buffer->element[0].flags |= 0x40;
2854 if (!atomic_read(&queue->set_pci_flags_count)){
2856 * there's no outstanding PCI any more, so we
2857 * have to request a PCI to be sure the the PCI
2858 * will wake at some time in the future then we
2859 * can flush packed buffers that might still be
2860 * hanging around, which can happen if no
2861 * further send was requested by the stack
2863 atomic_inc(&queue->set_pci_flags_count);
2864 buf->buffer->element[0].flags |= 0x40;
2869 queue->card->dev->trans_start = jiffies;
2870 #ifdef CONFIG_QETH_PERF_STATS
2871 queue->card->perf_stats.outbound_do_qdio_cnt++;
2872 queue->card->perf_stats.outbound_do_qdio_start_time = qeth_get_micros();
2875 rc = do_QDIO(CARD_DDEV(queue->card),
2876 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT,
2877 queue->queue_no, index, count, NULL);
2879 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT,
2880 queue->queue_no, index, count, NULL);
2881 #ifdef CONFIG_QETH_PERF_STATS
2882 queue->card->perf_stats.outbound_do_qdio_time += qeth_get_micros() -
2883 queue->card->perf_stats.outbound_do_qdio_start_time;
2886 QETH_DBF_TEXT(trace, 2, "flushbuf");
2887 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
2888 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
2889 queue->card->stats.tx_errors += count;
2890 /* this must not happen under normal circumstances. if it
2891 * happens something is really wrong -> recover */
2892 qeth_schedule_recovery(queue->card);
2895 atomic_add(count, &queue->used_buffers);
2896 #ifdef CONFIG_QETH_PERF_STATS
2897 queue->card->perf_stats.bufs_sent += count;
2902 * Switched to packing state if the number of used buffers on a queue
2903 * reaches a certain limit.
2906 qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2908 if (!queue->do_pack) {
2909 if (atomic_read(&queue->used_buffers)
2910 >= QETH_HIGH_WATERMARK_PACK){
2911 /* switch non-PACKING -> PACKING */
2912 QETH_DBF_TEXT(trace, 6, "np->pack");
2913 #ifdef CONFIG_QETH_PERF_STATS
2914 queue->card->perf_stats.sc_dp_p++;
2922 * Switches from packing to non-packing mode. If there is a packing
2923 * buffer on the queue this buffer will be prepared to be flushed.
2924 * In that case 1 is returned to inform the caller. If no buffer
2925 * has to be flushed, zero is returned.
2928 qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2930 struct qeth_qdio_out_buffer *buffer;
2931 int flush_count = 0;
2933 if (queue->do_pack) {
2934 if (atomic_read(&queue->used_buffers)
2935 <= QETH_LOW_WATERMARK_PACK) {
2936 /* switch PACKING -> non-PACKING */
2937 QETH_DBF_TEXT(trace, 6, "pack->np");
2938 #ifdef CONFIG_QETH_PERF_STATS
2939 queue->card->perf_stats.sc_p_dp++;
2942 /* flush packing buffers */
2943 buffer = &queue->bufs[queue->next_buf_to_fill];
2944 if ((atomic_read(&buffer->state) ==
2945 QETH_QDIO_BUF_EMPTY) &&
2946 (buffer->next_element_to_fill > 0)) {
2947 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
2949 queue->next_buf_to_fill =
2950 (queue->next_buf_to_fill + 1) %
2951 QDIO_MAX_BUFFERS_PER_Q;
2959 * Called to flush a packing buffer if no more pci flags are on the queue.
2960 * Checks if there is a packing buffer and prepares it to be flushed.
2961 * In that case returns 1, otherwise zero.
2964 qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2966 struct qeth_qdio_out_buffer *buffer;
2968 buffer = &queue->bufs[queue->next_buf_to_fill];
2969 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2970 (buffer->next_element_to_fill > 0)){
2971 /* it's a packing buffer */
2972 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2973 queue->next_buf_to_fill =
2974 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2981 qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2985 int q_was_packing = 0;
2988 * check if weed have to switch to non-packing mode or if
2989 * we have to get a pci flag out on the queue
2991 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2992 !atomic_read(&queue->set_pci_flags_count)){
2993 if (atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2994 QETH_OUT_Q_UNLOCKED) {
2996 * If we get in here, there was no action in
2997 * do_send_packet. So, we check if there is a
2998 * packing buffer to be flushed here.
3000 netif_stop_queue(queue->card->dev);
3001 index = queue->next_buf_to_fill;
3002 q_was_packing = queue->do_pack;
3003 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
3005 !atomic_read(&queue->set_pci_flags_count))
3007 qeth_flush_buffers_on_no_pci(queue);
3008 #ifdef CONFIG_QETH_PERF_STATS
3010 queue->card->perf_stats.bufs_sent_pack +=
3014 qeth_flush_buffers(queue, 1, index, flush_cnt);
3015 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3021 qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3022 unsigned int qdio_error, unsigned int siga_error,
3023 unsigned int __queue, int first_element, int count,
3024 unsigned long card_ptr)
3026 struct qeth_card *card = (struct qeth_card *) card_ptr;
3027 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3028 struct qeth_qdio_out_buffer *buffer;
3031 QETH_DBF_TEXT(trace, 6, "qdouhdl");
3032 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
3033 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
3034 QETH_DBF_TEXT(trace, 2, "achkcond");
3035 QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
3036 QETH_DBF_TEXT_(trace, 2, "%08x", status);
3037 netif_stop_queue(card->dev);
3038 qeth_schedule_recovery(card);
3042 #ifdef CONFIG_QETH_PERF_STATS
3043 card->perf_stats.outbound_handler_cnt++;
3044 card->perf_stats.outbound_handler_start_time = qeth_get_micros();
3046 for(i = first_element; i < (first_element + count); ++i){
3047 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
3048 /*we only handle the KICK_IT error by doing a recovery */
3049 if (qeth_handle_send_error(card, buffer,
3050 qdio_error, siga_error)
3051 == QETH_SEND_ERROR_KICK_IT){
3052 netif_stop_queue(card->dev);
3053 qeth_schedule_recovery(card);
3056 qeth_clear_output_buffer(queue, buffer);
3058 atomic_sub(count, &queue->used_buffers);
3059 /* check if we need to do something on this outbound queue */
3060 if (card->info.type != QETH_CARD_TYPE_IQD)
3061 qeth_check_outbound_queue(queue);
3063 netif_wake_queue(queue->card->dev);
3064 #ifdef CONFIG_QETH_PERF_STATS
3065 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3066 card->perf_stats.outbound_handler_start_time;
3071 qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
3074 param_field[0] = _ascebc['P'];
3075 param_field[1] = _ascebc['C'];
3076 param_field[2] = _ascebc['I'];
3077 param_field[3] = _ascebc['T'];
3078 *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card);
3079 *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card);
3080 *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card);
3084 qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
3086 param_field[16] = _ascebc['B'];
3087 param_field[17] = _ascebc['L'];
3088 param_field[18] = _ascebc['K'];
3089 param_field[19] = _ascebc['T'];
3090 *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total;
3091 *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet;
3092 *((unsigned int *) (¶m_field[28])) = card->info.blkt.inter_packet_jumbo;
3096 qeth_initialize_working_pool_list(struct qeth_card *card)
3098 struct qeth_buffer_pool_entry *entry;
3100 QETH_DBF_TEXT(trace,5,"inwrklst");
3102 list_for_each_entry(entry,
3103 &card->qdio.init_pool.entry_list, init_list) {
3104 qeth_put_buffer_pool_entry(card,entry);
3109 qeth_clear_working_pool_list(struct qeth_card *card)
3111 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3113 QETH_DBF_TEXT(trace,5,"clwrklst");
3114 list_for_each_entry_safe(pool_entry, tmp,
3115 &card->qdio.in_buf_pool.entry_list, list){
3116 list_del(&pool_entry->list);
3121 qeth_free_buffer_pool(struct qeth_card *card)
3123 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3125 QETH_DBF_TEXT(trace,5,"freepool");
3126 list_for_each_entry_safe(pool_entry, tmp,
3127 &card->qdio.init_pool.entry_list, init_list){
3128 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3129 free_page((unsigned long)pool_entry->elements[i]);
3130 list_del(&pool_entry->init_list);
3136 qeth_alloc_buffer_pool(struct qeth_card *card)
3138 struct qeth_buffer_pool_entry *pool_entry;
3142 QETH_DBF_TEXT(trace,5,"alocpool");
3143 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3144 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3146 qeth_free_buffer_pool(card);
3149 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
3150 ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
3153 free_page((unsigned long)
3154 pool_entry->elements[--j]);
3156 qeth_free_buffer_pool(card);
3159 pool_entry->elements[j] = ptr;
3161 list_add(&pool_entry->init_list,
3162 &card->qdio.init_pool.entry_list);
3168 qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3170 QETH_DBF_TEXT(trace, 2, "realcbp");
3172 if ((card->state != CARD_STATE_DOWN) &&
3173 (card->state != CARD_STATE_RECOVER))
3176 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3177 qeth_clear_working_pool_list(card);
3178 qeth_free_buffer_pool(card);
3179 card->qdio.in_buf_pool.buf_count = bufcnt;
3180 card->qdio.init_pool.buf_count = bufcnt;
3181 return qeth_alloc_buffer_pool(card);
3185 qeth_alloc_qdio_buffers(struct qeth_card *card)
3189 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3191 if (card->qdio.state == QETH_QDIO_ALLOCATED)
3194 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3195 GFP_KERNEL|GFP_DMA);
3196 if (!card->qdio.in_q)
3198 QETH_DBF_TEXT(setup, 2, "inq");
3199 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3200 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3201 /* give inbound qeth_qdio_buffers their qdio_buffers */
3202 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3203 card->qdio.in_q->bufs[i].buffer =
3204 &card->qdio.in_q->qdio_bufs[i];
3205 /* inbound buffer pool */
3206 if (qeth_alloc_buffer_pool(card)){
3207 kfree(card->qdio.in_q);
3212 kmalloc(card->qdio.no_out_queues *
3213 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3214 if (!card->qdio.out_qs){
3215 qeth_free_buffer_pool(card);
3218 for (i = 0; i < card->qdio.no_out_queues; ++i){
3219 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3220 GFP_KERNEL|GFP_DMA);
3221 if (!card->qdio.out_qs[i]){
3223 kfree(card->qdio.out_qs[--i]);
3224 kfree(card->qdio.out_qs);
3227 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3228 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3229 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3230 card->qdio.out_qs[i]->queue_no = i;
3231 /* give outbound qeth_qdio_buffers their qdio_buffers */
3232 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3233 card->qdio.out_qs[i]->bufs[j].buffer =
3234 &card->qdio.out_qs[i]->qdio_bufs[j];
3235 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3237 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3240 card->qdio.state = QETH_QDIO_ALLOCATED;
3245 qeth_free_qdio_buffers(struct qeth_card *card)
3249 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3250 if (card->qdio.state == QETH_QDIO_UNINITIALIZED)
3252 kfree(card->qdio.in_q);
3253 /* inbound buffer pool */
3254 qeth_free_buffer_pool(card);
3255 /* free outbound qdio_qs */
3256 for (i = 0; i < card->qdio.no_out_queues; ++i){
3257 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3258 qeth_clear_output_buffer(card->qdio.out_qs[i],
3259 &card->qdio.out_qs[i]->bufs[j]);
3260 kfree(card->qdio.out_qs[i]);
3262 kfree(card->qdio.out_qs);
3263 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3267 qeth_clear_qdio_buffers(struct qeth_card *card)
3271 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3272 /* clear outbound buffers to free skbs */
3273 for (i = 0; i < card->qdio.no_out_queues; ++i)
3274 if (card->qdio.out_qs[i]){
3275 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3276 qeth_clear_output_buffer(card->qdio.out_qs[i],
3277 &card->qdio.out_qs[i]->bufs[j]);
3282 qeth_init_qdio_info(struct qeth_card *card)
3284 QETH_DBF_TEXT(setup, 4, "intqdinf");
3285 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3287 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3288 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3289 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3290 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3291 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3295 qeth_init_qdio_queues(struct qeth_card *card)
3300 QETH_DBF_TEXT(setup, 2, "initqdqs");
3303 memset(card->qdio.in_q->qdio_bufs, 0,
3304 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3305 qeth_initialize_working_pool_list(card);
3306 /*give only as many buffers to hardware as we have buffer pool entries*/
3307 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3308 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3309 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3310 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3311 card->qdio.in_buf_pool.buf_count - 1, NULL);
3313 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3316 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3318 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3321 /* outbound queue */
3322 for (i = 0; i < card->qdio.no_out_queues; ++i){
3323 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3324 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3325 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3326 qeth_clear_output_buffer(card->qdio.out_qs[i],
3327 &card->qdio.out_qs[i]->bufs[j]);
3329 card->qdio.out_qs[i]->card = card;
3330 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3331 card->qdio.out_qs[i]->do_pack = 0;
3332 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3333 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3334 atomic_set(&card->qdio.out_qs[i]->state,
3335 QETH_OUT_Q_UNLOCKED);
3341 qeth_qdio_establish(struct qeth_card *card)
3343 struct qdio_initialize init_data;
3344 char *qib_param_field;
3345 struct qdio_buffer **in_sbal_ptrs;
3346 struct qdio_buffer **out_sbal_ptrs;
3350 QETH_DBF_TEXT(setup, 2, "qdioest");
3352 qib_param_field = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3354 if (!qib_param_field)
3357 memset(qib_param_field, 0, QDIO_MAX_BUFFERS_PER_Q * sizeof(char));
3359 qeth_create_qib_param_field(card, qib_param_field);
3360 qeth_create_qib_param_field_blkt(card, qib_param_field);
3362 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3364 if (!in_sbal_ptrs) {
3365 kfree(qib_param_field);
3368 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3369 in_sbal_ptrs[i] = (struct qdio_buffer *)
3370 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3373 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3374 sizeof(void *), GFP_KERNEL);
3375 if (!out_sbal_ptrs) {
3376 kfree(in_sbal_ptrs);
3377 kfree(qib_param_field);
3380 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3381 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3382 out_sbal_ptrs[k] = (struct qdio_buffer *)
3383 virt_to_phys(card->qdio.out_qs[i]->
3387 memset(&init_data, 0, sizeof(struct qdio_initialize));
3388 init_data.cdev = CARD_DDEV(card);
3389 init_data.q_format = qeth_get_qdio_q_format(card);
3390 init_data.qib_param_field_format = 0;
3391 init_data.qib_param_field = qib_param_field;
3392 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3393 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3394 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3395 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3396 init_data.no_input_qs = 1;
3397 init_data.no_output_qs = card->qdio.no_out_queues;
3398 init_data.input_handler = (qdio_handler_t *)
3399 qeth_qdio_input_handler;
3400 init_data.output_handler = (qdio_handler_t *)
3401 qeth_qdio_output_handler;
3402 init_data.int_parm = (unsigned long) card;
3403 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3404 QDIO_OUTBOUND_0COPY_SBALS |
3405 QDIO_USE_OUTBOUND_PCIS;
3406 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3407 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3409 if (!(rc = qdio_initialize(&init_data)))
3410 card->qdio.state = QETH_QDIO_ESTABLISHED;
3412 kfree(out_sbal_ptrs);
3413 kfree(in_sbal_ptrs);
3414 kfree(qib_param_field);
3419 qeth_qdio_activate(struct qeth_card *card)
3421 QETH_DBF_TEXT(setup,3,"qdioact");
3422 return qdio_activate(CARD_DDEV(card), 0);
3426 qeth_clear_channel(struct qeth_channel *channel)
3428 unsigned long flags;
3429 struct qeth_card *card;
3432 QETH_DBF_TEXT(trace,3,"clearch");
3433 card = CARD_FROM_CDEV(channel->ccwdev);
3434 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3435 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3436 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3440 rc = wait_event_interruptible_timeout(card->wait_q,
3441 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3442 if (rc == -ERESTARTSYS)
3444 if (channel->state != CH_STATE_STOPPED)
3446 channel->state = CH_STATE_DOWN;
3451 qeth_halt_channel(struct qeth_channel *channel)
3453 unsigned long flags;
3454 struct qeth_card *card;
3457 QETH_DBF_TEXT(trace,3,"haltch");
3458 card = CARD_FROM_CDEV(channel->ccwdev);
3459 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3460 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3461 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3465 rc = wait_event_interruptible_timeout(card->wait_q,
3466 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3467 if (rc == -ERESTARTSYS)
3469 if (channel->state != CH_STATE_HALTED)
3475 qeth_halt_channels(struct qeth_card *card)
3477 int rc1 = 0, rc2=0, rc3 = 0;
3479 QETH_DBF_TEXT(trace,3,"haltchs");
3480 rc1 = qeth_halt_channel(&card->read);
3481 rc2 = qeth_halt_channel(&card->write);
3482 rc3 = qeth_halt_channel(&card->data);
3490 qeth_clear_channels(struct qeth_card *card)
3492 int rc1 = 0, rc2=0, rc3 = 0;
3494 QETH_DBF_TEXT(trace,3,"clearchs");
3495 rc1 = qeth_clear_channel(&card->read);
3496 rc2 = qeth_clear_channel(&card->write);
3497 rc3 = qeth_clear_channel(&card->data);
3506 qeth_clear_halt_card(struct qeth_card *card, int halt)
3510 QETH_DBF_TEXT(trace,3,"clhacrd");
3511 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3514 rc = qeth_halt_channels(card);
3517 return qeth_clear_channels(card);
3521 qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3525 QETH_DBF_TEXT(trace,3,"qdioclr");
3526 if (card->qdio.state == 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 card->qdio.state = QETH_QDIO_ALLOCATED;
3534 if ((rc = qeth_clear_halt_card(card, use_halt)))
3535 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3536 card->state = CARD_STATE_DOWN;
3541 qeth_dm_act(struct qeth_card *card)
3544 struct qeth_cmd_buffer *iob;
3546 QETH_DBF_TEXT(setup,2,"dmact");
3548 iob = qeth_wait_for_buffer(&card->write);
3549 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3551 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3552 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3553 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3554 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3555 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3560 qeth_mpc_initialize(struct qeth_card *card)
3564 QETH_DBF_TEXT(setup,2,"mpcinit");
3566 if ((rc = qeth_issue_next_read(card))){
3567 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3570 if ((rc = qeth_cm_enable(card))){
3571 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3574 if ((rc = qeth_cm_setup(card))){
3575 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3578 if ((rc = qeth_ulp_enable(card))){
3579 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3582 if ((rc = qeth_ulp_setup(card))){
3583 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3586 if ((rc = qeth_alloc_qdio_buffers(card))){
3587 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3590 if ((rc = qeth_qdio_establish(card))){
3591 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3592 qeth_free_qdio_buffers(card);
3595 if ((rc = qeth_qdio_activate(card))){
3596 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3599 if ((rc = qeth_dm_act(card))){
3600 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3606 qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
3610 static struct net_device *
3611 qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3613 struct net_device *dev = NULL;
3616 case QETH_CARD_TYPE_OSAE:
3618 case QETH_LINK_TYPE_LANE_TR:
3619 case QETH_LINK_TYPE_HSTR:
3621 dev = alloc_trdev(0);
3622 #endif /* CONFIG_TR */
3625 dev = alloc_etherdev(0);
3628 case QETH_CARD_TYPE_IQD:
3629 dev = alloc_netdev(0, "hsi%d", ether_setup);
3631 case QETH_CARD_TYPE_OSN:
3632 dev = alloc_netdev(0, "osn%d", ether_setup);
3635 dev = alloc_etherdev(0);
3640 /*hard_header fake function; used in case fake_ll is set */
3642 qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3643 unsigned short type, void *daddr, void *saddr,
3646 if(dev->type == ARPHRD_IEEE802_TR){
3647 struct trh_hdr *hdr;
3648 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3649 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3650 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3651 return QETH_FAKE_LL_LEN_TR;
3655 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3656 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3657 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3658 if (type != ETH_P_802_3)
3659 hdr->h_proto = htons(type);
3661 hdr->h_proto = htons(len);
3662 return QETH_FAKE_LL_LEN_ETH;
3668 qeth_send_packet(struct qeth_card *, struct sk_buff *);
3671 qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3674 struct qeth_card *card;
3676 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3677 card = (struct qeth_card *)dev->priv;
3679 card->stats.tx_dropped++;
3680 card->stats.tx_errors++;
3681 /* return OK; otherwise ksoftirqd goes to 100% */
3682 return NETDEV_TX_OK;
3684 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3685 card->stats.tx_dropped++;
3686 card->stats.tx_errors++;
3687 card->stats.tx_carrier_errors++;
3688 dev_kfree_skb_any(skb);
3689 /* return OK; otherwise ksoftirqd goes to 100% */
3690 return NETDEV_TX_OK;
3692 #ifdef CONFIG_QETH_PERF_STATS
3693 card->perf_stats.outbound_cnt++;
3694 card->perf_stats.outbound_start_time = qeth_get_micros();
3696 netif_stop_queue(dev);
3697 if ((rc = qeth_send_packet(card, skb))) {
3699 return NETDEV_TX_BUSY;
3701 card->stats.tx_errors++;
3702 card->stats.tx_dropped++;
3703 dev_kfree_skb_any(skb);
3704 /*set to OK; otherwise ksoftirqd goes to 100% */
3708 netif_wake_queue(dev);
3709 #ifdef CONFIG_QETH_PERF_STATS
3710 card->perf_stats.outbound_time += qeth_get_micros() -
3711 card->perf_stats.outbound_start_time;
3717 qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3720 #ifdef CONFIG_QETH_VLAN
3721 struct vlan_group *vg;
3724 if (!(vg = card->vlangrp))
3727 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3728 if (vg->vlan_devices[i] == dev){
3729 rc = QETH_VLAN_CARD;
3733 if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card))
3741 qeth_verify_dev(struct net_device *dev)
3743 struct qeth_card *card;
3744 unsigned long flags;
3747 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3748 list_for_each_entry(card, &qeth_card_list.list, list){
3749 if (card->dev == dev){
3750 rc = QETH_REAL_CARD;
3753 rc = qeth_verify_vlan_dev(dev, card);
3757 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3762 static struct qeth_card *
3763 qeth_get_card_from_dev(struct net_device *dev)
3765 struct qeth_card *card = NULL;
3768 rc = qeth_verify_dev(dev);
3769 if (rc == QETH_REAL_CARD)
3770 card = (struct qeth_card *)dev->priv;
3771 else if (rc == QETH_VLAN_CARD)
3772 card = (struct qeth_card *)
3773 VLAN_DEV_INFO(dev)->real_dev->priv;
3775 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3780 qeth_tx_timeout(struct net_device *dev)
3782 struct qeth_card *card;
3784 card = (struct qeth_card *) dev->priv;
3785 card->stats.tx_errors++;
3786 qeth_schedule_recovery(card);
3790 qeth_open(struct net_device *dev)
3792 struct qeth_card *card;
3794 QETH_DBF_TEXT(trace, 4, "qethopen");
3796 card = (struct qeth_card *) dev->priv;
3798 if (card->state != CARD_STATE_SOFTSETUP)
3801 if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3802 (card->options.layer2) &&
3803 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
3804 QETH_DBF_TEXT(trace,4,"nomacadr");
3807 card->dev->flags |= IFF_UP;
3808 netif_start_queue(dev);
3809 card->data.state = CH_STATE_UP;
3810 card->state = CARD_STATE_UP;
3812 if (!card->lan_online && netif_carrier_ok(dev))
3813 netif_carrier_off(dev);
3818 qeth_stop(struct net_device *dev)
3820 struct qeth_card *card;
3822 QETH_DBF_TEXT(trace, 4, "qethstop");
3824 card = (struct qeth_card *) dev->priv;
3826 netif_stop_queue(dev);
3827 card->dev->flags &= ~IFF_UP;
3828 if (card->state == CARD_STATE_UP)
3829 card->state = CARD_STATE_SOFTSETUP;
3834 qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3836 int cast_type = RTN_UNSPEC;
3838 if (card->info.type == QETH_CARD_TYPE_OSN)
3841 if (skb->dst && skb->dst->neighbour){
3842 cast_type = skb->dst->neighbour->type;
3843 if ((cast_type == RTN_BROADCAST) ||
3844 (cast_type == RTN_MULTICAST) ||
3845 (cast_type == RTN_ANYCAST))
3850 /* try something else */
3851 if (skb->protocol == ETH_P_IPV6)
3852 return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0;
3853 else if (skb->protocol == ETH_P_IP)
3854 return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0;
3856 if (!memcmp(skb->data, skb->dev->broadcast, 6))
3857 return RTN_BROADCAST;
3861 hdr_mac = *((u16 *)skb->data);
3863 switch (card->info.link_type) {
3864 case QETH_LINK_TYPE_HSTR:
3865 case QETH_LINK_TYPE_LANE_TR:
3866 if ((hdr_mac == QETH_TR_MAC_NC) ||
3867 (hdr_mac == QETH_TR_MAC_C))
3868 return RTN_MULTICAST;
3869 /* eth or so multicast? */
3871 if ((hdr_mac == QETH_ETH_MAC_V4) ||
3872 (hdr_mac == QETH_ETH_MAC_V6))
3873 return RTN_MULTICAST;
3880 qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3881 int ipv, int cast_type)
3883 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3884 return card->qdio.default_out_queue;
3885 switch (card->qdio.no_out_queues) {
3887 if (cast_type && card->info.is_multicast_different)
3888 return card->info.is_multicast_different &
3889 (card->qdio.no_out_queues - 1);
3890 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3891 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
3892 if (skb->nh.iph->tos & IP_TOS_NOTIMPORTANT)
3894 if (skb->nh.iph->tos & IP_TOS_HIGHRELIABILITY)
3896 if (skb->nh.iph->tos & IP_TOS_HIGHTHROUGHPUT)
3898 if (skb->nh.iph->tos & IP_TOS_LOWDELAY)
3901 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
3902 return 3 - (skb->nh.iph->tos >> 6);
3903 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3906 return card->qdio.default_out_queue;
3907 case 1: /* fallthrough for single-out-queue 1920-device */
3909 return card->qdio.default_out_queue;
3914 qeth_get_ip_version(struct sk_buff *skb)
3916 switch (skb->protocol) {
3927 qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb,
3928 struct qeth_hdr **hdr, int ipv)
3931 #ifdef CONFIG_QETH_VLAN
3935 QETH_DBF_TEXT(trace, 6, "prepskb");
3936 if (card->info.type == QETH_CARD_TYPE_OSN) {
3937 *hdr = (struct qeth_hdr *)(*skb)->data;
3940 rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3943 #ifdef CONFIG_QETH_VLAN
3944 if (card->vlangrp && vlan_tx_tag_present(*skb) &&
3945 ((ipv == 6) || card->options.layer2) ) {
3947 * Move the mac addresses (6 bytes src, 6 bytes dest)
3948 * to the beginning of the new header. We are using three
3949 * memcpys instead of one memmove to save cycles.
3951 skb_push(*skb, VLAN_HLEN);
3952 memcpy((*skb)->data, (*skb)->data + 4, 4);
3953 memcpy((*skb)->data + 4, (*skb)->data + 8, 4);
3954 memcpy((*skb)->data + 8, (*skb)->data + 12, 4);
3955 tag = (u16 *)((*skb)->data + 12);
3957 * first two bytes = ETH_P_8021Q (0x8100)
3958 * second two bytes = VLANID
3960 *tag = __constant_htons(ETH_P_8021Q);
3961 *(tag + 1) = htons(vlan_tx_tag_get(*skb));
3964 *hdr = (struct qeth_hdr *)
3965 qeth_push_skb(card, skb, sizeof(struct qeth_hdr));
3972 qeth_get_qeth_hdr_flags4(int cast_type)
3974 if (cast_type == RTN_MULTICAST)
3975 return QETH_CAST_MULTICAST;
3976 if (cast_type == RTN_BROADCAST)
3977 return QETH_CAST_BROADCAST;
3978 return QETH_CAST_UNICAST;
3982 qeth_get_qeth_hdr_flags6(int cast_type)
3984 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
3985 if (cast_type == RTN_MULTICAST)
3986 return ct | QETH_CAST_MULTICAST;
3987 if (cast_type == RTN_ANYCAST)
3988 return ct | QETH_CAST_ANYCAST;
3989 if (cast_type == RTN_BROADCAST)
3990 return ct | QETH_CAST_BROADCAST;
3991 return ct | QETH_CAST_UNICAST;
3995 qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
3996 struct sk_buff *skb)
4000 if (!memcmp(skb->data+QETH_HEADER_SIZE,
4001 skb->dev->broadcast,6)) { /* broadcast? */
4002 *(__u32 *)hdr->hdr.l2.flags |=
4003 QETH_LAYER2_FLAG_BROADCAST << 8;
4006 hdr_mac=*((__u16*)skb->data);
4008 switch (card->info.link_type) {
4009 case QETH_LINK_TYPE_HSTR:
4010 case QETH_LINK_TYPE_LANE_TR:
4011 if ((hdr_mac == QETH_TR_MAC_NC) ||
4012 (hdr_mac == QETH_TR_MAC_C) )
4013 *(__u32 *)hdr->hdr.l2.flags |=
4014 QETH_LAYER2_FLAG_MULTICAST << 8;
4016 *(__u32 *)hdr->hdr.l2.flags |=
4017 QETH_LAYER2_FLAG_UNICAST << 8;
4019 /* eth or so multicast? */
4021 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
4022 (hdr_mac==QETH_ETH_MAC_V6) )
4023 *(__u32 *)hdr->hdr.l2.flags |=
4024 QETH_LAYER2_FLAG_MULTICAST << 8;
4026 *(__u32 *)hdr->hdr.l2.flags |=
4027 QETH_LAYER2_FLAG_UNICAST << 8;
4032 qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4033 struct sk_buff *skb, int cast_type)
4035 memset(hdr, 0, sizeof(struct qeth_hdr));
4036 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
4038 /* set byte 0 to "0x02" and byte 3 to casting flags */
4039 if (cast_type==RTN_MULTICAST)
4040 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
4041 else if (cast_type==RTN_BROADCAST)
4042 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
4044 qeth_layer2_get_packet_type(card, hdr, skb);
4046 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
4047 #ifdef CONFIG_QETH_VLAN
4048 /* VSWITCH relies on the VLAN
4049 * information to be present in
4050 * the QDIO header */
4051 if ((card->vlangrp != NULL) &&
4052 vlan_tx_tag_present(skb)) {
4053 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
4054 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
4060 qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4061 struct sk_buff *skb, int ipv, int cast_type)
4063 QETH_DBF_TEXT(trace, 6, "fillhdr");
4065 memset(hdr, 0, sizeof(struct qeth_hdr));
4066 if (card->options.layer2) {
4067 qeth_layer2_fill_header(card, hdr, skb, cast_type);
4070 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
4071 hdr->hdr.l3.ext_flags = 0;
4072 #ifdef CONFIG_QETH_VLAN
4074 * before we're going to overwrite this location with next hop ip.
4075 * v6 uses passthrough, v4 sets the tag in the QDIO header.
4077 if (card->vlangrp && vlan_tx_tag_present(skb)) {
4078 hdr->hdr.l3.ext_flags = (ipv == 4) ?
4079 QETH_HDR_EXT_VLAN_FRAME :
4080 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
4081 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
4083 #endif /* CONFIG_QETH_VLAN */
4084 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
4085 if (ipv == 4) { /* IPv4 */
4086 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
4087 memset(hdr->hdr.l3.dest_addr, 0, 12);
4088 if ((skb->dst) && (skb->dst->neighbour)) {
4089 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
4090 *((u32 *) skb->dst->neighbour->primary_key);
4092 /* fill in destination address used in ip header */
4093 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = skb->nh.iph->daddr;
4095 } else if (ipv == 6) { /* IPv6 or passthru */
4096 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
4097 if ((skb->dst) && (skb->dst->neighbour)) {
4098 memcpy(hdr->hdr.l3.dest_addr,
4099 skb->dst->neighbour->primary_key, 16);
4101 /* fill in destination address used in ip header */
4102 memcpy(hdr->hdr.l3.dest_addr, &skb->nh.ipv6h->daddr, 16);
4104 } else { /* passthrough */
4105 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
4106 !memcmp(skb->data + sizeof(struct qeth_hdr) +
4107 sizeof(__u16), skb->dev->broadcast, 6)) {
4108 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4110 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
4111 skb->dev->broadcast, 6)) { /* broadcast? */
4112 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4115 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
4116 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
4117 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
4123 __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
4124 int is_tso, int *next_element_to_fill)
4126 int length = skb->len;
4132 element = *next_element_to_fill;
4134 first_lap = (is_tso == 0 ? 1 : 0);
4136 while (length > 0) {
4137 /* length_here is the remaining amount of data in this page */
4138 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4139 if (length < length_here)
4140 length_here = length;
4142 buffer->element[element].addr = data;
4143 buffer->element[element].length = length_here;
4144 length -= length_here;
4147 buffer->element[element].flags = 0;
4149 buffer->element[element].flags =
4150 SBAL_FLAGS_LAST_FRAG;
4153 buffer->element[element].flags =
4154 SBAL_FLAGS_FIRST_FRAG;
4156 buffer->element[element].flags =
4157 SBAL_FLAGS_MIDDLE_FRAG;
4159 data += length_here;
4163 *next_element_to_fill = element;
4167 qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4168 struct qeth_qdio_out_buffer *buf,
4169 struct sk_buff *skb)
4171 struct qdio_buffer *buffer;
4172 struct qeth_hdr_tso *hdr;
4173 int flush_cnt = 0, hdr_len, large_send = 0;
4175 QETH_DBF_TEXT(trace, 6, "qdfillbf");
4177 buffer = buf->buffer;
4178 atomic_inc(&skb->users);
4179 skb_queue_tail(&buf->skb_list, skb);
4181 hdr = (struct qeth_hdr_tso *) skb->data;
4182 /*check first on TSO ....*/
4183 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4184 int element = buf->next_element_to_fill;
4186 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4187 /*fill first buffer entry only with header information */
4188 buffer->element[element].addr = skb->data;
4189 buffer->element[element].length = hdr_len;
4190 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4191 buf->next_element_to_fill++;
4192 skb->data += hdr_len;
4193 skb->len -= hdr_len;
4196 if (skb_shinfo(skb)->nr_frags == 0)
4197 __qeth_fill_buffer(skb, buffer, large_send,
4198 (int *)&buf->next_element_to_fill);
4200 __qeth_fill_buffer_frag(skb, buffer, large_send,
4201 (int *)&buf->next_element_to_fill);
4203 if (!queue->do_pack) {
4204 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4205 /* set state to PRIMED -> will be flushed */
4206 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4209 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4210 #ifdef CONFIG_QETH_PERF_STATS
4211 queue->card->perf_stats.skbs_sent_pack++;
4213 if (buf->next_element_to_fill >=
4214 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4216 * packed buffer if full -> set state PRIMED
4217 * -> will be flushed
4219 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4227 qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4228 struct sk_buff *skb, struct qeth_hdr *hdr,
4229 int elements_needed,
4230 struct qeth_eddp_context *ctx)
4232 struct qeth_qdio_out_buffer *buffer;
4233 int buffers_needed = 0;
4237 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4239 /* spin until we get the queue ... */
4240 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4241 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4242 /* ... now we've got the queue */
4243 index = queue->next_buf_to_fill;
4244 buffer = &queue->bufs[queue->next_buf_to_fill];
4246 * check if buffer is empty to make sure that we do not 'overtake'
4247 * ourselves and try to fill a buffer that is already primed
4249 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4250 card->stats.tx_dropped++;
4251 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4255 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4256 QDIO_MAX_BUFFERS_PER_Q;
4258 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4259 if (buffers_needed < 0) {
4260 card->stats.tx_dropped++;
4261 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4264 queue->next_buf_to_fill =
4265 (queue->next_buf_to_fill + buffers_needed) %
4266 QDIO_MAX_BUFFERS_PER_Q;
4268 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4270 qeth_fill_buffer(queue, buffer, skb);
4271 qeth_flush_buffers(queue, 0, index, 1);
4273 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4274 WARN_ON(buffers_needed != flush_cnt);
4275 qeth_flush_buffers(queue, 0, index, flush_cnt);
4281 qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4282 struct sk_buff *skb, struct qeth_hdr *hdr,
4283 int elements_needed, struct qeth_eddp_context *ctx)
4285 struct qeth_qdio_out_buffer *buffer;
4287 int flush_count = 0;
4292 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4294 /* spin until we get the queue ... */
4295 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4296 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4297 start_index = queue->next_buf_to_fill;
4298 buffer = &queue->bufs[queue->next_buf_to_fill];
4300 * check if buffer is empty to make sure that we do not 'overtake'
4301 * ourselves and try to fill a buffer that is already primed
4303 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY){
4304 card->stats.tx_dropped++;
4305 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4308 /* check if we need to switch packing state of this queue */
4309 qeth_switch_to_packing_if_needed(queue);
4310 if (queue->do_pack){
4313 /* does packet fit in current buffer? */
4314 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4315 buffer->next_element_to_fill) < elements_needed){
4316 /* ... no -> set state PRIMED */
4317 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4319 queue->next_buf_to_fill =
4320 (queue->next_buf_to_fill + 1) %
4321 QDIO_MAX_BUFFERS_PER_Q;
4322 buffer = &queue->bufs[queue->next_buf_to_fill];
4323 /* we did a step forward, so check buffer state
4325 if (atomic_read(&buffer->state) !=
4326 QETH_QDIO_BUF_EMPTY){
4327 card->stats.tx_dropped++;
4328 qeth_flush_buffers(queue, 0, start_index, flush_count);
4329 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4334 /* check if we have enough elements (including following
4335 * free buffers) to handle eddp context */
4336 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4337 printk("eddp tx_dropped 1\n");
4338 card->stats.tx_dropped++;
4345 tmp = qeth_fill_buffer(queue, buffer, skb);
4347 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4349 printk("eddp tx_dropped 2\n");
4350 card->stats.tx_dropped++;
4355 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4356 QDIO_MAX_BUFFERS_PER_Q;
4360 qeth_flush_buffers(queue, 0, start_index, flush_count);
4361 else if (!atomic_read(&queue->set_pci_flags_count))
4362 atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
4364 * queue->state will go from LOCKED -> UNLOCKED or from
4365 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4366 * (switch packing state or flush buffer to get another pci flag out).
4367 * In that case we will enter this loop
4369 while (atomic_dec_return(&queue->state)){
4371 start_index = queue->next_buf_to_fill;
4372 /* check if we can go back to non-packing state */
4373 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4375 * check if we need to flush a packing buffer to get a pci
4376 * flag out on the queue
4378 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4379 flush_count += qeth_flush_buffers_on_no_pci(queue);
4381 qeth_flush_buffers(queue, 0, start_index, flush_count);
4383 /* at this point the queue is UNLOCKED again */
4384 #ifdef CONFIG_QETH_PERF_STATS
4386 queue->card->perf_stats.bufs_sent_pack += flush_count;
4387 #endif /* CONFIG_QETH_PERF_STATS */
4393 qeth_get_elements_no(struct qeth_card *card, void *hdr,
4394 struct sk_buff *skb, int elems)
4396 int elements_needed = 0;
4398 if (skb_shinfo(skb)->nr_frags > 0) {
4399 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4401 if (elements_needed == 0 )
4402 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4403 + skb->len) >> PAGE_SHIFT);
4404 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4405 PRINT_ERR("qeth_do_send_packet: invalid size of "
4406 "IP packet (Number=%d / Length=%d). Discarded.\n",
4407 (elements_needed+elems), skb->len);
4410 return elements_needed;
4414 qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4418 struct qeth_qdio_out_q *queue;
4419 struct qeth_hdr *hdr = NULL;
4420 int elements_needed = 0;
4421 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4422 struct qeth_eddp_context *ctx = NULL;
4425 QETH_DBF_TEXT(trace, 6, "sendpkt");
4427 if (!card->options.layer2) {
4428 ipv = qeth_get_ip_version(skb);
4429 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4430 if ((skb = qeth_pskb_unshare(skb,GFP_ATOMIC)) == NULL) {
4431 card->stats.tx_dropped++;
4432 dev_kfree_skb_irq(skb);
4435 if(card->dev->type == ARPHRD_IEEE802_TR){
4436 skb_pull(skb, QETH_FAKE_LL_LEN_TR);
4438 skb_pull(skb, QETH_FAKE_LL_LEN_ETH);
4442 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4443 (skb->protocol == htons(ETH_P_IPV6))) {
4444 dev_kfree_skb_any(skb);
4447 cast_type = qeth_get_cast_type(card, skb);
4448 if ((cast_type == RTN_BROADCAST) &&
4449 (card->info.broadcast_capable == 0)){
4450 card->stats.tx_dropped++;
4451 card->stats.tx_errors++;
4452 dev_kfree_skb_any(skb);
4453 return NETDEV_TX_OK;
4455 queue = card->qdio.out_qs
4456 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4458 if (skb_shinfo(skb)->tso_size)
4459 large_send = card->options.large_send;
4461 /*are we able to do TSO ? If so ,prepare and send it from here */
4462 if ((large_send == QETH_LARGE_SEND_TSO) &&
4463 (cast_type == RTN_UNSPEC)) {
4464 rc = qeth_tso_prepare_packet(card, skb, ipv, cast_type);
4466 card->stats.tx_dropped++;
4467 card->stats.tx_errors++;
4468 dev_kfree_skb_any(skb);
4469 return NETDEV_TX_OK;
4473 if ((rc = qeth_prepare_skb(card, &skb, &hdr, ipv))) {
4474 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc);
4477 if (card->info.type != QETH_CARD_TYPE_OSN)
4478 qeth_fill_header(card, hdr, skb, ipv, cast_type);
4481 if (large_send == QETH_LARGE_SEND_EDDP) {
4482 ctx = qeth_eddp_create_context(card, skb, hdr);
4484 PRINT_WARN("could not create eddp context\n");
4488 int elems = qeth_get_elements_no(card,(void*) hdr, skb,
4492 elements_needed += elems;
4495 if (card->info.type != QETH_CARD_TYPE_IQD)
4496 rc = qeth_do_send_packet(card, queue, skb, hdr,
4497 elements_needed, ctx);
4499 rc = qeth_do_send_packet_fast(card, queue, skb, hdr,
4500 elements_needed, ctx);
4502 card->stats.tx_packets++;
4503 card->stats.tx_bytes += skb->len;
4504 #ifdef CONFIG_QETH_PERF_STATS
4505 if (skb_shinfo(skb)->tso_size &&
4506 !(large_send == QETH_LARGE_SEND_NO)) {
4507 card->perf_stats.large_send_bytes += skb->len;
4508 card->perf_stats.large_send_cnt++;
4510 if (skb_shinfo(skb)->nr_frags > 0){
4511 card->perf_stats.sg_skbs_sent++;
4512 /* nr_frags + skb->data */
4513 card->perf_stats.sg_frags_sent +=
4514 skb_shinfo(skb)->nr_frags + 1;
4516 #endif /* CONFIG_QETH_PERF_STATS */
4519 /* drop creator's reference */
4520 qeth_eddp_put_context(ctx);
4521 /* free skb; it's not referenced by a buffer */
4523 dev_kfree_skb_any(skb);
4530 qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4532 struct qeth_card *card = (struct qeth_card *) dev->priv;
4536 case MII_BMCR: /* Basic mode control register */
4538 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4539 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4540 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4541 rc |= BMCR_SPEED100;
4543 case MII_BMSR: /* Basic mode status register */
4544 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4545 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4548 case MII_PHYSID1: /* PHYS ID 1 */
4549 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4551 rc = (rc >> 5) & 0xFFFF;
4553 case MII_PHYSID2: /* PHYS ID 2 */
4554 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4556 case MII_ADVERTISE: /* Advertisement control reg */
4559 case MII_LPA: /* Link partner ability reg */
4560 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4561 LPA_100BASE4 | LPA_LPACK;
4563 case MII_EXPANSION: /* Expansion register */
4565 case MII_DCOUNTER: /* disconnect counter */
4567 case MII_FCSCOUNTER: /* false carrier counter */
4569 case MII_NWAYTEST: /* N-way auto-neg test register */
4571 case MII_RERRCOUNTER: /* rx error counter */
4572 rc = card->stats.rx_errors;
4574 case MII_SREVISION: /* silicon revision */
4576 case MII_RESV1: /* reserved 1 */
4578 case MII_LBRERROR: /* loopback, rx, bypass error */
4580 case MII_PHYADDR: /* physical address */
4582 case MII_RESV2: /* reserved 2 */
4584 case MII_TPISTATUS: /* TPI status for 10mbps */
4586 case MII_NCONFIG: /* network interface config */
4596 qeth_mdio_write(struct net_device *dev, int phy_id, int regnum, int value)
4599 case MII_BMCR: /* Basic mode control register */
4600 case MII_BMSR: /* Basic mode status register */
4601 case MII_PHYSID1: /* PHYS ID 1 */
4602 case MII_PHYSID2: /* PHYS ID 2 */
4603 case MII_ADVERTISE: /* Advertisement control reg */
4604 case MII_LPA: /* Link partner ability reg */
4605 case MII_EXPANSION: /* Expansion register */
4606 case MII_DCOUNTER: /* disconnect counter */
4607 case MII_FCSCOUNTER: /* false carrier counter */
4608 case MII_NWAYTEST: /* N-way auto-neg test register */
4609 case MII_RERRCOUNTER: /* rx error counter */
4610 case MII_SREVISION: /* silicon revision */
4611 case MII_RESV1: /* reserved 1 */
4612 case MII_LBRERROR: /* loopback, rx, bypass error */
4613 case MII_PHYADDR: /* physical address */
4614 case MII_RESV2: /* reserved 2 */
4615 case MII_TPISTATUS: /* TPI status for 10mbps */
4616 case MII_NCONFIG: /* network interface config */
4622 static inline const char *
4623 qeth_arp_get_error_cause(int *rc)
4626 case QETH_IPA_ARP_RC_FAILED:
4628 return "operation failed";
4629 case QETH_IPA_ARP_RC_NOTSUPP:
4631 return "operation not supported";
4632 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4634 return "argument out of range";
4635 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4637 return "query operation not supported";
4638 case QETH_IPA_ARP_RC_Q_NO_DATA:
4640 return "no query data available";
4642 return "unknown error";
4647 qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4651 qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4656 QETH_DBF_TEXT(trace,3,"arpstnoe");
4659 * currently GuestLAN only supports the ARP assist function
4660 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4661 * thus we say EOPNOTSUPP for this ARP function
4663 if (card->info.guestlan)
4665 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4666 PRINT_WARN("ARP processing not supported "
4667 "on %s!\n", QETH_CARD_IFNAME(card));
4670 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4671 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4675 PRINT_WARN("Could not set number of ARP entries on %s: "
4677 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4684 qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4685 struct qeth_arp_query_data *qdata,
4686 int entry_size, int uentry_size)
4692 entry_ptr = (char *)&qdata->data;
4693 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4694 for (i = 0; i < qdata->no_entries; ++i){
4695 /* strip off 32 bytes "media specific information" */
4696 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4697 entry_ptr += entry_size;
4698 uentry_ptr += uentry_size;
4703 qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4706 struct qeth_ipa_cmd *cmd;
4707 struct qeth_arp_query_data *qdata;
4708 struct qeth_arp_query_info *qinfo;
4713 QETH_DBF_TEXT(trace,4,"arpquecb");
4715 qinfo = (struct qeth_arp_query_info *) reply->param;
4716 cmd = (struct qeth_ipa_cmd *) data;
4717 if (cmd->hdr.return_code) {
4718 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4721 if (cmd->data.setassparms.hdr.return_code) {
4722 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4723 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4726 qdata = &cmd->data.setassparms.data.query_arp;
4727 switch(qdata->reply_bits){
4729 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4730 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4731 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4734 /* fall through to default */
4736 /* tr is the same as eth -> entry7 */
4737 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4738 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4739 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4742 /* check if there is enough room in userspace */
4743 if ((qinfo->udata_len - qinfo->udata_offset) <
4744 qdata->no_entries * uentry_size){
4745 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4746 cmd->hdr.return_code = -ENOMEM;
4747 PRINT_WARN("query ARP user space buffer is too small for "
4748 "the returned number of ARP entries. "
4749 "Aborting query!\n");
4752 QETH_DBF_TEXT_(trace, 4, "anore%i",
4753 cmd->data.setassparms.hdr.number_of_replies);
4754 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4755 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4757 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4758 /* strip off "media specific information" */
4759 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4762 /*copy entries to user buffer*/
4763 memcpy(qinfo->udata + qinfo->udata_offset,
4764 (char *)&qdata->data, qdata->no_entries*uentry_size);
4766 qinfo->no_entries += qdata->no_entries;
4767 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4768 /* check if all replies received ... */
4769 if (cmd->data.setassparms.hdr.seq_no <
4770 cmd->data.setassparms.hdr.number_of_replies)
4772 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4773 /* keep STRIP_ENTRIES flag so the user program can distinguish
4774 * stripped entries from normal ones */
4775 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4776 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4777 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4781 memcpy(qinfo->udata, &i, 4);
4786 qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4787 int len, int (*reply_cb)(struct qeth_card *,
4788 struct qeth_reply *,
4792 QETH_DBF_TEXT(trace,4,"sendarp");
4794 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4795 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4796 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4797 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4798 reply_cb, reply_param);
4802 qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4803 int len, int (*reply_cb)(struct qeth_card *,
4804 struct qeth_reply *,
4810 QETH_DBF_TEXT(trace,4,"sendsnmp");
4812 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4813 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4814 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4815 /* adjust PDU length fields in IPA_PDU_HEADER */
4816 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4818 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4819 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4820 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4821 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4822 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4823 reply_cb, reply_param);
4826 static struct qeth_cmd_buffer *
4827 qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4828 __u16, __u16, enum qeth_prot_versions);
4830 qeth_arp_query(struct qeth_card *card, char *udata)
4832 struct qeth_cmd_buffer *iob;
4833 struct qeth_arp_query_info qinfo = {0, };
4837 QETH_DBF_TEXT(trace,3,"arpquery");
4839 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4840 IPA_ARP_PROCESSING)) {
4841 PRINT_WARN("ARP processing not supported "
4842 "on %s!\n", QETH_CARD_IFNAME(card));
4845 /* get size of userspace buffer and mask_bits -> 6 bytes */
4846 if (copy_from_user(&qinfo, udata, 6))
4848 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL)))
4850 memset(qinfo.udata, 0, qinfo.udata_len);
4851 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4852 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4853 IPA_CMD_ASS_ARP_QUERY_INFO,
4854 sizeof(int),QETH_PROT_IPV4);
4856 rc = qeth_send_ipa_arp_cmd(card, iob,
4857 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4858 qeth_arp_query_cb, (void *)&qinfo);
4861 PRINT_WARN("Error while querying ARP cache on %s: %s "
4863 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4865 copy_to_user(udata, qinfo.udata, 4);
4867 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4874 * SNMP command callback
4877 qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4878 unsigned long sdata)
4880 struct qeth_ipa_cmd *cmd;
4881 struct qeth_arp_query_info *qinfo;
4882 struct qeth_snmp_cmd *snmp;
4883 unsigned char *data;
4886 QETH_DBF_TEXT(trace,3,"snpcmdcb");
4888 cmd = (struct qeth_ipa_cmd *) sdata;
4889 data = (unsigned char *)((char *)cmd - reply->offset);
4890 qinfo = (struct qeth_arp_query_info *) reply->param;
4891 snmp = &cmd->data.setadapterparms.data.snmp;
4893 if (cmd->hdr.return_code) {
4894 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4897 if (cmd->data.setadapterparms.hdr.return_code) {
4898 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4899 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4902 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4903 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4904 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4906 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4908 /* check if there is enough room in userspace */
4909 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4910 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4911 cmd->hdr.return_code = -ENOMEM;
4914 QETH_DBF_TEXT_(trace, 4, "snore%i",
4915 cmd->data.setadapterparms.hdr.used_total);
4916 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4917 /*copy entries to user buffer*/
4918 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4919 memcpy(qinfo->udata + qinfo->udata_offset,
4921 data_len + offsetof(struct qeth_snmp_cmd,data));
4922 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4924 memcpy(qinfo->udata + qinfo->udata_offset,
4925 (char *)&snmp->request, data_len);
4927 qinfo->udata_offset += data_len;
4928 /* check if all replies received ... */
4929 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4930 cmd->data.setadapterparms.hdr.used_total);
4931 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4932 cmd->data.setadapterparms.hdr.seq_no);
4933 if (cmd->data.setadapterparms.hdr.seq_no <
4934 cmd->data.setadapterparms.hdr.used_total)
4939 static struct qeth_cmd_buffer *
4940 qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4941 enum qeth_prot_versions );
4943 static struct qeth_cmd_buffer *
4944 qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4946 struct qeth_cmd_buffer *iob;
4947 struct qeth_ipa_cmd *cmd;
4949 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4951 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4952 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4953 cmd->data.setadapterparms.hdr.command_code = command;
4954 cmd->data.setadapterparms.hdr.used_total = 1;
4955 cmd->data.setadapterparms.hdr.seq_no = 1;
4961 * function to send SNMP commands to OSA-E card
4964 qeth_snmp_command(struct qeth_card *card, char *udata)
4966 struct qeth_cmd_buffer *iob;
4967 struct qeth_ipa_cmd *cmd;
4968 struct qeth_snmp_ureq *ureq;
4970 struct qeth_arp_query_info qinfo = {0, };
4973 QETH_DBF_TEXT(trace,3,"snmpcmd");
4975 if (card->info.guestlan)
4978 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4979 (!card->options.layer2) ) {
4980 PRINT_WARN("SNMP Query MIBS not supported "
4981 "on %s!\n", QETH_CARD_IFNAME(card));
4984 /* skip 4 bytes (data_len struct member) to get req_len */
4985 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4987 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4989 QETH_DBF_TEXT(trace, 2, "snmpnome");
4992 if (copy_from_user(ureq, udata,
4993 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
4997 qinfo.udata_len = ureq->hdr.data_len;
4998 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL))){
5002 memset(qinfo.udata, 0, qinfo.udata_len);
5003 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
5005 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
5006 QETH_SNMP_SETADP_CMDLENGTH + req_len);
5007 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5008 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
5009 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
5010 qeth_snmp_command_cb, (void *)&qinfo);
5012 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
5013 QETH_CARD_IFNAME(card), rc);
5015 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
5023 qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
5027 qeth_default_setadapterparms_cb(struct qeth_card *card,
5028 struct qeth_reply *reply,
5029 unsigned long data);
5031 qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
5034 (struct qeth_card *, struct qeth_reply *, unsigned long),
5038 qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5040 struct qeth_cmd_buffer *iob;
5045 QETH_DBF_TEXT(trace,3,"arpadent");
5048 * currently GuestLAN only supports the ARP assist function
5049 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
5050 * thus we say EOPNOTSUPP for this ARP function
5052 if (card->info.guestlan)
5054 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5055 PRINT_WARN("ARP processing not supported "
5056 "on %s!\n", QETH_CARD_IFNAME(card));
5060 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5061 IPA_CMD_ASS_ARP_ADD_ENTRY,
5062 sizeof(struct qeth_arp_cache_entry),
5064 rc = qeth_send_setassparms(card, iob,
5065 sizeof(struct qeth_arp_cache_entry),
5066 (unsigned long) entry,
5067 qeth_default_setassparms_cb, NULL);
5070 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5071 PRINT_WARN("Could not add ARP entry for address %s on %s: "
5073 buf, QETH_CARD_IFNAME(card),
5074 qeth_arp_get_error_cause(&rc), tmp, tmp);
5080 qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5082 struct qeth_cmd_buffer *iob;
5083 char buf[16] = {0, };
5087 QETH_DBF_TEXT(trace,3,"arprment");
5090 * currently GuestLAN only supports the ARP assist function
5091 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5092 * thus we say EOPNOTSUPP for this ARP function
5094 if (card->info.guestlan)
5096 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5097 PRINT_WARN("ARP processing not supported "
5098 "on %s!\n", QETH_CARD_IFNAME(card));
5101 memcpy(buf, entry, 12);
5102 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5103 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5106 rc = qeth_send_setassparms(card, iob,
5107 12, (unsigned long)buf,
5108 qeth_default_setassparms_cb, NULL);
5112 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5113 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5115 buf, QETH_CARD_IFNAME(card),
5116 qeth_arp_get_error_cause(&rc), tmp, tmp);
5122 qeth_arp_flush_cache(struct qeth_card *card)
5127 QETH_DBF_TEXT(trace,3,"arpflush");
5130 * currently GuestLAN only supports the ARP assist function
5131 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5132 * thus we say EOPNOTSUPP for this ARP function
5134 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5136 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5137 PRINT_WARN("ARP processing not supported "
5138 "on %s!\n", QETH_CARD_IFNAME(card));
5141 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5142 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5145 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5146 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5153 qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5155 struct qeth_card *card = (struct qeth_card *)dev->priv;
5156 struct qeth_arp_cache_entry arp_entry;
5157 struct mii_ioctl_data *mii_data;
5163 if ((card->state != CARD_STATE_UP) &&
5164 (card->state != CARD_STATE_SOFTSETUP))
5167 if (card->info.type == QETH_CARD_TYPE_OSN)
5171 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5172 if ( !capable(CAP_NET_ADMIN) ||
5173 (card->options.layer2) ) {
5177 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5179 case SIOC_QETH_ARP_QUERY_INFO:
5180 if ( !capable(CAP_NET_ADMIN) ||
5181 (card->options.layer2) ) {
5185 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5187 case SIOC_QETH_ARP_ADD_ENTRY:
5188 if ( !capable(CAP_NET_ADMIN) ||
5189 (card->options.layer2) ) {
5193 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5194 sizeof(struct qeth_arp_cache_entry)))
5197 rc = qeth_arp_add_entry(card, &arp_entry);
5199 case SIOC_QETH_ARP_REMOVE_ENTRY:
5200 if ( !capable(CAP_NET_ADMIN) ||
5201 (card->options.layer2) ) {
5205 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5206 sizeof(struct qeth_arp_cache_entry)))
5209 rc = qeth_arp_remove_entry(card, &arp_entry);
5211 case SIOC_QETH_ARP_FLUSH_CACHE:
5212 if ( !capable(CAP_NET_ADMIN) ||
5213 (card->options.layer2) ) {
5217 rc = qeth_arp_flush_cache(card);
5219 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5220 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5222 case SIOC_QETH_GET_CARD_TYPE:
5223 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5224 !card->info.guestlan)
5229 mii_data = if_mii(rq);
5230 mii_data->phy_id = 0;
5233 mii_data = if_mii(rq);
5234 if (mii_data->phy_id != 0)
5237 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5243 /* TODO: remove return if qeth_mdio_write does something */
5244 if (!capable(CAP_NET_ADMIN)){
5248 mii_data = if_mii(rq);
5249 if (mii_data->phy_id != 0)
5252 qeth_mdio_write(dev, mii_data->phy_id, mii_data->reg_num,
5259 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5263 static struct net_device_stats *
5264 qeth_get_stats(struct net_device *dev)
5266 struct qeth_card *card;
5268 card = (struct qeth_card *) (dev->priv);
5270 QETH_DBF_TEXT(trace,5,"getstat");
5272 return &card->stats;
5276 qeth_change_mtu(struct net_device *dev, int new_mtu)
5278 struct qeth_card *card;
5281 card = (struct qeth_card *) (dev->priv);
5283 QETH_DBF_TEXT(trace,4,"chgmtu");
5284 sprintf(dbf_text, "%8x", new_mtu);
5285 QETH_DBF_TEXT(trace,4,dbf_text);
5289 if (new_mtu > 65535)
5291 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5292 (!qeth_mtu_is_valid(card, new_mtu)))
5298 #ifdef CONFIG_QETH_VLAN
5300 qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5302 struct qeth_card *card;
5303 unsigned long flags;
5305 QETH_DBF_TEXT(trace,4,"vlanreg");
5307 card = (struct qeth_card *) dev->priv;
5308 spin_lock_irqsave(&card->vlanlock, flags);
5309 card->vlangrp = grp;
5310 spin_unlock_irqrestore(&card->vlanlock, flags);
5314 qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5318 struct sk_buff *skb;
5319 struct sk_buff_head tmp_list;
5321 skb_queue_head_init(&tmp_list);
5322 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5323 while ((skb = skb_dequeue(&buf->skb_list))){
5324 if (vlan_tx_tag_present(skb) &&
5325 (vlan_tx_tag_get(skb) == vid)) {
5326 atomic_dec(&skb->users);
5329 skb_queue_tail(&tmp_list, skb);
5332 while ((skb = skb_dequeue(&tmp_list)))
5333 skb_queue_tail(&buf->skb_list, skb);
5337 qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5341 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5342 for (i = 0; i < card->qdio.no_out_queues; ++i){
5343 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5344 qeth_free_vlan_buffer(card, &card->qdio.
5345 out_qs[i]->bufs[j], vid);
5350 qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5352 struct in_device *in_dev;
5353 struct in_ifaddr *ifa;
5354 struct qeth_ipaddr *addr;
5356 QETH_DBF_TEXT(trace, 4, "frvaddr4");
5359 in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]);
5362 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5363 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5365 addr->u.a4.addr = ifa->ifa_address;
5366 addr->u.a4.mask = ifa->ifa_mask;
5367 addr->type = QETH_IP_TYPE_NORMAL;
5368 if (!qeth_delete_ip(card, addr))
5377 qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5379 #ifdef CONFIG_QETH_IPV6
5380 struct inet6_dev *in6_dev;
5381 struct inet6_ifaddr *ifa;
5382 struct qeth_ipaddr *addr;
5384 QETH_DBF_TEXT(trace, 4, "frvaddr6");
5386 in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]);
5389 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5390 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5392 memcpy(&addr->u.a6.addr, &ifa->addr,
5393 sizeof(struct in6_addr));
5394 addr->u.a6.pfxlen = ifa->prefix_len;
5395 addr->type = QETH_IP_TYPE_NORMAL;
5396 if (!qeth_delete_ip(card, addr))
5400 in6_dev_put(in6_dev);
5401 #endif /* CONFIG_QETH_IPV6 */
5405 qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5407 if (card->options.layer2 || !card->vlangrp)
5409 qeth_free_vlan_addresses4(card, vid);
5410 qeth_free_vlan_addresses6(card, vid);
5414 qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5415 struct qeth_reply *reply,
5418 struct qeth_ipa_cmd *cmd;
5420 QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5421 cmd = (struct qeth_ipa_cmd *) data;
5422 if (cmd->hdr.return_code) {
5423 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5424 "Continuing\n",cmd->data.setdelvlan.vlan_id,
5425 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5426 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5427 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5428 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5434 qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5435 enum qeth_ipa_cmds ipacmd)
5437 struct qeth_ipa_cmd *cmd;
5438 struct qeth_cmd_buffer *iob;
5440 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5441 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5442 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5443 cmd->data.setdelvlan.vlan_id = i;
5444 return qeth_send_ipa_cmd(card, iob,
5445 qeth_layer2_send_setdelvlan_cb, NULL);
5449 qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5453 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5457 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5458 if (card->vlangrp->vlan_devices[i] == NULL)
5461 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5463 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5467 /*add_vid is layer 2 used only ....*/
5469 qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5471 struct qeth_card *card;
5473 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5475 card = (struct qeth_card *) dev->priv;
5476 if (!card->options.layer2)
5478 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5481 /*... kill_vid used for both modes*/
5483 qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5485 struct qeth_card *card;
5486 unsigned long flags;
5488 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5490 card = (struct qeth_card *) dev->priv;
5491 /* free all skbs for the vlan device */
5492 qeth_free_vlan_skbs(card, vid);
5493 spin_lock_irqsave(&card->vlanlock, flags);
5494 /* unregister IP addresses of vlan device */
5495 qeth_free_vlan_addresses(card, vid);
5497 card->vlangrp->vlan_devices[vid] = NULL;
5498 spin_unlock_irqrestore(&card->vlanlock, flags);
5499 if (card->options.layer2)
5500 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5501 qeth_set_multicast_list(card->dev);
5505 * Examine hardware response to SET_PROMISC_MODE
5508 qeth_setadp_promisc_mode_cb(struct qeth_card *card,
5509 struct qeth_reply *reply,
5512 struct qeth_ipa_cmd *cmd;
5513 struct qeth_ipacmd_setadpparms *setparms;
5515 QETH_DBF_TEXT(trace,4,"prmadpcb");
5517 cmd = (struct qeth_ipa_cmd *) data;
5518 setparms = &(cmd->data.setadapterparms);
5520 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
5521 if (cmd->hdr.return_code) {
5522 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
5523 setparms->data.mode = SET_PROMISC_MODE_OFF;
5525 card->info.promisc_mode = setparms->data.mode;
5529 * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5532 qeth_setadp_promisc_mode(struct qeth_card *card)
5534 enum qeth_ipa_promisc_modes mode;
5535 struct net_device *dev = card->dev;
5536 struct qeth_cmd_buffer *iob;
5537 struct qeth_ipa_cmd *cmd;
5539 QETH_DBF_TEXT(trace, 4, "setprom");
5541 if (((dev->flags & IFF_PROMISC) &&
5542 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5543 (!(dev->flags & IFF_PROMISC) &&
5544 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5546 mode = SET_PROMISC_MODE_OFF;
5547 if (dev->flags & IFF_PROMISC)
5548 mode = SET_PROMISC_MODE_ON;
5549 QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5551 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5552 sizeof(struct qeth_ipacmd_setadpparms));
5553 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5554 cmd->data.setadapterparms.data.mode = mode;
5555 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5559 * set multicast address on card
5562 qeth_set_multicast_list(struct net_device *dev)
5564 struct qeth_card *card = (struct qeth_card *) dev->priv;
5566 if (card->info.type == QETH_CARD_TYPE_OSN)
5569 QETH_DBF_TEXT(trace,3,"setmulti");
5570 qeth_delete_mc_addresses(card);
5571 if (card->options.layer2) {
5572 qeth_layer2_add_multicast(card);
5575 qeth_add_multicast_ipv4(card);
5576 #ifdef CONFIG_QETH_IPV6
5577 qeth_add_multicast_ipv6(card);
5580 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
5581 schedule_work(&card->kernel_thread_starter);
5582 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5584 if (qeth_set_thread_start_bit(card, QETH_SET_PROMISC_MODE_THREAD)==0)
5585 schedule_work(&card->kernel_thread_starter);
5590 qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5596 qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5598 if (dev->type == ARPHRD_IEEE802_TR)
5599 ip_tr_mc_map(ipm, mac);
5601 ip_eth_mc_map(ipm, mac);
5604 static struct qeth_ipaddr *
5605 qeth_get_addr_buffer(enum qeth_prot_versions prot)
5607 struct qeth_ipaddr *addr;
5609 addr = kmalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5611 PRINT_WARN("Not enough memory to add address\n");
5614 memset(addr,0,sizeof(struct qeth_ipaddr));
5615 addr->type = QETH_IP_TYPE_NORMAL;
5621 qeth_osn_assist(struct net_device *dev,
5625 struct qeth_cmd_buffer *iob;
5626 struct qeth_card *card;
5629 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5632 card = (struct qeth_card *)dev->priv;
5635 if ((card->state != CARD_STATE_UP) &&
5636 (card->state != CARD_STATE_SOFTSETUP))
5638 iob = qeth_wait_for_buffer(&card->write);
5639 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5640 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5644 static struct net_device *
5645 qeth_netdev_by_devno(unsigned char *read_dev_no)
5647 struct qeth_card *card;
5648 struct net_device *ndev;
5649 unsigned char *readno;
5650 __u16 temp_dev_no, card_dev_no;
5652 unsigned long flags;
5655 memcpy(&temp_dev_no, read_dev_no, 2);
5656 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5657 list_for_each_entry(card, &qeth_card_list.list, list) {
5658 readno = CARD_RDEV_ID(card);
5659 readno += (strlen(readno) - 4);
5660 card_dev_no = simple_strtoul(readno, &endp, 16);
5661 if (card_dev_no == temp_dev_no) {
5666 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5671 qeth_osn_register(unsigned char *read_dev_no,
5672 struct net_device **dev,
5673 int (*assist_cb)(struct net_device *, void *),
5674 int (*data_cb)(struct sk_buff *))
5676 struct qeth_card * card;
5678 QETH_DBF_TEXT(trace, 2, "osnreg");
5679 *dev = qeth_netdev_by_devno(read_dev_no);
5682 card = (struct qeth_card *)(*dev)->priv;
5685 if ((assist_cb == NULL) || (data_cb == NULL))
5687 card->osn_info.assist_cb = assist_cb;
5688 card->osn_info.data_cb = data_cb;
5693 qeth_osn_deregister(struct net_device * dev)
5695 struct qeth_card *card;
5697 QETH_DBF_TEXT(trace, 2, "osndereg");
5700 card = (struct qeth_card *)dev->priv;
5703 card->osn_info.assist_cb = NULL;
5704 card->osn_info.data_cb = NULL;
5709 qeth_delete_mc_addresses(struct qeth_card *card)
5711 struct qeth_ipaddr *iptodo;
5712 unsigned long flags;
5714 QETH_DBF_TEXT(trace,4,"delmc");
5715 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5717 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5720 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5721 spin_lock_irqsave(&card->ip_lock, flags);
5722 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5724 spin_unlock_irqrestore(&card->ip_lock, flags);
5728 qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5730 struct qeth_ipaddr *ipm;
5731 struct ip_mc_list *im4;
5732 char buf[MAX_ADDR_LEN];
5734 QETH_DBF_TEXT(trace,4,"addmc");
5735 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5736 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5737 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5740 ipm->u.a4.addr = im4->multiaddr;
5741 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5742 ipm->is_multicast = 1;
5743 if (!qeth_add_ip(card,ipm))
5749 qeth_add_vlan_mc(struct qeth_card *card)
5751 #ifdef CONFIG_QETH_VLAN
5752 struct in_device *in_dev;
5753 struct vlan_group *vg;
5756 QETH_DBF_TEXT(trace,4,"addmcvl");
5757 if ( ((card->options.layer2 == 0) &&
5758 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5759 (card->vlangrp == NULL) )
5763 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5764 if (vg->vlan_devices[i] == NULL ||
5765 !(vg->vlan_devices[i]->flags & IFF_UP))
5767 in_dev = in_dev_get(vg->vlan_devices[i]);
5770 read_lock(&in_dev->mc_list_lock);
5771 qeth_add_mc(card,in_dev);
5772 read_unlock(&in_dev->mc_list_lock);
5779 qeth_add_multicast_ipv4(struct qeth_card *card)
5781 struct in_device *in4_dev;
5783 QETH_DBF_TEXT(trace,4,"chkmcv4");
5784 in4_dev = in_dev_get(card->dev);
5785 if (in4_dev == NULL)
5787 read_lock(&in4_dev->mc_list_lock);
5788 qeth_add_mc(card, in4_dev);
5789 qeth_add_vlan_mc(card);
5790 read_unlock(&in4_dev->mc_list_lock);
5791 in_dev_put(in4_dev);
5795 qeth_layer2_add_multicast(struct qeth_card *card)
5797 struct qeth_ipaddr *ipm;
5798 struct dev_mc_list *dm;
5800 QETH_DBF_TEXT(trace,4,"L2addmc");
5801 for (dm = card->dev->mc_list; dm; dm = dm->next) {
5802 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5805 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5806 ipm->is_multicast = 1;
5807 if (!qeth_add_ip(card, ipm))
5812 #ifdef CONFIG_QETH_IPV6
5814 qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5816 struct qeth_ipaddr *ipm;
5817 struct ifmcaddr6 *im6;
5818 char buf[MAX_ADDR_LEN];
5820 QETH_DBF_TEXT(trace,4,"addmc6");
5821 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5822 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5823 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5826 ipm->is_multicast = 1;
5827 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5828 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5829 sizeof(struct in6_addr));
5830 if (!qeth_add_ip(card,ipm))
5836 qeth_add_vlan_mc6(struct qeth_card *card)
5838 #ifdef CONFIG_QETH_VLAN
5839 struct inet6_dev *in_dev;
5840 struct vlan_group *vg;
5843 QETH_DBF_TEXT(trace,4,"admc6vl");
5844 if ( ((card->options.layer2 == 0) &&
5845 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5846 (card->vlangrp == NULL))
5850 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5851 if (vg->vlan_devices[i] == NULL ||
5852 !(vg->vlan_devices[i]->flags & IFF_UP))
5854 in_dev = in6_dev_get(vg->vlan_devices[i]);
5857 read_lock(&in_dev->lock);
5858 qeth_add_mc6(card,in_dev);
5859 read_unlock(&in_dev->lock);
5860 in6_dev_put(in_dev);
5862 #endif /* CONFIG_QETH_VLAN */
5866 qeth_add_multicast_ipv6(struct qeth_card *card)
5868 struct inet6_dev *in6_dev;
5870 QETH_DBF_TEXT(trace,4,"chkmcv6");
5871 if (!qeth_is_supported(card, IPA_IPV6))
5873 in6_dev = in6_dev_get(card->dev);
5874 if (in6_dev == NULL)
5876 read_lock(&in6_dev->lock);
5877 qeth_add_mc6(card, in6_dev);
5878 qeth_add_vlan_mc6(card);
5879 read_unlock(&in6_dev->lock);
5880 in6_dev_put(in6_dev);
5882 #endif /* CONFIG_QETH_IPV6 */
5885 qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5886 enum qeth_ipa_cmds ipacmd,
5887 int (*reply_cb) (struct qeth_card *,
5891 struct qeth_ipa_cmd *cmd;
5892 struct qeth_cmd_buffer *iob;
5894 QETH_DBF_TEXT(trace, 2, "L2sdmac");
5895 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5896 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5897 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5898 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5899 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5903 qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5904 struct qeth_reply *reply,
5907 struct qeth_ipa_cmd *cmd;
5910 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5911 cmd = (struct qeth_ipa_cmd *) data;
5912 mac = &cmd->data.setdelmac.mac[0];
5913 /* MAC already registered, needed in couple/uncouple case */
5914 if (cmd->hdr.return_code == 0x2005) {
5915 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5916 "already existing on %s \n",
5917 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5918 QETH_CARD_IFNAME(card));
5919 cmd->hdr.return_code = 0;
5921 if (cmd->hdr.return_code)
5922 PRINT_ERR("Could not set group MAC " \
5923 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5924 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5925 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5930 qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5932 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5933 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5934 qeth_layer2_send_setgroupmac_cb);
5938 qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5939 struct qeth_reply *reply,
5942 struct qeth_ipa_cmd *cmd;
5945 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5946 cmd = (struct qeth_ipa_cmd *) data;
5947 mac = &cmd->data.setdelmac.mac[0];
5948 if (cmd->hdr.return_code)
5949 PRINT_ERR("Could not delete group MAC " \
5950 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5951 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5952 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5957 qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5959 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5960 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5961 qeth_layer2_send_delgroupmac_cb);
5965 qeth_layer2_send_setmac_cb(struct qeth_card *card,
5966 struct qeth_reply *reply,
5969 struct qeth_ipa_cmd *cmd;
5971 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5972 cmd = (struct qeth_ipa_cmd *) data;
5973 if (cmd->hdr.return_code) {
5974 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5975 PRINT_WARN("Error in registering MAC address on " \
5976 "device %s: x%x\n", CARD_BUS_ID(card),
5977 cmd->hdr.return_code);
5978 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
5979 cmd->hdr.return_code = -EIO;
5981 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
5982 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5984 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5985 "successfully registered on device %s\n",
5986 card->dev->dev_addr[0], card->dev->dev_addr[1],
5987 card->dev->dev_addr[2], card->dev->dev_addr[3],
5988 card->dev->dev_addr[4], card->dev->dev_addr[5],
5995 qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
5997 QETH_DBF_TEXT(trace, 2, "L2Setmac");
5998 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
5999 qeth_layer2_send_setmac_cb);
6003 qeth_layer2_send_delmac_cb(struct qeth_card *card,
6004 struct qeth_reply *reply,
6007 struct qeth_ipa_cmd *cmd;
6009 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
6010 cmd = (struct qeth_ipa_cmd *) data;
6011 if (cmd->hdr.return_code) {
6012 PRINT_WARN("Error in deregistering MAC address on " \
6013 "device %s: x%x\n", CARD_BUS_ID(card),
6014 cmd->hdr.return_code);
6015 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
6016 cmd->hdr.return_code = -EIO;
6019 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
6024 qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
6026 QETH_DBF_TEXT(trace, 2, "L2Delmac");
6027 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
6029 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
6030 qeth_layer2_send_delmac_cb);
6034 qeth_layer2_set_mac_address(struct net_device *dev, void *p)
6036 struct sockaddr *addr = p;
6037 struct qeth_card *card;
6040 QETH_DBF_TEXT(trace, 3, "setmac");
6042 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
6043 QETH_DBF_TEXT(trace, 3, "setmcINV");
6046 card = (struct qeth_card *) dev->priv;
6048 if (!card->options.layer2) {
6049 PRINT_WARN("Setting MAC address on %s is not supported "
6050 "in Layer 3 mode.\n", dev->name);
6051 QETH_DBF_TEXT(trace, 3, "setmcLY3");
6054 if (card->info.type == QETH_CARD_TYPE_OSN) {
6055 PRINT_WARN("Setting MAC address on %s is not supported.\n",
6057 QETH_DBF_TEXT(trace, 3, "setmcOSN");
6060 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
6061 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
6062 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
6064 rc = qeth_layer2_send_setmac(card, addr->sa_data);
6069 qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
6070 __u8 command, enum qeth_prot_versions prot)
6072 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
6073 cmd->hdr.command = command;
6074 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
6075 cmd->hdr.seqno = card->seqno.ipa;
6076 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
6077 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
6078 if (card->options.layer2)
6079 cmd->hdr.prim_version_no = 2;
6081 cmd->hdr.prim_version_no = 1;
6082 cmd->hdr.param_count = 1;
6083 cmd->hdr.prot_version = prot;
6084 cmd->hdr.ipa_supported = 0;
6085 cmd->hdr.ipa_enabled = 0;
6088 static struct qeth_cmd_buffer *
6089 qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6090 enum qeth_prot_versions prot)
6092 struct qeth_cmd_buffer *iob;
6093 struct qeth_ipa_cmd *cmd;
6095 iob = qeth_wait_for_buffer(&card->write);
6096 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6097 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6103 qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6106 struct qeth_cmd_buffer *iob;
6107 struct qeth_ipa_cmd *cmd;
6109 QETH_DBF_TEXT(trace,4,"setdelmc");
6111 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6112 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6113 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6114 if (addr->proto == QETH_PROT_IPV6)
6115 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6116 sizeof(struct in6_addr));
6118 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6120 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6125 qeth_fill_netmask(u8 *netmask, unsigned int len)
6128 for (i=0;i<16;i++) {
6133 netmask[i] = (u8)(0xFF00>>j);
6140 qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6141 int ipacmd, unsigned int flags)
6144 struct qeth_cmd_buffer *iob;
6145 struct qeth_ipa_cmd *cmd;
6148 QETH_DBF_TEXT(trace,4,"setdelip");
6149 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6151 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6152 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6153 if (addr->proto == QETH_PROT_IPV6) {
6154 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6155 sizeof(struct in6_addr));
6156 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6157 memcpy(cmd->data.setdelip6.mask, netmask,
6158 sizeof(struct in6_addr));
6159 cmd->data.setdelip6.flags = flags;
6161 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6162 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6163 cmd->data.setdelip4.flags = flags;
6166 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6172 qeth_layer2_register_addr_entry(struct qeth_card *card,
6173 struct qeth_ipaddr *addr)
6175 if (!addr->is_multicast)
6177 QETH_DBF_TEXT(trace, 2, "setgmac");
6178 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6179 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6183 qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6184 struct qeth_ipaddr *addr)
6186 if (!addr->is_multicast)
6188 QETH_DBF_TEXT(trace, 2, "delgmac");
6189 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6190 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6194 qeth_layer3_register_addr_entry(struct qeth_card *card,
6195 struct qeth_ipaddr *addr)
6201 if (addr->proto == QETH_PROT_IPV4) {
6202 QETH_DBF_TEXT(trace, 2,"setaddr4");
6203 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6204 } else if (addr->proto == QETH_PROT_IPV6) {
6205 QETH_DBF_TEXT(trace, 2, "setaddr6");
6206 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6207 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6209 QETH_DBF_TEXT(trace, 2, "setaddr?");
6210 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6213 if (addr->is_multicast)
6214 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6216 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6219 QETH_DBF_TEXT(trace, 2, "failed");
6220 } while ((--cnt > 0) && rc);
6222 QETH_DBF_TEXT(trace, 2, "FAILED");
6223 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6224 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6231 qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6232 struct qeth_ipaddr *addr)
6237 if (addr->proto == QETH_PROT_IPV4) {
6238 QETH_DBF_TEXT(trace, 2,"deladdr4");
6239 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6240 } else if (addr->proto == QETH_PROT_IPV6) {
6241 QETH_DBF_TEXT(trace, 2, "deladdr6");
6242 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6243 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6245 QETH_DBF_TEXT(trace, 2, "deladdr?");
6246 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6248 if (addr->is_multicast)
6249 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6251 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6254 QETH_DBF_TEXT(trace, 2, "failed");
6255 /* TODO: re-activate this warning as soon as we have a
6257 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6258 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6266 qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6268 if (card->options.layer2)
6269 return qeth_layer2_register_addr_entry(card, addr);
6271 return qeth_layer3_register_addr_entry(card, addr);
6275 qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6277 if (card->options.layer2)
6278 return qeth_layer2_deregister_addr_entry(card, addr);
6280 return qeth_layer3_deregister_addr_entry(card, addr);
6284 qeth_ethtool_get_tx_csum(struct net_device *dev)
6286 /* We may need to say that we support tx csum offload if
6287 * we do EDDP or TSO. There are discussions going on to
6288 * enforce rules in the stack and in ethtool that make
6289 * SG and TSO depend on HW_CSUM. At the moment there are
6291 * If we say yes here, we have to checksum outbound packets
6297 qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6303 qeth_ethtool_get_rx_csum(struct net_device *dev)
6305 struct qeth_card *card = (struct qeth_card *)dev->priv;
6307 return (card->options.checksum_type == HW_CHECKSUMMING);
6311 qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6313 struct qeth_card *card = (struct qeth_card *)dev->priv;
6315 if ((card->state != CARD_STATE_DOWN) &&
6316 (card->state != CARD_STATE_RECOVER))
6319 card->options.checksum_type = HW_CHECKSUMMING;
6321 card->options.checksum_type = SW_CHECKSUMMING;
6326 qeth_ethtool_get_sg(struct net_device *dev)
6328 struct qeth_card *card = (struct qeth_card *)dev->priv;
6330 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6331 (dev->features & NETIF_F_SG));
6335 qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6337 struct qeth_card *card = (struct qeth_card *)dev->priv;
6340 if (card->options.large_send != QETH_LARGE_SEND_NO)
6341 dev->features |= NETIF_F_SG;
6343 dev->features &= ~NETIF_F_SG;
6347 dev->features &= ~NETIF_F_SG;
6352 qeth_ethtool_get_tso(struct net_device *dev)
6354 struct qeth_card *card = (struct qeth_card *)dev->priv;
6356 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6357 (dev->features & NETIF_F_TSO));
6361 qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6363 struct qeth_card *card = (struct qeth_card *)dev->priv;
6366 if (card->options.large_send != QETH_LARGE_SEND_NO)
6367 dev->features |= NETIF_F_TSO;
6369 dev->features &= ~NETIF_F_TSO;
6373 dev->features &= ~NETIF_F_TSO;
6377 static struct ethtool_ops qeth_ethtool_ops = {
6378 .get_tx_csum = qeth_ethtool_get_tx_csum,
6379 .set_tx_csum = qeth_ethtool_set_tx_csum,
6380 .get_rx_csum = qeth_ethtool_get_rx_csum,
6381 .set_rx_csum = qeth_ethtool_set_rx_csum,
6382 .get_sg = qeth_ethtool_get_sg,
6383 .set_sg = qeth_ethtool_set_sg,
6384 .get_tso = qeth_ethtool_get_tso,
6385 .set_tso = qeth_ethtool_set_tso,
6389 qeth_netdev_init(struct net_device *dev)
6391 struct qeth_card *card;
6393 card = (struct qeth_card *) dev->priv;
6395 QETH_DBF_TEXT(trace,3,"initdev");
6397 dev->tx_timeout = &qeth_tx_timeout;
6398 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6399 dev->open = qeth_open;
6400 dev->stop = qeth_stop;
6401 dev->hard_start_xmit = qeth_hard_start_xmit;
6402 dev->do_ioctl = qeth_do_ioctl;
6403 dev->get_stats = qeth_get_stats;
6404 dev->change_mtu = qeth_change_mtu;
6405 dev->neigh_setup = qeth_neigh_setup;
6406 dev->set_multicast_list = qeth_set_multicast_list;
6407 #ifdef CONFIG_QETH_VLAN
6408 dev->vlan_rx_register = qeth_vlan_rx_register;
6409 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6410 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6412 dev->hard_header = card->orig_hard_header;
6413 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6414 dev->rebuild_header = NULL;
6415 dev->hard_header = NULL;
6416 if (card->options.fake_ll)
6417 dev->hard_header = qeth_fake_header;
6418 dev->header_cache_update = NULL;
6419 dev->hard_header_cache = NULL;
6421 #ifdef CONFIG_QETH_IPV6
6422 /*IPv6 address autoconfiguration stuff*/
6423 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6424 card->dev->dev_id = card->info.unique_id & 0xffff;
6426 dev->hard_header_parse = NULL;
6427 dev->set_mac_address = qeth_layer2_set_mac_address;
6428 dev->flags |= qeth_get_netdev_flags(card);
6429 if ((card->options.fake_broadcast) ||
6430 (card->info.broadcast_capable))
6431 dev->flags |= IFF_BROADCAST;
6432 dev->hard_header_len =
6433 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6434 dev->addr_len = OSA_ADDR_LEN;
6435 dev->mtu = card->info.initial_mtu;
6436 if (card->info.type != QETH_CARD_TYPE_OSN)
6437 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6438 SET_MODULE_OWNER(dev);
6443 qeth_init_func_level(struct qeth_card *card)
6445 if (card->ipato.enabled) {
6446 if (card->info.type == QETH_CARD_TYPE_IQD)
6447 card->info.func_level =
6448 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6450 card->info.func_level =
6451 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6453 if (card->info.type == QETH_CARD_TYPE_IQD)
6454 /*FIXME:why do we have same values for dis and ena for osae??? */
6455 card->info.func_level =
6456 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6458 card->info.func_level =
6459 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6464 * hardsetup card, initialize MPC and QDIO stuff
6467 qeth_hardsetup_card(struct qeth_card *card)
6472 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6476 PRINT_WARN("Retrying to do IDX activates.\n");
6477 ccw_device_set_offline(CARD_DDEV(card));
6478 ccw_device_set_offline(CARD_WDEV(card));
6479 ccw_device_set_offline(CARD_RDEV(card));
6480 ccw_device_set_online(CARD_RDEV(card));
6481 ccw_device_set_online(CARD_WDEV(card));
6482 ccw_device_set_online(CARD_DDEV(card));
6484 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
6485 if (rc == -ERESTARTSYS) {
6486 QETH_DBF_TEXT(setup, 2, "break1");
6489 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6495 if ((rc = qeth_get_unitaddr(card))){
6496 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6499 qeth_init_tokens(card);
6500 qeth_init_func_level(card);
6501 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6502 if (rc == -ERESTARTSYS) {
6503 QETH_DBF_TEXT(setup, 2, "break2");
6506 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6512 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6513 if (rc == -ERESTARTSYS) {
6514 QETH_DBF_TEXT(setup, 2, "break3");
6517 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6523 if ((rc = qeth_mpc_initialize(card))){
6524 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6527 /*network device will be recovered*/
6529 card->dev->hard_header = card->orig_hard_header;
6532 /* at first set_online allocate netdev */
6533 card->dev = qeth_get_netdevice(card->info.type,
6534 card->info.link_type);
6536 qeth_qdio_clear_card(card, card->info.type !=
6537 QETH_CARD_TYPE_IQD);
6539 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6542 card->dev->priv = card;
6543 card->orig_hard_header = card->dev->hard_header;
6544 card->dev->type = qeth_get_arphdr_type(card->info.type,
6545 card->info.link_type);
6546 card->dev->init = qeth_netdev_init;
6549 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6554 qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6557 struct qeth_ipa_cmd *cmd;
6559 QETH_DBF_TEXT(trace,4,"defadpcb");
6561 cmd = (struct qeth_ipa_cmd *) data;
6562 if (cmd->hdr.return_code == 0){
6563 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6564 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6565 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6566 #ifdef CONFIG_QETH_IPV6
6567 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6568 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6571 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6572 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6573 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6574 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6580 qeth_default_setadapterparms_cb(struct qeth_card *card,
6581 struct qeth_reply *reply,
6584 struct qeth_ipa_cmd *cmd;
6586 QETH_DBF_TEXT(trace,4,"defadpcb");
6588 cmd = (struct qeth_ipa_cmd *) data;
6589 if (cmd->hdr.return_code == 0)
6590 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6597 qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6600 struct qeth_ipa_cmd *cmd;
6602 QETH_DBF_TEXT(trace,3,"quyadpcb");
6604 cmd = (struct qeth_ipa_cmd *) data;
6605 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6606 card->info.link_type =
6607 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6608 card->options.adp.supported_funcs =
6609 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6610 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6614 qeth_query_setadapterparms(struct qeth_card *card)
6617 struct qeth_cmd_buffer *iob;
6619 QETH_DBF_TEXT(trace,3,"queryadp");
6620 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6621 sizeof(struct qeth_ipacmd_setadpparms));
6622 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6627 qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6628 struct qeth_reply *reply,
6631 struct qeth_ipa_cmd *cmd;
6633 QETH_DBF_TEXT(trace,4,"chgmaccb");
6635 cmd = (struct qeth_ipa_cmd *) data;
6636 if (!card->options.layer2 || card->info.guestlan ||
6637 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
6638 memcpy(card->dev->dev_addr,
6639 &cmd->data.setadapterparms.data.change_addr.addr,
6641 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6643 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6648 qeth_setadpparms_change_macaddr(struct qeth_card *card)
6651 struct qeth_cmd_buffer *iob;
6652 struct qeth_ipa_cmd *cmd;
6654 QETH_DBF_TEXT(trace,4,"chgmac");
6656 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6657 sizeof(struct qeth_ipacmd_setadpparms));
6658 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6659 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6660 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6661 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6662 card->dev->dev_addr, OSA_ADDR_LEN);
6663 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6669 qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6672 struct qeth_cmd_buffer *iob;
6673 struct qeth_ipa_cmd *cmd;
6675 QETH_DBF_TEXT(trace,4,"adpmode");
6677 iob = qeth_get_adapter_cmd(card, command,
6678 sizeof(struct qeth_ipacmd_setadpparms));
6679 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6680 cmd->data.setadapterparms.data.mode = mode;
6681 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6687 qeth_setadapter_hstr(struct qeth_card *card)
6691 QETH_DBF_TEXT(trace,4,"adphstr");
6693 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6694 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6695 card->options.broadcast_mode);
6697 PRINT_WARN("couldn't set broadcast mode on "
6699 CARD_BUS_ID(card), rc);
6700 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6701 card->options.macaddr_mode);
6703 PRINT_WARN("couldn't set macaddr mode on "
6704 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6707 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6708 PRINT_WARN("set adapter parameters not available "
6709 "to set broadcast mode, using ALLRINGS "
6710 "on device %s:\n", CARD_BUS_ID(card));
6711 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6712 PRINT_WARN("set adapter parameters not available "
6713 "to set macaddr mode, using NONCANONICAL "
6714 "on device %s:\n", CARD_BUS_ID(card));
6719 qeth_setadapter_parms(struct qeth_card *card)
6723 QETH_DBF_TEXT(setup, 2, "setadprm");
6725 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6726 PRINT_WARN("set adapter parameters not supported "
6729 QETH_DBF_TEXT(setup, 2, " notsupp");
6732 rc = qeth_query_setadapterparms(card);
6734 PRINT_WARN("couldn't set adapter parameters on device %s: "
6735 "x%x\n", CARD_BUS_ID(card), rc);
6738 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6739 rc = qeth_setadpparms_change_macaddr(card);
6741 PRINT_WARN("couldn't get MAC address on "
6743 CARD_BUS_ID(card), rc);
6746 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6747 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6748 rc = qeth_setadapter_hstr(card);
6754 qeth_layer2_initialize(struct qeth_card *card)
6759 QETH_DBF_TEXT(setup, 2, "doL2init");
6760 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6762 rc = qeth_query_setadapterparms(card);
6764 PRINT_WARN("could not query adapter parameters on device %s: "
6765 "x%x\n", CARD_BUS_ID(card), rc);
6768 rc = qeth_setadpparms_change_macaddr(card);
6770 PRINT_WARN("couldn't get MAC address on "
6772 CARD_BUS_ID(card), rc);
6773 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6776 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6778 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6780 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6786 qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6787 enum qeth_prot_versions prot)
6790 struct qeth_cmd_buffer *iob;
6792 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6793 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6799 qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6803 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6805 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6810 qeth_send_stoplan(struct qeth_card *card)
6815 * TODO: according to the IPA format document page 14,
6816 * TCP/IP (we!) never issue a STOPLAN
6819 QETH_DBF_TEXT(trace, 2, "stoplan");
6821 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6826 qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6829 struct qeth_ipa_cmd *cmd;
6831 QETH_DBF_TEXT(setup, 2, "qipasscb");
6833 cmd = (struct qeth_ipa_cmd *) data;
6834 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6835 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6836 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6837 /* Disable IPV6 support hard coded for Hipersockets */
6838 if(card->info.type == QETH_CARD_TYPE_IQD)
6839 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
6841 #ifdef CONFIG_QETH_IPV6
6842 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6843 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6846 QETH_DBF_TEXT(setup, 2, "suppenbl");
6847 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6848 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6853 qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6856 struct qeth_cmd_buffer *iob;
6858 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6859 if (card->options.layer2) {
6860 QETH_DBF_TEXT(setup, 2, "noprmly2");
6864 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6865 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6869 static struct qeth_cmd_buffer *
6870 qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6871 __u16 cmd_code, __u16 len,
6872 enum qeth_prot_versions prot)
6874 struct qeth_cmd_buffer *iob;
6875 struct qeth_ipa_cmd *cmd;
6877 QETH_DBF_TEXT(trace,4,"getasscm");
6878 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6880 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6881 cmd->data.setassparms.hdr.assist_no = ipa_func;
6882 cmd->data.setassparms.hdr.length = 8 + len;
6883 cmd->data.setassparms.hdr.command_code = cmd_code;
6884 cmd->data.setassparms.hdr.return_code = 0;
6885 cmd->data.setassparms.hdr.seq_no = 0;
6891 qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6892 __u16 len, long data,
6894 (struct qeth_card *,struct qeth_reply *,unsigned long),
6898 struct qeth_ipa_cmd *cmd;
6900 QETH_DBF_TEXT(trace,4,"sendassp");
6902 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6903 if (len <= sizeof(__u32))
6904 cmd->data.setassparms.data.flags_32bit = (__u32) data;
6905 else if (len > sizeof(__u32))
6906 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6908 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6912 #ifdef CONFIG_QETH_IPV6
6914 qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6915 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6919 struct qeth_cmd_buffer *iob;
6921 QETH_DBF_TEXT(trace,4,"simassp6");
6922 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6924 rc = qeth_send_setassparms(card, iob, 0, 0,
6925 qeth_default_setassparms_cb, NULL);
6931 qeth_send_simple_setassparms(struct qeth_card *card,
6932 enum qeth_ipa_funcs ipa_func,
6933 __u16 cmd_code, long data)
6937 struct qeth_cmd_buffer *iob;
6939 QETH_DBF_TEXT(trace,4,"simassp4");
6941 length = sizeof(__u32);
6942 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6943 length, QETH_PROT_IPV4);
6944 rc = qeth_send_setassparms(card, iob, length, data,
6945 qeth_default_setassparms_cb, NULL);
6950 qeth_start_ipa_arp_processing(struct qeth_card *card)
6954 QETH_DBF_TEXT(trace,3,"ipaarp");
6956 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6957 PRINT_WARN("ARP processing not supported "
6958 "on %s!\n", QETH_CARD_IFNAME(card));
6961 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6962 IPA_CMD_ASS_START, 0);
6964 PRINT_WARN("Could not start ARP processing "
6965 "assist on %s: 0x%x\n",
6966 QETH_CARD_IFNAME(card), rc);
6972 qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6976 QETH_DBF_TEXT(trace,3,"ipaipfrg");
6978 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
6979 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
6980 QETH_CARD_IFNAME(card));
6984 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
6985 IPA_CMD_ASS_START, 0);
6987 PRINT_WARN("Could not start Hardware IP fragmentation "
6988 "assist on %s: 0x%x\n",
6989 QETH_CARD_IFNAME(card), rc);
6991 PRINT_INFO("Hardware IP fragmentation enabled \n");
6996 qeth_start_ipa_source_mac(struct qeth_card *card)
7000 QETH_DBF_TEXT(trace,3,"stsrcmac");
7002 if (!card->options.fake_ll)
7005 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
7006 PRINT_INFO("Inbound source address not "
7007 "supported on %s\n", QETH_CARD_IFNAME(card));
7011 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
7012 IPA_CMD_ASS_START, 0);
7014 PRINT_WARN("Could not start inbound source "
7015 "assist on %s: 0x%x\n",
7016 QETH_CARD_IFNAME(card), rc);
7021 qeth_start_ipa_vlan(struct qeth_card *card)
7025 QETH_DBF_TEXT(trace,3,"strtvlan");
7027 #ifdef CONFIG_QETH_VLAN
7028 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
7029 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
7033 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
7034 IPA_CMD_ASS_START,0);
7036 PRINT_WARN("Could not start vlan "
7037 "assist on %s: 0x%x\n",
7038 QETH_CARD_IFNAME(card), rc);
7040 PRINT_INFO("VLAN enabled \n");
7041 card->dev->features |=
7042 NETIF_F_HW_VLAN_FILTER |
7043 NETIF_F_HW_VLAN_TX |
7046 #endif /* QETH_VLAN */
7051 qeth_start_ipa_multicast(struct qeth_card *card)
7055 QETH_DBF_TEXT(trace,3,"stmcast");
7057 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7058 PRINT_WARN("Multicast not supported on %s\n",
7059 QETH_CARD_IFNAME(card));
7063 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7064 IPA_CMD_ASS_START,0);
7066 PRINT_WARN("Could not start multicast "
7067 "assist on %s: rc=%i\n",
7068 QETH_CARD_IFNAME(card), rc);
7070 PRINT_INFO("Multicast enabled\n");
7071 card->dev->flags |= IFF_MULTICAST;
7076 #ifdef CONFIG_QETH_IPV6
7078 qeth_softsetup_ipv6(struct qeth_card *card)
7082 QETH_DBF_TEXT(trace,3,"softipv6");
7084 netif_stop_queue(card->dev);
7085 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7087 PRINT_ERR("IPv6 startlan failed on %s\n",
7088 QETH_CARD_IFNAME(card));
7091 netif_wake_queue(card->dev);
7092 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7094 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7095 QETH_CARD_IFNAME(card));
7098 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7099 IPA_CMD_ASS_START, 3);
7101 PRINT_WARN("IPv6 start assist (version 4) failed "
7103 QETH_CARD_IFNAME(card), rc);
7106 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7109 PRINT_WARN("IPV6 start assist (version 6) failed "
7111 QETH_CARD_IFNAME(card), rc);
7114 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7117 PRINT_WARN("Could not enable passthrough "
7119 QETH_CARD_IFNAME(card), rc);
7122 PRINT_INFO("IPV6 enabled \n");
7129 qeth_start_ipa_ipv6(struct qeth_card *card)
7132 #ifdef CONFIG_QETH_IPV6
7133 QETH_DBF_TEXT(trace,3,"strtipv6");
7135 if (!qeth_is_supported(card, IPA_IPV6)) {
7136 PRINT_WARN("IPv6 not supported on %s\n",
7137 QETH_CARD_IFNAME(card));
7140 rc = qeth_softsetup_ipv6(card);
7146 qeth_start_ipa_broadcast(struct qeth_card *card)
7150 QETH_DBF_TEXT(trace,3,"stbrdcst");
7151 card->info.broadcast_capable = 0;
7152 if (!qeth_is_supported(card, IPA_FILTERING)) {
7153 PRINT_WARN("Broadcast not supported on %s\n",
7154 QETH_CARD_IFNAME(card));
7158 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7159 IPA_CMD_ASS_START, 0);
7161 PRINT_WARN("Could not enable broadcasting filtering "
7163 QETH_CARD_IFNAME(card), rc);
7167 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7168 IPA_CMD_ASS_CONFIGURE, 1);
7170 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7171 QETH_CARD_IFNAME(card), rc);
7174 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7175 PRINT_INFO("Broadcast enabled \n");
7176 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7177 IPA_CMD_ASS_ENABLE, 1);
7179 PRINT_WARN("Could not set up broadcast echo filtering on "
7180 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7183 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7185 if (card->info.broadcast_capable)
7186 card->dev->flags |= IFF_BROADCAST;
7188 card->dev->flags &= ~IFF_BROADCAST;
7193 qeth_send_checksum_command(struct qeth_card *card)
7197 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7198 IPA_CMD_ASS_START, 0);
7200 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7201 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7202 QETH_CARD_IFNAME(card), rc);
7205 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7207 card->info.csum_mask);
7209 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7210 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7211 QETH_CARD_IFNAME(card), rc);
7218 qeth_start_ipa_checksum(struct qeth_card *card)
7222 QETH_DBF_TEXT(trace,3,"strtcsum");
7224 if (card->options.checksum_type == NO_CHECKSUMMING) {
7225 PRINT_WARN("Using no checksumming on %s.\n",
7226 QETH_CARD_IFNAME(card));
7229 if (card->options.checksum_type == SW_CHECKSUMMING) {
7230 PRINT_WARN("Using SW checksumming on %s.\n",
7231 QETH_CARD_IFNAME(card));
7234 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7235 PRINT_WARN("Inbound HW Checksumming not "
7236 "supported on %s,\ncontinuing "
7237 "using Inbound SW Checksumming\n",
7238 QETH_CARD_IFNAME(card));
7239 card->options.checksum_type = SW_CHECKSUMMING;
7242 rc = qeth_send_checksum_command(card);
7244 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7250 qeth_start_ipa_tso(struct qeth_card *card)
7254 QETH_DBF_TEXT(trace,3,"sttso");
7256 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7257 PRINT_WARN("Outbound TSO not supported on %s\n",
7258 QETH_CARD_IFNAME(card));
7261 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7262 IPA_CMD_ASS_START,0);
7264 PRINT_WARN("Could not start outbound TSO "
7265 "assist on %s: rc=%i\n",
7266 QETH_CARD_IFNAME(card), rc);
7268 PRINT_INFO("Outbound TSO enabled\n");
7270 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7271 card->options.large_send = QETH_LARGE_SEND_NO;
7272 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
7278 qeth_start_ipassists(struct qeth_card *card)
7280 QETH_DBF_TEXT(trace,3,"strtipas");
7281 qeth_start_ipa_arp_processing(card); /* go on*/
7282 qeth_start_ipa_ip_fragmentation(card); /* go on*/
7283 qeth_start_ipa_source_mac(card); /* go on*/
7284 qeth_start_ipa_vlan(card); /* go on*/
7285 qeth_start_ipa_multicast(card); /* go on*/
7286 qeth_start_ipa_ipv6(card); /* go on*/
7287 qeth_start_ipa_broadcast(card); /* go on*/
7288 qeth_start_ipa_checksum(card); /* go on*/
7289 qeth_start_ipa_tso(card); /* go on*/
7294 qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7295 enum qeth_prot_versions prot)
7298 struct qeth_ipa_cmd *cmd;
7299 struct qeth_cmd_buffer *iob;
7301 QETH_DBF_TEXT(trace,4,"setroutg");
7302 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7303 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7304 cmd->data.setrtg.type = (type);
7305 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7312 qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7313 enum qeth_prot_versions prot)
7315 if (card->info.type == QETH_CARD_TYPE_IQD) {
7318 case PRIMARY_CONNECTOR:
7319 case SECONDARY_CONNECTOR:
7320 case MULTICAST_ROUTER:
7328 case PRIMARY_ROUTER:
7329 case SECONDARY_ROUTER:
7331 case MULTICAST_ROUTER:
7332 if (qeth_is_ipafunc_supported(card, prot,
7340 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7341 "Router status set to 'no router'.\n",
7342 ((*type == PRIMARY_ROUTER)? "primary router" :
7343 (*type == SECONDARY_ROUTER)? "secondary router" :
7344 (*type == PRIMARY_CONNECTOR)? "primary connector" :
7345 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7346 (*type == MULTICAST_ROUTER)? "multicast router" :
7353 qeth_setrouting_v4(struct qeth_card *card)
7357 QETH_DBF_TEXT(trace,3,"setrtg4");
7359 qeth_correct_routing_type(card, &card->options.route4.type,
7362 rc = qeth_send_setrouting(card, card->options.route4.type,
7365 card->options.route4.type = NO_ROUTER;
7366 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7367 "Type set to 'no router'.\n",
7368 rc, QETH_CARD_IFNAME(card));
7374 qeth_setrouting_v6(struct qeth_card *card)
7378 QETH_DBF_TEXT(trace,3,"setrtg6");
7379 #ifdef CONFIG_QETH_IPV6
7381 qeth_correct_routing_type(card, &card->options.route6.type,
7384 if ((card->options.route6.type == NO_ROUTER) ||
7385 ((card->info.type == QETH_CARD_TYPE_OSAE) &&
7386 (card->options.route6.type == MULTICAST_ROUTER) &&
7387 !qeth_is_supported6(card,IPA_OSA_MC_ROUTER)))
7389 rc = qeth_send_setrouting(card, card->options.route6.type,
7392 card->options.route6.type = NO_ROUTER;
7393 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7394 "Type set to 'no router'.\n",
7395 rc, QETH_CARD_IFNAME(card));
7402 qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
7406 if (card->dev == NULL) {
7407 card->options.large_send = type;
7410 netif_stop_queue(card->dev);
7411 card->options.large_send = type;
7412 switch (card->options.large_send) {
7413 case QETH_LARGE_SEND_EDDP:
7414 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7416 case QETH_LARGE_SEND_TSO:
7417 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7418 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7420 PRINT_WARN("TSO not supported on %s. "
7421 "large_send set to 'no'.\n",
7423 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7424 card->options.large_send = QETH_LARGE_SEND_NO;
7428 default: /* includes QETH_LARGE_SEND_NO */
7429 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7432 netif_wake_queue(card->dev);
7437 * softsetup card: init IPA stuff
7440 qeth_softsetup_card(struct qeth_card *card)
7444 QETH_DBF_TEXT(setup, 2, "softsetp");
7446 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7447 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7449 PRINT_WARN("LAN on card %s if offline! "
7450 "Continuing softsetup.\n",
7452 card->lan_online = 0;
7456 card->lan_online = 1;
7457 if (card->info.type==QETH_CARD_TYPE_OSN)
7459 if (card->options.layer2) {
7460 card->dev->features |=
7461 NETIF_F_HW_VLAN_FILTER |
7462 NETIF_F_HW_VLAN_TX |
7464 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7465 card->info.broadcast_capable=1;
7466 if ((rc = qeth_layer2_initialize(card))) {
7467 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7470 #ifdef CONFIG_QETH_VLAN
7471 qeth_layer2_process_vlans(card, 0);
7475 if ((card->options.large_send == QETH_LARGE_SEND_EDDP) ||
7476 (card->options.large_send == QETH_LARGE_SEND_TSO))
7477 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7479 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7481 if ((rc = qeth_setadapter_parms(card)))
7482 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7483 if ((rc = qeth_start_ipassists(card)))
7484 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7485 if ((rc = qeth_setrouting_v4(card)))
7486 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7487 if ((rc = qeth_setrouting_v6(card)))
7488 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7490 netif_stop_queue(card->dev);
7494 #ifdef CONFIG_QETH_IPV6
7496 qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7499 struct qeth_ipa_cmd *cmd;
7501 cmd = (struct qeth_ipa_cmd *) data;
7502 if (cmd->hdr.return_code == 0)
7503 card->info.unique_id = *((__u16 *)
7504 &cmd->data.create_destroy_addr.unique_id[6]);
7506 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7507 UNIQUE_ID_NOT_BY_CARD;
7508 PRINT_WARN("couldn't get a unique id from the card on device "
7509 "%s (result=x%x), using default id. ipv6 "
7510 "autoconfig on other lpars may lead to duplicate "
7511 "ip addresses. please use manually "
7512 "configured ones.\n",
7513 CARD_BUS_ID(card), cmd->hdr.return_code);
7520 qeth_put_unique_id(struct qeth_card *card)
7524 #ifdef CONFIG_QETH_IPV6
7525 struct qeth_cmd_buffer *iob;
7526 struct qeth_ipa_cmd *cmd;
7528 QETH_DBF_TEXT(trace,2,"puniqeid");
7530 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7531 UNIQUE_ID_NOT_BY_CARD)
7533 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7535 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7536 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7537 card->info.unique_id;
7538 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7539 card->dev->dev_addr, OSA_ADDR_LEN);
7540 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7542 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7543 UNIQUE_ID_NOT_BY_CARD;
7552 qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7554 struct qeth_ipaddr *addr, *tmp;
7555 unsigned long flags;
7557 QETH_DBF_TEXT(trace,4,"clearip");
7558 spin_lock_irqsave(&card->ip_lock, flags);
7559 /* clear todo list */
7560 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7561 list_del(&addr->entry);
7565 while (!list_empty(&card->ip_list)) {
7566 addr = list_entry(card->ip_list.next,
7567 struct qeth_ipaddr, entry);
7568 list_del_init(&addr->entry);
7570 spin_unlock_irqrestore(&card->ip_lock, flags);
7571 qeth_deregister_addr_entry(card, addr);
7572 spin_lock_irqsave(&card->ip_lock, flags);
7574 if (!recover || addr->is_multicast) {
7578 list_add_tail(&addr->entry, card->ip_tbd_list);
7580 spin_unlock_irqrestore(&card->ip_lock, flags);
7584 qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7585 int clear_start_mask)
7587 unsigned long flags;
7589 spin_lock_irqsave(&card->thread_mask_lock, flags);
7590 card->thread_allowed_mask = threads;
7591 if (clear_start_mask)
7592 card->thread_start_mask &= threads;
7593 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7594 wake_up(&card->wait_q);
7598 qeth_threads_running(struct qeth_card *card, unsigned long threads)
7600 unsigned long flags;
7603 spin_lock_irqsave(&card->thread_mask_lock, flags);
7604 rc = (card->thread_running_mask & threads);
7605 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7610 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7612 return wait_event_interruptible(card->wait_q,
7613 qeth_threads_running(card, threads) == 0);
7617 qeth_stop_card(struct qeth_card *card, int recovery_mode)
7621 QETH_DBF_TEXT(setup ,2,"stopcard");
7622 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7624 qeth_set_allowed_threads(card, 0, 1);
7625 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7626 return -ERESTARTSYS;
7627 if (card->read.state == CH_STATE_UP &&
7628 card->write.state == CH_STATE_UP &&
7629 (card->state == CARD_STATE_UP)) {
7630 if (recovery_mode &&
7631 card->info.type != QETH_CARD_TYPE_OSN) {
7632 qeth_stop(card->dev);
7635 dev_close(card->dev);
7638 if (!card->use_hard_stop) {
7639 __u8 *mac = &card->dev->dev_addr[0];
7640 rc = qeth_layer2_send_delmac(card, mac);
7641 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7642 if ((rc = qeth_send_stoplan(card)))
7643 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7645 card->state = CARD_STATE_SOFTSETUP;
7647 if (card->state == CARD_STATE_SOFTSETUP) {
7648 #ifdef CONFIG_QETH_VLAN
7649 if (card->options.layer2)
7650 qeth_layer2_process_vlans(card, 1);
7652 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7653 qeth_clear_ipacmd_list(card);
7654 card->state = CARD_STATE_HARDSETUP;
7656 if (card->state == CARD_STATE_HARDSETUP) {
7657 if ((!card->use_hard_stop) &&
7658 (!card->options.layer2))
7659 if ((rc = qeth_put_unique_id(card)))
7660 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7661 qeth_qdio_clear_card(card, 0);
7662 qeth_clear_qdio_buffers(card);
7663 qeth_clear_working_pool_list(card);
7664 card->state = CARD_STATE_DOWN;
7666 if (card->state == CARD_STATE_DOWN) {
7667 qeth_clear_cmd_buffers(&card->read);
7668 qeth_clear_cmd_buffers(&card->write);
7670 card->use_hard_stop = 0;
7676 qeth_get_unique_id(struct qeth_card *card)
7679 #ifdef CONFIG_QETH_IPV6
7680 struct qeth_cmd_buffer *iob;
7681 struct qeth_ipa_cmd *cmd;
7683 QETH_DBF_TEXT(setup, 2, "guniqeid");
7685 if (!qeth_is_supported(card,IPA_IPV6)) {
7686 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7687 UNIQUE_ID_NOT_BY_CARD;
7691 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7693 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7694 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7695 card->info.unique_id;
7697 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7699 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7700 UNIQUE_ID_NOT_BY_CARD;
7705 qeth_print_status_with_portname(struct qeth_card *card)
7710 sprintf(dbf_text, "%s", card->info.portname + 1);
7711 for (i = 0; i < 8; i++)
7713 (char) _ebcasc[(__u8) dbf_text[i]];
7715 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7716 "with link type %s (portname: %s)\n",
7720 qeth_get_cardname(card),
7721 (card->info.mcl_level[0]) ? " (level: " : "",
7722 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7723 (card->info.mcl_level[0]) ? ")" : "",
7724 qeth_get_cardname_short(card),
7730 qeth_print_status_no_portname(struct qeth_card *card)
7732 if (card->info.portname[0])
7733 printk("qeth: Device %s/%s/%s is a%s "
7734 "card%s%s%s\nwith link type %s "
7735 "(no portname needed by interface).\n",
7739 qeth_get_cardname(card),
7740 (card->info.mcl_level[0]) ? " (level: " : "",
7741 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7742 (card->info.mcl_level[0]) ? ")" : "",
7743 qeth_get_cardname_short(card));
7745 printk("qeth: Device %s/%s/%s is a%s "
7746 "card%s%s%s\nwith link type %s.\n",
7750 qeth_get_cardname(card),
7751 (card->info.mcl_level[0]) ? " (level: " : "",
7752 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7753 (card->info.mcl_level[0]) ? ")" : "",
7754 qeth_get_cardname_short(card));
7758 qeth_print_status_message(struct qeth_card *card)
7760 switch (card->info.type) {
7761 case QETH_CARD_TYPE_OSAE:
7762 /* VM will use a non-zero first character
7763 * to indicate a HiperSockets like reporting
7764 * of the level OSA sets the first character to zero
7766 if (!card->info.mcl_level[0]) {
7767 sprintf(card->info.mcl_level,"%02x%02x",
7768 card->info.mcl_level[2],
7769 card->info.mcl_level[3]);
7771 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7775 case QETH_CARD_TYPE_IQD:
7776 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7777 card->info.mcl_level[0]];
7778 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7779 card->info.mcl_level[1]];
7780 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7781 card->info.mcl_level[2]];
7782 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7783 card->info.mcl_level[3]];
7784 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7787 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7789 if (card->info.portname_required)
7790 qeth_print_status_with_portname(card);
7792 qeth_print_status_no_portname(card);
7796 qeth_register_netdev(struct qeth_card *card)
7798 QETH_DBF_TEXT(setup, 3, "regnetd");
7799 if (card->dev->reg_state != NETREG_UNINITIALIZED) {
7800 qeth_netdev_init(card->dev);
7804 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7805 return register_netdev(card->dev);
7809 qeth_start_again(struct qeth_card *card, int recovery_mode)
7811 QETH_DBF_TEXT(setup ,2, "startag");
7813 if (recovery_mode &&
7814 card->info.type != QETH_CARD_TYPE_OSN) {
7815 qeth_open(card->dev);
7818 dev_open(card->dev);
7821 /* this also sets saved unicast addresses */
7822 qeth_set_multicast_list(card->dev);
7826 /* Layer 2 specific stuff */
7827 #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7828 if (card->options.option == value) { \
7829 PRINT_ERR("%s not supported with layer 2 " \
7830 "functionality, ignoring option on read" \
7831 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7832 card->options.option = reset_value; \
7834 #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7835 if (card->options.option != value) { \
7836 PRINT_ERR("%s not supported with layer 2 " \
7837 "functionality, ignoring option on read" \
7838 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7839 card->options.option = reset_value; \
7843 static void qeth_make_parameters_consistent(struct qeth_card *card)
7846 if (card->options.layer2 == 0)
7848 if (card->info.type == QETH_CARD_TYPE_OSN)
7850 if (card->info.type == QETH_CARD_TYPE_IQD) {
7851 PRINT_ERR("Device %s does not support layer 2 functionality." \
7852 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7853 card->options.layer2 = 0;
7856 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7857 "Routing options are");
7858 #ifdef CONFIG_QETH_IPV6
7859 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7860 "Routing options are");
7862 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7863 QETH_CHECKSUM_DEFAULT,
7864 "Checksumming options are");
7865 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7866 QETH_TR_BROADCAST_ALLRINGS,
7867 "Broadcast mode options are");
7868 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7869 QETH_TR_MACADDR_NONCANONICAL,
7870 "Canonical MAC addr options are");
7871 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7872 "Broadcast faking options are");
7873 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7874 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7875 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
7880 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
7882 struct qeth_card *card = gdev->dev.driver_data;
7884 enum qeth_card_states recover_flag;
7887 QETH_DBF_TEXT(setup ,2, "setonlin");
7888 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7890 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7891 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7892 PRINT_WARN("set_online of card %s interrupted by user!\n",
7894 return -ERESTARTSYS;
7897 recover_flag = card->state;
7898 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7899 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7900 (rc = ccw_device_set_online(CARD_DDEV(card)))){
7901 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7905 qeth_make_parameters_consistent(card);
7907 if ((rc = qeth_hardsetup_card(card))){
7908 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7911 card->state = CARD_STATE_HARDSETUP;
7913 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7914 rc = qeth_get_unique_id(card);
7916 if (rc && card->options.layer2 == 0) {
7917 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7920 qeth_print_status_message(card);
7921 if ((rc = qeth_register_netdev(card))){
7922 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7925 if ((rc = qeth_softsetup_card(card))){
7926 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7929 card->state = CARD_STATE_SOFTSETUP;
7931 if ((rc = qeth_init_qdio_queues(card))){
7932 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7935 netif_carrier_on(card->dev);
7937 qeth_set_allowed_threads(card, 0xffffffff, 0);
7938 if (recover_flag == CARD_STATE_RECOVER)
7939 qeth_start_again(card, recovery_mode);
7940 qeth_notify_processes();
7943 card->use_hard_stop = 1;
7944 qeth_stop_card(card, 0);
7945 ccw_device_set_offline(CARD_DDEV(card));
7946 ccw_device_set_offline(CARD_WDEV(card));
7947 ccw_device_set_offline(CARD_RDEV(card));
7948 if (recover_flag == CARD_STATE_RECOVER)
7949 card->state = CARD_STATE_RECOVER;
7951 card->state = CARD_STATE_DOWN;
7956 qeth_set_online(struct ccwgroup_device *gdev)
7958 return __qeth_set_online(gdev, 0);
7961 static struct ccw_device_id qeth_ids[] = {
7962 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE},
7963 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD},
7964 {CCW_DEVICE(0x1731, 0x06), driver_info:QETH_CARD_TYPE_OSN},
7967 MODULE_DEVICE_TABLE(ccw, qeth_ids);
7969 struct device *qeth_root_dev = NULL;
7971 struct ccwgroup_driver qeth_ccwgroup_driver = {
7972 .owner = THIS_MODULE,
7974 .driver_id = 0xD8C5E3C8,
7975 .probe = qeth_probe_device,
7976 .remove = qeth_remove_device,
7977 .set_online = qeth_set_online,
7978 .set_offline = qeth_set_offline,
7981 struct ccw_driver qeth_ccw_driver = {
7984 .probe = ccwgroup_probe_ccwdev,
7985 .remove = ccwgroup_remove_ccwdev,
7990 qeth_unregister_dbf_views(void)
7993 debug_unregister(qeth_dbf_setup);
7995 debug_unregister(qeth_dbf_qerr);
7997 debug_unregister(qeth_dbf_sense);
7999 debug_unregister(qeth_dbf_misc);
8001 debug_unregister(qeth_dbf_data);
8002 if (qeth_dbf_control)
8003 debug_unregister(qeth_dbf_control);
8005 debug_unregister(qeth_dbf_trace);
8008 qeth_register_dbf_views(void)
8010 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
8011 QETH_DBF_SETUP_PAGES,
8012 QETH_DBF_SETUP_NR_AREAS,
8013 QETH_DBF_SETUP_LEN);
8014 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
8015 QETH_DBF_MISC_PAGES,
8016 QETH_DBF_MISC_NR_AREAS,
8018 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
8019 QETH_DBF_DATA_PAGES,
8020 QETH_DBF_DATA_NR_AREAS,
8022 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
8023 QETH_DBF_CONTROL_PAGES,
8024 QETH_DBF_CONTROL_NR_AREAS,
8025 QETH_DBF_CONTROL_LEN);
8026 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
8027 QETH_DBF_SENSE_PAGES,
8028 QETH_DBF_SENSE_NR_AREAS,
8029 QETH_DBF_SENSE_LEN);
8030 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
8031 QETH_DBF_QERR_PAGES,
8032 QETH_DBF_QERR_NR_AREAS,
8034 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
8035 QETH_DBF_TRACE_PAGES,
8036 QETH_DBF_TRACE_NR_AREAS,
8037 QETH_DBF_TRACE_LEN);
8039 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
8040 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
8041 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
8042 (qeth_dbf_trace == NULL)) {
8043 qeth_unregister_dbf_views();
8046 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
8047 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
8049 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
8050 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
8052 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
8053 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
8055 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
8056 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
8058 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
8059 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8061 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8062 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8064 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8065 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8070 #ifdef CONFIG_QETH_IPV6
8071 extern struct neigh_table arp_tbl;
8072 static struct neigh_ops *arp_direct_ops;
8073 static int (*qeth_old_arp_constructor) (struct neighbour *);
8075 static struct neigh_ops arp_direct_ops_template = {
8079 .error_report = NULL,
8080 .output = dev_queue_xmit,
8081 .connected_output = dev_queue_xmit,
8082 .hh_output = dev_queue_xmit,
8083 .queue_xmit = dev_queue_xmit
8087 qeth_arp_constructor(struct neighbour *neigh)
8089 struct net_device *dev = neigh->dev;
8090 struct in_device *in_dev;
8091 struct neigh_parms *parms;
8092 struct qeth_card *card;
8094 card = qeth_get_card_from_dev(dev);
8097 if((card->options.layer2) ||
8098 (card->dev->hard_header == qeth_fake_header))
8102 in_dev = __in_dev_get_rcu(dev);
8103 if (in_dev == NULL) {
8108 parms = in_dev->arp_parms;
8109 __neigh_parms_put(neigh->parms);
8110 neigh->parms = neigh_parms_clone(parms);
8113 neigh->type = inet_addr_type(*(u32 *) neigh->primary_key);
8114 neigh->nud_state = NUD_NOARP;
8115 neigh->ops = arp_direct_ops;
8116 neigh->output = neigh->ops->queue_xmit;
8119 return qeth_old_arp_constructor(neigh);
8121 #endif /*CONFIG_QETH_IPV6*/
8124 * IP address takeover related functions
8127 qeth_clear_ipato_list(struct qeth_card *card)
8129 struct qeth_ipato_entry *ipatoe, *tmp;
8130 unsigned long flags;
8132 spin_lock_irqsave(&card->ip_lock, flags);
8133 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8134 list_del(&ipatoe->entry);
8137 spin_unlock_irqrestore(&card->ip_lock, flags);
8141 qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8143 struct qeth_ipato_entry *ipatoe;
8144 unsigned long flags;
8147 QETH_DBF_TEXT(trace, 2, "addipato");
8148 spin_lock_irqsave(&card->ip_lock, flags);
8149 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8150 if (ipatoe->proto != new->proto)
8152 if (!memcmp(ipatoe->addr, new->addr,
8153 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8154 (ipatoe->mask_bits == new->mask_bits)){
8155 PRINT_WARN("ipato entry already exists!\n");
8161 list_add_tail(&new->entry, &card->ipato.entries);
8163 spin_unlock_irqrestore(&card->ip_lock, flags);
8168 qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8169 u8 *addr, int mask_bits)
8171 struct qeth_ipato_entry *ipatoe, *tmp;
8172 unsigned long flags;
8174 QETH_DBF_TEXT(trace, 2, "delipato");
8175 spin_lock_irqsave(&card->ip_lock, flags);
8176 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8177 if (ipatoe->proto != proto)
8179 if (!memcmp(ipatoe->addr, addr,
8180 (proto == QETH_PROT_IPV4)? 4:16) &&
8181 (ipatoe->mask_bits == mask_bits)){
8182 list_del(&ipatoe->entry);
8186 spin_unlock_irqrestore(&card->ip_lock, flags);
8190 qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8195 for (i = 0; i < len; ++i){
8197 for (j = 7; j >= 0; --j){
8198 bits[i*8 + j] = octet & 1;
8205 qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8207 struct qeth_ipato_entry *ipatoe;
8208 u8 addr_bits[128] = {0, };
8209 u8 ipatoe_bits[128] = {0, };
8212 if (!card->ipato.enabled)
8215 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8216 (addr->proto == QETH_PROT_IPV4)? 4:16);
8217 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8218 if (addr->proto != ipatoe->proto)
8220 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8221 (ipatoe->proto==QETH_PROT_IPV4) ?
8223 if (addr->proto == QETH_PROT_IPV4)
8224 rc = !memcmp(addr_bits, ipatoe_bits,
8225 min(32, ipatoe->mask_bits));
8227 rc = !memcmp(addr_bits, ipatoe_bits,
8228 min(128, ipatoe->mask_bits));
8233 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8235 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8242 * VIPA related functions
8245 qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8248 struct qeth_ipaddr *ipaddr;
8249 unsigned long flags;
8252 ipaddr = qeth_get_addr_buffer(proto);
8254 if (proto == QETH_PROT_IPV4){
8255 QETH_DBF_TEXT(trace, 2, "addvipa4");
8256 memcpy(&ipaddr->u.a4.addr, addr, 4);
8257 ipaddr->u.a4.mask = 0;
8258 #ifdef CONFIG_QETH_IPV6
8259 } else if (proto == QETH_PROT_IPV6){
8260 QETH_DBF_TEXT(trace, 2, "addvipa6");
8261 memcpy(&ipaddr->u.a6.addr, addr, 16);
8262 ipaddr->u.a6.pfxlen = 0;
8265 ipaddr->type = QETH_IP_TYPE_VIPA;
8266 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8267 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8270 spin_lock_irqsave(&card->ip_lock, flags);
8271 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8272 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8274 spin_unlock_irqrestore(&card->ip_lock, flags);
8276 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8279 if (!qeth_add_ip(card, ipaddr))
8281 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8282 schedule_work(&card->kernel_thread_starter);
8287 qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8290 struct qeth_ipaddr *ipaddr;
8292 ipaddr = qeth_get_addr_buffer(proto);
8294 if (proto == QETH_PROT_IPV4){
8295 QETH_DBF_TEXT(trace, 2, "delvipa4");
8296 memcpy(&ipaddr->u.a4.addr, addr, 4);
8297 ipaddr->u.a4.mask = 0;
8298 #ifdef CONFIG_QETH_IPV6
8299 } else if (proto == QETH_PROT_IPV6){
8300 QETH_DBF_TEXT(trace, 2, "delvipa6");
8301 memcpy(&ipaddr->u.a6.addr, addr, 16);
8302 ipaddr->u.a6.pfxlen = 0;
8305 ipaddr->type = QETH_IP_TYPE_VIPA;
8308 if (!qeth_delete_ip(card, ipaddr))
8310 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8311 schedule_work(&card->kernel_thread_starter);
8315 * proxy ARP related functions
8318 qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8321 struct qeth_ipaddr *ipaddr;
8322 unsigned long flags;
8325 ipaddr = qeth_get_addr_buffer(proto);
8327 if (proto == QETH_PROT_IPV4){
8328 QETH_DBF_TEXT(trace, 2, "addrxip4");
8329 memcpy(&ipaddr->u.a4.addr, addr, 4);
8330 ipaddr->u.a4.mask = 0;
8331 #ifdef CONFIG_QETH_IPV6
8332 } else if (proto == QETH_PROT_IPV6){
8333 QETH_DBF_TEXT(trace, 2, "addrxip6");
8334 memcpy(&ipaddr->u.a6.addr, addr, 16);
8335 ipaddr->u.a6.pfxlen = 0;
8338 ipaddr->type = QETH_IP_TYPE_RXIP;
8339 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8340 ipaddr->del_flags = 0;
8343 spin_lock_irqsave(&card->ip_lock, flags);
8344 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8345 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8347 spin_unlock_irqrestore(&card->ip_lock, flags);
8349 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8352 if (!qeth_add_ip(card, ipaddr))
8354 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8355 schedule_work(&card->kernel_thread_starter);
8360 qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8363 struct qeth_ipaddr *ipaddr;
8365 ipaddr = qeth_get_addr_buffer(proto);
8367 if (proto == QETH_PROT_IPV4){
8368 QETH_DBF_TEXT(trace, 2, "addrxip4");
8369 memcpy(&ipaddr->u.a4.addr, addr, 4);
8370 ipaddr->u.a4.mask = 0;
8371 #ifdef CONFIG_QETH_IPV6
8372 } else if (proto == QETH_PROT_IPV6){
8373 QETH_DBF_TEXT(trace, 2, "addrxip6");
8374 memcpy(&ipaddr->u.a6.addr, addr, 16);
8375 ipaddr->u.a6.pfxlen = 0;
8378 ipaddr->type = QETH_IP_TYPE_RXIP;
8381 if (!qeth_delete_ip(card, ipaddr))
8383 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8384 schedule_work(&card->kernel_thread_starter);
8391 qeth_ip_event(struct notifier_block *this,
8392 unsigned long event,void *ptr)
8394 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8395 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8396 struct qeth_ipaddr *addr;
8397 struct qeth_card *card;
8399 QETH_DBF_TEXT(trace,3,"ipevent");
8400 card = qeth_get_card_from_dev(dev);
8403 if (card->options.layer2)
8406 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8408 addr->u.a4.addr = ifa->ifa_address;
8409 addr->u.a4.mask = ifa->ifa_mask;
8410 addr->type = QETH_IP_TYPE_NORMAL;
8416 if (!qeth_add_ip(card, addr))
8420 if (!qeth_delete_ip(card, addr))
8426 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8427 schedule_work(&card->kernel_thread_starter);
8432 static struct notifier_block qeth_ip_notifier = {
8437 #ifdef CONFIG_QETH_IPV6
8439 * IPv6 event handler
8442 qeth_ip6_event(struct notifier_block *this,
8443 unsigned long event,void *ptr)
8446 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8447 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8448 struct qeth_ipaddr *addr;
8449 struct qeth_card *card;
8451 QETH_DBF_TEXT(trace,3,"ip6event");
8453 card = qeth_get_card_from_dev(dev);
8456 if (!qeth_is_supported(card, IPA_IPV6))
8459 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8461 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8462 addr->u.a6.pfxlen = ifa->prefix_len;
8463 addr->type = QETH_IP_TYPE_NORMAL;
8469 if (!qeth_add_ip(card, addr))
8473 if (!qeth_delete_ip(card, addr))
8479 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8480 schedule_work(&card->kernel_thread_starter);
8485 static struct notifier_block qeth_ip6_notifier = {
8492 __qeth_reboot_event_card(struct device *dev, void *data)
8494 struct qeth_card *card;
8496 card = (struct qeth_card *) dev->driver_data;
8497 qeth_clear_ip_list(card, 0, 0);
8498 qeth_qdio_clear_card(card, 0);
8503 qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8506 driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8507 __qeth_reboot_event_card);
8512 static struct notifier_block qeth_reboot_notifier = {
8518 qeth_register_notifiers(void)
8522 QETH_DBF_TEXT(trace,5,"regnotif");
8523 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8525 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8527 #ifdef CONFIG_QETH_IPV6
8528 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8533 #ifdef CONFIG_QETH_IPV6
8535 unregister_inetaddr_notifier(&qeth_ip_notifier);
8538 unregister_reboot_notifier(&qeth_reboot_notifier);
8543 * unregister all event notifiers
8546 qeth_unregister_notifiers(void)
8549 QETH_DBF_TEXT(trace,5,"unregnot");
8550 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8551 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8552 #ifdef CONFIG_QETH_IPV6
8553 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8554 #endif /* QETH_IPV6 */
8558 #ifdef CONFIG_QETH_IPV6
8560 qeth_ipv6_init(void)
8562 qeth_old_arp_constructor = arp_tbl.constructor;
8563 write_lock(&arp_tbl.lock);
8564 arp_tbl.constructor = qeth_arp_constructor;
8565 write_unlock(&arp_tbl.lock);
8567 arp_direct_ops = (struct neigh_ops*)
8568 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8569 if (!arp_direct_ops)
8572 memcpy(arp_direct_ops, &arp_direct_ops_template,
8573 sizeof(struct neigh_ops));
8579 qeth_ipv6_uninit(void)
8581 write_lock(&arp_tbl.lock);
8582 arp_tbl.constructor = qeth_old_arp_constructor;
8583 write_unlock(&arp_tbl.lock);
8584 kfree(arp_direct_ops);
8586 #endif /* CONFIG_QETH_IPV6 */
8589 qeth_sysfs_unregister(void)
8591 qeth_remove_driver_attributes();
8592 ccw_driver_unregister(&qeth_ccw_driver);
8593 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8594 s390_root_dev_unregister(qeth_root_dev);
8597 * register qeth at sysfs
8600 qeth_sysfs_register(void)
8604 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8607 rc = ccw_driver_register(&qeth_ccw_driver);
8610 rc = qeth_create_driver_attributes();
8613 qeth_root_dev = s390_root_dev_register("qeth");
8614 if (IS_ERR(qeth_root_dev)) {
8615 rc = PTR_ERR(qeth_root_dev);
8629 PRINT_INFO("loading %s (%s/%s/%s/%s/%s/%s/%s %s %s)\n",
8630 version, VERSION_QETH_C, VERSION_QETH_H,
8631 VERSION_QETH_MPC_H, VERSION_QETH_MPC_C,
8632 VERSION_QETH_FS_H, VERSION_QETH_PROC_C,
8633 VERSION_QETH_SYS_C, QETH_VERSION_IPV6,
8636 INIT_LIST_HEAD(&qeth_card_list.list);
8637 INIT_LIST_HEAD(&qeth_notify_list);
8638 spin_lock_init(&qeth_notify_lock);
8639 rwlock_init(&qeth_card_list.rwlock);
8641 if (qeth_register_dbf_views())
8643 if (qeth_sysfs_register())
8646 #ifdef CONFIG_QETH_IPV6
8647 if (qeth_ipv6_init()) {
8648 PRINT_ERR("Out of memory during ipv6 init.\n");
8651 #endif /* QETH_IPV6 */
8652 if (qeth_register_notifiers())
8654 if (qeth_create_procfs_entries())
8660 qeth_unregister_notifiers();
8662 #ifdef CONFIG_QETH_IPV6
8664 #endif /* QETH_IPV6 */
8666 qeth_sysfs_unregister();
8667 qeth_unregister_dbf_views();
8669 PRINT_ERR("Initialization failed");
8674 __exit qeth_exit(void)
8676 struct qeth_card *card, *tmp;
8677 unsigned long flags;
8679 QETH_DBF_TEXT(trace,1, "cleanup.");
8682 * Weed would not need to clean up our devices here, because the
8683 * common device layer calls qeth_remove_device for each device
8684 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8685 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8686 * qeth_remove_device called by the common device layer would otherwise
8687 * do a "hard" shutdown (card->use_hard_stop is set to one in
8688 * qeth_remove_device).
8691 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8692 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8693 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8694 qeth_set_offline(card->gdev);
8695 qeth_remove_device(card->gdev);
8698 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8699 #ifdef CONFIG_QETH_IPV6
8702 qeth_unregister_notifiers();
8703 qeth_remove_procfs_entries();
8704 qeth_sysfs_unregister();
8705 qeth_unregister_dbf_views();
8706 printk("qeth: removed\n");
8709 EXPORT_SYMBOL(qeth_osn_register);
8710 EXPORT_SYMBOL(qeth_osn_deregister);
8711 EXPORT_SYMBOL(qeth_osn_assist);
8712 module_init(qeth_init);
8713 module_exit(qeth_exit);
8714 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
8715 MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8716 "Copyright 2000,2003 IBM Corporation\n");
8718 MODULE_LICENSE("GPL");