2 * linux/drivers/s390/net/qeth_main.c
4 * Linux on zSeries OSA Express and HiperSockets support
6 * Copyright 2000,2003 IBM Corporation
8 * Author(s): Original Code written by
9 * Utz Bacher (utz.bacher@de.ibm.com)
11 * Frank Pavlic (fpavlic@de.ibm.com) and
12 * Thomas Spatzier <tspat@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <linux/module.h>
31 #include <linux/moduleparam.h>
32 #include <linux/string.h>
33 #include <linux/errno.h>
36 #include <linux/inetdevice.h>
37 #include <linux/netdevice.h>
38 #include <linux/sched.h>
39 #include <linux/workqueue.h>
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/interrupt.h>
43 #include <linux/tcp.h>
44 #include <linux/icmp.h>
45 #include <linux/skbuff.h>
47 #include <linux/igmp.h>
48 #include <linux/init.h>
49 #include <linux/reboot.h>
50 #include <linux/mii.h>
51 #include <linux/rcupdate.h>
52 #include <linux/ethtool.h>
56 #include <net/route.h>
58 #include <asm/ebcdic.h>
61 #include <asm/timex.h>
62 #include <asm/semaphore.h>
63 #include <asm/uaccess.h>
64 #include <asm/s390_rdev.h>
69 #include "qeth_eddp.h"
72 static const char *version = "qeth S/390 OSA-Express driver";
75 * Debug Facility Stuff
77 static debug_info_t *qeth_dbf_setup = NULL;
78 static debug_info_t *qeth_dbf_data = NULL;
79 static debug_info_t *qeth_dbf_misc = NULL;
80 static debug_info_t *qeth_dbf_control = NULL;
81 debug_info_t *qeth_dbf_trace = NULL;
82 static debug_info_t *qeth_dbf_sense = NULL;
83 static debug_info_t *qeth_dbf_qerr = NULL;
85 DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
87 static struct lock_class_key qdio_out_skb_queue_key;
90 * some more definitions and declarations
92 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
94 /* list of our cards */
95 struct qeth_card_list_struct qeth_card_list;
96 /*process list want to be notified*/
97 spinlock_t qeth_notify_lock;
98 struct list_head qeth_notify_list;
100 static void qeth_send_control_data_cb(struct qeth_channel *,
101 struct qeth_cmd_buffer *);
104 * here we go with function implementation
107 qeth_init_qdio_info(struct qeth_card *card);
110 qeth_init_qdio_queues(struct qeth_card *card);
113 qeth_alloc_qdio_buffers(struct qeth_card *card);
116 qeth_free_qdio_buffers(struct qeth_card *);
119 qeth_clear_qdio_buffers(struct qeth_card *);
122 qeth_clear_ip_list(struct qeth_card *, int, int);
125 qeth_clear_ipacmd_list(struct qeth_card *);
128 qeth_qdio_clear_card(struct qeth_card *, int);
131 qeth_clear_working_pool_list(struct qeth_card *);
134 qeth_clear_cmd_buffers(struct qeth_channel *);
137 qeth_stop(struct net_device *);
140 qeth_clear_ipato_list(struct qeth_card *);
143 qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
146 qeth_irq_tasklet(unsigned long);
149 qeth_set_online(struct ccwgroup_device *);
152 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
154 static struct qeth_ipaddr *
155 qeth_get_addr_buffer(enum qeth_prot_versions);
158 qeth_set_multicast_list(struct net_device *);
161 qeth_setadp_promisc_mode(struct qeth_card *);
164 qeth_notify_processes(void)
166 /*notify all registered processes */
167 struct qeth_notify_list_struct *n_entry;
169 QETH_DBF_TEXT(trace,3,"procnoti");
170 spin_lock(&qeth_notify_lock);
171 list_for_each_entry(n_entry, &qeth_notify_list, list) {
172 send_sig(n_entry->signum, n_entry->task, 1);
174 spin_unlock(&qeth_notify_lock);
178 qeth_notifier_unregister(struct task_struct *p)
180 struct qeth_notify_list_struct *n_entry, *tmp;
182 QETH_DBF_TEXT(trace, 2, "notunreg");
183 spin_lock(&qeth_notify_lock);
184 list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
185 if (n_entry->task == p) {
186 list_del(&n_entry->list);
192 spin_unlock(&qeth_notify_lock);
196 qeth_notifier_register(struct task_struct *p, int signum)
198 struct qeth_notify_list_struct *n_entry;
200 /*check first if entry already exists*/
201 spin_lock(&qeth_notify_lock);
202 list_for_each_entry(n_entry, &qeth_notify_list, list) {
203 if (n_entry->task == p) {
204 n_entry->signum = signum;
205 spin_unlock(&qeth_notify_lock);
209 spin_unlock(&qeth_notify_lock);
211 n_entry = (struct qeth_notify_list_struct *)
212 kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL);
216 n_entry->signum = signum;
217 spin_lock(&qeth_notify_lock);
218 list_add(&n_entry->list,&qeth_notify_list);
219 spin_unlock(&qeth_notify_lock);
225 * free channel command buffers
228 qeth_clean_channel(struct qeth_channel *channel)
232 QETH_DBF_TEXT(setup, 2, "freech");
233 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
234 kfree(channel->iob[cnt].data);
241 qeth_free_card(struct qeth_card *card)
244 QETH_DBF_TEXT(setup, 2, "freecrd");
245 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
246 qeth_clean_channel(&card->read);
247 qeth_clean_channel(&card->write);
249 free_netdev(card->dev);
250 qeth_clear_ip_list(card, 0, 0);
251 qeth_clear_ipato_list(card);
252 kfree(card->ip_tbd_list);
253 qeth_free_qdio_buffers(card);
258 * alloc memory for command buffer per channel
261 qeth_setup_channel(struct qeth_channel *channel)
265 QETH_DBF_TEXT(setup, 2, "setupch");
266 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
267 channel->iob[cnt].data = (char *)
268 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
269 if (channel->iob[cnt].data == NULL)
271 channel->iob[cnt].state = BUF_STATE_FREE;
272 channel->iob[cnt].channel = channel;
273 channel->iob[cnt].callback = qeth_send_control_data_cb;
274 channel->iob[cnt].rc = 0;
276 if (cnt < QETH_CMD_BUFFER_NO) {
278 kfree(channel->iob[cnt].data);
282 channel->io_buf_no = 0;
283 atomic_set(&channel->irq_pending, 0);
284 spin_lock_init(&channel->iob_lock);
286 init_waitqueue_head(&channel->wait_q);
287 channel->irq_tasklet.data = (unsigned long) channel;
288 channel->irq_tasklet.func = qeth_irq_tasklet;
293 * alloc memory for card structure
295 static struct qeth_card *
296 qeth_alloc_card(void)
298 struct qeth_card *card;
300 QETH_DBF_TEXT(setup, 2, "alloccrd");
301 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
304 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
305 if (qeth_setup_channel(&card->read)) {
309 if (qeth_setup_channel(&card->write)) {
310 qeth_clean_channel(&card->read);
318 __qeth_check_irb_error(struct ccw_device *cdev, unsigned long intparm,
324 switch (PTR_ERR(irb)) {
326 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
327 QETH_DBF_TEXT(trace, 2, "ckirberr");
328 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
331 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
332 QETH_DBF_TEXT(trace, 2, "ckirberr");
333 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
334 if (intparm == QETH_RCD_PARM) {
335 struct qeth_card *card = CARD_FROM_CDEV(cdev);
337 if (card && (card->data.ccwdev == cdev)) {
338 card->data.state = CH_STATE_DOWN;
339 wake_up(&card->wait_q);
344 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
346 QETH_DBF_TEXT(trace, 2, "ckirberr");
347 QETH_DBF_TEXT(trace, 2, " rc???");
353 qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
358 sense = (char *) irb->ecw;
359 cstat = irb->scsw.cstat;
360 dstat = irb->scsw.dstat;
362 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
363 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
364 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
365 QETH_DBF_TEXT(trace,2, "CGENCHK");
366 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
367 cdev->dev.bus_id, dstat, cstat);
368 HEXDUMP16(WARN, "irb: ", irb);
369 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
373 if (dstat & DEV_STAT_UNIT_CHECK) {
374 if (sense[SENSE_RESETTING_EVENT_BYTE] &
375 SENSE_RESETTING_EVENT_FLAG) {
376 QETH_DBF_TEXT(trace,2,"REVIND");
379 if (sense[SENSE_COMMAND_REJECT_BYTE] &
380 SENSE_COMMAND_REJECT_FLAG) {
381 QETH_DBF_TEXT(trace,2,"CMDREJi");
384 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
385 QETH_DBF_TEXT(trace,2,"AFFE");
388 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
389 QETH_DBF_TEXT(trace,2,"ZEROSEN");
392 QETH_DBF_TEXT(trace,2,"DGENCHK");
397 static int qeth_issue_next_read(struct qeth_card *);
403 qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
407 struct qeth_cmd_buffer *buffer;
408 struct qeth_channel *channel;
409 struct qeth_card *card;
411 QETH_DBF_TEXT(trace,5,"irq");
413 if (__qeth_check_irb_error(cdev, intparm, irb))
415 cstat = irb->scsw.cstat;
416 dstat = irb->scsw.dstat;
418 card = CARD_FROM_CDEV(cdev);
422 if (card->read.ccwdev == cdev){
423 channel = &card->read;
424 QETH_DBF_TEXT(trace,5,"read");
425 } else if (card->write.ccwdev == cdev) {
426 channel = &card->write;
427 QETH_DBF_TEXT(trace,5,"write");
429 channel = &card->data;
430 QETH_DBF_TEXT(trace,5,"data");
432 atomic_set(&channel->irq_pending, 0);
434 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
435 channel->state = CH_STATE_STOPPED;
437 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
438 channel->state = CH_STATE_HALTED;
440 /*let's wake up immediately on data channel*/
441 if ((channel == &card->data) && (intparm != 0) &&
442 (intparm != QETH_RCD_PARM))
445 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
446 QETH_DBF_TEXT(trace, 6, "clrchpar");
447 /* we don't have to handle this further */
450 if (intparm == QETH_HALT_CHANNEL_PARM) {
451 QETH_DBF_TEXT(trace, 6, "hltchpar");
452 /* we don't have to handle this further */
455 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
456 (dstat & DEV_STAT_UNIT_CHECK) ||
458 if (irb->esw.esw0.erw.cons) {
459 /* TODO: we should make this s390dbf */
460 PRINT_WARN("sense data available on channel %s.\n",
461 CHANNEL_ID(channel));
462 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
463 HEXDUMP16(WARN,"irb: ",irb);
464 HEXDUMP16(WARN,"sense data: ",irb->ecw);
466 if (intparm == QETH_RCD_PARM) {
467 channel->state = CH_STATE_DOWN;
470 rc = qeth_get_problem(cdev,irb);
472 qeth_schedule_recovery(card);
477 if (intparm == QETH_RCD_PARM) {
478 channel->state = CH_STATE_RCD_DONE;
482 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
483 buffer->state = BUF_STATE_PROCESSED;
485 if (channel == &card->data)
488 if (channel == &card->read &&
489 channel->state == CH_STATE_UP)
490 qeth_issue_next_read(card);
492 qeth_irq_tasklet((unsigned long)channel);
495 wake_up(&card->wait_q);
499 * tasklet function scheduled from irq handler
502 qeth_irq_tasklet(unsigned long data)
504 struct qeth_card *card;
505 struct qeth_channel *channel;
506 struct qeth_cmd_buffer *iob;
509 QETH_DBF_TEXT(trace,5,"irqtlet");
510 channel = (struct qeth_channel *) data;
512 index = channel->buf_no;
513 card = CARD_FROM_CDEV(channel->ccwdev);
514 while (iob[index].state == BUF_STATE_PROCESSED) {
515 if (iob[index].callback !=NULL) {
516 iob[index].callback(channel,iob + index);
518 index = (index + 1) % QETH_CMD_BUFFER_NO;
520 channel->buf_no = index;
521 wake_up(&card->wait_q);
524 static int qeth_stop_card(struct qeth_card *, int);
527 __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
529 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
530 int rc = 0, rc2 = 0, rc3 = 0;
531 enum qeth_card_states recover_flag;
533 QETH_DBF_TEXT(setup, 3, "setoffl");
534 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
536 if (card->dev && netif_carrier_ok(card->dev))
537 netif_carrier_off(card->dev);
538 recover_flag = card->state;
539 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
540 PRINT_WARN("Stopping card %s interrupted by user!\n",
544 rc = ccw_device_set_offline(CARD_DDEV(card));
545 rc2 = ccw_device_set_offline(CARD_WDEV(card));
546 rc3 = ccw_device_set_offline(CARD_RDEV(card));
548 rc = (rc2) ? rc2 : rc3;
550 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
551 if (recover_flag == CARD_STATE_UP)
552 card->state = CARD_STATE_RECOVER;
553 qeth_notify_processes();
558 qeth_set_offline(struct ccwgroup_device *cgdev)
560 return __qeth_set_offline(cgdev, 0);
564 qeth_threads_running(struct qeth_card *card, unsigned long threads);
568 qeth_remove_device(struct ccwgroup_device *cgdev)
570 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
573 QETH_DBF_TEXT(setup, 3, "rmdev");
574 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
579 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
581 if (cgdev->state == CCWGROUP_ONLINE){
582 card->use_hard_stop = 1;
583 qeth_set_offline(cgdev);
585 /* remove form our internal list */
586 write_lock_irqsave(&qeth_card_list.rwlock, flags);
587 list_del(&card->list);
588 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
590 unregister_netdev(card->dev);
591 qeth_remove_device_attributes(&cgdev->dev);
592 qeth_free_card(card);
593 cgdev->dev.driver_data = NULL;
594 put_device(&cgdev->dev);
598 qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
600 qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
603 * Add/remove address to/from card's ip list, i.e. try to add or remove
604 * reference to/from an IP address that is already registered on the card.
606 * 0 address was on card and its reference count has been adjusted,
607 * but is still > 0, so nothing has to be done
608 * also returns 0 if card was not on card and the todo was to delete
609 * the address -> there is also nothing to be done
610 * 1 address was not on card and the todo is to add it to the card's ip
612 * -1 address was on card and its reference count has been decremented
613 * to <= 0 by the todo -> address must be removed from card
616 __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
617 struct qeth_ipaddr **__addr)
619 struct qeth_ipaddr *addr;
622 list_for_each_entry(addr, &card->ip_list, entry) {
623 if (card->options.layer2) {
624 if ((addr->type == todo->type) &&
625 (memcmp(&addr->mac, &todo->mac,
626 OSA_ADDR_LEN) == 0)) {
632 if ((addr->proto == QETH_PROT_IPV4) &&
633 (todo->proto == QETH_PROT_IPV4) &&
634 (addr->type == todo->type) &&
635 (addr->u.a4.addr == todo->u.a4.addr) &&
636 (addr->u.a4.mask == todo->u.a4.mask)) {
640 if ((addr->proto == QETH_PROT_IPV6) &&
641 (todo->proto == QETH_PROT_IPV6) &&
642 (addr->type == todo->type) &&
643 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
644 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
645 sizeof(struct in6_addr)) == 0)) {
651 addr->users += todo->users;
652 if (addr->users <= 0){
656 /* for VIPA and RXIP limit refcount to 1 */
657 if (addr->type != QETH_IP_TYPE_NORMAL)
662 if (todo->users > 0) {
663 /* for VIPA and RXIP limit refcount to 1 */
664 if (todo->type != QETH_IP_TYPE_NORMAL)
672 __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
675 struct qeth_ipaddr *tmp;
677 list_for_each_entry(tmp, list, entry) {
678 if ((tmp->proto == QETH_PROT_IPV4) &&
679 (addr->proto == QETH_PROT_IPV4) &&
680 ((same_type && (tmp->type == addr->type)) ||
681 (!same_type && (tmp->type != addr->type)) ) &&
682 (tmp->u.a4.addr == addr->u.a4.addr) ){
685 if ((tmp->proto == QETH_PROT_IPV6) &&
686 (addr->proto == QETH_PROT_IPV6) &&
687 ((same_type && (tmp->type == addr->type)) ||
688 (!same_type && (tmp->type != addr->type)) ) &&
689 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
690 sizeof(struct in6_addr)) == 0) ) {
698 * Add IP to be added to todo list. If there is already an "add todo"
699 * in this list we just incremenent the reference count.
700 * Returns 0 if we just incremented reference count.
703 __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
705 struct qeth_ipaddr *tmp, *t;
708 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
709 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
710 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
712 if (card->options.layer2) {
713 if ((tmp->type == addr->type) &&
714 (tmp->is_multicast == addr->is_multicast) &&
715 (memcmp(&tmp->mac, &addr->mac,
716 OSA_ADDR_LEN) == 0)) {
722 if ((tmp->proto == QETH_PROT_IPV4) &&
723 (addr->proto == QETH_PROT_IPV4) &&
724 (tmp->type == addr->type) &&
725 (tmp->is_multicast == addr->is_multicast) &&
726 (tmp->u.a4.addr == addr->u.a4.addr) &&
727 (tmp->u.a4.mask == addr->u.a4.mask)) {
731 if ((tmp->proto == QETH_PROT_IPV6) &&
732 (addr->proto == QETH_PROT_IPV6) &&
733 (tmp->type == addr->type) &&
734 (tmp->is_multicast == addr->is_multicast) &&
735 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
736 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
737 sizeof(struct in6_addr)) == 0)) {
743 if (addr->users != 0)
744 tmp->users += addr->users;
746 tmp->users += add? 1:-1;
747 if (tmp->users == 0) {
748 list_del(&tmp->entry);
753 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
754 list_add(&addr->entry, card->ip_tbd_list);
756 if (addr->users == 0)
757 addr->users += add? 1:-1;
758 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
759 qeth_is_addr_covered_by_ipato(card, addr)){
760 QETH_DBF_TEXT(trace, 2, "tkovaddr");
761 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
763 list_add_tail(&addr->entry, card->ip_tbd_list);
770 * Remove IP address from list
773 qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
778 QETH_DBF_TEXT(trace, 4, "delip");
780 if (card->options.layer2)
781 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
782 else if (addr->proto == QETH_PROT_IPV4)
783 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
785 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
786 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
788 spin_lock_irqsave(&card->ip_lock, flags);
789 rc = __qeth_insert_ip_todo(card, addr, 0);
790 spin_unlock_irqrestore(&card->ip_lock, flags);
795 qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
800 QETH_DBF_TEXT(trace, 4, "addip");
801 if (card->options.layer2)
802 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
803 else if (addr->proto == QETH_PROT_IPV4)
804 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
806 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
807 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
809 spin_lock_irqsave(&card->ip_lock, flags);
810 rc = __qeth_insert_ip_todo(card, addr, 1);
811 spin_unlock_irqrestore(&card->ip_lock, flags);
816 __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
818 struct qeth_ipaddr *addr, *tmp;
821 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
822 if (addr->is_multicast) {
823 spin_unlock_irqrestore(&card->ip_lock, *flags);
824 rc = qeth_deregister_addr_entry(card, addr);
825 spin_lock_irqsave(&card->ip_lock, *flags);
827 list_del(&addr->entry);
836 qeth_set_ip_addr_list(struct qeth_card *card)
838 struct list_head *tbd_list;
839 struct qeth_ipaddr *todo, *addr;
843 QETH_DBF_TEXT(trace, 2, "sdiplist");
844 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
846 spin_lock_irqsave(&card->ip_lock, flags);
847 tbd_list = card->ip_tbd_list;
848 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
849 if (!card->ip_tbd_list) {
850 QETH_DBF_TEXT(trace, 0, "silnomem");
851 card->ip_tbd_list = tbd_list;
852 spin_unlock_irqrestore(&card->ip_lock, flags);
855 INIT_LIST_HEAD(card->ip_tbd_list);
857 while (!list_empty(tbd_list)){
858 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
859 list_del(&todo->entry);
860 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
861 __qeth_delete_all_mc(card, &flags);
865 rc = __qeth_ref_ip_on_card(card, todo, &addr);
867 /* nothing to be done; only adjusted refcount */
869 } else if (rc == 1) {
870 /* new entry to be added to on-card list */
871 spin_unlock_irqrestore(&card->ip_lock, flags);
872 rc = qeth_register_addr_entry(card, todo);
873 spin_lock_irqsave(&card->ip_lock, flags);
875 list_add_tail(&todo->entry, &card->ip_list);
878 } else if (rc == -1) {
879 /* on-card entry to be removed */
880 list_del_init(&addr->entry);
881 spin_unlock_irqrestore(&card->ip_lock, flags);
882 rc = qeth_deregister_addr_entry(card, addr);
883 spin_lock_irqsave(&card->ip_lock, flags);
887 list_add_tail(&addr->entry, &card->ip_list);
891 spin_unlock_irqrestore(&card->ip_lock, flags);
895 static void qeth_delete_mc_addresses(struct qeth_card *);
896 static void qeth_add_multicast_ipv4(struct qeth_card *);
897 static void qeth_layer2_add_multicast(struct qeth_card *);
898 #ifdef CONFIG_QETH_IPV6
899 static void qeth_add_multicast_ipv6(struct qeth_card *);
903 qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
907 spin_lock_irqsave(&card->thread_mask_lock, flags);
908 if ( !(card->thread_allowed_mask & thread) ||
909 (card->thread_start_mask & thread) ) {
910 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
913 card->thread_start_mask |= thread;
914 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
919 qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
923 spin_lock_irqsave(&card->thread_mask_lock, flags);
924 card->thread_start_mask &= ~thread;
925 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
926 wake_up(&card->wait_q);
930 qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
934 spin_lock_irqsave(&card->thread_mask_lock, flags);
935 card->thread_running_mask &= ~thread;
936 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
937 wake_up(&card->wait_q);
941 __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
946 spin_lock_irqsave(&card->thread_mask_lock, flags);
947 if (card->thread_start_mask & thread){
948 if ((card->thread_allowed_mask & thread) &&
949 !(card->thread_running_mask & thread)){
951 card->thread_start_mask &= ~thread;
952 card->thread_running_mask |= thread;
956 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
961 qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
965 wait_event(card->wait_q,
966 (rc = __qeth_do_run_thread(card, thread)) >= 0);
971 qeth_recover(void *ptr)
973 struct qeth_card *card;
976 card = (struct qeth_card *) ptr;
977 daemonize("qeth_recover");
978 QETH_DBF_TEXT(trace,2,"recover1");
979 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
980 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
982 QETH_DBF_TEXT(trace,2,"recover2");
983 PRINT_WARN("Recovery of device %s started ...\n",
985 card->use_hard_stop = 1;
986 __qeth_set_offline(card->gdev,1);
987 rc = __qeth_set_online(card->gdev,1);
988 /* don't run another scheduled recovery */
989 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
990 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
992 PRINT_INFO("Device %s successfully recovered!\n",
995 PRINT_INFO("Device %s could not be recovered!\n",
1001 qeth_schedule_recovery(struct qeth_card *card)
1003 QETH_DBF_TEXT(trace,2,"startrec");
1004 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
1005 schedule_work(&card->kernel_thread_starter);
1009 qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1011 unsigned long flags;
1014 spin_lock_irqsave(&card->thread_mask_lock, flags);
1015 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
1016 (u8) card->thread_start_mask,
1017 (u8) card->thread_allowed_mask,
1018 (u8) card->thread_running_mask);
1019 rc = (card->thread_start_mask & thread);
1020 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1025 qeth_start_kernel_thread(struct work_struct *work)
1027 struct qeth_card *card = container_of(work, struct qeth_card, kernel_thread_starter);
1028 QETH_DBF_TEXT(trace , 2, "strthrd");
1030 if (card->read.state != CH_STATE_UP &&
1031 card->write.state != CH_STATE_UP)
1033 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1034 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1039 qeth_set_intial_options(struct qeth_card *card)
1041 card->options.route4.type = NO_ROUTER;
1042 #ifdef CONFIG_QETH_IPV6
1043 card->options.route6.type = NO_ROUTER;
1044 #endif /* QETH_IPV6 */
1045 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1046 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1047 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1048 card->options.fake_broadcast = 0;
1049 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1050 card->options.fake_ll = 0;
1051 if (card->info.type == QETH_CARD_TYPE_OSN)
1052 card->options.layer2 = 1;
1054 card->options.layer2 = 0;
1055 card->options.performance_stats = 0;
1056 card->options.rx_sg_cb = QETH_RX_SG_CB;
1060 * initialize channels ,card and all state machines
1063 qeth_setup_card(struct qeth_card *card)
1066 QETH_DBF_TEXT(setup, 2, "setupcrd");
1067 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1069 card->read.state = CH_STATE_DOWN;
1070 card->write.state = CH_STATE_DOWN;
1071 card->data.state = CH_STATE_DOWN;
1072 card->state = CARD_STATE_DOWN;
1073 card->lan_online = 0;
1074 card->use_hard_stop = 0;
1076 #ifdef CONFIG_QETH_VLAN
1077 spin_lock_init(&card->vlanlock);
1078 card->vlangrp = NULL;
1080 spin_lock_init(&card->lock);
1081 spin_lock_init(&card->ip_lock);
1082 spin_lock_init(&card->thread_mask_lock);
1083 card->thread_start_mask = 0;
1084 card->thread_allowed_mask = 0;
1085 card->thread_running_mask = 0;
1086 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1087 INIT_LIST_HEAD(&card->ip_list);
1088 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1089 if (!card->ip_tbd_list) {
1090 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1093 INIT_LIST_HEAD(card->ip_tbd_list);
1094 INIT_LIST_HEAD(&card->cmd_waiter_list);
1095 init_waitqueue_head(&card->wait_q);
1096 /* intial options */
1097 qeth_set_intial_options(card);
1098 /* IP address takeover */
1099 INIT_LIST_HEAD(&card->ipato.entries);
1100 card->ipato.enabled = 0;
1101 card->ipato.invert4 = 0;
1102 card->ipato.invert6 = 0;
1103 /* init QDIO stuff */
1104 qeth_init_qdio_info(card);
1109 is_1920_device (struct qeth_card *card)
1111 int single_queue = 0;
1112 struct ccw_device *ccwdev;
1113 struct channelPath_dsc {
1124 QETH_DBF_TEXT(setup, 2, "chk_1920");
1126 ccwdev = card->data.ccwdev;
1127 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1128 if (chp_dsc != NULL) {
1129 /* CHPP field bit 6 == 1 -> single queue */
1130 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1133 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1134 return single_queue;
1138 qeth_determine_card_type(struct qeth_card *card)
1142 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1144 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1145 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1146 while (known_devices[i][4]) {
1147 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1148 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1149 card->info.type = known_devices[i][4];
1150 card->qdio.no_out_queues = known_devices[i][8];
1151 card->info.is_multicast_different = known_devices[i][9];
1152 if (is_1920_device(card)) {
1153 PRINT_INFO("Priority Queueing not able "
1154 "due to hardware limitations!\n");
1155 card->qdio.no_out_queues = 1;
1156 card->qdio.default_out_queue = 0;
1162 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1163 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1168 qeth_probe_device(struct ccwgroup_device *gdev)
1170 struct qeth_card *card;
1172 unsigned long flags;
1175 QETH_DBF_TEXT(setup, 2, "probedev");
1178 if (!get_device(dev))
1181 QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
1183 card = qeth_alloc_card();
1186 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1189 card->read.ccwdev = gdev->cdev[0];
1190 card->write.ccwdev = gdev->cdev[1];
1191 card->data.ccwdev = gdev->cdev[2];
1192 gdev->dev.driver_data = card;
1194 gdev->cdev[0]->handler = qeth_irq;
1195 gdev->cdev[1]->handler = qeth_irq;
1196 gdev->cdev[2]->handler = qeth_irq;
1198 if ((rc = qeth_determine_card_type(card))){
1199 PRINT_WARN("%s: not a valid card type\n", __func__);
1200 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1202 qeth_free_card(card);
1205 if ((rc = qeth_setup_card(card))){
1206 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1208 qeth_free_card(card);
1211 rc = qeth_create_device_attributes(dev);
1214 qeth_free_card(card);
1217 /* insert into our internal list */
1218 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1219 list_add_tail(&card->list, &qeth_card_list.list);
1220 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1225 static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
1231 struct qeth_channel *channel = &card->data;
1232 unsigned long flags;
1235 * scan for RCD command in extended SenseID data
1237 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
1238 if (!ciw || ciw->cmd == 0)
1240 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
1244 channel->ccw.cmd_code = ciw->cmd;
1245 channel->ccw.cda = (__u32) __pa (rcd_buf);
1246 channel->ccw.count = ciw->count;
1247 channel->ccw.flags = CCW_FLAG_SLI;
1248 channel->state = CH_STATE_RCD;
1249 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1250 ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1251 QETH_RCD_PARM, LPM_ANYPATH, 0,
1253 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1255 wait_event(card->wait_q,
1256 (channel->state == CH_STATE_RCD_DONE ||
1257 channel->state == CH_STATE_DOWN));
1258 if (channel->state == CH_STATE_DOWN)
1261 channel->state = CH_STATE_DOWN;
1267 *length = ciw->count;
1274 qeth_get_unitaddr(struct qeth_card *card)
1280 QETH_DBF_TEXT(setup, 2, "getunit");
1281 rc = qeth_read_conf_data(card, (void **) &prcd, &length);
1283 PRINT_ERR("qeth_read_conf_data for device %s returned %i\n",
1284 CARD_DDEV_ID(card), rc);
1287 card->info.chpid = prcd[30];
1288 card->info.unit_addr2 = prcd[31];
1289 card->info.cula = prcd[63];
1290 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1291 (prcd[0x11] == _ascebc['M']));
1297 qeth_init_tokens(struct qeth_card *card)
1299 card->token.issuer_rm_w = 0x00010103UL;
1300 card->token.cm_filter_w = 0x00010108UL;
1301 card->token.cm_connection_w = 0x0001010aUL;
1302 card->token.ulp_filter_w = 0x0001010bUL;
1303 card->token.ulp_connection_w = 0x0001010dUL;
1307 raw_devno_from_bus_id(char *id)
1309 id += (strlen(id) - 4);
1310 return (__u16) simple_strtoul(id, &id, 16);
1316 qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1318 struct qeth_card *card;
1320 QETH_DBF_TEXT(trace, 4, "setupccw");
1321 card = CARD_FROM_CDEV(channel->ccwdev);
1322 if (channel == &card->read)
1323 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1325 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1326 channel->ccw.count = len;
1327 channel->ccw.cda = (__u32) __pa(iob);
1331 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1333 static struct qeth_cmd_buffer *
1334 __qeth_get_buffer(struct qeth_channel *channel)
1338 QETH_DBF_TEXT(trace, 6, "getbuff");
1339 index = channel->io_buf_no;
1341 if (channel->iob[index].state == BUF_STATE_FREE) {
1342 channel->iob[index].state = BUF_STATE_LOCKED;
1343 channel->io_buf_no = (channel->io_buf_no + 1) %
1345 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1346 return channel->iob + index;
1348 index = (index + 1) % QETH_CMD_BUFFER_NO;
1349 } while(index != channel->io_buf_no);
1355 * release command buffer
1358 qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1360 unsigned long flags;
1362 QETH_DBF_TEXT(trace, 6, "relbuff");
1363 spin_lock_irqsave(&channel->iob_lock, flags);
1364 memset(iob->data, 0, QETH_BUFSIZE);
1365 iob->state = BUF_STATE_FREE;
1366 iob->callback = qeth_send_control_data_cb;
1368 spin_unlock_irqrestore(&channel->iob_lock, flags);
1371 static struct qeth_cmd_buffer *
1372 qeth_get_buffer(struct qeth_channel *channel)
1374 struct qeth_cmd_buffer *buffer = NULL;
1375 unsigned long flags;
1377 spin_lock_irqsave(&channel->iob_lock, flags);
1378 buffer = __qeth_get_buffer(channel);
1379 spin_unlock_irqrestore(&channel->iob_lock, flags);
1383 static struct qeth_cmd_buffer *
1384 qeth_wait_for_buffer(struct qeth_channel *channel)
1386 struct qeth_cmd_buffer *buffer;
1387 wait_event(channel->wait_q,
1388 ((buffer = qeth_get_buffer(channel)) != NULL));
1393 qeth_clear_cmd_buffers(struct qeth_channel *channel)
1397 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1398 qeth_release_buffer(channel,&channel->iob[cnt]);
1399 channel->buf_no = 0;
1400 channel->io_buf_no = 0;
1404 * start IDX for read and write channel
1407 qeth_idx_activate_get_answer(struct qeth_channel *channel,
1408 void (*idx_reply_cb)(struct qeth_channel *,
1409 struct qeth_cmd_buffer *))
1411 struct qeth_cmd_buffer *iob;
1412 unsigned long flags;
1414 struct qeth_card *card;
1416 QETH_DBF_TEXT(setup, 2, "idxanswr");
1417 card = CARD_FROM_CDEV(channel->ccwdev);
1418 iob = qeth_get_buffer(channel);
1419 iob->callback = idx_reply_cb;
1420 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1421 channel->ccw.count = QETH_BUFSIZE;
1422 channel->ccw.cda = (__u32) __pa(iob->data);
1424 wait_event(card->wait_q,
1425 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1426 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1427 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1428 rc = ccw_device_start(channel->ccwdev,
1429 &channel->ccw,(addr_t) iob, 0, 0);
1430 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1433 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1434 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1435 atomic_set(&channel->irq_pending, 0);
1436 wake_up(&card->wait_q);
1439 rc = wait_event_interruptible_timeout(card->wait_q,
1440 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1441 if (rc == -ERESTARTSYS)
1443 if (channel->state != CH_STATE_UP){
1445 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1446 qeth_clear_cmd_buffers(channel);
1453 qeth_idx_activate_channel(struct qeth_channel *channel,
1454 void (*idx_reply_cb)(struct qeth_channel *,
1455 struct qeth_cmd_buffer *))
1457 struct qeth_card *card;
1458 struct qeth_cmd_buffer *iob;
1459 unsigned long flags;
1463 card = CARD_FROM_CDEV(channel->ccwdev);
1465 QETH_DBF_TEXT(setup, 2, "idxactch");
1467 iob = qeth_get_buffer(channel);
1468 iob->callback = idx_reply_cb;
1469 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1470 channel->ccw.count = IDX_ACTIVATE_SIZE;
1471 channel->ccw.cda = (__u32) __pa(iob->data);
1472 if (channel == &card->write) {
1473 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1474 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1475 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1476 card->seqno.trans_hdr++;
1478 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1479 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1480 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1482 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1483 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1484 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1485 &card->info.func_level,sizeof(__u16));
1486 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1487 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1488 temp = (card->info.cula << 8) + card->info.unit_addr2;
1489 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1491 wait_event(card->wait_q,
1492 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1493 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1494 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1495 rc = ccw_device_start(channel->ccwdev,
1496 &channel->ccw,(addr_t) iob, 0, 0);
1497 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1500 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1501 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1502 atomic_set(&channel->irq_pending, 0);
1503 wake_up(&card->wait_q);
1506 rc = wait_event_interruptible_timeout(card->wait_q,
1507 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1508 if (rc == -ERESTARTSYS)
1510 if (channel->state != CH_STATE_ACTIVATING) {
1511 PRINT_WARN("qeth: IDX activate timed out!\n");
1512 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1513 qeth_clear_cmd_buffers(channel);
1516 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1520 qeth_peer_func_level(int level)
1522 if ((level & 0xff) == 8)
1523 return (level & 0xff) + 0x400;
1524 if (((level >> 8) & 3) == 1)
1525 return (level & 0xff) + 0x200;
1530 qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1532 struct qeth_card *card;
1535 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1537 if (channel->state == CH_STATE_DOWN) {
1538 channel->state = CH_STATE_ACTIVATING;
1541 card = CARD_FROM_CDEV(channel->ccwdev);
1543 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1544 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1545 "reply\n", CARD_WDEV_ID(card));
1548 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1549 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1550 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1551 "function level mismatch "
1552 "(sent: 0x%x, received: 0x%x)\n",
1553 CARD_WDEV_ID(card), card->info.func_level, temp);
1556 channel->state = CH_STATE_UP;
1558 qeth_release_buffer(channel, iob);
1562 qeth_check_idx_response(unsigned char *buffer)
1567 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1568 if ((buffer[2] & 0xc0) == 0xc0) {
1569 PRINT_WARN("received an IDX TERMINATE "
1570 "with cause code 0x%02x%s\n",
1572 ((buffer[4] == 0x22) ?
1573 " -- try another portname" : ""));
1574 QETH_DBF_TEXT(trace, 2, "ckidxres");
1575 QETH_DBF_TEXT(trace, 2, " idxterm");
1576 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1583 qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1585 struct qeth_card *card;
1588 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1589 if (channel->state == CH_STATE_DOWN) {
1590 channel->state = CH_STATE_ACTIVATING;
1594 card = CARD_FROM_CDEV(channel->ccwdev);
1595 if (qeth_check_idx_response(iob->data)) {
1598 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1599 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1600 "reply\n", CARD_RDEV_ID(card));
1605 * temporary fix for microcode bug
1606 * to revert it,replace OR by AND
1608 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1609 (card->info.type == QETH_CARD_TYPE_OSAE) )
1610 card->info.portname_required = 1;
1612 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1613 if (temp != qeth_peer_func_level(card->info.func_level)) {
1614 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1615 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1616 CARD_RDEV_ID(card), card->info.func_level, temp);
1619 memcpy(&card->token.issuer_rm_r,
1620 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1621 QETH_MPC_TOKEN_LENGTH);
1622 memcpy(&card->info.mcl_level[0],
1623 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1624 channel->state = CH_STATE_UP;
1626 qeth_release_buffer(channel,iob);
1630 qeth_issue_next_read(struct qeth_card *card)
1633 struct qeth_cmd_buffer *iob;
1635 QETH_DBF_TEXT(trace,5,"issnxrd");
1636 if (card->read.state != CH_STATE_UP)
1638 iob = qeth_get_buffer(&card->read);
1640 PRINT_WARN("issue_next_read failed: no iob available!\n");
1643 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1644 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1645 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1646 (addr_t) iob, 0, 0);
1648 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1649 atomic_set(&card->read.irq_pending, 0);
1650 qeth_schedule_recovery(card);
1651 wake_up(&card->wait_q);
1656 static struct qeth_reply *
1657 qeth_alloc_reply(struct qeth_card *card)
1659 struct qeth_reply *reply;
1661 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1663 atomic_set(&reply->refcnt, 1);
1664 atomic_set(&reply->received, 0);
1671 qeth_get_reply(struct qeth_reply *reply)
1673 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1674 atomic_inc(&reply->refcnt);
1678 qeth_put_reply(struct qeth_reply *reply)
1680 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1681 if (atomic_dec_and_test(&reply->refcnt))
1686 qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, struct qeth_card *card)
1692 com = cmd->hdr.command;
1693 rc = cmd->hdr.return_code;
1694 ipa_name = qeth_get_ipa_cmd_name(com);
1696 PRINT_ERR("%s(x%X) for %s returned x%X \"%s\"\n", ipa_name, com,
1697 QETH_CARD_IFNAME(card), rc, qeth_get_ipa_msg(rc));
1700 static struct qeth_ipa_cmd *
1701 qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1703 struct qeth_ipa_cmd *cmd = NULL;
1705 QETH_DBF_TEXT(trace,5,"chkipad");
1706 if (IS_IPA(iob->data)){
1707 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1708 if (IS_IPA_REPLY(cmd)) {
1709 if (cmd->hdr.return_code)
1710 qeth_issue_ipa_msg(cmd, card);
1714 switch (cmd->hdr.command) {
1715 case IPA_CMD_STOPLAN:
1716 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1717 "there is a network problem or "
1718 "someone pulled the cable or "
1719 "disabled the port.\n",
1720 QETH_CARD_IFNAME(card),
1722 card->lan_online = 0;
1723 if (card->dev && netif_carrier_ok(card->dev))
1724 netif_carrier_off(card->dev);
1726 case IPA_CMD_STARTLAN:
1727 PRINT_INFO("Link reestablished on %s "
1728 "(CHPID 0x%X). Scheduling "
1729 "IP address reset.\n",
1730 QETH_CARD_IFNAME(card),
1732 netif_carrier_on(card->dev);
1733 qeth_schedule_recovery(card);
1735 case IPA_CMD_MODCCID:
1737 case IPA_CMD_REGISTER_LOCAL_ADDR:
1738 QETH_DBF_TEXT(trace,3, "irla");
1740 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1741 QETH_DBF_TEXT(trace,3, "urla");
1744 PRINT_WARN("Received data is IPA "
1745 "but not a reply!\n");
1754 * wake all waiting ipa commands
1757 qeth_clear_ipacmd_list(struct qeth_card *card)
1759 struct qeth_reply *reply, *r;
1760 unsigned long flags;
1762 QETH_DBF_TEXT(trace, 4, "clipalst");
1764 spin_lock_irqsave(&card->lock, flags);
1765 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1766 qeth_get_reply(reply);
1768 atomic_inc(&reply->received);
1769 list_del_init(&reply->list);
1770 wake_up(&reply->wait_q);
1771 qeth_put_reply(reply);
1773 spin_unlock_irqrestore(&card->lock, flags);
1777 qeth_send_control_data_cb(struct qeth_channel *channel,
1778 struct qeth_cmd_buffer *iob)
1780 struct qeth_card *card;
1781 struct qeth_reply *reply, *r;
1782 struct qeth_ipa_cmd *cmd;
1783 unsigned long flags;
1786 QETH_DBF_TEXT(trace,4,"sndctlcb");
1788 card = CARD_FROM_CDEV(channel->ccwdev);
1789 if (qeth_check_idx_response(iob->data)) {
1790 qeth_clear_ipacmd_list(card);
1791 qeth_schedule_recovery(card);
1795 cmd = qeth_check_ipa_data(card, iob);
1796 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1798 /*in case of OSN : check if cmd is set */
1799 if (card->info.type == QETH_CARD_TYPE_OSN &&
1801 cmd->hdr.command != IPA_CMD_STARTLAN &&
1802 card->osn_info.assist_cb != NULL) {
1803 card->osn_info.assist_cb(card->dev, cmd);
1807 spin_lock_irqsave(&card->lock, flags);
1808 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1809 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1810 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1811 qeth_get_reply(reply);
1812 list_del_init(&reply->list);
1813 spin_unlock_irqrestore(&card->lock, flags);
1815 if (reply->callback != NULL) {
1817 reply->offset = (__u16)((char*)cmd -
1819 keep_reply = reply->callback(card,
1821 (unsigned long)cmd);
1823 keep_reply = reply->callback(card,
1825 (unsigned long)iob);
1828 reply->rc = (u16) cmd->hdr.return_code;
1830 reply->rc = iob->rc;
1832 spin_lock_irqsave(&card->lock, flags);
1833 list_add_tail(&reply->list,
1834 &card->cmd_waiter_list);
1835 spin_unlock_irqrestore(&card->lock, flags);
1837 atomic_inc(&reply->received);
1838 wake_up(&reply->wait_q);
1840 qeth_put_reply(reply);
1844 spin_unlock_irqrestore(&card->lock, flags);
1846 memcpy(&card->seqno.pdu_hdr_ack,
1847 QETH_PDU_HEADER_SEQ_NO(iob->data),
1848 QETH_SEQ_NO_LENGTH);
1849 qeth_release_buffer(channel,iob);
1853 qeth_prepare_control_data(struct qeth_card *card, int len,
1854 struct qeth_cmd_buffer *iob)
1856 qeth_setup_ccw(&card->write,iob->data,len);
1857 iob->callback = qeth_release_buffer;
1859 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1860 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1861 card->seqno.trans_hdr++;
1862 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1863 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1864 card->seqno.pdu_hdr++;
1865 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1866 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1867 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1871 qeth_send_control_data(struct qeth_card *card, int len,
1872 struct qeth_cmd_buffer *iob,
1874 (struct qeth_card *, struct qeth_reply*, unsigned long),
1879 unsigned long flags;
1880 struct qeth_reply *reply = NULL;
1881 unsigned long timeout;
1883 QETH_DBF_TEXT(trace, 2, "sendctl");
1885 reply = qeth_alloc_reply(card);
1887 PRINT_WARN("Could no alloc qeth_reply!\n");
1890 reply->callback = reply_cb;
1891 reply->param = reply_param;
1892 if (card->state == CARD_STATE_DOWN)
1893 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1895 reply->seqno = card->seqno.ipa++;
1896 init_waitqueue_head(&reply->wait_q);
1897 spin_lock_irqsave(&card->lock, flags);
1898 list_add_tail(&reply->list, &card->cmd_waiter_list);
1899 spin_unlock_irqrestore(&card->lock, flags);
1900 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1902 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
1903 qeth_prepare_control_data(card, len, iob);
1905 if (IS_IPA(iob->data))
1906 timeout = jiffies + QETH_IPA_TIMEOUT;
1908 timeout = jiffies + QETH_TIMEOUT;
1910 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1911 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1912 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1913 (addr_t) iob, 0, 0);
1914 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1916 PRINT_WARN("qeth_send_control_data: "
1917 "ccw_device_start rc = %i\n", rc);
1918 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1919 spin_lock_irqsave(&card->lock, flags);
1920 list_del_init(&reply->list);
1921 qeth_put_reply(reply);
1922 spin_unlock_irqrestore(&card->lock, flags);
1923 qeth_release_buffer(iob->channel, iob);
1924 atomic_set(&card->write.irq_pending, 0);
1925 wake_up(&card->wait_q);
1928 while (!atomic_read(&reply->received)) {
1929 if (time_after(jiffies, timeout)) {
1930 spin_lock_irqsave(&reply->card->lock, flags);
1931 list_del_init(&reply->list);
1932 spin_unlock_irqrestore(&reply->card->lock, flags);
1934 atomic_inc(&reply->received);
1935 wake_up(&reply->wait_q);
1940 qeth_put_reply(reply);
1945 qeth_osn_send_control_data(struct qeth_card *card, int len,
1946 struct qeth_cmd_buffer *iob)
1948 unsigned long flags;
1951 QETH_DBF_TEXT(trace, 5, "osndctrd");
1953 wait_event(card->wait_q,
1954 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1955 qeth_prepare_control_data(card, len, iob);
1956 QETH_DBF_TEXT(trace, 6, "osnoirqp");
1957 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1958 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1959 (addr_t) iob, 0, 0);
1960 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1962 PRINT_WARN("qeth_osn_send_control_data: "
1963 "ccw_device_start rc = %i\n", rc);
1964 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1965 qeth_release_buffer(iob->channel, iob);
1966 atomic_set(&card->write.irq_pending, 0);
1967 wake_up(&card->wait_q);
1973 qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1976 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1977 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1978 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1979 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1983 qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1988 QETH_DBF_TEXT(trace,4,"osndipa");
1990 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1991 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1993 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1994 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1995 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1996 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1997 return qeth_osn_send_control_data(card, s1, iob);
2001 qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2003 (struct qeth_card *,struct qeth_reply*, unsigned long),
2009 QETH_DBF_TEXT(trace,4,"sendipa");
2011 if (card->options.layer2)
2012 if (card->info.type == QETH_CARD_TYPE_OSN)
2013 prot_type = QETH_PROT_OSN2;
2015 prot_type = QETH_PROT_LAYER2;
2017 prot_type = QETH_PROT_TCPIP;
2018 qeth_prepare_ipa_cmd(card,iob,prot_type);
2019 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
2020 reply_cb, reply_param);
2026 qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2029 struct qeth_cmd_buffer *iob;
2031 QETH_DBF_TEXT(setup, 2, "cmenblcb");
2033 iob = (struct qeth_cmd_buffer *) data;
2034 memcpy(&card->token.cm_filter_r,
2035 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2036 QETH_MPC_TOKEN_LENGTH);
2037 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2042 qeth_cm_enable(struct qeth_card *card)
2045 struct qeth_cmd_buffer *iob;
2047 QETH_DBF_TEXT(setup,2,"cmenable");
2049 iob = qeth_wait_for_buffer(&card->write);
2050 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2051 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2052 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2053 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2054 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2056 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2057 qeth_cm_enable_cb, NULL);
2062 qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2066 struct qeth_cmd_buffer *iob;
2068 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
2070 iob = (struct qeth_cmd_buffer *) data;
2071 memcpy(&card->token.cm_connection_r,
2072 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2073 QETH_MPC_TOKEN_LENGTH);
2074 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2079 qeth_cm_setup(struct qeth_card *card)
2082 struct qeth_cmd_buffer *iob;
2084 QETH_DBF_TEXT(setup,2,"cmsetup");
2086 iob = qeth_wait_for_buffer(&card->write);
2087 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2088 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2089 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2090 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2091 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2092 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2093 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2094 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2095 qeth_cm_setup_cb, NULL);
2101 qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2105 __u16 mtu, framesize;
2108 struct qeth_cmd_buffer *iob;
2110 QETH_DBF_TEXT(setup, 2, "ulpenacb");
2112 iob = (struct qeth_cmd_buffer *) data;
2113 memcpy(&card->token.ulp_filter_r,
2114 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2115 QETH_MPC_TOKEN_LENGTH);
2116 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
2117 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2118 mtu = qeth_get_mtu_outof_framesize(framesize);
2121 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2124 card->info.max_mtu = mtu;
2125 card->info.initial_mtu = mtu;
2126 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2128 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2129 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
2130 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2133 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2134 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2136 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2137 card->info.link_type = link_type;
2139 card->info.link_type = 0;
2140 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2145 qeth_ulp_enable(struct qeth_card *card)
2149 struct qeth_cmd_buffer *iob;
2151 /*FIXME: trace view callbacks*/
2152 QETH_DBF_TEXT(setup,2,"ulpenabl");
2154 iob = qeth_wait_for_buffer(&card->write);
2155 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2157 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2158 (__u8) card->info.portno;
2159 if (card->options.layer2)
2160 if (card->info.type == QETH_CARD_TYPE_OSN)
2161 prot_type = QETH_PROT_OSN2;
2163 prot_type = QETH_PROT_LAYER2;
2165 prot_type = QETH_PROT_TCPIP;
2167 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2168 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2169 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2170 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2171 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2172 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2173 card->info.portname, 9);
2174 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2175 qeth_ulp_enable_cb, NULL);
2181 qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2184 struct qeth_cmd_buffer *iob;
2186 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2188 iob = (struct qeth_cmd_buffer *) data;
2189 memcpy(&card->token.ulp_connection_r,
2190 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2191 QETH_MPC_TOKEN_LENGTH);
2192 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2197 qeth_ulp_setup(struct qeth_card *card)
2201 struct qeth_cmd_buffer *iob;
2202 struct ccw_dev_id dev_id;
2204 QETH_DBF_TEXT(setup,2,"ulpsetup");
2206 iob = qeth_wait_for_buffer(&card->write);
2207 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2209 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2210 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2211 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2212 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2213 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2214 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2216 ccw_device_get_id(CARD_DDEV(card), &dev_id);
2217 memcpy(QETH_ULP_SETUP_CUA(iob->data), &dev_id.devno, 2);
2218 temp = (card->info.cula << 8) + card->info.unit_addr2;
2219 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2220 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2221 qeth_ulp_setup_cb, NULL);
2226 qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2227 unsigned int siga_error, const char *dbftext)
2229 if (qdio_error || siga_error) {
2230 QETH_DBF_TEXT(trace, 2, dbftext);
2231 QETH_DBF_TEXT(qerr, 2, dbftext);
2232 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
2233 buf->element[15].flags & 0xff);
2234 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
2235 buf->element[14].flags & 0xff);
2236 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2237 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
2243 static struct sk_buff *
2244 qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
2246 struct sk_buff* skb;
2250 if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2251 add_len = sizeof(struct qeth_hdr);
2252 #ifdef CONFIG_QETH_VLAN
2254 add_len = VLAN_HLEN;
2256 skb = dev_alloc_skb(length + add_len);
2258 skb_reserve(skb, add_len);
2263 qeth_create_skb_frag(struct qdio_buffer_element *element,
2264 struct sk_buff **pskb,
2265 int offset, int *pfrag, int data_len)
2267 struct page *page = virt_to_page(element->addr);
2269 /* the upper protocol layers assume that there is data in the
2270 * skb itself. Copy a small amount (64 bytes) to make them
2272 *pskb = dev_alloc_skb(64 + QETH_FAKE_LL_LEN_ETH);
2275 skb_reserve(*pskb, QETH_FAKE_LL_LEN_ETH);
2276 if (data_len <= 64) {
2277 memcpy(skb_put(*pskb, data_len), element->addr + offset,
2281 memcpy(skb_put(*pskb, 64), element->addr + offset, 64);
2282 skb_fill_page_desc(*pskb, *pfrag, page, offset + 64,
2284 (*pskb)->data_len += data_len - 64;
2285 (*pskb)->len += data_len - 64;
2286 (*pskb)->truesize += data_len - 64;
2290 skb_fill_page_desc(*pskb, *pfrag, page, offset, data_len);
2291 (*pskb)->data_len += data_len;
2292 (*pskb)->len += data_len;
2293 (*pskb)->truesize += data_len;
2299 static inline struct qeth_buffer_pool_entry *
2300 qeth_find_free_buffer_pool_entry(struct qeth_card *card)
2302 struct list_head *plh;
2303 struct qeth_buffer_pool_entry *entry;
2307 if (list_empty(&card->qdio.in_buf_pool.entry_list))
2310 list_for_each(plh, &card->qdio.in_buf_pool.entry_list) {
2311 entry = list_entry(plh, struct qeth_buffer_pool_entry, list);
2313 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2314 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2320 list_del_init(&entry->list);
2325 /* no free buffer in pool so take first one and swap pages */
2326 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2327 struct qeth_buffer_pool_entry, list);
2328 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2329 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2330 page = alloc_page(GFP_ATOMIC|GFP_DMA);
2334 free_page((unsigned long)entry->elements[i]);
2335 entry->elements[i] = page_address(page);
2336 if (card->options.performance_stats)
2337 card->perf_stats.sg_alloc_page_rx++;
2341 list_del_init(&entry->list);
2345 static struct sk_buff *
2346 qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2347 struct qdio_buffer_element **__element, int *__offset,
2348 struct qeth_hdr **hdr)
2350 struct qdio_buffer_element *element = *__element;
2351 int offset = *__offset;
2352 struct sk_buff *skb = NULL;
2359 QETH_DBF_TEXT(trace,6,"nextskb");
2360 /* qeth_hdr must not cross element boundaries */
2361 if (element->length < offset + sizeof(struct qeth_hdr)){
2362 if (qeth_is_last_sbale(element))
2366 if (element->length < sizeof(struct qeth_hdr))
2369 *hdr = element->addr + offset;
2371 offset += sizeof(struct qeth_hdr);
2372 if (card->options.layer2)
2373 if (card->info.type == QETH_CARD_TYPE_OSN)
2374 skb_len = (*hdr)->hdr.osn.pdu_length;
2376 skb_len = (*hdr)->hdr.l2.pkt_length;
2378 skb_len = (*hdr)->hdr.l3.length;
2382 if ((skb_len >= card->options.rx_sg_cb) &&
2383 (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
2384 (!atomic_read(&card->force_alloc_skb))) {
2387 if (card->options.fake_ll) {
2388 if (card->dev->type == ARPHRD_IEEE802_TR) {
2389 if (!(skb = qeth_get_skb(skb_len +
2390 QETH_FAKE_LL_LEN_TR, *hdr)))
2392 skb_reserve(skb, QETH_FAKE_LL_LEN_TR);
2394 if (!(skb = qeth_get_skb(skb_len +
2395 QETH_FAKE_LL_LEN_ETH, *hdr)))
2397 skb_reserve(skb, QETH_FAKE_LL_LEN_ETH);
2400 skb = qeth_get_skb(skb_len, *hdr);
2406 data_ptr = element->addr + offset;
2408 data_len = min(skb_len, (int)(element->length - offset));
2411 if (qeth_create_skb_frag(element, &skb, offset,
2415 memcpy(skb_put(skb, data_len), data_ptr,
2419 skb_len -= data_len;
2421 if (qeth_is_last_sbale(element)){
2422 QETH_DBF_TEXT(trace,4,"unexeob");
2423 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2424 QETH_DBF_TEXT(qerr,2,"unexeob");
2425 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2426 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2427 dev_kfree_skb_any(skb);
2428 card->stats.rx_errors++;
2433 data_ptr = element->addr;
2438 *__element = element;
2440 if (use_rx_sg && card->options.performance_stats) {
2441 card->perf_stats.sg_skbs_rx++;
2442 card->perf_stats.sg_frags_rx += skb_shinfo(skb)->nr_frags;
2446 if (net_ratelimit()){
2447 PRINT_WARN("No memory for packet received on %s.\n",
2448 QETH_CARD_IFNAME(card));
2449 QETH_DBF_TEXT(trace,2,"noskbmem");
2450 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2452 card->stats.rx_dropped++;
2457 qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2459 struct qeth_card *card;
2462 QETH_DBF_TEXT(trace,6,"typtrans");
2464 card = (struct qeth_card *)dev->priv;
2466 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2467 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2468 return tr_type_trans(skb,dev);
2469 #endif /* CONFIG_TR */
2470 skb_reset_mac_header(skb);
2471 skb_pull(skb, ETH_HLEN );
2474 if (*eth->h_dest & 1) {
2475 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2476 skb->pkt_type = PACKET_BROADCAST;
2478 skb->pkt_type = PACKET_MULTICAST;
2479 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2480 skb->pkt_type = PACKET_OTHERHOST;
2482 if (ntohs(eth->h_proto) >= 1536)
2483 return eth->h_proto;
2484 if (*(unsigned short *) (skb->data) == 0xFFFF)
2485 return htons(ETH_P_802_3);
2486 return htons(ETH_P_802_2);
2490 qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2491 struct qeth_hdr *hdr)
2493 struct trh_hdr *fake_hdr;
2494 struct trllc *fake_llc;
2495 struct iphdr *ip_hdr;
2497 QETH_DBF_TEXT(trace,5,"skbfktr");
2498 skb_set_mac_header(skb, -QETH_FAKE_LL_LEN_TR);
2499 /* this is a fake ethernet header */
2500 fake_hdr = tr_hdr(skb);
2502 /* the destination MAC address */
2503 switch (skb->pkt_type){
2504 case PACKET_MULTICAST:
2505 switch (skb->protocol){
2506 #ifdef CONFIG_QETH_IPV6
2507 case __constant_htons(ETH_P_IPV6):
2508 ndisc_mc_map((struct in6_addr *)
2509 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2510 fake_hdr->daddr, card->dev, 0);
2512 #endif /* CONFIG_QETH_IPV6 */
2513 case __constant_htons(ETH_P_IP):
2514 ip_hdr = (struct iphdr *)skb->data;
2515 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2518 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2521 case PACKET_BROADCAST:
2522 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2525 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2527 /* the source MAC address */
2528 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2529 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2531 memset(fake_hdr->saddr, 0, TR_ALEN);
2533 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2534 fake_llc->dsap = EXTENDED_SAP;
2535 fake_llc->ssap = EXTENDED_SAP;
2536 fake_llc->llc = UI_CMD;
2537 fake_llc->protid[0] = 0;
2538 fake_llc->protid[1] = 0;
2539 fake_llc->protid[2] = 0;
2540 fake_llc->ethertype = ETH_P_IP;
2544 qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
2545 struct qeth_hdr *hdr)
2547 struct ethhdr *fake_hdr;
2548 struct iphdr *ip_hdr;
2550 QETH_DBF_TEXT(trace,5,"skbfketh");
2551 skb_set_mac_header(skb, -QETH_FAKE_LL_LEN_ETH);
2552 /* this is a fake ethernet header */
2553 fake_hdr = eth_hdr(skb);
2555 /* the destination MAC address */
2556 switch (skb->pkt_type){
2557 case PACKET_MULTICAST:
2558 switch (skb->protocol){
2559 #ifdef CONFIG_QETH_IPV6
2560 case __constant_htons(ETH_P_IPV6):
2561 ndisc_mc_map((struct in6_addr *)
2562 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2563 fake_hdr->h_dest, card->dev, 0);
2565 #endif /* CONFIG_QETH_IPV6 */
2566 case __constant_htons(ETH_P_IP):
2567 ip_hdr = (struct iphdr *)skb->data;
2568 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
2571 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2574 case PACKET_BROADCAST:
2575 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2578 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2580 /* the source MAC address */
2581 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2582 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2584 memset(fake_hdr->h_source, 0, ETH_ALEN);
2586 fake_hdr->h_proto = skb->protocol;
2590 qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2591 struct qeth_hdr *hdr)
2593 if (card->dev->type == ARPHRD_IEEE802_TR)
2594 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2596 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2600 qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2601 struct qeth_hdr *hdr)
2603 skb->pkt_type = PACKET_HOST;
2604 skb->protocol = qeth_type_trans(skb, skb->dev);
2605 if (card->options.checksum_type == NO_CHECKSUMMING)
2606 skb->ip_summed = CHECKSUM_UNNECESSARY;
2608 skb->ip_summed = CHECKSUM_NONE;
2609 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
2613 qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2614 struct qeth_hdr *hdr)
2616 unsigned short vlan_id = 0;
2617 #ifdef CONFIG_QETH_IPV6
2618 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2619 skb->pkt_type = PACKET_HOST;
2620 skb->protocol = qeth_type_trans(skb, card->dev);
2623 #endif /* CONFIG_QETH_IPV6 */
2624 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2626 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2627 case QETH_CAST_UNICAST:
2628 skb->pkt_type = PACKET_HOST;
2630 case QETH_CAST_MULTICAST:
2631 skb->pkt_type = PACKET_MULTICAST;
2632 card->stats.multicast++;
2634 case QETH_CAST_BROADCAST:
2635 skb->pkt_type = PACKET_BROADCAST;
2636 card->stats.multicast++;
2638 case QETH_CAST_ANYCAST:
2639 case QETH_CAST_NOCAST:
2641 skb->pkt_type = PACKET_HOST;
2644 if (hdr->hdr.l3.ext_flags &
2645 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2646 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2647 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2650 if (card->options.fake_ll)
2651 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2653 skb_reset_mac_header(skb);
2654 skb->ip_summed = card->options.checksum_type;
2655 if (card->options.checksum_type == HW_CHECKSUMMING){
2656 if ( (hdr->hdr.l3.ext_flags &
2657 (QETH_HDR_EXT_CSUM_HDR_REQ |
2658 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2659 (QETH_HDR_EXT_CSUM_HDR_REQ |
2660 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2661 skb->ip_summed = CHECKSUM_UNNECESSARY;
2663 skb->ip_summed = SW_CHECKSUMMING;
2669 qeth_process_inbound_buffer(struct qeth_card *card,
2670 struct qeth_qdio_buffer *buf, int index)
2672 struct qdio_buffer_element *element;
2673 struct sk_buff *skb;
2674 struct qeth_hdr *hdr;
2679 /* get first element of current buffer */
2680 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2682 if (card->options.performance_stats)
2683 card->perf_stats.bufs_rec++;
2684 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2686 skb->dev = card->dev;
2687 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2688 qeth_layer2_rebuild_skb(card, skb, hdr);
2689 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2690 vlan_tag = qeth_rebuild_skb(card, skb, hdr);
2691 else { /*in case of OSN*/
2692 skb_push(skb, sizeof(struct qeth_hdr));
2693 skb_copy_to_linear_data(skb, hdr,
2694 sizeof(struct qeth_hdr));
2696 /* is device UP ? */
2697 if (!(card->dev->flags & IFF_UP)){
2698 dev_kfree_skb_any(skb);
2701 if (card->info.type == QETH_CARD_TYPE_OSN)
2702 rxrc = card->osn_info.data_cb(skb);
2704 #ifdef CONFIG_QETH_VLAN
2707 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2709 dev_kfree_skb_any(skb);
2714 rxrc = netif_rx(skb);
2715 card->dev->last_rx = jiffies;
2716 card->stats.rx_packets++;
2717 card->stats.rx_bytes += skb->len;
2722 qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2724 struct qeth_buffer_pool_entry *pool_entry;
2727 pool_entry = qeth_find_free_buffer_pool_entry(card);
2731 * since the buffer is accessed only from the input_tasklet
2732 * there shouldn't be a need to synchronize; also, since we use
2733 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2736 BUG_ON(!pool_entry);
2738 buf->pool_entry = pool_entry;
2739 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2740 buf->buffer->element[i].length = PAGE_SIZE;
2741 buf->buffer->element[i].addr = pool_entry->elements[i];
2742 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2743 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2745 buf->buffer->element[i].flags = 0;
2747 buf->state = QETH_QDIO_BUF_EMPTY;
2752 qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2753 struct qeth_qdio_out_buffer *buf)
2756 struct sk_buff *skb;
2758 /* is PCI flag set on buffer? */
2759 if (buf->buffer->element[0].flags & 0x40)
2760 atomic_dec(&queue->set_pci_flags_count);
2762 while ((skb = skb_dequeue(&buf->skb_list))){
2763 atomic_dec(&skb->users);
2764 dev_kfree_skb_any(skb);
2766 qeth_eddp_buf_release_contexts(buf);
2767 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2768 buf->buffer->element[i].length = 0;
2769 buf->buffer->element[i].addr = NULL;
2770 buf->buffer->element[i].flags = 0;
2772 buf->next_element_to_fill = 0;
2773 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2777 qeth_queue_input_buffer(struct qeth_card *card, int index)
2779 struct qeth_qdio_q *queue = card->qdio.in_q;
2785 QETH_DBF_TEXT(trace,6,"queinbuf");
2786 count = (index < queue->next_buf_to_init)?
2787 card->qdio.in_buf_pool.buf_count -
2788 (queue->next_buf_to_init - index) :
2789 card->qdio.in_buf_pool.buf_count -
2790 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2791 /* only requeue at a certain threshold to avoid SIGAs */
2792 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2793 for (i = queue->next_buf_to_init;
2794 i < queue->next_buf_to_init + count; ++i) {
2795 if (qeth_init_input_buffer(card,
2796 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q])) {
2803 if (newcount < count) {
2804 /* we are in memory shortage so we switch back to
2805 traditional skb allocation and drop packages */
2806 if (!atomic_read(&card->force_alloc_skb) &&
2808 PRINT_WARN("Switch to alloc skb\n");
2809 atomic_set(&card->force_alloc_skb, 3);
2812 if ((atomic_read(&card->force_alloc_skb) == 1) &&
2814 PRINT_WARN("Switch to sg\n");
2815 atomic_add_unless(&card->force_alloc_skb, -1, 0);
2819 * according to old code it should be avoided to requeue all
2820 * 128 buffers in order to benefit from PCI avoidance.
2821 * this function keeps at least one buffer (the buffer at
2822 * 'index') un-requeued -> this buffer is the first buffer that
2823 * will be requeued the next time
2825 if (card->options.performance_stats) {
2826 card->perf_stats.inbound_do_qdio_cnt++;
2827 card->perf_stats.inbound_do_qdio_start_time =
2830 rc = do_QDIO(CARD_DDEV(card),
2831 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2832 0, queue->next_buf_to_init, count, NULL);
2833 if (card->options.performance_stats)
2834 card->perf_stats.inbound_do_qdio_time +=
2836 card->perf_stats.inbound_do_qdio_start_time;
2838 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2839 "return %i (device %s).\n",
2840 rc, CARD_DDEV_ID(card));
2841 QETH_DBF_TEXT(trace,2,"qinberr");
2842 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2844 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2845 QDIO_MAX_BUFFERS_PER_Q;
2850 qeth_put_buffer_pool_entry(struct qeth_card *card,
2851 struct qeth_buffer_pool_entry *entry)
2853 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2854 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2858 qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2859 unsigned int qdio_err, unsigned int siga_err,
2860 unsigned int queue, int first_element, int count,
2861 unsigned long card_ptr)
2863 struct net_device *net_dev;
2864 struct qeth_card *card;
2865 struct qeth_qdio_buffer *buffer;
2869 QETH_DBF_TEXT(trace, 6, "qdinput");
2870 card = (struct qeth_card *) card_ptr;
2871 net_dev = card->dev;
2872 if (card->options.performance_stats) {
2873 card->perf_stats.inbound_cnt++;
2874 card->perf_stats.inbound_start_time = qeth_get_micros();
2876 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2877 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2878 QETH_DBF_TEXT(trace, 1,"qdinchk");
2879 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2880 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2881 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2882 qeth_schedule_recovery(card);
2886 for (i = first_element; i < (first_element + count); ++i) {
2887 index = i % QDIO_MAX_BUFFERS_PER_Q;
2888 buffer = &card->qdio.in_q->bufs[index];
2889 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
2890 qeth_check_qdio_errors(buffer->buffer,
2891 qdio_err, siga_err,"qinerr")))
2892 qeth_process_inbound_buffer(card, buffer, index);
2893 /* clear buffer and give back to hardware */
2894 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2895 qeth_queue_input_buffer(card, index);
2897 if (card->options.performance_stats)
2898 card->perf_stats.inbound_time += qeth_get_micros() -
2899 card->perf_stats.inbound_start_time;
2903 qeth_handle_send_error(struct qeth_card *card,
2904 struct qeth_qdio_out_buffer *buffer,
2905 unsigned int qdio_err, unsigned int siga_err)
2907 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2908 int cc = siga_err & 3;
2910 QETH_DBF_TEXT(trace, 6, "hdsnderr");
2911 qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr");
2915 QETH_DBF_TEXT(trace, 1,"lnkfail");
2916 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2917 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2918 (u16)qdio_err, (u8)sbalf15);
2919 return QETH_SEND_ERROR_LINK_FAILURE;
2921 return QETH_SEND_ERROR_NONE;
2923 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2924 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2925 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2926 return QETH_SEND_ERROR_KICK_IT;
2928 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2929 return QETH_SEND_ERROR_RETRY;
2930 return QETH_SEND_ERROR_LINK_FAILURE;
2931 /* look at qdio_error and sbalf 15 */
2933 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2934 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2935 return QETH_SEND_ERROR_LINK_FAILURE;
2938 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2939 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2940 return QETH_SEND_ERROR_KICK_IT;
2945 qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2946 int index, int count)
2948 struct qeth_qdio_out_buffer *buf;
2951 unsigned int qdio_flags;
2953 QETH_DBF_TEXT(trace, 6, "flushbuf");
2955 for (i = index; i < index + count; ++i) {
2956 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2957 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2958 SBAL_FLAGS_LAST_ENTRY;
2960 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2963 if (!queue->do_pack){
2964 if ((atomic_read(&queue->used_buffers) >=
2965 (QETH_HIGH_WATERMARK_PACK -
2966 QETH_WATERMARK_PACK_FUZZ)) &&
2967 !atomic_read(&queue->set_pci_flags_count)){
2968 /* it's likely that we'll go to packing
2970 atomic_inc(&queue->set_pci_flags_count);
2971 buf->buffer->element[0].flags |= 0x40;
2974 if (!atomic_read(&queue->set_pci_flags_count)){
2976 * there's no outstanding PCI any more, so we
2977 * have to request a PCI to be sure that the PCI
2978 * will wake at some time in the future then we
2979 * can flush packed buffers that might still be
2980 * hanging around, which can happen if no
2981 * further send was requested by the stack
2983 atomic_inc(&queue->set_pci_flags_count);
2984 buf->buffer->element[0].flags |= 0x40;
2989 queue->card->dev->trans_start = jiffies;
2990 if (queue->card->options.performance_stats) {
2991 queue->card->perf_stats.outbound_do_qdio_cnt++;
2992 queue->card->perf_stats.outbound_do_qdio_start_time =
2995 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
2997 qdio_flags |= QDIO_FLAG_UNDER_INTERRUPT;
2998 if (atomic_read(&queue->set_pci_flags_count))
2999 qdio_flags |= QDIO_FLAG_PCI_OUT;
3000 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
3001 queue->queue_no, index, count, NULL);
3002 if (queue->card->options.performance_stats)
3003 queue->card->perf_stats.outbound_do_qdio_time +=
3005 queue->card->perf_stats.outbound_do_qdio_start_time;
3007 QETH_DBF_TEXT(trace, 2, "flushbuf");
3008 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
3009 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
3010 queue->card->stats.tx_errors += count;
3011 /* this must not happen under normal circumstances. if it
3012 * happens something is really wrong -> recover */
3013 qeth_schedule_recovery(queue->card);
3016 atomic_add(count, &queue->used_buffers);
3017 if (queue->card->options.performance_stats)
3018 queue->card->perf_stats.bufs_sent += count;
3022 * Switched to packing state if the number of used buffers on a queue
3023 * reaches a certain limit.
3026 qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
3028 if (!queue->do_pack) {
3029 if (atomic_read(&queue->used_buffers)
3030 >= QETH_HIGH_WATERMARK_PACK){
3031 /* switch non-PACKING -> PACKING */
3032 QETH_DBF_TEXT(trace, 6, "np->pack");
3033 if (queue->card->options.performance_stats)
3034 queue->card->perf_stats.sc_dp_p++;
3041 * Switches from packing to non-packing mode. If there is a packing
3042 * buffer on the queue this buffer will be prepared to be flushed.
3043 * In that case 1 is returned to inform the caller. If no buffer
3044 * has to be flushed, zero is returned.
3047 qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
3049 struct qeth_qdio_out_buffer *buffer;
3050 int flush_count = 0;
3052 if (queue->do_pack) {
3053 if (atomic_read(&queue->used_buffers)
3054 <= QETH_LOW_WATERMARK_PACK) {
3055 /* switch PACKING -> non-PACKING */
3056 QETH_DBF_TEXT(trace, 6, "pack->np");
3057 if (queue->card->options.performance_stats)
3058 queue->card->perf_stats.sc_p_dp++;
3060 /* flush packing buffers */
3061 buffer = &queue->bufs[queue->next_buf_to_fill];
3062 if ((atomic_read(&buffer->state) ==
3063 QETH_QDIO_BUF_EMPTY) &&
3064 (buffer->next_element_to_fill > 0)) {
3065 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
3067 queue->next_buf_to_fill =
3068 (queue->next_buf_to_fill + 1) %
3069 QDIO_MAX_BUFFERS_PER_Q;
3077 * Called to flush a packing buffer if no more pci flags are on the queue.
3078 * Checks if there is a packing buffer and prepares it to be flushed.
3079 * In that case returns 1, otherwise zero.
3082 qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
3084 struct qeth_qdio_out_buffer *buffer;
3086 buffer = &queue->bufs[queue->next_buf_to_fill];
3087 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
3088 (buffer->next_element_to_fill > 0)){
3089 /* it's a packing buffer */
3090 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
3091 queue->next_buf_to_fill =
3092 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
3099 qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
3103 int q_was_packing = 0;
3106 * check if weed have to switch to non-packing mode or if
3107 * we have to get a pci flag out on the queue
3109 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
3110 !atomic_read(&queue->set_pci_flags_count)){
3111 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
3112 QETH_OUT_Q_UNLOCKED) {
3114 * If we get in here, there was no action in
3115 * do_send_packet. So, we check if there is a
3116 * packing buffer to be flushed here.
3118 netif_stop_queue(queue->card->dev);
3119 index = queue->next_buf_to_fill;
3120 q_was_packing = queue->do_pack;
3121 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
3123 !atomic_read(&queue->set_pci_flags_count))
3125 qeth_flush_buffers_on_no_pci(queue);
3126 if (queue->card->options.performance_stats &&
3128 queue->card->perf_stats.bufs_sent_pack +=
3131 qeth_flush_buffers(queue, 1, index, flush_cnt);
3132 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3138 qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3139 unsigned int qdio_error, unsigned int siga_error,
3140 unsigned int __queue, int first_element, int count,
3141 unsigned long card_ptr)
3143 struct qeth_card *card = (struct qeth_card *) card_ptr;
3144 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3145 struct qeth_qdio_out_buffer *buffer;
3148 QETH_DBF_TEXT(trace, 6, "qdouhdl");
3149 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
3150 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
3151 QETH_DBF_TEXT(trace, 2, "achkcond");
3152 QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
3153 QETH_DBF_TEXT_(trace, 2, "%08x", status);
3154 netif_stop_queue(card->dev);
3155 qeth_schedule_recovery(card);
3159 if (card->options.performance_stats) {
3160 card->perf_stats.outbound_handler_cnt++;
3161 card->perf_stats.outbound_handler_start_time =
3164 for(i = first_element; i < (first_element + count); ++i){
3165 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
3166 /*we only handle the KICK_IT error by doing a recovery */
3167 if (qeth_handle_send_error(card, buffer,
3168 qdio_error, siga_error)
3169 == QETH_SEND_ERROR_KICK_IT){
3170 netif_stop_queue(card->dev);
3171 qeth_schedule_recovery(card);
3174 qeth_clear_output_buffer(queue, buffer);
3176 atomic_sub(count, &queue->used_buffers);
3177 /* check if we need to do something on this outbound queue */
3178 if (card->info.type != QETH_CARD_TYPE_IQD)
3179 qeth_check_outbound_queue(queue);
3181 netif_wake_queue(queue->card->dev);
3182 if (card->options.performance_stats)
3183 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3184 card->perf_stats.outbound_handler_start_time;
3188 qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
3191 param_field[0] = _ascebc['P'];
3192 param_field[1] = _ascebc['C'];
3193 param_field[2] = _ascebc['I'];
3194 param_field[3] = _ascebc['T'];
3195 *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card);
3196 *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card);
3197 *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card);
3201 qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
3203 param_field[16] = _ascebc['B'];
3204 param_field[17] = _ascebc['L'];
3205 param_field[18] = _ascebc['K'];
3206 param_field[19] = _ascebc['T'];
3207 *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total;
3208 *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet;
3209 *((unsigned int *) (¶m_field[28])) = card->info.blkt.inter_packet_jumbo;
3213 qeth_initialize_working_pool_list(struct qeth_card *card)
3215 struct qeth_buffer_pool_entry *entry;
3217 QETH_DBF_TEXT(trace,5,"inwrklst");
3219 list_for_each_entry(entry,
3220 &card->qdio.init_pool.entry_list, init_list) {
3221 qeth_put_buffer_pool_entry(card,entry);
3226 qeth_clear_working_pool_list(struct qeth_card *card)
3228 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3230 QETH_DBF_TEXT(trace,5,"clwrklst");
3231 list_for_each_entry_safe(pool_entry, tmp,
3232 &card->qdio.in_buf_pool.entry_list, list){
3233 list_del(&pool_entry->list);
3238 qeth_free_buffer_pool(struct qeth_card *card)
3240 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3242 QETH_DBF_TEXT(trace,5,"freepool");
3243 list_for_each_entry_safe(pool_entry, tmp,
3244 &card->qdio.init_pool.entry_list, init_list){
3245 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3246 free_page((unsigned long)pool_entry->elements[i]);
3247 list_del(&pool_entry->init_list);
3253 qeth_alloc_buffer_pool(struct qeth_card *card)
3255 struct qeth_buffer_pool_entry *pool_entry;
3259 QETH_DBF_TEXT(trace,5,"alocpool");
3260 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3261 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3263 qeth_free_buffer_pool(card);
3266 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
3267 ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
3270 free_page((unsigned long)
3271 pool_entry->elements[--j]);
3273 qeth_free_buffer_pool(card);
3276 pool_entry->elements[j] = ptr;
3278 list_add(&pool_entry->init_list,
3279 &card->qdio.init_pool.entry_list);
3285 qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3287 QETH_DBF_TEXT(trace, 2, "realcbp");
3289 if ((card->state != CARD_STATE_DOWN) &&
3290 (card->state != CARD_STATE_RECOVER))
3293 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3294 qeth_clear_working_pool_list(card);
3295 qeth_free_buffer_pool(card);
3296 card->qdio.in_buf_pool.buf_count = bufcnt;
3297 card->qdio.init_pool.buf_count = bufcnt;
3298 return qeth_alloc_buffer_pool(card);
3302 qeth_alloc_qdio_buffers(struct qeth_card *card)
3306 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3308 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
3309 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
3312 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3313 GFP_KERNEL|GFP_DMA);
3314 if (!card->qdio.in_q)
3316 QETH_DBF_TEXT(setup, 2, "inq");
3317 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3318 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3319 /* give inbound qeth_qdio_buffers their qdio_buffers */
3320 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3321 card->qdio.in_q->bufs[i].buffer =
3322 &card->qdio.in_q->qdio_bufs[i];
3323 /* inbound buffer pool */
3324 if (qeth_alloc_buffer_pool(card))
3328 kmalloc(card->qdio.no_out_queues *
3329 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3330 if (!card->qdio.out_qs)
3332 for (i = 0; i < card->qdio.no_out_queues; ++i) {
3333 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3334 GFP_KERNEL|GFP_DMA);
3335 if (!card->qdio.out_qs[i])
3337 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3338 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3339 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3340 card->qdio.out_qs[i]->queue_no = i;
3341 /* give outbound qeth_qdio_buffers their qdio_buffers */
3342 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3343 card->qdio.out_qs[i]->bufs[j].buffer =
3344 &card->qdio.out_qs[i]->qdio_bufs[j];
3345 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3348 &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
3349 &qdio_out_skb_queue_key);
3350 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3357 kfree(card->qdio.out_qs[--i]);
3358 kfree(card->qdio.out_qs);
3360 qeth_free_buffer_pool(card);
3362 kfree(card->qdio.in_q);
3364 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3369 qeth_free_qdio_buffers(struct qeth_card *card)
3373 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3374 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
3375 QETH_QDIO_UNINITIALIZED)
3377 kfree(card->qdio.in_q);
3378 /* inbound buffer pool */
3379 qeth_free_buffer_pool(card);
3380 /* free outbound qdio_qs */
3381 for (i = 0; i < card->qdio.no_out_queues; ++i){
3382 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3383 qeth_clear_output_buffer(card->qdio.out_qs[i],
3384 &card->qdio.out_qs[i]->bufs[j]);
3385 kfree(card->qdio.out_qs[i]);
3387 kfree(card->qdio.out_qs);
3391 qeth_clear_qdio_buffers(struct qeth_card *card)
3395 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3396 /* clear outbound buffers to free skbs */
3397 for (i = 0; i < card->qdio.no_out_queues; ++i)
3398 if (card->qdio.out_qs[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]);
3406 qeth_init_qdio_info(struct qeth_card *card)
3408 QETH_DBF_TEXT(setup, 4, "intqdinf");
3409 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3411 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3412 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3413 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3414 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3415 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3419 qeth_init_qdio_queues(struct qeth_card *card)
3424 QETH_DBF_TEXT(setup, 2, "initqdqs");
3427 memset(card->qdio.in_q->qdio_bufs, 0,
3428 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3429 qeth_initialize_working_pool_list(card);
3430 /*give only as many buffers to hardware as we have buffer pool entries*/
3431 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3432 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3433 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3434 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3435 card->qdio.in_buf_pool.buf_count - 1, NULL);
3437 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3440 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3442 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3445 /* outbound queue */
3446 for (i = 0; i < card->qdio.no_out_queues; ++i){
3447 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3448 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3449 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3450 qeth_clear_output_buffer(card->qdio.out_qs[i],
3451 &card->qdio.out_qs[i]->bufs[j]);
3453 card->qdio.out_qs[i]->card = card;
3454 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3455 card->qdio.out_qs[i]->do_pack = 0;
3456 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3457 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3458 atomic_set(&card->qdio.out_qs[i]->state,
3459 QETH_OUT_Q_UNLOCKED);
3465 qeth_qdio_establish(struct qeth_card *card)
3467 struct qdio_initialize init_data;
3468 char *qib_param_field;
3469 struct qdio_buffer **in_sbal_ptrs;
3470 struct qdio_buffer **out_sbal_ptrs;
3474 QETH_DBF_TEXT(setup, 2, "qdioest");
3476 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3478 if (!qib_param_field)
3481 qeth_create_qib_param_field(card, qib_param_field);
3482 qeth_create_qib_param_field_blkt(card, qib_param_field);
3484 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3486 if (!in_sbal_ptrs) {
3487 kfree(qib_param_field);
3490 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3491 in_sbal_ptrs[i] = (struct qdio_buffer *)
3492 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3495 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3496 sizeof(void *), GFP_KERNEL);
3497 if (!out_sbal_ptrs) {
3498 kfree(in_sbal_ptrs);
3499 kfree(qib_param_field);
3502 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3503 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3504 out_sbal_ptrs[k] = (struct qdio_buffer *)
3505 virt_to_phys(card->qdio.out_qs[i]->
3509 memset(&init_data, 0, sizeof(struct qdio_initialize));
3510 init_data.cdev = CARD_DDEV(card);
3511 init_data.q_format = qeth_get_qdio_q_format(card);
3512 init_data.qib_param_field_format = 0;
3513 init_data.qib_param_field = qib_param_field;
3514 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3515 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3516 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3517 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3518 init_data.no_input_qs = 1;
3519 init_data.no_output_qs = card->qdio.no_out_queues;
3520 init_data.input_handler = (qdio_handler_t *)
3521 qeth_qdio_input_handler;
3522 init_data.output_handler = (qdio_handler_t *)
3523 qeth_qdio_output_handler;
3524 init_data.int_parm = (unsigned long) card;
3525 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3526 QDIO_OUTBOUND_0COPY_SBALS |
3527 QDIO_USE_OUTBOUND_PCIS;
3528 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3529 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3531 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3532 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED)
3533 if ((rc = qdio_initialize(&init_data)))
3534 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3536 kfree(out_sbal_ptrs);
3537 kfree(in_sbal_ptrs);
3538 kfree(qib_param_field);
3543 qeth_qdio_activate(struct qeth_card *card)
3545 QETH_DBF_TEXT(setup,3,"qdioact");
3546 return qdio_activate(CARD_DDEV(card), 0);
3550 qeth_clear_channel(struct qeth_channel *channel)
3552 unsigned long flags;
3553 struct qeth_card *card;
3556 QETH_DBF_TEXT(trace,3,"clearch");
3557 card = CARD_FROM_CDEV(channel->ccwdev);
3558 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3559 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3560 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3564 rc = wait_event_interruptible_timeout(card->wait_q,
3565 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3566 if (rc == -ERESTARTSYS)
3568 if (channel->state != CH_STATE_STOPPED)
3570 channel->state = CH_STATE_DOWN;
3575 qeth_halt_channel(struct qeth_channel *channel)
3577 unsigned long flags;
3578 struct qeth_card *card;
3581 QETH_DBF_TEXT(trace,3,"haltch");
3582 card = CARD_FROM_CDEV(channel->ccwdev);
3583 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3584 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3585 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3589 rc = wait_event_interruptible_timeout(card->wait_q,
3590 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3591 if (rc == -ERESTARTSYS)
3593 if (channel->state != CH_STATE_HALTED)
3599 qeth_halt_channels(struct qeth_card *card)
3601 int rc1 = 0, rc2=0, rc3 = 0;
3603 QETH_DBF_TEXT(trace,3,"haltchs");
3604 rc1 = qeth_halt_channel(&card->read);
3605 rc2 = qeth_halt_channel(&card->write);
3606 rc3 = qeth_halt_channel(&card->data);
3614 qeth_clear_channels(struct qeth_card *card)
3616 int rc1 = 0, rc2=0, rc3 = 0;
3618 QETH_DBF_TEXT(trace,3,"clearchs");
3619 rc1 = qeth_clear_channel(&card->read);
3620 rc2 = qeth_clear_channel(&card->write);
3621 rc3 = qeth_clear_channel(&card->data);
3630 qeth_clear_halt_card(struct qeth_card *card, int halt)
3634 QETH_DBF_TEXT(trace,3,"clhacrd");
3635 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3638 rc = qeth_halt_channels(card);
3641 return qeth_clear_channels(card);
3645 qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3649 QETH_DBF_TEXT(trace,3,"qdioclr");
3650 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
3651 QETH_QDIO_CLEANING)) {
3652 case QETH_QDIO_ESTABLISHED:
3653 if ((rc = qdio_cleanup(CARD_DDEV(card),
3654 (card->info.type == QETH_CARD_TYPE_IQD) ?
3655 QDIO_FLAG_CLEANUP_USING_HALT :
3656 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3657 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3658 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3660 case QETH_QDIO_CLEANING:
3665 if ((rc = qeth_clear_halt_card(card, use_halt)))
3666 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3667 card->state = CARD_STATE_DOWN;
3672 qeth_dm_act(struct qeth_card *card)
3675 struct qeth_cmd_buffer *iob;
3677 QETH_DBF_TEXT(setup,2,"dmact");
3679 iob = qeth_wait_for_buffer(&card->write);
3680 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3682 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3683 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3684 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3685 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3686 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3691 qeth_mpc_initialize(struct qeth_card *card)
3695 QETH_DBF_TEXT(setup,2,"mpcinit");
3697 if ((rc = qeth_issue_next_read(card))){
3698 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3701 if ((rc = qeth_cm_enable(card))){
3702 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3705 if ((rc = qeth_cm_setup(card))){
3706 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3709 if ((rc = qeth_ulp_enable(card))){
3710 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3713 if ((rc = qeth_ulp_setup(card))){
3714 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3717 if ((rc = qeth_alloc_qdio_buffers(card))){
3718 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3721 if ((rc = qeth_qdio_establish(card))){
3722 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3723 qeth_free_qdio_buffers(card);
3726 if ((rc = qeth_qdio_activate(card))){
3727 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3730 if ((rc = qeth_dm_act(card))){
3731 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3737 qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
3741 static struct net_device *
3742 qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3744 struct net_device *dev = NULL;
3747 case QETH_CARD_TYPE_OSAE:
3749 case QETH_LINK_TYPE_LANE_TR:
3750 case QETH_LINK_TYPE_HSTR:
3752 dev = alloc_trdev(0);
3753 #endif /* CONFIG_TR */
3756 dev = alloc_etherdev(0);
3759 case QETH_CARD_TYPE_IQD:
3760 dev = alloc_netdev(0, "hsi%d", ether_setup);
3762 case QETH_CARD_TYPE_OSN:
3763 dev = alloc_netdev(0, "osn%d", ether_setup);
3766 dev = alloc_etherdev(0);
3771 /*hard_header fake function; used in case fake_ll is set */
3773 qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3774 unsigned short type, void *daddr, void *saddr,
3777 if(dev->type == ARPHRD_IEEE802_TR){
3778 struct trh_hdr *hdr;
3779 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3780 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3781 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3782 return QETH_FAKE_LL_LEN_TR;
3786 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3787 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3788 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3789 if (type != ETH_P_802_3)
3790 hdr->h_proto = htons(type);
3792 hdr->h_proto = htons(len);
3793 return QETH_FAKE_LL_LEN_ETH;
3799 qeth_send_packet(struct qeth_card *, struct sk_buff *);
3802 qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3805 struct qeth_card *card;
3807 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3808 card = (struct qeth_card *)dev->priv;
3810 card->stats.tx_dropped++;
3811 card->stats.tx_errors++;
3812 /* return OK; otherwise ksoftirqd goes to 100% */
3813 return NETDEV_TX_OK;
3815 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3816 card->stats.tx_dropped++;
3817 card->stats.tx_errors++;
3818 card->stats.tx_carrier_errors++;
3819 dev_kfree_skb_any(skb);
3820 /* return OK; otherwise ksoftirqd goes to 100% */
3821 return NETDEV_TX_OK;
3823 if (card->options.performance_stats) {
3824 card->perf_stats.outbound_cnt++;
3825 card->perf_stats.outbound_start_time = qeth_get_micros();
3827 netif_stop_queue(dev);
3828 if ((rc = qeth_send_packet(card, skb))) {
3830 return NETDEV_TX_BUSY;
3832 card->stats.tx_errors++;
3833 card->stats.tx_dropped++;
3834 dev_kfree_skb_any(skb);
3835 /*set to OK; otherwise ksoftirqd goes to 100% */
3839 netif_wake_queue(dev);
3840 if (card->options.performance_stats)
3841 card->perf_stats.outbound_time += qeth_get_micros() -
3842 card->perf_stats.outbound_start_time;
3847 qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3850 #ifdef CONFIG_QETH_VLAN
3851 struct vlan_group *vg;
3854 if (!(vg = card->vlangrp))
3857 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3858 if (vlan_group_get_device(vg, i) == dev){
3859 rc = QETH_VLAN_CARD;
3863 if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card))
3871 qeth_verify_dev(struct net_device *dev)
3873 struct qeth_card *card;
3874 unsigned long flags;
3877 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3878 list_for_each_entry(card, &qeth_card_list.list, list){
3879 if (card->dev == dev){
3880 rc = QETH_REAL_CARD;
3883 rc = qeth_verify_vlan_dev(dev, card);
3887 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3892 static struct qeth_card *
3893 qeth_get_card_from_dev(struct net_device *dev)
3895 struct qeth_card *card = NULL;
3898 rc = qeth_verify_dev(dev);
3899 if (rc == QETH_REAL_CARD)
3900 card = (struct qeth_card *)dev->priv;
3901 else if (rc == QETH_VLAN_CARD)
3902 card = (struct qeth_card *)
3903 VLAN_DEV_INFO(dev)->real_dev->priv;
3905 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3910 qeth_tx_timeout(struct net_device *dev)
3912 struct qeth_card *card;
3914 card = (struct qeth_card *) dev->priv;
3915 card->stats.tx_errors++;
3916 qeth_schedule_recovery(card);
3920 qeth_open(struct net_device *dev)
3922 struct qeth_card *card;
3924 QETH_DBF_TEXT(trace, 4, "qethopen");
3926 card = (struct qeth_card *) dev->priv;
3928 if (card->state != CARD_STATE_SOFTSETUP)
3931 if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3932 (card->options.layer2) &&
3933 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
3934 QETH_DBF_TEXT(trace,4,"nomacadr");
3937 card->data.state = CH_STATE_UP;
3938 card->state = CARD_STATE_UP;
3939 card->dev->flags |= IFF_UP;
3940 netif_start_queue(dev);
3942 if (!card->lan_online && netif_carrier_ok(dev))
3943 netif_carrier_off(dev);
3948 qeth_stop(struct net_device *dev)
3950 struct qeth_card *card;
3952 QETH_DBF_TEXT(trace, 4, "qethstop");
3954 card = (struct qeth_card *) dev->priv;
3956 netif_tx_disable(dev);
3957 card->dev->flags &= ~IFF_UP;
3958 if (card->state == CARD_STATE_UP)
3959 card->state = CARD_STATE_SOFTSETUP;
3964 qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3966 int cast_type = RTN_UNSPEC;
3968 if (card->info.type == QETH_CARD_TYPE_OSN)
3971 if (skb->dst && skb->dst->neighbour){
3972 cast_type = skb->dst->neighbour->type;
3973 if ((cast_type == RTN_BROADCAST) ||
3974 (cast_type == RTN_MULTICAST) ||
3975 (cast_type == RTN_ANYCAST))
3980 /* try something else */
3981 if (skb->protocol == ETH_P_IPV6)
3982 return (skb_network_header(skb)[24] == 0xff) ?
3984 else if (skb->protocol == ETH_P_IP)
3985 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
3988 if (!memcmp(skb->data, skb->dev->broadcast, 6))
3989 return RTN_BROADCAST;
3993 hdr_mac = *((u16 *)skb->data);
3995 switch (card->info.link_type) {
3996 case QETH_LINK_TYPE_HSTR:
3997 case QETH_LINK_TYPE_LANE_TR:
3998 if ((hdr_mac == QETH_TR_MAC_NC) ||
3999 (hdr_mac == QETH_TR_MAC_C))
4000 return RTN_MULTICAST;
4002 /* eth or so multicast? */
4004 if ((hdr_mac == QETH_ETH_MAC_V4) ||
4005 (hdr_mac == QETH_ETH_MAC_V6))
4006 return RTN_MULTICAST;
4013 qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
4014 int ipv, int cast_type)
4016 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
4017 return card->qdio.default_out_queue;
4018 switch (card->qdio.no_out_queues) {
4020 if (cast_type && card->info.is_multicast_different)
4021 return card->info.is_multicast_different &
4022 (card->qdio.no_out_queues - 1);
4023 if (card->qdio.do_prio_queueing && (ipv == 4)) {
4024 const u8 tos = ip_hdr(skb)->tos;
4026 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
4027 if (tos & IP_TOS_NOTIMPORTANT)
4029 if (tos & IP_TOS_HIGHRELIABILITY)
4031 if (tos & IP_TOS_HIGHTHROUGHPUT)
4033 if (tos & IP_TOS_LOWDELAY)
4036 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
4037 return 3 - (tos >> 6);
4038 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
4041 return card->qdio.default_out_queue;
4042 case 1: /* fallthrough for single-out-queue 1920-device */
4044 return card->qdio.default_out_queue;
4049 qeth_get_ip_version(struct sk_buff *skb)
4051 switch (skb->protocol) {
4061 static struct qeth_hdr *
4062 __qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, int ipv)
4064 #ifdef CONFIG_QETH_VLAN
4066 if (card->vlangrp && vlan_tx_tag_present(skb) &&
4067 ((ipv == 6) || card->options.layer2) ) {
4069 * Move the mac addresses (6 bytes src, 6 bytes dest)
4070 * to the beginning of the new header. We are using three
4071 * memcpys instead of one memmove to save cycles.
4073 skb_push(skb, VLAN_HLEN);
4074 skb_copy_to_linear_data(skb, skb->data + 4, 4);
4075 skb_copy_to_linear_data_offset(skb, 4, skb->data + 8, 4);
4076 skb_copy_to_linear_data_offset(skb, 8, skb->data + 12, 4);
4077 tag = (u16 *)(skb->data + 12);
4079 * first two bytes = ETH_P_8021Q (0x8100)
4080 * second two bytes = VLANID
4082 *tag = __constant_htons(ETH_P_8021Q);
4083 *(tag + 1) = htons(vlan_tx_tag_get(skb));
4086 return ((struct qeth_hdr *)
4087 qeth_push_skb(card, skb, sizeof(struct qeth_hdr)));
4091 __qeth_free_new_skb(struct sk_buff *orig_skb, struct sk_buff *new_skb)
4093 if (orig_skb != new_skb)
4094 dev_kfree_skb_any(new_skb);
4097 static struct sk_buff *
4098 qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb,
4099 struct qeth_hdr **hdr, int ipv)
4101 struct sk_buff *new_skb, *new_skb2;
4103 QETH_DBF_TEXT(trace, 6, "prepskb");
4105 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
4108 new_skb2 = qeth_realloc_headroom(card, new_skb,
4109 sizeof(struct qeth_hdr));
4111 __qeth_free_new_skb(skb, new_skb);
4115 __qeth_free_new_skb(new_skb2, new_skb);
4117 *hdr = __qeth_prepare_skb(card, new_skb, ipv);
4119 __qeth_free_new_skb(skb, new_skb);
4126 qeth_get_qeth_hdr_flags4(int cast_type)
4128 if (cast_type == RTN_MULTICAST)
4129 return QETH_CAST_MULTICAST;
4130 if (cast_type == RTN_BROADCAST)
4131 return QETH_CAST_BROADCAST;
4132 return QETH_CAST_UNICAST;
4136 qeth_get_qeth_hdr_flags6(int cast_type)
4138 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
4139 if (cast_type == RTN_MULTICAST)
4140 return ct | QETH_CAST_MULTICAST;
4141 if (cast_type == RTN_ANYCAST)
4142 return ct | QETH_CAST_ANYCAST;
4143 if (cast_type == RTN_BROADCAST)
4144 return ct | QETH_CAST_BROADCAST;
4145 return ct | QETH_CAST_UNICAST;
4149 qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
4150 struct sk_buff *skb)
4154 if (!memcmp(skb->data+QETH_HEADER_SIZE,
4155 skb->dev->broadcast,6)) { /* broadcast? */
4156 *(__u32 *)hdr->hdr.l2.flags |=
4157 QETH_LAYER2_FLAG_BROADCAST << 8;
4160 hdr_mac=*((__u16*)skb->data);
4162 switch (card->info.link_type) {
4163 case QETH_LINK_TYPE_HSTR:
4164 case QETH_LINK_TYPE_LANE_TR:
4165 if ((hdr_mac == QETH_TR_MAC_NC) ||
4166 (hdr_mac == QETH_TR_MAC_C) )
4167 *(__u32 *)hdr->hdr.l2.flags |=
4168 QETH_LAYER2_FLAG_MULTICAST << 8;
4170 *(__u32 *)hdr->hdr.l2.flags |=
4171 QETH_LAYER2_FLAG_UNICAST << 8;
4173 /* eth or so multicast? */
4175 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
4176 (hdr_mac==QETH_ETH_MAC_V6) )
4177 *(__u32 *)hdr->hdr.l2.flags |=
4178 QETH_LAYER2_FLAG_MULTICAST << 8;
4180 *(__u32 *)hdr->hdr.l2.flags |=
4181 QETH_LAYER2_FLAG_UNICAST << 8;
4186 qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4187 struct sk_buff *skb, int cast_type)
4189 memset(hdr, 0, sizeof(struct qeth_hdr));
4190 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
4192 /* set byte 0 to "0x02" and byte 3 to casting flags */
4193 if (cast_type==RTN_MULTICAST)
4194 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
4195 else if (cast_type==RTN_BROADCAST)
4196 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
4198 qeth_layer2_get_packet_type(card, hdr, skb);
4200 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
4201 #ifdef CONFIG_QETH_VLAN
4202 /* VSWITCH relies on the VLAN
4203 * information to be present in
4204 * the QDIO header */
4205 if ((card->vlangrp != NULL) &&
4206 vlan_tx_tag_present(skb)) {
4207 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
4208 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
4214 qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4215 struct sk_buff *skb, int ipv, int cast_type)
4217 QETH_DBF_TEXT(trace, 6, "fillhdr");
4219 memset(hdr, 0, sizeof(struct qeth_hdr));
4220 if (card->options.layer2) {
4221 qeth_layer2_fill_header(card, hdr, skb, cast_type);
4224 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
4225 hdr->hdr.l3.ext_flags = 0;
4226 #ifdef CONFIG_QETH_VLAN
4228 * before we're going to overwrite this location with next hop ip.
4229 * v6 uses passthrough, v4 sets the tag in the QDIO header.
4231 if (card->vlangrp && vlan_tx_tag_present(skb)) {
4232 hdr->hdr.l3.ext_flags = (ipv == 4) ?
4233 QETH_HDR_EXT_VLAN_FRAME :
4234 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
4235 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
4237 #endif /* CONFIG_QETH_VLAN */
4238 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
4239 if (ipv == 4) { /* IPv4 */
4240 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
4241 memset(hdr->hdr.l3.dest_addr, 0, 12);
4242 if ((skb->dst) && (skb->dst->neighbour)) {
4243 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
4244 *((u32 *) skb->dst->neighbour->primary_key);
4246 /* fill in destination address used in ip header */
4247 *((u32 *)(&hdr->hdr.l3.dest_addr[12])) =
4250 } else if (ipv == 6) { /* IPv6 or passthru */
4251 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
4252 if ((skb->dst) && (skb->dst->neighbour)) {
4253 memcpy(hdr->hdr.l3.dest_addr,
4254 skb->dst->neighbour->primary_key, 16);
4256 /* fill in destination address used in ip header */
4257 memcpy(hdr->hdr.l3.dest_addr,
4258 &ipv6_hdr(skb)->daddr, 16);
4260 } else { /* passthrough */
4261 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
4262 !memcmp(skb->data + sizeof(struct qeth_hdr) +
4263 sizeof(__u16), skb->dev->broadcast, 6)) {
4264 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4266 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
4267 skb->dev->broadcast, 6)) { /* broadcast? */
4268 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4271 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
4272 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
4273 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
4279 __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
4280 int is_tso, int *next_element_to_fill)
4282 int length = skb->len;
4288 element = *next_element_to_fill;
4290 first_lap = (is_tso == 0 ? 1 : 0);
4292 while (length > 0) {
4293 /* length_here is the remaining amount of data in this page */
4294 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4295 if (length < length_here)
4296 length_here = length;
4298 buffer->element[element].addr = data;
4299 buffer->element[element].length = length_here;
4300 length -= length_here;
4303 buffer->element[element].flags = 0;
4305 buffer->element[element].flags =
4306 SBAL_FLAGS_LAST_FRAG;
4309 buffer->element[element].flags =
4310 SBAL_FLAGS_FIRST_FRAG;
4312 buffer->element[element].flags =
4313 SBAL_FLAGS_MIDDLE_FRAG;
4315 data += length_here;
4319 *next_element_to_fill = element;
4323 qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4324 struct qeth_qdio_out_buffer *buf,
4325 struct sk_buff *skb)
4327 struct qdio_buffer *buffer;
4328 struct qeth_hdr_tso *hdr;
4329 int flush_cnt = 0, hdr_len, large_send = 0;
4331 QETH_DBF_TEXT(trace, 6, "qdfillbf");
4333 buffer = buf->buffer;
4334 atomic_inc(&skb->users);
4335 skb_queue_tail(&buf->skb_list, skb);
4337 hdr = (struct qeth_hdr_tso *) skb->data;
4338 /*check first on TSO ....*/
4339 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4340 int element = buf->next_element_to_fill;
4342 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4343 /*fill first buffer entry only with header information */
4344 buffer->element[element].addr = skb->data;
4345 buffer->element[element].length = hdr_len;
4346 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4347 buf->next_element_to_fill++;
4348 skb->data += hdr_len;
4349 skb->len -= hdr_len;
4352 if (skb_shinfo(skb)->nr_frags == 0)
4353 __qeth_fill_buffer(skb, buffer, large_send,
4354 (int *)&buf->next_element_to_fill);
4356 __qeth_fill_buffer_frag(skb, buffer, large_send,
4357 (int *)&buf->next_element_to_fill);
4359 if (!queue->do_pack) {
4360 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4361 /* set state to PRIMED -> will be flushed */
4362 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4365 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4366 if (queue->card->options.performance_stats)
4367 queue->card->perf_stats.skbs_sent_pack++;
4368 if (buf->next_element_to_fill >=
4369 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4371 * packed buffer if full -> set state PRIMED
4372 * -> will be flushed
4374 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4382 qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4383 struct sk_buff *skb, struct qeth_hdr *hdr,
4384 int elements_needed,
4385 struct qeth_eddp_context *ctx)
4387 struct qeth_qdio_out_buffer *buffer;
4388 int buffers_needed = 0;
4392 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4394 /* spin until we get the queue ... */
4395 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4396 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4397 /* ... now we've got the queue */
4398 index = queue->next_buf_to_fill;
4399 buffer = &queue->bufs[queue->next_buf_to_fill];
4401 * check if buffer is empty to make sure that we do not 'overtake'
4402 * ourselves and try to fill a buffer that is already primed
4404 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4407 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4408 QDIO_MAX_BUFFERS_PER_Q;
4410 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4411 if (buffers_needed < 0)
4413 queue->next_buf_to_fill =
4414 (queue->next_buf_to_fill + buffers_needed) %
4415 QDIO_MAX_BUFFERS_PER_Q;
4417 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4419 qeth_fill_buffer(queue, buffer, skb);
4420 qeth_flush_buffers(queue, 0, index, 1);
4422 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4423 WARN_ON(buffers_needed != flush_cnt);
4424 qeth_flush_buffers(queue, 0, index, flush_cnt);
4428 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4433 qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4434 struct sk_buff *skb, struct qeth_hdr *hdr,
4435 int elements_needed, struct qeth_eddp_context *ctx)
4437 struct qeth_qdio_out_buffer *buffer;
4439 int flush_count = 0;
4444 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4446 /* spin until we get the queue ... */
4447 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4448 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4449 start_index = queue->next_buf_to_fill;
4450 buffer = &queue->bufs[queue->next_buf_to_fill];
4452 * check if buffer is empty to make sure that we do not 'overtake'
4453 * ourselves and try to fill a buffer that is already primed
4455 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4456 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4459 /* check if we need to switch packing state of this queue */
4460 qeth_switch_to_packing_if_needed(queue);
4461 if (queue->do_pack){
4464 /* does packet fit in current buffer? */
4465 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4466 buffer->next_element_to_fill) < elements_needed){
4467 /* ... no -> set state PRIMED */
4468 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4470 queue->next_buf_to_fill =
4471 (queue->next_buf_to_fill + 1) %
4472 QDIO_MAX_BUFFERS_PER_Q;
4473 buffer = &queue->bufs[queue->next_buf_to_fill];
4474 /* we did a step forward, so check buffer state
4476 if (atomic_read(&buffer->state) !=
4477 QETH_QDIO_BUF_EMPTY){
4478 qeth_flush_buffers(queue, 0, start_index, flush_count);
4479 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4484 /* check if we have enough elements (including following
4485 * free buffers) to handle eddp context */
4486 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4487 printk("eddp tx_dropped 1\n");
4494 tmp = qeth_fill_buffer(queue, buffer, skb);
4496 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4498 printk("eddp tx_dropped 2\n");
4503 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4504 QDIO_MAX_BUFFERS_PER_Q;
4508 qeth_flush_buffers(queue, 0, start_index, flush_count);
4509 else if (!atomic_read(&queue->set_pci_flags_count))
4510 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
4512 * queue->state will go from LOCKED -> UNLOCKED or from
4513 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4514 * (switch packing state or flush buffer to get another pci flag out).
4515 * In that case we will enter this loop
4517 while (atomic_dec_return(&queue->state)){
4519 start_index = queue->next_buf_to_fill;
4520 /* check if we can go back to non-packing state */
4521 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4523 * check if we need to flush a packing buffer to get a pci
4524 * flag out on the queue
4526 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4527 flush_count += qeth_flush_buffers_on_no_pci(queue);
4529 qeth_flush_buffers(queue, 0, start_index, flush_count);
4531 /* at this point the queue is UNLOCKED again */
4532 if (queue->card->options.performance_stats && do_pack)
4533 queue->card->perf_stats.bufs_sent_pack += flush_count;
4539 qeth_get_elements_no(struct qeth_card *card, void *hdr,
4540 struct sk_buff *skb, int elems)
4542 int elements_needed = 0;
4544 if (skb_shinfo(skb)->nr_frags > 0)
4545 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4546 if (elements_needed == 0)
4547 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4548 + skb->len) >> PAGE_SHIFT);
4549 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4550 PRINT_ERR("Invalid size of IP packet "
4551 "(Number=%d / Length=%d). Discarded.\n",
4552 (elements_needed+elems), skb->len);
4555 return elements_needed;
4560 qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4564 struct qeth_qdio_out_q *queue;
4565 struct qeth_hdr *hdr = NULL;
4566 int elements_needed = 0;
4567 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4568 struct qeth_eddp_context *ctx = NULL;
4569 int tx_bytes = skb->len;
4570 unsigned short nr_frags = skb_shinfo(skb)->nr_frags;
4571 unsigned short tso_size = skb_shinfo(skb)->gso_size;
4572 struct sk_buff *new_skb, *new_skb2;
4575 QETH_DBF_TEXT(trace, 6, "sendpkt");
4578 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4579 (skb->protocol == htons(ETH_P_IPV6)))
4581 cast_type = qeth_get_cast_type(card, skb);
4582 if ((cast_type == RTN_BROADCAST) &&
4583 (card->info.broadcast_capable == 0))
4585 queue = card->qdio.out_qs
4586 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4587 if (!card->options.layer2) {
4588 ipv = qeth_get_ip_version(skb);
4589 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4590 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
4593 if(card->dev->type == ARPHRD_IEEE802_TR){
4594 skb_pull(new_skb, QETH_FAKE_LL_LEN_TR);
4596 skb_pull(new_skb, QETH_FAKE_LL_LEN_ETH);
4600 if (skb_is_gso(skb))
4601 large_send = card->options.large_send;
4602 /* check on OSN device*/
4603 if (card->info.type == QETH_CARD_TYPE_OSN)
4604 hdr = (struct qeth_hdr *)new_skb->data;
4605 /*are we able to do TSO ? */
4606 if ((large_send == QETH_LARGE_SEND_TSO) &&
4607 (cast_type == RTN_UNSPEC)) {
4608 rc = qeth_tso_prepare_packet(card, new_skb, ipv, cast_type);
4610 __qeth_free_new_skb(skb, new_skb);
4614 } else if (card->info.type != QETH_CARD_TYPE_OSN) {
4615 new_skb2 = qeth_prepare_skb(card, new_skb, &hdr, ipv);
4617 __qeth_free_new_skb(skb, new_skb);
4621 __qeth_free_new_skb(new_skb2, new_skb);
4623 qeth_fill_header(card, hdr, new_skb, ipv, cast_type);
4625 if (large_send == QETH_LARGE_SEND_EDDP) {
4626 ctx = qeth_eddp_create_context(card, new_skb, hdr,
4627 skb->sk->sk_protocol);
4629 __qeth_free_new_skb(skb, new_skb);
4630 PRINT_WARN("could not create eddp context\n");
4634 int elems = qeth_get_elements_no(card,(void*) hdr, new_skb,
4637 __qeth_free_new_skb(skb, new_skb);
4640 elements_needed += elems;
4643 if (card->info.type != QETH_CARD_TYPE_IQD)
4644 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
4645 elements_needed, ctx);
4647 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
4648 elements_needed, ctx);
4650 card->stats.tx_packets++;
4651 card->stats.tx_bytes += tx_bytes;
4653 dev_kfree_skb_any(skb);
4654 if (card->options.performance_stats) {
4656 !(large_send == QETH_LARGE_SEND_NO)) {
4657 card->perf_stats.large_send_bytes += tx_bytes;
4658 card->perf_stats.large_send_cnt++;
4661 card->perf_stats.sg_skbs_sent++;
4662 /* nr_frags + skb->data */
4663 card->perf_stats.sg_frags_sent +=
4668 card->stats.tx_dropped++;
4669 __qeth_free_new_skb(skb, new_skb);
4672 /* drop creator's reference */
4673 qeth_eddp_put_context(ctx);
4674 /* free skb; it's not referenced by a buffer */
4676 dev_kfree_skb_any(new_skb);
4682 qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4684 struct qeth_card *card = (struct qeth_card *) dev->priv;
4688 case MII_BMCR: /* Basic mode control register */
4690 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4691 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4692 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4693 rc |= BMCR_SPEED100;
4695 case MII_BMSR: /* Basic mode status register */
4696 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4697 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4700 case MII_PHYSID1: /* PHYS ID 1 */
4701 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4703 rc = (rc >> 5) & 0xFFFF;
4705 case MII_PHYSID2: /* PHYS ID 2 */
4706 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4708 case MII_ADVERTISE: /* Advertisement control reg */
4711 case MII_LPA: /* Link partner ability reg */
4712 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4713 LPA_100BASE4 | LPA_LPACK;
4715 case MII_EXPANSION: /* Expansion register */
4717 case MII_DCOUNTER: /* disconnect counter */
4719 case MII_FCSCOUNTER: /* false carrier counter */
4721 case MII_NWAYTEST: /* N-way auto-neg test register */
4723 case MII_RERRCOUNTER: /* rx error counter */
4724 rc = card->stats.rx_errors;
4726 case MII_SREVISION: /* silicon revision */
4728 case MII_RESV1: /* reserved 1 */
4730 case MII_LBRERROR: /* loopback, rx, bypass error */
4732 case MII_PHYADDR: /* physical address */
4734 case MII_RESV2: /* reserved 2 */
4736 case MII_TPISTATUS: /* TPI status for 10mbps */
4738 case MII_NCONFIG: /* network interface config */
4748 qeth_arp_get_error_cause(int *rc)
4751 case QETH_IPA_ARP_RC_FAILED:
4753 return "operation failed";
4754 case QETH_IPA_ARP_RC_NOTSUPP:
4756 return "operation not supported";
4757 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4759 return "argument out of range";
4760 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4762 return "query operation not supported";
4763 case QETH_IPA_ARP_RC_Q_NO_DATA:
4765 return "no query data available";
4767 return "unknown error";
4772 qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4776 qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4781 QETH_DBF_TEXT(trace,3,"arpstnoe");
4784 * currently GuestLAN only supports the ARP assist function
4785 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4786 * thus we say EOPNOTSUPP for this ARP function
4788 if (card->info.guestlan)
4790 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4791 PRINT_WARN("ARP processing not supported "
4792 "on %s!\n", QETH_CARD_IFNAME(card));
4795 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4796 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4800 PRINT_WARN("Could not set number of ARP entries on %s: "
4802 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4809 qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4810 struct qeth_arp_query_data *qdata,
4811 int entry_size, int uentry_size)
4817 entry_ptr = (char *)&qdata->data;
4818 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4819 for (i = 0; i < qdata->no_entries; ++i){
4820 /* strip off 32 bytes "media specific information" */
4821 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4822 entry_ptr += entry_size;
4823 uentry_ptr += uentry_size;
4828 qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4831 struct qeth_ipa_cmd *cmd;
4832 struct qeth_arp_query_data *qdata;
4833 struct qeth_arp_query_info *qinfo;
4838 QETH_DBF_TEXT(trace,4,"arpquecb");
4840 qinfo = (struct qeth_arp_query_info *) reply->param;
4841 cmd = (struct qeth_ipa_cmd *) data;
4842 if (cmd->hdr.return_code) {
4843 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4846 if (cmd->data.setassparms.hdr.return_code) {
4847 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4848 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4851 qdata = &cmd->data.setassparms.data.query_arp;
4852 switch(qdata->reply_bits){
4854 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4855 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4856 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4859 /* fall through to default */
4861 /* tr is the same as eth -> entry7 */
4862 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4863 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4864 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4867 /* check if there is enough room in userspace */
4868 if ((qinfo->udata_len - qinfo->udata_offset) <
4869 qdata->no_entries * uentry_size){
4870 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4871 cmd->hdr.return_code = -ENOMEM;
4872 PRINT_WARN("query ARP user space buffer is too small for "
4873 "the returned number of ARP entries. "
4874 "Aborting query!\n");
4877 QETH_DBF_TEXT_(trace, 4, "anore%i",
4878 cmd->data.setassparms.hdr.number_of_replies);
4879 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4880 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4882 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4883 /* strip off "media specific information" */
4884 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4887 /*copy entries to user buffer*/
4888 memcpy(qinfo->udata + qinfo->udata_offset,
4889 (char *)&qdata->data, qdata->no_entries*uentry_size);
4891 qinfo->no_entries += qdata->no_entries;
4892 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4893 /* check if all replies received ... */
4894 if (cmd->data.setassparms.hdr.seq_no <
4895 cmd->data.setassparms.hdr.number_of_replies)
4897 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4898 /* keep STRIP_ENTRIES flag so the user program can distinguish
4899 * stripped entries from normal ones */
4900 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4901 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4902 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4906 memcpy(qinfo->udata, &i, 4);
4911 qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4912 int len, int (*reply_cb)(struct qeth_card *,
4913 struct qeth_reply *,
4917 QETH_DBF_TEXT(trace,4,"sendarp");
4919 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4920 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4921 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4922 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4923 reply_cb, reply_param);
4927 qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4928 int len, int (*reply_cb)(struct qeth_card *,
4929 struct qeth_reply *,
4935 QETH_DBF_TEXT(trace,4,"sendsnmp");
4937 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4938 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4939 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4940 /* adjust PDU length fields in IPA_PDU_HEADER */
4941 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4943 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4944 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4945 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4946 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4947 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4948 reply_cb, reply_param);
4951 static struct qeth_cmd_buffer *
4952 qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4953 __u16, __u16, enum qeth_prot_versions);
4955 qeth_arp_query(struct qeth_card *card, char __user *udata)
4957 struct qeth_cmd_buffer *iob;
4958 struct qeth_arp_query_info qinfo = {0, };
4962 QETH_DBF_TEXT(trace,3,"arpquery");
4964 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4965 IPA_ARP_PROCESSING)) {
4966 PRINT_WARN("ARP processing not supported "
4967 "on %s!\n", QETH_CARD_IFNAME(card));
4970 /* get size of userspace buffer and mask_bits -> 6 bytes */
4971 if (copy_from_user(&qinfo, udata, 6))
4973 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL)))
4975 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4976 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4977 IPA_CMD_ASS_ARP_QUERY_INFO,
4978 sizeof(int),QETH_PROT_IPV4);
4980 rc = qeth_send_ipa_arp_cmd(card, iob,
4981 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4982 qeth_arp_query_cb, (void *)&qinfo);
4985 PRINT_WARN("Error while querying ARP cache on %s: %s "
4987 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4989 if (copy_to_user(udata, qinfo.udata, 4))
4992 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
5000 * SNMP command callback
5003 qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
5004 unsigned long sdata)
5006 struct qeth_ipa_cmd *cmd;
5007 struct qeth_arp_query_info *qinfo;
5008 struct qeth_snmp_cmd *snmp;
5009 unsigned char *data;
5012 QETH_DBF_TEXT(trace,3,"snpcmdcb");
5014 cmd = (struct qeth_ipa_cmd *) sdata;
5015 data = (unsigned char *)((char *)cmd - reply->offset);
5016 qinfo = (struct qeth_arp_query_info *) reply->param;
5017 snmp = &cmd->data.setadapterparms.data.snmp;
5019 if (cmd->hdr.return_code) {
5020 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
5023 if (cmd->data.setadapterparms.hdr.return_code) {
5024 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
5025 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
5028 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
5029 if (cmd->data.setadapterparms.hdr.seq_no == 1)
5030 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
5032 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
5034 /* check if there is enough room in userspace */
5035 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
5036 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
5037 cmd->hdr.return_code = -ENOMEM;
5040 QETH_DBF_TEXT_(trace, 4, "snore%i",
5041 cmd->data.setadapterparms.hdr.used_total);
5042 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
5043 /*copy entries to user buffer*/
5044 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
5045 memcpy(qinfo->udata + qinfo->udata_offset,
5047 data_len + offsetof(struct qeth_snmp_cmd,data));
5048 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
5050 memcpy(qinfo->udata + qinfo->udata_offset,
5051 (char *)&snmp->request, data_len);
5053 qinfo->udata_offset += data_len;
5054 /* check if all replies received ... */
5055 QETH_DBF_TEXT_(trace, 4, "srtot%i",
5056 cmd->data.setadapterparms.hdr.used_total);
5057 QETH_DBF_TEXT_(trace, 4, "srseq%i",
5058 cmd->data.setadapterparms.hdr.seq_no);
5059 if (cmd->data.setadapterparms.hdr.seq_no <
5060 cmd->data.setadapterparms.hdr.used_total)
5065 static struct qeth_cmd_buffer *
5066 qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
5067 enum qeth_prot_versions );
5069 static struct qeth_cmd_buffer *
5070 qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
5072 struct qeth_cmd_buffer *iob;
5073 struct qeth_ipa_cmd *cmd;
5075 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
5077 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5078 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
5079 cmd->data.setadapterparms.hdr.command_code = command;
5080 cmd->data.setadapterparms.hdr.used_total = 1;
5081 cmd->data.setadapterparms.hdr.seq_no = 1;
5087 * function to send SNMP commands to OSA-E card
5090 qeth_snmp_command(struct qeth_card *card, char __user *udata)
5092 struct qeth_cmd_buffer *iob;
5093 struct qeth_ipa_cmd *cmd;
5094 struct qeth_snmp_ureq *ureq;
5096 struct qeth_arp_query_info qinfo = {0, };
5099 QETH_DBF_TEXT(trace,3,"snmpcmd");
5101 if (card->info.guestlan)
5104 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
5105 (!card->options.layer2) ) {
5106 PRINT_WARN("SNMP Query MIBS not supported "
5107 "on %s!\n", QETH_CARD_IFNAME(card));
5110 /* skip 4 bytes (data_len struct member) to get req_len */
5111 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
5113 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
5115 QETH_DBF_TEXT(trace, 2, "snmpnome");
5118 if (copy_from_user(ureq, udata,
5119 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
5123 qinfo.udata_len = ureq->hdr.data_len;
5124 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){
5128 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
5130 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
5131 QETH_SNMP_SETADP_CMDLENGTH + req_len);
5132 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5133 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
5134 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
5135 qeth_snmp_command_cb, (void *)&qinfo);
5137 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
5138 QETH_CARD_IFNAME(card), rc);
5140 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
5150 qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
5154 qeth_default_setadapterparms_cb(struct qeth_card *card,
5155 struct qeth_reply *reply,
5156 unsigned long data);
5158 qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
5161 (struct qeth_card *, struct qeth_reply *, unsigned long),
5165 qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5167 struct qeth_cmd_buffer *iob;
5172 QETH_DBF_TEXT(trace,3,"arpadent");
5175 * currently GuestLAN only supports the ARP assist function
5176 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
5177 * thus we say EOPNOTSUPP for this ARP function
5179 if (card->info.guestlan)
5181 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5182 PRINT_WARN("ARP processing not supported "
5183 "on %s!\n", QETH_CARD_IFNAME(card));
5187 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5188 IPA_CMD_ASS_ARP_ADD_ENTRY,
5189 sizeof(struct qeth_arp_cache_entry),
5191 rc = qeth_send_setassparms(card, iob,
5192 sizeof(struct qeth_arp_cache_entry),
5193 (unsigned long) entry,
5194 qeth_default_setassparms_cb, NULL);
5197 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5198 PRINT_WARN("Could not add ARP entry for address %s on %s: "
5200 buf, QETH_CARD_IFNAME(card),
5201 qeth_arp_get_error_cause(&rc), tmp, tmp);
5207 qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5209 struct qeth_cmd_buffer *iob;
5210 char buf[16] = {0, };
5214 QETH_DBF_TEXT(trace,3,"arprment");
5217 * currently GuestLAN only supports the ARP assist function
5218 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5219 * thus we say EOPNOTSUPP for this ARP function
5221 if (card->info.guestlan)
5223 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5224 PRINT_WARN("ARP processing not supported "
5225 "on %s!\n", QETH_CARD_IFNAME(card));
5228 memcpy(buf, entry, 12);
5229 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5230 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5233 rc = qeth_send_setassparms(card, iob,
5234 12, (unsigned long)buf,
5235 qeth_default_setassparms_cb, NULL);
5239 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5240 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5242 buf, QETH_CARD_IFNAME(card),
5243 qeth_arp_get_error_cause(&rc), tmp, tmp);
5249 qeth_arp_flush_cache(struct qeth_card *card)
5254 QETH_DBF_TEXT(trace,3,"arpflush");
5257 * currently GuestLAN only supports the ARP assist function
5258 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5259 * thus we say EOPNOTSUPP for this ARP function
5261 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5263 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5264 PRINT_WARN("ARP processing not supported "
5265 "on %s!\n", QETH_CARD_IFNAME(card));
5268 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5269 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5272 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5273 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5280 qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5282 struct qeth_card *card = (struct qeth_card *)dev->priv;
5283 struct qeth_arp_cache_entry arp_entry;
5284 struct mii_ioctl_data *mii_data;
5290 if ((card->state != CARD_STATE_UP) &&
5291 (card->state != CARD_STATE_SOFTSETUP))
5294 if (card->info.type == QETH_CARD_TYPE_OSN)
5298 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5299 if ( !capable(CAP_NET_ADMIN) ||
5300 (card->options.layer2) ) {
5304 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5306 case SIOC_QETH_ARP_QUERY_INFO:
5307 if ( !capable(CAP_NET_ADMIN) ||
5308 (card->options.layer2) ) {
5312 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5314 case SIOC_QETH_ARP_ADD_ENTRY:
5315 if ( !capable(CAP_NET_ADMIN) ||
5316 (card->options.layer2) ) {
5320 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5321 sizeof(struct qeth_arp_cache_entry)))
5324 rc = qeth_arp_add_entry(card, &arp_entry);
5326 case SIOC_QETH_ARP_REMOVE_ENTRY:
5327 if ( !capable(CAP_NET_ADMIN) ||
5328 (card->options.layer2) ) {
5332 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5333 sizeof(struct qeth_arp_cache_entry)))
5336 rc = qeth_arp_remove_entry(card, &arp_entry);
5338 case SIOC_QETH_ARP_FLUSH_CACHE:
5339 if ( !capable(CAP_NET_ADMIN) ||
5340 (card->options.layer2) ) {
5344 rc = qeth_arp_flush_cache(card);
5346 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5347 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5349 case SIOC_QETH_GET_CARD_TYPE:
5350 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5351 !card->info.guestlan)
5356 mii_data = if_mii(rq);
5357 mii_data->phy_id = 0;
5360 mii_data = if_mii(rq);
5361 if (mii_data->phy_id != 0)
5364 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5371 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5375 static struct net_device_stats *
5376 qeth_get_stats(struct net_device *dev)
5378 struct qeth_card *card;
5380 card = (struct qeth_card *) (dev->priv);
5382 QETH_DBF_TEXT(trace,5,"getstat");
5384 return &card->stats;
5388 qeth_change_mtu(struct net_device *dev, int new_mtu)
5390 struct qeth_card *card;
5393 card = (struct qeth_card *) (dev->priv);
5395 QETH_DBF_TEXT(trace,4,"chgmtu");
5396 sprintf(dbf_text, "%8x", new_mtu);
5397 QETH_DBF_TEXT(trace,4,dbf_text);
5401 if (new_mtu > 65535)
5403 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5404 (!qeth_mtu_is_valid(card, new_mtu)))
5410 #ifdef CONFIG_QETH_VLAN
5412 qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5414 struct qeth_card *card;
5415 unsigned long flags;
5417 QETH_DBF_TEXT(trace,4,"vlanreg");
5419 card = (struct qeth_card *) dev->priv;
5420 spin_lock_irqsave(&card->vlanlock, flags);
5421 card->vlangrp = grp;
5422 spin_unlock_irqrestore(&card->vlanlock, flags);
5426 qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5430 struct sk_buff *skb;
5431 struct sk_buff_head tmp_list;
5433 skb_queue_head_init(&tmp_list);
5434 lockdep_set_class(&tmp_list.lock, &qdio_out_skb_queue_key);
5435 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5436 while ((skb = skb_dequeue(&buf->skb_list))){
5437 if (vlan_tx_tag_present(skb) &&
5438 (vlan_tx_tag_get(skb) == vid)) {
5439 atomic_dec(&skb->users);
5442 skb_queue_tail(&tmp_list, skb);
5445 while ((skb = skb_dequeue(&tmp_list)))
5446 skb_queue_tail(&buf->skb_list, skb);
5450 qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5454 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5455 for (i = 0; i < card->qdio.no_out_queues; ++i){
5456 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5457 qeth_free_vlan_buffer(card, &card->qdio.
5458 out_qs[i]->bufs[j], vid);
5463 qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5465 struct in_device *in_dev;
5466 struct in_ifaddr *ifa;
5467 struct qeth_ipaddr *addr;
5469 QETH_DBF_TEXT(trace, 4, "frvaddr4");
5472 in_dev = __in_dev_get_rcu(vlan_group_get_device(card->vlangrp, vid));
5475 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5476 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5478 addr->u.a4.addr = ifa->ifa_address;
5479 addr->u.a4.mask = ifa->ifa_mask;
5480 addr->type = QETH_IP_TYPE_NORMAL;
5481 if (!qeth_delete_ip(card, addr))
5490 qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5492 #ifdef CONFIG_QETH_IPV6
5493 struct inet6_dev *in6_dev;
5494 struct inet6_ifaddr *ifa;
5495 struct qeth_ipaddr *addr;
5497 QETH_DBF_TEXT(trace, 4, "frvaddr6");
5499 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
5502 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5503 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5505 memcpy(&addr->u.a6.addr, &ifa->addr,
5506 sizeof(struct in6_addr));
5507 addr->u.a6.pfxlen = ifa->prefix_len;
5508 addr->type = QETH_IP_TYPE_NORMAL;
5509 if (!qeth_delete_ip(card, addr))
5513 in6_dev_put(in6_dev);
5514 #endif /* CONFIG_QETH_IPV6 */
5518 qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5520 if (card->options.layer2 || !card->vlangrp)
5522 qeth_free_vlan_addresses4(card, vid);
5523 qeth_free_vlan_addresses6(card, vid);
5527 qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5528 struct qeth_reply *reply,
5531 struct qeth_ipa_cmd *cmd;
5533 QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5534 cmd = (struct qeth_ipa_cmd *) data;
5535 if (cmd->hdr.return_code) {
5536 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5537 "Continuing\n",cmd->data.setdelvlan.vlan_id,
5538 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5539 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5540 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5541 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5547 qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5548 enum qeth_ipa_cmds ipacmd)
5550 struct qeth_ipa_cmd *cmd;
5551 struct qeth_cmd_buffer *iob;
5553 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5554 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5555 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5556 cmd->data.setdelvlan.vlan_id = i;
5557 return qeth_send_ipa_cmd(card, iob,
5558 qeth_layer2_send_setdelvlan_cb, NULL);
5562 qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5566 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5570 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5571 if (vlan_group_get_device(card->vlangrp, i) == NULL)
5574 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5576 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5580 /*add_vid is layer 2 used only ....*/
5582 qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5584 struct qeth_card *card;
5586 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5588 card = (struct qeth_card *) dev->priv;
5589 if (!card->options.layer2)
5591 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5594 /*... kill_vid used for both modes*/
5596 qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5598 struct qeth_card *card;
5599 unsigned long flags;
5601 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5603 card = (struct qeth_card *) dev->priv;
5604 /* free all skbs for the vlan device */
5605 qeth_free_vlan_skbs(card, vid);
5606 spin_lock_irqsave(&card->vlanlock, flags);
5607 /* unregister IP addresses of vlan device */
5608 qeth_free_vlan_addresses(card, vid);
5609 vlan_group_set_device(card->vlangrp, vid, NULL);
5610 spin_unlock_irqrestore(&card->vlanlock, flags);
5611 if (card->options.layer2)
5612 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5613 qeth_set_multicast_list(card->dev);
5617 * Examine hardware response to SET_PROMISC_MODE
5620 qeth_setadp_promisc_mode_cb(struct qeth_card *card,
5621 struct qeth_reply *reply,
5624 struct qeth_ipa_cmd *cmd;
5625 struct qeth_ipacmd_setadpparms *setparms;
5627 QETH_DBF_TEXT(trace,4,"prmadpcb");
5629 cmd = (struct qeth_ipa_cmd *) data;
5630 setparms = &(cmd->data.setadapterparms);
5632 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
5633 if (cmd->hdr.return_code) {
5634 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
5635 setparms->data.mode = SET_PROMISC_MODE_OFF;
5637 card->info.promisc_mode = setparms->data.mode;
5641 * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5644 qeth_setadp_promisc_mode(struct qeth_card *card)
5646 enum qeth_ipa_promisc_modes mode;
5647 struct net_device *dev = card->dev;
5648 struct qeth_cmd_buffer *iob;
5649 struct qeth_ipa_cmd *cmd;
5651 QETH_DBF_TEXT(trace, 4, "setprom");
5653 if (((dev->flags & IFF_PROMISC) &&
5654 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5655 (!(dev->flags & IFF_PROMISC) &&
5656 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5658 mode = SET_PROMISC_MODE_OFF;
5659 if (dev->flags & IFF_PROMISC)
5660 mode = SET_PROMISC_MODE_ON;
5661 QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5663 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5664 sizeof(struct qeth_ipacmd_setadpparms));
5665 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5666 cmd->data.setadapterparms.data.mode = mode;
5667 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5671 * set multicast address on card
5674 qeth_set_multicast_list(struct net_device *dev)
5676 struct qeth_card *card = (struct qeth_card *) dev->priv;
5678 if (card->info.type == QETH_CARD_TYPE_OSN)
5681 QETH_DBF_TEXT(trace, 3, "setmulti");
5682 qeth_delete_mc_addresses(card);
5683 if (card->options.layer2) {
5684 qeth_layer2_add_multicast(card);
5687 qeth_add_multicast_ipv4(card);
5688 #ifdef CONFIG_QETH_IPV6
5689 qeth_add_multicast_ipv6(card);
5692 qeth_set_ip_addr_list(card);
5693 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5695 qeth_setadp_promisc_mode(card);
5699 qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5705 qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5707 if (dev->type == ARPHRD_IEEE802_TR)
5708 ip_tr_mc_map(ipm, mac);
5710 ip_eth_mc_map(ipm, mac);
5713 static struct qeth_ipaddr *
5714 qeth_get_addr_buffer(enum qeth_prot_versions prot)
5716 struct qeth_ipaddr *addr;
5718 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5720 PRINT_WARN("Not enough memory to add address\n");
5723 addr->type = QETH_IP_TYPE_NORMAL;
5729 qeth_osn_assist(struct net_device *dev,
5733 struct qeth_cmd_buffer *iob;
5734 struct qeth_card *card;
5737 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5740 card = (struct qeth_card *)dev->priv;
5743 if ((card->state != CARD_STATE_UP) &&
5744 (card->state != CARD_STATE_SOFTSETUP))
5746 iob = qeth_wait_for_buffer(&card->write);
5747 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5748 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5752 static struct net_device *
5753 qeth_netdev_by_devno(unsigned char *read_dev_no)
5755 struct qeth_card *card;
5756 struct net_device *ndev;
5757 unsigned char *readno;
5758 __u16 temp_dev_no, card_dev_no;
5760 unsigned long flags;
5763 memcpy(&temp_dev_no, read_dev_no, 2);
5764 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5765 list_for_each_entry(card, &qeth_card_list.list, list) {
5766 readno = CARD_RDEV_ID(card);
5767 readno += (strlen(readno) - 4);
5768 card_dev_no = simple_strtoul(readno, &endp, 16);
5769 if (card_dev_no == temp_dev_no) {
5774 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5779 qeth_osn_register(unsigned char *read_dev_no,
5780 struct net_device **dev,
5781 int (*assist_cb)(struct net_device *, void *),
5782 int (*data_cb)(struct sk_buff *))
5784 struct qeth_card * card;
5786 QETH_DBF_TEXT(trace, 2, "osnreg");
5787 *dev = qeth_netdev_by_devno(read_dev_no);
5790 card = (struct qeth_card *)(*dev)->priv;
5793 if ((assist_cb == NULL) || (data_cb == NULL))
5795 card->osn_info.assist_cb = assist_cb;
5796 card->osn_info.data_cb = data_cb;
5801 qeth_osn_deregister(struct net_device * dev)
5803 struct qeth_card *card;
5805 QETH_DBF_TEXT(trace, 2, "osndereg");
5808 card = (struct qeth_card *)dev->priv;
5811 card->osn_info.assist_cb = NULL;
5812 card->osn_info.data_cb = NULL;
5817 qeth_delete_mc_addresses(struct qeth_card *card)
5819 struct qeth_ipaddr *iptodo;
5820 unsigned long flags;
5822 QETH_DBF_TEXT(trace,4,"delmc");
5823 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5825 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5828 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5829 spin_lock_irqsave(&card->ip_lock, flags);
5830 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5832 spin_unlock_irqrestore(&card->ip_lock, flags);
5836 qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5838 struct qeth_ipaddr *ipm;
5839 struct ip_mc_list *im4;
5840 char buf[MAX_ADDR_LEN];
5842 QETH_DBF_TEXT(trace,4,"addmc");
5843 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5844 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5845 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5848 ipm->u.a4.addr = im4->multiaddr;
5849 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5850 ipm->is_multicast = 1;
5851 if (!qeth_add_ip(card,ipm))
5857 qeth_add_vlan_mc(struct qeth_card *card)
5859 #ifdef CONFIG_QETH_VLAN
5860 struct in_device *in_dev;
5861 struct vlan_group *vg;
5864 QETH_DBF_TEXT(trace,4,"addmcvl");
5865 if ( ((card->options.layer2 == 0) &&
5866 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5867 (card->vlangrp == NULL) )
5871 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5872 struct net_device *netdev = vlan_group_get_device(vg, i);
5873 if (netdev == NULL ||
5874 !(netdev->flags & IFF_UP))
5876 in_dev = in_dev_get(netdev);
5879 read_lock(&in_dev->mc_list_lock);
5880 qeth_add_mc(card,in_dev);
5881 read_unlock(&in_dev->mc_list_lock);
5888 qeth_add_multicast_ipv4(struct qeth_card *card)
5890 struct in_device *in4_dev;
5892 QETH_DBF_TEXT(trace,4,"chkmcv4");
5893 in4_dev = in_dev_get(card->dev);
5894 if (in4_dev == NULL)
5896 read_lock(&in4_dev->mc_list_lock);
5897 qeth_add_mc(card, in4_dev);
5898 qeth_add_vlan_mc(card);
5899 read_unlock(&in4_dev->mc_list_lock);
5900 in_dev_put(in4_dev);
5904 qeth_layer2_add_multicast(struct qeth_card *card)
5906 struct qeth_ipaddr *ipm;
5907 struct dev_mc_list *dm;
5909 QETH_DBF_TEXT(trace,4,"L2addmc");
5910 for (dm = card->dev->mc_list; dm; dm = dm->next) {
5911 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5914 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5915 ipm->is_multicast = 1;
5916 if (!qeth_add_ip(card, ipm))
5921 #ifdef CONFIG_QETH_IPV6
5923 qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5925 struct qeth_ipaddr *ipm;
5926 struct ifmcaddr6 *im6;
5927 char buf[MAX_ADDR_LEN];
5929 QETH_DBF_TEXT(trace,4,"addmc6");
5930 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5931 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5932 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5935 ipm->is_multicast = 1;
5936 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5937 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5938 sizeof(struct in6_addr));
5939 if (!qeth_add_ip(card,ipm))
5945 qeth_add_vlan_mc6(struct qeth_card *card)
5947 #ifdef CONFIG_QETH_VLAN
5948 struct inet6_dev *in_dev;
5949 struct vlan_group *vg;
5952 QETH_DBF_TEXT(trace,4,"admc6vl");
5953 if ( ((card->options.layer2 == 0) &&
5954 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5955 (card->vlangrp == NULL))
5959 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5960 struct net_device *netdev = vlan_group_get_device(vg, i);
5961 if (netdev == NULL ||
5962 !(netdev->flags & IFF_UP))
5964 in_dev = in6_dev_get(netdev);
5967 read_lock_bh(&in_dev->lock);
5968 qeth_add_mc6(card,in_dev);
5969 read_unlock_bh(&in_dev->lock);
5970 in6_dev_put(in_dev);
5972 #endif /* CONFIG_QETH_VLAN */
5976 qeth_add_multicast_ipv6(struct qeth_card *card)
5978 struct inet6_dev *in6_dev;
5980 QETH_DBF_TEXT(trace,4,"chkmcv6");
5981 if (!qeth_is_supported(card, IPA_IPV6))
5983 in6_dev = in6_dev_get(card->dev);
5984 if (in6_dev == NULL)
5986 read_lock_bh(&in6_dev->lock);
5987 qeth_add_mc6(card, in6_dev);
5988 qeth_add_vlan_mc6(card);
5989 read_unlock_bh(&in6_dev->lock);
5990 in6_dev_put(in6_dev);
5992 #endif /* CONFIG_QETH_IPV6 */
5995 qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5996 enum qeth_ipa_cmds ipacmd,
5997 int (*reply_cb) (struct qeth_card *,
6001 struct qeth_ipa_cmd *cmd;
6002 struct qeth_cmd_buffer *iob;
6004 QETH_DBF_TEXT(trace, 2, "L2sdmac");
6005 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
6006 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6007 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
6008 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
6009 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
6013 qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
6014 struct qeth_reply *reply,
6017 struct qeth_ipa_cmd *cmd;
6020 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
6021 cmd = (struct qeth_ipa_cmd *) data;
6022 mac = &cmd->data.setdelmac.mac[0];
6023 /* MAC already registered, needed in couple/uncouple case */
6024 if (cmd->hdr.return_code == 0x2005) {
6025 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
6026 "already existing on %s \n",
6027 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
6028 QETH_CARD_IFNAME(card));
6029 cmd->hdr.return_code = 0;
6031 if (cmd->hdr.return_code)
6032 PRINT_ERR("Could not set group MAC " \
6033 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
6034 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
6035 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
6040 qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
6042 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
6043 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
6044 qeth_layer2_send_setgroupmac_cb);
6048 qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
6049 struct qeth_reply *reply,
6052 struct qeth_ipa_cmd *cmd;
6055 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
6056 cmd = (struct qeth_ipa_cmd *) data;
6057 mac = &cmd->data.setdelmac.mac[0];
6058 if (cmd->hdr.return_code)
6059 PRINT_ERR("Could not delete group MAC " \
6060 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
6061 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
6062 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
6067 qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
6069 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
6070 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
6071 qeth_layer2_send_delgroupmac_cb);
6075 qeth_layer2_send_setmac_cb(struct qeth_card *card,
6076 struct qeth_reply *reply,
6079 struct qeth_ipa_cmd *cmd;
6081 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
6082 cmd = (struct qeth_ipa_cmd *) data;
6083 if (cmd->hdr.return_code) {
6084 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
6085 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
6086 cmd->hdr.return_code = -EIO;
6088 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
6089 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
6091 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
6092 "successfully registered on device %s\n",
6093 card->dev->dev_addr[0], card->dev->dev_addr[1],
6094 card->dev->dev_addr[2], card->dev->dev_addr[3],
6095 card->dev->dev_addr[4], card->dev->dev_addr[5],
6102 qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
6104 QETH_DBF_TEXT(trace, 2, "L2Setmac");
6105 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
6106 qeth_layer2_send_setmac_cb);
6110 qeth_layer2_send_delmac_cb(struct qeth_card *card,
6111 struct qeth_reply *reply,
6114 struct qeth_ipa_cmd *cmd;
6116 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
6117 cmd = (struct qeth_ipa_cmd *) data;
6118 if (cmd->hdr.return_code) {
6119 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
6120 cmd->hdr.return_code = -EIO;
6123 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
6128 qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
6130 QETH_DBF_TEXT(trace, 2, "L2Delmac");
6131 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
6133 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
6134 qeth_layer2_send_delmac_cb);
6138 qeth_layer2_set_mac_address(struct net_device *dev, void *p)
6140 struct sockaddr *addr = p;
6141 struct qeth_card *card;
6144 QETH_DBF_TEXT(trace, 3, "setmac");
6146 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
6147 QETH_DBF_TEXT(trace, 3, "setmcINV");
6150 card = (struct qeth_card *) dev->priv;
6152 if (!card->options.layer2) {
6153 PRINT_WARN("Setting MAC address on %s is not supported "
6154 "in Layer 3 mode.\n", dev->name);
6155 QETH_DBF_TEXT(trace, 3, "setmcLY3");
6158 if (card->info.type == QETH_CARD_TYPE_OSN) {
6159 PRINT_WARN("Setting MAC address on %s is not supported.\n",
6161 QETH_DBF_TEXT(trace, 3, "setmcOSN");
6164 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
6165 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
6166 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
6168 rc = qeth_layer2_send_setmac(card, addr->sa_data);
6173 qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
6174 __u8 command, enum qeth_prot_versions prot)
6176 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
6177 cmd->hdr.command = command;
6178 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
6179 cmd->hdr.seqno = card->seqno.ipa;
6180 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
6181 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
6182 if (card->options.layer2)
6183 cmd->hdr.prim_version_no = 2;
6185 cmd->hdr.prim_version_no = 1;
6186 cmd->hdr.param_count = 1;
6187 cmd->hdr.prot_version = prot;
6188 cmd->hdr.ipa_supported = 0;
6189 cmd->hdr.ipa_enabled = 0;
6192 static struct qeth_cmd_buffer *
6193 qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6194 enum qeth_prot_versions prot)
6196 struct qeth_cmd_buffer *iob;
6197 struct qeth_ipa_cmd *cmd;
6199 iob = qeth_wait_for_buffer(&card->write);
6200 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6201 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6207 qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6210 struct qeth_cmd_buffer *iob;
6211 struct qeth_ipa_cmd *cmd;
6213 QETH_DBF_TEXT(trace,4,"setdelmc");
6215 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6216 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6217 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6218 if (addr->proto == QETH_PROT_IPV6)
6219 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6220 sizeof(struct in6_addr));
6222 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6224 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6229 qeth_fill_netmask(u8 *netmask, unsigned int len)
6232 for (i=0;i<16;i++) {
6237 netmask[i] = (u8)(0xFF00>>j);
6244 qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6245 int ipacmd, unsigned int flags)
6248 struct qeth_cmd_buffer *iob;
6249 struct qeth_ipa_cmd *cmd;
6252 QETH_DBF_TEXT(trace,4,"setdelip");
6253 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6255 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6256 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6257 if (addr->proto == QETH_PROT_IPV6) {
6258 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6259 sizeof(struct in6_addr));
6260 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6261 memcpy(cmd->data.setdelip6.mask, netmask,
6262 sizeof(struct in6_addr));
6263 cmd->data.setdelip6.flags = flags;
6265 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6266 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6267 cmd->data.setdelip4.flags = flags;
6270 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6276 qeth_layer2_register_addr_entry(struct qeth_card *card,
6277 struct qeth_ipaddr *addr)
6279 if (!addr->is_multicast)
6281 QETH_DBF_TEXT(trace, 2, "setgmac");
6282 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6283 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6287 qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6288 struct qeth_ipaddr *addr)
6290 if (!addr->is_multicast)
6292 QETH_DBF_TEXT(trace, 2, "delgmac");
6293 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6294 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6298 qeth_layer3_register_addr_entry(struct qeth_card *card,
6299 struct qeth_ipaddr *addr)
6305 if (addr->proto == QETH_PROT_IPV4) {
6306 QETH_DBF_TEXT(trace, 2,"setaddr4");
6307 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6308 } else if (addr->proto == QETH_PROT_IPV6) {
6309 QETH_DBF_TEXT(trace, 2, "setaddr6");
6310 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6311 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6313 QETH_DBF_TEXT(trace, 2, "setaddr?");
6314 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6317 if (addr->is_multicast)
6318 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6320 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6323 QETH_DBF_TEXT(trace, 2, "failed");
6324 } while ((--cnt > 0) && rc);
6326 QETH_DBF_TEXT(trace, 2, "FAILED");
6327 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6328 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6335 qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6336 struct qeth_ipaddr *addr)
6341 if (addr->proto == QETH_PROT_IPV4) {
6342 QETH_DBF_TEXT(trace, 2,"deladdr4");
6343 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6344 } else if (addr->proto == QETH_PROT_IPV6) {
6345 QETH_DBF_TEXT(trace, 2, "deladdr6");
6346 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6347 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6349 QETH_DBF_TEXT(trace, 2, "deladdr?");
6350 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6352 if (addr->is_multicast)
6353 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6355 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6358 QETH_DBF_TEXT(trace, 2, "failed");
6359 /* TODO: re-activate this warning as soon as we have a
6361 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6362 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6370 qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6372 if (card->options.layer2)
6373 return qeth_layer2_register_addr_entry(card, addr);
6375 return qeth_layer3_register_addr_entry(card, addr);
6379 qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6381 if (card->options.layer2)
6382 return qeth_layer2_deregister_addr_entry(card, addr);
6384 return qeth_layer3_deregister_addr_entry(card, addr);
6388 qeth_ethtool_get_tx_csum(struct net_device *dev)
6390 /* We may need to say that we support tx csum offload if
6391 * we do EDDP or TSO. There are discussions going on to
6392 * enforce rules in the stack and in ethtool that make
6393 * SG and TSO depend on HW_CSUM. At the moment there are
6395 * If we say yes here, we have to checksum outbound packets
6401 qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6407 qeth_ethtool_get_rx_csum(struct net_device *dev)
6409 struct qeth_card *card = (struct qeth_card *)dev->priv;
6411 return (card->options.checksum_type == HW_CHECKSUMMING);
6415 qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6417 struct qeth_card *card = (struct qeth_card *)dev->priv;
6419 if ((card->state != CARD_STATE_DOWN) &&
6420 (card->state != CARD_STATE_RECOVER))
6423 card->options.checksum_type = HW_CHECKSUMMING;
6425 card->options.checksum_type = SW_CHECKSUMMING;
6430 qeth_ethtool_get_sg(struct net_device *dev)
6432 struct qeth_card *card = (struct qeth_card *)dev->priv;
6434 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6435 (dev->features & NETIF_F_SG));
6439 qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6441 struct qeth_card *card = (struct qeth_card *)dev->priv;
6444 if (card->options.large_send != QETH_LARGE_SEND_NO)
6445 dev->features |= NETIF_F_SG;
6447 dev->features &= ~NETIF_F_SG;
6451 dev->features &= ~NETIF_F_SG;
6456 qeth_ethtool_get_tso(struct net_device *dev)
6458 struct qeth_card *card = (struct qeth_card *)dev->priv;
6460 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6461 (dev->features & NETIF_F_TSO));
6465 qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6467 struct qeth_card *card = (struct qeth_card *)dev->priv;
6470 if (card->options.large_send != QETH_LARGE_SEND_NO)
6471 dev->features |= NETIF_F_TSO;
6473 dev->features &= ~NETIF_F_TSO;
6477 dev->features &= ~NETIF_F_TSO;
6481 static struct ethtool_ops qeth_ethtool_ops = {
6482 .get_tx_csum = qeth_ethtool_get_tx_csum,
6483 .set_tx_csum = qeth_ethtool_set_tx_csum,
6484 .get_rx_csum = qeth_ethtool_get_rx_csum,
6485 .set_rx_csum = qeth_ethtool_set_rx_csum,
6486 .get_sg = qeth_ethtool_get_sg,
6487 .set_sg = qeth_ethtool_set_sg,
6488 .get_tso = qeth_ethtool_get_tso,
6489 .set_tso = qeth_ethtool_set_tso,
6493 qeth_hard_header_parse(struct sk_buff *skb, unsigned char *haddr)
6495 struct qeth_card *card;
6498 card = qeth_get_card_from_dev(skb->dev);
6499 if (card->options.layer2)
6501 #ifdef CONFIG_QETH_IPV6
6502 /* cause of the manipulated arp constructor and the ARP
6503 flag for OSAE devices we have some nasty exceptions */
6504 if (card->info.type == QETH_CARD_TYPE_OSAE) {
6505 if (!card->options.fake_ll) {
6506 if ((skb->pkt_type==PACKET_OUTGOING) &&
6507 (skb->protocol==ETH_P_IPV6))
6512 if ((skb->pkt_type==PACKET_OUTGOING) &&
6513 (skb->protocol==ETH_P_IP))
6520 if (!card->options.fake_ll)
6524 memcpy(haddr, eth->h_source, ETH_ALEN);
6529 qeth_netdev_init(struct net_device *dev)
6531 struct qeth_card *card;
6533 card = (struct qeth_card *) dev->priv;
6535 QETH_DBF_TEXT(trace,3,"initdev");
6537 dev->tx_timeout = &qeth_tx_timeout;
6538 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6539 dev->open = qeth_open;
6540 dev->stop = qeth_stop;
6541 dev->hard_start_xmit = qeth_hard_start_xmit;
6542 dev->do_ioctl = qeth_do_ioctl;
6543 dev->get_stats = qeth_get_stats;
6544 dev->change_mtu = qeth_change_mtu;
6545 dev->neigh_setup = qeth_neigh_setup;
6546 dev->set_multicast_list = qeth_set_multicast_list;
6547 #ifdef CONFIG_QETH_VLAN
6548 dev->vlan_rx_register = qeth_vlan_rx_register;
6549 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6550 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6552 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6553 dev->rebuild_header = NULL;
6554 dev->hard_header = NULL;
6555 dev->header_cache_update = NULL;
6556 dev->hard_header_cache = NULL;
6558 #ifdef CONFIG_QETH_IPV6
6559 /*IPv6 address autoconfiguration stuff*/
6560 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6561 card->dev->dev_id = card->info.unique_id & 0xffff;
6563 if (card->options.fake_ll &&
6564 (qeth_get_netdev_flags(card) & IFF_NOARP))
6565 dev->hard_header = qeth_fake_header;
6566 if (dev->type == ARPHRD_IEEE802_TR)
6567 dev->hard_header_parse = NULL;
6569 dev->hard_header_parse = qeth_hard_header_parse;
6570 dev->set_mac_address = qeth_layer2_set_mac_address;
6571 dev->flags |= qeth_get_netdev_flags(card);
6572 if ((card->options.fake_broadcast) ||
6573 (card->info.broadcast_capable))
6574 dev->flags |= IFF_BROADCAST;
6575 dev->hard_header_len =
6576 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6577 dev->addr_len = OSA_ADDR_LEN;
6578 dev->mtu = card->info.initial_mtu;
6579 if (card->info.type != QETH_CARD_TYPE_OSN)
6580 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6581 SET_MODULE_OWNER(dev);
6586 qeth_init_func_level(struct qeth_card *card)
6588 if (card->ipato.enabled) {
6589 if (card->info.type == QETH_CARD_TYPE_IQD)
6590 card->info.func_level =
6591 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6593 card->info.func_level =
6594 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6596 if (card->info.type == QETH_CARD_TYPE_IQD)
6597 /*FIXME:why do we have same values for dis and ena for osae??? */
6598 card->info.func_level =
6599 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6601 card->info.func_level =
6602 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6607 * hardsetup card, initialize MPC and QDIO stuff
6610 qeth_hardsetup_card(struct qeth_card *card)
6615 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6617 atomic_set(&card->force_alloc_skb, 0);
6620 PRINT_WARN("Retrying to do IDX activates.\n");
6621 ccw_device_set_offline(CARD_DDEV(card));
6622 ccw_device_set_offline(CARD_WDEV(card));
6623 ccw_device_set_offline(CARD_RDEV(card));
6624 ccw_device_set_online(CARD_RDEV(card));
6625 ccw_device_set_online(CARD_WDEV(card));
6626 ccw_device_set_online(CARD_DDEV(card));
6628 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
6629 if (rc == -ERESTARTSYS) {
6630 QETH_DBF_TEXT(setup, 2, "break1");
6633 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6639 if ((rc = qeth_get_unitaddr(card))){
6640 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6643 qeth_init_tokens(card);
6644 qeth_init_func_level(card);
6645 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6646 if (rc == -ERESTARTSYS) {
6647 QETH_DBF_TEXT(setup, 2, "break2");
6650 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6656 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6657 if (rc == -ERESTARTSYS) {
6658 QETH_DBF_TEXT(setup, 2, "break3");
6661 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6667 if ((rc = qeth_mpc_initialize(card))){
6668 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6671 /*network device will be recovered*/
6673 card->dev->hard_header = card->orig_hard_header;
6674 if (card->options.fake_ll &&
6675 (qeth_get_netdev_flags(card) & IFF_NOARP))
6676 card->dev->hard_header = qeth_fake_header;
6679 /* at first set_online allocate netdev */
6680 card->dev = qeth_get_netdevice(card->info.type,
6681 card->info.link_type);
6683 qeth_qdio_clear_card(card, card->info.type !=
6684 QETH_CARD_TYPE_IQD);
6686 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6689 card->dev->priv = card;
6690 card->orig_hard_header = card->dev->hard_header;
6691 card->dev->type = qeth_get_arphdr_type(card->info.type,
6692 card->info.link_type);
6693 card->dev->init = qeth_netdev_init;
6696 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6701 qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6704 struct qeth_ipa_cmd *cmd;
6706 QETH_DBF_TEXT(trace,4,"defadpcb");
6708 cmd = (struct qeth_ipa_cmd *) data;
6709 if (cmd->hdr.return_code == 0){
6710 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6711 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6712 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6713 #ifdef CONFIG_QETH_IPV6
6714 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6715 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6718 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6719 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6720 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6721 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6727 qeth_default_setadapterparms_cb(struct qeth_card *card,
6728 struct qeth_reply *reply,
6731 struct qeth_ipa_cmd *cmd;
6733 QETH_DBF_TEXT(trace,4,"defadpcb");
6735 cmd = (struct qeth_ipa_cmd *) data;
6736 if (cmd->hdr.return_code == 0)
6737 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6744 qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6747 struct qeth_ipa_cmd *cmd;
6749 QETH_DBF_TEXT(trace,3,"quyadpcb");
6751 cmd = (struct qeth_ipa_cmd *) data;
6752 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6753 card->info.link_type =
6754 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6755 card->options.adp.supported_funcs =
6756 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6757 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6761 qeth_query_setadapterparms(struct qeth_card *card)
6764 struct qeth_cmd_buffer *iob;
6766 QETH_DBF_TEXT(trace,3,"queryadp");
6767 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6768 sizeof(struct qeth_ipacmd_setadpparms));
6769 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6774 qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6775 struct qeth_reply *reply,
6778 struct qeth_ipa_cmd *cmd;
6780 QETH_DBF_TEXT(trace,4,"chgmaccb");
6782 cmd = (struct qeth_ipa_cmd *) data;
6783 if (!card->options.layer2 ||
6784 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
6785 memcpy(card->dev->dev_addr,
6786 &cmd->data.setadapterparms.data.change_addr.addr,
6788 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6790 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6795 qeth_setadpparms_change_macaddr(struct qeth_card *card)
6798 struct qeth_cmd_buffer *iob;
6799 struct qeth_ipa_cmd *cmd;
6801 QETH_DBF_TEXT(trace,4,"chgmac");
6803 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6804 sizeof(struct qeth_ipacmd_setadpparms));
6805 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6806 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6807 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6808 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6809 card->dev->dev_addr, OSA_ADDR_LEN);
6810 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6816 qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6819 struct qeth_cmd_buffer *iob;
6820 struct qeth_ipa_cmd *cmd;
6822 QETH_DBF_TEXT(trace,4,"adpmode");
6824 iob = qeth_get_adapter_cmd(card, command,
6825 sizeof(struct qeth_ipacmd_setadpparms));
6826 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6827 cmd->data.setadapterparms.data.mode = mode;
6828 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6834 qeth_setadapter_hstr(struct qeth_card *card)
6838 QETH_DBF_TEXT(trace,4,"adphstr");
6840 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6841 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6842 card->options.broadcast_mode);
6844 PRINT_WARN("couldn't set broadcast mode on "
6846 CARD_BUS_ID(card), rc);
6847 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6848 card->options.macaddr_mode);
6850 PRINT_WARN("couldn't set macaddr mode on "
6851 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6854 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6855 PRINT_WARN("set adapter parameters not available "
6856 "to set broadcast mode, using ALLRINGS "
6857 "on device %s:\n", CARD_BUS_ID(card));
6858 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6859 PRINT_WARN("set adapter parameters not available "
6860 "to set macaddr mode, using NONCANONICAL "
6861 "on device %s:\n", CARD_BUS_ID(card));
6866 qeth_setadapter_parms(struct qeth_card *card)
6870 QETH_DBF_TEXT(setup, 2, "setadprm");
6872 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6873 PRINT_WARN("set adapter parameters not supported "
6876 QETH_DBF_TEXT(setup, 2, " notsupp");
6879 rc = qeth_query_setadapterparms(card);
6881 PRINT_WARN("couldn't set adapter parameters on device %s: "
6882 "x%x\n", CARD_BUS_ID(card), rc);
6885 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6886 rc = qeth_setadpparms_change_macaddr(card);
6888 PRINT_WARN("couldn't get MAC address on "
6890 CARD_BUS_ID(card), rc);
6893 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6894 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6895 rc = qeth_setadapter_hstr(card);
6901 qeth_layer2_initialize(struct qeth_card *card)
6906 QETH_DBF_TEXT(setup, 2, "doL2init");
6907 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6909 rc = qeth_query_setadapterparms(card);
6911 PRINT_WARN("could not query adapter parameters on device %s: "
6912 "x%x\n", CARD_BUS_ID(card), rc);
6915 rc = qeth_setadpparms_change_macaddr(card);
6917 PRINT_WARN("couldn't get MAC address on "
6919 CARD_BUS_ID(card), rc);
6920 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6923 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6925 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6927 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6933 qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6934 enum qeth_prot_versions prot)
6937 struct qeth_cmd_buffer *iob;
6939 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6940 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6946 qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6950 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6952 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6957 qeth_send_stoplan(struct qeth_card *card)
6962 * TODO: according to the IPA format document page 14,
6963 * TCP/IP (we!) never issue a STOPLAN
6966 QETH_DBF_TEXT(trace, 2, "stoplan");
6968 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6973 qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6976 struct qeth_ipa_cmd *cmd;
6978 QETH_DBF_TEXT(setup, 2, "qipasscb");
6980 cmd = (struct qeth_ipa_cmd *) data;
6981 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6982 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6983 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6984 /* Disable IPV6 support hard coded for Hipersockets */
6985 if(card->info.type == QETH_CARD_TYPE_IQD)
6986 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
6988 #ifdef CONFIG_QETH_IPV6
6989 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6990 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6993 QETH_DBF_TEXT(setup, 2, "suppenbl");
6994 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6995 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
7000 qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
7003 struct qeth_cmd_buffer *iob;
7005 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
7006 if (card->options.layer2) {
7007 QETH_DBF_TEXT(setup, 2, "noprmly2");
7011 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
7012 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
7016 static struct qeth_cmd_buffer *
7017 qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
7018 __u16 cmd_code, __u16 len,
7019 enum qeth_prot_versions prot)
7021 struct qeth_cmd_buffer *iob;
7022 struct qeth_ipa_cmd *cmd;
7024 QETH_DBF_TEXT(trace,4,"getasscm");
7025 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
7027 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7028 cmd->data.setassparms.hdr.assist_no = ipa_func;
7029 cmd->data.setassparms.hdr.length = 8 + len;
7030 cmd->data.setassparms.hdr.command_code = cmd_code;
7031 cmd->data.setassparms.hdr.return_code = 0;
7032 cmd->data.setassparms.hdr.seq_no = 0;
7038 qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
7039 __u16 len, long data,
7041 (struct qeth_card *,struct qeth_reply *,unsigned long),
7045 struct qeth_ipa_cmd *cmd;
7047 QETH_DBF_TEXT(trace,4,"sendassp");
7049 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7050 if (len <= sizeof(__u32))
7051 cmd->data.setassparms.data.flags_32bit = (__u32) data;
7052 else /* (len > sizeof(__u32)) */
7053 memcpy(&cmd->data.setassparms.data, (void *) data, len);
7055 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
7059 #ifdef CONFIG_QETH_IPV6
7061 qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
7062 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
7066 struct qeth_cmd_buffer *iob;
7068 QETH_DBF_TEXT(trace,4,"simassp6");
7069 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
7071 rc = qeth_send_setassparms(card, iob, 0, 0,
7072 qeth_default_setassparms_cb, NULL);
7078 qeth_send_simple_setassparms(struct qeth_card *card,
7079 enum qeth_ipa_funcs ipa_func,
7080 __u16 cmd_code, long data)
7084 struct qeth_cmd_buffer *iob;
7086 QETH_DBF_TEXT(trace,4,"simassp4");
7088 length = sizeof(__u32);
7089 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
7090 length, QETH_PROT_IPV4);
7091 rc = qeth_send_setassparms(card, iob, length, data,
7092 qeth_default_setassparms_cb, NULL);
7097 qeth_start_ipa_arp_processing(struct qeth_card *card)
7101 QETH_DBF_TEXT(trace,3,"ipaarp");
7103 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
7104 PRINT_WARN("ARP processing not supported "
7105 "on %s!\n", QETH_CARD_IFNAME(card));
7108 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
7109 IPA_CMD_ASS_START, 0);
7111 PRINT_WARN("Could not start ARP processing "
7112 "assist on %s: 0x%x\n",
7113 QETH_CARD_IFNAME(card), rc);
7119 qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
7123 QETH_DBF_TEXT(trace,3,"ipaipfrg");
7125 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
7126 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
7127 QETH_CARD_IFNAME(card));
7131 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
7132 IPA_CMD_ASS_START, 0);
7134 PRINT_WARN("Could not start Hardware IP fragmentation "
7135 "assist on %s: 0x%x\n",
7136 QETH_CARD_IFNAME(card), rc);
7138 PRINT_INFO("Hardware IP fragmentation enabled \n");
7143 qeth_start_ipa_source_mac(struct qeth_card *card)
7147 QETH_DBF_TEXT(trace,3,"stsrcmac");
7149 if (!card->options.fake_ll)
7152 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
7153 PRINT_INFO("Inbound source address not "
7154 "supported on %s\n", QETH_CARD_IFNAME(card));
7158 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
7159 IPA_CMD_ASS_START, 0);
7161 PRINT_WARN("Could not start inbound source "
7162 "assist on %s: 0x%x\n",
7163 QETH_CARD_IFNAME(card), rc);
7168 qeth_start_ipa_vlan(struct qeth_card *card)
7172 QETH_DBF_TEXT(trace,3,"strtvlan");
7174 #ifdef CONFIG_QETH_VLAN
7175 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
7176 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
7180 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
7181 IPA_CMD_ASS_START,0);
7183 PRINT_WARN("Could not start vlan "
7184 "assist on %s: 0x%x\n",
7185 QETH_CARD_IFNAME(card), rc);
7187 PRINT_INFO("VLAN enabled \n");
7188 card->dev->features |=
7189 NETIF_F_HW_VLAN_FILTER |
7190 NETIF_F_HW_VLAN_TX |
7193 #endif /* QETH_VLAN */
7198 qeth_start_ipa_multicast(struct qeth_card *card)
7202 QETH_DBF_TEXT(trace,3,"stmcast");
7204 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7205 PRINT_WARN("Multicast not supported on %s\n",
7206 QETH_CARD_IFNAME(card));
7210 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7211 IPA_CMD_ASS_START,0);
7213 PRINT_WARN("Could not start multicast "
7214 "assist on %s: rc=%i\n",
7215 QETH_CARD_IFNAME(card), rc);
7217 PRINT_INFO("Multicast enabled\n");
7218 card->dev->flags |= IFF_MULTICAST;
7223 #ifdef CONFIG_QETH_IPV6
7225 qeth_softsetup_ipv6(struct qeth_card *card)
7229 QETH_DBF_TEXT(trace,3,"softipv6");
7231 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7233 PRINT_ERR("IPv6 startlan failed on %s\n",
7234 QETH_CARD_IFNAME(card));
7237 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7239 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7240 QETH_CARD_IFNAME(card));
7243 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7244 IPA_CMD_ASS_START, 3);
7246 PRINT_WARN("IPv6 start assist (version 4) failed "
7248 QETH_CARD_IFNAME(card), rc);
7251 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7254 PRINT_WARN("IPV6 start assist (version 6) failed "
7256 QETH_CARD_IFNAME(card), rc);
7259 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7262 PRINT_WARN("Could not enable passthrough "
7264 QETH_CARD_IFNAME(card), rc);
7267 PRINT_INFO("IPV6 enabled \n");
7274 qeth_start_ipa_ipv6(struct qeth_card *card)
7277 #ifdef CONFIG_QETH_IPV6
7278 QETH_DBF_TEXT(trace,3,"strtipv6");
7280 if (!qeth_is_supported(card, IPA_IPV6)) {
7281 PRINT_WARN("IPv6 not supported on %s\n",
7282 QETH_CARD_IFNAME(card));
7285 rc = qeth_softsetup_ipv6(card);
7291 qeth_start_ipa_broadcast(struct qeth_card *card)
7295 QETH_DBF_TEXT(trace,3,"stbrdcst");
7296 card->info.broadcast_capable = 0;
7297 if (!qeth_is_supported(card, IPA_FILTERING)) {
7298 PRINT_WARN("Broadcast not supported on %s\n",
7299 QETH_CARD_IFNAME(card));
7303 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7304 IPA_CMD_ASS_START, 0);
7306 PRINT_WARN("Could not enable broadcasting filtering "
7308 QETH_CARD_IFNAME(card), rc);
7312 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7313 IPA_CMD_ASS_CONFIGURE, 1);
7315 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7316 QETH_CARD_IFNAME(card), rc);
7319 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7320 PRINT_INFO("Broadcast enabled \n");
7321 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7322 IPA_CMD_ASS_ENABLE, 1);
7324 PRINT_WARN("Could not set up broadcast echo filtering on "
7325 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7328 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7330 if (card->info.broadcast_capable)
7331 card->dev->flags |= IFF_BROADCAST;
7333 card->dev->flags &= ~IFF_BROADCAST;
7338 qeth_send_checksum_command(struct qeth_card *card)
7342 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7343 IPA_CMD_ASS_START, 0);
7345 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7346 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7347 QETH_CARD_IFNAME(card), rc);
7350 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7352 card->info.csum_mask);
7354 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7355 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7356 QETH_CARD_IFNAME(card), rc);
7363 qeth_start_ipa_checksum(struct qeth_card *card)
7367 QETH_DBF_TEXT(trace,3,"strtcsum");
7369 if (card->options.checksum_type == NO_CHECKSUMMING) {
7370 PRINT_WARN("Using no checksumming on %s.\n",
7371 QETH_CARD_IFNAME(card));
7374 if (card->options.checksum_type == SW_CHECKSUMMING) {
7375 PRINT_WARN("Using SW checksumming on %s.\n",
7376 QETH_CARD_IFNAME(card));
7379 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7380 PRINT_WARN("Inbound HW Checksumming not "
7381 "supported on %s,\ncontinuing "
7382 "using Inbound SW Checksumming\n",
7383 QETH_CARD_IFNAME(card));
7384 card->options.checksum_type = SW_CHECKSUMMING;
7387 rc = qeth_send_checksum_command(card);
7389 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7395 qeth_start_ipa_tso(struct qeth_card *card)
7399 QETH_DBF_TEXT(trace,3,"sttso");
7401 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7402 PRINT_WARN("Outbound TSO not supported on %s\n",
7403 QETH_CARD_IFNAME(card));
7406 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7407 IPA_CMD_ASS_START,0);
7409 PRINT_WARN("Could not start outbound TSO "
7410 "assist on %s: rc=%i\n",
7411 QETH_CARD_IFNAME(card), rc);
7413 PRINT_INFO("Outbound TSO enabled\n");
7415 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7416 card->options.large_send = QETH_LARGE_SEND_NO;
7417 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
7423 qeth_start_ipassists(struct qeth_card *card)
7425 QETH_DBF_TEXT(trace,3,"strtipas");
7426 qeth_start_ipa_arp_processing(card); /* go on*/
7427 qeth_start_ipa_ip_fragmentation(card); /* go on*/
7428 qeth_start_ipa_source_mac(card); /* go on*/
7429 qeth_start_ipa_vlan(card); /* go on*/
7430 qeth_start_ipa_multicast(card); /* go on*/
7431 qeth_start_ipa_ipv6(card); /* go on*/
7432 qeth_start_ipa_broadcast(card); /* go on*/
7433 qeth_start_ipa_checksum(card); /* go on*/
7434 qeth_start_ipa_tso(card); /* go on*/
7439 qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7440 enum qeth_prot_versions prot)
7443 struct qeth_ipa_cmd *cmd;
7444 struct qeth_cmd_buffer *iob;
7446 QETH_DBF_TEXT(trace,4,"setroutg");
7447 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7448 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7449 cmd->data.setrtg.type = (type);
7450 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7457 qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7458 enum qeth_prot_versions prot)
7460 if (card->info.type == QETH_CARD_TYPE_IQD) {
7463 case PRIMARY_CONNECTOR:
7464 case SECONDARY_CONNECTOR:
7465 case MULTICAST_ROUTER:
7473 case PRIMARY_ROUTER:
7474 case SECONDARY_ROUTER:
7476 case MULTICAST_ROUTER:
7477 if (qeth_is_ipafunc_supported(card, prot,
7485 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7486 "Router status set to 'no router'.\n",
7487 ((*type == PRIMARY_ROUTER)? "primary router" :
7488 (*type == SECONDARY_ROUTER)? "secondary router" :
7489 (*type == PRIMARY_CONNECTOR)? "primary connector" :
7490 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7491 (*type == MULTICAST_ROUTER)? "multicast router" :
7498 qeth_setrouting_v4(struct qeth_card *card)
7502 QETH_DBF_TEXT(trace,3,"setrtg4");
7504 qeth_correct_routing_type(card, &card->options.route4.type,
7507 rc = qeth_send_setrouting(card, card->options.route4.type,
7510 card->options.route4.type = NO_ROUTER;
7511 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7512 "Type set to 'no router'.\n",
7513 rc, QETH_CARD_IFNAME(card));
7519 qeth_setrouting_v6(struct qeth_card *card)
7523 QETH_DBF_TEXT(trace,3,"setrtg6");
7524 #ifdef CONFIG_QETH_IPV6
7526 if (!qeth_is_supported(card, IPA_IPV6))
7528 qeth_correct_routing_type(card, &card->options.route6.type,
7531 rc = qeth_send_setrouting(card, card->options.route6.type,
7534 card->options.route6.type = NO_ROUTER;
7535 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7536 "Type set to 'no router'.\n",
7537 rc, QETH_CARD_IFNAME(card));
7544 qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
7548 if (card->dev == NULL) {
7549 card->options.large_send = type;
7552 if (card->state == CARD_STATE_UP)
7553 netif_tx_disable(card->dev);
7554 card->options.large_send = type;
7555 switch (card->options.large_send) {
7556 case QETH_LARGE_SEND_EDDP:
7557 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7559 case QETH_LARGE_SEND_TSO:
7560 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7561 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7563 PRINT_WARN("TSO not supported on %s. "
7564 "large_send set to 'no'.\n",
7566 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7567 card->options.large_send = QETH_LARGE_SEND_NO;
7571 default: /* includes QETH_LARGE_SEND_NO */
7572 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7575 if (card->state == CARD_STATE_UP)
7576 netif_wake_queue(card->dev);
7581 * softsetup card: init IPA stuff
7584 qeth_softsetup_card(struct qeth_card *card)
7588 QETH_DBF_TEXT(setup, 2, "softsetp");
7590 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7591 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7593 PRINT_WARN("LAN on card %s if offline! "
7594 "Waiting for STARTLAN from card.\n",
7596 card->lan_online = 0;
7600 card->lan_online = 1;
7601 if (card->info.type==QETH_CARD_TYPE_OSN)
7603 qeth_set_large_send(card, card->options.large_send);
7604 if (card->options.layer2) {
7605 card->dev->features |=
7606 NETIF_F_HW_VLAN_FILTER |
7607 NETIF_F_HW_VLAN_TX |
7609 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7610 card->info.broadcast_capable=1;
7611 if ((rc = qeth_layer2_initialize(card))) {
7612 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7615 #ifdef CONFIG_QETH_VLAN
7616 qeth_layer2_process_vlans(card, 0);
7620 if ((rc = qeth_setadapter_parms(card)))
7621 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7622 if ((rc = qeth_start_ipassists(card)))
7623 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7624 if ((rc = qeth_setrouting_v4(card)))
7625 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7626 if ((rc = qeth_setrouting_v6(card)))
7627 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7629 netif_tx_disable(card->dev);
7633 #ifdef CONFIG_QETH_IPV6
7635 qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7638 struct qeth_ipa_cmd *cmd;
7640 cmd = (struct qeth_ipa_cmd *) data;
7641 if (cmd->hdr.return_code == 0)
7642 card->info.unique_id = *((__u16 *)
7643 &cmd->data.create_destroy_addr.unique_id[6]);
7645 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7646 UNIQUE_ID_NOT_BY_CARD;
7647 PRINT_WARN("couldn't get a unique id from the card on device "
7648 "%s (result=x%x), using default id. ipv6 "
7649 "autoconfig on other lpars may lead to duplicate "
7650 "ip addresses. please use manually "
7651 "configured ones.\n",
7652 CARD_BUS_ID(card), cmd->hdr.return_code);
7659 qeth_put_unique_id(struct qeth_card *card)
7663 #ifdef CONFIG_QETH_IPV6
7664 struct qeth_cmd_buffer *iob;
7665 struct qeth_ipa_cmd *cmd;
7667 QETH_DBF_TEXT(trace,2,"puniqeid");
7669 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7670 UNIQUE_ID_NOT_BY_CARD)
7672 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7674 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7675 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7676 card->info.unique_id;
7677 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7678 card->dev->dev_addr, OSA_ADDR_LEN);
7679 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7681 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7682 UNIQUE_ID_NOT_BY_CARD;
7691 qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7693 struct qeth_ipaddr *addr, *tmp;
7694 unsigned long flags;
7696 QETH_DBF_TEXT(trace,4,"clearip");
7697 spin_lock_irqsave(&card->ip_lock, flags);
7698 /* clear todo list */
7699 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7700 list_del(&addr->entry);
7704 while (!list_empty(&card->ip_list)) {
7705 addr = list_entry(card->ip_list.next,
7706 struct qeth_ipaddr, entry);
7707 list_del_init(&addr->entry);
7709 spin_unlock_irqrestore(&card->ip_lock, flags);
7710 qeth_deregister_addr_entry(card, addr);
7711 spin_lock_irqsave(&card->ip_lock, flags);
7713 if (!recover || addr->is_multicast) {
7717 list_add_tail(&addr->entry, card->ip_tbd_list);
7719 spin_unlock_irqrestore(&card->ip_lock, flags);
7723 qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7724 int clear_start_mask)
7726 unsigned long flags;
7728 spin_lock_irqsave(&card->thread_mask_lock, flags);
7729 card->thread_allowed_mask = threads;
7730 if (clear_start_mask)
7731 card->thread_start_mask &= threads;
7732 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7733 wake_up(&card->wait_q);
7737 qeth_threads_running(struct qeth_card *card, unsigned long threads)
7739 unsigned long flags;
7742 spin_lock_irqsave(&card->thread_mask_lock, flags);
7743 rc = (card->thread_running_mask & threads);
7744 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7749 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7751 return wait_event_interruptible(card->wait_q,
7752 qeth_threads_running(card, threads) == 0);
7756 qeth_stop_card(struct qeth_card *card, int recovery_mode)
7760 QETH_DBF_TEXT(setup ,2,"stopcard");
7761 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7763 qeth_set_allowed_threads(card, 0, 1);
7764 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7765 return -ERESTARTSYS;
7766 if (card->read.state == CH_STATE_UP &&
7767 card->write.state == CH_STATE_UP &&
7768 (card->state == CARD_STATE_UP)) {
7769 if (recovery_mode &&
7770 card->info.type != QETH_CARD_TYPE_OSN) {
7771 qeth_stop(card->dev);
7774 dev_close(card->dev);
7777 if (!card->use_hard_stop) {
7778 __u8 *mac = &card->dev->dev_addr[0];
7779 rc = qeth_layer2_send_delmac(card, mac);
7780 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7781 if ((rc = qeth_send_stoplan(card)))
7782 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7784 card->state = CARD_STATE_SOFTSETUP;
7786 if (card->state == CARD_STATE_SOFTSETUP) {
7787 #ifdef CONFIG_QETH_VLAN
7788 if (card->options.layer2)
7789 qeth_layer2_process_vlans(card, 1);
7791 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7792 qeth_clear_ipacmd_list(card);
7793 card->state = CARD_STATE_HARDSETUP;
7795 if (card->state == CARD_STATE_HARDSETUP) {
7796 if ((!card->use_hard_stop) &&
7797 (!card->options.layer2))
7798 if ((rc = qeth_put_unique_id(card)))
7799 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7800 qeth_qdio_clear_card(card, 0);
7801 qeth_clear_qdio_buffers(card);
7802 qeth_clear_working_pool_list(card);
7803 card->state = CARD_STATE_DOWN;
7805 if (card->state == CARD_STATE_DOWN) {
7806 qeth_clear_cmd_buffers(&card->read);
7807 qeth_clear_cmd_buffers(&card->write);
7809 card->use_hard_stop = 0;
7815 qeth_get_unique_id(struct qeth_card *card)
7818 #ifdef CONFIG_QETH_IPV6
7819 struct qeth_cmd_buffer *iob;
7820 struct qeth_ipa_cmd *cmd;
7822 QETH_DBF_TEXT(setup, 2, "guniqeid");
7824 if (!qeth_is_supported(card,IPA_IPV6)) {
7825 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7826 UNIQUE_ID_NOT_BY_CARD;
7830 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7832 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7833 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7834 card->info.unique_id;
7836 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7838 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7839 UNIQUE_ID_NOT_BY_CARD;
7844 qeth_print_status_with_portname(struct qeth_card *card)
7849 sprintf(dbf_text, "%s", card->info.portname + 1);
7850 for (i = 0; i < 8; i++)
7852 (char) _ebcasc[(__u8) dbf_text[i]];
7854 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7855 "with link type %s (portname: %s)\n",
7859 qeth_get_cardname(card),
7860 (card->info.mcl_level[0]) ? " (level: " : "",
7861 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7862 (card->info.mcl_level[0]) ? ")" : "",
7863 qeth_get_cardname_short(card),
7869 qeth_print_status_no_portname(struct qeth_card *card)
7871 if (card->info.portname[0])
7872 printk("qeth: Device %s/%s/%s is a%s "
7873 "card%s%s%s\nwith link type %s "
7874 "(no portname needed by interface).\n",
7878 qeth_get_cardname(card),
7879 (card->info.mcl_level[0]) ? " (level: " : "",
7880 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7881 (card->info.mcl_level[0]) ? ")" : "",
7882 qeth_get_cardname_short(card));
7884 printk("qeth: Device %s/%s/%s is a%s "
7885 "card%s%s%s\nwith link type %s.\n",
7889 qeth_get_cardname(card),
7890 (card->info.mcl_level[0]) ? " (level: " : "",
7891 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7892 (card->info.mcl_level[0]) ? ")" : "",
7893 qeth_get_cardname_short(card));
7897 qeth_print_status_message(struct qeth_card *card)
7899 switch (card->info.type) {
7900 case QETH_CARD_TYPE_OSAE:
7901 /* VM will use a non-zero first character
7902 * to indicate a HiperSockets like reporting
7903 * of the level OSA sets the first character to zero
7905 if (!card->info.mcl_level[0]) {
7906 sprintf(card->info.mcl_level,"%02x%02x",
7907 card->info.mcl_level[2],
7908 card->info.mcl_level[3]);
7910 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7914 case QETH_CARD_TYPE_IQD:
7915 if (card->info.guestlan) {
7916 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7917 card->info.mcl_level[0]];
7918 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7919 card->info.mcl_level[1]];
7920 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7921 card->info.mcl_level[2]];
7922 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7923 card->info.mcl_level[3]];
7924 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7928 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7930 if (card->info.portname_required)
7931 qeth_print_status_with_portname(card);
7933 qeth_print_status_no_portname(card);
7937 qeth_register_netdev(struct qeth_card *card)
7939 QETH_DBF_TEXT(setup, 3, "regnetd");
7940 if (card->dev->reg_state != NETREG_UNINITIALIZED)
7943 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7944 return register_netdev(card->dev);
7948 qeth_start_again(struct qeth_card *card, int recovery_mode)
7950 QETH_DBF_TEXT(setup ,2, "startag");
7952 if (recovery_mode &&
7953 card->info.type != QETH_CARD_TYPE_OSN) {
7954 qeth_open(card->dev);
7957 dev_open(card->dev);
7960 /* this also sets saved unicast addresses */
7961 qeth_set_multicast_list(card->dev);
7965 /* Layer 2 specific stuff */
7966 #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7967 if (card->options.option == value) { \
7968 PRINT_ERR("%s not supported with layer 2 " \
7969 "functionality, ignoring option on read" \
7970 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7971 card->options.option = reset_value; \
7973 #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7974 if (card->options.option != value) { \
7975 PRINT_ERR("%s not supported with layer 2 " \
7976 "functionality, ignoring option on read" \
7977 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7978 card->options.option = reset_value; \
7982 static void qeth_make_parameters_consistent(struct qeth_card *card)
7985 if (card->options.layer2 == 0)
7987 if (card->info.type == QETH_CARD_TYPE_OSN)
7989 if (card->info.type == QETH_CARD_TYPE_IQD) {
7990 PRINT_ERR("Device %s does not support layer 2 functionality." \
7991 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7992 card->options.layer2 = 0;
7995 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7996 "Routing options are");
7997 #ifdef CONFIG_QETH_IPV6
7998 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7999 "Routing options are");
8001 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
8002 QETH_CHECKSUM_DEFAULT,
8003 "Checksumming options are");
8004 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
8005 QETH_TR_BROADCAST_ALLRINGS,
8006 "Broadcast mode options are");
8007 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
8008 QETH_TR_MACADDR_NONCANONICAL,
8009 "Canonical MAC addr options are");
8010 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
8011 "Broadcast faking options are");
8012 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
8013 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
8014 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
8019 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
8021 struct qeth_card *card = gdev->dev.driver_data;
8023 enum qeth_card_states recover_flag;
8026 QETH_DBF_TEXT(setup ,2, "setonlin");
8027 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
8029 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
8030 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
8031 PRINT_WARN("set_online of card %s interrupted by user!\n",
8033 return -ERESTARTSYS;
8036 recover_flag = card->state;
8037 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
8038 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
8039 (rc = ccw_device_set_online(CARD_DDEV(card)))){
8040 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
8044 qeth_make_parameters_consistent(card);
8046 if ((rc = qeth_hardsetup_card(card))){
8047 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
8050 card->state = CARD_STATE_HARDSETUP;
8052 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
8053 rc = qeth_get_unique_id(card);
8055 if (rc && card->options.layer2 == 0) {
8056 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
8059 qeth_print_status_message(card);
8060 if ((rc = qeth_register_netdev(card))){
8061 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
8064 if ((rc = qeth_softsetup_card(card))){
8065 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
8069 if ((rc = qeth_init_qdio_queues(card))){
8070 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
8073 card->state = CARD_STATE_SOFTSETUP;
8074 netif_carrier_on(card->dev);
8076 qeth_set_allowed_threads(card, 0xffffffff, 0);
8077 if (recover_flag == CARD_STATE_RECOVER)
8078 qeth_start_again(card, recovery_mode);
8079 qeth_notify_processes();
8082 card->use_hard_stop = 1;
8083 qeth_stop_card(card, 0);
8084 ccw_device_set_offline(CARD_DDEV(card));
8085 ccw_device_set_offline(CARD_WDEV(card));
8086 ccw_device_set_offline(CARD_RDEV(card));
8087 if (recover_flag == CARD_STATE_RECOVER)
8088 card->state = CARD_STATE_RECOVER;
8090 card->state = CARD_STATE_DOWN;
8095 qeth_set_online(struct ccwgroup_device *gdev)
8097 return __qeth_set_online(gdev, 0);
8100 static struct ccw_device_id qeth_ids[] = {
8101 {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
8102 {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
8103 {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
8106 MODULE_DEVICE_TABLE(ccw, qeth_ids);
8108 struct device *qeth_root_dev = NULL;
8110 struct ccwgroup_driver qeth_ccwgroup_driver = {
8111 .owner = THIS_MODULE,
8113 .driver_id = 0xD8C5E3C8,
8114 .probe = qeth_probe_device,
8115 .remove = qeth_remove_device,
8116 .set_online = qeth_set_online,
8117 .set_offline = qeth_set_offline,
8120 struct ccw_driver qeth_ccw_driver = {
8123 .probe = ccwgroup_probe_ccwdev,
8124 .remove = ccwgroup_remove_ccwdev,
8129 qeth_unregister_dbf_views(void)
8132 debug_unregister(qeth_dbf_setup);
8134 debug_unregister(qeth_dbf_qerr);
8136 debug_unregister(qeth_dbf_sense);
8138 debug_unregister(qeth_dbf_misc);
8140 debug_unregister(qeth_dbf_data);
8141 if (qeth_dbf_control)
8142 debug_unregister(qeth_dbf_control);
8144 debug_unregister(qeth_dbf_trace);
8147 qeth_register_dbf_views(void)
8149 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
8150 QETH_DBF_SETUP_PAGES,
8151 QETH_DBF_SETUP_NR_AREAS,
8152 QETH_DBF_SETUP_LEN);
8153 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
8154 QETH_DBF_MISC_PAGES,
8155 QETH_DBF_MISC_NR_AREAS,
8157 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
8158 QETH_DBF_DATA_PAGES,
8159 QETH_DBF_DATA_NR_AREAS,
8161 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
8162 QETH_DBF_CONTROL_PAGES,
8163 QETH_DBF_CONTROL_NR_AREAS,
8164 QETH_DBF_CONTROL_LEN);
8165 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
8166 QETH_DBF_SENSE_PAGES,
8167 QETH_DBF_SENSE_NR_AREAS,
8168 QETH_DBF_SENSE_LEN);
8169 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
8170 QETH_DBF_QERR_PAGES,
8171 QETH_DBF_QERR_NR_AREAS,
8173 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
8174 QETH_DBF_TRACE_PAGES,
8175 QETH_DBF_TRACE_NR_AREAS,
8176 QETH_DBF_TRACE_LEN);
8178 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
8179 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
8180 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
8181 (qeth_dbf_trace == NULL)) {
8182 qeth_unregister_dbf_views();
8185 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
8186 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
8188 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
8189 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
8191 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
8192 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
8194 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
8195 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
8197 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
8198 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8200 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8201 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8203 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8204 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8209 #ifdef CONFIG_QETH_IPV6
8210 extern struct neigh_table arp_tbl;
8211 static struct neigh_ops *arp_direct_ops;
8212 static int (*qeth_old_arp_constructor) (struct neighbour *);
8214 static struct neigh_ops arp_direct_ops_template = {
8217 .error_report = NULL,
8218 .output = dev_queue_xmit,
8219 .connected_output = dev_queue_xmit,
8220 .hh_output = dev_queue_xmit,
8221 .queue_xmit = dev_queue_xmit
8225 qeth_arp_constructor(struct neighbour *neigh)
8227 struct net_device *dev = neigh->dev;
8228 struct in_device *in_dev;
8229 struct neigh_parms *parms;
8230 struct qeth_card *card;
8232 card = qeth_get_card_from_dev(dev);
8235 if((card->options.layer2) ||
8236 (card->dev->hard_header == qeth_fake_header))
8240 in_dev = __in_dev_get_rcu(dev);
8241 if (in_dev == NULL) {
8246 parms = in_dev->arp_parms;
8247 __neigh_parms_put(neigh->parms);
8248 neigh->parms = neigh_parms_clone(parms);
8251 neigh->type = inet_addr_type(*(__be32 *) neigh->primary_key);
8252 neigh->nud_state = NUD_NOARP;
8253 neigh->ops = arp_direct_ops;
8254 neigh->output = neigh->ops->queue_xmit;
8257 return qeth_old_arp_constructor(neigh);
8259 #endif /*CONFIG_QETH_IPV6*/
8262 * IP address takeover related functions
8265 qeth_clear_ipato_list(struct qeth_card *card)
8267 struct qeth_ipato_entry *ipatoe, *tmp;
8268 unsigned long flags;
8270 spin_lock_irqsave(&card->ip_lock, flags);
8271 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8272 list_del(&ipatoe->entry);
8275 spin_unlock_irqrestore(&card->ip_lock, flags);
8279 qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8281 struct qeth_ipato_entry *ipatoe;
8282 unsigned long flags;
8285 QETH_DBF_TEXT(trace, 2, "addipato");
8286 spin_lock_irqsave(&card->ip_lock, flags);
8287 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8288 if (ipatoe->proto != new->proto)
8290 if (!memcmp(ipatoe->addr, new->addr,
8291 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8292 (ipatoe->mask_bits == new->mask_bits)){
8293 PRINT_WARN("ipato entry already exists!\n");
8299 list_add_tail(&new->entry, &card->ipato.entries);
8301 spin_unlock_irqrestore(&card->ip_lock, flags);
8306 qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8307 u8 *addr, int mask_bits)
8309 struct qeth_ipato_entry *ipatoe, *tmp;
8310 unsigned long flags;
8312 QETH_DBF_TEXT(trace, 2, "delipato");
8313 spin_lock_irqsave(&card->ip_lock, flags);
8314 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8315 if (ipatoe->proto != proto)
8317 if (!memcmp(ipatoe->addr, addr,
8318 (proto == QETH_PROT_IPV4)? 4:16) &&
8319 (ipatoe->mask_bits == mask_bits)){
8320 list_del(&ipatoe->entry);
8324 spin_unlock_irqrestore(&card->ip_lock, flags);
8328 qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8333 for (i = 0; i < len; ++i){
8335 for (j = 7; j >= 0; --j){
8336 bits[i*8 + j] = octet & 1;
8343 qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8345 struct qeth_ipato_entry *ipatoe;
8346 u8 addr_bits[128] = {0, };
8347 u8 ipatoe_bits[128] = {0, };
8350 if (!card->ipato.enabled)
8353 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8354 (addr->proto == QETH_PROT_IPV4)? 4:16);
8355 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8356 if (addr->proto != ipatoe->proto)
8358 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8359 (ipatoe->proto==QETH_PROT_IPV4) ?
8361 if (addr->proto == QETH_PROT_IPV4)
8362 rc = !memcmp(addr_bits, ipatoe_bits,
8363 min(32, ipatoe->mask_bits));
8365 rc = !memcmp(addr_bits, ipatoe_bits,
8366 min(128, ipatoe->mask_bits));
8371 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8373 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8380 * VIPA related functions
8383 qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8386 struct qeth_ipaddr *ipaddr;
8387 unsigned long flags;
8390 ipaddr = qeth_get_addr_buffer(proto);
8392 if (proto == QETH_PROT_IPV4){
8393 QETH_DBF_TEXT(trace, 2, "addvipa4");
8394 memcpy(&ipaddr->u.a4.addr, addr, 4);
8395 ipaddr->u.a4.mask = 0;
8396 #ifdef CONFIG_QETH_IPV6
8397 } else if (proto == QETH_PROT_IPV6){
8398 QETH_DBF_TEXT(trace, 2, "addvipa6");
8399 memcpy(&ipaddr->u.a6.addr, addr, 16);
8400 ipaddr->u.a6.pfxlen = 0;
8403 ipaddr->type = QETH_IP_TYPE_VIPA;
8404 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8405 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8408 spin_lock_irqsave(&card->ip_lock, flags);
8409 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8410 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8412 spin_unlock_irqrestore(&card->ip_lock, flags);
8414 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8417 if (!qeth_add_ip(card, ipaddr))
8419 qeth_set_ip_addr_list(card);
8424 qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8427 struct qeth_ipaddr *ipaddr;
8429 ipaddr = qeth_get_addr_buffer(proto);
8431 if (proto == QETH_PROT_IPV4){
8432 QETH_DBF_TEXT(trace, 2, "delvipa4");
8433 memcpy(&ipaddr->u.a4.addr, addr, 4);
8434 ipaddr->u.a4.mask = 0;
8435 #ifdef CONFIG_QETH_IPV6
8436 } else if (proto == QETH_PROT_IPV6){
8437 QETH_DBF_TEXT(trace, 2, "delvipa6");
8438 memcpy(&ipaddr->u.a6.addr, addr, 16);
8439 ipaddr->u.a6.pfxlen = 0;
8442 ipaddr->type = QETH_IP_TYPE_VIPA;
8445 if (!qeth_delete_ip(card, ipaddr))
8447 qeth_set_ip_addr_list(card);
8451 * proxy ARP related functions
8454 qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8457 struct qeth_ipaddr *ipaddr;
8458 unsigned long flags;
8461 ipaddr = qeth_get_addr_buffer(proto);
8463 if (proto == QETH_PROT_IPV4){
8464 QETH_DBF_TEXT(trace, 2, "addrxip4");
8465 memcpy(&ipaddr->u.a4.addr, addr, 4);
8466 ipaddr->u.a4.mask = 0;
8467 #ifdef CONFIG_QETH_IPV6
8468 } else if (proto == QETH_PROT_IPV6){
8469 QETH_DBF_TEXT(trace, 2, "addrxip6");
8470 memcpy(&ipaddr->u.a6.addr, addr, 16);
8471 ipaddr->u.a6.pfxlen = 0;
8474 ipaddr->type = QETH_IP_TYPE_RXIP;
8475 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8476 ipaddr->del_flags = 0;
8479 spin_lock_irqsave(&card->ip_lock, flags);
8480 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8481 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8483 spin_unlock_irqrestore(&card->ip_lock, flags);
8485 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8488 if (!qeth_add_ip(card, ipaddr))
8490 qeth_set_ip_addr_list(card);
8495 qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8498 struct qeth_ipaddr *ipaddr;
8500 ipaddr = qeth_get_addr_buffer(proto);
8502 if (proto == QETH_PROT_IPV4){
8503 QETH_DBF_TEXT(trace, 2, "addrxip4");
8504 memcpy(&ipaddr->u.a4.addr, addr, 4);
8505 ipaddr->u.a4.mask = 0;
8506 #ifdef CONFIG_QETH_IPV6
8507 } else if (proto == QETH_PROT_IPV6){
8508 QETH_DBF_TEXT(trace, 2, "addrxip6");
8509 memcpy(&ipaddr->u.a6.addr, addr, 16);
8510 ipaddr->u.a6.pfxlen = 0;
8513 ipaddr->type = QETH_IP_TYPE_RXIP;
8516 if (!qeth_delete_ip(card, ipaddr))
8518 qeth_set_ip_addr_list(card);
8525 qeth_ip_event(struct notifier_block *this,
8526 unsigned long event,void *ptr)
8528 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8529 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8530 struct qeth_ipaddr *addr;
8531 struct qeth_card *card;
8533 QETH_DBF_TEXT(trace,3,"ipevent");
8534 card = qeth_get_card_from_dev(dev);
8537 if (card->options.layer2)
8540 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8542 addr->u.a4.addr = ifa->ifa_address;
8543 addr->u.a4.mask = ifa->ifa_mask;
8544 addr->type = QETH_IP_TYPE_NORMAL;
8550 if (!qeth_add_ip(card, addr))
8554 if (!qeth_delete_ip(card, addr))
8560 qeth_set_ip_addr_list(card);
8565 static struct notifier_block qeth_ip_notifier = {
8570 #ifdef CONFIG_QETH_IPV6
8572 * IPv6 event handler
8575 qeth_ip6_event(struct notifier_block *this,
8576 unsigned long event,void *ptr)
8579 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8580 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8581 struct qeth_ipaddr *addr;
8582 struct qeth_card *card;
8584 QETH_DBF_TEXT(trace,3,"ip6event");
8586 card = qeth_get_card_from_dev(dev);
8589 if (!qeth_is_supported(card, IPA_IPV6))
8592 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8594 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8595 addr->u.a6.pfxlen = ifa->prefix_len;
8596 addr->type = QETH_IP_TYPE_NORMAL;
8602 if (!qeth_add_ip(card, addr))
8606 if (!qeth_delete_ip(card, addr))
8612 qeth_set_ip_addr_list(card);
8617 static struct notifier_block qeth_ip6_notifier = {
8624 __qeth_reboot_event_card(struct device *dev, void *data)
8626 struct qeth_card *card;
8628 card = (struct qeth_card *) dev->driver_data;
8629 qeth_clear_ip_list(card, 0, 0);
8630 qeth_qdio_clear_card(card, 0);
8631 qeth_clear_qdio_buffers(card);
8636 qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8640 ret = driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8641 __qeth_reboot_event_card);
8642 return ret ? NOTIFY_BAD : NOTIFY_DONE;
8646 static struct notifier_block qeth_reboot_notifier = {
8652 qeth_register_notifiers(void)
8656 QETH_DBF_TEXT(trace,5,"regnotif");
8657 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8659 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8661 #ifdef CONFIG_QETH_IPV6
8662 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8667 #ifdef CONFIG_QETH_IPV6
8669 unregister_inetaddr_notifier(&qeth_ip_notifier);
8672 unregister_reboot_notifier(&qeth_reboot_notifier);
8677 * unregister all event notifiers
8680 qeth_unregister_notifiers(void)
8683 QETH_DBF_TEXT(trace,5,"unregnot");
8684 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8685 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8686 #ifdef CONFIG_QETH_IPV6
8687 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8688 #endif /* QETH_IPV6 */
8692 #ifdef CONFIG_QETH_IPV6
8694 qeth_ipv6_init(void)
8696 qeth_old_arp_constructor = arp_tbl.constructor;
8697 write_lock_bh(&arp_tbl.lock);
8698 arp_tbl.constructor = qeth_arp_constructor;
8699 write_unlock_bh(&arp_tbl.lock);
8701 arp_direct_ops = (struct neigh_ops*)
8702 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8703 if (!arp_direct_ops)
8706 memcpy(arp_direct_ops, &arp_direct_ops_template,
8707 sizeof(struct neigh_ops));
8713 qeth_ipv6_uninit(void)
8715 write_lock_bh(&arp_tbl.lock);
8716 arp_tbl.constructor = qeth_old_arp_constructor;
8717 write_unlock_bh(&arp_tbl.lock);
8718 kfree(arp_direct_ops);
8720 #endif /* CONFIG_QETH_IPV6 */
8723 qeth_sysfs_unregister(void)
8725 s390_root_dev_unregister(qeth_root_dev);
8726 qeth_remove_driver_attributes();
8727 ccw_driver_unregister(&qeth_ccw_driver);
8728 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8732 * register qeth at sysfs
8735 qeth_sysfs_register(void)
8739 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8743 rc = ccw_driver_register(&qeth_ccw_driver);
8745 goto out_ccw_driver;
8747 rc = qeth_create_driver_attributes();
8751 qeth_root_dev = s390_root_dev_register("qeth");
8752 rc = IS_ERR(qeth_root_dev) ? PTR_ERR(qeth_root_dev) : 0;
8756 qeth_remove_driver_attributes();
8758 ccw_driver_unregister(&qeth_ccw_driver);
8760 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8773 PRINT_INFO("loading %s\n", version);
8775 INIT_LIST_HEAD(&qeth_card_list.list);
8776 INIT_LIST_HEAD(&qeth_notify_list);
8777 spin_lock_init(&qeth_notify_lock);
8778 rwlock_init(&qeth_card_list.rwlock);
8780 rc = qeth_register_dbf_views();
8784 rc = qeth_sysfs_register();
8788 #ifdef CONFIG_QETH_IPV6
8789 rc = qeth_ipv6_init();
8791 PRINT_ERR("Out of memory during ipv6 init code = %d\n", rc);
8794 #endif /* QETH_IPV6 */
8795 rc = qeth_register_notifiers();
8798 rc = qeth_create_procfs_entries();
8805 qeth_unregister_notifiers();
8807 #ifdef CONFIG_QETH_IPV6
8810 #endif /* QETH_IPV6 */
8811 qeth_sysfs_unregister();
8813 qeth_unregister_dbf_views();
8815 PRINT_ERR("Initialization failed with code %d\n", rc);
8820 __exit qeth_exit(void)
8822 struct qeth_card *card, *tmp;
8823 unsigned long flags;
8825 QETH_DBF_TEXT(trace,1, "cleanup.");
8828 * Weed would not need to clean up our devices here, because the
8829 * common device layer calls qeth_remove_device for each device
8830 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8831 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8832 * qeth_remove_device called by the common device layer would otherwise
8833 * do a "hard" shutdown (card->use_hard_stop is set to one in
8834 * qeth_remove_device).
8837 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8838 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8839 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8840 qeth_set_offline(card->gdev);
8841 qeth_remove_device(card->gdev);
8844 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8845 #ifdef CONFIG_QETH_IPV6
8848 qeth_unregister_notifiers();
8849 qeth_remove_procfs_entries();
8850 qeth_sysfs_unregister();
8851 qeth_unregister_dbf_views();
8852 printk("qeth: removed\n");
8855 EXPORT_SYMBOL(qeth_osn_register);
8856 EXPORT_SYMBOL(qeth_osn_deregister);
8857 EXPORT_SYMBOL(qeth_osn_assist);
8858 module_init(qeth_init);
8859 module_exit(qeth_exit);
8860 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
8861 MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8862 "Copyright 2000,2003 IBM Corporation\n");
8864 MODULE_LICENSE("GPL");