3 * linux/drivers/s390/net/qeth_main.c ($Revision: 1.224 $)
5 * Linux on zSeries OSA Express and HiperSockets support
7 * Copyright 2000,2003 IBM Corporation
9 * Author(s): Original Code written by
10 * Utz Bacher (utz.bacher@de.ibm.com)
12 * Frank Pavlic (pavlic@de.ibm.com) and
13 * Thomas Spatzier <tspat@de.ibm.com>
15 * $Revision: 1.224 $ $Date: 2005/05/04 20:19:18 $
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/string.h>
37 #include <linux/errno.h>
40 #include <linux/inetdevice.h>
41 #include <linux/netdevice.h>
42 #include <linux/sched.h>
43 #include <linux/workqueue.h>
44 #include <linux/kernel.h>
45 #include <linux/slab.h>
46 #include <linux/interrupt.h>
47 #include <linux/tcp.h>
48 #include <linux/icmp.h>
49 #include <linux/skbuff.h>
51 #include <linux/igmp.h>
52 #include <linux/init.h>
53 #include <linux/reboot.h>
54 #include <linux/mii.h>
55 #include <linux/rcupdate.h>
56 #include <linux/ethtool.h>
60 #include <net/route.h>
62 #include <asm/ebcdic.h>
65 #include <asm/timex.h>
66 #include <asm/semaphore.h>
67 #include <asm/uaccess.h>
72 #include "qeth_eddp.h"
75 #define VERSION_QETH_C "$Revision: 1.224 $"
76 static const char *version = "qeth S/390 OSA-Express driver";
79 * Debug Facility Stuff
81 static debug_info_t *qeth_dbf_setup = NULL;
82 static debug_info_t *qeth_dbf_data = NULL;
83 static debug_info_t *qeth_dbf_misc = NULL;
84 static debug_info_t *qeth_dbf_control = NULL;
85 debug_info_t *qeth_dbf_trace = NULL;
86 static debug_info_t *qeth_dbf_sense = NULL;
87 static debug_info_t *qeth_dbf_qerr = NULL;
89 DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
92 * some more definitions and declarations
94 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
96 /* list of our cards */
97 struct qeth_card_list_struct qeth_card_list;
98 /*process list want to be notified*/
99 spinlock_t qeth_notify_lock;
100 struct list_head qeth_notify_list;
102 static void qeth_send_control_data_cb(struct qeth_channel *,
103 struct qeth_cmd_buffer *);
106 * here we go with function implementation
109 qeth_init_qdio_info(struct qeth_card *card);
112 qeth_init_qdio_queues(struct qeth_card *card);
115 qeth_alloc_qdio_buffers(struct qeth_card *card);
118 qeth_free_qdio_buffers(struct qeth_card *);
121 qeth_clear_qdio_buffers(struct qeth_card *);
124 qeth_clear_ip_list(struct qeth_card *, int, int);
127 qeth_clear_ipacmd_list(struct qeth_card *);
130 qeth_qdio_clear_card(struct qeth_card *, int);
133 qeth_clear_working_pool_list(struct qeth_card *);
136 qeth_clear_cmd_buffers(struct qeth_channel *);
139 qeth_stop(struct net_device *);
142 qeth_clear_ipato_list(struct qeth_card *);
145 qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
148 qeth_irq_tasklet(unsigned long);
151 qeth_set_online(struct ccwgroup_device *);
154 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
156 static struct qeth_ipaddr *
157 qeth_get_addr_buffer(enum qeth_prot_versions);
160 qeth_set_multicast_list(struct net_device *);
163 qeth_notify_processes(void)
165 /*notify all registered processes */
166 struct qeth_notify_list_struct *n_entry;
168 QETH_DBF_TEXT(trace,3,"procnoti");
169 spin_lock(&qeth_notify_lock);
170 list_for_each_entry(n_entry, &qeth_notify_list, list) {
171 send_sig(n_entry->signum, n_entry->task, 1);
173 spin_unlock(&qeth_notify_lock);
177 qeth_notifier_unregister(struct task_struct *p)
179 struct qeth_notify_list_struct *n_entry, *tmp;
181 QETH_DBF_TEXT(trace, 2, "notunreg");
182 spin_lock(&qeth_notify_lock);
183 list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
184 if (n_entry->task == p) {
185 list_del(&n_entry->list);
191 spin_unlock(&qeth_notify_lock);
195 qeth_notifier_register(struct task_struct *p, int signum)
197 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 = (struct qeth_card *) kmalloc(sizeof(struct qeth_card),
305 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
306 memset(card, 0, sizeof(struct qeth_card));
307 if (qeth_setup_channel(&card->read)) {
311 if (qeth_setup_channel(&card->write)) {
312 qeth_clean_channel(&card->read);
320 __qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb)
325 switch (PTR_ERR(irb)) {
327 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
328 QETH_DBF_TEXT(trace, 2, "ckirberr");
329 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
332 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
333 QETH_DBF_TEXT(trace, 2, "ckirberr");
334 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
337 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
339 QETH_DBF_TEXT(trace, 2, "ckirberr");
340 QETH_DBF_TEXT(trace, 2, " rc???");
346 qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
351 sense = (char *) irb->ecw;
352 cstat = irb->scsw.cstat;
353 dstat = irb->scsw.dstat;
355 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
356 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
357 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
358 QETH_DBF_TEXT(trace,2, "CGENCHK");
359 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
360 cdev->dev.bus_id, dstat, cstat);
361 HEXDUMP16(WARN, "irb: ", irb);
362 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
366 if (dstat & DEV_STAT_UNIT_CHECK) {
367 if (sense[SENSE_RESETTING_EVENT_BYTE] &
368 SENSE_RESETTING_EVENT_FLAG) {
369 QETH_DBF_TEXT(trace,2,"REVIND");
372 if (sense[SENSE_COMMAND_REJECT_BYTE] &
373 SENSE_COMMAND_REJECT_FLAG) {
374 QETH_DBF_TEXT(trace,2,"CMDREJi");
377 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
378 QETH_DBF_TEXT(trace,2,"AFFE");
381 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
382 QETH_DBF_TEXT(trace,2,"ZEROSEN");
385 QETH_DBF_TEXT(trace,2,"DGENCHK");
390 static int qeth_issue_next_read(struct qeth_card *);
396 qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
400 struct qeth_cmd_buffer *buffer;
401 struct qeth_channel *channel;
402 struct qeth_card *card;
404 QETH_DBF_TEXT(trace,5,"irq");
406 if (__qeth_check_irb_error(cdev, irb))
408 cstat = irb->scsw.cstat;
409 dstat = irb->scsw.dstat;
411 card = CARD_FROM_CDEV(cdev);
415 if (card->read.ccwdev == cdev){
416 channel = &card->read;
417 QETH_DBF_TEXT(trace,5,"read");
418 } else if (card->write.ccwdev == cdev) {
419 channel = &card->write;
420 QETH_DBF_TEXT(trace,5,"write");
422 channel = &card->data;
423 QETH_DBF_TEXT(trace,5,"data");
425 atomic_set(&channel->irq_pending, 0);
427 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
428 channel->state = CH_STATE_STOPPED;
430 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
431 channel->state = CH_STATE_HALTED;
433 /*let's wake up immediately on data channel*/
434 if ((channel == &card->data) && (intparm != 0))
437 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
438 QETH_DBF_TEXT(trace, 6, "clrchpar");
439 /* we don't have to handle this further */
442 if (intparm == QETH_HALT_CHANNEL_PARM) {
443 QETH_DBF_TEXT(trace, 6, "hltchpar");
444 /* we don't have to handle this further */
447 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
448 (dstat & DEV_STAT_UNIT_CHECK) ||
450 if (irb->esw.esw0.erw.cons) {
451 /* TODO: we should make this s390dbf */
452 PRINT_WARN("sense data available on channel %s.\n",
453 CHANNEL_ID(channel));
454 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
455 HEXDUMP16(WARN,"irb: ",irb);
456 HEXDUMP16(WARN,"sense data: ",irb->ecw);
458 rc = qeth_get_problem(cdev,irb);
460 qeth_schedule_recovery(card);
466 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
467 buffer->state = BUF_STATE_PROCESSED;
469 if (channel == &card->data)
472 if (channel == &card->read &&
473 channel->state == CH_STATE_UP)
474 qeth_issue_next_read(card);
476 tasklet_schedule(&channel->irq_tasklet);
479 wake_up(&card->wait_q);
483 * tasklet function scheduled from irq handler
486 qeth_irq_tasklet(unsigned long data)
488 struct qeth_card *card;
489 struct qeth_channel *channel;
490 struct qeth_cmd_buffer *iob;
493 QETH_DBF_TEXT(trace,5,"irqtlet");
494 channel = (struct qeth_channel *) data;
496 index = channel->buf_no;
497 card = CARD_FROM_CDEV(channel->ccwdev);
498 while (iob[index].state == BUF_STATE_PROCESSED) {
499 if (iob[index].callback !=NULL) {
500 iob[index].callback(channel,iob + index);
502 index = (index + 1) % QETH_CMD_BUFFER_NO;
504 channel->buf_no = index;
505 wake_up(&card->wait_q);
508 static int qeth_stop_card(struct qeth_card *, int);
511 __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
513 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
514 int rc = 0, rc2 = 0, rc3 = 0;
515 enum qeth_card_states recover_flag;
517 QETH_DBF_TEXT(setup, 3, "setoffl");
518 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
520 recover_flag = card->state;
521 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
522 PRINT_WARN("Stopping card %s interrupted by user!\n",
526 rc = ccw_device_set_offline(CARD_DDEV(card));
527 rc2 = ccw_device_set_offline(CARD_WDEV(card));
528 rc3 = ccw_device_set_offline(CARD_RDEV(card));
530 rc = (rc2) ? rc2 : rc3;
532 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
533 if (recover_flag == CARD_STATE_UP)
534 card->state = CARD_STATE_RECOVER;
535 qeth_notify_processes();
540 qeth_set_offline(struct ccwgroup_device *cgdev)
542 return __qeth_set_offline(cgdev, 0);
546 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads);
550 qeth_remove_device(struct ccwgroup_device *cgdev)
552 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
555 QETH_DBF_TEXT(setup, 3, "rmdev");
556 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
561 if (qeth_wait_for_threads(card, 0xffffffff))
564 if (cgdev->state == CCWGROUP_ONLINE){
565 card->use_hard_stop = 1;
566 qeth_set_offline(cgdev);
568 /* remove form our internal list */
569 write_lock_irqsave(&qeth_card_list.rwlock, flags);
570 list_del(&card->list);
571 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
573 unregister_netdev(card->dev);
574 qeth_remove_device_attributes(&cgdev->dev);
575 qeth_free_card(card);
576 cgdev->dev.driver_data = NULL;
577 put_device(&cgdev->dev);
581 qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
583 qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
586 * Add/remove address to/from card's ip list, i.e. try to add or remove
587 * reference to/from an IP address that is already registered on the card.
589 * 0 address was on card and its reference count has been adjusted,
590 * but is still > 0, so nothing has to be done
591 * also returns 0 if card was not on card and the todo was to delete
592 * the address -> there is also nothing to be done
593 * 1 address was not on card and the todo is to add it to the card's ip
595 * -1 address was on card and its reference count has been decremented
596 * to <= 0 by the todo -> address must be removed from card
599 __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
600 struct qeth_ipaddr **__addr)
602 struct qeth_ipaddr *addr;
605 list_for_each_entry(addr, &card->ip_list, entry) {
606 if ((addr->proto == QETH_PROT_IPV4) &&
607 (todo->proto == QETH_PROT_IPV4) &&
608 (addr->type == todo->type) &&
609 (addr->u.a4.addr == todo->u.a4.addr) &&
610 (addr->u.a4.mask == todo->u.a4.mask) ){
614 if ((addr->proto == QETH_PROT_IPV6) &&
615 (todo->proto == QETH_PROT_IPV6) &&
616 (addr->type == todo->type) &&
617 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
618 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
619 sizeof(struct in6_addr)) == 0)) {
625 addr->users += todo->users;
626 if (addr->users <= 0){
630 /* for VIPA and RXIP limit refcount to 1 */
631 if (addr->type != QETH_IP_TYPE_NORMAL)
636 if (todo->users > 0){
637 /* for VIPA and RXIP limit refcount to 1 */
638 if (todo->type != QETH_IP_TYPE_NORMAL)
646 __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
649 struct qeth_ipaddr *tmp;
651 list_for_each_entry(tmp, list, entry) {
652 if ((tmp->proto == QETH_PROT_IPV4) &&
653 (addr->proto == QETH_PROT_IPV4) &&
654 ((same_type && (tmp->type == addr->type)) ||
655 (!same_type && (tmp->type != addr->type)) ) &&
656 (tmp->u.a4.addr == addr->u.a4.addr) ){
659 if ((tmp->proto == QETH_PROT_IPV6) &&
660 (addr->proto == QETH_PROT_IPV6) &&
661 ((same_type && (tmp->type == addr->type)) ||
662 (!same_type && (tmp->type != addr->type)) ) &&
663 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
664 sizeof(struct in6_addr)) == 0) ) {
672 * Add IP to be added to todo list. If there is already an "add todo"
673 * in this list we just incremenent the reference count.
674 * Returns 0 if we just incremented reference count.
677 __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
679 struct qeth_ipaddr *tmp, *t;
682 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
683 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
684 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
686 if ((tmp->proto == QETH_PROT_IPV4) &&
687 (addr->proto == QETH_PROT_IPV4) &&
688 (tmp->type == addr->type) &&
689 (tmp->is_multicast == addr->is_multicast) &&
690 (tmp->u.a4.addr == addr->u.a4.addr) &&
691 (tmp->u.a4.mask == addr->u.a4.mask) ){
695 if ((tmp->proto == QETH_PROT_IPV6) &&
696 (addr->proto == QETH_PROT_IPV6) &&
697 (tmp->type == addr->type) &&
698 (tmp->is_multicast == addr->is_multicast) &&
699 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
700 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
701 sizeof(struct in6_addr)) == 0) ){
707 if (addr->users != 0)
708 tmp->users += addr->users;
710 tmp->users += add? 1:-1;
711 if (tmp->users == 0){
712 list_del(&tmp->entry);
717 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
718 list_add(&addr->entry, card->ip_tbd_list);
720 if (addr->users == 0)
721 addr->users += add? 1:-1;
722 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
723 qeth_is_addr_covered_by_ipato(card, addr)){
724 QETH_DBF_TEXT(trace, 2, "tkovaddr");
725 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
727 list_add_tail(&addr->entry, card->ip_tbd_list);
734 * Remove IP address from list
737 qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
742 QETH_DBF_TEXT(trace,4,"delip");
743 if (addr->proto == QETH_PROT_IPV4)
744 QETH_DBF_HEX(trace,4,&addr->u.a4.addr,4);
746 QETH_DBF_HEX(trace,4,&addr->u.a6.addr,8);
747 QETH_DBF_HEX(trace,4,((char *)&addr->u.a6.addr)+8,8);
749 spin_lock_irqsave(&card->ip_lock, flags);
750 rc = __qeth_insert_ip_todo(card, addr, 0);
751 spin_unlock_irqrestore(&card->ip_lock, flags);
756 qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
761 QETH_DBF_TEXT(trace,4,"addip");
762 if (addr->proto == QETH_PROT_IPV4)
763 QETH_DBF_HEX(trace,4,&addr->u.a4.addr,4);
765 QETH_DBF_HEX(trace,4,&addr->u.a6.addr,8);
766 QETH_DBF_HEX(trace,4,((char *)&addr->u.a6.addr)+8,8);
768 spin_lock_irqsave(&card->ip_lock, flags);
769 rc = __qeth_insert_ip_todo(card, addr, 1);
770 spin_unlock_irqrestore(&card->ip_lock, flags);
775 __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
777 struct qeth_ipaddr *addr, *tmp;
780 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
781 if (addr->is_multicast) {
782 spin_unlock_irqrestore(&card->ip_lock, *flags);
783 rc = qeth_deregister_addr_entry(card, addr);
784 spin_lock_irqsave(&card->ip_lock, *flags);
786 list_del(&addr->entry);
794 qeth_set_ip_addr_list(struct qeth_card *card)
796 struct list_head *tbd_list;
797 struct qeth_ipaddr *todo, *addr;
801 QETH_DBF_TEXT(trace, 2, "sdiplist");
802 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
804 spin_lock_irqsave(&card->ip_lock, flags);
805 tbd_list = card->ip_tbd_list;
806 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
807 if (!card->ip_tbd_list) {
808 QETH_DBF_TEXT(trace, 0, "silnomem");
809 card->ip_tbd_list = tbd_list;
810 spin_unlock_irqrestore(&card->ip_lock, flags);
813 INIT_LIST_HEAD(card->ip_tbd_list);
815 while (!list_empty(tbd_list)){
816 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
817 list_del(&todo->entry);
818 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
819 __qeth_delete_all_mc(card, &flags);
823 rc = __qeth_ref_ip_on_card(card, todo, &addr);
825 /* nothing to be done; only adjusted refcount */
827 } else if (rc == 1) {
828 /* new entry to be added to on-card list */
829 spin_unlock_irqrestore(&card->ip_lock, flags);
830 rc = qeth_register_addr_entry(card, todo);
831 spin_lock_irqsave(&card->ip_lock, flags);
833 list_add_tail(&todo->entry, &card->ip_list);
836 } else if (rc == -1) {
837 /* on-card entry to be removed */
838 list_del_init(&addr->entry);
839 spin_unlock_irqrestore(&card->ip_lock, flags);
840 rc = qeth_deregister_addr_entry(card, addr);
841 spin_lock_irqsave(&card->ip_lock, flags);
845 list_add_tail(&addr->entry, &card->ip_list);
849 spin_unlock_irqrestore(&card->ip_lock, flags);
853 static void qeth_delete_mc_addresses(struct qeth_card *);
854 static void qeth_add_multicast_ipv4(struct qeth_card *);
855 #ifdef CONFIG_QETH_IPV6
856 static void qeth_add_multicast_ipv6(struct qeth_card *);
860 qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
864 spin_lock_irqsave(&card->thread_mask_lock, flags);
865 if ( !(card->thread_allowed_mask & thread) ||
866 (card->thread_start_mask & thread) ) {
867 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
870 card->thread_start_mask |= thread;
871 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
876 qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
880 spin_lock_irqsave(&card->thread_mask_lock, flags);
881 card->thread_start_mask &= ~thread;
882 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
883 wake_up(&card->wait_q);
887 qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
891 spin_lock_irqsave(&card->thread_mask_lock, flags);
892 card->thread_running_mask &= ~thread;
893 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
894 wake_up(&card->wait_q);
898 __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
903 spin_lock_irqsave(&card->thread_mask_lock, flags);
904 if (card->thread_start_mask & thread){
905 if ((card->thread_allowed_mask & thread) &&
906 !(card->thread_running_mask & thread)){
908 card->thread_start_mask &= ~thread;
909 card->thread_running_mask |= thread;
913 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
918 qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
922 wait_event(card->wait_q,
923 (rc = __qeth_do_run_thread(card, thread)) >= 0);
928 qeth_register_ip_addresses(void *ptr)
930 struct qeth_card *card;
932 card = (struct qeth_card *) ptr;
933 daemonize("qeth_reg_ip");
934 QETH_DBF_TEXT(trace,4,"regipth1");
935 if (!qeth_do_run_thread(card, QETH_SET_IP_THREAD))
937 QETH_DBF_TEXT(trace,4,"regipth2");
938 qeth_set_ip_addr_list(card);
939 qeth_clear_thread_running_bit(card, QETH_SET_IP_THREAD);
944 qeth_recover(void *ptr)
946 struct qeth_card *card;
949 card = (struct qeth_card *) ptr;
950 daemonize("qeth_recover");
951 QETH_DBF_TEXT(trace,2,"recover1");
952 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
953 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
955 QETH_DBF_TEXT(trace,2,"recover2");
956 PRINT_WARN("Recovery of device %s started ...\n",
958 card->use_hard_stop = 1;
959 __qeth_set_offline(card->gdev,1);
960 rc = __qeth_set_online(card->gdev,1);
962 PRINT_INFO("Device %s successfully recovered!\n",
965 PRINT_INFO("Device %s could not be recovered!\n",
967 /* don't run another scheduled recovery */
968 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
969 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
974 qeth_schedule_recovery(struct qeth_card *card)
976 QETH_DBF_TEXT(trace,2,"startrec");
978 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
979 schedule_work(&card->kernel_thread_starter);
983 qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
988 spin_lock_irqsave(&card->thread_mask_lock, flags);
989 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
990 (u8) card->thread_start_mask,
991 (u8) card->thread_allowed_mask,
992 (u8) card->thread_running_mask);
993 rc = (card->thread_start_mask & thread);
994 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
999 qeth_start_kernel_thread(struct qeth_card *card)
1001 QETH_DBF_TEXT(trace , 2, "strthrd");
1003 if (card->read.state != CH_STATE_UP &&
1004 card->write.state != CH_STATE_UP)
1007 if (qeth_do_start_thread(card, QETH_SET_IP_THREAD))
1008 kernel_thread(qeth_register_ip_addresses, (void *)card,SIGCHLD);
1009 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1010 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1015 qeth_set_intial_options(struct qeth_card *card)
1017 card->options.route4.type = NO_ROUTER;
1018 #ifdef CONFIG_QETH_IPV6
1019 card->options.route6.type = NO_ROUTER;
1020 #endif /* QETH_IPV6 */
1021 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1022 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1023 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1024 card->options.fake_broadcast = 0;
1025 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1026 card->options.fake_ll = 0;
1027 card->options.layer2 = 0;
1031 * initialize channels ,card and all state machines
1034 qeth_setup_card(struct qeth_card *card)
1037 QETH_DBF_TEXT(setup, 2, "setupcrd");
1038 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1040 card->read.state = CH_STATE_DOWN;
1041 card->write.state = CH_STATE_DOWN;
1042 card->data.state = CH_STATE_DOWN;
1043 card->state = CARD_STATE_DOWN;
1044 card->lan_online = 0;
1045 card->use_hard_stop = 0;
1047 #ifdef CONFIG_QETH_VLAN
1048 spin_lock_init(&card->vlanlock);
1049 card->vlangrp = NULL;
1051 spin_lock_init(&card->lock);
1052 spin_lock_init(&card->ip_lock);
1053 spin_lock_init(&card->thread_mask_lock);
1054 card->thread_start_mask = 0;
1055 card->thread_allowed_mask = 0;
1056 card->thread_running_mask = 0;
1057 INIT_WORK(&card->kernel_thread_starter,
1058 (void *)qeth_start_kernel_thread,card);
1059 INIT_LIST_HEAD(&card->ip_list);
1060 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1061 if (!card->ip_tbd_list) {
1062 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1065 INIT_LIST_HEAD(card->ip_tbd_list);
1066 INIT_LIST_HEAD(&card->cmd_waiter_list);
1067 init_waitqueue_head(&card->wait_q);
1068 /* intial options */
1069 qeth_set_intial_options(card);
1070 /* IP address takeover */
1071 INIT_LIST_HEAD(&card->ipato.entries);
1072 card->ipato.enabled = 0;
1073 card->ipato.invert4 = 0;
1074 card->ipato.invert6 = 0;
1075 /* init QDIO stuff */
1076 qeth_init_qdio_info(card);
1081 is_1920_device (struct qeth_card *card)
1083 int single_queue = 0;
1084 struct ccw_device *ccwdev;
1085 struct channelPath_dsc {
1096 QETH_DBF_TEXT(setup, 2, "chk_1920");
1098 ccwdev = card->data.ccwdev;
1099 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1100 if (chp_dsc != NULL) {
1101 /* CHPP field bit 6 == 1 -> single queue */
1102 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1105 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1106 return single_queue;
1110 qeth_determine_card_type(struct qeth_card *card)
1114 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1116 while (known_devices[i][4]) {
1117 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1118 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1119 card->info.type = known_devices[i][4];
1120 if (is_1920_device(card)) {
1121 PRINT_INFO("Priority Queueing not able "
1122 "due to hardware limitations!\n");
1123 card->qdio.no_out_queues = 1;
1124 card->qdio.default_out_queue = 0;
1126 card->qdio.no_out_queues = known_devices[i][8];
1128 card->info.is_multicast_different = known_devices[i][9];
1133 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1134 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1139 qeth_probe_device(struct ccwgroup_device *gdev)
1141 struct qeth_card *card;
1143 unsigned long flags;
1146 QETH_DBF_TEXT(setup, 2, "probedev");
1149 if (!get_device(dev))
1152 card = qeth_alloc_card();
1155 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1158 card->read.ccwdev = gdev->cdev[0];
1159 card->write.ccwdev = gdev->cdev[1];
1160 card->data.ccwdev = gdev->cdev[2];
1162 if ((rc = qeth_setup_card(card))){
1163 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1165 qeth_free_card(card);
1168 gdev->dev.driver_data = card;
1170 gdev->cdev[0]->handler = qeth_irq;
1171 gdev->cdev[1]->handler = qeth_irq;
1172 gdev->cdev[2]->handler = qeth_irq;
1174 rc = qeth_create_device_attributes(dev);
1177 qeth_free_card(card);
1180 if ((rc = qeth_determine_card_type(card))){
1181 PRINT_WARN("%s: not a valid card type\n", __func__);
1182 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1184 qeth_free_card(card);
1187 /* insert into our internal list */
1188 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1189 list_add_tail(&card->list, &qeth_card_list.list);
1190 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1196 qeth_get_unitaddr(struct qeth_card *card)
1202 QETH_DBF_TEXT(setup, 2, "getunit");
1203 rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length);
1205 PRINT_ERR("read_conf_data for device %s returned %i\n",
1206 CARD_DDEV_ID(card), rc);
1209 card->info.chpid = prcd[30];
1210 card->info.unit_addr2 = prcd[31];
1211 card->info.cula = prcd[63];
1212 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1213 (prcd[0x11] == _ascebc['M']));
1218 qeth_init_tokens(struct qeth_card *card)
1220 card->token.issuer_rm_w = 0x00010103UL;
1221 card->token.cm_filter_w = 0x00010108UL;
1222 card->token.cm_connection_w = 0x0001010aUL;
1223 card->token.ulp_filter_w = 0x0001010bUL;
1224 card->token.ulp_connection_w = 0x0001010dUL;
1228 raw_devno_from_bus_id(char *id)
1230 id += (strlen(id) - 4);
1231 return (__u16) simple_strtoul(id, &id, 16);
1237 qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1239 struct qeth_card *card;
1241 QETH_DBF_TEXT(trace, 4, "setupccw");
1242 card = CARD_FROM_CDEV(channel->ccwdev);
1243 if (channel == &card->read)
1244 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1246 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1247 channel->ccw.count = len;
1248 channel->ccw.cda = (__u32) __pa(iob);
1252 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1254 static struct qeth_cmd_buffer *
1255 __qeth_get_buffer(struct qeth_channel *channel)
1259 QETH_DBF_TEXT(trace, 6, "getbuff");
1260 index = channel->io_buf_no;
1262 if (channel->iob[index].state == BUF_STATE_FREE) {
1263 channel->iob[index].state = BUF_STATE_LOCKED;
1264 channel->io_buf_no = (channel->io_buf_no + 1) %
1266 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1267 return channel->iob + index;
1269 index = (index + 1) % QETH_CMD_BUFFER_NO;
1270 } while(index != channel->io_buf_no);
1276 * release command buffer
1279 qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1281 unsigned long flags;
1283 QETH_DBF_TEXT(trace, 6, "relbuff");
1284 spin_lock_irqsave(&channel->iob_lock, flags);
1285 memset(iob->data, 0, QETH_BUFSIZE);
1286 iob->state = BUF_STATE_FREE;
1287 iob->callback = qeth_send_control_data_cb;
1289 spin_unlock_irqrestore(&channel->iob_lock, flags);
1292 static struct qeth_cmd_buffer *
1293 qeth_get_buffer(struct qeth_channel *channel)
1295 struct qeth_cmd_buffer *buffer = NULL;
1296 unsigned long flags;
1298 spin_lock_irqsave(&channel->iob_lock, flags);
1299 buffer = __qeth_get_buffer(channel);
1300 spin_unlock_irqrestore(&channel->iob_lock, flags);
1304 static struct qeth_cmd_buffer *
1305 qeth_wait_for_buffer(struct qeth_channel *channel)
1307 struct qeth_cmd_buffer *buffer;
1308 wait_event(channel->wait_q,
1309 ((buffer = qeth_get_buffer(channel)) != NULL));
1314 qeth_clear_cmd_buffers(struct qeth_channel *channel)
1318 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1319 qeth_release_buffer(channel,&channel->iob[cnt]);
1320 channel->buf_no = 0;
1321 channel->io_buf_no = 0;
1325 * start IDX for read and write channel
1328 qeth_idx_activate_get_answer(struct qeth_channel *channel,
1329 void (*idx_reply_cb)(struct qeth_channel *,
1330 struct qeth_cmd_buffer *))
1332 struct qeth_cmd_buffer *iob;
1333 unsigned long flags;
1335 struct qeth_card *card;
1337 QETH_DBF_TEXT(setup, 2, "idxanswr");
1338 card = CARD_FROM_CDEV(channel->ccwdev);
1339 iob = qeth_get_buffer(channel);
1340 iob->callback = idx_reply_cb;
1341 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1342 channel->ccw.count = QETH_BUFSIZE;
1343 channel->ccw.cda = (__u32) __pa(iob->data);
1345 wait_event(card->wait_q,
1346 atomic_compare_and_swap(0,1,&channel->irq_pending) == 0);
1347 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1348 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1349 rc = ccw_device_start(channel->ccwdev,
1350 &channel->ccw,(addr_t) iob, 0, 0);
1351 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1354 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1355 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1356 atomic_set(&channel->irq_pending, 0);
1357 wake_up(&card->wait_q);
1360 rc = wait_event_interruptible_timeout(card->wait_q,
1361 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1362 if (rc == -ERESTARTSYS)
1364 if (channel->state != CH_STATE_UP){
1366 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1367 qeth_clear_cmd_buffers(channel);
1374 qeth_idx_activate_channel(struct qeth_channel *channel,
1375 void (*idx_reply_cb)(struct qeth_channel *,
1376 struct qeth_cmd_buffer *))
1378 struct qeth_card *card;
1379 struct qeth_cmd_buffer *iob;
1380 unsigned long flags;
1384 card = CARD_FROM_CDEV(channel->ccwdev);
1386 QETH_DBF_TEXT(setup, 2, "idxactch");
1388 iob = qeth_get_buffer(channel);
1389 iob->callback = idx_reply_cb;
1390 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1391 channel->ccw.count = IDX_ACTIVATE_SIZE;
1392 channel->ccw.cda = (__u32) __pa(iob->data);
1393 if (channel == &card->write) {
1394 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1395 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1396 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1397 card->seqno.trans_hdr++;
1399 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1400 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1401 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1403 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1404 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1405 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1406 &card->info.func_level,sizeof(__u16));
1407 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1408 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1409 temp = (card->info.cula << 8) + card->info.unit_addr2;
1410 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1412 wait_event(card->wait_q,
1413 atomic_compare_and_swap(0,1,&channel->irq_pending) == 0);
1414 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1415 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1416 rc = ccw_device_start(channel->ccwdev,
1417 &channel->ccw,(addr_t) iob, 0, 0);
1418 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1421 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1422 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1423 atomic_set(&channel->irq_pending, 0);
1424 wake_up(&card->wait_q);
1427 rc = wait_event_interruptible_timeout(card->wait_q,
1428 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1429 if (rc == -ERESTARTSYS)
1431 if (channel->state != CH_STATE_ACTIVATING) {
1432 PRINT_WARN("qeth: IDX activate timed out!\n");
1433 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1434 qeth_clear_cmd_buffers(channel);
1437 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1441 qeth_peer_func_level(int level)
1443 if ((level & 0xff) == 8)
1444 return (level & 0xff) + 0x400;
1445 if (((level >> 8) & 3) == 1)
1446 return (level & 0xff) + 0x200;
1451 qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1453 struct qeth_card *card;
1456 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1458 if (channel->state == CH_STATE_DOWN) {
1459 channel->state = CH_STATE_ACTIVATING;
1462 card = CARD_FROM_CDEV(channel->ccwdev);
1464 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1465 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1466 "reply\n", CARD_WDEV_ID(card));
1469 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1470 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1471 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1472 "function level mismatch "
1473 "(sent: 0x%x, received: 0x%x)\n",
1474 CARD_WDEV_ID(card), card->info.func_level, temp);
1477 channel->state = CH_STATE_UP;
1479 qeth_release_buffer(channel, iob);
1483 qeth_check_idx_response(unsigned char *buffer)
1488 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1489 if ((buffer[2] & 0xc0) == 0xc0) {
1490 PRINT_WARN("received an IDX TERMINATE "
1491 "with cause code 0x%02x%s\n",
1493 ((buffer[4] == 0x22) ?
1494 " -- try another portname" : ""));
1495 QETH_DBF_TEXT(trace, 2, "ckidxres");
1496 QETH_DBF_TEXT(trace, 2, " idxterm");
1497 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1504 qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1506 struct qeth_card *card;
1509 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1510 if (channel->state == CH_STATE_DOWN) {
1511 channel->state = CH_STATE_ACTIVATING;
1515 card = CARD_FROM_CDEV(channel->ccwdev);
1516 if (qeth_check_idx_response(iob->data)) {
1519 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1520 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1521 "reply\n", CARD_RDEV_ID(card));
1526 * temporary fix for microcode bug
1527 * to revert it,replace OR by AND
1529 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1530 (card->info.type == QETH_CARD_TYPE_OSAE) )
1531 card->info.portname_required = 1;
1533 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1534 if (temp != qeth_peer_func_level(card->info.func_level)) {
1535 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1536 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1537 CARD_RDEV_ID(card), card->info.func_level, temp);
1540 memcpy(&card->token.issuer_rm_r,
1541 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1542 QETH_MPC_TOKEN_LENGTH);
1543 memcpy(&card->info.mcl_level[0],
1544 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1545 channel->state = CH_STATE_UP;
1547 qeth_release_buffer(channel,iob);
1551 qeth_issue_next_read(struct qeth_card *card)
1554 struct qeth_cmd_buffer *iob;
1556 QETH_DBF_TEXT(trace,5,"issnxrd");
1557 if (card->read.state != CH_STATE_UP)
1559 iob = qeth_get_buffer(&card->read);
1561 PRINT_WARN("issue_next_read failed: no iob available!\n");
1564 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1565 wait_event(card->wait_q,
1566 atomic_compare_and_swap(0,1,&card->read.irq_pending) == 0);
1567 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1568 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1569 (addr_t) iob, 0, 0);
1571 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1572 atomic_set(&card->read.irq_pending, 0);
1573 qeth_schedule_recovery(card);
1574 wake_up(&card->wait_q);
1579 static struct qeth_reply *
1580 qeth_alloc_reply(struct qeth_card *card)
1582 struct qeth_reply *reply;
1584 reply = kmalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1586 memset(reply, 0, sizeof(struct qeth_reply));
1587 atomic_set(&reply->refcnt, 1);
1594 qeth_get_reply(struct qeth_reply *reply)
1596 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1597 atomic_inc(&reply->refcnt);
1601 qeth_put_reply(struct qeth_reply *reply)
1603 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1604 if (atomic_dec_and_test(&reply->refcnt))
1609 qeth_cmd_timeout(unsigned long data)
1611 struct qeth_reply *reply, *list_reply, *r;
1612 unsigned long flags;
1614 reply = (struct qeth_reply *) data;
1615 spin_lock_irqsave(&reply->card->lock, flags);
1616 list_for_each_entry_safe(list_reply, r,
1617 &reply->card->cmd_waiter_list, list) {
1618 if (reply == list_reply){
1619 qeth_get_reply(reply);
1620 list_del_init(&reply->list);
1621 spin_unlock_irqrestore(&reply->card->lock, flags);
1623 reply->received = 1;
1624 wake_up(&reply->wait_q);
1625 qeth_put_reply(reply);
1629 spin_unlock_irqrestore(&reply->card->lock, flags);
1632 static struct qeth_ipa_cmd *
1633 qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1635 struct qeth_ipa_cmd *cmd = NULL;
1637 QETH_DBF_TEXT(trace,5,"chkipad");
1638 if (IS_IPA(iob->data)){
1639 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1640 if (IS_IPA_REPLY(cmd))
1643 switch (cmd->hdr.command) {
1644 case IPA_CMD_STOPLAN:
1645 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1646 "there is a network problem or "
1647 "someone pulled the cable or "
1648 "disabled the port.\n",
1649 QETH_CARD_IFNAME(card),
1651 card->lan_online = 0;
1652 netif_carrier_off(card->dev);
1654 case IPA_CMD_STARTLAN:
1655 PRINT_INFO("Link reestablished on %s "
1656 "(CHPID 0x%X). Scheduling "
1657 "IP address reset.\n",
1658 QETH_CARD_IFNAME(card),
1660 netif_carrier_on(card->dev);
1661 qeth_schedule_recovery(card);
1663 case IPA_CMD_REGISTER_LOCAL_ADDR:
1664 QETH_DBF_TEXT(trace,3, "irla");
1666 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1667 QETH_DBF_TEXT(trace,3, "urla");
1670 PRINT_WARN("Received data is IPA "
1671 "but not a reply!\n");
1680 * wake all waiting ipa commands
1683 qeth_clear_ipacmd_list(struct qeth_card *card)
1685 struct qeth_reply *reply, *r;
1686 unsigned long flags;
1688 QETH_DBF_TEXT(trace, 4, "clipalst");
1690 spin_lock_irqsave(&card->lock, flags);
1691 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1692 qeth_get_reply(reply);
1694 reply->received = 1;
1695 list_del_init(&reply->list);
1696 wake_up(&reply->wait_q);
1697 qeth_put_reply(reply);
1699 spin_unlock_irqrestore(&card->lock, flags);
1703 qeth_send_control_data_cb(struct qeth_channel *channel,
1704 struct qeth_cmd_buffer *iob)
1706 struct qeth_card *card;
1707 struct qeth_reply *reply, *r;
1708 struct qeth_ipa_cmd *cmd;
1709 unsigned long flags;
1712 QETH_DBF_TEXT(trace,4,"sndctlcb");
1714 card = CARD_FROM_CDEV(channel->ccwdev);
1715 if (qeth_check_idx_response(iob->data)) {
1716 qeth_clear_ipacmd_list(card);
1717 qeth_schedule_recovery(card);
1721 cmd = qeth_check_ipa_data(card, iob);
1722 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1725 spin_lock_irqsave(&card->lock, flags);
1726 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1727 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1728 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1729 qeth_get_reply(reply);
1730 list_del_init(&reply->list);
1731 spin_unlock_irqrestore(&card->lock, flags);
1733 if (reply->callback != NULL) {
1735 reply->offset = (__u16)((char*)cmd -
1737 keep_reply = reply->callback(card,
1739 (unsigned long)cmd);
1742 keep_reply = reply->callback(card,
1744 (unsigned long)iob);
1747 reply->rc = (u16) cmd->hdr.return_code;
1749 reply->rc = iob->rc;
1751 spin_lock_irqsave(&card->lock, flags);
1752 list_add_tail(&reply->list,
1753 &card->cmd_waiter_list);
1754 spin_unlock_irqrestore(&card->lock, flags);
1756 reply->received = 1;
1757 wake_up(&reply->wait_q);
1759 qeth_put_reply(reply);
1763 spin_unlock_irqrestore(&card->lock, flags);
1765 memcpy(&card->seqno.pdu_hdr_ack,
1766 QETH_PDU_HEADER_SEQ_NO(iob->data),
1767 QETH_SEQ_NO_LENGTH);
1768 qeth_release_buffer(channel,iob);
1772 qeth_send_control_data(struct qeth_card *card, int len,
1773 struct qeth_cmd_buffer *iob,
1775 (struct qeth_card *, struct qeth_reply*, unsigned long),
1780 unsigned long flags;
1781 struct qeth_reply *reply;
1782 struct timer_list timer;
1784 QETH_DBF_TEXT(trace, 2, "sendctl");
1786 qeth_setup_ccw(&card->write,iob->data,len);
1788 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1789 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1790 card->seqno.trans_hdr++;
1792 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1793 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1794 card->seqno.pdu_hdr++;
1795 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1796 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1797 iob->callback = qeth_release_buffer;
1799 reply = qeth_alloc_reply(card);
1801 PRINT_WARN("Could no alloc qeth_reply!\n");
1804 reply->callback = reply_cb;
1805 reply->param = reply_param;
1806 if (card->state == CARD_STATE_DOWN)
1807 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1809 reply->seqno = card->seqno.ipa++;
1811 timer.function = qeth_cmd_timeout;
1812 timer.data = (unsigned long) reply;
1813 if (IS_IPA(iob->data))
1814 timer.expires = jiffies + QETH_IPA_TIMEOUT;
1816 timer.expires = jiffies + QETH_TIMEOUT;
1817 init_waitqueue_head(&reply->wait_q);
1818 spin_lock_irqsave(&card->lock, flags);
1819 list_add_tail(&reply->list, &card->cmd_waiter_list);
1820 spin_unlock_irqrestore(&card->lock, flags);
1821 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1822 wait_event(card->wait_q,
1823 atomic_compare_and_swap(0,1,&card->write.irq_pending) == 0);
1824 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1825 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1826 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1827 (addr_t) iob, 0, 0);
1828 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1830 PRINT_WARN("qeth_send_control_data: "
1831 "ccw_device_start rc = %i\n", rc);
1832 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1833 spin_lock_irqsave(&card->lock, flags);
1834 list_del_init(&reply->list);
1835 qeth_put_reply(reply);
1836 spin_unlock_irqrestore(&card->lock, flags);
1837 qeth_release_buffer(iob->channel, iob);
1838 atomic_set(&card->write.irq_pending, 0);
1839 wake_up(&card->wait_q);
1843 wait_event(reply->wait_q, reply->received);
1844 del_timer_sync(&timer);
1846 qeth_put_reply(reply);
1851 qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1853 (struct qeth_card *,struct qeth_reply*, unsigned long),
1859 QETH_DBF_TEXT(trace,4,"sendipa");
1861 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1863 if (card->options.layer2)
1864 prot_type = QETH_PROT_LAYER2;
1866 prot_type = QETH_PROT_TCPIP;
1868 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1869 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1870 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1872 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
1873 reply_cb, reply_param);
1879 qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1882 struct qeth_cmd_buffer *iob;
1884 QETH_DBF_TEXT(setup, 2, "cmenblcb");
1886 iob = (struct qeth_cmd_buffer *) data;
1887 memcpy(&card->token.cm_filter_r,
1888 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
1889 QETH_MPC_TOKEN_LENGTH);
1890 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
1895 qeth_cm_enable(struct qeth_card *card)
1898 struct qeth_cmd_buffer *iob;
1900 QETH_DBF_TEXT(setup,2,"cmenable");
1902 iob = qeth_wait_for_buffer(&card->write);
1903 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
1904 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
1905 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1906 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
1907 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
1909 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
1910 qeth_cm_enable_cb, NULL);
1915 qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
1919 struct qeth_cmd_buffer *iob;
1921 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
1923 iob = (struct qeth_cmd_buffer *) data;
1924 memcpy(&card->token.cm_connection_r,
1925 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
1926 QETH_MPC_TOKEN_LENGTH);
1927 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
1932 qeth_cm_setup(struct qeth_card *card)
1935 struct qeth_cmd_buffer *iob;
1937 QETH_DBF_TEXT(setup,2,"cmsetup");
1939 iob = qeth_wait_for_buffer(&card->write);
1940 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
1941 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
1942 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1943 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
1944 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
1945 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
1946 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
1947 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
1948 qeth_cm_setup_cb, NULL);
1954 qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1958 __u16 mtu, framesize;
1961 struct qeth_cmd_buffer *iob;
1963 QETH_DBF_TEXT(setup, 2, "ulpenacb");
1965 iob = (struct qeth_cmd_buffer *) data;
1966 memcpy(&card->token.ulp_filter_r,
1967 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
1968 QETH_MPC_TOKEN_LENGTH);
1969 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
1970 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
1971 mtu = qeth_get_mtu_outof_framesize(framesize);
1974 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
1977 card->info.max_mtu = mtu;
1978 card->info.initial_mtu = mtu;
1979 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
1981 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
1982 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
1983 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1986 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
1987 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
1989 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
1990 card->info.link_type = link_type;
1992 card->info.link_type = 0;
1993 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
1998 qeth_ulp_enable(struct qeth_card *card)
2002 struct qeth_cmd_buffer *iob;
2004 /*FIXME: trace view callbacks*/
2005 QETH_DBF_TEXT(setup,2,"ulpenabl");
2007 iob = qeth_wait_for_buffer(&card->write);
2008 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2010 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2011 (__u8) card->info.portno;
2012 if (card->options.layer2)
2013 prot_type = QETH_PROT_LAYER2;
2015 prot_type = QETH_PROT_TCPIP;
2017 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2018 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2019 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2020 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2021 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2022 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2023 card->info.portname, 9);
2024 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2025 qeth_ulp_enable_cb, NULL);
2031 __raw_devno_from_bus_id(char *id)
2033 id += (strlen(id) - 4);
2034 return (__u16) simple_strtoul(id, &id, 16);
2038 qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2041 struct qeth_cmd_buffer *iob;
2043 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2045 iob = (struct qeth_cmd_buffer *) data;
2046 memcpy(&card->token.ulp_connection_r,
2047 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2048 QETH_MPC_TOKEN_LENGTH);
2049 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2054 qeth_ulp_setup(struct qeth_card *card)
2058 struct qeth_cmd_buffer *iob;
2060 QETH_DBF_TEXT(setup,2,"ulpsetup");
2062 iob = qeth_wait_for_buffer(&card->write);
2063 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2065 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2066 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2067 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2068 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2069 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2070 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2072 temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card));
2073 memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2);
2074 temp = (card->info.cula << 8) + card->info.unit_addr2;
2075 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2076 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2077 qeth_ulp_setup_cb, NULL);
2082 qeth_check_for_inbound_error(struct qeth_qdio_buffer *buf,
2083 unsigned int qdio_error,
2084 unsigned int siga_error)
2088 if (qdio_error || siga_error) {
2089 QETH_DBF_TEXT(trace, 2, "qdinerr");
2090 QETH_DBF_TEXT(qerr, 2, "qdinerr");
2091 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
2092 buf->buffer->element[15].flags & 0xff);
2093 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
2094 buf->buffer->element[14].flags & 0xff);
2095 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2096 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
2102 static inline struct sk_buff *
2103 qeth_get_skb(unsigned int length)
2105 struct sk_buff* skb;
2106 #ifdef CONFIG_QETH_VLAN
2107 if ((skb = dev_alloc_skb(length + VLAN_HLEN)))
2108 skb_reserve(skb, VLAN_HLEN);
2110 skb = dev_alloc_skb(length);
2115 static inline struct sk_buff *
2116 qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2117 struct qdio_buffer_element **__element, int *__offset,
2118 struct qeth_hdr **hdr)
2120 struct qdio_buffer_element *element = *__element;
2121 int offset = *__offset;
2122 struct sk_buff *skb = NULL;
2127 QETH_DBF_TEXT(trace,6,"nextskb");
2128 /* qeth_hdr must not cross element boundaries */
2129 if (element->length < offset + sizeof(struct qeth_hdr)){
2130 if (qeth_is_last_sbale(element))
2134 if (element->length < sizeof(struct qeth_hdr))
2137 *hdr = element->addr + offset;
2139 offset += sizeof(struct qeth_hdr);
2140 if (card->options.layer2)
2141 skb_len = (*hdr)->hdr.l2.pkt_length;
2143 skb_len = (*hdr)->hdr.l3.length;
2147 if (card->options.fake_ll){
2148 if(card->dev->type == ARPHRD_IEEE802_TR){
2149 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR)))
2151 skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2153 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH)))
2155 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2157 } else if (!(skb = qeth_get_skb(skb_len)))
2159 data_ptr = element->addr + offset;
2161 data_len = min(skb_len, (int)(element->length - offset));
2163 memcpy(skb_put(skb, data_len), data_ptr, data_len);
2164 skb_len -= data_len;
2166 if (qeth_is_last_sbale(element)){
2167 QETH_DBF_TEXT(trace,4,"unexeob");
2168 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2169 QETH_DBF_TEXT(qerr,2,"unexeob");
2170 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2171 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2172 dev_kfree_skb_any(skb);
2173 card->stats.rx_errors++;
2178 data_ptr = element->addr;
2183 *__element = element;
2187 if (net_ratelimit()){
2188 PRINT_WARN("No memory for packet received on %s.\n",
2189 QETH_CARD_IFNAME(card));
2190 QETH_DBF_TEXT(trace,2,"noskbmem");
2191 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2193 card->stats.rx_dropped++;
2197 static inline __be16
2198 qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2200 struct qeth_card *card;
2203 QETH_DBF_TEXT(trace,6,"typtrans");
2205 card = (struct qeth_card *)dev->priv;
2207 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2208 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2209 return tr_type_trans(skb,dev);
2210 #endif /* CONFIG_TR */
2211 skb->mac.raw = skb->data;
2212 skb_pull(skb, ETH_HLEN );
2215 if (*eth->h_dest & 1) {
2216 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2217 skb->pkt_type = PACKET_BROADCAST;
2219 skb->pkt_type = PACKET_MULTICAST;
2220 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2221 skb->pkt_type = PACKET_OTHERHOST;
2223 if (ntohs(eth->h_proto) >= 1536)
2224 return eth->h_proto;
2225 if (*(unsigned short *) (skb->data) == 0xFFFF)
2226 return htons(ETH_P_802_3);
2227 return htons(ETH_P_802_2);
2231 qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2232 struct qeth_hdr *hdr)
2234 struct trh_hdr *fake_hdr;
2235 struct trllc *fake_llc;
2236 struct iphdr *ip_hdr;
2238 QETH_DBF_TEXT(trace,5,"skbfktr");
2239 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_TR;
2240 /* this is a fake ethernet header */
2241 fake_hdr = (struct trh_hdr *) skb->mac.raw;
2243 /* the destination MAC address */
2244 switch (skb->pkt_type){
2245 case PACKET_MULTICAST:
2246 switch (skb->protocol){
2247 #ifdef CONFIG_QETH_IPV6
2248 case __constant_htons(ETH_P_IPV6):
2249 ndisc_mc_map((struct in6_addr *)
2250 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2251 fake_hdr->daddr, card->dev, 0);
2253 #endif /* CONFIG_QETH_IPV6 */
2254 case __constant_htons(ETH_P_IP):
2255 ip_hdr = (struct iphdr *)skb->data;
2256 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2259 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2262 case PACKET_BROADCAST:
2263 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2266 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2268 /* the source MAC address */
2269 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2270 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2272 memset(fake_hdr->saddr, 0, TR_ALEN);
2274 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2275 fake_llc->dsap = EXTENDED_SAP;
2276 fake_llc->ssap = EXTENDED_SAP;
2277 fake_llc->llc = UI_CMD;
2278 fake_llc->protid[0] = 0;
2279 fake_llc->protid[1] = 0;
2280 fake_llc->protid[2] = 0;
2281 fake_llc->ethertype = ETH_P_IP;
2285 qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
2286 struct qeth_hdr *hdr)
2288 struct ethhdr *fake_hdr;
2289 struct iphdr *ip_hdr;
2291 QETH_DBF_TEXT(trace,5,"skbfketh");
2292 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_ETH;
2293 /* this is a fake ethernet header */
2294 fake_hdr = (struct ethhdr *) skb->mac.raw;
2296 /* the destination MAC address */
2297 switch (skb->pkt_type){
2298 case PACKET_MULTICAST:
2299 switch (skb->protocol){
2300 #ifdef CONFIG_QETH_IPV6
2301 case __constant_htons(ETH_P_IPV6):
2302 ndisc_mc_map((struct in6_addr *)
2303 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2304 fake_hdr->h_dest, card->dev, 0);
2306 #endif /* CONFIG_QETH_IPV6 */
2307 case __constant_htons(ETH_P_IP):
2308 ip_hdr = (struct iphdr *)skb->data;
2309 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
2312 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2315 case PACKET_BROADCAST:
2316 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2319 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2321 /* the source MAC address */
2322 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2323 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2325 memset(fake_hdr->h_source, 0, ETH_ALEN);
2327 fake_hdr->h_proto = skb->protocol;
2331 qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2332 struct qeth_hdr *hdr)
2334 if (card->dev->type == ARPHRD_IEEE802_TR)
2335 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2337 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2341 qeth_rebuild_skb_vlan(struct qeth_card *card, struct sk_buff *skb,
2342 struct qeth_hdr *hdr)
2344 #ifdef CONFIG_QETH_VLAN
2347 if (hdr->hdr.l3.ext_flags &
2348 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2349 vlan_tag = (u16 *) skb_push(skb, VLAN_HLEN);
2350 *vlan_tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2351 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2352 *(vlan_tag + 1) = skb->protocol;
2353 skb->protocol = __constant_htons(ETH_P_8021Q);
2355 #endif /* CONFIG_QETH_VLAN */
2359 qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2360 struct qeth_hdr *hdr)
2362 unsigned short vlan_id = 0;
2363 #ifdef CONFIG_QETH_VLAN
2364 struct vlan_hdr *vhdr;
2367 skb->pkt_type = PACKET_HOST;
2368 skb->protocol = qeth_type_trans(skb, skb->dev);
2369 if (card->options.checksum_type == NO_CHECKSUMMING)
2370 skb->ip_summed = CHECKSUM_UNNECESSARY;
2372 skb->ip_summed = CHECKSUM_NONE;
2373 #ifdef CONFIG_QETH_VLAN
2374 if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) {
2375 vhdr = (struct vlan_hdr *) skb->data;
2377 __constant_htons(vhdr->h_vlan_encapsulated_proto);
2378 vlan_id = hdr->hdr.l2.vlan_id;
2379 skb_pull(skb, VLAN_HLEN);
2382 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
2387 qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2388 struct qeth_hdr *hdr)
2390 #ifdef CONFIG_QETH_IPV6
2391 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2392 skb->pkt_type = PACKET_HOST;
2393 skb->protocol = qeth_type_trans(skb, card->dev);
2396 #endif /* CONFIG_QETH_IPV6 */
2397 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2399 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2400 case QETH_CAST_UNICAST:
2401 skb->pkt_type = PACKET_HOST;
2403 case QETH_CAST_MULTICAST:
2404 skb->pkt_type = PACKET_MULTICAST;
2405 card->stats.multicast++;
2407 case QETH_CAST_BROADCAST:
2408 skb->pkt_type = PACKET_BROADCAST;
2409 card->stats.multicast++;
2411 case QETH_CAST_ANYCAST:
2412 case QETH_CAST_NOCAST:
2414 skb->pkt_type = PACKET_HOST;
2416 qeth_rebuild_skb_vlan(card, skb, hdr);
2417 if (card->options.fake_ll)
2418 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2420 skb->mac.raw = skb->data;
2421 skb->ip_summed = card->options.checksum_type;
2422 if (card->options.checksum_type == HW_CHECKSUMMING){
2423 if ( (hdr->hdr.l3.ext_flags &
2424 (QETH_HDR_EXT_CSUM_HDR_REQ |
2425 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2426 (QETH_HDR_EXT_CSUM_HDR_REQ |
2427 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2428 skb->ip_summed = CHECKSUM_UNNECESSARY;
2430 skb->ip_summed = SW_CHECKSUMMING;
2435 qeth_process_inbound_buffer(struct qeth_card *card,
2436 struct qeth_qdio_buffer *buf, int index)
2438 struct qdio_buffer_element *element;
2439 struct sk_buff *skb;
2440 struct qeth_hdr *hdr;
2445 /* get first element of current buffer */
2446 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2448 #ifdef CONFIG_QETH_PERF_STATS
2449 card->perf_stats.bufs_rec++;
2451 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2453 skb->dev = card->dev;
2454 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2455 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr);
2457 qeth_rebuild_skb(card, skb, hdr);
2458 /* is device UP ? */
2459 if (!(card->dev->flags & IFF_UP)){
2460 dev_kfree_skb_any(skb);
2463 #ifdef CONFIG_QETH_VLAN
2465 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2468 rxrc = netif_rx(skb);
2469 card->dev->last_rx = jiffies;
2470 card->stats.rx_packets++;
2471 card->stats.rx_bytes += skb->len;
2475 static inline struct qeth_buffer_pool_entry *
2476 qeth_get_buffer_pool_entry(struct qeth_card *card)
2478 struct qeth_buffer_pool_entry *entry;
2480 QETH_DBF_TEXT(trace, 6, "gtbfplen");
2481 if (!list_empty(&card->qdio.in_buf_pool.entry_list)) {
2482 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2483 struct qeth_buffer_pool_entry, list);
2484 list_del_init(&entry->list);
2491 qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2493 struct qeth_buffer_pool_entry *pool_entry;
2496 pool_entry = qeth_get_buffer_pool_entry(card);
2498 * since the buffer is accessed only from the input_tasklet
2499 * there shouldn't be a need to synchronize; also, since we use
2500 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2503 BUG_ON(!pool_entry);
2505 buf->pool_entry = pool_entry;
2506 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2507 buf->buffer->element[i].length = PAGE_SIZE;
2508 buf->buffer->element[i].addr = pool_entry->elements[i];
2509 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2510 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2512 buf->buffer->element[i].flags = 0;
2514 buf->state = QETH_QDIO_BUF_EMPTY;
2518 qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2519 struct qeth_qdio_out_buffer *buf)
2522 struct sk_buff *skb;
2524 /* is PCI flag set on buffer? */
2525 if (buf->buffer->element[0].flags & 0x40)
2526 atomic_dec(&queue->set_pci_flags_count);
2528 while ((skb = skb_dequeue(&buf->skb_list))){
2529 atomic_dec(&skb->users);
2530 dev_kfree_skb_any(skb);
2532 qeth_eddp_buf_release_contexts(buf);
2533 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2534 buf->buffer->element[i].length = 0;
2535 buf->buffer->element[i].addr = NULL;
2536 buf->buffer->element[i].flags = 0;
2538 buf->next_element_to_fill = 0;
2539 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2543 qeth_queue_input_buffer(struct qeth_card *card, int index)
2545 struct qeth_qdio_q *queue = card->qdio.in_q;
2550 QETH_DBF_TEXT(trace,6,"queinbuf");
2551 count = (index < queue->next_buf_to_init)?
2552 card->qdio.in_buf_pool.buf_count -
2553 (queue->next_buf_to_init - index) :
2554 card->qdio.in_buf_pool.buf_count -
2555 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2556 /* only requeue at a certain threshold to avoid SIGAs */
2557 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2558 for (i = queue->next_buf_to_init;
2559 i < queue->next_buf_to_init + count; ++i)
2560 qeth_init_input_buffer(card,
2561 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]);
2563 * according to old code it should be avoided to requeue all
2564 * 128 buffers in order to benefit from PCI avoidance.
2565 * this function keeps at least one buffer (the buffer at
2566 * 'index') un-requeued -> this buffer is the first buffer that
2567 * will be requeued the next time
2569 #ifdef CONFIG_QETH_PERF_STATS
2570 card->perf_stats.inbound_do_qdio_cnt++;
2571 card->perf_stats.inbound_do_qdio_start_time = qeth_get_micros();
2573 rc = do_QDIO(CARD_DDEV(card),
2574 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2575 0, queue->next_buf_to_init, count, NULL);
2576 #ifdef CONFIG_QETH_PERF_STATS
2577 card->perf_stats.inbound_do_qdio_time += qeth_get_micros() -
2578 card->perf_stats.inbound_do_qdio_start_time;
2581 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2582 "return %i (device %s).\n",
2583 rc, CARD_DDEV_ID(card));
2584 QETH_DBF_TEXT(trace,2,"qinberr");
2585 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2587 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2588 QDIO_MAX_BUFFERS_PER_Q;
2593 qeth_put_buffer_pool_entry(struct qeth_card *card,
2594 struct qeth_buffer_pool_entry *entry)
2596 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2597 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2601 qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2602 unsigned int qdio_err, unsigned int siga_err,
2603 unsigned int queue, int first_element, int count,
2604 unsigned long card_ptr)
2606 struct net_device *net_dev;
2607 struct qeth_card *card;
2608 struct qeth_qdio_buffer *buffer;
2612 QETH_DBF_TEXT(trace, 6, "qdinput");
2613 card = (struct qeth_card *) card_ptr;
2614 net_dev = card->dev;
2615 #ifdef CONFIG_QETH_PERF_STATS
2616 card->perf_stats.inbound_cnt++;
2617 card->perf_stats.inbound_start_time = qeth_get_micros();
2619 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2620 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2621 QETH_DBF_TEXT(trace, 1,"qdinchk");
2622 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2623 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2624 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2625 qeth_schedule_recovery(card);
2629 for (i = first_element; i < (first_element + count); ++i) {
2630 index = i % QDIO_MAX_BUFFERS_PER_Q;
2631 buffer = &card->qdio.in_q->bufs[index];
2632 if (!((status == QDIO_STATUS_LOOK_FOR_ERROR) &&
2633 qeth_check_for_inbound_error(buffer, qdio_err, siga_err)))
2634 qeth_process_inbound_buffer(card, buffer, index);
2635 /* clear buffer and give back to hardware */
2636 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2637 qeth_queue_input_buffer(card, index);
2639 #ifdef CONFIG_QETH_PERF_STATS
2640 card->perf_stats.inbound_time += qeth_get_micros() -
2641 card->perf_stats.inbound_start_time;
2646 qeth_handle_send_error(struct qeth_card *card,
2647 struct qeth_qdio_out_buffer *buffer,
2648 int qdio_err, int siga_err)
2650 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2651 int cc = siga_err & 3;
2653 QETH_DBF_TEXT(trace, 6, "hdsnderr");
2657 QETH_DBF_TEXT(trace, 1,"lnkfail");
2658 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2659 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2660 (u16)qdio_err, (u8)sbalf15);
2661 return QETH_SEND_ERROR_LINK_FAILURE;
2663 return QETH_SEND_ERROR_NONE;
2665 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2666 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2667 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2668 return QETH_SEND_ERROR_KICK_IT;
2670 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2671 return QETH_SEND_ERROR_RETRY;
2672 return QETH_SEND_ERROR_LINK_FAILURE;
2673 /* look at qdio_error and sbalf 15 */
2675 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2676 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2677 return QETH_SEND_ERROR_LINK_FAILURE;
2679 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2680 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2681 return QETH_SEND_ERROR_KICK_IT;
2683 return QETH_SEND_ERROR_LINK_FAILURE;
2687 qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2688 int index, int count)
2690 struct qeth_qdio_out_buffer *buf;
2694 QETH_DBF_TEXT(trace, 6, "flushbuf");
2696 for (i = index; i < index + count; ++i) {
2697 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2698 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2699 SBAL_FLAGS_LAST_ENTRY;
2701 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2704 if (!queue->do_pack){
2705 if ((atomic_read(&queue->used_buffers) >=
2706 (QETH_HIGH_WATERMARK_PACK -
2707 QETH_WATERMARK_PACK_FUZZ)) &&
2708 !atomic_read(&queue->set_pci_flags_count)){
2709 /* it's likely that we'll go to packing
2711 atomic_inc(&queue->set_pci_flags_count);
2712 buf->buffer->element[0].flags |= 0x40;
2715 if (!atomic_read(&queue->set_pci_flags_count)){
2717 * there's no outstanding PCI any more, so we
2718 * have to request a PCI to be sure the the PCI
2719 * will wake at some time in the future then we
2720 * can flush packed buffers that might still be
2721 * hanging around, which can happen if no
2722 * further send was requested by the stack
2724 atomic_inc(&queue->set_pci_flags_count);
2725 buf->buffer->element[0].flags |= 0x40;
2730 queue->card->dev->trans_start = jiffies;
2731 #ifdef CONFIG_QETH_PERF_STATS
2732 queue->card->perf_stats.outbound_do_qdio_cnt++;
2733 queue->card->perf_stats.outbound_do_qdio_start_time = qeth_get_micros();
2736 rc = do_QDIO(CARD_DDEV(queue->card),
2737 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT,
2738 queue->queue_no, index, count, NULL);
2740 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT,
2741 queue->queue_no, index, count, NULL);
2742 #ifdef CONFIG_QETH_PERF_STATS
2743 queue->card->perf_stats.outbound_do_qdio_time += qeth_get_micros() -
2744 queue->card->perf_stats.outbound_do_qdio_start_time;
2747 QETH_DBF_TEXT(trace, 2, "flushbuf");
2748 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
2749 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
2750 queue->card->stats.tx_errors += count;
2751 /* this must not happen under normal circumstances. if it
2752 * happens something is really wrong -> recover */
2753 qeth_schedule_recovery(queue->card);
2756 atomic_add(count, &queue->used_buffers);
2757 #ifdef CONFIG_QETH_PERF_STATS
2758 queue->card->perf_stats.bufs_sent += count;
2763 * Switched to packing state if the number of used buffers on a queue
2764 * reaches a certain limit.
2767 qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2769 if (!queue->do_pack) {
2770 if (atomic_read(&queue->used_buffers)
2771 >= QETH_HIGH_WATERMARK_PACK){
2772 /* switch non-PACKING -> PACKING */
2773 QETH_DBF_TEXT(trace, 6, "np->pack");
2774 #ifdef CONFIG_QETH_PERF_STATS
2775 queue->card->perf_stats.sc_dp_p++;
2783 * Switches from packing to non-packing mode. If there is a packing
2784 * buffer on the queue this buffer will be prepared to be flushed.
2785 * In that case 1 is returned to inform the caller. If no buffer
2786 * has to be flushed, zero is returned.
2789 qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2791 struct qeth_qdio_out_buffer *buffer;
2792 int flush_count = 0;
2794 if (queue->do_pack) {
2795 if (atomic_read(&queue->used_buffers)
2796 <= QETH_LOW_WATERMARK_PACK) {
2797 /* switch PACKING -> non-PACKING */
2798 QETH_DBF_TEXT(trace, 6, "pack->np");
2799 #ifdef CONFIG_QETH_PERF_STATS
2800 queue->card->perf_stats.sc_p_dp++;
2803 /* flush packing buffers */
2804 buffer = &queue->bufs[queue->next_buf_to_fill];
2805 if ((atomic_read(&buffer->state) ==
2806 QETH_QDIO_BUF_EMPTY) &&
2807 (buffer->next_element_to_fill > 0)) {
2808 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
2810 queue->next_buf_to_fill =
2811 (queue->next_buf_to_fill + 1) %
2812 QDIO_MAX_BUFFERS_PER_Q;
2820 * Called to flush a packing buffer if no more pci flags are on the queue.
2821 * Checks if there is a packing buffer and prepares it to be flushed.
2822 * In that case returns 1, otherwise zero.
2825 qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2827 struct qeth_qdio_out_buffer *buffer;
2829 buffer = &queue->bufs[queue->next_buf_to_fill];
2830 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2831 (buffer->next_element_to_fill > 0)){
2832 /* it's a packing buffer */
2833 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2834 queue->next_buf_to_fill =
2835 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2842 qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2846 int q_was_packing = 0;
2849 * check if weed have to switch to non-packing mode or if
2850 * we have to get a pci flag out on the queue
2852 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2853 !atomic_read(&queue->set_pci_flags_count)){
2854 if (atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2855 QETH_OUT_Q_UNLOCKED) {
2857 * If we get in here, there was no action in
2858 * do_send_packet. So, we check if there is a
2859 * packing buffer to be flushed here.
2861 netif_stop_queue(queue->card->dev);
2862 index = queue->next_buf_to_fill;
2863 q_was_packing = queue->do_pack;
2864 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
2866 !atomic_read(&queue->set_pci_flags_count))
2868 qeth_flush_buffers_on_no_pci(queue);
2869 #ifdef CONFIG_QETH_PERF_STATS
2871 queue->card->perf_stats.bufs_sent_pack +=
2875 qeth_flush_buffers(queue, 1, index, flush_cnt);
2876 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
2882 qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
2883 unsigned int qdio_error, unsigned int siga_error,
2884 unsigned int __queue, int first_element, int count,
2885 unsigned long card_ptr)
2887 struct qeth_card *card = (struct qeth_card *) card_ptr;
2888 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
2889 struct qeth_qdio_out_buffer *buffer;
2892 QETH_DBF_TEXT(trace, 6, "qdouhdl");
2893 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2894 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2895 QETH_DBF_TEXT(trace, 2, "achkcond");
2896 QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
2897 QETH_DBF_TEXT_(trace, 2, "%08x", status);
2898 netif_stop_queue(card->dev);
2899 qeth_schedule_recovery(card);
2903 #ifdef CONFIG_QETH_PERF_STATS
2904 card->perf_stats.outbound_handler_cnt++;
2905 card->perf_stats.outbound_handler_start_time = qeth_get_micros();
2907 for(i = first_element; i < (first_element + count); ++i){
2908 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2909 /*we only handle the KICK_IT error by doing a recovery */
2910 if (qeth_handle_send_error(card, buffer, qdio_error, siga_error)
2911 == QETH_SEND_ERROR_KICK_IT){
2912 netif_stop_queue(card->dev);
2913 qeth_schedule_recovery(card);
2916 qeth_clear_output_buffer(queue, buffer);
2918 atomic_sub(count, &queue->used_buffers);
2919 /* check if we need to do something on this outbound queue */
2920 if (card->info.type != QETH_CARD_TYPE_IQD)
2921 qeth_check_outbound_queue(queue);
2923 netif_wake_queue(queue->card->dev);
2924 #ifdef CONFIG_QETH_PERF_STATS
2925 card->perf_stats.outbound_handler_time += qeth_get_micros() -
2926 card->perf_stats.outbound_handler_start_time;
2931 qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
2934 param_field[0] = _ascebc['P'];
2935 param_field[1] = _ascebc['C'];
2936 param_field[2] = _ascebc['I'];
2937 param_field[3] = _ascebc['T'];
2938 *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card);
2939 *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card);
2940 *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card);
2944 qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
2946 param_field[16] = _ascebc['B'];
2947 param_field[17] = _ascebc['L'];
2948 param_field[18] = _ascebc['K'];
2949 param_field[19] = _ascebc['T'];
2950 *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total;
2951 *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet;
2952 *((unsigned int *) (¶m_field[28])) = card->info.blkt.inter_packet_jumbo;
2956 qeth_initialize_working_pool_list(struct qeth_card *card)
2958 struct qeth_buffer_pool_entry *entry;
2960 QETH_DBF_TEXT(trace,5,"inwrklst");
2962 list_for_each_entry(entry,
2963 &card->qdio.init_pool.entry_list, init_list) {
2964 qeth_put_buffer_pool_entry(card,entry);
2969 qeth_clear_working_pool_list(struct qeth_card *card)
2971 struct qeth_buffer_pool_entry *pool_entry, *tmp;
2973 QETH_DBF_TEXT(trace,5,"clwrklst");
2974 list_for_each_entry_safe(pool_entry, tmp,
2975 &card->qdio.in_buf_pool.entry_list, list){
2976 list_del(&pool_entry->list);
2981 qeth_free_buffer_pool(struct qeth_card *card)
2983 struct qeth_buffer_pool_entry *pool_entry, *tmp;
2985 QETH_DBF_TEXT(trace,5,"freepool");
2986 list_for_each_entry_safe(pool_entry, tmp,
2987 &card->qdio.init_pool.entry_list, init_list){
2988 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
2989 free_page((unsigned long)pool_entry->elements[i]);
2990 list_del(&pool_entry->init_list);
2996 qeth_alloc_buffer_pool(struct qeth_card *card)
2998 struct qeth_buffer_pool_entry *pool_entry;
3002 QETH_DBF_TEXT(trace,5,"alocpool");
3003 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3004 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3006 qeth_free_buffer_pool(card);
3009 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
3010 ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
3013 free_page((unsigned long)
3014 pool_entry->elements[--j]);
3016 qeth_free_buffer_pool(card);
3019 pool_entry->elements[j] = ptr;
3021 list_add(&pool_entry->init_list,
3022 &card->qdio.init_pool.entry_list);
3028 qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3030 QETH_DBF_TEXT(trace, 2, "realcbp");
3032 if ((card->state != CARD_STATE_DOWN) &&
3033 (card->state != CARD_STATE_RECOVER))
3036 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3037 qeth_clear_working_pool_list(card);
3038 qeth_free_buffer_pool(card);
3039 card->qdio.in_buf_pool.buf_count = bufcnt;
3040 card->qdio.init_pool.buf_count = bufcnt;
3041 return qeth_alloc_buffer_pool(card);
3045 qeth_alloc_qdio_buffers(struct qeth_card *card)
3049 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3051 if (card->qdio.state == QETH_QDIO_ALLOCATED)
3054 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3055 GFP_KERNEL|GFP_DMA);
3056 if (!card->qdio.in_q)
3058 QETH_DBF_TEXT(setup, 2, "inq");
3059 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3060 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3061 /* give inbound qeth_qdio_buffers their qdio_buffers */
3062 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3063 card->qdio.in_q->bufs[i].buffer =
3064 &card->qdio.in_q->qdio_bufs[i];
3065 /* inbound buffer pool */
3066 if (qeth_alloc_buffer_pool(card)){
3067 kfree(card->qdio.in_q);
3072 kmalloc(card->qdio.no_out_queues *
3073 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3074 if (!card->qdio.out_qs){
3075 qeth_free_buffer_pool(card);
3078 for (i = 0; i < card->qdio.no_out_queues; ++i){
3079 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3080 GFP_KERNEL|GFP_DMA);
3081 if (!card->qdio.out_qs[i]){
3083 kfree(card->qdio.out_qs[--i]);
3084 kfree(card->qdio.out_qs);
3087 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3088 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3089 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3090 card->qdio.out_qs[i]->queue_no = i;
3091 /* give outbound qeth_qdio_buffers their qdio_buffers */
3092 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3093 card->qdio.out_qs[i]->bufs[j].buffer =
3094 &card->qdio.out_qs[i]->qdio_bufs[j];
3095 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3097 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3100 card->qdio.state = QETH_QDIO_ALLOCATED;
3105 qeth_free_qdio_buffers(struct qeth_card *card)
3109 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3110 if (card->qdio.state == QETH_QDIO_UNINITIALIZED)
3112 kfree(card->qdio.in_q);
3113 /* inbound buffer pool */
3114 qeth_free_buffer_pool(card);
3115 /* free outbound qdio_qs */
3116 for (i = 0; i < card->qdio.no_out_queues; ++i){
3117 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3118 qeth_clear_output_buffer(card->qdio.out_qs[i],
3119 &card->qdio.out_qs[i]->bufs[j]);
3120 kfree(card->qdio.out_qs[i]);
3122 kfree(card->qdio.out_qs);
3123 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3127 qeth_clear_qdio_buffers(struct qeth_card *card)
3131 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3132 /* clear outbound buffers to free skbs */
3133 for (i = 0; i < card->qdio.no_out_queues; ++i)
3134 if (card->qdio.out_qs[i]){
3135 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3136 qeth_clear_output_buffer(card->qdio.out_qs[i],
3137 &card->qdio.out_qs[i]->bufs[j]);
3142 qeth_init_qdio_info(struct qeth_card *card)
3144 QETH_DBF_TEXT(setup, 4, "intqdinf");
3145 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3147 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3148 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3149 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3150 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3151 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3153 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
3154 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
3158 qeth_init_qdio_queues(struct qeth_card *card)
3163 QETH_DBF_TEXT(setup, 2, "initqdqs");
3166 memset(card->qdio.in_q->qdio_bufs, 0,
3167 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3168 qeth_initialize_working_pool_list(card);
3169 /*give only as many buffers to hardware as we have buffer pool entries*/
3170 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3171 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3172 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3173 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3174 card->qdio.in_buf_pool.buf_count - 1, NULL);
3176 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3179 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3181 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3184 /* outbound queue */
3185 for (i = 0; i < card->qdio.no_out_queues; ++i){
3186 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3187 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3188 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3189 qeth_clear_output_buffer(card->qdio.out_qs[i],
3190 &card->qdio.out_qs[i]->bufs[j]);
3192 card->qdio.out_qs[i]->card = card;
3193 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3194 card->qdio.out_qs[i]->do_pack = 0;
3195 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3196 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3197 atomic_set(&card->qdio.out_qs[i]->state,
3198 QETH_OUT_Q_UNLOCKED);
3204 qeth_qdio_establish(struct qeth_card *card)
3206 struct qdio_initialize init_data;
3207 char *qib_param_field;
3208 struct qdio_buffer **in_sbal_ptrs;
3209 struct qdio_buffer **out_sbal_ptrs;
3213 QETH_DBF_TEXT(setup, 2, "qdioest");
3215 qib_param_field = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3217 if (!qib_param_field)
3220 memset(qib_param_field, 0, QDIO_MAX_BUFFERS_PER_Q * sizeof(char));
3222 qeth_create_qib_param_field(card, qib_param_field);
3223 qeth_create_qib_param_field_blkt(card, qib_param_field);
3225 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3227 if (!in_sbal_ptrs) {
3228 kfree(qib_param_field);
3231 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3232 in_sbal_ptrs[i] = (struct qdio_buffer *)
3233 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3236 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3237 sizeof(void *), GFP_KERNEL);
3238 if (!out_sbal_ptrs) {
3239 kfree(in_sbal_ptrs);
3240 kfree(qib_param_field);
3243 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3244 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3245 out_sbal_ptrs[k] = (struct qdio_buffer *)
3246 virt_to_phys(card->qdio.out_qs[i]->
3250 memset(&init_data, 0, sizeof(struct qdio_initialize));
3251 init_data.cdev = CARD_DDEV(card);
3252 init_data.q_format = qeth_get_qdio_q_format(card);
3253 init_data.qib_param_field_format = 0;
3254 init_data.qib_param_field = qib_param_field;
3255 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3256 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3257 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3258 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3259 init_data.no_input_qs = 1;
3260 init_data.no_output_qs = card->qdio.no_out_queues;
3261 init_data.input_handler = (qdio_handler_t *)
3262 qeth_qdio_input_handler;
3263 init_data.output_handler = (qdio_handler_t *)
3264 qeth_qdio_output_handler;
3265 init_data.int_parm = (unsigned long) card;
3266 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3267 QDIO_OUTBOUND_0COPY_SBALS |
3268 QDIO_USE_OUTBOUND_PCIS;
3269 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3270 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3272 if (!(rc = qdio_initialize(&init_data)))
3273 card->qdio.state = QETH_QDIO_ESTABLISHED;
3275 kfree(out_sbal_ptrs);
3276 kfree(in_sbal_ptrs);
3277 kfree(qib_param_field);
3282 qeth_qdio_activate(struct qeth_card *card)
3284 QETH_DBF_TEXT(setup,3,"qdioact");
3285 return qdio_activate(CARD_DDEV(card), 0);
3289 qeth_clear_channel(struct qeth_channel *channel)
3291 unsigned long flags;
3292 struct qeth_card *card;
3295 QETH_DBF_TEXT(trace,3,"clearch");
3296 card = CARD_FROM_CDEV(channel->ccwdev);
3297 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3298 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3299 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3303 rc = wait_event_interruptible_timeout(card->wait_q,
3304 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3305 if (rc == -ERESTARTSYS)
3307 if (channel->state != CH_STATE_STOPPED)
3309 channel->state = CH_STATE_DOWN;
3314 qeth_halt_channel(struct qeth_channel *channel)
3316 unsigned long flags;
3317 struct qeth_card *card;
3320 QETH_DBF_TEXT(trace,3,"haltch");
3321 card = CARD_FROM_CDEV(channel->ccwdev);
3322 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3323 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3324 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3328 rc = wait_event_interruptible_timeout(card->wait_q,
3329 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3330 if (rc == -ERESTARTSYS)
3332 if (channel->state != CH_STATE_HALTED)
3338 qeth_halt_channels(struct qeth_card *card)
3340 int rc1 = 0, rc2=0, rc3 = 0;
3342 QETH_DBF_TEXT(trace,3,"haltchs");
3343 rc1 = qeth_halt_channel(&card->read);
3344 rc2 = qeth_halt_channel(&card->write);
3345 rc3 = qeth_halt_channel(&card->data);
3353 qeth_clear_channels(struct qeth_card *card)
3355 int rc1 = 0, rc2=0, rc3 = 0;
3357 QETH_DBF_TEXT(trace,3,"clearchs");
3358 rc1 = qeth_clear_channel(&card->read);
3359 rc2 = qeth_clear_channel(&card->write);
3360 rc3 = qeth_clear_channel(&card->data);
3369 qeth_clear_halt_card(struct qeth_card *card, int halt)
3373 QETH_DBF_TEXT(trace,3,"clhacrd");
3374 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3377 rc = qeth_halt_channels(card);
3380 return qeth_clear_channels(card);
3384 qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3388 QETH_DBF_TEXT(trace,3,"qdioclr");
3389 if (card->qdio.state == QETH_QDIO_ESTABLISHED){
3390 if ((rc = qdio_cleanup(CARD_DDEV(card),
3391 (card->info.type == QETH_CARD_TYPE_IQD) ?
3392 QDIO_FLAG_CLEANUP_USING_HALT :
3393 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3394 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3395 card->qdio.state = QETH_QDIO_ALLOCATED;
3397 if ((rc = qeth_clear_halt_card(card, use_halt)))
3398 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3399 card->state = CARD_STATE_DOWN;
3404 qeth_dm_act(struct qeth_card *card)
3407 struct qeth_cmd_buffer *iob;
3409 QETH_DBF_TEXT(setup,2,"dmact");
3411 iob = qeth_wait_for_buffer(&card->write);
3412 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3414 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3415 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3416 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3417 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3418 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3423 qeth_mpc_initialize(struct qeth_card *card)
3427 QETH_DBF_TEXT(setup,2,"mpcinit");
3429 if ((rc = qeth_issue_next_read(card))){
3430 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3433 if ((rc = qeth_cm_enable(card))){
3434 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3437 if ((rc = qeth_cm_setup(card))){
3438 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
3441 if ((rc = qeth_ulp_enable(card))){
3442 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
3445 if ((rc = qeth_ulp_setup(card))){
3446 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3449 if ((rc = qeth_alloc_qdio_buffers(card))){
3450 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
3453 if ((rc = qeth_qdio_establish(card))){
3454 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3455 qeth_free_qdio_buffers(card);
3458 if ((rc = qeth_qdio_activate(card))){
3459 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3462 if ((rc = qeth_dm_act(card))){
3463 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3469 qeth_qdio_clear_card(card, card->info.type==QETH_CARD_TYPE_OSAE);
3473 static struct net_device *
3474 qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3476 struct net_device *dev = NULL;
3479 case QETH_CARD_TYPE_OSAE:
3481 case QETH_LINK_TYPE_LANE_TR:
3482 case QETH_LINK_TYPE_HSTR:
3484 dev = alloc_trdev(0);
3485 #endif /* CONFIG_TR */
3488 dev = alloc_etherdev(0);
3491 case QETH_CARD_TYPE_IQD:
3492 dev = alloc_netdev(0, "hsi%d", ether_setup);
3495 dev = alloc_etherdev(0);
3500 /*hard_header fake function; used in case fake_ll is set */
3502 qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3503 unsigned short type, void *daddr, void *saddr,
3506 if(dev->type == ARPHRD_IEEE802_TR){
3507 struct trh_hdr *hdr;
3508 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3509 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3510 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3511 return QETH_FAKE_LL_LEN_TR;
3515 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3516 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3517 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3518 if (type != ETH_P_802_3)
3519 hdr->h_proto = htons(type);
3521 hdr->h_proto = htons(len);
3522 return QETH_FAKE_LL_LEN_ETH;
3528 qeth_send_packet(struct qeth_card *, struct sk_buff *);
3531 qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3534 struct qeth_card *card;
3536 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3537 card = (struct qeth_card *)dev->priv;
3539 card->stats.tx_dropped++;
3540 card->stats.tx_errors++;
3541 /* return OK; otherwise ksoftirqd goes to 100% */
3542 return NETDEV_TX_OK;
3544 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3545 card->stats.tx_dropped++;
3546 card->stats.tx_errors++;
3547 card->stats.tx_carrier_errors++;
3548 dev_kfree_skb_any(skb);
3549 /* return OK; otherwise ksoftirqd goes to 100% */
3550 return NETDEV_TX_OK;
3552 #ifdef CONFIG_QETH_PERF_STATS
3553 card->perf_stats.outbound_cnt++;
3554 card->perf_stats.outbound_start_time = qeth_get_micros();
3556 netif_stop_queue(dev);
3557 if ((rc = qeth_send_packet(card, skb))) {
3559 return NETDEV_TX_BUSY;
3561 card->stats.tx_errors++;
3562 card->stats.tx_dropped++;
3563 dev_kfree_skb_any(skb);
3564 /*set to OK; otherwise ksoftirqd goes to 100% */
3568 netif_wake_queue(dev);
3569 #ifdef CONFIG_QETH_PERF_STATS
3570 card->perf_stats.outbound_time += qeth_get_micros() -
3571 card->perf_stats.outbound_start_time;
3577 qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3580 #ifdef CONFIG_QETH_VLAN
3581 struct vlan_group *vg;
3584 if (!(vg = card->vlangrp))
3587 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3588 if (vg->vlan_devices[i] == dev){
3589 rc = QETH_VLAN_CARD;
3598 qeth_verify_dev(struct net_device *dev)
3600 struct qeth_card *card;
3601 unsigned long flags;
3604 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3605 list_for_each_entry(card, &qeth_card_list.list, list){
3606 if (card->dev == dev){
3607 rc = QETH_REAL_CARD;
3610 rc = qeth_verify_vlan_dev(dev, card);
3614 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3619 static struct qeth_card *
3620 qeth_get_card_from_dev(struct net_device *dev)
3622 struct qeth_card *card = NULL;
3625 rc = qeth_verify_dev(dev);
3626 if (rc == QETH_REAL_CARD)
3627 card = (struct qeth_card *)dev->priv;
3628 else if (rc == QETH_VLAN_CARD)
3629 card = (struct qeth_card *)
3630 VLAN_DEV_INFO(dev)->real_dev->priv;
3632 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3637 qeth_tx_timeout(struct net_device *dev)
3639 struct qeth_card *card;
3641 card = (struct qeth_card *) dev->priv;
3642 card->stats.tx_errors++;
3643 qeth_schedule_recovery(card);
3647 qeth_open(struct net_device *dev)
3649 struct qeth_card *card;
3651 QETH_DBF_TEXT(trace, 4, "qethopen");
3653 card = (struct qeth_card *) dev->priv;
3655 if (card->state != CARD_STATE_SOFTSETUP)
3658 if ( (card->options.layer2) &&
3659 (!card->info.layer2_mac_registered)) {
3660 QETH_DBF_TEXT(trace,4,"nomacadr");
3663 card->dev->flags |= IFF_UP;
3664 netif_start_queue(dev);
3665 card->data.state = CH_STATE_UP;
3666 card->state = CARD_STATE_UP;
3668 if (!card->lan_online){
3669 if (netif_carrier_ok(dev))
3670 netif_carrier_off(dev);
3676 qeth_stop(struct net_device *dev)
3678 struct qeth_card *card;
3680 QETH_DBF_TEXT(trace, 4, "qethstop");
3682 card = (struct qeth_card *) dev->priv;
3684 netif_stop_queue(dev);
3685 card->dev->flags &= ~IFF_UP;
3686 if (card->state == CARD_STATE_UP)
3687 card->state = CARD_STATE_SOFTSETUP;
3692 qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3694 int cast_type = RTN_UNSPEC;
3696 if (skb->dst && skb->dst->neighbour){
3697 cast_type = skb->dst->neighbour->type;
3698 if ((cast_type == RTN_BROADCAST) ||
3699 (cast_type == RTN_MULTICAST) ||
3700 (cast_type == RTN_ANYCAST))
3705 /* try something else */
3706 if (skb->protocol == ETH_P_IPV6)
3707 return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0;
3708 else if (skb->protocol == ETH_P_IP)
3709 return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0;
3711 if (!memcmp(skb->data, skb->dev->broadcast, 6))
3712 return RTN_BROADCAST;
3716 hdr_mac = *((u16 *)skb->data);
3718 switch (card->info.link_type) {
3719 case QETH_LINK_TYPE_HSTR:
3720 case QETH_LINK_TYPE_LANE_TR:
3721 if ((hdr_mac == QETH_TR_MAC_NC) ||
3722 (hdr_mac == QETH_TR_MAC_C))
3723 return RTN_MULTICAST;
3724 /* eth or so multicast? */
3726 if ((hdr_mac == QETH_ETH_MAC_V4) ||
3727 (hdr_mac == QETH_ETH_MAC_V6))
3728 return RTN_MULTICAST;
3735 qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3736 int ipv, int cast_type)
3738 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3739 return card->qdio.default_out_queue;
3740 switch (card->qdio.no_out_queues) {
3742 if (cast_type && card->info.is_multicast_different)
3743 return card->info.is_multicast_different &
3744 (card->qdio.no_out_queues - 1);
3745 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3746 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
3747 if (skb->nh.iph->tos & IP_TOS_NOTIMPORTANT)
3749 if (skb->nh.iph->tos & IP_TOS_HIGHRELIABILITY)
3751 if (skb->nh.iph->tos & IP_TOS_HIGHTHROUGHPUT)
3753 if (skb->nh.iph->tos & IP_TOS_LOWDELAY)
3756 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
3757 return 3 - (skb->nh.iph->tos >> 6);
3758 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3761 return card->qdio.default_out_queue;
3762 case 1: /* fallthrough for single-out-queue 1920-device */
3764 return card->qdio.default_out_queue;
3769 qeth_get_ip_version(struct sk_buff *skb)
3771 switch (skb->protocol) {
3782 qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb,
3783 struct qeth_hdr **hdr, int ipv)
3786 #ifdef CONFIG_QETH_VLAN
3790 QETH_DBF_TEXT(trace, 6, "prepskb");
3792 rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3795 #ifdef CONFIG_QETH_VLAN
3796 if (card->vlangrp && vlan_tx_tag_present(*skb) &&
3797 ((ipv == 6) || card->options.layer2) ) {
3799 * Move the mac addresses (6 bytes src, 6 bytes dest)
3800 * to the beginning of the new header. We are using three
3801 * memcpys instead of one memmove to save cycles.
3803 skb_push(*skb, VLAN_HLEN);
3804 memcpy((*skb)->data, (*skb)->data + 4, 4);
3805 memcpy((*skb)->data + 4, (*skb)->data + 8, 4);
3806 memcpy((*skb)->data + 8, (*skb)->data + 12, 4);
3807 tag = (u16 *)((*skb)->data + 12);
3809 * first two bytes = ETH_P_8021Q (0x8100)
3810 * second two bytes = VLANID
3812 *tag = __constant_htons(ETH_P_8021Q);
3813 *(tag + 1) = htons(vlan_tx_tag_get(*skb));
3816 *hdr = (struct qeth_hdr *)
3817 qeth_push_skb(card, skb, sizeof(struct qeth_hdr));
3824 qeth_get_qeth_hdr_flags4(int cast_type)
3826 if (cast_type == RTN_MULTICAST)
3827 return QETH_CAST_MULTICAST;
3828 if (cast_type == RTN_BROADCAST)
3829 return QETH_CAST_BROADCAST;
3830 return QETH_CAST_UNICAST;
3834 qeth_get_qeth_hdr_flags6(int cast_type)
3836 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
3837 if (cast_type == RTN_MULTICAST)
3838 return ct | QETH_CAST_MULTICAST;
3839 if (cast_type == RTN_ANYCAST)
3840 return ct | QETH_CAST_ANYCAST;
3841 if (cast_type == RTN_BROADCAST)
3842 return ct | QETH_CAST_BROADCAST;
3843 return ct | QETH_CAST_UNICAST;
3847 qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
3848 struct sk_buff *skb)
3852 if (!memcmp(skb->data+QETH_HEADER_SIZE,
3853 skb->dev->broadcast,6)) { /* broadcast? */
3854 *(__u32 *)hdr->hdr.l2.flags |=
3855 QETH_LAYER2_FLAG_BROADCAST << 8;
3858 hdr_mac=*((__u16*)skb->data);
3860 switch (card->info.link_type) {
3861 case QETH_LINK_TYPE_HSTR:
3862 case QETH_LINK_TYPE_LANE_TR:
3863 if ((hdr_mac == QETH_TR_MAC_NC) ||
3864 (hdr_mac == QETH_TR_MAC_C) )
3865 *(__u32 *)hdr->hdr.l2.flags |=
3866 QETH_LAYER2_FLAG_MULTICAST << 8;
3868 *(__u32 *)hdr->hdr.l2.flags |=
3869 QETH_LAYER2_FLAG_UNICAST << 8;
3871 /* eth or so multicast? */
3873 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
3874 (hdr_mac==QETH_ETH_MAC_V6) )
3875 *(__u32 *)hdr->hdr.l2.flags |=
3876 QETH_LAYER2_FLAG_MULTICAST << 8;
3878 *(__u32 *)hdr->hdr.l2.flags |=
3879 QETH_LAYER2_FLAG_UNICAST << 8;
3884 qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
3885 struct sk_buff *skb, int cast_type)
3887 memset(hdr, 0, sizeof(struct qeth_hdr));
3888 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
3890 /* set byte 0 to "0x02" and byte 3 to casting flags */
3891 if (cast_type==RTN_MULTICAST)
3892 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
3893 else if (cast_type==RTN_BROADCAST)
3894 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
3896 qeth_layer2_get_packet_type(card, hdr, skb);
3898 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
3899 #ifdef CONFIG_QETH_VLAN
3900 /* VSWITCH relies on the VLAN
3901 * information to be present in
3902 * the QDIO header */
3903 if ((card->vlangrp != NULL) &&
3904 vlan_tx_tag_present(skb)) {
3905 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
3906 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
3912 qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
3913 struct sk_buff *skb, int ipv, int cast_type)
3915 QETH_DBF_TEXT(trace, 6, "fillhdr");
3917 memset(hdr, 0, sizeof(struct qeth_hdr));
3918 if (card->options.layer2) {
3919 qeth_layer2_fill_header(card, hdr, skb, cast_type);
3922 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
3923 hdr->hdr.l3.ext_flags = 0;
3924 #ifdef CONFIG_QETH_VLAN
3926 * before we're going to overwrite this location with next hop ip.
3927 * v6 uses passthrough, v4 sets the tag in the QDIO header.
3929 if (card->vlangrp && vlan_tx_tag_present(skb)) {
3930 hdr->hdr.l3.ext_flags = (ipv == 4) ?
3931 QETH_HDR_EXT_VLAN_FRAME :
3932 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
3933 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
3935 #endif /* CONFIG_QETH_VLAN */
3936 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
3937 if (ipv == 4) { /* IPv4 */
3938 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
3939 memset(hdr->hdr.l3.dest_addr, 0, 12);
3940 if ((skb->dst) && (skb->dst->neighbour)) {
3941 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
3942 *((u32 *) skb->dst->neighbour->primary_key);
3944 /* fill in destination address used in ip header */
3945 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = skb->nh.iph->daddr;
3947 } else if (ipv == 6) { /* IPv6 or passthru */
3948 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
3949 if ((skb->dst) && (skb->dst->neighbour)) {
3950 memcpy(hdr->hdr.l3.dest_addr,
3951 skb->dst->neighbour->primary_key, 16);
3953 /* fill in destination address used in ip header */
3954 memcpy(hdr->hdr.l3.dest_addr, &skb->nh.ipv6h->daddr, 16);
3956 } else { /* passthrough */
3957 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
3958 !memcmp(skb->data + sizeof(struct qeth_hdr) +
3959 sizeof(__u16), skb->dev->broadcast, 6)) {
3960 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
3962 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
3963 skb->dev->broadcast, 6)) { /* broadcast? */
3964 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
3967 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
3968 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
3969 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
3975 __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
3976 int is_tso, int *next_element_to_fill)
3978 int length = skb->len;
3984 element = *next_element_to_fill;
3986 first_lap = (is_tso == 0 ? 1 : 0);
3988 while (length > 0) {
3989 /* length_here is the remaining amount of data in this page */
3990 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
3991 if (length < length_here)
3992 length_here = length;
3994 buffer->element[element].addr = data;
3995 buffer->element[element].length = length_here;
3996 length -= length_here;
3999 buffer->element[element].flags = 0;
4001 buffer->element[element].flags =
4002 SBAL_FLAGS_LAST_FRAG;
4005 buffer->element[element].flags =
4006 SBAL_FLAGS_FIRST_FRAG;
4008 buffer->element[element].flags =
4009 SBAL_FLAGS_MIDDLE_FRAG;
4011 data += length_here;
4015 *next_element_to_fill = element;
4019 qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4020 struct qeth_qdio_out_buffer *buf,
4021 struct sk_buff *skb)
4023 struct qdio_buffer *buffer;
4024 struct qeth_hdr_tso *hdr;
4025 int flush_cnt = 0, hdr_len, large_send = 0;
4027 QETH_DBF_TEXT(trace, 6, "qdfillbf");
4029 buffer = buf->buffer;
4030 atomic_inc(&skb->users);
4031 skb_queue_tail(&buf->skb_list, skb);
4033 hdr = (struct qeth_hdr_tso *) skb->data;
4034 /*check first on TSO ....*/
4035 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4036 int element = buf->next_element_to_fill;
4038 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4039 /*fill first buffer entry only with header information */
4040 buffer->element[element].addr = skb->data;
4041 buffer->element[element].length = hdr_len;
4042 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4043 buf->next_element_to_fill++;
4044 skb->data += hdr_len;
4045 skb->len -= hdr_len;
4048 if (skb_shinfo(skb)->nr_frags == 0)
4049 __qeth_fill_buffer(skb, buffer, large_send,
4050 (int *)&buf->next_element_to_fill);
4052 __qeth_fill_buffer_frag(skb, buffer, large_send,
4053 (int *)&buf->next_element_to_fill);
4055 if (!queue->do_pack) {
4056 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4057 /* set state to PRIMED -> will be flushed */
4058 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4061 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4062 #ifdef CONFIG_QETH_PERF_STATS
4063 queue->card->perf_stats.skbs_sent_pack++;
4065 if (buf->next_element_to_fill >=
4066 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4068 * packed buffer if full -> set state PRIMED
4069 * -> will be flushed
4071 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4079 qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4080 struct sk_buff *skb, struct qeth_hdr *hdr,
4081 int elements_needed,
4082 struct qeth_eddp_context *ctx)
4084 struct qeth_qdio_out_buffer *buffer;
4085 int buffers_needed = 0;
4089 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4091 /* spin until we get the queue ... */
4092 while (atomic_compare_and_swap(QETH_OUT_Q_UNLOCKED,
4095 /* ... now we've got the queue */
4096 index = queue->next_buf_to_fill;
4097 buffer = &queue->bufs[queue->next_buf_to_fill];
4099 * check if buffer is empty to make sure that we do not 'overtake'
4100 * ourselves and try to fill a buffer that is already primed
4102 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4103 card->stats.tx_dropped++;
4104 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4108 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4109 QDIO_MAX_BUFFERS_PER_Q;
4111 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4112 if (buffers_needed < 0) {
4113 card->stats.tx_dropped++;
4114 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4117 queue->next_buf_to_fill =
4118 (queue->next_buf_to_fill + buffers_needed) %
4119 QDIO_MAX_BUFFERS_PER_Q;
4121 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4123 qeth_fill_buffer(queue, buffer, skb);
4124 qeth_flush_buffers(queue, 0, index, 1);
4126 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4127 WARN_ON(buffers_needed != flush_cnt);
4128 qeth_flush_buffers(queue, 0, index, flush_cnt);
4134 qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4135 struct sk_buff *skb, struct qeth_hdr *hdr,
4136 int elements_needed, struct qeth_eddp_context *ctx)
4138 struct qeth_qdio_out_buffer *buffer;
4140 int flush_count = 0;
4145 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4147 /* spin until we get the queue ... */
4148 while (atomic_compare_and_swap(QETH_OUT_Q_UNLOCKED,
4151 start_index = queue->next_buf_to_fill;
4152 buffer = &queue->bufs[queue->next_buf_to_fill];
4154 * check if buffer is empty to make sure that we do not 'overtake'
4155 * ourselves and try to fill a buffer that is already primed
4157 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY){
4158 card->stats.tx_dropped++;
4159 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4162 /* check if we need to switch packing state of this queue */
4163 qeth_switch_to_packing_if_needed(queue);
4164 if (queue->do_pack){
4167 /* does packet fit in current buffer? */
4168 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4169 buffer->next_element_to_fill) < elements_needed){
4170 /* ... no -> set state PRIMED */
4171 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4173 queue->next_buf_to_fill =
4174 (queue->next_buf_to_fill + 1) %
4175 QDIO_MAX_BUFFERS_PER_Q;
4176 buffer = &queue->bufs[queue->next_buf_to_fill];
4177 /* we did a step forward, so check buffer state
4179 if (atomic_read(&buffer->state) !=
4180 QETH_QDIO_BUF_EMPTY){
4181 card->stats.tx_dropped++;
4182 qeth_flush_buffers(queue, 0, start_index, flush_count);
4183 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4188 /* check if we have enough elements (including following
4189 * free buffers) to handle eddp context */
4190 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4191 printk("eddp tx_dropped 1\n");
4192 card->stats.tx_dropped++;
4199 tmp = qeth_fill_buffer(queue, buffer, skb);
4201 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4203 printk("eddp tx_dropped 2\n");
4204 card->stats.tx_dropped++;
4209 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4210 QDIO_MAX_BUFFERS_PER_Q;
4214 qeth_flush_buffers(queue, 0, start_index, flush_count);
4216 * queue->state will go from LOCKED -> UNLOCKED or from
4217 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4218 * (switch packing state or flush buffer to get another pci flag out).
4219 * In that case we will enter this loop
4221 while (atomic_dec_return(&queue->state)){
4223 start_index = queue->next_buf_to_fill;
4224 /* check if we can go back to non-packing state */
4225 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4227 * check if we need to flush a packing buffer to get a pci
4228 * flag out on the queue
4230 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4231 flush_count += qeth_flush_buffers_on_no_pci(queue);
4233 qeth_flush_buffers(queue, 0, start_index, flush_count);
4235 /* at this point the queue is UNLOCKED again */
4236 #ifdef CONFIG_QETH_PERF_STATS
4238 queue->card->perf_stats.bufs_sent_pack += flush_count;
4239 #endif /* CONFIG_QETH_PERF_STATS */
4245 qeth_get_elements_no(struct qeth_card *card, void *hdr,
4246 struct sk_buff *skb, int elems)
4248 int elements_needed = 0;
4250 if (skb_shinfo(skb)->nr_frags > 0) {
4251 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4253 if (elements_needed == 0 )
4254 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4255 + skb->len) >> PAGE_SHIFT);
4256 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4257 PRINT_ERR("qeth_do_send_packet: invalid size of "
4258 "IP packet (Number=%d / Length=%d). Discarded.\n",
4259 (elements_needed+elems), skb->len);
4262 return elements_needed;
4266 qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4270 struct qeth_qdio_out_q *queue;
4271 struct qeth_hdr *hdr = NULL;
4272 int elements_needed = 0;
4273 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4274 struct qeth_eddp_context *ctx = NULL;
4277 QETH_DBF_TEXT(trace, 6, "sendpkt");
4279 if (!card->options.layer2) {
4280 ipv = qeth_get_ip_version(skb);
4281 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4282 if ((skb = qeth_pskb_unshare(skb,GFP_ATOMIC)) == NULL) {
4283 card->stats.tx_dropped++;
4284 dev_kfree_skb_irq(skb);
4287 if(card->dev->type == ARPHRD_IEEE802_TR){
4288 skb_pull(skb, QETH_FAKE_LL_LEN_TR);
4290 skb_pull(skb, QETH_FAKE_LL_LEN_ETH);
4294 cast_type = qeth_get_cast_type(card, skb);
4295 if ((cast_type == RTN_BROADCAST) && (card->info.broadcast_capable == 0)){
4296 card->stats.tx_dropped++;
4297 card->stats.tx_errors++;
4298 dev_kfree_skb_any(skb);
4299 return NETDEV_TX_OK;
4301 queue = card->qdio.out_qs
4302 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4304 if (skb_shinfo(skb)->tso_size)
4305 large_send = card->options.large_send;
4307 /*are we able to do TSO ? If so ,prepare and send it from here */
4308 if ((large_send == QETH_LARGE_SEND_TSO) &&
4309 (cast_type == RTN_UNSPEC)) {
4310 rc = qeth_tso_prepare_packet(card, skb, ipv, cast_type);
4312 card->stats.tx_dropped++;
4313 card->stats.tx_errors++;
4314 dev_kfree_skb_any(skb);
4315 return NETDEV_TX_OK;
4319 if ((rc = qeth_prepare_skb(card, &skb, &hdr, ipv))) {
4320 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc);
4323 qeth_fill_header(card, hdr, skb, ipv, cast_type);
4326 if (large_send == QETH_LARGE_SEND_EDDP) {
4327 ctx = qeth_eddp_create_context(card, skb, hdr);
4329 PRINT_WARN("could not create eddp context\n");
4333 int elems = qeth_get_elements_no(card,(void*) hdr, skb,
4337 elements_needed += elems;
4340 if (card->info.type != QETH_CARD_TYPE_IQD)
4341 rc = qeth_do_send_packet(card, queue, skb, hdr,
4342 elements_needed, ctx);
4344 rc = qeth_do_send_packet_fast(card, queue, skb, hdr,
4345 elements_needed, ctx);
4347 card->stats.tx_packets++;
4348 card->stats.tx_bytes += skb->len;
4349 #ifdef CONFIG_QETH_PERF_STATS
4350 if (skb_shinfo(skb)->tso_size &&
4351 !(large_send == QETH_LARGE_SEND_NO)) {
4352 card->perf_stats.large_send_bytes += skb->len;
4353 card->perf_stats.large_send_cnt++;
4355 if (skb_shinfo(skb)->nr_frags > 0){
4356 card->perf_stats.sg_skbs_sent++;
4357 /* nr_frags + skb->data */
4358 card->perf_stats.sg_frags_sent +=
4359 skb_shinfo(skb)->nr_frags + 1;
4361 #endif /* CONFIG_QETH_PERF_STATS */
4364 /* drop creator's reference */
4365 qeth_eddp_put_context(ctx);
4366 /* free skb; it's not referenced by a buffer */
4368 dev_kfree_skb_any(skb);
4375 qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4377 struct qeth_card *card = (struct qeth_card *) dev->priv;
4381 case MII_BMCR: /* Basic mode control register */
4383 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4384 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4385 rc |= BMCR_SPEED100;
4387 case MII_BMSR: /* Basic mode status register */
4388 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4389 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4392 case MII_PHYSID1: /* PHYS ID 1 */
4393 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4395 rc = (rc >> 5) & 0xFFFF;
4397 case MII_PHYSID2: /* PHYS ID 2 */
4398 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4400 case MII_ADVERTISE: /* Advertisement control reg */
4403 case MII_LPA: /* Link partner ability reg */
4404 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4405 LPA_100BASE4 | LPA_LPACK;
4407 case MII_EXPANSION: /* Expansion register */
4409 case MII_DCOUNTER: /* disconnect counter */
4411 case MII_FCSCOUNTER: /* false carrier counter */
4413 case MII_NWAYTEST: /* N-way auto-neg test register */
4415 case MII_RERRCOUNTER: /* rx error counter */
4416 rc = card->stats.rx_errors;
4418 case MII_SREVISION: /* silicon revision */
4420 case MII_RESV1: /* reserved 1 */
4422 case MII_LBRERROR: /* loopback, rx, bypass error */
4424 case MII_PHYADDR: /* physical address */
4426 case MII_RESV2: /* reserved 2 */
4428 case MII_TPISTATUS: /* TPI status for 10mbps */
4430 case MII_NCONFIG: /* network interface config */
4440 qeth_mdio_write(struct net_device *dev, int phy_id, int regnum, int value)
4443 case MII_BMCR: /* Basic mode control register */
4444 case MII_BMSR: /* Basic mode status register */
4445 case MII_PHYSID1: /* PHYS ID 1 */
4446 case MII_PHYSID2: /* PHYS ID 2 */
4447 case MII_ADVERTISE: /* Advertisement control reg */
4448 case MII_LPA: /* Link partner ability reg */
4449 case MII_EXPANSION: /* Expansion register */
4450 case MII_DCOUNTER: /* disconnect counter */
4451 case MII_FCSCOUNTER: /* false carrier counter */
4452 case MII_NWAYTEST: /* N-way auto-neg test register */
4453 case MII_RERRCOUNTER: /* rx error counter */
4454 case MII_SREVISION: /* silicon revision */
4455 case MII_RESV1: /* reserved 1 */
4456 case MII_LBRERROR: /* loopback, rx, bypass error */
4457 case MII_PHYADDR: /* physical address */
4458 case MII_RESV2: /* reserved 2 */
4459 case MII_TPISTATUS: /* TPI status for 10mbps */
4460 case MII_NCONFIG: /* network interface config */
4466 static inline const char *
4467 qeth_arp_get_error_cause(int *rc)
4470 case QETH_IPA_ARP_RC_FAILED:
4472 return "operation failed";
4473 case QETH_IPA_ARP_RC_NOTSUPP:
4475 return "operation not supported";
4476 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4478 return "argument out of range";
4479 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4481 return "query operation not supported";
4482 case QETH_IPA_ARP_RC_Q_NO_DATA:
4484 return "no query data available";
4486 return "unknown error";
4491 qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4495 qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4500 QETH_DBF_TEXT(trace,3,"arpstnoe");
4503 * currently GuestLAN only supports the ARP assist function
4504 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4505 * thus we say EOPNOTSUPP for this ARP function
4507 if (card->info.guestlan)
4509 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4510 PRINT_WARN("ARP processing not supported "
4511 "on %s!\n", QETH_CARD_IFNAME(card));
4514 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4515 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4519 PRINT_WARN("Could not set number of ARP entries on %s: "
4521 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4528 qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4529 struct qeth_arp_query_data *qdata,
4530 int entry_size, int uentry_size)
4536 entry_ptr = (char *)&qdata->data;
4537 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4538 for (i = 0; i < qdata->no_entries; ++i){
4539 /* strip off 32 bytes "media specific information" */
4540 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4541 entry_ptr += entry_size;
4542 uentry_ptr += uentry_size;
4547 qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4550 struct qeth_ipa_cmd *cmd;
4551 struct qeth_arp_query_data *qdata;
4552 struct qeth_arp_query_info *qinfo;
4557 QETH_DBF_TEXT(trace,4,"arpquecb");
4559 qinfo = (struct qeth_arp_query_info *) reply->param;
4560 cmd = (struct qeth_ipa_cmd *) data;
4561 if (cmd->hdr.return_code) {
4562 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4565 if (cmd->data.setassparms.hdr.return_code) {
4566 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4567 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4570 qdata = &cmd->data.setassparms.data.query_arp;
4571 switch(qdata->reply_bits){
4573 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4574 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4575 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4578 /* fall through to default */
4580 /* tr is the same as eth -> entry7 */
4581 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4582 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4583 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4586 /* check if there is enough room in userspace */
4587 if ((qinfo->udata_len - qinfo->udata_offset) <
4588 qdata->no_entries * uentry_size){
4589 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4590 cmd->hdr.return_code = -ENOMEM;
4591 PRINT_WARN("query ARP user space buffer is too small for "
4592 "the returned number of ARP entries. "
4593 "Aborting query!\n");
4596 QETH_DBF_TEXT_(trace, 4, "anore%i",
4597 cmd->data.setassparms.hdr.number_of_replies);
4598 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4599 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4601 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4602 /* strip off "media specific information" */
4603 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4606 /*copy entries to user buffer*/
4607 memcpy(qinfo->udata + qinfo->udata_offset,
4608 (char *)&qdata->data, qdata->no_entries*uentry_size);
4610 qinfo->no_entries += qdata->no_entries;
4611 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4612 /* check if all replies received ... */
4613 if (cmd->data.setassparms.hdr.seq_no <
4614 cmd->data.setassparms.hdr.number_of_replies)
4616 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4617 /* keep STRIP_ENTRIES flag so the user program can distinguish
4618 * stripped entries from normal ones */
4619 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4620 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4621 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4625 memcpy(qinfo->udata, &i, 4);
4630 qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4631 int len, int (*reply_cb)(struct qeth_card *,
4632 struct qeth_reply *,
4636 QETH_DBF_TEXT(trace,4,"sendarp");
4638 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4639 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4640 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4641 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4642 reply_cb, reply_param);
4646 qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4647 int len, int (*reply_cb)(struct qeth_card *,
4648 struct qeth_reply *,
4654 QETH_DBF_TEXT(trace,4,"sendsnmp");
4656 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4657 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4658 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4659 /* adjust PDU length fields in IPA_PDU_HEADER */
4660 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4662 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4663 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4664 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4665 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4666 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4667 reply_cb, reply_param);
4670 static struct qeth_cmd_buffer *
4671 qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4672 __u16, __u16, enum qeth_prot_versions);
4674 qeth_arp_query(struct qeth_card *card, char *udata)
4676 struct qeth_cmd_buffer *iob;
4677 struct qeth_arp_query_info qinfo = {0, };
4681 QETH_DBF_TEXT(trace,3,"arpquery");
4683 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4684 IPA_ARP_PROCESSING)) {
4685 PRINT_WARN("ARP processing not supported "
4686 "on %s!\n", QETH_CARD_IFNAME(card));
4689 /* get size of userspace buffer and mask_bits -> 6 bytes */
4690 if (copy_from_user(&qinfo, udata, 6))
4692 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL)))
4694 memset(qinfo.udata, 0, qinfo.udata_len);
4695 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4696 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4697 IPA_CMD_ASS_ARP_QUERY_INFO,
4698 sizeof(int),QETH_PROT_IPV4);
4700 rc = qeth_send_ipa_arp_cmd(card, iob,
4701 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4702 qeth_arp_query_cb, (void *)&qinfo);
4705 PRINT_WARN("Error while querying ARP cache on %s: %s "
4707 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4709 copy_to_user(udata, qinfo.udata, 4);
4711 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4718 * SNMP command callback
4721 qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4722 unsigned long sdata)
4724 struct qeth_ipa_cmd *cmd;
4725 struct qeth_arp_query_info *qinfo;
4726 struct qeth_snmp_cmd *snmp;
4727 unsigned char *data;
4730 QETH_DBF_TEXT(trace,3,"snpcmdcb");
4732 cmd = (struct qeth_ipa_cmd *) sdata;
4733 data = (unsigned char *)((char *)cmd - reply->offset);
4734 qinfo = (struct qeth_arp_query_info *) reply->param;
4735 snmp = &cmd->data.setadapterparms.data.snmp;
4737 if (cmd->hdr.return_code) {
4738 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4741 if (cmd->data.setadapterparms.hdr.return_code) {
4742 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4743 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4746 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4747 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4748 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4750 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4752 /* check if there is enough room in userspace */
4753 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4754 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4755 cmd->hdr.return_code = -ENOMEM;
4758 QETH_DBF_TEXT_(trace, 4, "snore%i",
4759 cmd->data.setadapterparms.hdr.used_total);
4760 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4761 /*copy entries to user buffer*/
4762 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4763 memcpy(qinfo->udata + qinfo->udata_offset,
4765 data_len + offsetof(struct qeth_snmp_cmd,data));
4766 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4768 memcpy(qinfo->udata + qinfo->udata_offset,
4769 (char *)&snmp->request, data_len);
4771 qinfo->udata_offset += data_len;
4772 /* check if all replies received ... */
4773 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4774 cmd->data.setadapterparms.hdr.used_total);
4775 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4776 cmd->data.setadapterparms.hdr.seq_no);
4777 if (cmd->data.setadapterparms.hdr.seq_no <
4778 cmd->data.setadapterparms.hdr.used_total)
4783 static struct qeth_cmd_buffer *
4784 qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4785 enum qeth_prot_versions );
4787 static struct qeth_cmd_buffer *
4788 qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4790 struct qeth_cmd_buffer *iob;
4791 struct qeth_ipa_cmd *cmd;
4793 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4795 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4796 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4797 cmd->data.setadapterparms.hdr.command_code = command;
4798 cmd->data.setadapterparms.hdr.used_total = 1;
4799 cmd->data.setadapterparms.hdr.seq_no = 1;
4805 * function to send SNMP commands to OSA-E card
4808 qeth_snmp_command(struct qeth_card *card, char *udata)
4810 struct qeth_cmd_buffer *iob;
4811 struct qeth_ipa_cmd *cmd;
4812 struct qeth_snmp_ureq *ureq;
4814 struct qeth_arp_query_info qinfo = {0, };
4817 QETH_DBF_TEXT(trace,3,"snmpcmd");
4819 if (card->info.guestlan)
4822 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4823 (!card->options.layer2) ) {
4824 PRINT_WARN("SNMP Query MIBS not supported "
4825 "on %s!\n", QETH_CARD_IFNAME(card));
4828 /* skip 4 bytes (data_len struct member) to get req_len */
4829 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4831 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4833 QETH_DBF_TEXT(trace, 2, "snmpnome");
4836 if (copy_from_user(ureq, udata,
4837 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
4841 qinfo.udata_len = ureq->hdr.data_len;
4842 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL))){
4846 memset(qinfo.udata, 0, qinfo.udata_len);
4847 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4849 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
4850 QETH_SNMP_SETADP_CMDLENGTH + req_len);
4851 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4852 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
4853 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
4854 qeth_snmp_command_cb, (void *)&qinfo);
4856 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
4857 QETH_CARD_IFNAME(card), rc);
4859 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4867 qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
4871 qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
4874 (struct qeth_card *, struct qeth_reply *, unsigned long),
4878 qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
4880 struct qeth_cmd_buffer *iob;
4885 QETH_DBF_TEXT(trace,3,"arpadent");
4888 * currently GuestLAN only supports the ARP assist function
4889 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
4890 * thus we say EOPNOTSUPP for this ARP function
4892 if (card->info.guestlan)
4894 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4895 PRINT_WARN("ARP processing not supported "
4896 "on %s!\n", QETH_CARD_IFNAME(card));
4900 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4901 IPA_CMD_ASS_ARP_ADD_ENTRY,
4902 sizeof(struct qeth_arp_cache_entry),
4904 rc = qeth_send_setassparms(card, iob,
4905 sizeof(struct qeth_arp_cache_entry),
4906 (unsigned long) entry,
4907 qeth_default_setassparms_cb, NULL);
4910 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
4911 PRINT_WARN("Could not add ARP entry for address %s on %s: "
4913 buf, QETH_CARD_IFNAME(card),
4914 qeth_arp_get_error_cause(&rc), tmp, tmp);
4920 qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
4922 struct qeth_cmd_buffer *iob;
4923 char buf[16] = {0, };
4927 QETH_DBF_TEXT(trace,3,"arprment");
4930 * currently GuestLAN only supports the ARP assist function
4931 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
4932 * thus we say EOPNOTSUPP for this ARP function
4934 if (card->info.guestlan)
4936 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4937 PRINT_WARN("ARP processing not supported "
4938 "on %s!\n", QETH_CARD_IFNAME(card));
4941 memcpy(buf, entry, 12);
4942 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4943 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
4946 rc = qeth_send_setassparms(card, iob,
4947 12, (unsigned long)buf,
4948 qeth_default_setassparms_cb, NULL);
4952 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
4953 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
4955 buf, QETH_CARD_IFNAME(card),
4956 qeth_arp_get_error_cause(&rc), tmp, tmp);
4962 qeth_arp_flush_cache(struct qeth_card *card)
4967 QETH_DBF_TEXT(trace,3,"arpflush");
4970 * currently GuestLAN only supports the ARP assist function
4971 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
4972 * thus we say EOPNOTSUPP for this ARP function
4974 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
4976 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4977 PRINT_WARN("ARP processing not supported "
4978 "on %s!\n", QETH_CARD_IFNAME(card));
4981 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4982 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
4985 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
4986 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4993 qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
4995 struct qeth_card *card = (struct qeth_card *)dev->priv;
4996 struct qeth_arp_cache_entry arp_entry;
4997 struct mii_ioctl_data *mii_data;
5003 if ((card->state != CARD_STATE_UP) &&
5004 (card->state != CARD_STATE_SOFTSETUP))
5008 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5009 if ( !capable(CAP_NET_ADMIN) ||
5010 (card->options.layer2) ) {
5014 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5016 case SIOC_QETH_ARP_QUERY_INFO:
5017 if ( !capable(CAP_NET_ADMIN) ||
5018 (card->options.layer2) ) {
5022 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5024 case SIOC_QETH_ARP_ADD_ENTRY:
5025 if ( !capable(CAP_NET_ADMIN) ||
5026 (card->options.layer2) ) {
5030 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5031 sizeof(struct qeth_arp_cache_entry)))
5034 rc = qeth_arp_add_entry(card, &arp_entry);
5036 case SIOC_QETH_ARP_REMOVE_ENTRY:
5037 if ( !capable(CAP_NET_ADMIN) ||
5038 (card->options.layer2) ) {
5042 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5043 sizeof(struct qeth_arp_cache_entry)))
5046 rc = qeth_arp_remove_entry(card, &arp_entry);
5048 case SIOC_QETH_ARP_FLUSH_CACHE:
5049 if ( !capable(CAP_NET_ADMIN) ||
5050 (card->options.layer2) ) {
5054 rc = qeth_arp_flush_cache(card);
5056 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5057 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5059 case SIOC_QETH_GET_CARD_TYPE:
5060 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5061 !card->info.guestlan)
5066 mii_data = if_mii(rq);
5067 mii_data->phy_id = 0;
5070 mii_data = if_mii(rq);
5071 if (mii_data->phy_id != 0)
5074 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5080 /* TODO: remove return if qeth_mdio_write does something */
5081 if (!capable(CAP_NET_ADMIN)){
5085 mii_data = if_mii(rq);
5086 if (mii_data->phy_id != 0)
5089 qeth_mdio_write(dev, mii_data->phy_id, mii_data->reg_num,
5096 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5100 static struct net_device_stats *
5101 qeth_get_stats(struct net_device *dev)
5103 struct qeth_card *card;
5105 card = (struct qeth_card *) (dev->priv);
5107 QETH_DBF_TEXT(trace,5,"getstat");
5109 return &card->stats;
5113 qeth_change_mtu(struct net_device *dev, int new_mtu)
5115 struct qeth_card *card;
5118 card = (struct qeth_card *) (dev->priv);
5120 QETH_DBF_TEXT(trace,4,"chgmtu");
5121 sprintf(dbf_text, "%8x", new_mtu);
5122 QETH_DBF_TEXT(trace,4,dbf_text);
5126 if (new_mtu > 65535)
5128 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5129 (!qeth_mtu_is_valid(card, new_mtu)))
5135 #ifdef CONFIG_QETH_VLAN
5137 qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5139 struct qeth_card *card;
5140 unsigned long flags;
5142 QETH_DBF_TEXT(trace,4,"vlanreg");
5144 card = (struct qeth_card *) dev->priv;
5145 spin_lock_irqsave(&card->vlanlock, flags);
5146 card->vlangrp = grp;
5147 spin_unlock_irqrestore(&card->vlanlock, flags);
5151 qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5155 struct sk_buff *skb;
5156 struct sk_buff_head tmp_list;
5158 skb_queue_head_init(&tmp_list);
5159 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5160 while ((skb = skb_dequeue(&buf->skb_list))){
5161 if (vlan_tx_tag_present(skb) &&
5162 (vlan_tx_tag_get(skb) == vid)) {
5163 atomic_dec(&skb->users);
5166 skb_queue_tail(&tmp_list, skb);
5169 while ((skb = skb_dequeue(&tmp_list)))
5170 skb_queue_tail(&buf->skb_list, skb);
5174 qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5178 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5179 for (i = 0; i < card->qdio.no_out_queues; ++i){
5180 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5181 qeth_free_vlan_buffer(card, &card->qdio.
5182 out_qs[i]->bufs[j], vid);
5187 qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5189 struct in_device *in_dev;
5190 struct in_ifaddr *ifa;
5191 struct qeth_ipaddr *addr;
5193 QETH_DBF_TEXT(trace, 4, "frvaddr4");
5197 in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]);
5200 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5201 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5203 addr->u.a4.addr = ifa->ifa_address;
5204 addr->u.a4.mask = ifa->ifa_mask;
5205 addr->type = QETH_IP_TYPE_NORMAL;
5206 if (!qeth_delete_ip(card, addr))
5215 qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5217 #ifdef CONFIG_QETH_IPV6
5218 struct inet6_dev *in6_dev;
5219 struct inet6_ifaddr *ifa;
5220 struct qeth_ipaddr *addr;
5222 QETH_DBF_TEXT(trace, 4, "frvaddr6");
5225 in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]);
5228 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5229 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5231 memcpy(&addr->u.a6.addr, &ifa->addr,
5232 sizeof(struct in6_addr));
5233 addr->u.a6.pfxlen = ifa->prefix_len;
5234 addr->type = QETH_IP_TYPE_NORMAL;
5235 if (!qeth_delete_ip(card, addr))
5239 in6_dev_put(in6_dev);
5240 #endif /* CONFIG_QETH_IPV6 */
5244 qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5245 enum qeth_ipa_cmds ipacmd)
5248 struct qeth_ipa_cmd *cmd;
5249 struct qeth_cmd_buffer *iob;
5251 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5252 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5253 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5254 cmd->data.setdelvlan.vlan_id = i;
5256 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
5258 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5259 "Continuing\n",i, QETH_CARD_IFNAME(card), rc);
5260 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", ipacmd);
5261 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5262 QETH_DBF_TEXT_(trace, 2, "err%d", rc);
5267 qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5271 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5275 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5276 if (card->vlangrp->vlan_devices[i] == NULL)
5279 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5281 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5285 /*add_vid is layer 2 used only ....*/
5287 qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5289 struct qeth_card *card;
5291 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5293 card = (struct qeth_card *) dev->priv;
5294 if (!card->options.layer2)
5296 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5299 /*... kill_vid used for both modes*/
5301 qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5303 struct qeth_card *card;
5304 unsigned long flags;
5306 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5308 card = (struct qeth_card *) dev->priv;
5309 /* free all skbs for the vlan device */
5310 qeth_free_vlan_skbs(card, vid);
5311 spin_lock_irqsave(&card->vlanlock, flags);
5312 /* unregister IP addresses of vlan device */
5313 qeth_free_vlan_addresses4(card, vid);
5314 qeth_free_vlan_addresses6(card, vid);
5316 card->vlangrp->vlan_devices[vid] = NULL;
5317 spin_unlock_irqrestore(&card->vlanlock, flags);
5318 if (card->options.layer2)
5319 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5320 qeth_set_multicast_list(card->dev);
5325 * set multicast address on card
5328 qeth_set_multicast_list(struct net_device *dev)
5330 struct qeth_card *card = (struct qeth_card *) dev->priv;
5332 QETH_DBF_TEXT(trace,3,"setmulti");
5333 qeth_delete_mc_addresses(card);
5334 qeth_add_multicast_ipv4(card);
5335 #ifdef CONFIG_QETH_IPV6
5336 qeth_add_multicast_ipv6(card);
5338 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
5339 schedule_work(&card->kernel_thread_starter);
5343 qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5349 qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5351 if (dev->type == ARPHRD_IEEE802_TR)
5352 ip_tr_mc_map(ipm, mac);
5354 ip_eth_mc_map(ipm, mac);
5357 static struct qeth_ipaddr *
5358 qeth_get_addr_buffer(enum qeth_prot_versions prot)
5360 struct qeth_ipaddr *addr;
5362 addr = kmalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5364 PRINT_WARN("Not enough memory to add address\n");
5367 memset(addr,0,sizeof(struct qeth_ipaddr));
5368 addr->type = QETH_IP_TYPE_NORMAL;
5374 qeth_delete_mc_addresses(struct qeth_card *card)
5376 struct qeth_ipaddr *iptodo;
5377 unsigned long flags;
5379 QETH_DBF_TEXT(trace,4,"delmc");
5380 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5382 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5385 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5386 spin_lock_irqsave(&card->ip_lock, flags);
5387 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5389 spin_unlock_irqrestore(&card->ip_lock, flags);
5393 qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5395 struct qeth_ipaddr *ipm;
5396 struct ip_mc_list *im4;
5397 char buf[MAX_ADDR_LEN];
5399 QETH_DBF_TEXT(trace,4,"addmc");
5400 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5401 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5402 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5405 ipm->u.a4.addr = im4->multiaddr;
5406 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5407 ipm->is_multicast = 1;
5408 if (!qeth_add_ip(card,ipm))
5414 qeth_add_vlan_mc(struct qeth_card *card)
5416 #ifdef CONFIG_QETH_VLAN
5417 struct in_device *in_dev;
5418 struct vlan_group *vg;
5421 QETH_DBF_TEXT(trace,4,"addmcvl");
5422 if ( ((card->options.layer2 == 0) &&
5423 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5424 (card->vlangrp == NULL) )
5428 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5429 if (vg->vlan_devices[i] == NULL ||
5430 !(vg->vlan_devices[i]->flags & IFF_UP))
5432 in_dev = in_dev_get(vg->vlan_devices[i]);
5435 read_lock(&in_dev->mc_list_lock);
5436 qeth_add_mc(card,in_dev);
5437 read_unlock(&in_dev->mc_list_lock);
5444 qeth_add_multicast_ipv4(struct qeth_card *card)
5446 struct in_device *in4_dev;
5448 QETH_DBF_TEXT(trace,4,"chkmcv4");
5449 in4_dev = in_dev_get(card->dev);
5450 if (in4_dev == NULL)
5452 read_lock(&in4_dev->mc_list_lock);
5453 qeth_add_mc(card, in4_dev);
5454 qeth_add_vlan_mc(card);
5455 read_unlock(&in4_dev->mc_list_lock);
5456 in_dev_put(in4_dev);
5459 #ifdef CONFIG_QETH_IPV6
5461 qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5463 struct qeth_ipaddr *ipm;
5464 struct ifmcaddr6 *im6;
5465 char buf[MAX_ADDR_LEN];
5467 QETH_DBF_TEXT(trace,4,"addmc6");
5468 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5469 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5470 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5473 ipm->is_multicast = 1;
5474 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5475 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5476 sizeof(struct in6_addr));
5477 if (!qeth_add_ip(card,ipm))
5483 qeth_add_vlan_mc6(struct qeth_card *card)
5485 #ifdef CONFIG_QETH_VLAN
5486 struct inet6_dev *in_dev;
5487 struct vlan_group *vg;
5490 QETH_DBF_TEXT(trace,4,"admc6vl");
5491 if ( ((card->options.layer2 == 0) &&
5492 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5493 (card->vlangrp == NULL))
5497 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5498 if (vg->vlan_devices[i] == NULL ||
5499 !(vg->vlan_devices[i]->flags & IFF_UP))
5501 in_dev = in6_dev_get(vg->vlan_devices[i]);
5504 read_lock(&in_dev->lock);
5505 qeth_add_mc6(card,in_dev);
5506 read_unlock(&in_dev->lock);
5507 in6_dev_put(in_dev);
5509 #endif /* CONFIG_QETH_VLAN */
5513 qeth_add_multicast_ipv6(struct qeth_card *card)
5515 struct inet6_dev *in6_dev;
5517 QETH_DBF_TEXT(trace,4,"chkmcv6");
5518 if ((card->options.layer2 == 0) &&
5519 (!qeth_is_supported(card, IPA_IPV6)) )
5522 in6_dev = in6_dev_get(card->dev);
5523 if (in6_dev == NULL)
5525 read_lock(&in6_dev->lock);
5526 qeth_add_mc6(card, in6_dev);
5527 qeth_add_vlan_mc6(card);
5528 read_unlock(&in6_dev->lock);
5529 in6_dev_put(in6_dev);
5531 #endif /* CONFIG_QETH_IPV6 */
5534 qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5535 enum qeth_ipa_cmds ipacmd,
5536 int (*reply_cb) (struct qeth_card *,
5540 struct qeth_ipa_cmd *cmd;
5541 struct qeth_cmd_buffer *iob;
5543 QETH_DBF_TEXT(trace, 2, "L2sdmac");
5544 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5545 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5546 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5547 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5548 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5552 qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5553 struct qeth_reply *reply,
5556 struct qeth_ipa_cmd *cmd;
5559 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5560 cmd = (struct qeth_ipa_cmd *) data;
5561 mac = &cmd->data.setdelmac.mac[0];
5562 /* MAC already registered, needed in couple/uncouple case */
5563 if (cmd->hdr.return_code == 0x2005) {
5564 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5565 "already existing on %s \n",
5566 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5567 QETH_CARD_IFNAME(card));
5568 cmd->hdr.return_code = 0;
5570 if (cmd->hdr.return_code)
5571 PRINT_ERR("Could not set group MAC " \
5572 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5573 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5574 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5579 qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5581 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5582 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5583 qeth_layer2_send_setgroupmac_cb);
5587 qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5588 struct qeth_reply *reply,
5591 struct qeth_ipa_cmd *cmd;
5594 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5595 cmd = (struct qeth_ipa_cmd *) data;
5596 mac = &cmd->data.setdelmac.mac[0];
5597 if (cmd->hdr.return_code)
5598 PRINT_ERR("Could not delete group MAC " \
5599 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5600 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5601 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5606 qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5608 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5609 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5610 qeth_layer2_send_delgroupmac_cb);
5614 qeth_layer2_send_setmac_cb(struct qeth_card *card,
5615 struct qeth_reply *reply,
5618 struct qeth_ipa_cmd *cmd;
5620 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5621 cmd = (struct qeth_ipa_cmd *) data;
5622 if (cmd->hdr.return_code) {
5623 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5624 PRINT_WARN("Error in registering MAC address on " \
5625 "device %s: x%x\n", CARD_BUS_ID(card),
5626 cmd->hdr.return_code);
5627 card->info.layer2_mac_registered = 0;
5628 cmd->hdr.return_code = -EIO;
5630 card->info.layer2_mac_registered = 1;
5631 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5633 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5634 "successfully registered on device %s\n",
5635 card->dev->dev_addr[0], card->dev->dev_addr[1],
5636 card->dev->dev_addr[2], card->dev->dev_addr[3],
5637 card->dev->dev_addr[4], card->dev->dev_addr[5],
5644 qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
5646 QETH_DBF_TEXT(trace, 2, "L2Setmac");
5647 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
5648 qeth_layer2_send_setmac_cb);
5652 qeth_layer2_send_delmac_cb(struct qeth_card *card,
5653 struct qeth_reply *reply,
5656 struct qeth_ipa_cmd *cmd;
5658 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
5659 cmd = (struct qeth_ipa_cmd *) data;
5660 if (cmd->hdr.return_code) {
5661 PRINT_WARN("Error in deregistering MAC address on " \
5662 "device %s: x%x\n", CARD_BUS_ID(card),
5663 cmd->hdr.return_code);
5664 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5665 cmd->hdr.return_code = -EIO;
5668 card->info.layer2_mac_registered = 0;
5673 qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
5675 QETH_DBF_TEXT(trace, 2, "L2Delmac");
5676 if (!card->info.layer2_mac_registered)
5678 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
5679 qeth_layer2_send_delmac_cb);
5683 qeth_layer2_set_mac_address(struct net_device *dev, void *p)
5685 struct sockaddr *addr = p;
5686 struct qeth_card *card;
5689 QETH_DBF_TEXT(trace, 3, "setmac");
5691 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
5692 QETH_DBF_TEXT(trace, 3, "setmcINV");
5695 card = (struct qeth_card *) dev->priv;
5697 if (!card->options.layer2) {
5698 PRINT_WARN("Setting MAC address on %s is not supported"
5699 "in Layer 3 mode.\n", dev->name);
5700 QETH_DBF_TEXT(trace, 3, "setmcLY3");
5703 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
5704 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
5705 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
5707 rc = qeth_layer2_send_setmac(card, addr->sa_data);
5712 qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
5713 __u8 command, enum qeth_prot_versions prot)
5715 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
5716 cmd->hdr.command = command;
5717 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
5718 cmd->hdr.seqno = card->seqno.ipa;
5719 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
5720 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
5721 if (card->options.layer2)
5722 cmd->hdr.prim_version_no = 2;
5724 cmd->hdr.prim_version_no = 1;
5725 cmd->hdr.param_count = 1;
5726 cmd->hdr.prot_version = prot;
5727 cmd->hdr.ipa_supported = 0;
5728 cmd->hdr.ipa_enabled = 0;
5731 static struct qeth_cmd_buffer *
5732 qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
5733 enum qeth_prot_versions prot)
5735 struct qeth_cmd_buffer *iob;
5736 struct qeth_ipa_cmd *cmd;
5738 iob = qeth_wait_for_buffer(&card->write);
5739 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5740 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
5746 qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
5749 struct qeth_cmd_buffer *iob;
5750 struct qeth_ipa_cmd *cmd;
5752 QETH_DBF_TEXT(trace,4,"setdelmc");
5754 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
5755 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5756 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
5757 if (addr->proto == QETH_PROT_IPV6)
5758 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
5759 sizeof(struct in6_addr));
5761 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
5763 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
5768 qeth_fill_netmask(u8 *netmask, unsigned int len)
5771 for (i=0;i<16;i++) {
5776 netmask[i] = (u8)(0xFF00>>j);
5783 qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
5784 int ipacmd, unsigned int flags)
5787 struct qeth_cmd_buffer *iob;
5788 struct qeth_ipa_cmd *cmd;
5791 QETH_DBF_TEXT(trace,4,"setdelip");
5792 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
5794 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
5795 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5796 if (addr->proto == QETH_PROT_IPV6) {
5797 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
5798 sizeof(struct in6_addr));
5799 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
5800 memcpy(cmd->data.setdelip6.mask, netmask,
5801 sizeof(struct in6_addr));
5802 cmd->data.setdelip6.flags = flags;
5804 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
5805 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
5806 cmd->data.setdelip4.flags = flags;
5809 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
5815 qeth_layer2_register_addr_entry(struct qeth_card *card,
5816 struct qeth_ipaddr *addr)
5818 if (!addr->is_multicast)
5820 QETH_DBF_TEXT(trace, 2, "setgmac");
5821 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
5822 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
5826 qeth_layer2_deregister_addr_entry(struct qeth_card *card,
5827 struct qeth_ipaddr *addr)
5829 if (!addr->is_multicast)
5831 QETH_DBF_TEXT(trace, 2, "delgmac");
5832 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
5833 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
5837 qeth_layer3_register_addr_entry(struct qeth_card *card,
5838 struct qeth_ipaddr *addr)
5844 if (addr->proto == QETH_PROT_IPV4) {
5845 QETH_DBF_TEXT(trace, 2,"setaddr4");
5846 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
5847 } else if (addr->proto == QETH_PROT_IPV6) {
5848 QETH_DBF_TEXT(trace, 2, "setaddr6");
5849 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
5850 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
5852 QETH_DBF_TEXT(trace, 2, "setaddr?");
5853 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
5856 if (addr->is_multicast)
5857 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
5859 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
5862 QETH_DBF_TEXT(trace, 2, "failed");
5863 } while ((--cnt > 0) && rc);
5865 QETH_DBF_TEXT(trace, 2, "FAILED");
5866 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
5867 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
5874 qeth_layer3_deregister_addr_entry(struct qeth_card *card,
5875 struct qeth_ipaddr *addr)
5880 if (addr->proto == QETH_PROT_IPV4) {
5881 QETH_DBF_TEXT(trace, 2,"deladdr4");
5882 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
5883 } else if (addr->proto == QETH_PROT_IPV6) {
5884 QETH_DBF_TEXT(trace, 2, "deladdr6");
5885 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
5886 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
5888 QETH_DBF_TEXT(trace, 2, "deladdr?");
5889 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
5891 if (addr->is_multicast)
5892 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
5894 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
5897 QETH_DBF_TEXT(trace, 2, "failed");
5898 /* TODO: re-activate this warning as soon as we have a
5900 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
5901 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
5909 qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
5911 if (card->options.layer2)
5912 return qeth_layer2_register_addr_entry(card, addr);
5914 return qeth_layer3_register_addr_entry(card, addr);
5918 qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
5920 if (card->options.layer2)
5921 return qeth_layer2_deregister_addr_entry(card, addr);
5923 return qeth_layer3_deregister_addr_entry(card, addr);
5927 qeth_ethtool_get_tx_csum(struct net_device *dev)
5929 /* We may need to say that we support tx csum offload if
5930 * we do EDDP or TSO. There are discussions going on to
5931 * enforce rules in the stack and in ethtool that make
5932 * SG and TSO depend on HW_CSUM. At the moment there are
5934 * If we say yes here, we have to checksum outbound packets
5940 qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
5946 qeth_ethtool_get_rx_csum(struct net_device *dev)
5948 struct qeth_card *card = (struct qeth_card *)dev->priv;
5950 return (card->options.checksum_type == HW_CHECKSUMMING);
5954 qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
5956 struct qeth_card *card = (struct qeth_card *)dev->priv;
5958 if ((card->state != CARD_STATE_DOWN) &&
5959 (card->state != CARD_STATE_RECOVER))
5962 card->options.checksum_type = HW_CHECKSUMMING;
5964 card->options.checksum_type = SW_CHECKSUMMING;
5969 qeth_ethtool_get_sg(struct net_device *dev)
5971 struct qeth_card *card = (struct qeth_card *)dev->priv;
5973 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
5974 (dev->features & NETIF_F_SG));
5978 qeth_ethtool_set_sg(struct net_device *dev, u32 data)
5980 struct qeth_card *card = (struct qeth_card *)dev->priv;
5983 if (card->options.large_send != QETH_LARGE_SEND_NO)
5984 dev->features |= NETIF_F_SG;
5986 dev->features &= ~NETIF_F_SG;
5990 dev->features &= ~NETIF_F_SG;
5995 qeth_ethtool_get_tso(struct net_device *dev)
5997 struct qeth_card *card = (struct qeth_card *)dev->priv;
5999 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6000 (dev->features & NETIF_F_TSO));
6004 qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6006 struct qeth_card *card = (struct qeth_card *)dev->priv;
6009 if (card->options.large_send != QETH_LARGE_SEND_NO)
6010 dev->features |= NETIF_F_TSO;
6012 dev->features &= ~NETIF_F_TSO;
6016 dev->features &= ~NETIF_F_TSO;
6020 static struct ethtool_ops qeth_ethtool_ops = {
6021 .get_tx_csum = qeth_ethtool_get_tx_csum,
6022 .set_tx_csum = qeth_ethtool_set_tx_csum,
6023 .get_rx_csum = qeth_ethtool_get_rx_csum,
6024 .set_rx_csum = qeth_ethtool_set_rx_csum,
6025 .get_sg = qeth_ethtool_get_sg,
6026 .set_sg = qeth_ethtool_set_sg,
6027 .get_tso = qeth_ethtool_get_tso,
6028 .set_tso = qeth_ethtool_set_tso,
6032 qeth_netdev_init(struct net_device *dev)
6034 struct qeth_card *card;
6036 card = (struct qeth_card *) dev->priv;
6038 QETH_DBF_TEXT(trace,3,"initdev");
6040 dev->tx_timeout = &qeth_tx_timeout;
6041 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6042 dev->open = qeth_open;
6043 dev->stop = qeth_stop;
6044 dev->hard_start_xmit = qeth_hard_start_xmit;
6045 dev->do_ioctl = qeth_do_ioctl;
6046 dev->get_stats = qeth_get_stats;
6047 dev->change_mtu = qeth_change_mtu;
6048 dev->neigh_setup = qeth_neigh_setup;
6049 dev->set_multicast_list = qeth_set_multicast_list;
6050 #ifdef CONFIG_QETH_VLAN
6051 dev->vlan_rx_register = qeth_vlan_rx_register;
6052 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6053 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6055 dev->hard_header = card->orig_hard_header;
6056 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6057 dev->rebuild_header = NULL;
6058 dev->hard_header = NULL;
6059 if (card->options.fake_ll)
6060 dev->hard_header = qeth_fake_header;
6061 dev->header_cache_update = NULL;
6062 dev->hard_header_cache = NULL;
6064 #ifdef CONFIG_QETH_IPV6
6065 /*IPv6 address autoconfiguration stuff*/
6066 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6067 card->dev->dev_id = card->info.unique_id & 0xffff;
6069 dev->hard_header_parse = NULL;
6070 dev->set_mac_address = qeth_layer2_set_mac_address;
6071 dev->flags |= qeth_get_netdev_flags(card);
6072 if ((card->options.fake_broadcast) ||
6073 (card->info.broadcast_capable))
6074 dev->flags |= IFF_BROADCAST;
6075 dev->hard_header_len =
6076 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6077 dev->addr_len = OSA_ADDR_LEN;
6078 dev->mtu = card->info.initial_mtu;
6080 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6082 SET_MODULE_OWNER(dev);
6087 qeth_init_func_level(struct qeth_card *card)
6089 if (card->ipato.enabled) {
6090 if (card->info.type == QETH_CARD_TYPE_IQD)
6091 card->info.func_level =
6092 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6094 card->info.func_level =
6095 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6097 if (card->info.type == QETH_CARD_TYPE_IQD)
6098 card->info.func_level =
6099 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6101 card->info.func_level =
6102 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6107 * hardsetup card, initialize MPC and QDIO stuff
6110 qeth_hardsetup_card(struct qeth_card *card)
6115 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6119 PRINT_WARN("Retrying to do IDX activates.\n");
6120 ccw_device_set_offline(CARD_DDEV(card));
6121 ccw_device_set_offline(CARD_WDEV(card));
6122 ccw_device_set_offline(CARD_RDEV(card));
6123 ccw_device_set_online(CARD_RDEV(card));
6124 ccw_device_set_online(CARD_WDEV(card));
6125 ccw_device_set_online(CARD_DDEV(card));
6127 rc = qeth_qdio_clear_card(card,card->info.type==QETH_CARD_TYPE_OSAE);
6128 if (rc == -ERESTARTSYS) {
6129 QETH_DBF_TEXT(setup, 2, "break1");
6132 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6138 if ((rc = qeth_get_unitaddr(card))){
6139 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6142 qeth_init_tokens(card);
6143 qeth_init_func_level(card);
6144 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6145 if (rc == -ERESTARTSYS) {
6146 QETH_DBF_TEXT(setup, 2, "break2");
6149 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6155 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6156 if (rc == -ERESTARTSYS) {
6157 QETH_DBF_TEXT(setup, 2, "break3");
6160 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6166 if ((rc = qeth_mpc_initialize(card))){
6167 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6170 /*network device will be recovered*/
6172 card->dev->hard_header = card->orig_hard_header;
6175 /* at first set_online allocate netdev */
6176 card->dev = qeth_get_netdevice(card->info.type,
6177 card->info.link_type);
6179 qeth_qdio_clear_card(card, card->info.type ==
6180 QETH_CARD_TYPE_OSAE);
6182 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6185 card->dev->priv = card;
6186 card->orig_hard_header = card->dev->hard_header;
6187 card->dev->type = qeth_get_arphdr_type(card->info.type,
6188 card->info.link_type);
6189 card->dev->init = qeth_netdev_init;
6192 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6197 qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6200 struct qeth_ipa_cmd *cmd;
6202 QETH_DBF_TEXT(trace,4,"defadpcb");
6204 cmd = (struct qeth_ipa_cmd *) data;
6205 if (cmd->hdr.return_code == 0){
6206 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6207 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6208 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6209 #ifdef CONFIG_QETH_IPV6
6210 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6211 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6214 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6215 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6216 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6217 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6223 qeth_default_setadapterparms_cb(struct qeth_card *card,
6224 struct qeth_reply *reply,
6227 struct qeth_ipa_cmd *cmd;
6229 QETH_DBF_TEXT(trace,4,"defadpcb");
6231 cmd = (struct qeth_ipa_cmd *) data;
6232 if (cmd->hdr.return_code == 0)
6233 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6238 qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6241 struct qeth_ipa_cmd *cmd;
6243 QETH_DBF_TEXT(trace,3,"quyadpcb");
6245 cmd = (struct qeth_ipa_cmd *) data;
6246 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6247 card->info.link_type =
6248 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6249 card->options.adp.supported_funcs =
6250 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6251 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6255 qeth_query_setadapterparms(struct qeth_card *card)
6258 struct qeth_cmd_buffer *iob;
6260 QETH_DBF_TEXT(trace,3,"queryadp");
6261 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6262 sizeof(struct qeth_ipacmd_setadpparms));
6263 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6268 qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6269 struct qeth_reply *reply,
6272 struct qeth_ipa_cmd *cmd;
6274 QETH_DBF_TEXT(trace,4,"chgmaccb");
6276 cmd = (struct qeth_ipa_cmd *) data;
6277 memcpy(card->dev->dev_addr,
6278 &cmd->data.setadapterparms.data.change_addr.addr,OSA_ADDR_LEN);
6279 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6284 qeth_setadpparms_change_macaddr(struct qeth_card *card)
6287 struct qeth_cmd_buffer *iob;
6288 struct qeth_ipa_cmd *cmd;
6290 QETH_DBF_TEXT(trace,4,"chgmac");
6292 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6293 sizeof(struct qeth_ipacmd_setadpparms));
6294 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6295 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6296 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6297 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6298 card->dev->dev_addr, OSA_ADDR_LEN);
6299 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6305 qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6308 struct qeth_cmd_buffer *iob;
6309 struct qeth_ipa_cmd *cmd;
6311 QETH_DBF_TEXT(trace,4,"adpmode");
6313 iob = qeth_get_adapter_cmd(card, command,
6314 sizeof(struct qeth_ipacmd_setadpparms));
6315 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6316 cmd->data.setadapterparms.data.mode = mode;
6317 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6323 qeth_setadapter_hstr(struct qeth_card *card)
6327 QETH_DBF_TEXT(trace,4,"adphstr");
6329 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6330 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6331 card->options.broadcast_mode);
6333 PRINT_WARN("couldn't set broadcast mode on "
6335 CARD_BUS_ID(card), rc);
6336 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6337 card->options.macaddr_mode);
6339 PRINT_WARN("couldn't set macaddr mode on "
6340 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6343 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6344 PRINT_WARN("set adapter parameters not available "
6345 "to set broadcast mode, using ALLRINGS "
6346 "on device %s:\n", CARD_BUS_ID(card));
6347 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6348 PRINT_WARN("set adapter parameters not available "
6349 "to set macaddr mode, using NONCANONICAL "
6350 "on device %s:\n", CARD_BUS_ID(card));
6355 qeth_setadapter_parms(struct qeth_card *card)
6359 QETH_DBF_TEXT(setup, 2, "setadprm");
6361 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6362 PRINT_WARN("set adapter parameters not supported "
6365 QETH_DBF_TEXT(setup, 2, " notsupp");
6368 rc = qeth_query_setadapterparms(card);
6370 PRINT_WARN("couldn't set adapter parameters on device %s: "
6371 "x%x\n", CARD_BUS_ID(card), rc);
6374 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6375 rc = qeth_setadpparms_change_macaddr(card);
6377 PRINT_WARN("couldn't get MAC address on "
6379 CARD_BUS_ID(card), rc);
6382 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6383 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6384 rc = qeth_setadapter_hstr(card);
6390 qeth_layer2_initialize(struct qeth_card *card)
6395 QETH_DBF_TEXT(setup, 2, "doL2init");
6396 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6398 rc = qeth_setadpparms_change_macaddr(card);
6400 PRINT_WARN("couldn't get MAC address on "
6402 CARD_BUS_ID(card), rc);
6403 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6406 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6408 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6410 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6416 qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6417 enum qeth_prot_versions prot)
6420 struct qeth_cmd_buffer *iob;
6422 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6423 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6429 qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6433 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6435 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6440 qeth_send_stoplan(struct qeth_card *card)
6445 * TODO: according to the IPA format document page 14,
6446 * TCP/IP (we!) never issue a STOPLAN
6449 QETH_DBF_TEXT(trace, 2, "stoplan");
6451 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6456 qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6459 struct qeth_ipa_cmd *cmd;
6461 QETH_DBF_TEXT(setup, 2, "qipasscb");
6463 cmd = (struct qeth_ipa_cmd *) data;
6464 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6465 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6466 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6467 /* Disable IPV6 support hard coded for Hipersockets */
6468 if(card->info.type == QETH_CARD_TYPE_IQD)
6469 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
6471 #ifdef CONFIG_QETH_IPV6
6472 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6473 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6476 QETH_DBF_TEXT(setup, 2, "suppenbl");
6477 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6478 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6483 qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6486 struct qeth_cmd_buffer *iob;
6488 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6489 if (card->options.layer2) {
6490 QETH_DBF_TEXT(setup, 2, "noprmly2");
6494 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6495 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6499 static struct qeth_cmd_buffer *
6500 qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6501 __u16 cmd_code, __u16 len,
6502 enum qeth_prot_versions prot)
6504 struct qeth_cmd_buffer *iob;
6505 struct qeth_ipa_cmd *cmd;
6507 QETH_DBF_TEXT(trace,4,"getasscm");
6508 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6510 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6511 cmd->data.setassparms.hdr.assist_no = ipa_func;
6512 cmd->data.setassparms.hdr.length = 8 + len;
6513 cmd->data.setassparms.hdr.command_code = cmd_code;
6514 cmd->data.setassparms.hdr.return_code = 0;
6515 cmd->data.setassparms.hdr.seq_no = 0;
6521 qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6522 __u16 len, long data,
6524 (struct qeth_card *,struct qeth_reply *,unsigned long),
6528 struct qeth_ipa_cmd *cmd;
6530 QETH_DBF_TEXT(trace,4,"sendassp");
6532 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6533 if (len <= sizeof(__u32))
6534 cmd->data.setassparms.data.flags_32bit = (__u32) data;
6535 else if (len > sizeof(__u32))
6536 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6538 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6542 #ifdef CONFIG_QETH_IPV6
6544 qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6545 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6549 struct qeth_cmd_buffer *iob;
6551 QETH_DBF_TEXT(trace,4,"simassp6");
6552 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6554 rc = qeth_send_setassparms(card, iob, 0, 0,
6555 qeth_default_setassparms_cb, NULL);
6561 qeth_send_simple_setassparms(struct qeth_card *card,
6562 enum qeth_ipa_funcs ipa_func,
6563 __u16 cmd_code, long data)
6567 struct qeth_cmd_buffer *iob;
6569 QETH_DBF_TEXT(trace,4,"simassp4");
6571 length = sizeof(__u32);
6572 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6573 length, QETH_PROT_IPV4);
6574 rc = qeth_send_setassparms(card, iob, length, data,
6575 qeth_default_setassparms_cb, NULL);
6580 qeth_start_ipa_arp_processing(struct qeth_card *card)
6584 QETH_DBF_TEXT(trace,3,"ipaarp");
6586 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6587 PRINT_WARN("ARP processing not supported "
6588 "on %s!\n", QETH_CARD_IFNAME(card));
6591 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6592 IPA_CMD_ASS_START, 0);
6594 PRINT_WARN("Could not start ARP processing "
6595 "assist on %s: 0x%x\n",
6596 QETH_CARD_IFNAME(card), rc);
6602 qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6606 QETH_DBF_TEXT(trace,3,"ipaipfrg");
6608 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
6609 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
6610 QETH_CARD_IFNAME(card));
6614 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
6615 IPA_CMD_ASS_START, 0);
6617 PRINT_WARN("Could not start Hardware IP fragmentation "
6618 "assist on %s: 0x%x\n",
6619 QETH_CARD_IFNAME(card), rc);
6621 PRINT_INFO("Hardware IP fragmentation enabled \n");
6626 qeth_start_ipa_source_mac(struct qeth_card *card)
6630 QETH_DBF_TEXT(trace,3,"stsrcmac");
6632 if (!card->options.fake_ll)
6635 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
6636 PRINT_INFO("Inbound source address not "
6637 "supported on %s\n", QETH_CARD_IFNAME(card));
6641 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
6642 IPA_CMD_ASS_START, 0);
6644 PRINT_WARN("Could not start inbound source "
6645 "assist on %s: 0x%x\n",
6646 QETH_CARD_IFNAME(card), rc);
6651 qeth_start_ipa_vlan(struct qeth_card *card)
6655 QETH_DBF_TEXT(trace,3,"strtvlan");
6657 #ifdef CONFIG_QETH_VLAN
6658 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
6659 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
6663 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
6664 IPA_CMD_ASS_START,0);
6666 PRINT_WARN("Could not start vlan "
6667 "assist on %s: 0x%x\n",
6668 QETH_CARD_IFNAME(card), rc);
6670 PRINT_INFO("VLAN enabled \n");
6671 card->dev->features |=
6672 NETIF_F_HW_VLAN_FILTER |
6673 NETIF_F_HW_VLAN_TX |
6676 #endif /* QETH_VLAN */
6681 qeth_start_ipa_multicast(struct qeth_card *card)
6685 QETH_DBF_TEXT(trace,3,"stmcast");
6687 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
6688 PRINT_WARN("Multicast not supported on %s\n",
6689 QETH_CARD_IFNAME(card));
6693 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
6694 IPA_CMD_ASS_START,0);
6696 PRINT_WARN("Could not start multicast "
6697 "assist on %s: rc=%i\n",
6698 QETH_CARD_IFNAME(card), rc);
6700 PRINT_INFO("Multicast enabled\n");
6701 card->dev->flags |= IFF_MULTICAST;
6706 #ifdef CONFIG_QETH_IPV6
6708 qeth_softsetup_ipv6(struct qeth_card *card)
6712 QETH_DBF_TEXT(trace,3,"softipv6");
6714 netif_stop_queue(card->dev);
6715 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
6717 PRINT_ERR("IPv6 startlan failed on %s\n",
6718 QETH_CARD_IFNAME(card));
6721 netif_wake_queue(card->dev);
6722 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
6724 PRINT_ERR("IPv6 query ipassist failed on %s\n",
6725 QETH_CARD_IFNAME(card));
6728 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
6729 IPA_CMD_ASS_START, 3);
6731 PRINT_WARN("IPv6 start assist (version 4) failed "
6733 QETH_CARD_IFNAME(card), rc);
6736 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
6739 PRINT_WARN("IPV6 start assist (version 6) failed "
6741 QETH_CARD_IFNAME(card), rc);
6744 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
6747 PRINT_WARN("Could not enable passthrough "
6749 QETH_CARD_IFNAME(card), rc);
6752 PRINT_INFO("IPV6 enabled \n");
6759 qeth_start_ipa_ipv6(struct qeth_card *card)
6762 #ifdef CONFIG_QETH_IPV6
6763 QETH_DBF_TEXT(trace,3,"strtipv6");
6765 if (!qeth_is_supported(card, IPA_IPV6)) {
6766 PRINT_WARN("IPv6 not supported on %s\n",
6767 QETH_CARD_IFNAME(card));
6770 rc = qeth_softsetup_ipv6(card);
6776 qeth_start_ipa_broadcast(struct qeth_card *card)
6780 QETH_DBF_TEXT(trace,3,"stbrdcst");
6781 card->info.broadcast_capable = 0;
6782 if (!qeth_is_supported(card, IPA_FILTERING)) {
6783 PRINT_WARN("Broadcast not supported on %s\n",
6784 QETH_CARD_IFNAME(card));
6788 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
6789 IPA_CMD_ASS_START, 0);
6791 PRINT_WARN("Could not enable broadcasting filtering "
6793 QETH_CARD_IFNAME(card), rc);
6797 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
6798 IPA_CMD_ASS_CONFIGURE, 1);
6800 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
6801 QETH_CARD_IFNAME(card), rc);
6804 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
6805 PRINT_INFO("Broadcast enabled \n");
6806 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
6807 IPA_CMD_ASS_ENABLE, 1);
6809 PRINT_WARN("Could not set up broadcast echo filtering on "
6810 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
6813 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
6815 if (card->info.broadcast_capable)
6816 card->dev->flags |= IFF_BROADCAST;
6818 card->dev->flags &= ~IFF_BROADCAST;
6823 qeth_send_checksum_command(struct qeth_card *card)
6827 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
6828 IPA_CMD_ASS_START, 0);
6830 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
6831 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
6832 QETH_CARD_IFNAME(card), rc);
6835 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
6837 card->info.csum_mask);
6839 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
6840 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
6841 QETH_CARD_IFNAME(card), rc);
6848 qeth_start_ipa_checksum(struct qeth_card *card)
6852 QETH_DBF_TEXT(trace,3,"strtcsum");
6854 if (card->options.checksum_type == NO_CHECKSUMMING) {
6855 PRINT_WARN("Using no checksumming on %s.\n",
6856 QETH_CARD_IFNAME(card));
6859 if (card->options.checksum_type == SW_CHECKSUMMING) {
6860 PRINT_WARN("Using SW checksumming on %s.\n",
6861 QETH_CARD_IFNAME(card));
6864 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
6865 PRINT_WARN("Inbound HW Checksumming not "
6866 "supported on %s,\ncontinuing "
6867 "using Inbound SW Checksumming\n",
6868 QETH_CARD_IFNAME(card));
6869 card->options.checksum_type = SW_CHECKSUMMING;
6872 rc = qeth_send_checksum_command(card);
6874 PRINT_INFO("HW Checksumming (inbound) enabled \n");
6880 qeth_start_ipa_tso(struct qeth_card *card)
6884 QETH_DBF_TEXT(trace,3,"sttso");
6886 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
6887 PRINT_WARN("Outbound TSO not supported on %s\n",
6888 QETH_CARD_IFNAME(card));
6891 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
6892 IPA_CMD_ASS_START,0);
6894 PRINT_WARN("Could not start outbound TSO "
6895 "assist on %s: rc=%i\n",
6896 QETH_CARD_IFNAME(card), rc);
6898 PRINT_INFO("Outbound TSO enabled\n");
6900 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
6901 card->options.large_send = QETH_LARGE_SEND_NO;
6902 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
6908 qeth_start_ipassists(struct qeth_card *card)
6910 QETH_DBF_TEXT(trace,3,"strtipas");
6911 qeth_start_ipa_arp_processing(card); /* go on*/
6912 qeth_start_ipa_ip_fragmentation(card); /* go on*/
6913 qeth_start_ipa_source_mac(card); /* go on*/
6914 qeth_start_ipa_vlan(card); /* go on*/
6915 qeth_start_ipa_multicast(card); /* go on*/
6916 qeth_start_ipa_ipv6(card); /* go on*/
6917 qeth_start_ipa_broadcast(card); /* go on*/
6918 qeth_start_ipa_checksum(card); /* go on*/
6919 qeth_start_ipa_tso(card); /* go on*/
6924 qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
6925 enum qeth_prot_versions prot)
6928 struct qeth_ipa_cmd *cmd;
6929 struct qeth_cmd_buffer *iob;
6931 QETH_DBF_TEXT(trace,4,"setroutg");
6932 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
6933 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6934 cmd->data.setrtg.type = (type);
6935 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6942 qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
6943 enum qeth_prot_versions prot)
6945 if (card->info.type == QETH_CARD_TYPE_IQD) {
6948 case PRIMARY_CONNECTOR:
6949 case SECONDARY_CONNECTOR:
6950 case MULTICAST_ROUTER:
6958 case PRIMARY_ROUTER:
6959 case SECONDARY_ROUTER:
6961 case MULTICAST_ROUTER:
6962 if (qeth_is_ipafunc_supported(card, prot,
6970 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
6971 "Router status set to 'no router'.\n",
6972 ((*type == PRIMARY_ROUTER)? "primary router" :
6973 (*type == SECONDARY_ROUTER)? "secondary router" :
6974 (*type == PRIMARY_CONNECTOR)? "primary connector" :
6975 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
6976 (*type == MULTICAST_ROUTER)? "multicast router" :
6983 qeth_setrouting_v4(struct qeth_card *card)
6987 QETH_DBF_TEXT(trace,3,"setrtg4");
6989 qeth_correct_routing_type(card, &card->options.route4.type,
6992 rc = qeth_send_setrouting(card, card->options.route4.type,
6995 card->options.route4.type = NO_ROUTER;
6996 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
6997 "Type set to 'no router'.\n",
6998 rc, QETH_CARD_IFNAME(card));
7004 qeth_setrouting_v6(struct qeth_card *card)
7008 QETH_DBF_TEXT(trace,3,"setrtg6");
7009 #ifdef CONFIG_QETH_IPV6
7011 qeth_correct_routing_type(card, &card->options.route6.type,
7014 if ((card->options.route6.type == NO_ROUTER) ||
7015 ((card->info.type == QETH_CARD_TYPE_OSAE) &&
7016 (card->options.route6.type == MULTICAST_ROUTER) &&
7017 !qeth_is_supported6(card,IPA_OSA_MC_ROUTER)))
7019 rc = qeth_send_setrouting(card, card->options.route6.type,
7022 card->options.route6.type = NO_ROUTER;
7023 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7024 "Type set to 'no router'.\n",
7025 rc, QETH_CARD_IFNAME(card));
7032 qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
7036 if (card->dev == NULL) {
7037 card->options.large_send = type;
7040 netif_stop_queue(card->dev);
7041 card->options.large_send = type;
7042 switch (card->options.large_send) {
7043 case QETH_LARGE_SEND_EDDP:
7044 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7046 case QETH_LARGE_SEND_TSO:
7047 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7048 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7050 PRINT_WARN("TSO not supported on %s. "
7051 "large_send set to 'no'.\n",
7053 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7054 card->options.large_send = QETH_LARGE_SEND_NO;
7058 default: /* includes QETH_LARGE_SEND_NO */
7059 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7062 netif_wake_queue(card->dev);
7067 * softsetup card: init IPA stuff
7070 qeth_softsetup_card(struct qeth_card *card)
7074 QETH_DBF_TEXT(setup, 2, "softsetp");
7076 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7077 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7079 PRINT_WARN("LAN on card %s if offline! "
7080 "Continuing softsetup.\n",
7082 card->lan_online = 0;
7086 card->lan_online = 1;
7087 if (card->options.layer2) {
7088 card->dev->features |=
7089 NETIF_F_HW_VLAN_FILTER |
7090 NETIF_F_HW_VLAN_TX |
7092 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7093 card->info.broadcast_capable=1;
7094 if ((rc = qeth_layer2_initialize(card))) {
7095 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7098 #ifdef CONFIG_QETH_VLAN
7099 qeth_layer2_process_vlans(card, 0);
7103 if ((card->options.large_send == QETH_LARGE_SEND_EDDP) ||
7104 (card->options.large_send == QETH_LARGE_SEND_TSO))
7105 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7107 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7109 if ((rc = qeth_setadapter_parms(card)))
7110 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7111 if ((rc = qeth_start_ipassists(card)))
7112 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7113 if ((rc = qeth_setrouting_v4(card)))
7114 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7115 if ((rc = qeth_setrouting_v6(card)))
7116 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7118 netif_stop_queue(card->dev);
7122 #ifdef CONFIG_QETH_IPV6
7124 qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7127 struct qeth_ipa_cmd *cmd;
7129 cmd = (struct qeth_ipa_cmd *) data;
7130 if (cmd->hdr.return_code == 0)
7131 card->info.unique_id = *((__u16 *)
7132 &cmd->data.create_destroy_addr.unique_id[6]);
7134 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7135 UNIQUE_ID_NOT_BY_CARD;
7136 PRINT_WARN("couldn't get a unique id from the card on device "
7137 "%s (result=x%x), using default id. ipv6 "
7138 "autoconfig on other lpars may lead to duplicate "
7139 "ip addresses. please use manually "
7140 "configured ones.\n",
7141 CARD_BUS_ID(card), cmd->hdr.return_code);
7148 qeth_put_unique_id(struct qeth_card *card)
7152 #ifdef CONFIG_QETH_IPV6
7153 struct qeth_cmd_buffer *iob;
7154 struct qeth_ipa_cmd *cmd;
7156 QETH_DBF_TEXT(trace,2,"puniqeid");
7158 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7159 UNIQUE_ID_NOT_BY_CARD)
7161 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7163 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7164 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7165 card->info.unique_id;
7166 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7167 card->dev->dev_addr, OSA_ADDR_LEN);
7168 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7170 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7171 UNIQUE_ID_NOT_BY_CARD;
7180 qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7182 struct qeth_ipaddr *addr, *tmp;
7183 unsigned long flags;
7185 QETH_DBF_TEXT(trace,4,"clearip");
7186 spin_lock_irqsave(&card->ip_lock, flags);
7187 /* clear todo list */
7188 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7189 list_del(&addr->entry);
7193 while (!list_empty(&card->ip_list)) {
7194 addr = list_entry(card->ip_list.next,
7195 struct qeth_ipaddr, entry);
7196 list_del_init(&addr->entry);
7198 spin_unlock_irqrestore(&card->ip_lock, flags);
7199 qeth_deregister_addr_entry(card, addr);
7200 spin_lock_irqsave(&card->ip_lock, flags);
7202 if (!recover || addr->is_multicast) {
7206 list_add_tail(&addr->entry, card->ip_tbd_list);
7208 spin_unlock_irqrestore(&card->ip_lock, flags);
7212 qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7213 int clear_start_mask)
7215 unsigned long flags;
7217 spin_lock_irqsave(&card->thread_mask_lock, flags);
7218 card->thread_allowed_mask = threads;
7219 if (clear_start_mask)
7220 card->thread_start_mask &= threads;
7221 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7222 wake_up(&card->wait_q);
7226 qeth_threads_running(struct qeth_card *card, unsigned long threads)
7228 unsigned long flags;
7231 spin_lock_irqsave(&card->thread_mask_lock, flags);
7232 rc = (card->thread_running_mask & threads);
7233 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7238 qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7240 return wait_event_interruptible(card->wait_q,
7241 qeth_threads_running(card, threads) == 0);
7245 qeth_stop_card(struct qeth_card *card, int recovery_mode)
7249 QETH_DBF_TEXT(setup ,2,"stopcard");
7250 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7252 qeth_set_allowed_threads(card, 0, 1);
7253 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7254 return -ERESTARTSYS;
7255 if (card->read.state == CH_STATE_UP &&
7256 card->write.state == CH_STATE_UP &&
7257 (card->state == CARD_STATE_UP)) {
7259 qeth_stop(card->dev);
7262 dev_close(card->dev);
7265 if (!card->use_hard_stop) {
7266 __u8 *mac = &card->dev->dev_addr[0];
7267 rc = qeth_layer2_send_delmac(card, mac);
7268 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7269 if ((rc = qeth_send_stoplan(card)))
7270 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7272 card->state = CARD_STATE_SOFTSETUP;
7274 if (card->state == CARD_STATE_SOFTSETUP) {
7275 #ifdef CONFIG_QETH_VLAN
7276 if (card->options.layer2)
7277 qeth_layer2_process_vlans(card, 1);
7279 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7280 qeth_clear_ipacmd_list(card);
7281 card->state = CARD_STATE_HARDSETUP;
7283 if (card->state == CARD_STATE_HARDSETUP) {
7284 if ((!card->use_hard_stop) &&
7285 (!card->options.layer2))
7286 if ((rc = qeth_put_unique_id(card)))
7287 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7288 qeth_qdio_clear_card(card, 0);
7289 qeth_clear_qdio_buffers(card);
7290 qeth_clear_working_pool_list(card);
7291 card->state = CARD_STATE_DOWN;
7293 if (card->state == CARD_STATE_DOWN) {
7294 qeth_clear_cmd_buffers(&card->read);
7295 qeth_clear_cmd_buffers(&card->write);
7297 card->use_hard_stop = 0;
7303 qeth_get_unique_id(struct qeth_card *card)
7306 #ifdef CONFIG_QETH_IPV6
7307 struct qeth_cmd_buffer *iob;
7308 struct qeth_ipa_cmd *cmd;
7310 QETH_DBF_TEXT(setup, 2, "guniqeid");
7312 if (!qeth_is_supported(card,IPA_IPV6)) {
7313 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7314 UNIQUE_ID_NOT_BY_CARD;
7318 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7320 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7321 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7322 card->info.unique_id;
7324 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7326 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7327 UNIQUE_ID_NOT_BY_CARD;
7332 qeth_print_status_with_portname(struct qeth_card *card)
7337 sprintf(dbf_text, "%s", card->info.portname + 1);
7338 for (i = 0; i < 8; i++)
7340 (char) _ebcasc[(__u8) dbf_text[i]];
7342 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7343 "with link type %s (portname: %s)\n",
7347 qeth_get_cardname(card),
7348 (card->info.mcl_level[0]) ? " (level: " : "",
7349 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7350 (card->info.mcl_level[0]) ? ")" : "",
7351 qeth_get_cardname_short(card),
7357 qeth_print_status_no_portname(struct qeth_card *card)
7359 if (card->info.portname[0])
7360 printk("qeth: Device %s/%s/%s is a%s "
7361 "card%s%s%s\nwith link type %s "
7362 "(no portname needed by interface).\n",
7366 qeth_get_cardname(card),
7367 (card->info.mcl_level[0]) ? " (level: " : "",
7368 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7369 (card->info.mcl_level[0]) ? ")" : "",
7370 qeth_get_cardname_short(card));
7372 printk("qeth: Device %s/%s/%s is a%s "
7373 "card%s%s%s\nwith link type %s.\n",
7377 qeth_get_cardname(card),
7378 (card->info.mcl_level[0]) ? " (level: " : "",
7379 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7380 (card->info.mcl_level[0]) ? ")" : "",
7381 qeth_get_cardname_short(card));
7385 qeth_print_status_message(struct qeth_card *card)
7387 switch (card->info.type) {
7388 case QETH_CARD_TYPE_OSAE:
7389 /* VM will use a non-zero first character
7390 * to indicate a HiperSockets like reporting
7391 * of the level OSA sets the first character to zero
7393 if (!card->info.mcl_level[0]) {
7394 sprintf(card->info.mcl_level,"%02x%02x",
7395 card->info.mcl_level[2],
7396 card->info.mcl_level[3]);
7398 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7402 case QETH_CARD_TYPE_IQD:
7403 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7404 card->info.mcl_level[0]];
7405 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7406 card->info.mcl_level[1]];
7407 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7408 card->info.mcl_level[2]];
7409 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7410 card->info.mcl_level[3]];
7411 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7414 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7416 if (card->info.portname_required)
7417 qeth_print_status_with_portname(card);
7419 qeth_print_status_no_portname(card);
7423 qeth_register_netdev(struct qeth_card *card)
7425 QETH_DBF_TEXT(setup, 3, "regnetd");
7426 if (card->dev->reg_state != NETREG_UNINITIALIZED) {
7427 qeth_netdev_init(card->dev);
7431 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7432 return register_netdev(card->dev);
7436 qeth_start_again(struct qeth_card *card, int recovery_mode)
7438 QETH_DBF_TEXT(setup ,2, "startag");
7441 qeth_open(card->dev);
7444 dev_open(card->dev);
7447 /* this also sets saved unicast addresses */
7448 qeth_set_multicast_list(card->dev);
7452 /* Layer 2 specific stuff */
7453 #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7454 if (card->options.option == value) { \
7455 PRINT_ERR("%s not supported with layer 2 " \
7456 "functionality, ignoring option on read" \
7457 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7458 card->options.option = reset_value; \
7460 #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7461 if (card->options.option != value) { \
7462 PRINT_ERR("%s not supported with layer 2 " \
7463 "functionality, ignoring option on read" \
7464 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7465 card->options.option = reset_value; \
7469 static void qeth_make_parameters_consistent(struct qeth_card *card)
7472 if (card->options.layer2) {
7473 if (card->info.type == QETH_CARD_TYPE_IQD) {
7474 PRINT_ERR("Device %s does not support " \
7475 "layer 2 functionality. " \
7476 "Ignoring layer2 option.\n",CARD_BUS_ID(card));
7478 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7479 "Routing options are");
7480 #ifdef CONFIG_QETH_IPV6
7481 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7482 "Routing options are");
7484 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7485 QETH_CHECKSUM_DEFAULT,
7486 "Checksumming options are");
7487 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7488 QETH_TR_BROADCAST_ALLRINGS,
7489 "Broadcast mode options are");
7490 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7491 QETH_TR_MACADDR_NONCANONICAL,
7492 "Canonical MAC addr options are");
7493 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7494 "Broadcast faking options are");
7495 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7496 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7497 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
7503 __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
7505 struct qeth_card *card = gdev->dev.driver_data;
7507 enum qeth_card_states recover_flag;
7510 QETH_DBF_TEXT(setup ,2, "setonlin");
7511 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7513 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7514 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7515 PRINT_WARN("set_online of card %s interrupted by user!\n",
7517 return -ERESTARTSYS;
7520 recover_flag = card->state;
7521 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7522 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7523 (rc = ccw_device_set_online(CARD_DDEV(card)))){
7524 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7528 if (card->options.layer2)
7529 qeth_make_parameters_consistent(card);
7531 if ((rc = qeth_hardsetup_card(card))){
7532 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7535 card->state = CARD_STATE_HARDSETUP;
7537 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7538 rc = qeth_get_unique_id(card);
7540 if (rc && card->options.layer2 == 0) {
7541 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7544 qeth_print_status_message(card);
7545 if ((rc = qeth_register_netdev(card))){
7546 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7549 if ((rc = qeth_softsetup_card(card))){
7550 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7553 card->state = CARD_STATE_SOFTSETUP;
7555 if ((rc = qeth_init_qdio_queues(card))){
7556 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7559 /*maybe it was set offline without ifconfig down
7560 * we can also use this state for recovery purposes*/
7561 qeth_set_allowed_threads(card, 0xffffffff, 0);
7562 if (recover_flag == CARD_STATE_RECOVER)
7563 qeth_start_again(card, recovery_mode);
7564 qeth_notify_processes();
7567 card->use_hard_stop = 1;
7568 qeth_stop_card(card, 0);
7569 ccw_device_set_offline(CARD_DDEV(card));
7570 ccw_device_set_offline(CARD_WDEV(card));
7571 ccw_device_set_offline(CARD_RDEV(card));
7572 if (recover_flag == CARD_STATE_RECOVER)
7573 card->state = CARD_STATE_RECOVER;
7575 card->state = CARD_STATE_DOWN;
7580 qeth_set_online(struct ccwgroup_device *gdev)
7582 return __qeth_set_online(gdev, 0);
7585 static struct ccw_device_id qeth_ids[] = {
7586 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE},
7587 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD},
7590 MODULE_DEVICE_TABLE(ccw, qeth_ids);
7592 struct device *qeth_root_dev = NULL;
7594 struct ccwgroup_driver qeth_ccwgroup_driver = {
7595 .owner = THIS_MODULE,
7597 .driver_id = 0xD8C5E3C8,
7598 .probe = qeth_probe_device,
7599 .remove = qeth_remove_device,
7600 .set_online = qeth_set_online,
7601 .set_offline = qeth_set_offline,
7604 struct ccw_driver qeth_ccw_driver = {
7607 .probe = ccwgroup_probe_ccwdev,
7608 .remove = ccwgroup_remove_ccwdev,
7613 qeth_unregister_dbf_views(void)
7616 debug_unregister(qeth_dbf_setup);
7618 debug_unregister(qeth_dbf_qerr);
7620 debug_unregister(qeth_dbf_sense);
7622 debug_unregister(qeth_dbf_misc);
7624 debug_unregister(qeth_dbf_data);
7625 if (qeth_dbf_control)
7626 debug_unregister(qeth_dbf_control);
7628 debug_unregister(qeth_dbf_trace);
7631 qeth_register_dbf_views(void)
7633 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
7634 QETH_DBF_SETUP_PAGES,
7635 QETH_DBF_SETUP_NR_AREAS,
7636 QETH_DBF_SETUP_LEN);
7637 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
7638 QETH_DBF_MISC_PAGES,
7639 QETH_DBF_MISC_NR_AREAS,
7641 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
7642 QETH_DBF_DATA_PAGES,
7643 QETH_DBF_DATA_NR_AREAS,
7645 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
7646 QETH_DBF_CONTROL_PAGES,
7647 QETH_DBF_CONTROL_NR_AREAS,
7648 QETH_DBF_CONTROL_LEN);
7649 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
7650 QETH_DBF_SENSE_PAGES,
7651 QETH_DBF_SENSE_NR_AREAS,
7652 QETH_DBF_SENSE_LEN);
7653 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
7654 QETH_DBF_QERR_PAGES,
7655 QETH_DBF_QERR_NR_AREAS,
7657 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
7658 QETH_DBF_TRACE_PAGES,
7659 QETH_DBF_TRACE_NR_AREAS,
7660 QETH_DBF_TRACE_LEN);
7662 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
7663 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
7664 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
7665 (qeth_dbf_trace == NULL)) {
7666 qeth_unregister_dbf_views();
7669 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
7670 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
7672 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
7673 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
7675 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
7676 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
7678 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
7679 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
7681 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
7682 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
7684 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
7685 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
7687 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
7688 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
7693 #ifdef CONFIG_QETH_IPV6
7694 extern struct neigh_table arp_tbl;
7695 static struct neigh_ops *arp_direct_ops;
7696 static int (*qeth_old_arp_constructor) (struct neighbour *);
7698 static struct neigh_ops arp_direct_ops_template = {
7702 .error_report = NULL,
7703 .output = dev_queue_xmit,
7704 .connected_output = dev_queue_xmit,
7705 .hh_output = dev_queue_xmit,
7706 .queue_xmit = dev_queue_xmit
7710 qeth_arp_constructor(struct neighbour *neigh)
7712 struct net_device *dev = neigh->dev;
7713 struct in_device *in_dev;
7714 struct neigh_parms *parms;
7715 struct qeth_card *card;
7717 card = qeth_get_card_from_dev(dev);
7720 if((card->options.layer2) ||
7721 (card->dev->hard_header == qeth_fake_header))
7725 in_dev = __in_dev_get_rcu(dev);
7726 if (in_dev == NULL) {
7731 parms = in_dev->arp_parms;
7732 __neigh_parms_put(neigh->parms);
7733 neigh->parms = neigh_parms_clone(parms);
7736 neigh->type = inet_addr_type(*(u32 *) neigh->primary_key);
7737 neigh->nud_state = NUD_NOARP;
7738 neigh->ops = arp_direct_ops;
7739 neigh->output = neigh->ops->queue_xmit;
7742 return qeth_old_arp_constructor(neigh);
7744 #endif /*CONFIG_QETH_IPV6*/
7747 * IP address takeover related functions
7750 qeth_clear_ipato_list(struct qeth_card *card)
7752 struct qeth_ipato_entry *ipatoe, *tmp;
7753 unsigned long flags;
7755 spin_lock_irqsave(&card->ip_lock, flags);
7756 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
7757 list_del(&ipatoe->entry);
7760 spin_unlock_irqrestore(&card->ip_lock, flags);
7764 qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
7766 struct qeth_ipato_entry *ipatoe;
7767 unsigned long flags;
7770 QETH_DBF_TEXT(trace, 2, "addipato");
7771 spin_lock_irqsave(&card->ip_lock, flags);
7772 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
7773 if (ipatoe->proto != new->proto)
7775 if (!memcmp(ipatoe->addr, new->addr,
7776 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
7777 (ipatoe->mask_bits == new->mask_bits)){
7778 PRINT_WARN("ipato entry already exists!\n");
7784 list_add_tail(&new->entry, &card->ipato.entries);
7786 spin_unlock_irqrestore(&card->ip_lock, flags);
7791 qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
7792 u8 *addr, int mask_bits)
7794 struct qeth_ipato_entry *ipatoe, *tmp;
7795 unsigned long flags;
7797 QETH_DBF_TEXT(trace, 2, "delipato");
7798 spin_lock_irqsave(&card->ip_lock, flags);
7799 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
7800 if (ipatoe->proto != proto)
7802 if (!memcmp(ipatoe->addr, addr,
7803 (proto == QETH_PROT_IPV4)? 4:16) &&
7804 (ipatoe->mask_bits == mask_bits)){
7805 list_del(&ipatoe->entry);
7809 spin_unlock_irqrestore(&card->ip_lock, flags);
7813 qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
7818 for (i = 0; i < len; ++i){
7820 for (j = 7; j >= 0; --j){
7821 bits[i*8 + j] = octet & 1;
7828 qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
7830 struct qeth_ipato_entry *ipatoe;
7831 u8 addr_bits[128] = {0, };
7832 u8 ipatoe_bits[128] = {0, };
7835 if (!card->ipato.enabled)
7838 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
7839 (addr->proto == QETH_PROT_IPV4)? 4:16);
7840 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
7841 if (addr->proto != ipatoe->proto)
7843 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
7844 (ipatoe->proto==QETH_PROT_IPV4) ?
7846 if (addr->proto == QETH_PROT_IPV4)
7847 rc = !memcmp(addr_bits, ipatoe_bits,
7848 min(32, ipatoe->mask_bits));
7850 rc = !memcmp(addr_bits, ipatoe_bits,
7851 min(128, ipatoe->mask_bits));
7856 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
7858 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
7865 * VIPA related functions
7868 qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
7871 struct qeth_ipaddr *ipaddr;
7872 unsigned long flags;
7875 ipaddr = qeth_get_addr_buffer(proto);
7877 if (proto == QETH_PROT_IPV4){
7878 QETH_DBF_TEXT(trace, 2, "addvipa4");
7879 memcpy(&ipaddr->u.a4.addr, addr, 4);
7880 ipaddr->u.a4.mask = 0;
7881 #ifdef CONFIG_QETH_IPV6
7882 } else if (proto == QETH_PROT_IPV6){
7883 QETH_DBF_TEXT(trace, 2, "addvipa6");
7884 memcpy(&ipaddr->u.a6.addr, addr, 16);
7885 ipaddr->u.a6.pfxlen = 0;
7888 ipaddr->type = QETH_IP_TYPE_VIPA;
7889 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
7890 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
7893 spin_lock_irqsave(&card->ip_lock, flags);
7894 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
7895 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
7897 spin_unlock_irqrestore(&card->ip_lock, flags);
7899 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
7902 if (!qeth_add_ip(card, ipaddr))
7904 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
7905 schedule_work(&card->kernel_thread_starter);
7910 qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
7913 struct qeth_ipaddr *ipaddr;
7915 ipaddr = qeth_get_addr_buffer(proto);
7917 if (proto == QETH_PROT_IPV4){
7918 QETH_DBF_TEXT(trace, 2, "delvipa4");
7919 memcpy(&ipaddr->u.a4.addr, addr, 4);
7920 ipaddr->u.a4.mask = 0;
7921 #ifdef CONFIG_QETH_IPV6
7922 } else if (proto == QETH_PROT_IPV6){
7923 QETH_DBF_TEXT(trace, 2, "delvipa6");
7924 memcpy(&ipaddr->u.a6.addr, addr, 16);
7925 ipaddr->u.a6.pfxlen = 0;
7928 ipaddr->type = QETH_IP_TYPE_VIPA;
7931 if (!qeth_delete_ip(card, ipaddr))
7933 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
7934 schedule_work(&card->kernel_thread_starter);
7938 * proxy ARP related functions
7941 qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
7944 struct qeth_ipaddr *ipaddr;
7945 unsigned long flags;
7948 ipaddr = qeth_get_addr_buffer(proto);
7950 if (proto == QETH_PROT_IPV4){
7951 QETH_DBF_TEXT(trace, 2, "addrxip4");
7952 memcpy(&ipaddr->u.a4.addr, addr, 4);
7953 ipaddr->u.a4.mask = 0;
7954 #ifdef CONFIG_QETH_IPV6
7955 } else if (proto == QETH_PROT_IPV6){
7956 QETH_DBF_TEXT(trace, 2, "addrxip6");
7957 memcpy(&ipaddr->u.a6.addr, addr, 16);
7958 ipaddr->u.a6.pfxlen = 0;
7961 ipaddr->type = QETH_IP_TYPE_RXIP;
7962 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
7963 ipaddr->del_flags = 0;
7966 spin_lock_irqsave(&card->ip_lock, flags);
7967 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
7968 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
7970 spin_unlock_irqrestore(&card->ip_lock, flags);
7972 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
7975 if (!qeth_add_ip(card, ipaddr))
7977 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
7978 schedule_work(&card->kernel_thread_starter);
7983 qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
7986 struct qeth_ipaddr *ipaddr;
7988 ipaddr = qeth_get_addr_buffer(proto);
7990 if (proto == QETH_PROT_IPV4){
7991 QETH_DBF_TEXT(trace, 2, "addrxip4");
7992 memcpy(&ipaddr->u.a4.addr, addr, 4);
7993 ipaddr->u.a4.mask = 0;
7994 #ifdef CONFIG_QETH_IPV6
7995 } else if (proto == QETH_PROT_IPV6){
7996 QETH_DBF_TEXT(trace, 2, "addrxip6");
7997 memcpy(&ipaddr->u.a6.addr, addr, 16);
7998 ipaddr->u.a6.pfxlen = 0;
8001 ipaddr->type = QETH_IP_TYPE_RXIP;
8004 if (!qeth_delete_ip(card, ipaddr))
8006 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8007 schedule_work(&card->kernel_thread_starter);
8014 qeth_ip_event(struct notifier_block *this,
8015 unsigned long event,void *ptr)
8017 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8018 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8019 struct qeth_ipaddr *addr;
8020 struct qeth_card *card;
8022 QETH_DBF_TEXT(trace,3,"ipevent");
8023 card = qeth_get_card_from_dev(dev);
8026 if (card->options.layer2)
8029 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8031 addr->u.a4.addr = ifa->ifa_address;
8032 addr->u.a4.mask = ifa->ifa_mask;
8033 addr->type = QETH_IP_TYPE_NORMAL;
8039 if (!qeth_add_ip(card, addr))
8043 if (!qeth_delete_ip(card, addr))
8049 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8050 schedule_work(&card->kernel_thread_starter);
8055 static struct notifier_block qeth_ip_notifier = {
8060 #ifdef CONFIG_QETH_IPV6
8062 * IPv6 event handler
8065 qeth_ip6_event(struct notifier_block *this,
8066 unsigned long event,void *ptr)
8069 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8070 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8071 struct qeth_ipaddr *addr;
8072 struct qeth_card *card;
8074 QETH_DBF_TEXT(trace,3,"ip6event");
8076 card = qeth_get_card_from_dev(dev);
8079 if (!qeth_is_supported(card, IPA_IPV6))
8082 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8084 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8085 addr->u.a6.pfxlen = ifa->prefix_len;
8086 addr->type = QETH_IP_TYPE_NORMAL;
8092 if (!qeth_add_ip(card, addr))
8096 if (!qeth_delete_ip(card, addr))
8102 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8103 schedule_work(&card->kernel_thread_starter);
8108 static struct notifier_block qeth_ip6_notifier = {
8115 __qeth_reboot_event_card(struct device *dev, void *data)
8117 struct qeth_card *card;
8119 card = (struct qeth_card *) dev->driver_data;
8120 qeth_clear_ip_list(card, 0, 0);
8121 qeth_qdio_clear_card(card, 0);
8126 qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8129 driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8130 __qeth_reboot_event_card);
8135 static struct notifier_block qeth_reboot_notifier = {
8141 qeth_register_notifiers(void)
8145 QETH_DBF_TEXT(trace,5,"regnotif");
8146 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8148 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8150 #ifdef CONFIG_QETH_IPV6
8151 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8156 #ifdef CONFIG_QETH_IPV6
8158 unregister_inetaddr_notifier(&qeth_ip_notifier);
8161 unregister_reboot_notifier(&qeth_reboot_notifier);
8166 * unregister all event notifiers
8169 qeth_unregister_notifiers(void)
8172 QETH_DBF_TEXT(trace,5,"unregnot");
8173 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8174 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8175 #ifdef CONFIG_QETH_IPV6
8176 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8177 #endif /* QETH_IPV6 */
8181 #ifdef CONFIG_QETH_IPV6
8183 qeth_ipv6_init(void)
8185 qeth_old_arp_constructor = arp_tbl.constructor;
8186 write_lock(&arp_tbl.lock);
8187 arp_tbl.constructor = qeth_arp_constructor;
8188 write_unlock(&arp_tbl.lock);
8190 arp_direct_ops = (struct neigh_ops*)
8191 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8192 if (!arp_direct_ops)
8195 memcpy(arp_direct_ops, &arp_direct_ops_template,
8196 sizeof(struct neigh_ops));
8202 qeth_ipv6_uninit(void)
8204 write_lock(&arp_tbl.lock);
8205 arp_tbl.constructor = qeth_old_arp_constructor;
8206 write_unlock(&arp_tbl.lock);
8207 kfree(arp_direct_ops);
8209 #endif /* CONFIG_QETH_IPV6 */
8212 qeth_sysfs_unregister(void)
8214 qeth_remove_driver_attributes();
8215 ccw_driver_unregister(&qeth_ccw_driver);
8216 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8217 s390_root_dev_unregister(qeth_root_dev);
8220 * register qeth at sysfs
8223 qeth_sysfs_register(void)
8227 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8230 rc = ccw_driver_register(&qeth_ccw_driver);
8233 rc = qeth_create_driver_attributes();
8236 qeth_root_dev = s390_root_dev_register("qeth");
8237 if (IS_ERR(qeth_root_dev)) {
8238 rc = PTR_ERR(qeth_root_dev);
8252 PRINT_INFO("loading %s (%s/%s/%s/%s/%s/%s/%s %s %s)\n",
8253 version, VERSION_QETH_C, VERSION_QETH_H,
8254 VERSION_QETH_MPC_H, VERSION_QETH_MPC_C,
8255 VERSION_QETH_FS_H, VERSION_QETH_PROC_C,
8256 VERSION_QETH_SYS_C, QETH_VERSION_IPV6,
8259 INIT_LIST_HEAD(&qeth_card_list.list);
8260 INIT_LIST_HEAD(&qeth_notify_list);
8261 spin_lock_init(&qeth_notify_lock);
8262 rwlock_init(&qeth_card_list.rwlock);
8264 if (qeth_register_dbf_views())
8266 if (qeth_sysfs_register())
8269 #ifdef CONFIG_QETH_IPV6
8270 if (qeth_ipv6_init()) {
8271 PRINT_ERR("Out of memory during ipv6 init.\n");
8274 #endif /* QETH_IPV6 */
8275 if (qeth_register_notifiers())
8277 if (qeth_create_procfs_entries())
8283 qeth_unregister_notifiers();
8285 #ifdef CONFIG_QETH_IPV6
8287 #endif /* QETH_IPV6 */
8289 qeth_sysfs_unregister();
8290 qeth_unregister_dbf_views();
8292 PRINT_ERR("Initialization failed");
8297 __exit qeth_exit(void)
8299 struct qeth_card *card, *tmp;
8300 unsigned long flags;
8302 QETH_DBF_TEXT(trace,1, "cleanup.");
8305 * Weed would not need to clean up our devices here, because the
8306 * common device layer calls qeth_remove_device for each device
8307 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8308 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8309 * qeth_remove_device called by the common device layer would otherwise
8310 * do a "hard" shutdown (card->use_hard_stop is set to one in
8311 * qeth_remove_device).
8314 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8315 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8316 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8317 qeth_set_offline(card->gdev);
8318 qeth_remove_device(card->gdev);
8321 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8322 #ifdef CONFIG_QETH_IPV6
8325 qeth_unregister_notifiers();
8326 qeth_remove_procfs_entries();
8327 qeth_sysfs_unregister();
8328 qeth_unregister_dbf_views();
8329 printk("qeth: removed\n");
8332 module_init(qeth_init);
8333 module_exit(qeth_exit);
8334 MODULE_AUTHOR("Frank Pavlic <pavlic@de.ibm.com>");
8335 MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8336 "Copyright 2000,2003 IBM Corporation\n");
8338 MODULE_LICENSE("GPL");