2 * linux/drivers/s390/net/qeth_main.c
4 * Linux on zSeries OSA Express and HiperSockets support
6 * Copyright 2000,2003 IBM Corporation
8 * Author(s): Original Code written by
9 * Utz Bacher (utz.bacher@de.ibm.com)
11 * Frank Pavlic (fpavlic@de.ibm.com) and
12 * Thomas Spatzier <tspat@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <linux/module.h>
31 #include <linux/moduleparam.h>
32 #include <linux/string.h>
33 #include <linux/errno.h>
36 #include <linux/inetdevice.h>
37 #include <linux/netdevice.h>
38 #include <linux/sched.h>
39 #include <linux/workqueue.h>
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/interrupt.h>
43 #include <linux/tcp.h>
44 #include <linux/icmp.h>
45 #include <linux/skbuff.h>
47 #include <linux/igmp.h>
48 #include <linux/init.h>
49 #include <linux/reboot.h>
50 #include <linux/mii.h>
51 #include <linux/rcupdate.h>
52 #include <linux/ethtool.h>
56 #include <net/route.h>
58 #include <asm/ebcdic.h>
61 #include <asm/timex.h>
62 #include <asm/semaphore.h>
63 #include <asm/uaccess.h>
64 #include <asm/s390_rdev.h>
69 #include "qeth_eddp.h"
72 static const char *version = "qeth S/390 OSA-Express driver";
75 * Debug Facility Stuff
77 static debug_info_t *qeth_dbf_setup = NULL;
78 static debug_info_t *qeth_dbf_data = NULL;
79 static debug_info_t *qeth_dbf_misc = NULL;
80 static debug_info_t *qeth_dbf_control = NULL;
81 debug_info_t *qeth_dbf_trace = NULL;
82 static debug_info_t *qeth_dbf_sense = NULL;
83 static debug_info_t *qeth_dbf_qerr = NULL;
85 DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
87 static struct lock_class_key qdio_out_skb_queue_key;
90 * some more definitions and declarations
92 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
94 /* list of our cards */
95 struct qeth_card_list_struct qeth_card_list;
96 /*process list want to be notified*/
97 spinlock_t qeth_notify_lock;
98 struct list_head qeth_notify_list;
100 static void qeth_send_control_data_cb(struct qeth_channel *,
101 struct qeth_cmd_buffer *);
104 * here we go with function implementation
107 qeth_init_qdio_info(struct qeth_card *card);
110 qeth_init_qdio_queues(struct qeth_card *card);
113 qeth_alloc_qdio_buffers(struct qeth_card *card);
116 qeth_free_qdio_buffers(struct qeth_card *);
119 qeth_clear_qdio_buffers(struct qeth_card *);
122 qeth_clear_ip_list(struct qeth_card *, int, int);
125 qeth_clear_ipacmd_list(struct qeth_card *);
128 qeth_qdio_clear_card(struct qeth_card *, int);
131 qeth_clear_working_pool_list(struct qeth_card *);
134 qeth_clear_cmd_buffers(struct qeth_channel *);
137 qeth_stop(struct net_device *);
140 qeth_clear_ipato_list(struct qeth_card *);
143 qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
146 qeth_irq_tasklet(unsigned long);
149 qeth_set_online(struct ccwgroup_device *);
152 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
154 static struct qeth_ipaddr *
155 qeth_get_addr_buffer(enum qeth_prot_versions);
158 qeth_set_multicast_list(struct net_device *);
161 qeth_setadp_promisc_mode(struct qeth_card *);
164 qeth_hard_header_parse(const struct sk_buff *skb, unsigned char *haddr);
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 = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
307 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
308 if (qeth_setup_channel(&card->read)) {
312 if (qeth_setup_channel(&card->write)) {
313 qeth_clean_channel(&card->read);
321 __qeth_check_irb_error(struct ccw_device *cdev, unsigned long intparm,
327 switch (PTR_ERR(irb)) {
329 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
330 QETH_DBF_TEXT(trace, 2, "ckirberr");
331 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
334 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
335 QETH_DBF_TEXT(trace, 2, "ckirberr");
336 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
337 if (intparm == QETH_RCD_PARM) {
338 struct qeth_card *card = CARD_FROM_CDEV(cdev);
340 if (card && (card->data.ccwdev == cdev)) {
341 card->data.state = CH_STATE_DOWN;
342 wake_up(&card->wait_q);
347 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
349 QETH_DBF_TEXT(trace, 2, "ckirberr");
350 QETH_DBF_TEXT(trace, 2, " rc???");
356 qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
361 sense = (char *) irb->ecw;
362 cstat = irb->scsw.cstat;
363 dstat = irb->scsw.dstat;
365 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
366 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
367 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
368 QETH_DBF_TEXT(trace,2, "CGENCHK");
369 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
370 cdev->dev.bus_id, dstat, cstat);
371 HEXDUMP16(WARN, "irb: ", irb);
372 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
376 if (dstat & DEV_STAT_UNIT_CHECK) {
377 if (sense[SENSE_RESETTING_EVENT_BYTE] &
378 SENSE_RESETTING_EVENT_FLAG) {
379 QETH_DBF_TEXT(trace,2,"REVIND");
382 if (sense[SENSE_COMMAND_REJECT_BYTE] &
383 SENSE_COMMAND_REJECT_FLAG) {
384 QETH_DBF_TEXT(trace,2,"CMDREJi");
387 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
388 QETH_DBF_TEXT(trace,2,"AFFE");
391 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
392 QETH_DBF_TEXT(trace,2,"ZEROSEN");
395 QETH_DBF_TEXT(trace,2,"DGENCHK");
400 static int qeth_issue_next_read(struct qeth_card *);
406 qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
410 struct qeth_cmd_buffer *buffer;
411 struct qeth_channel *channel;
412 struct qeth_card *card;
414 QETH_DBF_TEXT(trace,5,"irq");
416 if (__qeth_check_irb_error(cdev, intparm, irb))
418 cstat = irb->scsw.cstat;
419 dstat = irb->scsw.dstat;
421 card = CARD_FROM_CDEV(cdev);
425 if (card->read.ccwdev == cdev){
426 channel = &card->read;
427 QETH_DBF_TEXT(trace,5,"read");
428 } else if (card->write.ccwdev == cdev) {
429 channel = &card->write;
430 QETH_DBF_TEXT(trace,5,"write");
432 channel = &card->data;
433 QETH_DBF_TEXT(trace,5,"data");
435 atomic_set(&channel->irq_pending, 0);
437 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
438 channel->state = CH_STATE_STOPPED;
440 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
441 channel->state = CH_STATE_HALTED;
443 /*let's wake up immediately on data channel*/
444 if ((channel == &card->data) && (intparm != 0) &&
445 (intparm != QETH_RCD_PARM))
448 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
449 QETH_DBF_TEXT(trace, 6, "clrchpar");
450 /* we don't have to handle this further */
453 if (intparm == QETH_HALT_CHANNEL_PARM) {
454 QETH_DBF_TEXT(trace, 6, "hltchpar");
455 /* we don't have to handle this further */
458 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
459 (dstat & DEV_STAT_UNIT_CHECK) ||
461 if (irb->esw.esw0.erw.cons) {
462 /* TODO: we should make this s390dbf */
463 PRINT_WARN("sense data available on channel %s.\n",
464 CHANNEL_ID(channel));
465 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
466 HEXDUMP16(WARN,"irb: ",irb);
467 HEXDUMP16(WARN,"sense data: ",irb->ecw);
469 if (intparm == QETH_RCD_PARM) {
470 channel->state = CH_STATE_DOWN;
473 rc = qeth_get_problem(cdev,irb);
475 qeth_schedule_recovery(card);
480 if (intparm == QETH_RCD_PARM) {
481 channel->state = CH_STATE_RCD_DONE;
485 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
486 buffer->state = BUF_STATE_PROCESSED;
488 if (channel == &card->data)
491 if (channel == &card->read &&
492 channel->state == CH_STATE_UP)
493 qeth_issue_next_read(card);
495 qeth_irq_tasklet((unsigned long)channel);
498 wake_up(&card->wait_q);
502 * tasklet function scheduled from irq handler
505 qeth_irq_tasklet(unsigned long data)
507 struct qeth_card *card;
508 struct qeth_channel *channel;
509 struct qeth_cmd_buffer *iob;
512 QETH_DBF_TEXT(trace,5,"irqtlet");
513 channel = (struct qeth_channel *) data;
515 index = channel->buf_no;
516 card = CARD_FROM_CDEV(channel->ccwdev);
517 while (iob[index].state == BUF_STATE_PROCESSED) {
518 if (iob[index].callback !=NULL) {
519 iob[index].callback(channel,iob + index);
521 index = (index + 1) % QETH_CMD_BUFFER_NO;
523 channel->buf_no = index;
524 wake_up(&card->wait_q);
527 static int qeth_stop_card(struct qeth_card *, int);
530 __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
532 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
533 int rc = 0, rc2 = 0, rc3 = 0;
534 enum qeth_card_states recover_flag;
536 QETH_DBF_TEXT(setup, 3, "setoffl");
537 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
539 if (card->dev && netif_carrier_ok(card->dev))
540 netif_carrier_off(card->dev);
541 recover_flag = card->state;
542 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
543 PRINT_WARN("Stopping card %s interrupted by user!\n",
547 rc = ccw_device_set_offline(CARD_DDEV(card));
548 rc2 = ccw_device_set_offline(CARD_WDEV(card));
549 rc3 = ccw_device_set_offline(CARD_RDEV(card));
551 rc = (rc2) ? rc2 : rc3;
553 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
554 if (recover_flag == CARD_STATE_UP)
555 card->state = CARD_STATE_RECOVER;
556 qeth_notify_processes();
561 qeth_set_offline(struct ccwgroup_device *cgdev)
563 return __qeth_set_offline(cgdev, 0);
567 qeth_threads_running(struct qeth_card *card, unsigned long threads);
571 qeth_remove_device(struct ccwgroup_device *cgdev)
573 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
576 QETH_DBF_TEXT(setup, 3, "rmdev");
577 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
582 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
584 if (cgdev->state == CCWGROUP_ONLINE){
585 card->use_hard_stop = 1;
586 qeth_set_offline(cgdev);
588 /* remove form our internal list */
589 write_lock_irqsave(&qeth_card_list.rwlock, flags);
590 list_del(&card->list);
591 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
593 unregister_netdev(card->dev);
594 qeth_remove_device_attributes(&cgdev->dev);
595 qeth_free_card(card);
596 cgdev->dev.driver_data = NULL;
597 put_device(&cgdev->dev);
601 qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
603 qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
606 * Add/remove address to/from card's ip list, i.e. try to add or remove
607 * reference to/from an IP address that is already registered on the card.
609 * 0 address was on card and its reference count has been adjusted,
610 * but is still > 0, so nothing has to be done
611 * also returns 0 if card was not on card and the todo was to delete
612 * the address -> there is also nothing to be done
613 * 1 address was not on card and the todo is to add it to the card's ip
615 * -1 address was on card and its reference count has been decremented
616 * to <= 0 by the todo -> address must be removed from card
619 __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
620 struct qeth_ipaddr **__addr)
622 struct qeth_ipaddr *addr;
625 list_for_each_entry(addr, &card->ip_list, entry) {
626 if (card->options.layer2) {
627 if ((addr->type == todo->type) &&
628 (memcmp(&addr->mac, &todo->mac,
629 OSA_ADDR_LEN) == 0)) {
635 if ((addr->proto == QETH_PROT_IPV4) &&
636 (todo->proto == QETH_PROT_IPV4) &&
637 (addr->type == todo->type) &&
638 (addr->u.a4.addr == todo->u.a4.addr) &&
639 (addr->u.a4.mask == todo->u.a4.mask)) {
643 if ((addr->proto == QETH_PROT_IPV6) &&
644 (todo->proto == QETH_PROT_IPV6) &&
645 (addr->type == todo->type) &&
646 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
647 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
648 sizeof(struct in6_addr)) == 0)) {
654 addr->users += todo->users;
655 if (addr->users <= 0){
659 /* for VIPA and RXIP limit refcount to 1 */
660 if (addr->type != QETH_IP_TYPE_NORMAL)
665 if (todo->users > 0) {
666 /* for VIPA and RXIP limit refcount to 1 */
667 if (todo->type != QETH_IP_TYPE_NORMAL)
675 __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
678 struct qeth_ipaddr *tmp;
680 list_for_each_entry(tmp, list, entry) {
681 if ((tmp->proto == QETH_PROT_IPV4) &&
682 (addr->proto == QETH_PROT_IPV4) &&
683 ((same_type && (tmp->type == addr->type)) ||
684 (!same_type && (tmp->type != addr->type)) ) &&
685 (tmp->u.a4.addr == addr->u.a4.addr) ){
688 if ((tmp->proto == QETH_PROT_IPV6) &&
689 (addr->proto == QETH_PROT_IPV6) &&
690 ((same_type && (tmp->type == addr->type)) ||
691 (!same_type && (tmp->type != addr->type)) ) &&
692 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
693 sizeof(struct in6_addr)) == 0) ) {
701 * Add IP to be added to todo list. If there is already an "add todo"
702 * in this list we just incremenent the reference count.
703 * Returns 0 if we just incremented reference count.
706 __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
708 struct qeth_ipaddr *tmp, *t;
711 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
712 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
713 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
715 if (card->options.layer2) {
716 if ((tmp->type == addr->type) &&
717 (tmp->is_multicast == addr->is_multicast) &&
718 (memcmp(&tmp->mac, &addr->mac,
719 OSA_ADDR_LEN) == 0)) {
725 if ((tmp->proto == QETH_PROT_IPV4) &&
726 (addr->proto == QETH_PROT_IPV4) &&
727 (tmp->type == addr->type) &&
728 (tmp->is_multicast == addr->is_multicast) &&
729 (tmp->u.a4.addr == addr->u.a4.addr) &&
730 (tmp->u.a4.mask == addr->u.a4.mask)) {
734 if ((tmp->proto == QETH_PROT_IPV6) &&
735 (addr->proto == QETH_PROT_IPV6) &&
736 (tmp->type == addr->type) &&
737 (tmp->is_multicast == addr->is_multicast) &&
738 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
739 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
740 sizeof(struct in6_addr)) == 0)) {
746 if (addr->users != 0)
747 tmp->users += addr->users;
749 tmp->users += add? 1:-1;
750 if (tmp->users == 0) {
751 list_del(&tmp->entry);
756 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
757 list_add(&addr->entry, card->ip_tbd_list);
759 if (addr->users == 0)
760 addr->users += add? 1:-1;
761 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
762 qeth_is_addr_covered_by_ipato(card, addr)){
763 QETH_DBF_TEXT(trace, 2, "tkovaddr");
764 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
766 list_add_tail(&addr->entry, card->ip_tbd_list);
773 * Remove IP address from list
776 qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
781 QETH_DBF_TEXT(trace, 4, "delip");
783 if (card->options.layer2)
784 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
785 else if (addr->proto == QETH_PROT_IPV4)
786 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
788 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
789 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
791 spin_lock_irqsave(&card->ip_lock, flags);
792 rc = __qeth_insert_ip_todo(card, addr, 0);
793 spin_unlock_irqrestore(&card->ip_lock, flags);
798 qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
803 QETH_DBF_TEXT(trace, 4, "addip");
804 if (card->options.layer2)
805 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
806 else if (addr->proto == QETH_PROT_IPV4)
807 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
809 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
810 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
812 spin_lock_irqsave(&card->ip_lock, flags);
813 rc = __qeth_insert_ip_todo(card, addr, 1);
814 spin_unlock_irqrestore(&card->ip_lock, flags);
819 __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
821 struct qeth_ipaddr *addr, *tmp;
824 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
825 if (addr->is_multicast) {
826 spin_unlock_irqrestore(&card->ip_lock, *flags);
827 rc = qeth_deregister_addr_entry(card, addr);
828 spin_lock_irqsave(&card->ip_lock, *flags);
830 list_del(&addr->entry);
839 qeth_set_ip_addr_list(struct qeth_card *card)
841 struct list_head *tbd_list;
842 struct qeth_ipaddr *todo, *addr;
846 QETH_DBF_TEXT(trace, 2, "sdiplist");
847 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
849 spin_lock_irqsave(&card->ip_lock, flags);
850 tbd_list = card->ip_tbd_list;
851 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
852 if (!card->ip_tbd_list) {
853 QETH_DBF_TEXT(trace, 0, "silnomem");
854 card->ip_tbd_list = tbd_list;
855 spin_unlock_irqrestore(&card->ip_lock, flags);
858 INIT_LIST_HEAD(card->ip_tbd_list);
860 while (!list_empty(tbd_list)){
861 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
862 list_del(&todo->entry);
863 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
864 __qeth_delete_all_mc(card, &flags);
868 rc = __qeth_ref_ip_on_card(card, todo, &addr);
870 /* nothing to be done; only adjusted refcount */
872 } else if (rc == 1) {
873 /* new entry to be added to on-card list */
874 spin_unlock_irqrestore(&card->ip_lock, flags);
875 rc = qeth_register_addr_entry(card, todo);
876 spin_lock_irqsave(&card->ip_lock, flags);
878 list_add_tail(&todo->entry, &card->ip_list);
881 } else if (rc == -1) {
882 /* on-card entry to be removed */
883 list_del_init(&addr->entry);
884 spin_unlock_irqrestore(&card->ip_lock, flags);
885 rc = qeth_deregister_addr_entry(card, addr);
886 spin_lock_irqsave(&card->ip_lock, flags);
890 list_add_tail(&addr->entry, &card->ip_list);
894 spin_unlock_irqrestore(&card->ip_lock, flags);
898 static void qeth_delete_mc_addresses(struct qeth_card *);
899 static void qeth_add_multicast_ipv4(struct qeth_card *);
900 static void qeth_layer2_add_multicast(struct qeth_card *);
901 #ifdef CONFIG_QETH_IPV6
902 static void qeth_add_multicast_ipv6(struct qeth_card *);
906 qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
910 spin_lock_irqsave(&card->thread_mask_lock, flags);
911 if ( !(card->thread_allowed_mask & thread) ||
912 (card->thread_start_mask & thread) ) {
913 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
916 card->thread_start_mask |= thread;
917 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
922 qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
926 spin_lock_irqsave(&card->thread_mask_lock, flags);
927 card->thread_start_mask &= ~thread;
928 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
929 wake_up(&card->wait_q);
933 qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
937 spin_lock_irqsave(&card->thread_mask_lock, flags);
938 card->thread_running_mask &= ~thread;
939 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
940 wake_up(&card->wait_q);
944 __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
949 spin_lock_irqsave(&card->thread_mask_lock, flags);
950 if (card->thread_start_mask & thread){
951 if ((card->thread_allowed_mask & thread) &&
952 !(card->thread_running_mask & thread)){
954 card->thread_start_mask &= ~thread;
955 card->thread_running_mask |= thread;
959 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
964 qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
968 wait_event(card->wait_q,
969 (rc = __qeth_do_run_thread(card, thread)) >= 0);
974 qeth_recover(void *ptr)
976 struct qeth_card *card;
979 card = (struct qeth_card *) ptr;
980 daemonize("qeth_recover");
981 QETH_DBF_TEXT(trace,2,"recover1");
982 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
983 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
985 QETH_DBF_TEXT(trace,2,"recover2");
986 PRINT_WARN("Recovery of device %s started ...\n",
988 card->use_hard_stop = 1;
989 __qeth_set_offline(card->gdev,1);
990 rc = __qeth_set_online(card->gdev,1);
991 /* don't run another scheduled recovery */
992 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
993 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
995 PRINT_INFO("Device %s successfully recovered!\n",
998 PRINT_INFO("Device %s could not be recovered!\n",
1004 qeth_schedule_recovery(struct qeth_card *card)
1006 QETH_DBF_TEXT(trace,2,"startrec");
1007 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
1008 schedule_work(&card->kernel_thread_starter);
1012 qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1014 unsigned long flags;
1017 spin_lock_irqsave(&card->thread_mask_lock, flags);
1018 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
1019 (u8) card->thread_start_mask,
1020 (u8) card->thread_allowed_mask,
1021 (u8) card->thread_running_mask);
1022 rc = (card->thread_start_mask & thread);
1023 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1028 qeth_start_kernel_thread(struct work_struct *work)
1030 struct qeth_card *card = container_of(work, struct qeth_card, kernel_thread_starter);
1031 QETH_DBF_TEXT(trace , 2, "strthrd");
1033 if (card->read.state != CH_STATE_UP &&
1034 card->write.state != CH_STATE_UP)
1036 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1037 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1042 qeth_set_intial_options(struct qeth_card *card)
1044 card->options.route4.type = NO_ROUTER;
1045 #ifdef CONFIG_QETH_IPV6
1046 card->options.route6.type = NO_ROUTER;
1047 #endif /* QETH_IPV6 */
1048 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1049 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1050 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1051 card->options.fake_broadcast = 0;
1052 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1053 card->options.fake_ll = 0;
1054 if (card->info.type == QETH_CARD_TYPE_OSN)
1055 card->options.layer2 = 1;
1057 card->options.layer2 = 0;
1058 card->options.performance_stats = 0;
1059 card->options.rx_sg_cb = QETH_RX_SG_CB;
1063 * initialize channels ,card and all state machines
1066 qeth_setup_card(struct qeth_card *card)
1069 QETH_DBF_TEXT(setup, 2, "setupcrd");
1070 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1072 card->read.state = CH_STATE_DOWN;
1073 card->write.state = CH_STATE_DOWN;
1074 card->data.state = CH_STATE_DOWN;
1075 card->state = CARD_STATE_DOWN;
1076 card->lan_online = 0;
1077 card->use_hard_stop = 0;
1079 #ifdef CONFIG_QETH_VLAN
1080 spin_lock_init(&card->vlanlock);
1081 card->vlangrp = NULL;
1083 spin_lock_init(&card->lock);
1084 spin_lock_init(&card->ip_lock);
1085 spin_lock_init(&card->thread_mask_lock);
1086 card->thread_start_mask = 0;
1087 card->thread_allowed_mask = 0;
1088 card->thread_running_mask = 0;
1089 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1090 INIT_LIST_HEAD(&card->ip_list);
1091 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1092 if (!card->ip_tbd_list) {
1093 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1096 INIT_LIST_HEAD(card->ip_tbd_list);
1097 INIT_LIST_HEAD(&card->cmd_waiter_list);
1098 init_waitqueue_head(&card->wait_q);
1099 /* intial options */
1100 qeth_set_intial_options(card);
1101 /* IP address takeover */
1102 INIT_LIST_HEAD(&card->ipato.entries);
1103 card->ipato.enabled = 0;
1104 card->ipato.invert4 = 0;
1105 card->ipato.invert6 = 0;
1106 /* init QDIO stuff */
1107 qeth_init_qdio_info(card);
1112 is_1920_device (struct qeth_card *card)
1114 int single_queue = 0;
1115 struct ccw_device *ccwdev;
1116 struct channelPath_dsc {
1127 QETH_DBF_TEXT(setup, 2, "chk_1920");
1129 ccwdev = card->data.ccwdev;
1130 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1131 if (chp_dsc != NULL) {
1132 /* CHPP field bit 6 == 1 -> single queue */
1133 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1136 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1137 return single_queue;
1141 qeth_determine_card_type(struct qeth_card *card)
1145 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1147 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1148 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1149 while (known_devices[i][4]) {
1150 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1151 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1152 card->info.type = known_devices[i][4];
1153 card->qdio.no_out_queues = known_devices[i][8];
1154 card->info.is_multicast_different = known_devices[i][9];
1155 if (is_1920_device(card)) {
1156 PRINT_INFO("Priority Queueing not able "
1157 "due to hardware limitations!\n");
1158 card->qdio.no_out_queues = 1;
1159 card->qdio.default_out_queue = 0;
1165 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1166 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1171 qeth_probe_device(struct ccwgroup_device *gdev)
1173 struct qeth_card *card;
1175 unsigned long flags;
1178 QETH_DBF_TEXT(setup, 2, "probedev");
1181 if (!get_device(dev))
1184 QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
1186 card = qeth_alloc_card();
1189 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1192 card->read.ccwdev = gdev->cdev[0];
1193 card->write.ccwdev = gdev->cdev[1];
1194 card->data.ccwdev = gdev->cdev[2];
1195 gdev->dev.driver_data = card;
1197 gdev->cdev[0]->handler = qeth_irq;
1198 gdev->cdev[1]->handler = qeth_irq;
1199 gdev->cdev[2]->handler = qeth_irq;
1201 if ((rc = qeth_determine_card_type(card))){
1202 PRINT_WARN("%s: not a valid card type\n", __func__);
1203 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1205 qeth_free_card(card);
1208 if ((rc = qeth_setup_card(card))){
1209 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1211 qeth_free_card(card);
1214 rc = qeth_create_device_attributes(dev);
1217 qeth_free_card(card);
1220 /* insert into our internal list */
1221 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1222 list_add_tail(&card->list, &qeth_card_list.list);
1223 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1228 static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
1234 struct qeth_channel *channel = &card->data;
1235 unsigned long flags;
1238 * scan for RCD command in extended SenseID data
1240 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
1241 if (!ciw || ciw->cmd == 0)
1243 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
1247 channel->ccw.cmd_code = ciw->cmd;
1248 channel->ccw.cda = (__u32) __pa (rcd_buf);
1249 channel->ccw.count = ciw->count;
1250 channel->ccw.flags = CCW_FLAG_SLI;
1251 channel->state = CH_STATE_RCD;
1252 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1253 ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1254 QETH_RCD_PARM, LPM_ANYPATH, 0,
1256 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1258 wait_event(card->wait_q,
1259 (channel->state == CH_STATE_RCD_DONE ||
1260 channel->state == CH_STATE_DOWN));
1261 if (channel->state == CH_STATE_DOWN)
1264 channel->state = CH_STATE_DOWN;
1270 *length = ciw->count;
1277 qeth_get_unitaddr(struct qeth_card *card)
1283 QETH_DBF_TEXT(setup, 2, "getunit");
1284 rc = qeth_read_conf_data(card, (void **) &prcd, &length);
1286 PRINT_ERR("qeth_read_conf_data for device %s returned %i\n",
1287 CARD_DDEV_ID(card), rc);
1290 card->info.chpid = prcd[30];
1291 card->info.unit_addr2 = prcd[31];
1292 card->info.cula = prcd[63];
1293 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1294 (prcd[0x11] == _ascebc['M']));
1300 qeth_init_tokens(struct qeth_card *card)
1302 card->token.issuer_rm_w = 0x00010103UL;
1303 card->token.cm_filter_w = 0x00010108UL;
1304 card->token.cm_connection_w = 0x0001010aUL;
1305 card->token.ulp_filter_w = 0x0001010bUL;
1306 card->token.ulp_connection_w = 0x0001010dUL;
1310 raw_devno_from_bus_id(char *id)
1312 id += (strlen(id) - 4);
1313 return (__u16) simple_strtoul(id, &id, 16);
1319 qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1321 struct qeth_card *card;
1323 QETH_DBF_TEXT(trace, 4, "setupccw");
1324 card = CARD_FROM_CDEV(channel->ccwdev);
1325 if (channel == &card->read)
1326 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1328 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1329 channel->ccw.count = len;
1330 channel->ccw.cda = (__u32) __pa(iob);
1334 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1336 static struct qeth_cmd_buffer *
1337 __qeth_get_buffer(struct qeth_channel *channel)
1341 QETH_DBF_TEXT(trace, 6, "getbuff");
1342 index = channel->io_buf_no;
1344 if (channel->iob[index].state == BUF_STATE_FREE) {
1345 channel->iob[index].state = BUF_STATE_LOCKED;
1346 channel->io_buf_no = (channel->io_buf_no + 1) %
1348 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1349 return channel->iob + index;
1351 index = (index + 1) % QETH_CMD_BUFFER_NO;
1352 } while(index != channel->io_buf_no);
1358 * release command buffer
1361 qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1363 unsigned long flags;
1365 QETH_DBF_TEXT(trace, 6, "relbuff");
1366 spin_lock_irqsave(&channel->iob_lock, flags);
1367 memset(iob->data, 0, QETH_BUFSIZE);
1368 iob->state = BUF_STATE_FREE;
1369 iob->callback = qeth_send_control_data_cb;
1371 spin_unlock_irqrestore(&channel->iob_lock, flags);
1374 static struct qeth_cmd_buffer *
1375 qeth_get_buffer(struct qeth_channel *channel)
1377 struct qeth_cmd_buffer *buffer = NULL;
1378 unsigned long flags;
1380 spin_lock_irqsave(&channel->iob_lock, flags);
1381 buffer = __qeth_get_buffer(channel);
1382 spin_unlock_irqrestore(&channel->iob_lock, flags);
1386 static struct qeth_cmd_buffer *
1387 qeth_wait_for_buffer(struct qeth_channel *channel)
1389 struct qeth_cmd_buffer *buffer;
1390 wait_event(channel->wait_q,
1391 ((buffer = qeth_get_buffer(channel)) != NULL));
1396 qeth_clear_cmd_buffers(struct qeth_channel *channel)
1400 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1401 qeth_release_buffer(channel,&channel->iob[cnt]);
1402 channel->buf_no = 0;
1403 channel->io_buf_no = 0;
1407 * start IDX for read and write channel
1410 qeth_idx_activate_get_answer(struct qeth_channel *channel,
1411 void (*idx_reply_cb)(struct qeth_channel *,
1412 struct qeth_cmd_buffer *))
1414 struct qeth_cmd_buffer *iob;
1415 unsigned long flags;
1417 struct qeth_card *card;
1419 QETH_DBF_TEXT(setup, 2, "idxanswr");
1420 card = CARD_FROM_CDEV(channel->ccwdev);
1421 iob = qeth_get_buffer(channel);
1422 iob->callback = idx_reply_cb;
1423 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1424 channel->ccw.count = QETH_BUFSIZE;
1425 channel->ccw.cda = (__u32) __pa(iob->data);
1427 wait_event(card->wait_q,
1428 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1429 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1430 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1431 rc = ccw_device_start(channel->ccwdev,
1432 &channel->ccw,(addr_t) iob, 0, 0);
1433 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1436 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1437 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1438 atomic_set(&channel->irq_pending, 0);
1439 wake_up(&card->wait_q);
1442 rc = wait_event_interruptible_timeout(card->wait_q,
1443 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1444 if (rc == -ERESTARTSYS)
1446 if (channel->state != CH_STATE_UP){
1448 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1449 qeth_clear_cmd_buffers(channel);
1456 qeth_idx_activate_channel(struct qeth_channel *channel,
1457 void (*idx_reply_cb)(struct qeth_channel *,
1458 struct qeth_cmd_buffer *))
1460 struct qeth_card *card;
1461 struct qeth_cmd_buffer *iob;
1462 unsigned long flags;
1466 card = CARD_FROM_CDEV(channel->ccwdev);
1468 QETH_DBF_TEXT(setup, 2, "idxactch");
1470 iob = qeth_get_buffer(channel);
1471 iob->callback = idx_reply_cb;
1472 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1473 channel->ccw.count = IDX_ACTIVATE_SIZE;
1474 channel->ccw.cda = (__u32) __pa(iob->data);
1475 if (channel == &card->write) {
1476 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1477 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1478 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1479 card->seqno.trans_hdr++;
1481 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1482 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1483 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1485 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1486 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1487 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1488 &card->info.func_level,sizeof(__u16));
1489 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1490 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1491 temp = (card->info.cula << 8) + card->info.unit_addr2;
1492 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1494 wait_event(card->wait_q,
1495 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1496 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1497 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1498 rc = ccw_device_start(channel->ccwdev,
1499 &channel->ccw,(addr_t) iob, 0, 0);
1500 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1503 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1504 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1505 atomic_set(&channel->irq_pending, 0);
1506 wake_up(&card->wait_q);
1509 rc = wait_event_interruptible_timeout(card->wait_q,
1510 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1511 if (rc == -ERESTARTSYS)
1513 if (channel->state != CH_STATE_ACTIVATING) {
1514 PRINT_WARN("qeth: IDX activate timed out!\n");
1515 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1516 qeth_clear_cmd_buffers(channel);
1519 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1523 qeth_peer_func_level(int level)
1525 if ((level & 0xff) == 8)
1526 return (level & 0xff) + 0x400;
1527 if (((level >> 8) & 3) == 1)
1528 return (level & 0xff) + 0x200;
1533 qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1535 struct qeth_card *card;
1538 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1540 if (channel->state == CH_STATE_DOWN) {
1541 channel->state = CH_STATE_ACTIVATING;
1544 card = CARD_FROM_CDEV(channel->ccwdev);
1546 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1547 if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == 0x19)
1548 PRINT_ERR("IDX_ACTIVATE on write channel device %s: "
1549 "adapter exclusively used by another host\n",
1550 CARD_WDEV_ID(card));
1552 PRINT_ERR("IDX_ACTIVATE on write channel device %s: "
1553 "negative reply\n", CARD_WDEV_ID(card));
1556 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1557 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1558 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1559 "function level mismatch "
1560 "(sent: 0x%x, received: 0x%x)\n",
1561 CARD_WDEV_ID(card), card->info.func_level, temp);
1564 channel->state = CH_STATE_UP;
1566 qeth_release_buffer(channel, iob);
1570 qeth_check_idx_response(unsigned char *buffer)
1575 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1576 if ((buffer[2] & 0xc0) == 0xc0) {
1577 PRINT_WARN("received an IDX TERMINATE "
1578 "with cause code 0x%02x%s\n",
1580 ((buffer[4] == 0x22) ?
1581 " -- try another portname" : ""));
1582 QETH_DBF_TEXT(trace, 2, "ckidxres");
1583 QETH_DBF_TEXT(trace, 2, " idxterm");
1584 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1591 qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1593 struct qeth_card *card;
1596 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1597 if (channel->state == CH_STATE_DOWN) {
1598 channel->state = CH_STATE_ACTIVATING;
1602 card = CARD_FROM_CDEV(channel->ccwdev);
1603 if (qeth_check_idx_response(iob->data)) {
1606 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1607 if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == 0x19)
1608 PRINT_ERR("IDX_ACTIVATE on read channel device %s: "
1609 "adapter exclusively used by another host\n",
1610 CARD_RDEV_ID(card));
1612 PRINT_ERR("IDX_ACTIVATE on read channel device %s: "
1613 "negative reply\n", CARD_RDEV_ID(card));
1618 * temporary fix for microcode bug
1619 * to revert it,replace OR by AND
1621 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1622 (card->info.type == QETH_CARD_TYPE_OSAE) )
1623 card->info.portname_required = 1;
1625 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1626 if (temp != qeth_peer_func_level(card->info.func_level)) {
1627 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1628 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1629 CARD_RDEV_ID(card), card->info.func_level, temp);
1632 memcpy(&card->token.issuer_rm_r,
1633 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1634 QETH_MPC_TOKEN_LENGTH);
1635 memcpy(&card->info.mcl_level[0],
1636 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1637 channel->state = CH_STATE_UP;
1639 qeth_release_buffer(channel,iob);
1643 qeth_issue_next_read(struct qeth_card *card)
1646 struct qeth_cmd_buffer *iob;
1648 QETH_DBF_TEXT(trace,5,"issnxrd");
1649 if (card->read.state != CH_STATE_UP)
1651 iob = qeth_get_buffer(&card->read);
1653 PRINT_WARN("issue_next_read failed: no iob available!\n");
1656 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1657 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1658 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1659 (addr_t) iob, 0, 0);
1661 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1662 atomic_set(&card->read.irq_pending, 0);
1663 qeth_schedule_recovery(card);
1664 wake_up(&card->wait_q);
1669 static struct qeth_reply *
1670 qeth_alloc_reply(struct qeth_card *card)
1672 struct qeth_reply *reply;
1674 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1676 atomic_set(&reply->refcnt, 1);
1677 atomic_set(&reply->received, 0);
1684 qeth_get_reply(struct qeth_reply *reply)
1686 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1687 atomic_inc(&reply->refcnt);
1691 qeth_put_reply(struct qeth_reply *reply)
1693 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1694 if (atomic_dec_and_test(&reply->refcnt))
1699 qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, struct qeth_card *card)
1705 com = cmd->hdr.command;
1706 rc = cmd->hdr.return_code;
1707 ipa_name = qeth_get_ipa_cmd_name(com);
1709 PRINT_ERR("%s(x%X) for %s returned x%X \"%s\"\n", ipa_name, com,
1710 QETH_CARD_IFNAME(card), rc, qeth_get_ipa_msg(rc));
1713 static struct qeth_ipa_cmd *
1714 qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1716 struct qeth_ipa_cmd *cmd = NULL;
1718 QETH_DBF_TEXT(trace,5,"chkipad");
1719 if (IS_IPA(iob->data)){
1720 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1721 if (IS_IPA_REPLY(cmd)) {
1722 if (cmd->hdr.return_code)
1723 qeth_issue_ipa_msg(cmd, card);
1727 switch (cmd->hdr.command) {
1728 case IPA_CMD_STOPLAN:
1729 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1730 "there is a network problem or "
1731 "someone pulled the cable or "
1732 "disabled the port.\n",
1733 QETH_CARD_IFNAME(card),
1735 card->lan_online = 0;
1736 if (card->dev && netif_carrier_ok(card->dev))
1737 netif_carrier_off(card->dev);
1739 case IPA_CMD_STARTLAN:
1740 PRINT_INFO("Link reestablished on %s "
1741 "(CHPID 0x%X). Scheduling "
1742 "IP address reset.\n",
1743 QETH_CARD_IFNAME(card),
1745 netif_carrier_on(card->dev);
1746 qeth_schedule_recovery(card);
1748 case IPA_CMD_MODCCID:
1750 case IPA_CMD_REGISTER_LOCAL_ADDR:
1751 QETH_DBF_TEXT(trace,3, "irla");
1753 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1754 QETH_DBF_TEXT(trace,3, "urla");
1757 PRINT_WARN("Received data is IPA "
1758 "but not a reply!\n");
1767 * wake all waiting ipa commands
1770 qeth_clear_ipacmd_list(struct qeth_card *card)
1772 struct qeth_reply *reply, *r;
1773 unsigned long flags;
1775 QETH_DBF_TEXT(trace, 4, "clipalst");
1777 spin_lock_irqsave(&card->lock, flags);
1778 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1779 qeth_get_reply(reply);
1781 atomic_inc(&reply->received);
1782 list_del_init(&reply->list);
1783 wake_up(&reply->wait_q);
1784 qeth_put_reply(reply);
1786 spin_unlock_irqrestore(&card->lock, flags);
1790 qeth_send_control_data_cb(struct qeth_channel *channel,
1791 struct qeth_cmd_buffer *iob)
1793 struct qeth_card *card;
1794 struct qeth_reply *reply, *r;
1795 struct qeth_ipa_cmd *cmd;
1796 unsigned long flags;
1799 QETH_DBF_TEXT(trace,4,"sndctlcb");
1801 card = CARD_FROM_CDEV(channel->ccwdev);
1802 if (qeth_check_idx_response(iob->data)) {
1803 qeth_clear_ipacmd_list(card);
1804 qeth_schedule_recovery(card);
1808 cmd = qeth_check_ipa_data(card, iob);
1809 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1811 /*in case of OSN : check if cmd is set */
1812 if (card->info.type == QETH_CARD_TYPE_OSN &&
1814 cmd->hdr.command != IPA_CMD_STARTLAN &&
1815 card->osn_info.assist_cb != NULL) {
1816 card->osn_info.assist_cb(card->dev, cmd);
1820 spin_lock_irqsave(&card->lock, flags);
1821 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1822 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1823 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1824 qeth_get_reply(reply);
1825 list_del_init(&reply->list);
1826 spin_unlock_irqrestore(&card->lock, flags);
1828 if (reply->callback != NULL) {
1830 reply->offset = (__u16)((char*)cmd -
1832 keep_reply = reply->callback(card,
1834 (unsigned long)cmd);
1836 keep_reply = reply->callback(card,
1838 (unsigned long)iob);
1841 reply->rc = (u16) cmd->hdr.return_code;
1843 reply->rc = iob->rc;
1845 spin_lock_irqsave(&card->lock, flags);
1846 list_add_tail(&reply->list,
1847 &card->cmd_waiter_list);
1848 spin_unlock_irqrestore(&card->lock, flags);
1850 atomic_inc(&reply->received);
1851 wake_up(&reply->wait_q);
1853 qeth_put_reply(reply);
1857 spin_unlock_irqrestore(&card->lock, flags);
1859 memcpy(&card->seqno.pdu_hdr_ack,
1860 QETH_PDU_HEADER_SEQ_NO(iob->data),
1861 QETH_SEQ_NO_LENGTH);
1862 qeth_release_buffer(channel,iob);
1866 qeth_prepare_control_data(struct qeth_card *card, int len,
1867 struct qeth_cmd_buffer *iob)
1869 qeth_setup_ccw(&card->write,iob->data,len);
1870 iob->callback = qeth_release_buffer;
1872 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1873 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1874 card->seqno.trans_hdr++;
1875 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1876 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1877 card->seqno.pdu_hdr++;
1878 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1879 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1880 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1884 qeth_send_control_data(struct qeth_card *card, int len,
1885 struct qeth_cmd_buffer *iob,
1887 (struct qeth_card *, struct qeth_reply*, unsigned long),
1892 unsigned long flags;
1893 struct qeth_reply *reply = NULL;
1894 unsigned long timeout;
1896 QETH_DBF_TEXT(trace, 2, "sendctl");
1898 reply = qeth_alloc_reply(card);
1900 PRINT_WARN("Could no alloc qeth_reply!\n");
1903 reply->callback = reply_cb;
1904 reply->param = reply_param;
1905 if (card->state == CARD_STATE_DOWN)
1906 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1908 reply->seqno = card->seqno.ipa++;
1909 init_waitqueue_head(&reply->wait_q);
1910 spin_lock_irqsave(&card->lock, flags);
1911 list_add_tail(&reply->list, &card->cmd_waiter_list);
1912 spin_unlock_irqrestore(&card->lock, flags);
1913 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1915 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
1916 qeth_prepare_control_data(card, len, iob);
1918 if (IS_IPA(iob->data))
1919 timeout = jiffies + QETH_IPA_TIMEOUT;
1921 timeout = jiffies + QETH_TIMEOUT;
1923 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1924 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1925 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1926 (addr_t) iob, 0, 0);
1927 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1929 PRINT_WARN("qeth_send_control_data: "
1930 "ccw_device_start rc = %i\n", rc);
1931 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1932 spin_lock_irqsave(&card->lock, flags);
1933 list_del_init(&reply->list);
1934 qeth_put_reply(reply);
1935 spin_unlock_irqrestore(&card->lock, flags);
1936 qeth_release_buffer(iob->channel, iob);
1937 atomic_set(&card->write.irq_pending, 0);
1938 wake_up(&card->wait_q);
1941 while (!atomic_read(&reply->received)) {
1942 if (time_after(jiffies, timeout)) {
1943 spin_lock_irqsave(&reply->card->lock, flags);
1944 list_del_init(&reply->list);
1945 spin_unlock_irqrestore(&reply->card->lock, flags);
1947 atomic_inc(&reply->received);
1948 wake_up(&reply->wait_q);
1953 qeth_put_reply(reply);
1958 qeth_osn_send_control_data(struct qeth_card *card, int len,
1959 struct qeth_cmd_buffer *iob)
1961 unsigned long flags;
1964 QETH_DBF_TEXT(trace, 5, "osndctrd");
1966 wait_event(card->wait_q,
1967 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1968 qeth_prepare_control_data(card, len, iob);
1969 QETH_DBF_TEXT(trace, 6, "osnoirqp");
1970 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1971 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1972 (addr_t) iob, 0, 0);
1973 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1975 PRINT_WARN("qeth_osn_send_control_data: "
1976 "ccw_device_start rc = %i\n", rc);
1977 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1978 qeth_release_buffer(iob->channel, iob);
1979 atomic_set(&card->write.irq_pending, 0);
1980 wake_up(&card->wait_q);
1986 qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1989 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1990 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1991 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1992 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1996 qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2001 QETH_DBF_TEXT(trace,4,"osndipa");
2003 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
2004 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
2006 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
2007 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
2008 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
2009 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
2010 return qeth_osn_send_control_data(card, s1, iob);
2014 qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2016 (struct qeth_card *,struct qeth_reply*, unsigned long),
2022 QETH_DBF_TEXT(trace,4,"sendipa");
2024 if (card->options.layer2)
2025 if (card->info.type == QETH_CARD_TYPE_OSN)
2026 prot_type = QETH_PROT_OSN2;
2028 prot_type = QETH_PROT_LAYER2;
2030 prot_type = QETH_PROT_TCPIP;
2031 qeth_prepare_ipa_cmd(card,iob,prot_type);
2032 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
2033 reply_cb, reply_param);
2039 qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2042 struct qeth_cmd_buffer *iob;
2044 QETH_DBF_TEXT(setup, 2, "cmenblcb");
2046 iob = (struct qeth_cmd_buffer *) data;
2047 memcpy(&card->token.cm_filter_r,
2048 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2049 QETH_MPC_TOKEN_LENGTH);
2050 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2055 qeth_cm_enable(struct qeth_card *card)
2058 struct qeth_cmd_buffer *iob;
2060 QETH_DBF_TEXT(setup,2,"cmenable");
2062 iob = qeth_wait_for_buffer(&card->write);
2063 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2064 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2065 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2066 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2067 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2069 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2070 qeth_cm_enable_cb, NULL);
2075 qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2079 struct qeth_cmd_buffer *iob;
2081 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
2083 iob = (struct qeth_cmd_buffer *) data;
2084 memcpy(&card->token.cm_connection_r,
2085 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2086 QETH_MPC_TOKEN_LENGTH);
2087 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2092 qeth_cm_setup(struct qeth_card *card)
2095 struct qeth_cmd_buffer *iob;
2097 QETH_DBF_TEXT(setup,2,"cmsetup");
2099 iob = qeth_wait_for_buffer(&card->write);
2100 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2101 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2102 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2103 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2104 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2105 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2106 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2107 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2108 qeth_cm_setup_cb, NULL);
2114 qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2118 __u16 mtu, framesize;
2121 struct qeth_cmd_buffer *iob;
2123 QETH_DBF_TEXT(setup, 2, "ulpenacb");
2125 iob = (struct qeth_cmd_buffer *) data;
2126 memcpy(&card->token.ulp_filter_r,
2127 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2128 QETH_MPC_TOKEN_LENGTH);
2129 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
2130 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2131 mtu = qeth_get_mtu_outof_framesize(framesize);
2134 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2137 card->info.max_mtu = mtu;
2138 card->info.initial_mtu = mtu;
2139 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2141 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2142 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
2143 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2146 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2147 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2149 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2150 card->info.link_type = link_type;
2152 card->info.link_type = 0;
2153 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2158 qeth_ulp_enable(struct qeth_card *card)
2162 struct qeth_cmd_buffer *iob;
2164 /*FIXME: trace view callbacks*/
2165 QETH_DBF_TEXT(setup,2,"ulpenabl");
2167 iob = qeth_wait_for_buffer(&card->write);
2168 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2170 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2171 (__u8) card->info.portno;
2172 if (card->options.layer2)
2173 if (card->info.type == QETH_CARD_TYPE_OSN)
2174 prot_type = QETH_PROT_OSN2;
2176 prot_type = QETH_PROT_LAYER2;
2178 prot_type = QETH_PROT_TCPIP;
2180 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2181 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2182 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2183 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2184 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2185 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2186 card->info.portname, 9);
2187 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2188 qeth_ulp_enable_cb, NULL);
2194 qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2197 struct qeth_cmd_buffer *iob;
2199 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2201 iob = (struct qeth_cmd_buffer *) data;
2202 memcpy(&card->token.ulp_connection_r,
2203 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2204 QETH_MPC_TOKEN_LENGTH);
2205 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2210 qeth_ulp_setup(struct qeth_card *card)
2214 struct qeth_cmd_buffer *iob;
2215 struct ccw_dev_id dev_id;
2217 QETH_DBF_TEXT(setup,2,"ulpsetup");
2219 iob = qeth_wait_for_buffer(&card->write);
2220 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2222 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2223 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2224 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2225 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2226 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2227 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2229 ccw_device_get_id(CARD_DDEV(card), &dev_id);
2230 memcpy(QETH_ULP_SETUP_CUA(iob->data), &dev_id.devno, 2);
2231 temp = (card->info.cula << 8) + card->info.unit_addr2;
2232 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2233 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2234 qeth_ulp_setup_cb, NULL);
2239 qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2240 unsigned int siga_error, const char *dbftext)
2242 if (qdio_error || siga_error) {
2243 QETH_DBF_TEXT(trace, 2, dbftext);
2244 QETH_DBF_TEXT(qerr, 2, dbftext);
2245 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
2246 buf->element[15].flags & 0xff);
2247 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
2248 buf->element[14].flags & 0xff);
2249 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2250 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
2256 static struct sk_buff *
2257 qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
2259 struct sk_buff* skb;
2263 if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2264 add_len = sizeof(struct qeth_hdr);
2265 #ifdef CONFIG_QETH_VLAN
2267 add_len = VLAN_HLEN;
2269 skb = dev_alloc_skb(length + add_len);
2271 skb_reserve(skb, add_len);
2276 qeth_create_skb_frag(struct qdio_buffer_element *element,
2277 struct sk_buff **pskb,
2278 int offset, int *pfrag, int data_len)
2280 struct page *page = virt_to_page(element->addr);
2282 /* the upper protocol layers assume that there is data in the
2283 * skb itself. Copy a small amount (64 bytes) to make them
2285 *pskb = dev_alloc_skb(64 + QETH_FAKE_LL_LEN_ETH);
2288 skb_reserve(*pskb, QETH_FAKE_LL_LEN_ETH);
2289 if (data_len <= 64) {
2290 memcpy(skb_put(*pskb, data_len), element->addr + offset,
2294 memcpy(skb_put(*pskb, 64), element->addr + offset, 64);
2295 skb_fill_page_desc(*pskb, *pfrag, page, offset + 64,
2297 (*pskb)->data_len += data_len - 64;
2298 (*pskb)->len += data_len - 64;
2299 (*pskb)->truesize += data_len - 64;
2303 skb_fill_page_desc(*pskb, *pfrag, page, offset, data_len);
2304 (*pskb)->data_len += data_len;
2305 (*pskb)->len += data_len;
2306 (*pskb)->truesize += data_len;
2312 static inline struct qeth_buffer_pool_entry *
2313 qeth_find_free_buffer_pool_entry(struct qeth_card *card)
2315 struct list_head *plh;
2316 struct qeth_buffer_pool_entry *entry;
2320 if (list_empty(&card->qdio.in_buf_pool.entry_list))
2323 list_for_each(plh, &card->qdio.in_buf_pool.entry_list) {
2324 entry = list_entry(plh, struct qeth_buffer_pool_entry, list);
2326 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2327 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2333 list_del_init(&entry->list);
2338 /* no free buffer in pool so take first one and swap pages */
2339 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2340 struct qeth_buffer_pool_entry, list);
2341 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2342 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2343 page = alloc_page(GFP_ATOMIC|GFP_DMA);
2347 free_page((unsigned long)entry->elements[i]);
2348 entry->elements[i] = page_address(page);
2349 if (card->options.performance_stats)
2350 card->perf_stats.sg_alloc_page_rx++;
2354 list_del_init(&entry->list);
2358 static struct sk_buff *
2359 qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2360 struct qdio_buffer_element **__element, int *__offset,
2361 struct qeth_hdr **hdr)
2363 struct qdio_buffer_element *element = *__element;
2364 int offset = *__offset;
2365 struct sk_buff *skb = NULL;
2372 QETH_DBF_TEXT(trace,6,"nextskb");
2373 /* qeth_hdr must not cross element boundaries */
2374 if (element->length < offset + sizeof(struct qeth_hdr)){
2375 if (qeth_is_last_sbale(element))
2379 if (element->length < sizeof(struct qeth_hdr))
2382 *hdr = element->addr + offset;
2384 offset += sizeof(struct qeth_hdr);
2385 if (card->options.layer2)
2386 if (card->info.type == QETH_CARD_TYPE_OSN)
2387 skb_len = (*hdr)->hdr.osn.pdu_length;
2389 skb_len = (*hdr)->hdr.l2.pkt_length;
2391 skb_len = (*hdr)->hdr.l3.length;
2395 if ((skb_len >= card->options.rx_sg_cb) &&
2396 (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
2397 (!atomic_read(&card->force_alloc_skb))) {
2400 if (card->options.fake_ll) {
2401 if (card->dev->type == ARPHRD_IEEE802_TR) {
2402 if (!(skb = qeth_get_skb(skb_len +
2403 QETH_FAKE_LL_LEN_TR, *hdr)))
2405 skb_reserve(skb, QETH_FAKE_LL_LEN_TR);
2407 if (!(skb = qeth_get_skb(skb_len +
2408 QETH_FAKE_LL_LEN_ETH, *hdr)))
2410 skb_reserve(skb, QETH_FAKE_LL_LEN_ETH);
2413 skb = qeth_get_skb(skb_len, *hdr);
2419 data_ptr = element->addr + offset;
2421 data_len = min(skb_len, (int)(element->length - offset));
2424 if (qeth_create_skb_frag(element, &skb, offset,
2428 memcpy(skb_put(skb, data_len), data_ptr,
2432 skb_len -= data_len;
2434 if (qeth_is_last_sbale(element)){
2435 QETH_DBF_TEXT(trace,4,"unexeob");
2436 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2437 QETH_DBF_TEXT(qerr,2,"unexeob");
2438 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2439 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2440 dev_kfree_skb_any(skb);
2441 card->stats.rx_errors++;
2446 data_ptr = element->addr;
2451 *__element = element;
2453 if (use_rx_sg && card->options.performance_stats) {
2454 card->perf_stats.sg_skbs_rx++;
2455 card->perf_stats.sg_frags_rx += skb_shinfo(skb)->nr_frags;
2459 if (net_ratelimit()){
2460 PRINT_WARN("No memory for packet received on %s.\n",
2461 QETH_CARD_IFNAME(card));
2462 QETH_DBF_TEXT(trace,2,"noskbmem");
2463 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2465 card->stats.rx_dropped++;
2470 qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2472 struct qeth_card *card;
2475 QETH_DBF_TEXT(trace,6,"typtrans");
2477 card = (struct qeth_card *)dev->priv;
2479 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2480 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2481 return tr_type_trans(skb,dev);
2482 #endif /* CONFIG_TR */
2483 skb_reset_mac_header(skb);
2484 skb_pull(skb, ETH_HLEN );
2487 if (*eth->h_dest & 1) {
2488 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2489 skb->pkt_type = PACKET_BROADCAST;
2491 skb->pkt_type = PACKET_MULTICAST;
2492 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2493 skb->pkt_type = PACKET_OTHERHOST;
2495 if (ntohs(eth->h_proto) >= 1536)
2496 return eth->h_proto;
2497 if (*(unsigned short *) (skb->data) == 0xFFFF)
2498 return htons(ETH_P_802_3);
2499 return htons(ETH_P_802_2);
2503 qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2504 struct qeth_hdr *hdr)
2506 struct trh_hdr *fake_hdr;
2507 struct trllc *fake_llc;
2508 struct iphdr *ip_hdr;
2510 QETH_DBF_TEXT(trace,5,"skbfktr");
2511 skb_set_mac_header(skb, (int)-QETH_FAKE_LL_LEN_TR);
2512 /* this is a fake ethernet header */
2513 fake_hdr = tr_hdr(skb);
2515 /* the destination MAC address */
2516 switch (skb->pkt_type){
2517 case PACKET_MULTICAST:
2518 switch (skb->protocol){
2519 #ifdef CONFIG_QETH_IPV6
2520 case __constant_htons(ETH_P_IPV6):
2521 ndisc_mc_map((struct in6_addr *)
2522 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2523 fake_hdr->daddr, card->dev, 0);
2525 #endif /* CONFIG_QETH_IPV6 */
2526 case __constant_htons(ETH_P_IP):
2527 ip_hdr = (struct iphdr *)skb->data;
2528 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2531 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2534 case PACKET_BROADCAST:
2535 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2538 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2540 /* the source MAC address */
2541 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2542 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2544 memset(fake_hdr->saddr, 0, TR_ALEN);
2546 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2547 fake_llc->dsap = EXTENDED_SAP;
2548 fake_llc->ssap = EXTENDED_SAP;
2549 fake_llc->llc = UI_CMD;
2550 fake_llc->protid[0] = 0;
2551 fake_llc->protid[1] = 0;
2552 fake_llc->protid[2] = 0;
2553 fake_llc->ethertype = ETH_P_IP;
2557 qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
2558 struct qeth_hdr *hdr)
2560 struct ethhdr *fake_hdr;
2561 struct iphdr *ip_hdr;
2563 QETH_DBF_TEXT(trace,5,"skbfketh");
2564 skb_set_mac_header(skb, -QETH_FAKE_LL_LEN_ETH);
2565 /* this is a fake ethernet header */
2566 fake_hdr = eth_hdr(skb);
2568 /* the destination MAC address */
2569 switch (skb->pkt_type){
2570 case PACKET_MULTICAST:
2571 switch (skb->protocol){
2572 #ifdef CONFIG_QETH_IPV6
2573 case __constant_htons(ETH_P_IPV6):
2574 ndisc_mc_map((struct in6_addr *)
2575 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2576 fake_hdr->h_dest, card->dev, 0);
2578 #endif /* CONFIG_QETH_IPV6 */
2579 case __constant_htons(ETH_P_IP):
2580 ip_hdr = (struct iphdr *)skb->data;
2581 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
2584 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2587 case PACKET_BROADCAST:
2588 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2591 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2593 /* the source MAC address */
2594 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2595 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2597 memset(fake_hdr->h_source, 0, ETH_ALEN);
2599 fake_hdr->h_proto = skb->protocol;
2603 qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2604 struct qeth_hdr *hdr)
2606 if (card->dev->type == ARPHRD_IEEE802_TR)
2607 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2609 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2613 qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2614 struct qeth_hdr *hdr)
2616 skb->pkt_type = PACKET_HOST;
2617 skb->protocol = qeth_type_trans(skb, skb->dev);
2618 if (card->options.checksum_type == NO_CHECKSUMMING)
2619 skb->ip_summed = CHECKSUM_UNNECESSARY;
2621 skb->ip_summed = CHECKSUM_NONE;
2622 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
2626 qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2627 struct qeth_hdr *hdr)
2629 unsigned short vlan_id = 0;
2630 #ifdef CONFIG_QETH_IPV6
2631 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2632 skb->pkt_type = PACKET_HOST;
2633 skb->protocol = qeth_type_trans(skb, card->dev);
2636 #endif /* CONFIG_QETH_IPV6 */
2637 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2639 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2640 case QETH_CAST_UNICAST:
2641 skb->pkt_type = PACKET_HOST;
2643 case QETH_CAST_MULTICAST:
2644 skb->pkt_type = PACKET_MULTICAST;
2645 card->stats.multicast++;
2647 case QETH_CAST_BROADCAST:
2648 skb->pkt_type = PACKET_BROADCAST;
2649 card->stats.multicast++;
2651 case QETH_CAST_ANYCAST:
2652 case QETH_CAST_NOCAST:
2654 skb->pkt_type = PACKET_HOST;
2657 if (hdr->hdr.l3.ext_flags &
2658 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2659 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2660 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2663 if (card->options.fake_ll)
2664 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2666 skb_reset_mac_header(skb);
2667 skb->ip_summed = card->options.checksum_type;
2668 if (card->options.checksum_type == HW_CHECKSUMMING){
2669 if ( (hdr->hdr.l3.ext_flags &
2670 (QETH_HDR_EXT_CSUM_HDR_REQ |
2671 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2672 (QETH_HDR_EXT_CSUM_HDR_REQ |
2673 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2674 skb->ip_summed = CHECKSUM_UNNECESSARY;
2676 skb->ip_summed = SW_CHECKSUMMING;
2682 qeth_process_inbound_buffer(struct qeth_card *card,
2683 struct qeth_qdio_buffer *buf, int index)
2685 struct qdio_buffer_element *element;
2686 struct sk_buff *skb;
2687 struct qeth_hdr *hdr;
2692 /* get first element of current buffer */
2693 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2695 if (card->options.performance_stats)
2696 card->perf_stats.bufs_rec++;
2697 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2699 skb->dev = card->dev;
2700 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2701 qeth_layer2_rebuild_skb(card, skb, hdr);
2702 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2703 vlan_tag = qeth_rebuild_skb(card, skb, hdr);
2704 else { /*in case of OSN*/
2705 skb_push(skb, sizeof(struct qeth_hdr));
2706 skb_copy_to_linear_data(skb, hdr,
2707 sizeof(struct qeth_hdr));
2709 /* is device UP ? */
2710 if (!(card->dev->flags & IFF_UP)){
2711 dev_kfree_skb_any(skb);
2714 if (card->info.type == QETH_CARD_TYPE_OSN)
2715 rxrc = card->osn_info.data_cb(skb);
2717 #ifdef CONFIG_QETH_VLAN
2720 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2722 dev_kfree_skb_any(skb);
2727 rxrc = netif_rx(skb);
2728 card->dev->last_rx = jiffies;
2729 card->stats.rx_packets++;
2730 card->stats.rx_bytes += skb->len;
2735 qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2737 struct qeth_buffer_pool_entry *pool_entry;
2740 pool_entry = qeth_find_free_buffer_pool_entry(card);
2744 * since the buffer is accessed only from the input_tasklet
2745 * there shouldn't be a need to synchronize; also, since we use
2746 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2749 BUG_ON(!pool_entry);
2751 buf->pool_entry = pool_entry;
2752 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2753 buf->buffer->element[i].length = PAGE_SIZE;
2754 buf->buffer->element[i].addr = pool_entry->elements[i];
2755 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2756 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2758 buf->buffer->element[i].flags = 0;
2760 buf->state = QETH_QDIO_BUF_EMPTY;
2765 qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2766 struct qeth_qdio_out_buffer *buf)
2769 struct sk_buff *skb;
2771 /* is PCI flag set on buffer? */
2772 if (buf->buffer->element[0].flags & 0x40)
2773 atomic_dec(&queue->set_pci_flags_count);
2775 while ((skb = skb_dequeue(&buf->skb_list))){
2776 atomic_dec(&skb->users);
2777 dev_kfree_skb_any(skb);
2779 qeth_eddp_buf_release_contexts(buf);
2780 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2781 buf->buffer->element[i].length = 0;
2782 buf->buffer->element[i].addr = NULL;
2783 buf->buffer->element[i].flags = 0;
2785 buf->next_element_to_fill = 0;
2786 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2790 qeth_queue_input_buffer(struct qeth_card *card, int index)
2792 struct qeth_qdio_q *queue = card->qdio.in_q;
2798 QETH_DBF_TEXT(trace,6,"queinbuf");
2799 count = (index < queue->next_buf_to_init)?
2800 card->qdio.in_buf_pool.buf_count -
2801 (queue->next_buf_to_init - index) :
2802 card->qdio.in_buf_pool.buf_count -
2803 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2804 /* only requeue at a certain threshold to avoid SIGAs */
2805 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2806 for (i = queue->next_buf_to_init;
2807 i < queue->next_buf_to_init + count; ++i) {
2808 if (qeth_init_input_buffer(card,
2809 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q])) {
2816 if (newcount < count) {
2817 /* we are in memory shortage so we switch back to
2818 traditional skb allocation and drop packages */
2819 if (!atomic_read(&card->force_alloc_skb) &&
2821 PRINT_WARN("Switch to alloc skb\n");
2822 atomic_set(&card->force_alloc_skb, 3);
2825 if ((atomic_read(&card->force_alloc_skb) == 1) &&
2827 PRINT_WARN("Switch to sg\n");
2828 atomic_add_unless(&card->force_alloc_skb, -1, 0);
2832 * according to old code it should be avoided to requeue all
2833 * 128 buffers in order to benefit from PCI avoidance.
2834 * this function keeps at least one buffer (the buffer at
2835 * 'index') un-requeued -> this buffer is the first buffer that
2836 * will be requeued the next time
2838 if (card->options.performance_stats) {
2839 card->perf_stats.inbound_do_qdio_cnt++;
2840 card->perf_stats.inbound_do_qdio_start_time =
2843 rc = do_QDIO(CARD_DDEV(card),
2844 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2845 0, queue->next_buf_to_init, count, NULL);
2846 if (card->options.performance_stats)
2847 card->perf_stats.inbound_do_qdio_time +=
2849 card->perf_stats.inbound_do_qdio_start_time;
2851 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2852 "return %i (device %s).\n",
2853 rc, CARD_DDEV_ID(card));
2854 QETH_DBF_TEXT(trace,2,"qinberr");
2855 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2857 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2858 QDIO_MAX_BUFFERS_PER_Q;
2863 qeth_put_buffer_pool_entry(struct qeth_card *card,
2864 struct qeth_buffer_pool_entry *entry)
2866 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2867 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2871 qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2872 unsigned int qdio_err, unsigned int siga_err,
2873 unsigned int queue, int first_element, int count,
2874 unsigned long card_ptr)
2876 struct net_device *net_dev;
2877 struct qeth_card *card;
2878 struct qeth_qdio_buffer *buffer;
2882 QETH_DBF_TEXT(trace, 6, "qdinput");
2883 card = (struct qeth_card *) card_ptr;
2884 net_dev = card->dev;
2885 if (card->options.performance_stats) {
2886 card->perf_stats.inbound_cnt++;
2887 card->perf_stats.inbound_start_time = qeth_get_micros();
2889 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2890 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2891 QETH_DBF_TEXT(trace, 1,"qdinchk");
2892 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2893 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2894 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2895 qeth_schedule_recovery(card);
2899 for (i = first_element; i < (first_element + count); ++i) {
2900 index = i % QDIO_MAX_BUFFERS_PER_Q;
2901 buffer = &card->qdio.in_q->bufs[index];
2902 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
2903 qeth_check_qdio_errors(buffer->buffer,
2904 qdio_err, siga_err,"qinerr")))
2905 qeth_process_inbound_buffer(card, buffer, index);
2906 /* clear buffer and give back to hardware */
2907 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2908 qeth_queue_input_buffer(card, index);
2910 if (card->options.performance_stats)
2911 card->perf_stats.inbound_time += qeth_get_micros() -
2912 card->perf_stats.inbound_start_time;
2916 qeth_handle_send_error(struct qeth_card *card,
2917 struct qeth_qdio_out_buffer *buffer,
2918 unsigned int qdio_err, unsigned int siga_err)
2920 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2921 int cc = siga_err & 3;
2923 QETH_DBF_TEXT(trace, 6, "hdsnderr");
2924 qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr");
2928 QETH_DBF_TEXT(trace, 1,"lnkfail");
2929 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2930 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2931 (u16)qdio_err, (u8)sbalf15);
2932 return QETH_SEND_ERROR_LINK_FAILURE;
2934 return QETH_SEND_ERROR_NONE;
2936 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2937 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2938 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2939 return QETH_SEND_ERROR_KICK_IT;
2941 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2942 return QETH_SEND_ERROR_RETRY;
2943 return QETH_SEND_ERROR_LINK_FAILURE;
2944 /* look at qdio_error and sbalf 15 */
2946 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2947 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2948 return QETH_SEND_ERROR_LINK_FAILURE;
2951 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2952 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2953 return QETH_SEND_ERROR_KICK_IT;
2958 qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2959 int index, int count)
2961 struct qeth_qdio_out_buffer *buf;
2964 unsigned int qdio_flags;
2966 QETH_DBF_TEXT(trace, 6, "flushbuf");
2968 for (i = index; i < index + count; ++i) {
2969 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2970 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2971 SBAL_FLAGS_LAST_ENTRY;
2973 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2976 if (!queue->do_pack){
2977 if ((atomic_read(&queue->used_buffers) >=
2978 (QETH_HIGH_WATERMARK_PACK -
2979 QETH_WATERMARK_PACK_FUZZ)) &&
2980 !atomic_read(&queue->set_pci_flags_count)){
2981 /* it's likely that we'll go to packing
2983 atomic_inc(&queue->set_pci_flags_count);
2984 buf->buffer->element[0].flags |= 0x40;
2987 if (!atomic_read(&queue->set_pci_flags_count)){
2989 * there's no outstanding PCI any more, so we
2990 * have to request a PCI to be sure that the PCI
2991 * will wake at some time in the future then we
2992 * can flush packed buffers that might still be
2993 * hanging around, which can happen if no
2994 * further send was requested by the stack
2996 atomic_inc(&queue->set_pci_flags_count);
2997 buf->buffer->element[0].flags |= 0x40;
3002 queue->card->dev->trans_start = jiffies;
3003 if (queue->card->options.performance_stats) {
3004 queue->card->perf_stats.outbound_do_qdio_cnt++;
3005 queue->card->perf_stats.outbound_do_qdio_start_time =
3008 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
3010 qdio_flags |= QDIO_FLAG_UNDER_INTERRUPT;
3011 if (atomic_read(&queue->set_pci_flags_count))
3012 qdio_flags |= QDIO_FLAG_PCI_OUT;
3013 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
3014 queue->queue_no, index, count, NULL);
3015 if (queue->card->options.performance_stats)
3016 queue->card->perf_stats.outbound_do_qdio_time +=
3018 queue->card->perf_stats.outbound_do_qdio_start_time;
3020 QETH_DBF_TEXT(trace, 2, "flushbuf");
3021 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
3022 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
3023 queue->card->stats.tx_errors += count;
3024 /* this must not happen under normal circumstances. if it
3025 * happens something is really wrong -> recover */
3026 qeth_schedule_recovery(queue->card);
3029 atomic_add(count, &queue->used_buffers);
3030 if (queue->card->options.performance_stats)
3031 queue->card->perf_stats.bufs_sent += count;
3035 * Switched to packing state if the number of used buffers on a queue
3036 * reaches a certain limit.
3039 qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
3041 if (!queue->do_pack) {
3042 if (atomic_read(&queue->used_buffers)
3043 >= QETH_HIGH_WATERMARK_PACK){
3044 /* switch non-PACKING -> PACKING */
3045 QETH_DBF_TEXT(trace, 6, "np->pack");
3046 if (queue->card->options.performance_stats)
3047 queue->card->perf_stats.sc_dp_p++;
3054 * Switches from packing to non-packing mode. If there is a packing
3055 * buffer on the queue this buffer will be prepared to be flushed.
3056 * In that case 1 is returned to inform the caller. If no buffer
3057 * has to be flushed, zero is returned.
3060 qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
3062 struct qeth_qdio_out_buffer *buffer;
3063 int flush_count = 0;
3065 if (queue->do_pack) {
3066 if (atomic_read(&queue->used_buffers)
3067 <= QETH_LOW_WATERMARK_PACK) {
3068 /* switch PACKING -> non-PACKING */
3069 QETH_DBF_TEXT(trace, 6, "pack->np");
3070 if (queue->card->options.performance_stats)
3071 queue->card->perf_stats.sc_p_dp++;
3073 /* flush packing buffers */
3074 buffer = &queue->bufs[queue->next_buf_to_fill];
3075 if ((atomic_read(&buffer->state) ==
3076 QETH_QDIO_BUF_EMPTY) &&
3077 (buffer->next_element_to_fill > 0)) {
3078 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
3080 queue->next_buf_to_fill =
3081 (queue->next_buf_to_fill + 1) %
3082 QDIO_MAX_BUFFERS_PER_Q;
3090 * Called to flush a packing buffer if no more pci flags are on the queue.
3091 * Checks if there is a packing buffer and prepares it to be flushed.
3092 * In that case returns 1, otherwise zero.
3095 qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
3097 struct qeth_qdio_out_buffer *buffer;
3099 buffer = &queue->bufs[queue->next_buf_to_fill];
3100 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
3101 (buffer->next_element_to_fill > 0)){
3102 /* it's a packing buffer */
3103 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
3104 queue->next_buf_to_fill =
3105 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
3112 qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
3116 int q_was_packing = 0;
3119 * check if weed have to switch to non-packing mode or if
3120 * we have to get a pci flag out on the queue
3122 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
3123 !atomic_read(&queue->set_pci_flags_count)){
3124 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
3125 QETH_OUT_Q_UNLOCKED) {
3127 * If we get in here, there was no action in
3128 * do_send_packet. So, we check if there is a
3129 * packing buffer to be flushed here.
3131 netif_stop_queue(queue->card->dev);
3132 index = queue->next_buf_to_fill;
3133 q_was_packing = queue->do_pack;
3134 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
3136 !atomic_read(&queue->set_pci_flags_count))
3138 qeth_flush_buffers_on_no_pci(queue);
3139 if (queue->card->options.performance_stats &&
3141 queue->card->perf_stats.bufs_sent_pack +=
3144 qeth_flush_buffers(queue, 1, index, flush_cnt);
3145 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3151 qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3152 unsigned int qdio_error, unsigned int siga_error,
3153 unsigned int __queue, int first_element, int count,
3154 unsigned long card_ptr)
3156 struct qeth_card *card = (struct qeth_card *) card_ptr;
3157 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3158 struct qeth_qdio_out_buffer *buffer;
3161 QETH_DBF_TEXT(trace, 6, "qdouhdl");
3162 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
3163 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
3164 QETH_DBF_TEXT(trace, 2, "achkcond");
3165 QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
3166 QETH_DBF_TEXT_(trace, 2, "%08x", status);
3167 netif_stop_queue(card->dev);
3168 qeth_schedule_recovery(card);
3172 if (card->options.performance_stats) {
3173 card->perf_stats.outbound_handler_cnt++;
3174 card->perf_stats.outbound_handler_start_time =
3177 for(i = first_element; i < (first_element + count); ++i){
3178 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
3179 /*we only handle the KICK_IT error by doing a recovery */
3180 if (qeth_handle_send_error(card, buffer,
3181 qdio_error, siga_error)
3182 == QETH_SEND_ERROR_KICK_IT){
3183 netif_stop_queue(card->dev);
3184 qeth_schedule_recovery(card);
3187 qeth_clear_output_buffer(queue, buffer);
3189 atomic_sub(count, &queue->used_buffers);
3190 /* check if we need to do something on this outbound queue */
3191 if (card->info.type != QETH_CARD_TYPE_IQD)
3192 qeth_check_outbound_queue(queue);
3194 netif_wake_queue(queue->card->dev);
3195 if (card->options.performance_stats)
3196 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3197 card->perf_stats.outbound_handler_start_time;
3201 qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
3204 param_field[0] = _ascebc['P'];
3205 param_field[1] = _ascebc['C'];
3206 param_field[2] = _ascebc['I'];
3207 param_field[3] = _ascebc['T'];
3208 *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card);
3209 *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card);
3210 *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card);
3214 qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
3216 param_field[16] = _ascebc['B'];
3217 param_field[17] = _ascebc['L'];
3218 param_field[18] = _ascebc['K'];
3219 param_field[19] = _ascebc['T'];
3220 *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total;
3221 *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet;
3222 *((unsigned int *) (¶m_field[28])) = card->info.blkt.inter_packet_jumbo;
3226 qeth_initialize_working_pool_list(struct qeth_card *card)
3228 struct qeth_buffer_pool_entry *entry;
3230 QETH_DBF_TEXT(trace,5,"inwrklst");
3232 list_for_each_entry(entry,
3233 &card->qdio.init_pool.entry_list, init_list) {
3234 qeth_put_buffer_pool_entry(card,entry);
3239 qeth_clear_working_pool_list(struct qeth_card *card)
3241 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3243 QETH_DBF_TEXT(trace,5,"clwrklst");
3244 list_for_each_entry_safe(pool_entry, tmp,
3245 &card->qdio.in_buf_pool.entry_list, list){
3246 list_del(&pool_entry->list);
3251 qeth_free_buffer_pool(struct qeth_card *card)
3253 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3255 QETH_DBF_TEXT(trace,5,"freepool");
3256 list_for_each_entry_safe(pool_entry, tmp,
3257 &card->qdio.init_pool.entry_list, init_list){
3258 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3259 free_page((unsigned long)pool_entry->elements[i]);
3260 list_del(&pool_entry->init_list);
3266 qeth_alloc_buffer_pool(struct qeth_card *card)
3268 struct qeth_buffer_pool_entry *pool_entry;
3272 QETH_DBF_TEXT(trace,5,"alocpool");
3273 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3274 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3276 qeth_free_buffer_pool(card);
3279 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
3280 ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
3283 free_page((unsigned long)
3284 pool_entry->elements[--j]);
3286 qeth_free_buffer_pool(card);
3289 pool_entry->elements[j] = ptr;
3291 list_add(&pool_entry->init_list,
3292 &card->qdio.init_pool.entry_list);
3298 qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3300 QETH_DBF_TEXT(trace, 2, "realcbp");
3302 if ((card->state != CARD_STATE_DOWN) &&
3303 (card->state != CARD_STATE_RECOVER))
3306 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3307 qeth_clear_working_pool_list(card);
3308 qeth_free_buffer_pool(card);
3309 card->qdio.in_buf_pool.buf_count = bufcnt;
3310 card->qdio.init_pool.buf_count = bufcnt;
3311 return qeth_alloc_buffer_pool(card);
3315 qeth_alloc_qdio_buffers(struct qeth_card *card)
3319 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3321 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
3322 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
3325 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3326 GFP_KERNEL|GFP_DMA);
3327 if (!card->qdio.in_q)
3329 QETH_DBF_TEXT(setup, 2, "inq");
3330 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3331 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3332 /* give inbound qeth_qdio_buffers their qdio_buffers */
3333 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3334 card->qdio.in_q->bufs[i].buffer =
3335 &card->qdio.in_q->qdio_bufs[i];
3336 /* inbound buffer pool */
3337 if (qeth_alloc_buffer_pool(card))
3341 kmalloc(card->qdio.no_out_queues *
3342 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3343 if (!card->qdio.out_qs)
3345 for (i = 0; i < card->qdio.no_out_queues; ++i) {
3346 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3347 GFP_KERNEL|GFP_DMA);
3348 if (!card->qdio.out_qs[i])
3350 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3351 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3352 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3353 card->qdio.out_qs[i]->queue_no = i;
3354 /* give outbound qeth_qdio_buffers their qdio_buffers */
3355 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3356 card->qdio.out_qs[i]->bufs[j].buffer =
3357 &card->qdio.out_qs[i]->qdio_bufs[j];
3358 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3361 &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
3362 &qdio_out_skb_queue_key);
3363 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3370 kfree(card->qdio.out_qs[--i]);
3371 kfree(card->qdio.out_qs);
3372 card->qdio.out_qs = NULL;
3374 qeth_free_buffer_pool(card);
3376 kfree(card->qdio.in_q);
3377 card->qdio.in_q = NULL;
3379 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3384 qeth_free_qdio_buffers(struct qeth_card *card)
3388 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3389 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
3390 QETH_QDIO_UNINITIALIZED)
3392 kfree(card->qdio.in_q);
3393 card->qdio.in_q = NULL;
3394 /* inbound buffer pool */
3395 qeth_free_buffer_pool(card);
3396 /* free outbound qdio_qs */
3397 if (card->qdio.out_qs) {
3398 for (i = 0; i < card->qdio.no_out_queues; ++i) {
3399 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3400 qeth_clear_output_buffer(card->qdio.out_qs[i],
3401 &card->qdio.out_qs[i]->bufs[j]);
3402 kfree(card->qdio.out_qs[i]);
3404 kfree(card->qdio.out_qs);
3405 card->qdio.out_qs = NULL;
3410 qeth_clear_qdio_buffers(struct qeth_card *card)
3414 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3415 /* clear outbound buffers to free skbs */
3416 for (i = 0; i < card->qdio.no_out_queues; ++i)
3417 if (card->qdio.out_qs && card->qdio.out_qs[i]) {
3418 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3419 qeth_clear_output_buffer(card->qdio.out_qs[i],
3420 &card->qdio.out_qs[i]->bufs[j]);
3425 qeth_init_qdio_info(struct qeth_card *card)
3427 QETH_DBF_TEXT(setup, 4, "intqdinf");
3428 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3430 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3431 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3432 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3433 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3434 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3438 qeth_init_qdio_queues(struct qeth_card *card)
3443 QETH_DBF_TEXT(setup, 2, "initqdqs");
3446 memset(card->qdio.in_q->qdio_bufs, 0,
3447 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3448 qeth_initialize_working_pool_list(card);
3449 /*give only as many buffers to hardware as we have buffer pool entries*/
3450 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3451 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3452 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3453 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3454 card->qdio.in_buf_pool.buf_count - 1, NULL);
3456 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3459 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3461 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3464 /* outbound queue */
3465 for (i = 0; i < card->qdio.no_out_queues; ++i){
3466 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3467 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3468 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3469 qeth_clear_output_buffer(card->qdio.out_qs[i],
3470 &card->qdio.out_qs[i]->bufs[j]);
3472 card->qdio.out_qs[i]->card = card;
3473 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3474 card->qdio.out_qs[i]->do_pack = 0;
3475 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3476 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3477 atomic_set(&card->qdio.out_qs[i]->state,
3478 QETH_OUT_Q_UNLOCKED);
3484 qeth_qdio_establish(struct qeth_card *card)
3486 struct qdio_initialize init_data;
3487 char *qib_param_field;
3488 struct qdio_buffer **in_sbal_ptrs;
3489 struct qdio_buffer **out_sbal_ptrs;
3493 QETH_DBF_TEXT(setup, 2, "qdioest");
3495 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3497 if (!qib_param_field)
3500 qeth_create_qib_param_field(card, qib_param_field);
3501 qeth_create_qib_param_field_blkt(card, qib_param_field);
3503 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3505 if (!in_sbal_ptrs) {
3506 kfree(qib_param_field);
3509 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3510 in_sbal_ptrs[i] = (struct qdio_buffer *)
3511 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3514 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3515 sizeof(void *), GFP_KERNEL);
3516 if (!out_sbal_ptrs) {
3517 kfree(in_sbal_ptrs);
3518 kfree(qib_param_field);
3521 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3522 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3523 out_sbal_ptrs[k] = (struct qdio_buffer *)
3524 virt_to_phys(card->qdio.out_qs[i]->
3528 memset(&init_data, 0, sizeof(struct qdio_initialize));
3529 init_data.cdev = CARD_DDEV(card);
3530 init_data.q_format = qeth_get_qdio_q_format(card);
3531 init_data.qib_param_field_format = 0;
3532 init_data.qib_param_field = qib_param_field;
3533 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3534 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3535 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3536 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3537 init_data.no_input_qs = 1;
3538 init_data.no_output_qs = card->qdio.no_out_queues;
3539 init_data.input_handler = (qdio_handler_t *)
3540 qeth_qdio_input_handler;
3541 init_data.output_handler = (qdio_handler_t *)
3542 qeth_qdio_output_handler;
3543 init_data.int_parm = (unsigned long) card;
3544 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3545 QDIO_OUTBOUND_0COPY_SBALS |
3546 QDIO_USE_OUTBOUND_PCIS;
3547 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3548 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3550 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3551 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED)
3552 if ((rc = qdio_initialize(&init_data)))
3553 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3555 kfree(out_sbal_ptrs);
3556 kfree(in_sbal_ptrs);
3557 kfree(qib_param_field);
3562 qeth_qdio_activate(struct qeth_card *card)
3564 QETH_DBF_TEXT(setup,3,"qdioact");
3565 return qdio_activate(CARD_DDEV(card), 0);
3569 qeth_clear_channel(struct qeth_channel *channel)
3571 unsigned long flags;
3572 struct qeth_card *card;
3575 QETH_DBF_TEXT(trace,3,"clearch");
3576 card = CARD_FROM_CDEV(channel->ccwdev);
3577 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3578 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3579 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3583 rc = wait_event_interruptible_timeout(card->wait_q,
3584 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3585 if (rc == -ERESTARTSYS)
3587 if (channel->state != CH_STATE_STOPPED)
3589 channel->state = CH_STATE_DOWN;
3594 qeth_halt_channel(struct qeth_channel *channel)
3596 unsigned long flags;
3597 struct qeth_card *card;
3600 QETH_DBF_TEXT(trace,3,"haltch");
3601 card = CARD_FROM_CDEV(channel->ccwdev);
3602 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3603 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3604 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3608 rc = wait_event_interruptible_timeout(card->wait_q,
3609 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3610 if (rc == -ERESTARTSYS)
3612 if (channel->state != CH_STATE_HALTED)
3618 qeth_halt_channels(struct qeth_card *card)
3620 int rc1 = 0, rc2=0, rc3 = 0;
3622 QETH_DBF_TEXT(trace,3,"haltchs");
3623 rc1 = qeth_halt_channel(&card->read);
3624 rc2 = qeth_halt_channel(&card->write);
3625 rc3 = qeth_halt_channel(&card->data);
3633 qeth_clear_channels(struct qeth_card *card)
3635 int rc1 = 0, rc2=0, rc3 = 0;
3637 QETH_DBF_TEXT(trace,3,"clearchs");
3638 rc1 = qeth_clear_channel(&card->read);
3639 rc2 = qeth_clear_channel(&card->write);
3640 rc3 = qeth_clear_channel(&card->data);
3649 qeth_clear_halt_card(struct qeth_card *card, int halt)
3653 QETH_DBF_TEXT(trace,3,"clhacrd");
3654 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3657 rc = qeth_halt_channels(card);
3660 return qeth_clear_channels(card);
3664 qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3668 QETH_DBF_TEXT(trace,3,"qdioclr");
3669 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
3670 QETH_QDIO_CLEANING)) {
3671 case QETH_QDIO_ESTABLISHED:
3672 if ((rc = qdio_cleanup(CARD_DDEV(card),
3673 (card->info.type == QETH_CARD_TYPE_IQD) ?
3674 QDIO_FLAG_CLEANUP_USING_HALT :
3675 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3676 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3677 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3679 case QETH_QDIO_CLEANING:
3684 if ((rc = qeth_clear_halt_card(card, use_halt)))
3685 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3686 card->state = CARD_STATE_DOWN;
3691 qeth_dm_act(struct qeth_card *card)
3694 struct qeth_cmd_buffer *iob;
3696 QETH_DBF_TEXT(setup,2,"dmact");
3698 iob = qeth_wait_for_buffer(&card->write);
3699 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3701 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3702 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3703 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3704 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3705 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3710 qeth_mpc_initialize(struct qeth_card *card)
3714 QETH_DBF_TEXT(setup,2,"mpcinit");
3716 if ((rc = qeth_issue_next_read(card))){
3717 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3720 if ((rc = qeth_cm_enable(card))){
3721 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3724 if ((rc = qeth_cm_setup(card))){
3725 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3728 if ((rc = qeth_ulp_enable(card))){
3729 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3732 if ((rc = qeth_ulp_setup(card))){
3733 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3736 if ((rc = qeth_alloc_qdio_buffers(card))){
3737 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3740 if ((rc = qeth_qdio_establish(card))){
3741 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3742 qeth_free_qdio_buffers(card);
3745 if ((rc = qeth_qdio_activate(card))){
3746 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3749 if ((rc = qeth_dm_act(card))){
3750 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3756 qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
3760 static struct net_device *
3761 qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3763 struct net_device *dev = NULL;
3766 case QETH_CARD_TYPE_OSAE:
3768 case QETH_LINK_TYPE_LANE_TR:
3769 case QETH_LINK_TYPE_HSTR:
3771 dev = alloc_trdev(0);
3772 #endif /* CONFIG_TR */
3775 dev = alloc_etherdev(0);
3778 case QETH_CARD_TYPE_IQD:
3779 dev = alloc_netdev(0, "hsi%d", ether_setup);
3781 case QETH_CARD_TYPE_OSN:
3782 dev = alloc_netdev(0, "osn%d", ether_setup);
3785 dev = alloc_etherdev(0);
3790 /*hard_header fake function; used in case fake_ll is set */
3792 qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3793 unsigned short type, const void *daddr, const void *saddr,
3796 if(dev->type == ARPHRD_IEEE802_TR){
3797 struct trh_hdr *hdr;
3798 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3799 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3800 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3801 return QETH_FAKE_LL_LEN_TR;
3805 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3806 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3807 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3808 if (type != ETH_P_802_3)
3809 hdr->h_proto = htons(type);
3811 hdr->h_proto = htons(len);
3812 return QETH_FAKE_LL_LEN_ETH;
3817 static const struct header_ops qeth_fake_ops = {
3818 .create = qeth_fake_header,
3819 .parse = qeth_hard_header_parse,
3823 qeth_send_packet(struct qeth_card *, struct sk_buff *);
3826 qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3829 struct qeth_card *card;
3831 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3832 card = (struct qeth_card *)dev->priv;
3834 card->stats.tx_dropped++;
3835 card->stats.tx_errors++;
3836 /* return OK; otherwise ksoftirqd goes to 100% */
3837 return NETDEV_TX_OK;
3839 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3840 card->stats.tx_dropped++;
3841 card->stats.tx_errors++;
3842 card->stats.tx_carrier_errors++;
3843 dev_kfree_skb_any(skb);
3844 /* return OK; otherwise ksoftirqd goes to 100% */
3845 return NETDEV_TX_OK;
3847 if (card->options.performance_stats) {
3848 card->perf_stats.outbound_cnt++;
3849 card->perf_stats.outbound_start_time = qeth_get_micros();
3851 netif_stop_queue(dev);
3852 if ((rc = qeth_send_packet(card, skb))) {
3854 return NETDEV_TX_BUSY;
3856 card->stats.tx_errors++;
3857 card->stats.tx_dropped++;
3858 dev_kfree_skb_any(skb);
3859 /*set to OK; otherwise ksoftirqd goes to 100% */
3863 netif_wake_queue(dev);
3864 if (card->options.performance_stats)
3865 card->perf_stats.outbound_time += qeth_get_micros() -
3866 card->perf_stats.outbound_start_time;
3871 qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3874 #ifdef CONFIG_QETH_VLAN
3875 struct vlan_group *vg;
3878 if (!(vg = card->vlangrp))
3881 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3882 if (vlan_group_get_device(vg, i) == dev){
3883 rc = QETH_VLAN_CARD;
3887 if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card))
3895 qeth_verify_dev(struct net_device *dev)
3897 struct qeth_card *card;
3898 unsigned long flags;
3901 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3902 list_for_each_entry(card, &qeth_card_list.list, list){
3903 if (card->dev == dev){
3904 rc = QETH_REAL_CARD;
3907 rc = qeth_verify_vlan_dev(dev, card);
3911 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3916 static struct qeth_card *
3917 qeth_get_card_from_dev(struct net_device *dev)
3919 struct qeth_card *card = NULL;
3922 rc = qeth_verify_dev(dev);
3923 if (rc == QETH_REAL_CARD)
3924 card = (struct qeth_card *)dev->priv;
3925 else if (rc == QETH_VLAN_CARD)
3926 card = (struct qeth_card *)
3927 VLAN_DEV_INFO(dev)->real_dev->priv;
3929 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3934 qeth_tx_timeout(struct net_device *dev)
3936 struct qeth_card *card;
3938 card = (struct qeth_card *) dev->priv;
3939 card->stats.tx_errors++;
3940 qeth_schedule_recovery(card);
3944 qeth_open(struct net_device *dev)
3946 struct qeth_card *card;
3948 QETH_DBF_TEXT(trace, 4, "qethopen");
3950 card = (struct qeth_card *) dev->priv;
3952 if (card->state != CARD_STATE_SOFTSETUP)
3955 if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3956 (card->options.layer2) &&
3957 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
3958 QETH_DBF_TEXT(trace,4,"nomacadr");
3961 card->data.state = CH_STATE_UP;
3962 card->state = CARD_STATE_UP;
3963 card->dev->flags |= IFF_UP;
3964 netif_start_queue(dev);
3966 if (!card->lan_online && netif_carrier_ok(dev))
3967 netif_carrier_off(dev);
3972 qeth_stop(struct net_device *dev)
3974 struct qeth_card *card;
3976 QETH_DBF_TEXT(trace, 4, "qethstop");
3978 card = (struct qeth_card *) dev->priv;
3980 netif_tx_disable(dev);
3981 card->dev->flags &= ~IFF_UP;
3982 if (card->state == CARD_STATE_UP)
3983 card->state = CARD_STATE_SOFTSETUP;
3988 qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3990 int cast_type = RTN_UNSPEC;
3992 if (card->info.type == QETH_CARD_TYPE_OSN)
3995 if (skb->dst && skb->dst->neighbour){
3996 cast_type = skb->dst->neighbour->type;
3997 if ((cast_type == RTN_BROADCAST) ||
3998 (cast_type == RTN_MULTICAST) ||
3999 (cast_type == RTN_ANYCAST))
4004 /* try something else */
4005 if (skb->protocol == ETH_P_IPV6)
4006 return (skb_network_header(skb)[24] == 0xff) ?
4008 else if (skb->protocol == ETH_P_IP)
4009 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
4012 if (!memcmp(skb->data, skb->dev->broadcast, 6))
4013 return RTN_BROADCAST;
4017 hdr_mac = *((u16 *)skb->data);
4019 switch (card->info.link_type) {
4020 case QETH_LINK_TYPE_HSTR:
4021 case QETH_LINK_TYPE_LANE_TR:
4022 if ((hdr_mac == QETH_TR_MAC_NC) ||
4023 (hdr_mac == QETH_TR_MAC_C))
4024 return RTN_MULTICAST;
4026 /* eth or so multicast? */
4028 if ((hdr_mac == QETH_ETH_MAC_V4) ||
4029 (hdr_mac == QETH_ETH_MAC_V6))
4030 return RTN_MULTICAST;
4037 qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
4038 int ipv, int cast_type)
4040 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
4041 return card->qdio.default_out_queue;
4042 switch (card->qdio.no_out_queues) {
4044 if (cast_type && card->info.is_multicast_different)
4045 return card->info.is_multicast_different &
4046 (card->qdio.no_out_queues - 1);
4047 if (card->qdio.do_prio_queueing && (ipv == 4)) {
4048 const u8 tos = ip_hdr(skb)->tos;
4050 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
4051 if (tos & IP_TOS_NOTIMPORTANT)
4053 if (tos & IP_TOS_HIGHRELIABILITY)
4055 if (tos & IP_TOS_HIGHTHROUGHPUT)
4057 if (tos & IP_TOS_LOWDELAY)
4060 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
4061 return 3 - (tos >> 6);
4062 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
4065 return card->qdio.default_out_queue;
4066 case 1: /* fallthrough for single-out-queue 1920-device */
4068 return card->qdio.default_out_queue;
4073 qeth_get_ip_version(struct sk_buff *skb)
4075 switch (skb->protocol) {
4085 static struct qeth_hdr *
4086 __qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, int ipv)
4088 #ifdef CONFIG_QETH_VLAN
4090 if (card->vlangrp && vlan_tx_tag_present(skb) &&
4091 ((ipv == 6) || card->options.layer2) ) {
4093 * Move the mac addresses (6 bytes src, 6 bytes dest)
4094 * to the beginning of the new header. We are using three
4095 * memcpys instead of one memmove to save cycles.
4097 skb_push(skb, VLAN_HLEN);
4098 skb_copy_to_linear_data(skb, skb->data + 4, 4);
4099 skb_copy_to_linear_data_offset(skb, 4, skb->data + 8, 4);
4100 skb_copy_to_linear_data_offset(skb, 8, skb->data + 12, 4);
4101 tag = (u16 *)(skb->data + 12);
4103 * first two bytes = ETH_P_8021Q (0x8100)
4104 * second two bytes = VLANID
4106 *tag = __constant_htons(ETH_P_8021Q);
4107 *(tag + 1) = htons(vlan_tx_tag_get(skb));
4110 return ((struct qeth_hdr *)
4111 qeth_push_skb(card, skb, sizeof(struct qeth_hdr)));
4115 __qeth_free_new_skb(struct sk_buff *orig_skb, struct sk_buff *new_skb)
4117 if (orig_skb != new_skb)
4118 dev_kfree_skb_any(new_skb);
4121 static struct sk_buff *
4122 qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb,
4123 struct qeth_hdr **hdr, int ipv)
4125 struct sk_buff *new_skb, *new_skb2;
4127 QETH_DBF_TEXT(trace, 6, "prepskb");
4129 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
4132 new_skb2 = qeth_realloc_headroom(card, new_skb,
4133 sizeof(struct qeth_hdr));
4135 __qeth_free_new_skb(skb, new_skb);
4139 __qeth_free_new_skb(new_skb2, new_skb);
4141 *hdr = __qeth_prepare_skb(card, new_skb, ipv);
4143 __qeth_free_new_skb(skb, new_skb);
4150 qeth_get_qeth_hdr_flags4(int cast_type)
4152 if (cast_type == RTN_MULTICAST)
4153 return QETH_CAST_MULTICAST;
4154 if (cast_type == RTN_BROADCAST)
4155 return QETH_CAST_BROADCAST;
4156 return QETH_CAST_UNICAST;
4160 qeth_get_qeth_hdr_flags6(int cast_type)
4162 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
4163 if (cast_type == RTN_MULTICAST)
4164 return ct | QETH_CAST_MULTICAST;
4165 if (cast_type == RTN_ANYCAST)
4166 return ct | QETH_CAST_ANYCAST;
4167 if (cast_type == RTN_BROADCAST)
4168 return ct | QETH_CAST_BROADCAST;
4169 return ct | QETH_CAST_UNICAST;
4173 qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
4174 struct sk_buff *skb)
4178 if (!memcmp(skb->data+QETH_HEADER_SIZE,
4179 skb->dev->broadcast,6)) { /* broadcast? */
4180 *(__u32 *)hdr->hdr.l2.flags |=
4181 QETH_LAYER2_FLAG_BROADCAST << 8;
4184 hdr_mac=*((__u16*)skb->data);
4186 switch (card->info.link_type) {
4187 case QETH_LINK_TYPE_HSTR:
4188 case QETH_LINK_TYPE_LANE_TR:
4189 if ((hdr_mac == QETH_TR_MAC_NC) ||
4190 (hdr_mac == QETH_TR_MAC_C) )
4191 *(__u32 *)hdr->hdr.l2.flags |=
4192 QETH_LAYER2_FLAG_MULTICAST << 8;
4194 *(__u32 *)hdr->hdr.l2.flags |=
4195 QETH_LAYER2_FLAG_UNICAST << 8;
4197 /* eth or so multicast? */
4199 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
4200 (hdr_mac==QETH_ETH_MAC_V6) )
4201 *(__u32 *)hdr->hdr.l2.flags |=
4202 QETH_LAYER2_FLAG_MULTICAST << 8;
4204 *(__u32 *)hdr->hdr.l2.flags |=
4205 QETH_LAYER2_FLAG_UNICAST << 8;
4210 qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4211 struct sk_buff *skb, int cast_type)
4213 memset(hdr, 0, sizeof(struct qeth_hdr));
4214 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
4216 /* set byte 0 to "0x02" and byte 3 to casting flags */
4217 if (cast_type==RTN_MULTICAST)
4218 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
4219 else if (cast_type==RTN_BROADCAST)
4220 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
4222 qeth_layer2_get_packet_type(card, hdr, skb);
4224 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
4225 #ifdef CONFIG_QETH_VLAN
4226 /* VSWITCH relies on the VLAN
4227 * information to be present in
4228 * the QDIO header */
4229 if ((card->vlangrp != NULL) &&
4230 vlan_tx_tag_present(skb)) {
4231 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
4232 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
4238 qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4239 struct sk_buff *skb, int ipv, int cast_type)
4241 QETH_DBF_TEXT(trace, 6, "fillhdr");
4243 memset(hdr, 0, sizeof(struct qeth_hdr));
4244 if (card->options.layer2) {
4245 qeth_layer2_fill_header(card, hdr, skb, cast_type);
4248 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
4249 hdr->hdr.l3.ext_flags = 0;
4250 #ifdef CONFIG_QETH_VLAN
4252 * before we're going to overwrite this location with next hop ip.
4253 * v6 uses passthrough, v4 sets the tag in the QDIO header.
4255 if (card->vlangrp && vlan_tx_tag_present(skb)) {
4256 hdr->hdr.l3.ext_flags = (ipv == 4) ?
4257 QETH_HDR_EXT_VLAN_FRAME :
4258 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
4259 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
4261 #endif /* CONFIG_QETH_VLAN */
4262 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
4263 if (ipv == 4) { /* IPv4 */
4264 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
4265 memset(hdr->hdr.l3.dest_addr, 0, 12);
4266 if ((skb->dst) && (skb->dst->neighbour)) {
4267 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
4268 *((u32 *) skb->dst->neighbour->primary_key);
4270 /* fill in destination address used in ip header */
4271 *((u32 *)(&hdr->hdr.l3.dest_addr[12])) =
4274 } else if (ipv == 6) { /* IPv6 or passthru */
4275 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
4276 if ((skb->dst) && (skb->dst->neighbour)) {
4277 memcpy(hdr->hdr.l3.dest_addr,
4278 skb->dst->neighbour->primary_key, 16);
4280 /* fill in destination address used in ip header */
4281 memcpy(hdr->hdr.l3.dest_addr,
4282 &ipv6_hdr(skb)->daddr, 16);
4284 } else { /* passthrough */
4285 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
4286 !memcmp(skb->data + sizeof(struct qeth_hdr) +
4287 sizeof(__u16), skb->dev->broadcast, 6)) {
4288 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4290 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
4291 skb->dev->broadcast, 6)) { /* broadcast? */
4292 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4295 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
4296 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
4297 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
4303 __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
4304 int is_tso, int *next_element_to_fill)
4306 int length = skb->len;
4312 element = *next_element_to_fill;
4314 first_lap = (is_tso == 0 ? 1 : 0);
4316 while (length > 0) {
4317 /* length_here is the remaining amount of data in this page */
4318 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4319 if (length < length_here)
4320 length_here = length;
4322 buffer->element[element].addr = data;
4323 buffer->element[element].length = length_here;
4324 length -= length_here;
4327 buffer->element[element].flags = 0;
4329 buffer->element[element].flags =
4330 SBAL_FLAGS_LAST_FRAG;
4333 buffer->element[element].flags =
4334 SBAL_FLAGS_FIRST_FRAG;
4336 buffer->element[element].flags =
4337 SBAL_FLAGS_MIDDLE_FRAG;
4339 data += length_here;
4343 *next_element_to_fill = element;
4347 qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4348 struct qeth_qdio_out_buffer *buf,
4349 struct sk_buff *skb)
4351 struct qdio_buffer *buffer;
4352 struct qeth_hdr_tso *hdr;
4353 int flush_cnt = 0, hdr_len, large_send = 0;
4355 QETH_DBF_TEXT(trace, 6, "qdfillbf");
4357 buffer = buf->buffer;
4358 atomic_inc(&skb->users);
4359 skb_queue_tail(&buf->skb_list, skb);
4361 hdr = (struct qeth_hdr_tso *) skb->data;
4362 /*check first on TSO ....*/
4363 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4364 int element = buf->next_element_to_fill;
4366 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4367 /*fill first buffer entry only with header information */
4368 buffer->element[element].addr = skb->data;
4369 buffer->element[element].length = hdr_len;
4370 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4371 buf->next_element_to_fill++;
4372 skb->data += hdr_len;
4373 skb->len -= hdr_len;
4376 if (skb_shinfo(skb)->nr_frags == 0)
4377 __qeth_fill_buffer(skb, buffer, large_send,
4378 (int *)&buf->next_element_to_fill);
4380 __qeth_fill_buffer_frag(skb, buffer, large_send,
4381 (int *)&buf->next_element_to_fill);
4383 if (!queue->do_pack) {
4384 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4385 /* set state to PRIMED -> will be flushed */
4386 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4389 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4390 if (queue->card->options.performance_stats)
4391 queue->card->perf_stats.skbs_sent_pack++;
4392 if (buf->next_element_to_fill >=
4393 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4395 * packed buffer if full -> set state PRIMED
4396 * -> will be flushed
4398 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4406 qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4407 struct sk_buff *skb, struct qeth_hdr *hdr,
4408 int elements_needed,
4409 struct qeth_eddp_context *ctx)
4411 struct qeth_qdio_out_buffer *buffer;
4412 int buffers_needed = 0;
4416 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4418 /* spin until we get the queue ... */
4419 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4420 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4421 /* ... now we've got the queue */
4422 index = queue->next_buf_to_fill;
4423 buffer = &queue->bufs[queue->next_buf_to_fill];
4425 * check if buffer is empty to make sure that we do not 'overtake'
4426 * ourselves and try to fill a buffer that is already primed
4428 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4431 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4432 QDIO_MAX_BUFFERS_PER_Q;
4434 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4435 if (buffers_needed < 0)
4437 queue->next_buf_to_fill =
4438 (queue->next_buf_to_fill + buffers_needed) %
4439 QDIO_MAX_BUFFERS_PER_Q;
4441 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4443 qeth_fill_buffer(queue, buffer, skb);
4444 qeth_flush_buffers(queue, 0, index, 1);
4446 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4447 WARN_ON(buffers_needed != flush_cnt);
4448 qeth_flush_buffers(queue, 0, index, flush_cnt);
4452 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4457 qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4458 struct sk_buff *skb, struct qeth_hdr *hdr,
4459 int elements_needed, struct qeth_eddp_context *ctx)
4461 struct qeth_qdio_out_buffer *buffer;
4463 int flush_count = 0;
4468 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4470 /* spin until we get the queue ... */
4471 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4472 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4473 start_index = queue->next_buf_to_fill;
4474 buffer = &queue->bufs[queue->next_buf_to_fill];
4476 * check if buffer is empty to make sure that we do not 'overtake'
4477 * ourselves and try to fill a buffer that is already primed
4479 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4480 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4483 /* check if we need to switch packing state of this queue */
4484 qeth_switch_to_packing_if_needed(queue);
4485 if (queue->do_pack){
4488 /* does packet fit in current buffer? */
4489 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4490 buffer->next_element_to_fill) < elements_needed){
4491 /* ... no -> set state PRIMED */
4492 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4494 queue->next_buf_to_fill =
4495 (queue->next_buf_to_fill + 1) %
4496 QDIO_MAX_BUFFERS_PER_Q;
4497 buffer = &queue->bufs[queue->next_buf_to_fill];
4498 /* we did a step forward, so check buffer state
4500 if (atomic_read(&buffer->state) !=
4501 QETH_QDIO_BUF_EMPTY){
4502 qeth_flush_buffers(queue, 0, start_index, flush_count);
4503 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4508 /* check if we have enough elements (including following
4509 * free buffers) to handle eddp context */
4510 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4511 printk("eddp tx_dropped 1\n");
4518 tmp = qeth_fill_buffer(queue, buffer, skb);
4520 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4522 printk("eddp tx_dropped 2\n");
4527 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4528 QDIO_MAX_BUFFERS_PER_Q;
4532 qeth_flush_buffers(queue, 0, start_index, flush_count);
4533 else if (!atomic_read(&queue->set_pci_flags_count))
4534 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
4536 * queue->state will go from LOCKED -> UNLOCKED or from
4537 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4538 * (switch packing state or flush buffer to get another pci flag out).
4539 * In that case we will enter this loop
4541 while (atomic_dec_return(&queue->state)){
4543 start_index = queue->next_buf_to_fill;
4544 /* check if we can go back to non-packing state */
4545 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4547 * check if we need to flush a packing buffer to get a pci
4548 * flag out on the queue
4550 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4551 flush_count += qeth_flush_buffers_on_no_pci(queue);
4553 qeth_flush_buffers(queue, 0, start_index, flush_count);
4555 /* at this point the queue is UNLOCKED again */
4556 if (queue->card->options.performance_stats && do_pack)
4557 queue->card->perf_stats.bufs_sent_pack += flush_count;
4563 qeth_get_elements_no(struct qeth_card *card, void *hdr,
4564 struct sk_buff *skb, int elems)
4566 int elements_needed = 0;
4568 if (skb_shinfo(skb)->nr_frags > 0)
4569 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4570 if (elements_needed == 0)
4571 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4572 + skb->len) >> PAGE_SHIFT);
4573 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4574 PRINT_ERR("Invalid size of IP packet "
4575 "(Number=%d / Length=%d). Discarded.\n",
4576 (elements_needed+elems), skb->len);
4579 return elements_needed;
4582 static void qeth_tx_csum(struct sk_buff *skb)
4586 if (skb->protocol == htons(ETH_P_IP)) {
4587 tlen = ntohs(ip_hdr(skb)->tot_len) - (ip_hdr(skb)->ihl << 2);
4588 switch (ip_hdr(skb)->protocol) {
4590 tcp_hdr(skb)->check = 0;
4591 tcp_hdr(skb)->check = csum_tcpudp_magic(
4592 ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
4593 tlen, ip_hdr(skb)->protocol,
4594 skb_checksum(skb, skb_transport_offset(skb),
4598 udp_hdr(skb)->check = 0;
4599 udp_hdr(skb)->check = csum_tcpudp_magic(
4600 ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
4601 tlen, ip_hdr(skb)->protocol,
4602 skb_checksum(skb, skb_transport_offset(skb),
4606 } else if (skb->protocol == htons(ETH_P_IPV6)) {
4607 switch (ipv6_hdr(skb)->nexthdr) {
4609 tcp_hdr(skb)->check = 0;
4610 tcp_hdr(skb)->check = csum_ipv6_magic(
4611 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
4612 ipv6_hdr(skb)->payload_len,
4613 ipv6_hdr(skb)->nexthdr,
4614 skb_checksum(skb, skb_transport_offset(skb),
4615 ipv6_hdr(skb)->payload_len, 0));
4618 udp_hdr(skb)->check = 0;
4619 udp_hdr(skb)->check = csum_ipv6_magic(
4620 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
4621 ipv6_hdr(skb)->payload_len,
4622 ipv6_hdr(skb)->nexthdr,
4623 skb_checksum(skb, skb_transport_offset(skb),
4624 ipv6_hdr(skb)->payload_len, 0));
4631 qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4635 struct qeth_qdio_out_q *queue;
4636 struct qeth_hdr *hdr = NULL;
4637 int elements_needed = 0;
4638 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4639 struct qeth_eddp_context *ctx = NULL;
4640 int tx_bytes = skb->len;
4641 unsigned short nr_frags = skb_shinfo(skb)->nr_frags;
4642 unsigned short tso_size = skb_shinfo(skb)->gso_size;
4643 struct sk_buff *new_skb, *new_skb2;
4646 QETH_DBF_TEXT(trace, 6, "sendpkt");
4649 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4650 (skb->protocol == htons(ETH_P_IPV6)))
4652 cast_type = qeth_get_cast_type(card, skb);
4653 if ((cast_type == RTN_BROADCAST) &&
4654 (card->info.broadcast_capable == 0))
4656 queue = card->qdio.out_qs
4657 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4658 if (!card->options.layer2) {
4659 ipv = qeth_get_ip_version(skb);
4660 if ((card->dev->header_ops == &qeth_fake_ops) && ipv) {
4661 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
4664 if(card->dev->type == ARPHRD_IEEE802_TR){
4665 skb_pull(new_skb, QETH_FAKE_LL_LEN_TR);
4667 skb_pull(new_skb, QETH_FAKE_LL_LEN_ETH);
4671 if (skb_is_gso(skb))
4672 large_send = card->options.large_send;
4673 /* check on OSN device*/
4674 if (card->info.type == QETH_CARD_TYPE_OSN)
4675 hdr = (struct qeth_hdr *)new_skb->data;
4676 /*are we able to do TSO ? */
4677 if ((large_send == QETH_LARGE_SEND_TSO) &&
4678 (cast_type == RTN_UNSPEC)) {
4679 rc = qeth_tso_prepare_packet(card, new_skb, ipv, cast_type);
4681 __qeth_free_new_skb(skb, new_skb);
4685 } else if (card->info.type != QETH_CARD_TYPE_OSN) {
4686 new_skb2 = qeth_prepare_skb(card, new_skb, &hdr, ipv);
4688 __qeth_free_new_skb(skb, new_skb);
4692 __qeth_free_new_skb(new_skb2, new_skb);
4694 qeth_fill_header(card, hdr, new_skb, ipv, cast_type);
4696 if (large_send == QETH_LARGE_SEND_EDDP) {
4697 ctx = qeth_eddp_create_context(card, new_skb, hdr,
4698 skb->sk->sk_protocol);
4700 __qeth_free_new_skb(skb, new_skb);
4701 PRINT_WARN("could not create eddp context\n");
4705 int elems = qeth_get_elements_no(card,(void*) hdr, new_skb,
4708 __qeth_free_new_skb(skb, new_skb);
4711 elements_needed += elems;
4714 if ((large_send == QETH_LARGE_SEND_NO) &&
4715 (skb->ip_summed == CHECKSUM_PARTIAL))
4716 qeth_tx_csum(new_skb);
4718 if (card->info.type != QETH_CARD_TYPE_IQD)
4719 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
4720 elements_needed, ctx);
4722 if ((!card->options.layer2) &&
4724 __qeth_free_new_skb(skb, new_skb);
4727 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
4728 elements_needed, ctx);
4731 card->stats.tx_packets++;
4732 card->stats.tx_bytes += tx_bytes;
4734 dev_kfree_skb_any(skb);
4735 if (card->options.performance_stats) {
4737 !(large_send == QETH_LARGE_SEND_NO)) {
4738 card->perf_stats.large_send_bytes += tx_bytes;
4739 card->perf_stats.large_send_cnt++;
4742 card->perf_stats.sg_skbs_sent++;
4743 /* nr_frags + skb->data */
4744 card->perf_stats.sg_frags_sent +=
4749 card->stats.tx_dropped++;
4750 __qeth_free_new_skb(skb, new_skb);
4753 /* drop creator's reference */
4754 qeth_eddp_put_context(ctx);
4755 /* free skb; it's not referenced by a buffer */
4757 dev_kfree_skb_any(new_skb);
4763 qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4765 struct qeth_card *card = (struct qeth_card *) dev->priv;
4769 case MII_BMCR: /* Basic mode control register */
4771 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4772 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4773 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4774 rc |= BMCR_SPEED100;
4776 case MII_BMSR: /* Basic mode status register */
4777 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4778 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4781 case MII_PHYSID1: /* PHYS ID 1 */
4782 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4784 rc = (rc >> 5) & 0xFFFF;
4786 case MII_PHYSID2: /* PHYS ID 2 */
4787 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4789 case MII_ADVERTISE: /* Advertisement control reg */
4792 case MII_LPA: /* Link partner ability reg */
4793 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4794 LPA_100BASE4 | LPA_LPACK;
4796 case MII_EXPANSION: /* Expansion register */
4798 case MII_DCOUNTER: /* disconnect counter */
4800 case MII_FCSCOUNTER: /* false carrier counter */
4802 case MII_NWAYTEST: /* N-way auto-neg test register */
4804 case MII_RERRCOUNTER: /* rx error counter */
4805 rc = card->stats.rx_errors;
4807 case MII_SREVISION: /* silicon revision */
4809 case MII_RESV1: /* reserved 1 */
4811 case MII_LBRERROR: /* loopback, rx, bypass error */
4813 case MII_PHYADDR: /* physical address */
4815 case MII_RESV2: /* reserved 2 */
4817 case MII_TPISTATUS: /* TPI status for 10mbps */
4819 case MII_NCONFIG: /* network interface config */
4829 qeth_arp_get_error_cause(int *rc)
4832 case QETH_IPA_ARP_RC_FAILED:
4834 return "operation failed";
4835 case QETH_IPA_ARP_RC_NOTSUPP:
4837 return "operation not supported";
4838 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4840 return "argument out of range";
4841 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4843 return "query operation not supported";
4844 case QETH_IPA_ARP_RC_Q_NO_DATA:
4846 return "no query data available";
4848 return "unknown error";
4853 qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4857 qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4862 QETH_DBF_TEXT(trace,3,"arpstnoe");
4865 * currently GuestLAN only supports the ARP assist function
4866 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4867 * thus we say EOPNOTSUPP for this ARP function
4869 if (card->info.guestlan)
4871 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4872 PRINT_WARN("ARP processing not supported "
4873 "on %s!\n", QETH_CARD_IFNAME(card));
4876 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4877 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4881 PRINT_WARN("Could not set number of ARP entries on %s: "
4883 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4890 qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4891 struct qeth_arp_query_data *qdata,
4892 int entry_size, int uentry_size)
4898 entry_ptr = (char *)&qdata->data;
4899 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4900 for (i = 0; i < qdata->no_entries; ++i){
4901 /* strip off 32 bytes "media specific information" */
4902 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4903 entry_ptr += entry_size;
4904 uentry_ptr += uentry_size;
4909 qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4912 struct qeth_ipa_cmd *cmd;
4913 struct qeth_arp_query_data *qdata;
4914 struct qeth_arp_query_info *qinfo;
4919 QETH_DBF_TEXT(trace,4,"arpquecb");
4921 qinfo = (struct qeth_arp_query_info *) reply->param;
4922 cmd = (struct qeth_ipa_cmd *) data;
4923 if (cmd->hdr.return_code) {
4924 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4927 if (cmd->data.setassparms.hdr.return_code) {
4928 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4929 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4932 qdata = &cmd->data.setassparms.data.query_arp;
4933 switch(qdata->reply_bits){
4935 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4936 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4937 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4940 /* fall through to default */
4942 /* tr is the same as eth -> entry7 */
4943 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4944 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4945 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4948 /* check if there is enough room in userspace */
4949 if ((qinfo->udata_len - qinfo->udata_offset) <
4950 qdata->no_entries * uentry_size){
4951 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4952 cmd->hdr.return_code = -ENOMEM;
4953 PRINT_WARN("query ARP user space buffer is too small for "
4954 "the returned number of ARP entries. "
4955 "Aborting query!\n");
4958 QETH_DBF_TEXT_(trace, 4, "anore%i",
4959 cmd->data.setassparms.hdr.number_of_replies);
4960 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4961 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4963 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4964 /* strip off "media specific information" */
4965 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4968 /*copy entries to user buffer*/
4969 memcpy(qinfo->udata + qinfo->udata_offset,
4970 (char *)&qdata->data, qdata->no_entries*uentry_size);
4972 qinfo->no_entries += qdata->no_entries;
4973 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4974 /* check if all replies received ... */
4975 if (cmd->data.setassparms.hdr.seq_no <
4976 cmd->data.setassparms.hdr.number_of_replies)
4978 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4979 /* keep STRIP_ENTRIES flag so the user program can distinguish
4980 * stripped entries from normal ones */
4981 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4982 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4983 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4987 memcpy(qinfo->udata, &i, 4);
4992 qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4993 int len, int (*reply_cb)(struct qeth_card *,
4994 struct qeth_reply *,
4998 QETH_DBF_TEXT(trace,4,"sendarp");
5000 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
5001 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
5002 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
5003 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
5004 reply_cb, reply_param);
5008 qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
5009 int len, int (*reply_cb)(struct qeth_card *,
5010 struct qeth_reply *,
5016 QETH_DBF_TEXT(trace,4,"sendsnmp");
5018 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
5019 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
5020 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
5021 /* adjust PDU length fields in IPA_PDU_HEADER */
5022 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
5024 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
5025 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
5026 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
5027 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
5028 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
5029 reply_cb, reply_param);
5032 static struct qeth_cmd_buffer *
5033 qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
5034 __u16, __u16, enum qeth_prot_versions);
5036 qeth_arp_query(struct qeth_card *card, char __user *udata)
5038 struct qeth_cmd_buffer *iob;
5039 struct qeth_arp_query_info qinfo = {0, };
5043 QETH_DBF_TEXT(trace,3,"arpquery");
5045 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
5046 IPA_ARP_PROCESSING)) {
5047 PRINT_WARN("ARP processing not supported "
5048 "on %s!\n", QETH_CARD_IFNAME(card));
5051 /* get size of userspace buffer and mask_bits -> 6 bytes */
5052 if (copy_from_user(&qinfo, udata, 6))
5054 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL)))
5056 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
5057 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5058 IPA_CMD_ASS_ARP_QUERY_INFO,
5059 sizeof(int),QETH_PROT_IPV4);
5061 rc = qeth_send_ipa_arp_cmd(card, iob,
5062 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
5063 qeth_arp_query_cb, (void *)&qinfo);
5066 PRINT_WARN("Error while querying ARP cache on %s: %s "
5068 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5070 if (copy_to_user(udata, qinfo.udata, 4))
5073 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
5081 * SNMP command callback
5084 qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
5085 unsigned long sdata)
5087 struct qeth_ipa_cmd *cmd;
5088 struct qeth_arp_query_info *qinfo;
5089 struct qeth_snmp_cmd *snmp;
5090 unsigned char *data;
5093 QETH_DBF_TEXT(trace,3,"snpcmdcb");
5095 cmd = (struct qeth_ipa_cmd *) sdata;
5096 data = (unsigned char *)((char *)cmd - reply->offset);
5097 qinfo = (struct qeth_arp_query_info *) reply->param;
5098 snmp = &cmd->data.setadapterparms.data.snmp;
5100 if (cmd->hdr.return_code) {
5101 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
5104 if (cmd->data.setadapterparms.hdr.return_code) {
5105 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
5106 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
5109 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
5110 if (cmd->data.setadapterparms.hdr.seq_no == 1)
5111 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
5113 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
5115 /* check if there is enough room in userspace */
5116 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
5117 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
5118 cmd->hdr.return_code = -ENOMEM;
5121 QETH_DBF_TEXT_(trace, 4, "snore%i",
5122 cmd->data.setadapterparms.hdr.used_total);
5123 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
5124 /*copy entries to user buffer*/
5125 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
5126 memcpy(qinfo->udata + qinfo->udata_offset,
5128 data_len + offsetof(struct qeth_snmp_cmd,data));
5129 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
5131 memcpy(qinfo->udata + qinfo->udata_offset,
5132 (char *)&snmp->request, data_len);
5134 qinfo->udata_offset += data_len;
5135 /* check if all replies received ... */
5136 QETH_DBF_TEXT_(trace, 4, "srtot%i",
5137 cmd->data.setadapterparms.hdr.used_total);
5138 QETH_DBF_TEXT_(trace, 4, "srseq%i",
5139 cmd->data.setadapterparms.hdr.seq_no);
5140 if (cmd->data.setadapterparms.hdr.seq_no <
5141 cmd->data.setadapterparms.hdr.used_total)
5146 static struct qeth_cmd_buffer *
5147 qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
5148 enum qeth_prot_versions );
5150 static struct qeth_cmd_buffer *
5151 qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
5153 struct qeth_cmd_buffer *iob;
5154 struct qeth_ipa_cmd *cmd;
5156 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
5158 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5159 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
5160 cmd->data.setadapterparms.hdr.command_code = command;
5161 cmd->data.setadapterparms.hdr.used_total = 1;
5162 cmd->data.setadapterparms.hdr.seq_no = 1;
5168 * function to send SNMP commands to OSA-E card
5171 qeth_snmp_command(struct qeth_card *card, char __user *udata)
5173 struct qeth_cmd_buffer *iob;
5174 struct qeth_ipa_cmd *cmd;
5175 struct qeth_snmp_ureq *ureq;
5177 struct qeth_arp_query_info qinfo = {0, };
5180 QETH_DBF_TEXT(trace,3,"snmpcmd");
5182 if (card->info.guestlan)
5185 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
5186 (!card->options.layer2) ) {
5187 PRINT_WARN("SNMP Query MIBS not supported "
5188 "on %s!\n", QETH_CARD_IFNAME(card));
5191 /* skip 4 bytes (data_len struct member) to get req_len */
5192 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
5194 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
5196 QETH_DBF_TEXT(trace, 2, "snmpnome");
5199 if (copy_from_user(ureq, udata,
5200 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
5204 qinfo.udata_len = ureq->hdr.data_len;
5205 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){
5209 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
5211 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
5212 QETH_SNMP_SETADP_CMDLENGTH + req_len);
5213 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5214 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
5215 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
5216 qeth_snmp_command_cb, (void *)&qinfo);
5218 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
5219 QETH_CARD_IFNAME(card), rc);
5221 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
5231 qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
5235 qeth_default_setadapterparms_cb(struct qeth_card *card,
5236 struct qeth_reply *reply,
5237 unsigned long data);
5239 qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
5242 (struct qeth_card *, struct qeth_reply *, unsigned long),
5246 qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5248 struct qeth_cmd_buffer *iob;
5253 QETH_DBF_TEXT(trace,3,"arpadent");
5256 * currently GuestLAN only supports the ARP assist function
5257 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
5258 * thus we say EOPNOTSUPP for this ARP function
5260 if (card->info.guestlan)
5262 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5263 PRINT_WARN("ARP processing not supported "
5264 "on %s!\n", QETH_CARD_IFNAME(card));
5268 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5269 IPA_CMD_ASS_ARP_ADD_ENTRY,
5270 sizeof(struct qeth_arp_cache_entry),
5272 rc = qeth_send_setassparms(card, iob,
5273 sizeof(struct qeth_arp_cache_entry),
5274 (unsigned long) entry,
5275 qeth_default_setassparms_cb, NULL);
5278 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5279 PRINT_WARN("Could not add ARP entry for address %s on %s: "
5281 buf, QETH_CARD_IFNAME(card),
5282 qeth_arp_get_error_cause(&rc), tmp, tmp);
5288 qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5290 struct qeth_cmd_buffer *iob;
5291 char buf[16] = {0, };
5295 QETH_DBF_TEXT(trace,3,"arprment");
5298 * currently GuestLAN only supports the ARP assist function
5299 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5300 * thus we say EOPNOTSUPP for this ARP function
5302 if (card->info.guestlan)
5304 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5305 PRINT_WARN("ARP processing not supported "
5306 "on %s!\n", QETH_CARD_IFNAME(card));
5309 memcpy(buf, entry, 12);
5310 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5311 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5314 rc = qeth_send_setassparms(card, iob,
5315 12, (unsigned long)buf,
5316 qeth_default_setassparms_cb, NULL);
5320 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5321 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5323 buf, QETH_CARD_IFNAME(card),
5324 qeth_arp_get_error_cause(&rc), tmp, tmp);
5330 qeth_arp_flush_cache(struct qeth_card *card)
5335 QETH_DBF_TEXT(trace,3,"arpflush");
5338 * currently GuestLAN only supports the ARP assist function
5339 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5340 * thus we say EOPNOTSUPP for this ARP function
5342 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5344 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5345 PRINT_WARN("ARP processing not supported "
5346 "on %s!\n", QETH_CARD_IFNAME(card));
5349 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5350 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5353 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5354 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5361 qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5363 struct qeth_card *card = (struct qeth_card *)dev->priv;
5364 struct qeth_arp_cache_entry arp_entry;
5365 struct mii_ioctl_data *mii_data;
5371 if ((card->state != CARD_STATE_UP) &&
5372 (card->state != CARD_STATE_SOFTSETUP))
5375 if (card->info.type == QETH_CARD_TYPE_OSN)
5379 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5380 if ( !capable(CAP_NET_ADMIN) ||
5381 (card->options.layer2) ) {
5385 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5387 case SIOC_QETH_ARP_QUERY_INFO:
5388 if ( !capable(CAP_NET_ADMIN) ||
5389 (card->options.layer2) ) {
5393 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5395 case SIOC_QETH_ARP_ADD_ENTRY:
5396 if ( !capable(CAP_NET_ADMIN) ||
5397 (card->options.layer2) ) {
5401 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5402 sizeof(struct qeth_arp_cache_entry)))
5405 rc = qeth_arp_add_entry(card, &arp_entry);
5407 case SIOC_QETH_ARP_REMOVE_ENTRY:
5408 if ( !capable(CAP_NET_ADMIN) ||
5409 (card->options.layer2) ) {
5413 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5414 sizeof(struct qeth_arp_cache_entry)))
5417 rc = qeth_arp_remove_entry(card, &arp_entry);
5419 case SIOC_QETH_ARP_FLUSH_CACHE:
5420 if ( !capable(CAP_NET_ADMIN) ||
5421 (card->options.layer2) ) {
5425 rc = qeth_arp_flush_cache(card);
5427 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5428 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5430 case SIOC_QETH_GET_CARD_TYPE:
5431 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5432 !card->info.guestlan)
5437 mii_data = if_mii(rq);
5438 mii_data->phy_id = 0;
5441 mii_data = if_mii(rq);
5442 if (mii_data->phy_id != 0)
5445 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5452 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5456 static struct net_device_stats *
5457 qeth_get_stats(struct net_device *dev)
5459 struct qeth_card *card;
5461 card = (struct qeth_card *) (dev->priv);
5463 QETH_DBF_TEXT(trace,5,"getstat");
5465 return &card->stats;
5469 qeth_change_mtu(struct net_device *dev, int new_mtu)
5471 struct qeth_card *card;
5474 card = (struct qeth_card *) (dev->priv);
5476 QETH_DBF_TEXT(trace,4,"chgmtu");
5477 sprintf(dbf_text, "%8x", new_mtu);
5478 QETH_DBF_TEXT(trace,4,dbf_text);
5482 if (new_mtu > 65535)
5484 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5485 (!qeth_mtu_is_valid(card, new_mtu)))
5491 #ifdef CONFIG_QETH_VLAN
5493 qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5495 struct qeth_card *card;
5496 unsigned long flags;
5498 QETH_DBF_TEXT(trace,4,"vlanreg");
5500 card = (struct qeth_card *) dev->priv;
5501 spin_lock_irqsave(&card->vlanlock, flags);
5502 card->vlangrp = grp;
5503 spin_unlock_irqrestore(&card->vlanlock, flags);
5507 qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5511 struct sk_buff *skb;
5512 struct sk_buff_head tmp_list;
5514 skb_queue_head_init(&tmp_list);
5515 lockdep_set_class(&tmp_list.lock, &qdio_out_skb_queue_key);
5516 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5517 while ((skb = skb_dequeue(&buf->skb_list))){
5518 if (vlan_tx_tag_present(skb) &&
5519 (vlan_tx_tag_get(skb) == vid)) {
5520 atomic_dec(&skb->users);
5523 skb_queue_tail(&tmp_list, skb);
5526 while ((skb = skb_dequeue(&tmp_list)))
5527 skb_queue_tail(&buf->skb_list, skb);
5531 qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5535 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5536 for (i = 0; i < card->qdio.no_out_queues; ++i){
5537 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5538 qeth_free_vlan_buffer(card, &card->qdio.
5539 out_qs[i]->bufs[j], vid);
5544 qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5546 struct in_device *in_dev;
5547 struct in_ifaddr *ifa;
5548 struct qeth_ipaddr *addr;
5550 QETH_DBF_TEXT(trace, 4, "frvaddr4");
5553 in_dev = __in_dev_get_rcu(vlan_group_get_device(card->vlangrp, vid));
5556 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5557 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5559 addr->u.a4.addr = ifa->ifa_address;
5560 addr->u.a4.mask = ifa->ifa_mask;
5561 addr->type = QETH_IP_TYPE_NORMAL;
5562 if (!qeth_delete_ip(card, addr))
5571 qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5573 #ifdef CONFIG_QETH_IPV6
5574 struct inet6_dev *in6_dev;
5575 struct inet6_ifaddr *ifa;
5576 struct qeth_ipaddr *addr;
5578 QETH_DBF_TEXT(trace, 4, "frvaddr6");
5580 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
5583 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5584 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5586 memcpy(&addr->u.a6.addr, &ifa->addr,
5587 sizeof(struct in6_addr));
5588 addr->u.a6.pfxlen = ifa->prefix_len;
5589 addr->type = QETH_IP_TYPE_NORMAL;
5590 if (!qeth_delete_ip(card, addr))
5594 in6_dev_put(in6_dev);
5595 #endif /* CONFIG_QETH_IPV6 */
5599 qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5601 if (card->options.layer2 || !card->vlangrp)
5603 qeth_free_vlan_addresses4(card, vid);
5604 qeth_free_vlan_addresses6(card, vid);
5608 qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5609 struct qeth_reply *reply,
5612 struct qeth_ipa_cmd *cmd;
5614 QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5615 cmd = (struct qeth_ipa_cmd *) data;
5616 if (cmd->hdr.return_code) {
5617 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5618 "Continuing\n",cmd->data.setdelvlan.vlan_id,
5619 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5620 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5621 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5622 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5628 qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5629 enum qeth_ipa_cmds ipacmd)
5631 struct qeth_ipa_cmd *cmd;
5632 struct qeth_cmd_buffer *iob;
5634 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5635 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5636 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5637 cmd->data.setdelvlan.vlan_id = i;
5638 return qeth_send_ipa_cmd(card, iob,
5639 qeth_layer2_send_setdelvlan_cb, NULL);
5643 qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5647 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5651 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5652 if (vlan_group_get_device(card->vlangrp, i) == NULL)
5655 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5657 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5661 /*add_vid is layer 2 used only ....*/
5663 qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5665 struct qeth_card *card;
5667 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5669 card = (struct qeth_card *) dev->priv;
5670 if (!card->options.layer2)
5672 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5675 /*... kill_vid used for both modes*/
5677 qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5679 struct qeth_card *card;
5680 unsigned long flags;
5682 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5684 card = (struct qeth_card *) dev->priv;
5685 /* free all skbs for the vlan device */
5686 qeth_free_vlan_skbs(card, vid);
5687 spin_lock_irqsave(&card->vlanlock, flags);
5688 /* unregister IP addresses of vlan device */
5689 qeth_free_vlan_addresses(card, vid);
5690 vlan_group_set_device(card->vlangrp, vid, NULL);
5691 spin_unlock_irqrestore(&card->vlanlock, flags);
5692 if (card->options.layer2)
5693 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5694 qeth_set_multicast_list(card->dev);
5698 * Examine hardware response to SET_PROMISC_MODE
5701 qeth_setadp_promisc_mode_cb(struct qeth_card *card,
5702 struct qeth_reply *reply,
5705 struct qeth_ipa_cmd *cmd;
5706 struct qeth_ipacmd_setadpparms *setparms;
5708 QETH_DBF_TEXT(trace,4,"prmadpcb");
5710 cmd = (struct qeth_ipa_cmd *) data;
5711 setparms = &(cmd->data.setadapterparms);
5713 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
5714 if (cmd->hdr.return_code) {
5715 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
5716 setparms->data.mode = SET_PROMISC_MODE_OFF;
5718 card->info.promisc_mode = setparms->data.mode;
5722 * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5725 qeth_setadp_promisc_mode(struct qeth_card *card)
5727 enum qeth_ipa_promisc_modes mode;
5728 struct net_device *dev = card->dev;
5729 struct qeth_cmd_buffer *iob;
5730 struct qeth_ipa_cmd *cmd;
5732 QETH_DBF_TEXT(trace, 4, "setprom");
5734 if (((dev->flags & IFF_PROMISC) &&
5735 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5736 (!(dev->flags & IFF_PROMISC) &&
5737 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5739 mode = SET_PROMISC_MODE_OFF;
5740 if (dev->flags & IFF_PROMISC)
5741 mode = SET_PROMISC_MODE_ON;
5742 QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5744 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5745 sizeof(struct qeth_ipacmd_setadpparms));
5746 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5747 cmd->data.setadapterparms.data.mode = mode;
5748 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5752 * set multicast address on card
5755 qeth_set_multicast_list(struct net_device *dev)
5757 struct qeth_card *card = (struct qeth_card *) dev->priv;
5759 if (card->info.type == QETH_CARD_TYPE_OSN)
5762 QETH_DBF_TEXT(trace, 3, "setmulti");
5763 qeth_delete_mc_addresses(card);
5764 if (card->options.layer2) {
5765 qeth_layer2_add_multicast(card);
5768 qeth_add_multicast_ipv4(card);
5769 #ifdef CONFIG_QETH_IPV6
5770 qeth_add_multicast_ipv6(card);
5773 qeth_set_ip_addr_list(card);
5774 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5776 qeth_setadp_promisc_mode(card);
5780 qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5786 qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5788 if (dev->type == ARPHRD_IEEE802_TR)
5789 ip_tr_mc_map(ipm, mac);
5791 ip_eth_mc_map(ipm, mac);
5794 static struct qeth_ipaddr *
5795 qeth_get_addr_buffer(enum qeth_prot_versions prot)
5797 struct qeth_ipaddr *addr;
5799 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5801 PRINT_WARN("Not enough memory to add address\n");
5804 addr->type = QETH_IP_TYPE_NORMAL;
5810 qeth_osn_assist(struct net_device *dev,
5814 struct qeth_cmd_buffer *iob;
5815 struct qeth_card *card;
5818 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5821 card = (struct qeth_card *)dev->priv;
5824 if ((card->state != CARD_STATE_UP) &&
5825 (card->state != CARD_STATE_SOFTSETUP))
5827 iob = qeth_wait_for_buffer(&card->write);
5828 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5829 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5833 static struct net_device *
5834 qeth_netdev_by_devno(unsigned char *read_dev_no)
5836 struct qeth_card *card;
5837 struct net_device *ndev;
5838 unsigned char *readno;
5839 __u16 temp_dev_no, card_dev_no;
5841 unsigned long flags;
5844 memcpy(&temp_dev_no, read_dev_no, 2);
5845 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5846 list_for_each_entry(card, &qeth_card_list.list, list) {
5847 readno = CARD_RDEV_ID(card);
5848 readno += (strlen(readno) - 4);
5849 card_dev_no = simple_strtoul(readno, &endp, 16);
5850 if (card_dev_no == temp_dev_no) {
5855 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5860 qeth_osn_register(unsigned char *read_dev_no,
5861 struct net_device **dev,
5862 int (*assist_cb)(struct net_device *, void *),
5863 int (*data_cb)(struct sk_buff *))
5865 struct qeth_card * card;
5867 QETH_DBF_TEXT(trace, 2, "osnreg");
5868 *dev = qeth_netdev_by_devno(read_dev_no);
5871 card = (struct qeth_card *)(*dev)->priv;
5874 if ((assist_cb == NULL) || (data_cb == NULL))
5876 card->osn_info.assist_cb = assist_cb;
5877 card->osn_info.data_cb = data_cb;
5882 qeth_osn_deregister(struct net_device * dev)
5884 struct qeth_card *card;
5886 QETH_DBF_TEXT(trace, 2, "osndereg");
5889 card = (struct qeth_card *)dev->priv;
5892 card->osn_info.assist_cb = NULL;
5893 card->osn_info.data_cb = NULL;
5898 qeth_delete_mc_addresses(struct qeth_card *card)
5900 struct qeth_ipaddr *iptodo;
5901 unsigned long flags;
5903 QETH_DBF_TEXT(trace,4,"delmc");
5904 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5906 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5909 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5910 spin_lock_irqsave(&card->ip_lock, flags);
5911 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5913 spin_unlock_irqrestore(&card->ip_lock, flags);
5917 qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5919 struct qeth_ipaddr *ipm;
5920 struct ip_mc_list *im4;
5921 char buf[MAX_ADDR_LEN];
5923 QETH_DBF_TEXT(trace,4,"addmc");
5924 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5925 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5926 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5929 ipm->u.a4.addr = im4->multiaddr;
5930 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5931 ipm->is_multicast = 1;
5932 if (!qeth_add_ip(card,ipm))
5938 qeth_add_vlan_mc(struct qeth_card *card)
5940 #ifdef CONFIG_QETH_VLAN
5941 struct in_device *in_dev;
5942 struct vlan_group *vg;
5945 QETH_DBF_TEXT(trace,4,"addmcvl");
5946 if ( ((card->options.layer2 == 0) &&
5947 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5948 (card->vlangrp == NULL) )
5952 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5953 struct net_device *netdev = vlan_group_get_device(vg, i);
5954 if (netdev == NULL ||
5955 !(netdev->flags & IFF_UP))
5957 in_dev = in_dev_get(netdev);
5960 read_lock(&in_dev->mc_list_lock);
5961 qeth_add_mc(card,in_dev);
5962 read_unlock(&in_dev->mc_list_lock);
5969 qeth_add_multicast_ipv4(struct qeth_card *card)
5971 struct in_device *in4_dev;
5973 QETH_DBF_TEXT(trace,4,"chkmcv4");
5974 in4_dev = in_dev_get(card->dev);
5975 if (in4_dev == NULL)
5977 read_lock(&in4_dev->mc_list_lock);
5978 qeth_add_mc(card, in4_dev);
5979 qeth_add_vlan_mc(card);
5980 read_unlock(&in4_dev->mc_list_lock);
5981 in_dev_put(in4_dev);
5985 qeth_layer2_add_multicast(struct qeth_card *card)
5987 struct qeth_ipaddr *ipm;
5988 struct dev_mc_list *dm;
5990 QETH_DBF_TEXT(trace,4,"L2addmc");
5991 for (dm = card->dev->mc_list; dm; dm = dm->next) {
5992 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5995 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5996 ipm->is_multicast = 1;
5997 if (!qeth_add_ip(card, ipm))
6002 #ifdef CONFIG_QETH_IPV6
6004 qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
6006 struct qeth_ipaddr *ipm;
6007 struct ifmcaddr6 *im6;
6008 char buf[MAX_ADDR_LEN];
6010 QETH_DBF_TEXT(trace,4,"addmc6");
6011 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
6012 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
6013 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
6016 ipm->is_multicast = 1;
6017 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
6018 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
6019 sizeof(struct in6_addr));
6020 if (!qeth_add_ip(card,ipm))
6026 qeth_add_vlan_mc6(struct qeth_card *card)
6028 #ifdef CONFIG_QETH_VLAN
6029 struct inet6_dev *in_dev;
6030 struct vlan_group *vg;
6033 QETH_DBF_TEXT(trace,4,"admc6vl");
6034 if ( ((card->options.layer2 == 0) &&
6035 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
6036 (card->vlangrp == NULL))
6040 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
6041 struct net_device *netdev = vlan_group_get_device(vg, i);
6042 if (netdev == NULL ||
6043 !(netdev->flags & IFF_UP))
6045 in_dev = in6_dev_get(netdev);
6048 read_lock_bh(&in_dev->lock);
6049 qeth_add_mc6(card,in_dev);
6050 read_unlock_bh(&in_dev->lock);
6051 in6_dev_put(in_dev);
6053 #endif /* CONFIG_QETH_VLAN */
6057 qeth_add_multicast_ipv6(struct qeth_card *card)
6059 struct inet6_dev *in6_dev;
6061 QETH_DBF_TEXT(trace,4,"chkmcv6");
6062 if (!qeth_is_supported(card, IPA_IPV6))
6064 in6_dev = in6_dev_get(card->dev);
6065 if (in6_dev == NULL)
6067 read_lock_bh(&in6_dev->lock);
6068 qeth_add_mc6(card, in6_dev);
6069 qeth_add_vlan_mc6(card);
6070 read_unlock_bh(&in6_dev->lock);
6071 in6_dev_put(in6_dev);
6073 #endif /* CONFIG_QETH_IPV6 */
6076 qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
6077 enum qeth_ipa_cmds ipacmd,
6078 int (*reply_cb) (struct qeth_card *,
6082 struct qeth_ipa_cmd *cmd;
6083 struct qeth_cmd_buffer *iob;
6085 QETH_DBF_TEXT(trace, 2, "L2sdmac");
6086 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
6087 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6088 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
6089 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
6090 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
6094 qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
6095 struct qeth_reply *reply,
6098 struct qeth_ipa_cmd *cmd;
6101 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
6102 cmd = (struct qeth_ipa_cmd *) data;
6103 mac = &cmd->data.setdelmac.mac[0];
6104 /* MAC already registered, needed in couple/uncouple case */
6105 if (cmd->hdr.return_code == 0x2005) {
6106 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
6107 "already existing on %s \n",
6108 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
6109 QETH_CARD_IFNAME(card));
6110 cmd->hdr.return_code = 0;
6112 if (cmd->hdr.return_code)
6113 PRINT_ERR("Could not set group MAC " \
6114 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
6115 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
6116 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
6121 qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
6123 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
6124 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
6125 qeth_layer2_send_setgroupmac_cb);
6129 qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
6130 struct qeth_reply *reply,
6133 struct qeth_ipa_cmd *cmd;
6136 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
6137 cmd = (struct qeth_ipa_cmd *) data;
6138 mac = &cmd->data.setdelmac.mac[0];
6139 if (cmd->hdr.return_code)
6140 PRINT_ERR("Could not delete group MAC " \
6141 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
6142 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
6143 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
6148 qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
6150 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
6151 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
6152 qeth_layer2_send_delgroupmac_cb);
6156 qeth_layer2_send_setmac_cb(struct qeth_card *card,
6157 struct qeth_reply *reply,
6160 struct qeth_ipa_cmd *cmd;
6162 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
6163 cmd = (struct qeth_ipa_cmd *) data;
6164 if (cmd->hdr.return_code) {
6165 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
6166 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
6167 cmd->hdr.return_code = -EIO;
6169 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
6170 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
6172 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
6173 "successfully registered on device %s\n",
6174 card->dev->dev_addr[0], card->dev->dev_addr[1],
6175 card->dev->dev_addr[2], card->dev->dev_addr[3],
6176 card->dev->dev_addr[4], card->dev->dev_addr[5],
6183 qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
6185 QETH_DBF_TEXT(trace, 2, "L2Setmac");
6186 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
6187 qeth_layer2_send_setmac_cb);
6191 qeth_layer2_send_delmac_cb(struct qeth_card *card,
6192 struct qeth_reply *reply,
6195 struct qeth_ipa_cmd *cmd;
6197 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
6198 cmd = (struct qeth_ipa_cmd *) data;
6199 if (cmd->hdr.return_code) {
6200 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
6201 cmd->hdr.return_code = -EIO;
6204 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
6209 qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
6211 QETH_DBF_TEXT(trace, 2, "L2Delmac");
6212 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
6214 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
6215 qeth_layer2_send_delmac_cb);
6219 qeth_layer2_set_mac_address(struct net_device *dev, void *p)
6221 struct sockaddr *addr = p;
6222 struct qeth_card *card;
6225 QETH_DBF_TEXT(trace, 3, "setmac");
6227 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
6228 QETH_DBF_TEXT(trace, 3, "setmcINV");
6231 card = (struct qeth_card *) dev->priv;
6233 if (!card->options.layer2) {
6234 PRINT_WARN("Setting MAC address on %s is not supported "
6235 "in Layer 3 mode.\n", dev->name);
6236 QETH_DBF_TEXT(trace, 3, "setmcLY3");
6239 if (card->info.type == QETH_CARD_TYPE_OSN) {
6240 PRINT_WARN("Setting MAC address on %s is not supported.\n",
6242 QETH_DBF_TEXT(trace, 3, "setmcOSN");
6245 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
6246 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
6247 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
6249 rc = qeth_layer2_send_setmac(card, addr->sa_data);
6254 qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
6255 __u8 command, enum qeth_prot_versions prot)
6257 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
6258 cmd->hdr.command = command;
6259 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
6260 cmd->hdr.seqno = card->seqno.ipa;
6261 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
6262 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
6263 if (card->options.layer2)
6264 cmd->hdr.prim_version_no = 2;
6266 cmd->hdr.prim_version_no = 1;
6267 cmd->hdr.param_count = 1;
6268 cmd->hdr.prot_version = prot;
6269 cmd->hdr.ipa_supported = 0;
6270 cmd->hdr.ipa_enabled = 0;
6273 static struct qeth_cmd_buffer *
6274 qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6275 enum qeth_prot_versions prot)
6277 struct qeth_cmd_buffer *iob;
6278 struct qeth_ipa_cmd *cmd;
6280 iob = qeth_wait_for_buffer(&card->write);
6281 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6282 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6288 qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6291 struct qeth_cmd_buffer *iob;
6292 struct qeth_ipa_cmd *cmd;
6294 QETH_DBF_TEXT(trace,4,"setdelmc");
6296 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6297 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6298 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6299 if (addr->proto == QETH_PROT_IPV6)
6300 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6301 sizeof(struct in6_addr));
6303 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6305 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6310 qeth_fill_netmask(u8 *netmask, unsigned int len)
6313 for (i=0;i<16;i++) {
6318 netmask[i] = (u8)(0xFF00>>j);
6325 qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6326 int ipacmd, unsigned int flags)
6329 struct qeth_cmd_buffer *iob;
6330 struct qeth_ipa_cmd *cmd;
6333 QETH_DBF_TEXT(trace,4,"setdelip");
6334 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6336 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6337 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6338 if (addr->proto == QETH_PROT_IPV6) {
6339 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6340 sizeof(struct in6_addr));
6341 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6342 memcpy(cmd->data.setdelip6.mask, netmask,
6343 sizeof(struct in6_addr));
6344 cmd->data.setdelip6.flags = flags;
6346 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6347 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6348 cmd->data.setdelip4.flags = flags;
6351 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6357 qeth_layer2_register_addr_entry(struct qeth_card *card,
6358 struct qeth_ipaddr *addr)
6360 if (!addr->is_multicast)
6362 QETH_DBF_TEXT(trace, 2, "setgmac");
6363 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6364 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6368 qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6369 struct qeth_ipaddr *addr)
6371 if (!addr->is_multicast)
6373 QETH_DBF_TEXT(trace, 2, "delgmac");
6374 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6375 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6379 qeth_layer3_register_addr_entry(struct qeth_card *card,
6380 struct qeth_ipaddr *addr)
6386 if (addr->proto == QETH_PROT_IPV4) {
6387 QETH_DBF_TEXT(trace, 2,"setaddr4");
6388 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6389 } else if (addr->proto == QETH_PROT_IPV6) {
6390 QETH_DBF_TEXT(trace, 2, "setaddr6");
6391 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6392 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6394 QETH_DBF_TEXT(trace, 2, "setaddr?");
6395 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6398 if (addr->is_multicast)
6399 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6401 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6404 QETH_DBF_TEXT(trace, 2, "failed");
6405 } while ((--cnt > 0) && rc);
6407 QETH_DBF_TEXT(trace, 2, "FAILED");
6408 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6409 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6416 qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6417 struct qeth_ipaddr *addr)
6422 if (addr->proto == QETH_PROT_IPV4) {
6423 QETH_DBF_TEXT(trace, 2,"deladdr4");
6424 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6425 } else if (addr->proto == QETH_PROT_IPV6) {
6426 QETH_DBF_TEXT(trace, 2, "deladdr6");
6427 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6428 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6430 QETH_DBF_TEXT(trace, 2, "deladdr?");
6431 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6433 if (addr->is_multicast)
6434 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6436 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6439 QETH_DBF_TEXT(trace, 2, "failed");
6440 /* TODO: re-activate this warning as soon as we have a
6442 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6443 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6451 qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6453 if (card->options.layer2)
6454 return qeth_layer2_register_addr_entry(card, addr);
6456 return qeth_layer3_register_addr_entry(card, addr);
6460 qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6462 if (card->options.layer2)
6463 return qeth_layer2_deregister_addr_entry(card, addr);
6465 return qeth_layer3_deregister_addr_entry(card, addr);
6469 qeth_ethtool_get_tx_csum(struct net_device *dev)
6471 return (dev->features & NETIF_F_HW_CSUM) != 0;
6475 qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6478 dev->features |= NETIF_F_HW_CSUM;
6480 dev->features &= ~NETIF_F_HW_CSUM;
6486 qeth_ethtool_get_rx_csum(struct net_device *dev)
6488 struct qeth_card *card = (struct qeth_card *)dev->priv;
6490 return (card->options.checksum_type == HW_CHECKSUMMING);
6494 qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6496 struct qeth_card *card = (struct qeth_card *)dev->priv;
6498 if ((card->state != CARD_STATE_DOWN) &&
6499 (card->state != CARD_STATE_RECOVER))
6502 card->options.checksum_type = HW_CHECKSUMMING;
6504 card->options.checksum_type = SW_CHECKSUMMING;
6509 qeth_ethtool_get_sg(struct net_device *dev)
6511 struct qeth_card *card = (struct qeth_card *)dev->priv;
6513 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6514 (dev->features & NETIF_F_SG));
6518 qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6520 struct qeth_card *card = (struct qeth_card *)dev->priv;
6523 if (card->options.large_send != QETH_LARGE_SEND_NO)
6524 dev->features |= NETIF_F_SG;
6526 dev->features &= ~NETIF_F_SG;
6530 dev->features &= ~NETIF_F_SG;
6535 qeth_ethtool_get_tso(struct net_device *dev)
6537 struct qeth_card *card = (struct qeth_card *)dev->priv;
6539 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6540 (dev->features & NETIF_F_TSO));
6544 qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6546 struct qeth_card *card = (struct qeth_card *)dev->priv;
6549 if (card->options.large_send != QETH_LARGE_SEND_NO)
6550 dev->features |= NETIF_F_TSO;
6552 dev->features &= ~NETIF_F_TSO;
6556 dev->features &= ~NETIF_F_TSO;
6560 static struct ethtool_ops qeth_ethtool_ops = {
6561 .get_tx_csum = qeth_ethtool_get_tx_csum,
6562 .set_tx_csum = qeth_ethtool_set_tx_csum,
6563 .get_rx_csum = qeth_ethtool_get_rx_csum,
6564 .set_rx_csum = qeth_ethtool_set_rx_csum,
6565 .get_sg = qeth_ethtool_get_sg,
6566 .set_sg = qeth_ethtool_set_sg,
6567 .get_tso = qeth_ethtool_get_tso,
6568 .set_tso = qeth_ethtool_set_tso,
6572 qeth_hard_header_parse(const struct sk_buff *skb, unsigned char *haddr)
6574 const struct qeth_card *card;
6575 const struct ethhdr *eth;
6577 if (dev->type != ARPHRD_IEEE802_TR)
6580 card = qeth_get_card_from_dev(skb->dev);
6581 if (card->options.layer2)
6583 #ifdef CONFIG_QETH_IPV6
6584 /* cause of the manipulated arp constructor and the ARP
6585 flag for OSAE devices we have some nasty exceptions */
6586 if (card->info.type == QETH_CARD_TYPE_OSAE) {
6587 if (!card->options.fake_ll) {
6588 if ((skb->pkt_type==PACKET_OUTGOING) &&
6589 (skb->protocol==ETH_P_IPV6))
6594 if ((skb->pkt_type==PACKET_OUTGOING) &&
6595 (skb->protocol==ETH_P_IP))
6602 if (!card->options.fake_ll)
6606 memcpy(haddr, eth->h_source, ETH_ALEN);
6610 static const struct header_ops qeth_null_ops = {
6611 .parse = qeth_hard_header_parse,
6615 qeth_netdev_init(struct net_device *dev)
6617 struct qeth_card *card;
6619 card = (struct qeth_card *) dev->priv;
6621 QETH_DBF_TEXT(trace,3,"initdev");
6623 dev->tx_timeout = &qeth_tx_timeout;
6624 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6625 dev->open = qeth_open;
6626 dev->stop = qeth_stop;
6627 dev->hard_start_xmit = qeth_hard_start_xmit;
6628 dev->do_ioctl = qeth_do_ioctl;
6629 dev->get_stats = qeth_get_stats;
6630 dev->change_mtu = qeth_change_mtu;
6631 dev->neigh_setup = qeth_neigh_setup;
6632 dev->set_multicast_list = qeth_set_multicast_list;
6633 #ifdef CONFIG_QETH_VLAN
6634 dev->vlan_rx_register = qeth_vlan_rx_register;
6635 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6636 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6638 dev->header_ops = &qeth_null_ops;
6640 #ifdef CONFIG_QETH_IPV6
6641 /*IPv6 address autoconfiguration stuff*/
6642 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6643 card->dev->dev_id = card->info.unique_id & 0xffff;
6645 if (card->options.fake_ll &&
6646 (qeth_get_netdev_flags(card) & IFF_NOARP))
6647 dev->header_ops = &qeth_fake_ops;
6649 dev->set_mac_address = qeth_layer2_set_mac_address;
6650 dev->flags |= qeth_get_netdev_flags(card);
6651 if ((card->options.fake_broadcast) ||
6652 (card->info.broadcast_capable))
6653 dev->flags |= IFF_BROADCAST;
6654 dev->hard_header_len =
6655 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6656 dev->addr_len = OSA_ADDR_LEN;
6657 dev->mtu = card->info.initial_mtu;
6658 if (card->info.type != QETH_CARD_TYPE_OSN)
6659 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6664 qeth_init_func_level(struct qeth_card *card)
6666 if (card->ipato.enabled) {
6667 if (card->info.type == QETH_CARD_TYPE_IQD)
6668 card->info.func_level =
6669 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6671 card->info.func_level =
6672 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6674 if (card->info.type == QETH_CARD_TYPE_IQD)
6675 /*FIXME:why do we have same values for dis and ena for osae??? */
6676 card->info.func_level =
6677 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6679 card->info.func_level =
6680 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6685 * hardsetup card, initialize MPC and QDIO stuff
6688 qeth_hardsetup_card(struct qeth_card *card)
6693 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6695 atomic_set(&card->force_alloc_skb, 0);
6698 PRINT_WARN("Retrying to do IDX activates.\n");
6699 ccw_device_set_offline(CARD_DDEV(card));
6700 ccw_device_set_offline(CARD_WDEV(card));
6701 ccw_device_set_offline(CARD_RDEV(card));
6702 ccw_device_set_online(CARD_RDEV(card));
6703 ccw_device_set_online(CARD_WDEV(card));
6704 ccw_device_set_online(CARD_DDEV(card));
6706 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
6707 if (rc == -ERESTARTSYS) {
6708 QETH_DBF_TEXT(setup, 2, "break1");
6711 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6717 if ((rc = qeth_get_unitaddr(card))){
6718 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6721 qeth_init_tokens(card);
6722 qeth_init_func_level(card);
6723 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6724 if (rc == -ERESTARTSYS) {
6725 QETH_DBF_TEXT(setup, 2, "break2");
6728 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6734 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6735 if (rc == -ERESTARTSYS) {
6736 QETH_DBF_TEXT(setup, 2, "break3");
6739 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6745 if ((rc = qeth_mpc_initialize(card))){
6746 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6749 /*network device will be recovered*/
6751 card->dev->header_ops = card->orig_header_ops;
6752 if (card->options.fake_ll &&
6753 (qeth_get_netdev_flags(card) & IFF_NOARP))
6754 card->dev->header_ops = &qeth_fake_ops;
6757 /* at first set_online allocate netdev */
6758 card->dev = qeth_get_netdevice(card->info.type,
6759 card->info.link_type);
6761 qeth_qdio_clear_card(card, card->info.type !=
6762 QETH_CARD_TYPE_IQD);
6764 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6767 card->dev->priv = card;
6768 card->orig_header_ops = card->dev->header_ops;
6769 card->dev->type = qeth_get_arphdr_type(card->info.type,
6770 card->info.link_type);
6771 card->dev->init = qeth_netdev_init;
6774 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6779 qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6782 struct qeth_ipa_cmd *cmd;
6784 QETH_DBF_TEXT(trace,4,"defadpcb");
6786 cmd = (struct qeth_ipa_cmd *) data;
6787 if (cmd->hdr.return_code == 0){
6788 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6789 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6790 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6791 #ifdef CONFIG_QETH_IPV6
6792 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6793 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6796 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6797 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6798 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6799 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6805 qeth_default_setadapterparms_cb(struct qeth_card *card,
6806 struct qeth_reply *reply,
6809 struct qeth_ipa_cmd *cmd;
6811 QETH_DBF_TEXT(trace,4,"defadpcb");
6813 cmd = (struct qeth_ipa_cmd *) data;
6814 if (cmd->hdr.return_code == 0)
6815 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6822 qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6825 struct qeth_ipa_cmd *cmd;
6827 QETH_DBF_TEXT(trace,3,"quyadpcb");
6829 cmd = (struct qeth_ipa_cmd *) data;
6830 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6831 card->info.link_type =
6832 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6833 card->options.adp.supported_funcs =
6834 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6835 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6839 qeth_query_setadapterparms(struct qeth_card *card)
6842 struct qeth_cmd_buffer *iob;
6844 QETH_DBF_TEXT(trace,3,"queryadp");
6845 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6846 sizeof(struct qeth_ipacmd_setadpparms));
6847 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6852 qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6853 struct qeth_reply *reply,
6856 struct qeth_ipa_cmd *cmd;
6858 QETH_DBF_TEXT(trace,4,"chgmaccb");
6860 cmd = (struct qeth_ipa_cmd *) data;
6861 if (!card->options.layer2 ||
6862 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
6863 memcpy(card->dev->dev_addr,
6864 &cmd->data.setadapterparms.data.change_addr.addr,
6866 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6868 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6873 qeth_setadpparms_change_macaddr(struct qeth_card *card)
6876 struct qeth_cmd_buffer *iob;
6877 struct qeth_ipa_cmd *cmd;
6879 QETH_DBF_TEXT(trace,4,"chgmac");
6881 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6882 sizeof(struct qeth_ipacmd_setadpparms));
6883 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6884 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6885 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6886 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6887 card->dev->dev_addr, OSA_ADDR_LEN);
6888 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6894 qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6897 struct qeth_cmd_buffer *iob;
6898 struct qeth_ipa_cmd *cmd;
6900 QETH_DBF_TEXT(trace,4,"adpmode");
6902 iob = qeth_get_adapter_cmd(card, command,
6903 sizeof(struct qeth_ipacmd_setadpparms));
6904 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6905 cmd->data.setadapterparms.data.mode = mode;
6906 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6912 qeth_setadapter_hstr(struct qeth_card *card)
6916 QETH_DBF_TEXT(trace,4,"adphstr");
6918 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6919 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6920 card->options.broadcast_mode);
6922 PRINT_WARN("couldn't set broadcast mode on "
6924 CARD_BUS_ID(card), rc);
6925 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6926 card->options.macaddr_mode);
6928 PRINT_WARN("couldn't set macaddr mode on "
6929 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6932 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6933 PRINT_WARN("set adapter parameters not available "
6934 "to set broadcast mode, using ALLRINGS "
6935 "on device %s:\n", CARD_BUS_ID(card));
6936 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6937 PRINT_WARN("set adapter parameters not available "
6938 "to set macaddr mode, using NONCANONICAL "
6939 "on device %s:\n", CARD_BUS_ID(card));
6944 qeth_setadapter_parms(struct qeth_card *card)
6948 QETH_DBF_TEXT(setup, 2, "setadprm");
6950 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6951 PRINT_WARN("set adapter parameters not supported "
6954 QETH_DBF_TEXT(setup, 2, " notsupp");
6957 rc = qeth_query_setadapterparms(card);
6959 PRINT_WARN("couldn't set adapter parameters on device %s: "
6960 "x%x\n", CARD_BUS_ID(card), rc);
6963 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6964 rc = qeth_setadpparms_change_macaddr(card);
6966 PRINT_WARN("couldn't get MAC address on "
6968 CARD_BUS_ID(card), rc);
6971 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6972 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6973 rc = qeth_setadapter_hstr(card);
6979 qeth_layer2_initialize(struct qeth_card *card)
6984 QETH_DBF_TEXT(setup, 2, "doL2init");
6985 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6987 rc = qeth_query_setadapterparms(card);
6989 PRINT_WARN("could not query adapter parameters on device %s: "
6990 "x%x\n", CARD_BUS_ID(card), rc);
6993 rc = qeth_setadpparms_change_macaddr(card);
6995 PRINT_WARN("couldn't get MAC address on "
6997 CARD_BUS_ID(card), rc);
6998 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
7001 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
7003 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
7005 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
7011 qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
7012 enum qeth_prot_versions prot)
7015 struct qeth_cmd_buffer *iob;
7017 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
7018 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7024 qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
7028 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
7030 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
7035 qeth_send_stoplan(struct qeth_card *card)
7040 * TODO: according to the IPA format document page 14,
7041 * TCP/IP (we!) never issue a STOPLAN
7044 QETH_DBF_TEXT(trace, 2, "stoplan");
7046 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
7051 qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
7054 struct qeth_ipa_cmd *cmd;
7056 QETH_DBF_TEXT(setup, 2, "qipasscb");
7058 cmd = (struct qeth_ipa_cmd *) data;
7059 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
7060 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
7061 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
7062 /* Disable IPV6 support hard coded for Hipersockets */
7063 if(card->info.type == QETH_CARD_TYPE_IQD)
7064 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
7066 #ifdef CONFIG_QETH_IPV6
7067 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
7068 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
7071 QETH_DBF_TEXT(setup, 2, "suppenbl");
7072 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
7073 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
7078 qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
7081 struct qeth_cmd_buffer *iob;
7083 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
7084 if (card->options.layer2) {
7085 QETH_DBF_TEXT(setup, 2, "noprmly2");
7089 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
7090 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
7094 static struct qeth_cmd_buffer *
7095 qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
7096 __u16 cmd_code, __u16 len,
7097 enum qeth_prot_versions prot)
7099 struct qeth_cmd_buffer *iob;
7100 struct qeth_ipa_cmd *cmd;
7102 QETH_DBF_TEXT(trace,4,"getasscm");
7103 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
7105 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7106 cmd->data.setassparms.hdr.assist_no = ipa_func;
7107 cmd->data.setassparms.hdr.length = 8 + len;
7108 cmd->data.setassparms.hdr.command_code = cmd_code;
7109 cmd->data.setassparms.hdr.return_code = 0;
7110 cmd->data.setassparms.hdr.seq_no = 0;
7116 qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
7117 __u16 len, long data,
7119 (struct qeth_card *,struct qeth_reply *,unsigned long),
7123 struct qeth_ipa_cmd *cmd;
7125 QETH_DBF_TEXT(trace,4,"sendassp");
7127 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7128 if (len <= sizeof(__u32))
7129 cmd->data.setassparms.data.flags_32bit = (__u32) data;
7130 else /* (len > sizeof(__u32)) */
7131 memcpy(&cmd->data.setassparms.data, (void *) data, len);
7133 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
7137 #ifdef CONFIG_QETH_IPV6
7139 qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
7140 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
7144 struct qeth_cmd_buffer *iob;
7146 QETH_DBF_TEXT(trace,4,"simassp6");
7147 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
7149 rc = qeth_send_setassparms(card, iob, 0, 0,
7150 qeth_default_setassparms_cb, NULL);
7156 qeth_send_simple_setassparms(struct qeth_card *card,
7157 enum qeth_ipa_funcs ipa_func,
7158 __u16 cmd_code, long data)
7162 struct qeth_cmd_buffer *iob;
7164 QETH_DBF_TEXT(trace,4,"simassp4");
7166 length = sizeof(__u32);
7167 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
7168 length, QETH_PROT_IPV4);
7169 rc = qeth_send_setassparms(card, iob, length, data,
7170 qeth_default_setassparms_cb, NULL);
7175 qeth_start_ipa_arp_processing(struct qeth_card *card)
7179 QETH_DBF_TEXT(trace,3,"ipaarp");
7181 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
7182 PRINT_WARN("ARP processing not supported "
7183 "on %s!\n", QETH_CARD_IFNAME(card));
7186 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
7187 IPA_CMD_ASS_START, 0);
7189 PRINT_WARN("Could not start ARP processing "
7190 "assist on %s: 0x%x\n",
7191 QETH_CARD_IFNAME(card), rc);
7197 qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
7201 QETH_DBF_TEXT(trace,3,"ipaipfrg");
7203 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
7204 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
7205 QETH_CARD_IFNAME(card));
7209 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
7210 IPA_CMD_ASS_START, 0);
7212 PRINT_WARN("Could not start Hardware IP fragmentation "
7213 "assist on %s: 0x%x\n",
7214 QETH_CARD_IFNAME(card), rc);
7216 PRINT_INFO("Hardware IP fragmentation enabled \n");
7221 qeth_start_ipa_source_mac(struct qeth_card *card)
7225 QETH_DBF_TEXT(trace,3,"stsrcmac");
7227 if (!card->options.fake_ll)
7230 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
7231 PRINT_INFO("Inbound source address not "
7232 "supported on %s\n", QETH_CARD_IFNAME(card));
7236 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
7237 IPA_CMD_ASS_START, 0);
7239 PRINT_WARN("Could not start inbound source "
7240 "assist on %s: 0x%x\n",
7241 QETH_CARD_IFNAME(card), rc);
7246 qeth_start_ipa_vlan(struct qeth_card *card)
7250 QETH_DBF_TEXT(trace,3,"strtvlan");
7252 #ifdef CONFIG_QETH_VLAN
7253 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
7254 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
7258 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
7259 IPA_CMD_ASS_START,0);
7261 PRINT_WARN("Could not start vlan "
7262 "assist on %s: 0x%x\n",
7263 QETH_CARD_IFNAME(card), rc);
7265 PRINT_INFO("VLAN enabled \n");
7266 card->dev->features |=
7267 NETIF_F_HW_VLAN_FILTER |
7268 NETIF_F_HW_VLAN_TX |
7271 #endif /* QETH_VLAN */
7276 qeth_start_ipa_multicast(struct qeth_card *card)
7280 QETH_DBF_TEXT(trace,3,"stmcast");
7282 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7283 PRINT_WARN("Multicast not supported on %s\n",
7284 QETH_CARD_IFNAME(card));
7288 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7289 IPA_CMD_ASS_START,0);
7291 PRINT_WARN("Could not start multicast "
7292 "assist on %s: rc=%i\n",
7293 QETH_CARD_IFNAME(card), rc);
7295 PRINT_INFO("Multicast enabled\n");
7296 card->dev->flags |= IFF_MULTICAST;
7301 #ifdef CONFIG_QETH_IPV6
7303 qeth_softsetup_ipv6(struct qeth_card *card)
7307 QETH_DBF_TEXT(trace,3,"softipv6");
7309 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7311 PRINT_ERR("IPv6 startlan failed on %s\n",
7312 QETH_CARD_IFNAME(card));
7315 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7317 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7318 QETH_CARD_IFNAME(card));
7321 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7322 IPA_CMD_ASS_START, 3);
7324 PRINT_WARN("IPv6 start assist (version 4) failed "
7326 QETH_CARD_IFNAME(card), rc);
7329 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7332 PRINT_WARN("IPV6 start assist (version 6) failed "
7334 QETH_CARD_IFNAME(card), rc);
7337 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7340 PRINT_WARN("Could not enable passthrough "
7342 QETH_CARD_IFNAME(card), rc);
7345 PRINT_INFO("IPV6 enabled \n");
7352 qeth_start_ipa_ipv6(struct qeth_card *card)
7355 #ifdef CONFIG_QETH_IPV6
7356 QETH_DBF_TEXT(trace,3,"strtipv6");
7358 if (!qeth_is_supported(card, IPA_IPV6)) {
7359 PRINT_WARN("IPv6 not supported on %s\n",
7360 QETH_CARD_IFNAME(card));
7363 rc = qeth_softsetup_ipv6(card);
7369 qeth_start_ipa_broadcast(struct qeth_card *card)
7373 QETH_DBF_TEXT(trace,3,"stbrdcst");
7374 card->info.broadcast_capable = 0;
7375 if (!qeth_is_supported(card, IPA_FILTERING)) {
7376 PRINT_WARN("Broadcast not supported on %s\n",
7377 QETH_CARD_IFNAME(card));
7381 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7382 IPA_CMD_ASS_START, 0);
7384 PRINT_WARN("Could not enable broadcasting filtering "
7386 QETH_CARD_IFNAME(card), rc);
7390 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7391 IPA_CMD_ASS_CONFIGURE, 1);
7393 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7394 QETH_CARD_IFNAME(card), rc);
7397 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7398 PRINT_INFO("Broadcast enabled \n");
7399 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7400 IPA_CMD_ASS_ENABLE, 1);
7402 PRINT_WARN("Could not set up broadcast echo filtering on "
7403 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7406 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7408 if (card->info.broadcast_capable)
7409 card->dev->flags |= IFF_BROADCAST;
7411 card->dev->flags &= ~IFF_BROADCAST;
7416 qeth_send_checksum_command(struct qeth_card *card)
7420 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7421 IPA_CMD_ASS_START, 0);
7423 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7424 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7425 QETH_CARD_IFNAME(card), rc);
7428 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7430 card->info.csum_mask);
7432 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7433 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7434 QETH_CARD_IFNAME(card), rc);
7441 qeth_start_ipa_checksum(struct qeth_card *card)
7445 QETH_DBF_TEXT(trace,3,"strtcsum");
7447 if (card->options.checksum_type == NO_CHECKSUMMING) {
7448 PRINT_WARN("Using no checksumming on %s.\n",
7449 QETH_CARD_IFNAME(card));
7452 if (card->options.checksum_type == SW_CHECKSUMMING) {
7453 PRINT_WARN("Using SW checksumming on %s.\n",
7454 QETH_CARD_IFNAME(card));
7457 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7458 PRINT_WARN("Inbound HW Checksumming not "
7459 "supported on %s,\ncontinuing "
7460 "using Inbound SW Checksumming\n",
7461 QETH_CARD_IFNAME(card));
7462 card->options.checksum_type = SW_CHECKSUMMING;
7465 rc = qeth_send_checksum_command(card);
7467 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7473 qeth_start_ipa_tso(struct qeth_card *card)
7477 QETH_DBF_TEXT(trace,3,"sttso");
7479 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7480 PRINT_WARN("Outbound TSO not supported on %s\n",
7481 QETH_CARD_IFNAME(card));
7484 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7485 IPA_CMD_ASS_START,0);
7487 PRINT_WARN("Could not start outbound TSO "
7488 "assist on %s: rc=%i\n",
7489 QETH_CARD_IFNAME(card), rc);
7491 PRINT_INFO("Outbound TSO enabled\n");
7493 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7494 card->options.large_send = QETH_LARGE_SEND_NO;
7495 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
7502 qeth_start_ipassists(struct qeth_card *card)
7504 QETH_DBF_TEXT(trace,3,"strtipas");
7505 qeth_start_ipa_arp_processing(card); /* go on*/
7506 qeth_start_ipa_ip_fragmentation(card); /* go on*/
7507 qeth_start_ipa_source_mac(card); /* go on*/
7508 qeth_start_ipa_vlan(card); /* go on*/
7509 qeth_start_ipa_multicast(card); /* go on*/
7510 qeth_start_ipa_ipv6(card); /* go on*/
7511 qeth_start_ipa_broadcast(card); /* go on*/
7512 qeth_start_ipa_checksum(card); /* go on*/
7513 qeth_start_ipa_tso(card); /* go on*/
7518 qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7519 enum qeth_prot_versions prot)
7522 struct qeth_ipa_cmd *cmd;
7523 struct qeth_cmd_buffer *iob;
7525 QETH_DBF_TEXT(trace,4,"setroutg");
7526 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7527 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7528 cmd->data.setrtg.type = (type);
7529 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7536 qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7537 enum qeth_prot_versions prot)
7539 if (card->info.type == QETH_CARD_TYPE_IQD) {
7542 case PRIMARY_CONNECTOR:
7543 case SECONDARY_CONNECTOR:
7544 case MULTICAST_ROUTER:
7552 case PRIMARY_ROUTER:
7553 case SECONDARY_ROUTER:
7555 case MULTICAST_ROUTER:
7556 if (qeth_is_ipafunc_supported(card, prot,
7564 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7565 "Router status set to 'no router'.\n",
7566 ((*type == PRIMARY_ROUTER)? "primary router" :
7567 (*type == SECONDARY_ROUTER)? "secondary router" :
7568 (*type == PRIMARY_CONNECTOR)? "primary connector" :
7569 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7570 (*type == MULTICAST_ROUTER)? "multicast router" :
7577 qeth_setrouting_v4(struct qeth_card *card)
7581 QETH_DBF_TEXT(trace,3,"setrtg4");
7583 qeth_correct_routing_type(card, &card->options.route4.type,
7586 rc = qeth_send_setrouting(card, card->options.route4.type,
7589 card->options.route4.type = NO_ROUTER;
7590 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7591 "Type set to 'no router'.\n",
7592 rc, QETH_CARD_IFNAME(card));
7598 qeth_setrouting_v6(struct qeth_card *card)
7602 QETH_DBF_TEXT(trace,3,"setrtg6");
7603 #ifdef CONFIG_QETH_IPV6
7605 if (!qeth_is_supported(card, IPA_IPV6))
7607 qeth_correct_routing_type(card, &card->options.route6.type,
7610 rc = qeth_send_setrouting(card, card->options.route6.type,
7613 card->options.route6.type = NO_ROUTER;
7614 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7615 "Type set to 'no router'.\n",
7616 rc, QETH_CARD_IFNAME(card));
7623 qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
7627 if (card->dev == NULL) {
7628 card->options.large_send = type;
7631 if (card->state == CARD_STATE_UP)
7632 netif_tx_disable(card->dev);
7633 card->options.large_send = type;
7634 switch (card->options.large_send) {
7635 case QETH_LARGE_SEND_EDDP:
7636 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
7639 case QETH_LARGE_SEND_TSO:
7640 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7641 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
7644 PRINT_WARN("TSO not supported on %s. "
7645 "large_send set to 'no'.\n",
7647 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
7649 card->options.large_send = QETH_LARGE_SEND_NO;
7653 default: /* includes QETH_LARGE_SEND_NO */
7654 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
7658 if (card->state == CARD_STATE_UP)
7659 netif_wake_queue(card->dev);
7664 * softsetup card: init IPA stuff
7667 qeth_softsetup_card(struct qeth_card *card)
7671 QETH_DBF_TEXT(setup, 2, "softsetp");
7673 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7674 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7676 PRINT_WARN("LAN on card %s if offline! "
7677 "Waiting for STARTLAN from card.\n",
7679 card->lan_online = 0;
7683 card->lan_online = 1;
7684 if (card->info.type==QETH_CARD_TYPE_OSN)
7686 qeth_set_large_send(card, card->options.large_send);
7687 if (card->options.layer2) {
7688 card->dev->features |=
7689 NETIF_F_HW_VLAN_FILTER |
7690 NETIF_F_HW_VLAN_TX |
7692 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7693 card->info.broadcast_capable=1;
7694 if ((rc = qeth_layer2_initialize(card))) {
7695 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7698 #ifdef CONFIG_QETH_VLAN
7699 qeth_layer2_process_vlans(card, 0);
7703 if ((rc = qeth_setadapter_parms(card)))
7704 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7705 if ((rc = qeth_start_ipassists(card)))
7706 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7707 if ((rc = qeth_setrouting_v4(card)))
7708 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7709 if ((rc = qeth_setrouting_v6(card)))
7710 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7712 netif_tx_disable(card->dev);
7716 #ifdef CONFIG_QETH_IPV6
7718 qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7721 struct qeth_ipa_cmd *cmd;
7723 cmd = (struct qeth_ipa_cmd *) data;
7724 if (cmd->hdr.return_code == 0)
7725 card->info.unique_id = *((__u16 *)
7726 &cmd->data.create_destroy_addr.unique_id[6]);
7728 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7729 UNIQUE_ID_NOT_BY_CARD;
7730 PRINT_WARN("couldn't get a unique id from the card on device "
7731 "%s (result=x%x), using default id. ipv6 "
7732 "autoconfig on other lpars may lead to duplicate "
7733 "ip addresses. please use manually "
7734 "configured ones.\n",
7735 CARD_BUS_ID(card), cmd->hdr.return_code);
7742 qeth_put_unique_id(struct qeth_card *card)
7746 #ifdef CONFIG_QETH_IPV6
7747 struct qeth_cmd_buffer *iob;
7748 struct qeth_ipa_cmd *cmd;
7750 QETH_DBF_TEXT(trace,2,"puniqeid");
7752 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7753 UNIQUE_ID_NOT_BY_CARD)
7755 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7757 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7758 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7759 card->info.unique_id;
7760 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7761 card->dev->dev_addr, OSA_ADDR_LEN);
7762 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7764 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7765 UNIQUE_ID_NOT_BY_CARD;
7774 qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7776 struct qeth_ipaddr *addr, *tmp;
7777 unsigned long flags;
7779 QETH_DBF_TEXT(trace,4,"clearip");
7780 spin_lock_irqsave(&card->ip_lock, flags);
7781 /* clear todo list */
7782 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7783 list_del(&addr->entry);
7787 while (!list_empty(&card->ip_list)) {
7788 addr = list_entry(card->ip_list.next,
7789 struct qeth_ipaddr, entry);
7790 list_del_init(&addr->entry);
7792 spin_unlock_irqrestore(&card->ip_lock, flags);
7793 qeth_deregister_addr_entry(card, addr);
7794 spin_lock_irqsave(&card->ip_lock, flags);
7796 if (!recover || addr->is_multicast) {
7800 list_add_tail(&addr->entry, card->ip_tbd_list);
7802 spin_unlock_irqrestore(&card->ip_lock, flags);
7806 qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7807 int clear_start_mask)
7809 unsigned long flags;
7811 spin_lock_irqsave(&card->thread_mask_lock, flags);
7812 card->thread_allowed_mask = threads;
7813 if (clear_start_mask)
7814 card->thread_start_mask &= threads;
7815 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7816 wake_up(&card->wait_q);
7820 qeth_threads_running(struct qeth_card *card, unsigned long threads)
7822 unsigned long flags;
7825 spin_lock_irqsave(&card->thread_mask_lock, flags);
7826 rc = (card->thread_running_mask & threads);
7827 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7832 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7834 return wait_event_interruptible(card->wait_q,
7835 qeth_threads_running(card, threads) == 0);
7839 qeth_stop_card(struct qeth_card *card, int recovery_mode)
7843 QETH_DBF_TEXT(setup ,2,"stopcard");
7844 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7846 qeth_set_allowed_threads(card, 0, 1);
7847 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7848 return -ERESTARTSYS;
7849 if (card->read.state == CH_STATE_UP &&
7850 card->write.state == CH_STATE_UP &&
7851 (card->state == CARD_STATE_UP)) {
7852 if (recovery_mode &&
7853 card->info.type != QETH_CARD_TYPE_OSN) {
7854 qeth_stop(card->dev);
7857 dev_close(card->dev);
7860 if (!card->use_hard_stop) {
7861 __u8 *mac = &card->dev->dev_addr[0];
7862 rc = qeth_layer2_send_delmac(card, mac);
7863 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7864 if ((rc = qeth_send_stoplan(card)))
7865 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7867 card->state = CARD_STATE_SOFTSETUP;
7869 if (card->state == CARD_STATE_SOFTSETUP) {
7870 #ifdef CONFIG_QETH_VLAN
7871 if (card->options.layer2)
7872 qeth_layer2_process_vlans(card, 1);
7874 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7875 qeth_clear_ipacmd_list(card);
7876 card->state = CARD_STATE_HARDSETUP;
7878 if (card->state == CARD_STATE_HARDSETUP) {
7879 if ((!card->use_hard_stop) &&
7880 (!card->options.layer2))
7881 if ((rc = qeth_put_unique_id(card)))
7882 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7883 qeth_qdio_clear_card(card, 0);
7884 qeth_clear_qdio_buffers(card);
7885 qeth_clear_working_pool_list(card);
7886 card->state = CARD_STATE_DOWN;
7888 if (card->state == CARD_STATE_DOWN) {
7889 qeth_clear_cmd_buffers(&card->read);
7890 qeth_clear_cmd_buffers(&card->write);
7892 card->use_hard_stop = 0;
7898 qeth_get_unique_id(struct qeth_card *card)
7901 #ifdef CONFIG_QETH_IPV6
7902 struct qeth_cmd_buffer *iob;
7903 struct qeth_ipa_cmd *cmd;
7905 QETH_DBF_TEXT(setup, 2, "guniqeid");
7907 if (!qeth_is_supported(card,IPA_IPV6)) {
7908 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7909 UNIQUE_ID_NOT_BY_CARD;
7913 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7915 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7916 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7917 card->info.unique_id;
7919 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7921 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7922 UNIQUE_ID_NOT_BY_CARD;
7927 qeth_print_status_with_portname(struct qeth_card *card)
7932 sprintf(dbf_text, "%s", card->info.portname + 1);
7933 for (i = 0; i < 8; i++)
7935 (char) _ebcasc[(__u8) dbf_text[i]];
7937 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7938 "with link type %s (portname: %s)\n",
7942 qeth_get_cardname(card),
7943 (card->info.mcl_level[0]) ? " (level: " : "",
7944 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7945 (card->info.mcl_level[0]) ? ")" : "",
7946 qeth_get_cardname_short(card),
7952 qeth_print_status_no_portname(struct qeth_card *card)
7954 if (card->info.portname[0])
7955 printk("qeth: Device %s/%s/%s is a%s "
7956 "card%s%s%s\nwith link type %s "
7957 "(no portname needed by interface).\n",
7961 qeth_get_cardname(card),
7962 (card->info.mcl_level[0]) ? " (level: " : "",
7963 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7964 (card->info.mcl_level[0]) ? ")" : "",
7965 qeth_get_cardname_short(card));
7967 printk("qeth: Device %s/%s/%s is a%s "
7968 "card%s%s%s\nwith link type %s.\n",
7972 qeth_get_cardname(card),
7973 (card->info.mcl_level[0]) ? " (level: " : "",
7974 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7975 (card->info.mcl_level[0]) ? ")" : "",
7976 qeth_get_cardname_short(card));
7980 qeth_print_status_message(struct qeth_card *card)
7982 switch (card->info.type) {
7983 case QETH_CARD_TYPE_OSAE:
7984 /* VM will use a non-zero first character
7985 * to indicate a HiperSockets like reporting
7986 * of the level OSA sets the first character to zero
7988 if (!card->info.mcl_level[0]) {
7989 sprintf(card->info.mcl_level,"%02x%02x",
7990 card->info.mcl_level[2],
7991 card->info.mcl_level[3]);
7993 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7997 case QETH_CARD_TYPE_IQD:
7998 if (card->info.guestlan) {
7999 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
8000 card->info.mcl_level[0]];
8001 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
8002 card->info.mcl_level[1]];
8003 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
8004 card->info.mcl_level[2]];
8005 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
8006 card->info.mcl_level[3]];
8007 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
8011 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
8013 if (card->info.portname_required)
8014 qeth_print_status_with_portname(card);
8016 qeth_print_status_no_portname(card);
8020 qeth_register_netdev(struct qeth_card *card)
8022 QETH_DBF_TEXT(setup, 3, "regnetd");
8023 if (card->dev->reg_state != NETREG_UNINITIALIZED)
8026 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
8027 return register_netdev(card->dev);
8031 qeth_start_again(struct qeth_card *card, int recovery_mode)
8033 QETH_DBF_TEXT(setup ,2, "startag");
8035 if (recovery_mode &&
8036 card->info.type != QETH_CARD_TYPE_OSN) {
8037 qeth_open(card->dev);
8040 dev_open(card->dev);
8043 /* this also sets saved unicast addresses */
8044 qeth_set_multicast_list(card->dev);
8048 /* Layer 2 specific stuff */
8049 #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
8050 if (card->options.option == value) { \
8051 PRINT_ERR("%s not supported with layer 2 " \
8052 "functionality, ignoring option on read" \
8053 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
8054 card->options.option = reset_value; \
8056 #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
8057 if (card->options.option != value) { \
8058 PRINT_ERR("%s not supported with layer 2 " \
8059 "functionality, ignoring option on read" \
8060 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
8061 card->options.option = reset_value; \
8065 static void qeth_make_parameters_consistent(struct qeth_card *card)
8068 if (card->options.layer2 == 0)
8070 if (card->info.type == QETH_CARD_TYPE_OSN)
8072 if (card->info.type == QETH_CARD_TYPE_IQD) {
8073 PRINT_ERR("Device %s does not support layer 2 functionality." \
8074 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
8075 card->options.layer2 = 0;
8078 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
8079 "Routing options are");
8080 #ifdef CONFIG_QETH_IPV6
8081 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
8082 "Routing options are");
8084 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
8085 QETH_CHECKSUM_DEFAULT,
8086 "Checksumming options are");
8087 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
8088 QETH_TR_BROADCAST_ALLRINGS,
8089 "Broadcast mode options are");
8090 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
8091 QETH_TR_MACADDR_NONCANONICAL,
8092 "Canonical MAC addr options are");
8093 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
8094 "Broadcast faking options are");
8095 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
8096 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
8097 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
8102 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
8104 struct qeth_card *card = gdev->dev.driver_data;
8106 enum qeth_card_states recover_flag;
8109 QETH_DBF_TEXT(setup ,2, "setonlin");
8110 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
8112 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
8113 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
8114 PRINT_WARN("set_online of card %s interrupted by user!\n",
8116 return -ERESTARTSYS;
8119 recover_flag = card->state;
8120 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
8121 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
8122 (rc = ccw_device_set_online(CARD_DDEV(card)))){
8123 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
8127 qeth_make_parameters_consistent(card);
8129 if ((rc = qeth_hardsetup_card(card))){
8130 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
8133 card->state = CARD_STATE_HARDSETUP;
8135 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
8136 rc = qeth_get_unique_id(card);
8138 if (rc && card->options.layer2 == 0) {
8139 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
8142 qeth_print_status_message(card);
8143 if ((rc = qeth_register_netdev(card))){
8144 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
8147 if ((rc = qeth_softsetup_card(card))){
8148 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
8152 if ((rc = qeth_init_qdio_queues(card))){
8153 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
8156 card->state = CARD_STATE_SOFTSETUP;
8157 netif_carrier_on(card->dev);
8159 qeth_set_allowed_threads(card, 0xffffffff, 0);
8160 if (recover_flag == CARD_STATE_RECOVER)
8161 qeth_start_again(card, recovery_mode);
8162 qeth_notify_processes();
8165 card->use_hard_stop = 1;
8166 qeth_stop_card(card, 0);
8167 ccw_device_set_offline(CARD_DDEV(card));
8168 ccw_device_set_offline(CARD_WDEV(card));
8169 ccw_device_set_offline(CARD_RDEV(card));
8170 if (recover_flag == CARD_STATE_RECOVER)
8171 card->state = CARD_STATE_RECOVER;
8173 card->state = CARD_STATE_DOWN;
8178 qeth_set_online(struct ccwgroup_device *gdev)
8180 return __qeth_set_online(gdev, 0);
8183 static struct ccw_device_id qeth_ids[] = {
8184 {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
8185 {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
8186 {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
8189 MODULE_DEVICE_TABLE(ccw, qeth_ids);
8191 struct device *qeth_root_dev = NULL;
8193 struct ccwgroup_driver qeth_ccwgroup_driver = {
8194 .owner = THIS_MODULE,
8196 .driver_id = 0xD8C5E3C8,
8197 .probe = qeth_probe_device,
8198 .remove = qeth_remove_device,
8199 .set_online = qeth_set_online,
8200 .set_offline = qeth_set_offline,
8203 struct ccw_driver qeth_ccw_driver = {
8206 .probe = ccwgroup_probe_ccwdev,
8207 .remove = ccwgroup_remove_ccwdev,
8212 qeth_unregister_dbf_views(void)
8215 debug_unregister(qeth_dbf_setup);
8217 debug_unregister(qeth_dbf_qerr);
8219 debug_unregister(qeth_dbf_sense);
8221 debug_unregister(qeth_dbf_misc);
8223 debug_unregister(qeth_dbf_data);
8224 if (qeth_dbf_control)
8225 debug_unregister(qeth_dbf_control);
8227 debug_unregister(qeth_dbf_trace);
8230 qeth_register_dbf_views(void)
8232 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
8233 QETH_DBF_SETUP_PAGES,
8234 QETH_DBF_SETUP_NR_AREAS,
8235 QETH_DBF_SETUP_LEN);
8236 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
8237 QETH_DBF_MISC_PAGES,
8238 QETH_DBF_MISC_NR_AREAS,
8240 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
8241 QETH_DBF_DATA_PAGES,
8242 QETH_DBF_DATA_NR_AREAS,
8244 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
8245 QETH_DBF_CONTROL_PAGES,
8246 QETH_DBF_CONTROL_NR_AREAS,
8247 QETH_DBF_CONTROL_LEN);
8248 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
8249 QETH_DBF_SENSE_PAGES,
8250 QETH_DBF_SENSE_NR_AREAS,
8251 QETH_DBF_SENSE_LEN);
8252 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
8253 QETH_DBF_QERR_PAGES,
8254 QETH_DBF_QERR_NR_AREAS,
8256 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
8257 QETH_DBF_TRACE_PAGES,
8258 QETH_DBF_TRACE_NR_AREAS,
8259 QETH_DBF_TRACE_LEN);
8261 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
8262 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
8263 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
8264 (qeth_dbf_trace == NULL)) {
8265 qeth_unregister_dbf_views();
8268 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
8269 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
8271 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
8272 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
8274 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
8275 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
8277 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
8278 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
8280 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
8281 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8283 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8284 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8286 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8287 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8292 #ifdef CONFIG_QETH_IPV6
8293 extern struct neigh_table arp_tbl;
8294 static struct neigh_ops *arp_direct_ops;
8295 static int (*qeth_old_arp_constructor) (struct neighbour *);
8297 static struct neigh_ops arp_direct_ops_template = {
8300 .error_report = NULL,
8301 .output = dev_queue_xmit,
8302 .connected_output = dev_queue_xmit,
8303 .hh_output = dev_queue_xmit,
8304 .queue_xmit = dev_queue_xmit
8308 qeth_arp_constructor(struct neighbour *neigh)
8310 struct net_device *dev = neigh->dev;
8311 struct in_device *in_dev;
8312 struct neigh_parms *parms;
8313 struct qeth_card *card;
8315 card = qeth_get_card_from_dev(dev);
8318 if((card->options.layer2) ||
8319 (card->dev->header_ops == &qeth_fake_ops))
8323 in_dev = __in_dev_get_rcu(dev);
8324 if (in_dev == NULL) {
8329 parms = in_dev->arp_parms;
8330 __neigh_parms_put(neigh->parms);
8331 neigh->parms = neigh_parms_clone(parms);
8334 neigh->type = inet_addr_type(*(__be32 *) neigh->primary_key);
8335 neigh->nud_state = NUD_NOARP;
8336 neigh->ops = arp_direct_ops;
8337 neigh->output = neigh->ops->queue_xmit;
8340 return qeth_old_arp_constructor(neigh);
8342 #endif /*CONFIG_QETH_IPV6*/
8345 * IP address takeover related functions
8348 qeth_clear_ipato_list(struct qeth_card *card)
8350 struct qeth_ipato_entry *ipatoe, *tmp;
8351 unsigned long flags;
8353 spin_lock_irqsave(&card->ip_lock, flags);
8354 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8355 list_del(&ipatoe->entry);
8358 spin_unlock_irqrestore(&card->ip_lock, flags);
8362 qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8364 struct qeth_ipato_entry *ipatoe;
8365 unsigned long flags;
8368 QETH_DBF_TEXT(trace, 2, "addipato");
8369 spin_lock_irqsave(&card->ip_lock, flags);
8370 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8371 if (ipatoe->proto != new->proto)
8373 if (!memcmp(ipatoe->addr, new->addr,
8374 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8375 (ipatoe->mask_bits == new->mask_bits)){
8376 PRINT_WARN("ipato entry already exists!\n");
8382 list_add_tail(&new->entry, &card->ipato.entries);
8384 spin_unlock_irqrestore(&card->ip_lock, flags);
8389 qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8390 u8 *addr, int mask_bits)
8392 struct qeth_ipato_entry *ipatoe, *tmp;
8393 unsigned long flags;
8395 QETH_DBF_TEXT(trace, 2, "delipato");
8396 spin_lock_irqsave(&card->ip_lock, flags);
8397 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8398 if (ipatoe->proto != proto)
8400 if (!memcmp(ipatoe->addr, addr,
8401 (proto == QETH_PROT_IPV4)? 4:16) &&
8402 (ipatoe->mask_bits == mask_bits)){
8403 list_del(&ipatoe->entry);
8407 spin_unlock_irqrestore(&card->ip_lock, flags);
8411 qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8416 for (i = 0; i < len; ++i){
8418 for (j = 7; j >= 0; --j){
8419 bits[i*8 + j] = octet & 1;
8426 qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8428 struct qeth_ipato_entry *ipatoe;
8429 u8 addr_bits[128] = {0, };
8430 u8 ipatoe_bits[128] = {0, };
8433 if (!card->ipato.enabled)
8436 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8437 (addr->proto == QETH_PROT_IPV4)? 4:16);
8438 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8439 if (addr->proto != ipatoe->proto)
8441 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8442 (ipatoe->proto==QETH_PROT_IPV4) ?
8444 if (addr->proto == QETH_PROT_IPV4)
8445 rc = !memcmp(addr_bits, ipatoe_bits,
8446 min(32, ipatoe->mask_bits));
8448 rc = !memcmp(addr_bits, ipatoe_bits,
8449 min(128, ipatoe->mask_bits));
8454 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8456 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8463 * VIPA related functions
8466 qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8469 struct qeth_ipaddr *ipaddr;
8470 unsigned long flags;
8473 ipaddr = qeth_get_addr_buffer(proto);
8475 if (proto == QETH_PROT_IPV4){
8476 QETH_DBF_TEXT(trace, 2, "addvipa4");
8477 memcpy(&ipaddr->u.a4.addr, addr, 4);
8478 ipaddr->u.a4.mask = 0;
8479 #ifdef CONFIG_QETH_IPV6
8480 } else if (proto == QETH_PROT_IPV6){
8481 QETH_DBF_TEXT(trace, 2, "addvipa6");
8482 memcpy(&ipaddr->u.a6.addr, addr, 16);
8483 ipaddr->u.a6.pfxlen = 0;
8486 ipaddr->type = QETH_IP_TYPE_VIPA;
8487 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8488 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8491 spin_lock_irqsave(&card->ip_lock, flags);
8492 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8493 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8495 spin_unlock_irqrestore(&card->ip_lock, flags);
8497 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8500 if (!qeth_add_ip(card, ipaddr))
8502 qeth_set_ip_addr_list(card);
8507 qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8510 struct qeth_ipaddr *ipaddr;
8512 ipaddr = qeth_get_addr_buffer(proto);
8514 if (proto == QETH_PROT_IPV4){
8515 QETH_DBF_TEXT(trace, 2, "delvipa4");
8516 memcpy(&ipaddr->u.a4.addr, addr, 4);
8517 ipaddr->u.a4.mask = 0;
8518 #ifdef CONFIG_QETH_IPV6
8519 } else if (proto == QETH_PROT_IPV6){
8520 QETH_DBF_TEXT(trace, 2, "delvipa6");
8521 memcpy(&ipaddr->u.a6.addr, addr, 16);
8522 ipaddr->u.a6.pfxlen = 0;
8525 ipaddr->type = QETH_IP_TYPE_VIPA;
8528 if (!qeth_delete_ip(card, ipaddr))
8530 qeth_set_ip_addr_list(card);
8534 * proxy ARP related functions
8537 qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8540 struct qeth_ipaddr *ipaddr;
8541 unsigned long flags;
8544 ipaddr = qeth_get_addr_buffer(proto);
8546 if (proto == QETH_PROT_IPV4){
8547 QETH_DBF_TEXT(trace, 2, "addrxip4");
8548 memcpy(&ipaddr->u.a4.addr, addr, 4);
8549 ipaddr->u.a4.mask = 0;
8550 #ifdef CONFIG_QETH_IPV6
8551 } else if (proto == QETH_PROT_IPV6){
8552 QETH_DBF_TEXT(trace, 2, "addrxip6");
8553 memcpy(&ipaddr->u.a6.addr, addr, 16);
8554 ipaddr->u.a6.pfxlen = 0;
8557 ipaddr->type = QETH_IP_TYPE_RXIP;
8558 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8559 ipaddr->del_flags = 0;
8562 spin_lock_irqsave(&card->ip_lock, flags);
8563 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8564 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8566 spin_unlock_irqrestore(&card->ip_lock, flags);
8568 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8571 if (!qeth_add_ip(card, ipaddr))
8573 qeth_set_ip_addr_list(card);
8578 qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8581 struct qeth_ipaddr *ipaddr;
8583 ipaddr = qeth_get_addr_buffer(proto);
8585 if (proto == QETH_PROT_IPV4){
8586 QETH_DBF_TEXT(trace, 2, "addrxip4");
8587 memcpy(&ipaddr->u.a4.addr, addr, 4);
8588 ipaddr->u.a4.mask = 0;
8589 #ifdef CONFIG_QETH_IPV6
8590 } else if (proto == QETH_PROT_IPV6){
8591 QETH_DBF_TEXT(trace, 2, "addrxip6");
8592 memcpy(&ipaddr->u.a6.addr, addr, 16);
8593 ipaddr->u.a6.pfxlen = 0;
8596 ipaddr->type = QETH_IP_TYPE_RXIP;
8599 if (!qeth_delete_ip(card, ipaddr))
8601 qeth_set_ip_addr_list(card);
8608 qeth_ip_event(struct notifier_block *this,
8609 unsigned long event,void *ptr)
8611 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8612 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8613 struct qeth_ipaddr *addr;
8614 struct qeth_card *card;
8616 QETH_DBF_TEXT(trace,3,"ipevent");
8617 card = qeth_get_card_from_dev(dev);
8620 if (card->options.layer2)
8623 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8625 addr->u.a4.addr = ifa->ifa_address;
8626 addr->u.a4.mask = ifa->ifa_mask;
8627 addr->type = QETH_IP_TYPE_NORMAL;
8633 if (!qeth_add_ip(card, addr))
8637 if (!qeth_delete_ip(card, addr))
8643 qeth_set_ip_addr_list(card);
8648 static struct notifier_block qeth_ip_notifier = {
8653 #ifdef CONFIG_QETH_IPV6
8655 * IPv6 event handler
8658 qeth_ip6_event(struct notifier_block *this,
8659 unsigned long event,void *ptr)
8662 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8663 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8664 struct qeth_ipaddr *addr;
8665 struct qeth_card *card;
8667 QETH_DBF_TEXT(trace,3,"ip6event");
8669 card = qeth_get_card_from_dev(dev);
8672 if (!qeth_is_supported(card, IPA_IPV6))
8675 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8677 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8678 addr->u.a6.pfxlen = ifa->prefix_len;
8679 addr->type = QETH_IP_TYPE_NORMAL;
8685 if (!qeth_add_ip(card, addr))
8689 if (!qeth_delete_ip(card, addr))
8695 qeth_set_ip_addr_list(card);
8700 static struct notifier_block qeth_ip6_notifier = {
8707 __qeth_reboot_event_card(struct device *dev, void *data)
8709 struct qeth_card *card;
8711 card = (struct qeth_card *) dev->driver_data;
8712 qeth_clear_ip_list(card, 0, 0);
8713 qeth_qdio_clear_card(card, 0);
8714 qeth_clear_qdio_buffers(card);
8719 qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8723 ret = driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8724 __qeth_reboot_event_card);
8725 return ret ? NOTIFY_BAD : NOTIFY_DONE;
8729 static struct notifier_block qeth_reboot_notifier = {
8735 qeth_register_notifiers(void)
8739 QETH_DBF_TEXT(trace,5,"regnotif");
8740 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8742 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8744 #ifdef CONFIG_QETH_IPV6
8745 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8750 #ifdef CONFIG_QETH_IPV6
8752 unregister_inetaddr_notifier(&qeth_ip_notifier);
8755 unregister_reboot_notifier(&qeth_reboot_notifier);
8760 * unregister all event notifiers
8763 qeth_unregister_notifiers(void)
8766 QETH_DBF_TEXT(trace,5,"unregnot");
8767 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8768 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8769 #ifdef CONFIG_QETH_IPV6
8770 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8771 #endif /* QETH_IPV6 */
8775 #ifdef CONFIG_QETH_IPV6
8777 qeth_ipv6_init(void)
8779 qeth_old_arp_constructor = arp_tbl.constructor;
8780 write_lock_bh(&arp_tbl.lock);
8781 arp_tbl.constructor = qeth_arp_constructor;
8782 write_unlock_bh(&arp_tbl.lock);
8784 arp_direct_ops = (struct neigh_ops*)
8785 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8786 if (!arp_direct_ops)
8789 memcpy(arp_direct_ops, &arp_direct_ops_template,
8790 sizeof(struct neigh_ops));
8796 qeth_ipv6_uninit(void)
8798 write_lock_bh(&arp_tbl.lock);
8799 arp_tbl.constructor = qeth_old_arp_constructor;
8800 write_unlock_bh(&arp_tbl.lock);
8801 kfree(arp_direct_ops);
8803 #endif /* CONFIG_QETH_IPV6 */
8806 qeth_sysfs_unregister(void)
8808 s390_root_dev_unregister(qeth_root_dev);
8809 qeth_remove_driver_attributes();
8810 ccw_driver_unregister(&qeth_ccw_driver);
8811 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8815 * register qeth at sysfs
8818 qeth_sysfs_register(void)
8822 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8826 rc = ccw_driver_register(&qeth_ccw_driver);
8828 goto out_ccw_driver;
8830 rc = qeth_create_driver_attributes();
8834 qeth_root_dev = s390_root_dev_register("qeth");
8835 rc = IS_ERR(qeth_root_dev) ? PTR_ERR(qeth_root_dev) : 0;
8839 qeth_remove_driver_attributes();
8841 ccw_driver_unregister(&qeth_ccw_driver);
8843 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8856 PRINT_INFO("loading %s\n", version);
8858 INIT_LIST_HEAD(&qeth_card_list.list);
8859 INIT_LIST_HEAD(&qeth_notify_list);
8860 spin_lock_init(&qeth_notify_lock);
8861 rwlock_init(&qeth_card_list.rwlock);
8863 rc = qeth_register_dbf_views();
8867 rc = qeth_sysfs_register();
8871 #ifdef CONFIG_QETH_IPV6
8872 rc = qeth_ipv6_init();
8874 PRINT_ERR("Out of memory during ipv6 init code = %d\n", rc);
8877 #endif /* QETH_IPV6 */
8878 rc = qeth_register_notifiers();
8881 rc = qeth_create_procfs_entries();
8888 qeth_unregister_notifiers();
8890 #ifdef CONFIG_QETH_IPV6
8893 #endif /* QETH_IPV6 */
8894 qeth_sysfs_unregister();
8896 qeth_unregister_dbf_views();
8898 PRINT_ERR("Initialization failed with code %d\n", rc);
8903 __exit qeth_exit(void)
8905 struct qeth_card *card, *tmp;
8906 unsigned long flags;
8908 QETH_DBF_TEXT(trace,1, "cleanup.");
8911 * Weed would not need to clean up our devices here, because the
8912 * common device layer calls qeth_remove_device for each device
8913 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8914 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8915 * qeth_remove_device called by the common device layer would otherwise
8916 * do a "hard" shutdown (card->use_hard_stop is set to one in
8917 * qeth_remove_device).
8920 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8921 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8922 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8923 qeth_set_offline(card->gdev);
8924 qeth_remove_device(card->gdev);
8927 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8928 #ifdef CONFIG_QETH_IPV6
8931 qeth_unregister_notifiers();
8932 qeth_remove_procfs_entries();
8933 qeth_sysfs_unregister();
8934 qeth_unregister_dbf_views();
8935 printk("qeth: removed\n");
8938 EXPORT_SYMBOL(qeth_osn_register);
8939 EXPORT_SYMBOL(qeth_osn_deregister);
8940 EXPORT_SYMBOL(qeth_osn_assist);
8941 module_init(qeth_init);
8942 module_exit(qeth_exit);
8943 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
8944 MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8945 "Copyright 2000,2003 IBM Corporation\n");
8947 MODULE_LICENSE("GPL");