2 * drivers/s390/net/qeth_core_main.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
11 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
20 #include <linux/ipv6.h>
21 #include <linux/tcp.h>
22 #include <linux/mii.h>
23 #include <linux/kthread.h>
25 #include <asm/ebcdic.h>
27 #include <asm/s390_rdev.h>
29 #include "qeth_core.h"
30 #include "qeth_core_offl.h"
32 struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
33 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
35 [QETH_DBF_SETUP] = {"qeth_setup",
36 8, 1, 8, 5, &debug_hex_ascii_view, NULL},
37 [QETH_DBF_QERR] = {"qeth_qerr",
38 2, 1, 8, 2, &debug_hex_ascii_view, NULL},
39 [QETH_DBF_TRACE] = {"qeth_trace",
40 4, 1, 8, 3, &debug_hex_ascii_view, NULL},
41 [QETH_DBF_MSG] = {"qeth_msg",
42 8, 1, 128, 3, &debug_sprintf_view, NULL},
43 [QETH_DBF_SENSE] = {"qeth_sense",
44 2, 1, 64, 2, &debug_hex_ascii_view, NULL},
45 [QETH_DBF_MISC] = {"qeth_misc",
46 2, 1, 256, 2, &debug_hex_ascii_view, NULL},
47 [QETH_DBF_CTRL] = {"qeth_control",
48 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
50 EXPORT_SYMBOL_GPL(qeth_dbf);
52 struct qeth_card_list_struct qeth_core_card_list;
53 EXPORT_SYMBOL_GPL(qeth_core_card_list);
54 struct kmem_cache *qeth_core_header_cache;
55 EXPORT_SYMBOL_GPL(qeth_core_header_cache);
57 static struct device *qeth_core_root_dev;
58 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
59 static struct lock_class_key qdio_out_skb_queue_key;
61 static void qeth_send_control_data_cb(struct qeth_channel *,
62 struct qeth_cmd_buffer *);
63 static int qeth_issue_next_read(struct qeth_card *);
64 static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *);
65 static void qeth_setup_ccw(struct qeth_channel *, unsigned char *, __u32);
66 static void qeth_free_buffer_pool(struct qeth_card *);
67 static int qeth_qdio_establish(struct qeth_card *);
70 static inline void __qeth_fill_buffer_frag(struct sk_buff *skb,
71 struct qdio_buffer *buffer, int is_tso,
72 int *next_element_to_fill)
74 struct skb_frag_struct *frag;
77 int element, cnt, dlen;
79 fragno = skb_shinfo(skb)->nr_frags;
80 element = *next_element_to_fill;
84 buffer->element[element].flags =
85 SBAL_FLAGS_MIDDLE_FRAG;
87 buffer->element[element].flags =
88 SBAL_FLAGS_FIRST_FRAG;
89 dlen = skb->len - skb->data_len;
91 buffer->element[element].addr = skb->data;
92 buffer->element[element].length = dlen;
95 for (cnt = 0; cnt < fragno; cnt++) {
96 frag = &skb_shinfo(skb)->frags[cnt];
97 addr = (page_to_pfn(frag->page) << PAGE_SHIFT) +
99 buffer->element[element].addr = (char *)addr;
100 buffer->element[element].length = frag->size;
101 if (cnt < (fragno - 1))
102 buffer->element[element].flags =
103 SBAL_FLAGS_MIDDLE_FRAG;
105 buffer->element[element].flags =
106 SBAL_FLAGS_LAST_FRAG;
109 *next_element_to_fill = element;
112 static inline const char *qeth_get_cardname(struct qeth_card *card)
114 if (card->info.guestlan) {
115 switch (card->info.type) {
116 case QETH_CARD_TYPE_OSAE:
117 return " Guest LAN QDIO";
118 case QETH_CARD_TYPE_IQD:
119 return " Guest LAN Hiper";
124 switch (card->info.type) {
125 case QETH_CARD_TYPE_OSAE:
126 return " OSD Express";
127 case QETH_CARD_TYPE_IQD:
128 return " HiperSockets";
129 case QETH_CARD_TYPE_OSN:
138 /* max length to be returned: 14 */
139 const char *qeth_get_cardname_short(struct qeth_card *card)
141 if (card->info.guestlan) {
142 switch (card->info.type) {
143 case QETH_CARD_TYPE_OSAE:
144 return "GuestLAN QDIO";
145 case QETH_CARD_TYPE_IQD:
146 return "GuestLAN Hiper";
151 switch (card->info.type) {
152 case QETH_CARD_TYPE_OSAE:
153 switch (card->info.link_type) {
154 case QETH_LINK_TYPE_FAST_ETH:
156 case QETH_LINK_TYPE_HSTR:
158 case QETH_LINK_TYPE_GBIT_ETH:
160 case QETH_LINK_TYPE_10GBIT_ETH:
162 case QETH_LINK_TYPE_LANE_ETH100:
163 return "OSD_FE_LANE";
164 case QETH_LINK_TYPE_LANE_TR:
165 return "OSD_TR_LANE";
166 case QETH_LINK_TYPE_LANE_ETH1000:
167 return "OSD_GbE_LANE";
168 case QETH_LINK_TYPE_LANE:
169 return "OSD_ATM_LANE";
171 return "OSD_Express";
173 case QETH_CARD_TYPE_IQD:
174 return "HiperSockets";
175 case QETH_CARD_TYPE_OSN:
184 void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
185 int clear_start_mask)
189 spin_lock_irqsave(&card->thread_mask_lock, flags);
190 card->thread_allowed_mask = threads;
191 if (clear_start_mask)
192 card->thread_start_mask &= threads;
193 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
194 wake_up(&card->wait_q);
196 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads);
198 int qeth_threads_running(struct qeth_card *card, unsigned long threads)
203 spin_lock_irqsave(&card->thread_mask_lock, flags);
204 rc = (card->thread_running_mask & threads);
205 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
208 EXPORT_SYMBOL_GPL(qeth_threads_running);
210 int qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
212 return wait_event_interruptible(card->wait_q,
213 qeth_threads_running(card, threads) == 0);
215 EXPORT_SYMBOL_GPL(qeth_wait_for_threads);
217 void qeth_clear_working_pool_list(struct qeth_card *card)
219 struct qeth_buffer_pool_entry *pool_entry, *tmp;
221 QETH_DBF_TEXT(TRACE, 5, "clwrklst");
222 list_for_each_entry_safe(pool_entry, tmp,
223 &card->qdio.in_buf_pool.entry_list, list){
224 list_del(&pool_entry->list);
227 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list);
229 static int qeth_alloc_buffer_pool(struct qeth_card *card)
231 struct qeth_buffer_pool_entry *pool_entry;
235 QETH_DBF_TEXT(TRACE, 5, "alocpool");
236 for (i = 0; i < card->qdio.init_pool.buf_count; ++i) {
237 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
239 qeth_free_buffer_pool(card);
242 for (j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j) {
243 ptr = (void *) __get_free_page(GFP_KERNEL);
246 free_page((unsigned long)
247 pool_entry->elements[--j]);
249 qeth_free_buffer_pool(card);
252 pool_entry->elements[j] = ptr;
254 list_add(&pool_entry->init_list,
255 &card->qdio.init_pool.entry_list);
260 int qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
262 QETH_DBF_TEXT(TRACE, 2, "realcbp");
264 if ((card->state != CARD_STATE_DOWN) &&
265 (card->state != CARD_STATE_RECOVER))
268 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
269 qeth_clear_working_pool_list(card);
270 qeth_free_buffer_pool(card);
271 card->qdio.in_buf_pool.buf_count = bufcnt;
272 card->qdio.init_pool.buf_count = bufcnt;
273 return qeth_alloc_buffer_pool(card);
276 int qeth_set_large_send(struct qeth_card *card,
277 enum qeth_large_send_types type)
281 if (card->dev == NULL) {
282 card->options.large_send = type;
285 if (card->state == CARD_STATE_UP)
286 netif_tx_disable(card->dev);
287 card->options.large_send = type;
288 switch (card->options.large_send) {
289 case QETH_LARGE_SEND_EDDP:
290 if (card->info.type != QETH_CARD_TYPE_IQD) {
291 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
294 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
296 card->options.large_send = QETH_LARGE_SEND_NO;
300 case QETH_LARGE_SEND_TSO:
301 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
302 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
305 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
307 card->options.large_send = QETH_LARGE_SEND_NO;
311 default: /* includes QETH_LARGE_SEND_NO */
312 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
316 if (card->state == CARD_STATE_UP)
317 netif_wake_queue(card->dev);
320 EXPORT_SYMBOL_GPL(qeth_set_large_send);
322 static int qeth_issue_next_read(struct qeth_card *card)
325 struct qeth_cmd_buffer *iob;
327 QETH_DBF_TEXT(TRACE, 5, "issnxrd");
328 if (card->read.state != CH_STATE_UP)
330 iob = qeth_get_buffer(&card->read);
332 dev_warn(&card->gdev->dev, "The qeth device driver "
333 "failed to recover an error on the device\n");
334 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
335 "available\n", dev_name(&card->gdev->dev));
338 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
339 QETH_DBF_TEXT(TRACE, 6, "noirqpnd");
340 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
343 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
344 "rc=%i\n", dev_name(&card->gdev->dev), rc);
345 atomic_set(&card->read.irq_pending, 0);
346 qeth_schedule_recovery(card);
347 wake_up(&card->wait_q);
352 static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card)
354 struct qeth_reply *reply;
356 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
358 atomic_set(&reply->refcnt, 1);
359 atomic_set(&reply->received, 0);
365 static void qeth_get_reply(struct qeth_reply *reply)
367 WARN_ON(atomic_read(&reply->refcnt) <= 0);
368 atomic_inc(&reply->refcnt);
371 static void qeth_put_reply(struct qeth_reply *reply)
373 WARN_ON(atomic_read(&reply->refcnt) <= 0);
374 if (atomic_dec_and_test(&reply->refcnt))
378 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
379 struct qeth_card *card)
382 int com = cmd->hdr.command;
383 ipa_name = qeth_get_ipa_cmd_name(com);
385 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s returned x%X \"%s\"\n",
386 ipa_name, com, QETH_CARD_IFNAME(card),
387 rc, qeth_get_ipa_msg(rc));
389 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s succeeded\n",
390 ipa_name, com, QETH_CARD_IFNAME(card));
393 static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
394 struct qeth_cmd_buffer *iob)
396 struct qeth_ipa_cmd *cmd = NULL;
398 QETH_DBF_TEXT(TRACE, 5, "chkipad");
399 if (IS_IPA(iob->data)) {
400 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
401 if (IS_IPA_REPLY(cmd)) {
402 if (cmd->hdr.command < IPA_CMD_SETCCID ||
403 cmd->hdr.command > IPA_CMD_MODCCID)
404 qeth_issue_ipa_msg(cmd,
405 cmd->hdr.return_code, card);
408 switch (cmd->hdr.command) {
409 case IPA_CMD_STOPLAN:
410 dev_warn(&card->gdev->dev,
411 "The link for interface %s on CHPID"
413 QETH_CARD_IFNAME(card),
415 card->lan_online = 0;
416 if (card->dev && netif_carrier_ok(card->dev))
417 netif_carrier_off(card->dev);
419 case IPA_CMD_STARTLAN:
420 dev_info(&card->gdev->dev,
421 "The link for %s on CHPID 0x%X has"
423 QETH_CARD_IFNAME(card),
425 netif_carrier_on(card->dev);
426 card->lan_online = 1;
427 qeth_schedule_recovery(card);
429 case IPA_CMD_MODCCID:
431 case IPA_CMD_REGISTER_LOCAL_ADDR:
432 QETH_DBF_TEXT(TRACE, 3, "irla");
434 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
435 QETH_DBF_TEXT(TRACE, 3, "urla");
438 QETH_DBF_MESSAGE(2, "Received data is IPA "
439 "but not a reply!\n");
447 void qeth_clear_ipacmd_list(struct qeth_card *card)
449 struct qeth_reply *reply, *r;
452 QETH_DBF_TEXT(TRACE, 4, "clipalst");
454 spin_lock_irqsave(&card->lock, flags);
455 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
456 qeth_get_reply(reply);
458 atomic_inc(&reply->received);
459 list_del_init(&reply->list);
460 wake_up(&reply->wait_q);
461 qeth_put_reply(reply);
463 spin_unlock_irqrestore(&card->lock, flags);
465 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list);
467 static int qeth_check_idx_response(unsigned char *buffer)
472 QETH_DBF_HEX(CTRL, 2, buffer, QETH_DBF_CTRL_LEN);
473 if ((buffer[2] & 0xc0) == 0xc0) {
474 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
475 "with cause code 0x%02x%s\n",
477 ((buffer[4] == 0x22) ?
478 " -- try another portname" : ""));
479 QETH_DBF_TEXT(TRACE, 2, "ckidxres");
480 QETH_DBF_TEXT(TRACE, 2, " idxterm");
481 QETH_DBF_TEXT_(TRACE, 2, " rc%d", -EIO);
487 static void qeth_setup_ccw(struct qeth_channel *channel, unsigned char *iob,
490 struct qeth_card *card;
492 QETH_DBF_TEXT(TRACE, 4, "setupccw");
493 card = CARD_FROM_CDEV(channel->ccwdev);
494 if (channel == &card->read)
495 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
497 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
498 channel->ccw.count = len;
499 channel->ccw.cda = (__u32) __pa(iob);
502 static struct qeth_cmd_buffer *__qeth_get_buffer(struct qeth_channel *channel)
506 QETH_DBF_TEXT(TRACE, 6, "getbuff");
507 index = channel->io_buf_no;
509 if (channel->iob[index].state == BUF_STATE_FREE) {
510 channel->iob[index].state = BUF_STATE_LOCKED;
511 channel->io_buf_no = (channel->io_buf_no + 1) %
513 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
514 return channel->iob + index;
516 index = (index + 1) % QETH_CMD_BUFFER_NO;
517 } while (index != channel->io_buf_no);
522 void qeth_release_buffer(struct qeth_channel *channel,
523 struct qeth_cmd_buffer *iob)
527 QETH_DBF_TEXT(TRACE, 6, "relbuff");
528 spin_lock_irqsave(&channel->iob_lock, flags);
529 memset(iob->data, 0, QETH_BUFSIZE);
530 iob->state = BUF_STATE_FREE;
531 iob->callback = qeth_send_control_data_cb;
533 spin_unlock_irqrestore(&channel->iob_lock, flags);
535 EXPORT_SYMBOL_GPL(qeth_release_buffer);
537 static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *channel)
539 struct qeth_cmd_buffer *buffer = NULL;
542 spin_lock_irqsave(&channel->iob_lock, flags);
543 buffer = __qeth_get_buffer(channel);
544 spin_unlock_irqrestore(&channel->iob_lock, flags);
548 struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *channel)
550 struct qeth_cmd_buffer *buffer;
551 wait_event(channel->wait_q,
552 ((buffer = qeth_get_buffer(channel)) != NULL));
555 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer);
557 void qeth_clear_cmd_buffers(struct qeth_channel *channel)
561 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
562 qeth_release_buffer(channel, &channel->iob[cnt]);
564 channel->io_buf_no = 0;
566 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers);
568 static void qeth_send_control_data_cb(struct qeth_channel *channel,
569 struct qeth_cmd_buffer *iob)
571 struct qeth_card *card;
572 struct qeth_reply *reply, *r;
573 struct qeth_ipa_cmd *cmd;
577 QETH_DBF_TEXT(TRACE, 4, "sndctlcb");
579 card = CARD_FROM_CDEV(channel->ccwdev);
580 if (qeth_check_idx_response(iob->data)) {
581 qeth_clear_ipacmd_list(card);
582 if (((iob->data[2] & 0xc0) == 0xc0) && iob->data[4] == 0xf6)
583 dev_err(&card->gdev->dev,
584 "The qeth device is not configured "
585 "for the OSI layer required by z/VM\n");
586 qeth_schedule_recovery(card);
590 cmd = qeth_check_ipa_data(card, iob);
591 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
593 /*in case of OSN : check if cmd is set */
594 if (card->info.type == QETH_CARD_TYPE_OSN &&
596 cmd->hdr.command != IPA_CMD_STARTLAN &&
597 card->osn_info.assist_cb != NULL) {
598 card->osn_info.assist_cb(card->dev, cmd);
602 spin_lock_irqsave(&card->lock, flags);
603 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
604 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
605 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
606 qeth_get_reply(reply);
607 list_del_init(&reply->list);
608 spin_unlock_irqrestore(&card->lock, flags);
610 if (reply->callback != NULL) {
612 reply->offset = (__u16)((char *)cmd -
614 keep_reply = reply->callback(card,
618 keep_reply = reply->callback(card,
623 reply->rc = (u16) cmd->hdr.return_code;
627 spin_lock_irqsave(&card->lock, flags);
628 list_add_tail(&reply->list,
629 &card->cmd_waiter_list);
630 spin_unlock_irqrestore(&card->lock, flags);
632 atomic_inc(&reply->received);
633 wake_up(&reply->wait_q);
635 qeth_put_reply(reply);
639 spin_unlock_irqrestore(&card->lock, flags);
641 memcpy(&card->seqno.pdu_hdr_ack,
642 QETH_PDU_HEADER_SEQ_NO(iob->data),
644 qeth_release_buffer(channel, iob);
647 static int qeth_setup_channel(struct qeth_channel *channel)
651 QETH_DBF_TEXT(SETUP, 2, "setupch");
652 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
653 channel->iob[cnt].data = (char *)
654 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
655 if (channel->iob[cnt].data == NULL)
657 channel->iob[cnt].state = BUF_STATE_FREE;
658 channel->iob[cnt].channel = channel;
659 channel->iob[cnt].callback = qeth_send_control_data_cb;
660 channel->iob[cnt].rc = 0;
662 if (cnt < QETH_CMD_BUFFER_NO) {
664 kfree(channel->iob[cnt].data);
668 channel->io_buf_no = 0;
669 atomic_set(&channel->irq_pending, 0);
670 spin_lock_init(&channel->iob_lock);
672 init_waitqueue_head(&channel->wait_q);
676 static int qeth_set_thread_start_bit(struct qeth_card *card,
677 unsigned long thread)
681 spin_lock_irqsave(&card->thread_mask_lock, flags);
682 if (!(card->thread_allowed_mask & thread) ||
683 (card->thread_start_mask & thread)) {
684 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
687 card->thread_start_mask |= thread;
688 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
692 void qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
696 spin_lock_irqsave(&card->thread_mask_lock, flags);
697 card->thread_start_mask &= ~thread;
698 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
699 wake_up(&card->wait_q);
701 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit);
703 void qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
707 spin_lock_irqsave(&card->thread_mask_lock, flags);
708 card->thread_running_mask &= ~thread;
709 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
710 wake_up(&card->wait_q);
712 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit);
714 static int __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
719 spin_lock_irqsave(&card->thread_mask_lock, flags);
720 if (card->thread_start_mask & thread) {
721 if ((card->thread_allowed_mask & thread) &&
722 !(card->thread_running_mask & thread)) {
724 card->thread_start_mask &= ~thread;
725 card->thread_running_mask |= thread;
729 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
733 int qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
737 wait_event(card->wait_q,
738 (rc = __qeth_do_run_thread(card, thread)) >= 0);
741 EXPORT_SYMBOL_GPL(qeth_do_run_thread);
743 void qeth_schedule_recovery(struct qeth_card *card)
745 QETH_DBF_TEXT(TRACE, 2, "startrec");
746 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
747 schedule_work(&card->kernel_thread_starter);
749 EXPORT_SYMBOL_GPL(qeth_schedule_recovery);
751 static int qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
756 sense = (char *) irb->ecw;
757 cstat = irb->scsw.cmd.cstat;
758 dstat = irb->scsw.cmd.dstat;
760 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
761 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
762 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
763 QETH_DBF_TEXT(TRACE, 2, "CGENCHK");
764 dev_warn(&cdev->dev, "The qeth device driver "
765 "failed to recover an error on the device\n");
766 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x ",
767 dev_name(&cdev->dev), dstat, cstat);
768 print_hex_dump(KERN_WARNING, "qeth: irb ", DUMP_PREFIX_OFFSET,
773 if (dstat & DEV_STAT_UNIT_CHECK) {
774 if (sense[SENSE_RESETTING_EVENT_BYTE] &
775 SENSE_RESETTING_EVENT_FLAG) {
776 QETH_DBF_TEXT(TRACE, 2, "REVIND");
779 if (sense[SENSE_COMMAND_REJECT_BYTE] &
780 SENSE_COMMAND_REJECT_FLAG) {
781 QETH_DBF_TEXT(TRACE, 2, "CMDREJi");
784 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
785 QETH_DBF_TEXT(TRACE, 2, "AFFE");
788 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
789 QETH_DBF_TEXT(TRACE, 2, "ZEROSEN");
792 QETH_DBF_TEXT(TRACE, 2, "DGENCHK");
798 static long __qeth_check_irb_error(struct ccw_device *cdev,
799 unsigned long intparm, struct irb *irb)
804 switch (PTR_ERR(irb)) {
806 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
807 dev_name(&cdev->dev));
808 QETH_DBF_TEXT(TRACE, 2, "ckirberr");
809 QETH_DBF_TEXT_(TRACE, 2, " rc%d", -EIO);
812 dev_warn(&cdev->dev, "A hardware operation timed out"
814 QETH_DBF_TEXT(TRACE, 2, "ckirberr");
815 QETH_DBF_TEXT_(TRACE, 2, " rc%d", -ETIMEDOUT);
816 if (intparm == QETH_RCD_PARM) {
817 struct qeth_card *card = CARD_FROM_CDEV(cdev);
819 if (card && (card->data.ccwdev == cdev)) {
820 card->data.state = CH_STATE_DOWN;
821 wake_up(&card->wait_q);
826 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
827 dev_name(&cdev->dev), PTR_ERR(irb));
828 QETH_DBF_TEXT(TRACE, 2, "ckirberr");
829 QETH_DBF_TEXT(TRACE, 2, " rc???");
834 static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
839 struct qeth_cmd_buffer *buffer;
840 struct qeth_channel *channel;
841 struct qeth_card *card;
842 struct qeth_cmd_buffer *iob;
845 QETH_DBF_TEXT(TRACE, 5, "irq");
847 if (__qeth_check_irb_error(cdev, intparm, irb))
849 cstat = irb->scsw.cmd.cstat;
850 dstat = irb->scsw.cmd.dstat;
852 card = CARD_FROM_CDEV(cdev);
856 if (card->read.ccwdev == cdev) {
857 channel = &card->read;
858 QETH_DBF_TEXT(TRACE, 5, "read");
859 } else if (card->write.ccwdev == cdev) {
860 channel = &card->write;
861 QETH_DBF_TEXT(TRACE, 5, "write");
863 channel = &card->data;
864 QETH_DBF_TEXT(TRACE, 5, "data");
866 atomic_set(&channel->irq_pending, 0);
868 if (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC))
869 channel->state = CH_STATE_STOPPED;
871 if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC))
872 channel->state = CH_STATE_HALTED;
874 /*let's wake up immediately on data channel*/
875 if ((channel == &card->data) && (intparm != 0) &&
876 (intparm != QETH_RCD_PARM))
879 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
880 QETH_DBF_TEXT(TRACE, 6, "clrchpar");
881 /* we don't have to handle this further */
884 if (intparm == QETH_HALT_CHANNEL_PARM) {
885 QETH_DBF_TEXT(TRACE, 6, "hltchpar");
886 /* we don't have to handle this further */
889 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
890 (dstat & DEV_STAT_UNIT_CHECK) ||
892 if (irb->esw.esw0.erw.cons) {
893 dev_warn(&channel->ccwdev->dev,
894 "The qeth device driver failed to recover "
895 "an error on the device\n");
896 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
898 dev_name(&channel->ccwdev->dev), cstat, dstat);
899 print_hex_dump(KERN_WARNING, "qeth: irb ",
900 DUMP_PREFIX_OFFSET, 16, 1, irb, 32, 1);
901 print_hex_dump(KERN_WARNING, "qeth: sense data ",
902 DUMP_PREFIX_OFFSET, 16, 1, irb->ecw, 32, 1);
904 if (intparm == QETH_RCD_PARM) {
905 channel->state = CH_STATE_DOWN;
908 rc = qeth_get_problem(cdev, irb);
910 qeth_clear_ipacmd_list(card);
911 qeth_schedule_recovery(card);
916 if (intparm == QETH_RCD_PARM) {
917 channel->state = CH_STATE_RCD_DONE;
921 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
922 buffer->state = BUF_STATE_PROCESSED;
924 if (channel == &card->data)
926 if (channel == &card->read &&
927 channel->state == CH_STATE_UP)
928 qeth_issue_next_read(card);
931 index = channel->buf_no;
932 while (iob[index].state == BUF_STATE_PROCESSED) {
933 if (iob[index].callback != NULL)
934 iob[index].callback(channel, iob + index);
936 index = (index + 1) % QETH_CMD_BUFFER_NO;
938 channel->buf_no = index;
940 wake_up(&card->wait_q);
944 static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
945 struct qeth_qdio_out_buffer *buf)
950 /* is PCI flag set on buffer? */
951 if (buf->buffer->element[0].flags & 0x40)
952 atomic_dec(&queue->set_pci_flags_count);
954 skb = skb_dequeue(&buf->skb_list);
956 atomic_dec(&skb->users);
957 dev_kfree_skb_any(skb);
958 skb = skb_dequeue(&buf->skb_list);
960 qeth_eddp_buf_release_contexts(buf);
961 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i) {
962 if (buf->buffer->element[i].addr && buf->is_header[i])
963 kmem_cache_free(qeth_core_header_cache,
964 buf->buffer->element[i].addr);
965 buf->is_header[i] = 0;
966 buf->buffer->element[i].length = 0;
967 buf->buffer->element[i].addr = NULL;
968 buf->buffer->element[i].flags = 0;
970 buf->next_element_to_fill = 0;
971 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
974 void qeth_clear_qdio_buffers(struct qeth_card *card)
978 QETH_DBF_TEXT(TRACE, 2, "clearqdbf");
979 /* clear outbound buffers to free skbs */
980 for (i = 0; i < card->qdio.no_out_queues; ++i)
981 if (card->qdio.out_qs[i]) {
982 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
983 qeth_clear_output_buffer(card->qdio.out_qs[i],
984 &card->qdio.out_qs[i]->bufs[j]);
987 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers);
989 static void qeth_free_buffer_pool(struct qeth_card *card)
991 struct qeth_buffer_pool_entry *pool_entry, *tmp;
993 QETH_DBF_TEXT(TRACE, 5, "freepool");
994 list_for_each_entry_safe(pool_entry, tmp,
995 &card->qdio.init_pool.entry_list, init_list){
996 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
997 free_page((unsigned long)pool_entry->elements[i]);
998 list_del(&pool_entry->init_list);
1003 static void qeth_free_qdio_buffers(struct qeth_card *card)
1007 QETH_DBF_TEXT(TRACE, 2, "freeqdbf");
1008 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
1009 QETH_QDIO_UNINITIALIZED)
1011 kfree(card->qdio.in_q);
1012 card->qdio.in_q = NULL;
1013 /* inbound buffer pool */
1014 qeth_free_buffer_pool(card);
1015 /* free outbound qdio_qs */
1016 if (card->qdio.out_qs) {
1017 for (i = 0; i < card->qdio.no_out_queues; ++i) {
1018 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
1019 qeth_clear_output_buffer(card->qdio.out_qs[i],
1020 &card->qdio.out_qs[i]->bufs[j]);
1021 kfree(card->qdio.out_qs[i]);
1023 kfree(card->qdio.out_qs);
1024 card->qdio.out_qs = NULL;
1028 static void qeth_clean_channel(struct qeth_channel *channel)
1032 QETH_DBF_TEXT(SETUP, 2, "freech");
1033 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1034 kfree(channel->iob[cnt].data);
1037 static int qeth_is_1920_device(struct qeth_card *card)
1039 int single_queue = 0;
1040 struct ccw_device *ccwdev;
1041 struct channelPath_dsc {
1052 QETH_DBF_TEXT(SETUP, 2, "chk_1920");
1054 ccwdev = card->data.ccwdev;
1055 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1056 if (chp_dsc != NULL) {
1057 /* CHPP field bit 6 == 1 -> single queue */
1058 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1061 QETH_DBF_TEXT_(SETUP, 2, "rc:%x", single_queue);
1062 return single_queue;
1065 static void qeth_init_qdio_info(struct qeth_card *card)
1067 QETH_DBF_TEXT(SETUP, 4, "intqdinf");
1068 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
1070 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1071 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
1072 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
1073 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
1074 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
1077 static void qeth_set_intial_options(struct qeth_card *card)
1079 card->options.route4.type = NO_ROUTER;
1080 card->options.route6.type = NO_ROUTER;
1081 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1082 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1083 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1084 card->options.fake_broadcast = 0;
1085 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1086 card->options.performance_stats = 0;
1087 card->options.rx_sg_cb = QETH_RX_SG_CB;
1090 static int qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1092 unsigned long flags;
1095 spin_lock_irqsave(&card->thread_mask_lock, flags);
1096 QETH_DBF_TEXT_(TRACE, 4, " %02x%02x%02x",
1097 (u8) card->thread_start_mask,
1098 (u8) card->thread_allowed_mask,
1099 (u8) card->thread_running_mask);
1100 rc = (card->thread_start_mask & thread);
1101 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1105 static void qeth_start_kernel_thread(struct work_struct *work)
1107 struct qeth_card *card = container_of(work, struct qeth_card,
1108 kernel_thread_starter);
1109 QETH_DBF_TEXT(TRACE , 2, "strthrd");
1111 if (card->read.state != CH_STATE_UP &&
1112 card->write.state != CH_STATE_UP)
1114 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1115 kthread_run(card->discipline.recover, (void *) card,
1119 static int qeth_setup_card(struct qeth_card *card)
1122 QETH_DBF_TEXT(SETUP, 2, "setupcrd");
1123 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1125 card->read.state = CH_STATE_DOWN;
1126 card->write.state = CH_STATE_DOWN;
1127 card->data.state = CH_STATE_DOWN;
1128 card->state = CARD_STATE_DOWN;
1129 card->lan_online = 0;
1130 card->use_hard_stop = 0;
1132 spin_lock_init(&card->vlanlock);
1133 spin_lock_init(&card->mclock);
1134 card->vlangrp = NULL;
1135 spin_lock_init(&card->lock);
1136 spin_lock_init(&card->ip_lock);
1137 spin_lock_init(&card->thread_mask_lock);
1138 card->thread_start_mask = 0;
1139 card->thread_allowed_mask = 0;
1140 card->thread_running_mask = 0;
1141 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1142 INIT_LIST_HEAD(&card->ip_list);
1143 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1144 if (!card->ip_tbd_list) {
1145 QETH_DBF_TEXT(SETUP, 0, "iptbdnom");
1148 INIT_LIST_HEAD(card->ip_tbd_list);
1149 INIT_LIST_HEAD(&card->cmd_waiter_list);
1150 init_waitqueue_head(&card->wait_q);
1151 /* intial options */
1152 qeth_set_intial_options(card);
1153 /* IP address takeover */
1154 INIT_LIST_HEAD(&card->ipato.entries);
1155 card->ipato.enabled = 0;
1156 card->ipato.invert4 = 0;
1157 card->ipato.invert6 = 0;
1158 /* init QDIO stuff */
1159 qeth_init_qdio_info(card);
1163 static void qeth_core_sl_print(struct seq_file *m, struct service_level *slr)
1165 struct qeth_card *card = container_of(slr, struct qeth_card,
1166 qeth_service_level);
1167 seq_printf(m, "qeth: %s firmware level %s\n", CARD_BUS_ID(card),
1168 card->info.mcl_level);
1171 static struct qeth_card *qeth_alloc_card(void)
1173 struct qeth_card *card;
1175 QETH_DBF_TEXT(SETUP, 2, "alloccrd");
1176 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
1179 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1180 if (qeth_setup_channel(&card->read)) {
1184 if (qeth_setup_channel(&card->write)) {
1185 qeth_clean_channel(&card->read);
1189 card->options.layer2 = -1;
1190 card->qeth_service_level.seq_print = qeth_core_sl_print;
1191 register_service_level(&card->qeth_service_level);
1195 static int qeth_determine_card_type(struct qeth_card *card)
1199 QETH_DBF_TEXT(SETUP, 2, "detcdtyp");
1201 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1202 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1203 while (known_devices[i][4]) {
1204 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1205 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1206 card->info.type = known_devices[i][4];
1207 card->qdio.no_out_queues = known_devices[i][8];
1208 card->info.is_multicast_different = known_devices[i][9];
1209 if (qeth_is_1920_device(card)) {
1210 dev_info(&card->gdev->dev,
1211 "Priority Queueing not supported\n");
1212 card->qdio.no_out_queues = 1;
1213 card->qdio.default_out_queue = 0;
1219 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1220 dev_err(&card->gdev->dev, "The adapter hardware is of an "
1225 static int qeth_clear_channel(struct qeth_channel *channel)
1227 unsigned long flags;
1228 struct qeth_card *card;
1231 QETH_DBF_TEXT(TRACE, 3, "clearch");
1232 card = CARD_FROM_CDEV(channel->ccwdev);
1233 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1234 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
1235 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1239 rc = wait_event_interruptible_timeout(card->wait_q,
1240 channel->state == CH_STATE_STOPPED, QETH_TIMEOUT);
1241 if (rc == -ERESTARTSYS)
1243 if (channel->state != CH_STATE_STOPPED)
1245 channel->state = CH_STATE_DOWN;
1249 static int qeth_halt_channel(struct qeth_channel *channel)
1251 unsigned long flags;
1252 struct qeth_card *card;
1255 QETH_DBF_TEXT(TRACE, 3, "haltch");
1256 card = CARD_FROM_CDEV(channel->ccwdev);
1257 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1258 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
1259 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1263 rc = wait_event_interruptible_timeout(card->wait_q,
1264 channel->state == CH_STATE_HALTED, QETH_TIMEOUT);
1265 if (rc == -ERESTARTSYS)
1267 if (channel->state != CH_STATE_HALTED)
1272 static int qeth_halt_channels(struct qeth_card *card)
1274 int rc1 = 0, rc2 = 0, rc3 = 0;
1276 QETH_DBF_TEXT(TRACE, 3, "haltchs");
1277 rc1 = qeth_halt_channel(&card->read);
1278 rc2 = qeth_halt_channel(&card->write);
1279 rc3 = qeth_halt_channel(&card->data);
1287 static int qeth_clear_channels(struct qeth_card *card)
1289 int rc1 = 0, rc2 = 0, rc3 = 0;
1291 QETH_DBF_TEXT(TRACE, 3, "clearchs");
1292 rc1 = qeth_clear_channel(&card->read);
1293 rc2 = qeth_clear_channel(&card->write);
1294 rc3 = qeth_clear_channel(&card->data);
1302 static int qeth_clear_halt_card(struct qeth_card *card, int halt)
1306 QETH_DBF_TEXT(TRACE, 3, "clhacrd");
1307 QETH_DBF_HEX(TRACE, 3, &card, sizeof(void *));
1310 rc = qeth_halt_channels(card);
1313 return qeth_clear_channels(card);
1316 int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
1320 QETH_DBF_TEXT(TRACE, 3, "qdioclr");
1321 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
1322 QETH_QDIO_CLEANING)) {
1323 case QETH_QDIO_ESTABLISHED:
1324 if (card->info.type == QETH_CARD_TYPE_IQD)
1325 rc = qdio_cleanup(CARD_DDEV(card),
1326 QDIO_FLAG_CLEANUP_USING_HALT);
1328 rc = qdio_cleanup(CARD_DDEV(card),
1329 QDIO_FLAG_CLEANUP_USING_CLEAR);
1331 QETH_DBF_TEXT_(TRACE, 3, "1err%d", rc);
1332 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
1334 case QETH_QDIO_CLEANING:
1339 rc = qeth_clear_halt_card(card, use_halt);
1341 QETH_DBF_TEXT_(TRACE, 3, "2err%d", rc);
1342 card->state = CARD_STATE_DOWN;
1345 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card);
1347 static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
1353 struct qeth_channel *channel = &card->data;
1354 unsigned long flags;
1357 * scan for RCD command in extended SenseID data
1359 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
1360 if (!ciw || ciw->cmd == 0)
1362 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
1366 channel->ccw.cmd_code = ciw->cmd;
1367 channel->ccw.cda = (__u32) __pa(rcd_buf);
1368 channel->ccw.count = ciw->count;
1369 channel->ccw.flags = CCW_FLAG_SLI;
1370 channel->state = CH_STATE_RCD;
1371 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1372 ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1373 QETH_RCD_PARM, LPM_ANYPATH, 0,
1375 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1377 wait_event(card->wait_q,
1378 (channel->state == CH_STATE_RCD_DONE ||
1379 channel->state == CH_STATE_DOWN));
1380 if (channel->state == CH_STATE_DOWN)
1383 channel->state = CH_STATE_DOWN;
1389 *length = ciw->count;
1395 static int qeth_get_unitaddr(struct qeth_card *card)
1401 QETH_DBF_TEXT(SETUP, 2, "getunit");
1402 rc = qeth_read_conf_data(card, (void **) &prcd, &length);
1404 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
1405 dev_name(&card->gdev->dev), rc);
1408 card->info.chpid = prcd[30];
1409 card->info.unit_addr2 = prcd[31];
1410 card->info.cula = prcd[63];
1411 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1412 (prcd[0x11] == _ascebc['M']));
1417 static void qeth_init_tokens(struct qeth_card *card)
1419 card->token.issuer_rm_w = 0x00010103UL;
1420 card->token.cm_filter_w = 0x00010108UL;
1421 card->token.cm_connection_w = 0x0001010aUL;
1422 card->token.ulp_filter_w = 0x0001010bUL;
1423 card->token.ulp_connection_w = 0x0001010dUL;
1426 static void qeth_init_func_level(struct qeth_card *card)
1428 if (card->ipato.enabled) {
1429 if (card->info.type == QETH_CARD_TYPE_IQD)
1430 card->info.func_level =
1431 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
1433 card->info.func_level =
1434 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
1436 if (card->info.type == QETH_CARD_TYPE_IQD)
1437 /*FIXME:why do we have same values for dis and ena for
1439 card->info.func_level =
1440 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
1442 card->info.func_level =
1443 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
1447 static int qeth_idx_activate_get_answer(struct qeth_channel *channel,
1448 void (*idx_reply_cb)(struct qeth_channel *,
1449 struct qeth_cmd_buffer *))
1451 struct qeth_cmd_buffer *iob;
1452 unsigned long flags;
1454 struct qeth_card *card;
1456 QETH_DBF_TEXT(SETUP, 2, "idxanswr");
1457 card = CARD_FROM_CDEV(channel->ccwdev);
1458 iob = qeth_get_buffer(channel);
1459 iob->callback = idx_reply_cb;
1460 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1461 channel->ccw.count = QETH_BUFSIZE;
1462 channel->ccw.cda = (__u32) __pa(iob->data);
1464 wait_event(card->wait_q,
1465 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1466 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1467 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1468 rc = ccw_device_start(channel->ccwdev,
1469 &channel->ccw, (addr_t) iob, 0, 0);
1470 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1473 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc);
1474 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
1475 atomic_set(&channel->irq_pending, 0);
1476 wake_up(&card->wait_q);
1479 rc = wait_event_interruptible_timeout(card->wait_q,
1480 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1481 if (rc == -ERESTARTSYS)
1483 if (channel->state != CH_STATE_UP) {
1485 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
1486 qeth_clear_cmd_buffers(channel);
1492 static int qeth_idx_activate_channel(struct qeth_channel *channel,
1493 void (*idx_reply_cb)(struct qeth_channel *,
1494 struct qeth_cmd_buffer *))
1496 struct qeth_card *card;
1497 struct qeth_cmd_buffer *iob;
1498 unsigned long flags;
1502 struct ccw_dev_id temp_devid;
1504 card = CARD_FROM_CDEV(channel->ccwdev);
1506 QETH_DBF_TEXT(SETUP, 2, "idxactch");
1508 iob = qeth_get_buffer(channel);
1509 iob->callback = idx_reply_cb;
1510 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1511 channel->ccw.count = IDX_ACTIVATE_SIZE;
1512 channel->ccw.cda = (__u32) __pa(iob->data);
1513 if (channel == &card->write) {
1514 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1515 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1516 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1517 card->seqno.trans_hdr++;
1519 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1520 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1521 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1523 tmp = ((__u8)card->info.portno) | 0x80;
1524 memcpy(QETH_IDX_ACT_PNO(iob->data), &tmp, 1);
1525 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1526 &card->token.issuer_rm_w, QETH_MPC_TOKEN_LENGTH);
1527 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1528 &card->info.func_level, sizeof(__u16));
1529 ccw_device_get_id(CARD_DDEV(card), &temp_devid);
1530 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp_devid.devno, 2);
1531 temp = (card->info.cula << 8) + card->info.unit_addr2;
1532 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1534 wait_event(card->wait_q,
1535 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1536 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1537 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1538 rc = ccw_device_start(channel->ccwdev,
1539 &channel->ccw, (addr_t) iob, 0, 0);
1540 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1543 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1545 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1546 atomic_set(&channel->irq_pending, 0);
1547 wake_up(&card->wait_q);
1550 rc = wait_event_interruptible_timeout(card->wait_q,
1551 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1552 if (rc == -ERESTARTSYS)
1554 if (channel->state != CH_STATE_ACTIVATING) {
1555 dev_warn(&channel->ccwdev->dev, "The qeth device driver"
1556 " failed to recover an error on the device\n");
1557 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1558 dev_name(&channel->ccwdev->dev));
1559 QETH_DBF_TEXT_(SETUP, 2, "2err%d", -ETIME);
1560 qeth_clear_cmd_buffers(channel);
1563 return qeth_idx_activate_get_answer(channel, idx_reply_cb);
1566 static int qeth_peer_func_level(int level)
1568 if ((level & 0xff) == 8)
1569 return (level & 0xff) + 0x400;
1570 if (((level >> 8) & 3) == 1)
1571 return (level & 0xff) + 0x200;
1575 static void qeth_idx_write_cb(struct qeth_channel *channel,
1576 struct qeth_cmd_buffer *iob)
1578 struct qeth_card *card;
1581 QETH_DBF_TEXT(SETUP , 2, "idxwrcb");
1583 if (channel->state == CH_STATE_DOWN) {
1584 channel->state = CH_STATE_ACTIVATING;
1587 card = CARD_FROM_CDEV(channel->ccwdev);
1589 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1590 if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == 0x19)
1591 dev_err(&card->write.ccwdev->dev,
1592 "The adapter is used exclusively by another "
1595 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1596 " negative reply\n",
1597 dev_name(&card->write.ccwdev->dev));
1600 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1601 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1602 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
1603 "function level mismatch (sent: 0x%x, received: "
1604 "0x%x)\n", dev_name(&card->write.ccwdev->dev),
1605 card->info.func_level, temp);
1608 channel->state = CH_STATE_UP;
1610 qeth_release_buffer(channel, iob);
1613 static void qeth_idx_read_cb(struct qeth_channel *channel,
1614 struct qeth_cmd_buffer *iob)
1616 struct qeth_card *card;
1619 QETH_DBF_TEXT(SETUP , 2, "idxrdcb");
1620 if (channel->state == CH_STATE_DOWN) {
1621 channel->state = CH_STATE_ACTIVATING;
1625 card = CARD_FROM_CDEV(channel->ccwdev);
1626 if (qeth_check_idx_response(iob->data))
1629 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1630 if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == 0x19)
1631 dev_err(&card->write.ccwdev->dev,
1632 "The adapter is used exclusively by another "
1635 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
1636 " negative reply\n",
1637 dev_name(&card->read.ccwdev->dev));
1642 * temporary fix for microcode bug
1643 * to revert it,replace OR by AND
1645 if ((!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1646 (card->info.type == QETH_CARD_TYPE_OSAE))
1647 card->info.portname_required = 1;
1649 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1650 if (temp != qeth_peer_func_level(card->info.func_level)) {
1651 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
1652 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1653 dev_name(&card->read.ccwdev->dev),
1654 card->info.func_level, temp);
1657 memcpy(&card->token.issuer_rm_r,
1658 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1659 QETH_MPC_TOKEN_LENGTH);
1660 memcpy(&card->info.mcl_level[0],
1661 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1662 channel->state = CH_STATE_UP;
1664 qeth_release_buffer(channel, iob);
1667 void qeth_prepare_control_data(struct qeth_card *card, int len,
1668 struct qeth_cmd_buffer *iob)
1670 qeth_setup_ccw(&card->write, iob->data, len);
1671 iob->callback = qeth_release_buffer;
1673 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1674 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1675 card->seqno.trans_hdr++;
1676 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1677 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1678 card->seqno.pdu_hdr++;
1679 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1680 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1681 QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
1683 EXPORT_SYMBOL_GPL(qeth_prepare_control_data);
1685 int qeth_send_control_data(struct qeth_card *card, int len,
1686 struct qeth_cmd_buffer *iob,
1687 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1692 unsigned long flags;
1693 struct qeth_reply *reply = NULL;
1694 unsigned long timeout;
1695 struct qeth_ipa_cmd *cmd;
1697 QETH_DBF_TEXT(TRACE, 2, "sendctl");
1699 reply = qeth_alloc_reply(card);
1703 reply->callback = reply_cb;
1704 reply->param = reply_param;
1705 if (card->state == CARD_STATE_DOWN)
1706 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1708 reply->seqno = card->seqno.ipa++;
1709 init_waitqueue_head(&reply->wait_q);
1710 spin_lock_irqsave(&card->lock, flags);
1711 list_add_tail(&reply->list, &card->cmd_waiter_list);
1712 spin_unlock_irqrestore(&card->lock, flags);
1713 QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
1715 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
1716 qeth_prepare_control_data(card, len, iob);
1718 if (IS_IPA(iob->data))
1719 timeout = jiffies + QETH_IPA_TIMEOUT;
1721 timeout = jiffies + QETH_TIMEOUT;
1723 QETH_DBF_TEXT(TRACE, 6, "noirqpnd");
1724 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1725 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1726 (addr_t) iob, 0, 0);
1727 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1729 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
1730 "ccw_device_start rc = %i\n",
1731 dev_name(&card->write.ccwdev->dev), rc);
1732 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
1733 spin_lock_irqsave(&card->lock, flags);
1734 list_del_init(&reply->list);
1735 qeth_put_reply(reply);
1736 spin_unlock_irqrestore(&card->lock, flags);
1737 qeth_release_buffer(iob->channel, iob);
1738 atomic_set(&card->write.irq_pending, 0);
1739 wake_up(&card->wait_q);
1743 /* we have only one long running ipassist, since we can ensure
1744 process context of this command we can sleep */
1745 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1746 if ((cmd->hdr.command == IPA_CMD_SETIP) &&
1747 (cmd->hdr.prot_version == QETH_PROT_IPV4)) {
1748 if (!wait_event_timeout(reply->wait_q,
1749 atomic_read(&reply->received), timeout))
1752 while (!atomic_read(&reply->received)) {
1753 if (time_after(jiffies, timeout))
1760 qeth_put_reply(reply);
1764 spin_lock_irqsave(&reply->card->lock, flags);
1765 list_del_init(&reply->list);
1766 spin_unlock_irqrestore(&reply->card->lock, flags);
1768 atomic_inc(&reply->received);
1769 wake_up(&reply->wait_q);
1771 qeth_put_reply(reply);
1774 EXPORT_SYMBOL_GPL(qeth_send_control_data);
1776 static int qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1779 struct qeth_cmd_buffer *iob;
1781 QETH_DBF_TEXT(SETUP, 2, "cmenblcb");
1783 iob = (struct qeth_cmd_buffer *) data;
1784 memcpy(&card->token.cm_filter_r,
1785 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
1786 QETH_MPC_TOKEN_LENGTH);
1787 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1791 static int qeth_cm_enable(struct qeth_card *card)
1794 struct qeth_cmd_buffer *iob;
1796 QETH_DBF_TEXT(SETUP, 2, "cmenable");
1798 iob = qeth_wait_for_buffer(&card->write);
1799 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
1800 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
1801 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1802 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
1803 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
1805 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
1806 qeth_cm_enable_cb, NULL);
1810 static int qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
1814 struct qeth_cmd_buffer *iob;
1816 QETH_DBF_TEXT(SETUP, 2, "cmsetpcb");
1818 iob = (struct qeth_cmd_buffer *) data;
1819 memcpy(&card->token.cm_connection_r,
1820 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
1821 QETH_MPC_TOKEN_LENGTH);
1822 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1826 static int qeth_cm_setup(struct qeth_card *card)
1829 struct qeth_cmd_buffer *iob;
1831 QETH_DBF_TEXT(SETUP, 2, "cmsetup");
1833 iob = qeth_wait_for_buffer(&card->write);
1834 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
1835 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
1836 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1837 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
1838 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
1839 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
1840 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
1841 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
1842 qeth_cm_setup_cb, NULL);
1847 static inline int qeth_get_initial_mtu_for_card(struct qeth_card *card)
1849 switch (card->info.type) {
1850 case QETH_CARD_TYPE_UNKNOWN:
1852 case QETH_CARD_TYPE_IQD:
1853 return card->info.max_mtu;
1854 case QETH_CARD_TYPE_OSAE:
1855 switch (card->info.link_type) {
1856 case QETH_LINK_TYPE_HSTR:
1857 case QETH_LINK_TYPE_LANE_TR:
1867 static inline int qeth_get_max_mtu_for_card(int cardtype)
1871 case QETH_CARD_TYPE_UNKNOWN:
1872 case QETH_CARD_TYPE_OSAE:
1873 case QETH_CARD_TYPE_OSN:
1875 case QETH_CARD_TYPE_IQD:
1882 static inline int qeth_get_mtu_out_of_mpc(int cardtype)
1885 case QETH_CARD_TYPE_IQD:
1892 static inline int qeth_get_mtu_outof_framesize(int framesize)
1894 switch (framesize) {
1908 static inline int qeth_mtu_is_valid(struct qeth_card *card, int mtu)
1910 switch (card->info.type) {
1911 case QETH_CARD_TYPE_OSAE:
1912 return ((mtu >= 576) && (mtu <= 61440));
1913 case QETH_CARD_TYPE_IQD:
1914 return ((mtu >= 576) &&
1915 (mtu <= card->info.max_mtu + 4096 - 32));
1916 case QETH_CARD_TYPE_OSN:
1917 case QETH_CARD_TYPE_UNKNOWN:
1923 static int qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1927 __u16 mtu, framesize;
1930 struct qeth_cmd_buffer *iob;
1932 QETH_DBF_TEXT(SETUP, 2, "ulpenacb");
1934 iob = (struct qeth_cmd_buffer *) data;
1935 memcpy(&card->token.ulp_filter_r,
1936 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
1937 QETH_MPC_TOKEN_LENGTH);
1938 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
1939 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
1940 mtu = qeth_get_mtu_outof_framesize(framesize);
1943 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1946 card->info.max_mtu = mtu;
1947 card->info.initial_mtu = mtu;
1948 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
1950 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
1951 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
1952 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1955 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
1956 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
1958 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
1959 card->info.link_type = link_type;
1961 card->info.link_type = 0;
1962 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1966 static int qeth_ulp_enable(struct qeth_card *card)
1970 struct qeth_cmd_buffer *iob;
1972 /*FIXME: trace view callbacks*/
1973 QETH_DBF_TEXT(SETUP, 2, "ulpenabl");
1975 iob = qeth_wait_for_buffer(&card->write);
1976 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
1978 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
1979 (__u8) card->info.portno;
1980 if (card->options.layer2)
1981 if (card->info.type == QETH_CARD_TYPE_OSN)
1982 prot_type = QETH_PROT_OSN2;
1984 prot_type = QETH_PROT_LAYER2;
1986 prot_type = QETH_PROT_TCPIP;
1988 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data), &prot_type, 1);
1989 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
1990 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
1991 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
1992 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
1993 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
1994 card->info.portname, 9);
1995 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
1996 qeth_ulp_enable_cb, NULL);
2001 static int qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2004 struct qeth_cmd_buffer *iob;
2006 QETH_DBF_TEXT(SETUP, 2, "ulpstpcb");
2008 iob = (struct qeth_cmd_buffer *) data;
2009 memcpy(&card->token.ulp_connection_r,
2010 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2011 QETH_MPC_TOKEN_LENGTH);
2012 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2016 static int qeth_ulp_setup(struct qeth_card *card)
2020 struct qeth_cmd_buffer *iob;
2021 struct ccw_dev_id dev_id;
2023 QETH_DBF_TEXT(SETUP, 2, "ulpsetup");
2025 iob = qeth_wait_for_buffer(&card->write);
2026 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2028 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2029 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2030 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2031 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2032 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2033 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2035 ccw_device_get_id(CARD_DDEV(card), &dev_id);
2036 memcpy(QETH_ULP_SETUP_CUA(iob->data), &dev_id.devno, 2);
2037 temp = (card->info.cula << 8) + card->info.unit_addr2;
2038 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2039 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2040 qeth_ulp_setup_cb, NULL);
2044 static int qeth_alloc_qdio_buffers(struct qeth_card *card)
2048 QETH_DBF_TEXT(SETUP, 2, "allcqdbf");
2050 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
2051 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
2054 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
2056 if (!card->qdio.in_q)
2058 QETH_DBF_TEXT(SETUP, 2, "inq");
2059 QETH_DBF_HEX(SETUP, 2, &card->qdio.in_q, sizeof(void *));
2060 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
2061 /* give inbound qeth_qdio_buffers their qdio_buffers */
2062 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
2063 card->qdio.in_q->bufs[i].buffer =
2064 &card->qdio.in_q->qdio_bufs[i];
2065 /* inbound buffer pool */
2066 if (qeth_alloc_buffer_pool(card))
2070 kmalloc(card->qdio.no_out_queues *
2071 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
2072 if (!card->qdio.out_qs)
2074 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2075 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
2077 if (!card->qdio.out_qs[i])
2079 QETH_DBF_TEXT_(SETUP, 2, "outq %i", i);
2080 QETH_DBF_HEX(SETUP, 2, &card->qdio.out_qs[i], sizeof(void *));
2081 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
2082 card->qdio.out_qs[i]->queue_no = i;
2083 /* give outbound qeth_qdio_buffers their qdio_buffers */
2084 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2085 card->qdio.out_qs[i]->bufs[j].buffer =
2086 &card->qdio.out_qs[i]->qdio_bufs[j];
2087 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
2090 &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
2091 &qdio_out_skb_queue_key);
2092 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
2099 kfree(card->qdio.out_qs[--i]);
2100 kfree(card->qdio.out_qs);
2101 card->qdio.out_qs = NULL;
2103 qeth_free_buffer_pool(card);
2105 kfree(card->qdio.in_q);
2106 card->qdio.in_q = NULL;
2108 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
2112 static void qeth_create_qib_param_field(struct qeth_card *card,
2116 param_field[0] = _ascebc['P'];
2117 param_field[1] = _ascebc['C'];
2118 param_field[2] = _ascebc['I'];
2119 param_field[3] = _ascebc['T'];
2120 *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card);
2121 *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card);
2122 *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card);
2125 static void qeth_create_qib_param_field_blkt(struct qeth_card *card,
2128 param_field[16] = _ascebc['B'];
2129 param_field[17] = _ascebc['L'];
2130 param_field[18] = _ascebc['K'];
2131 param_field[19] = _ascebc['T'];
2132 *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total;
2133 *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet;
2134 *((unsigned int *) (¶m_field[28])) =
2135 card->info.blkt.inter_packet_jumbo;
2138 static int qeth_qdio_activate(struct qeth_card *card)
2140 QETH_DBF_TEXT(SETUP, 3, "qdioact");
2141 return qdio_activate(CARD_DDEV(card));
2144 static int qeth_dm_act(struct qeth_card *card)
2147 struct qeth_cmd_buffer *iob;
2149 QETH_DBF_TEXT(SETUP, 2, "dmact");
2151 iob = qeth_wait_for_buffer(&card->write);
2152 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
2154 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
2155 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2156 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
2157 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2158 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
2162 static int qeth_mpc_initialize(struct qeth_card *card)
2166 QETH_DBF_TEXT(SETUP, 2, "mpcinit");
2168 rc = qeth_issue_next_read(card);
2170 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2173 rc = qeth_cm_enable(card);
2175 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
2178 rc = qeth_cm_setup(card);
2180 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
2183 rc = qeth_ulp_enable(card);
2185 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
2188 rc = qeth_ulp_setup(card);
2190 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
2193 rc = qeth_alloc_qdio_buffers(card);
2195 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
2198 rc = qeth_qdio_establish(card);
2200 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
2201 qeth_free_qdio_buffers(card);
2204 rc = qeth_qdio_activate(card);
2206 QETH_DBF_TEXT_(SETUP, 2, "7err%d", rc);
2209 rc = qeth_dm_act(card);
2211 QETH_DBF_TEXT_(SETUP, 2, "8err%d", rc);
2217 qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
2221 static void qeth_print_status_with_portname(struct qeth_card *card)
2226 sprintf(dbf_text, "%s", card->info.portname + 1);
2227 for (i = 0; i < 8; i++)
2229 (char) _ebcasc[(__u8) dbf_text[i]];
2231 dev_info(&card->gdev->dev, "Device is a%s card%s%s%s\n"
2232 "with link type %s (portname: %s)\n",
2233 qeth_get_cardname(card),
2234 (card->info.mcl_level[0]) ? " (level: " : "",
2235 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2236 (card->info.mcl_level[0]) ? ")" : "",
2237 qeth_get_cardname_short(card),
2242 static void qeth_print_status_no_portname(struct qeth_card *card)
2244 if (card->info.portname[0])
2245 dev_info(&card->gdev->dev, "Device is a%s "
2246 "card%s%s%s\nwith link type %s "
2247 "(no portname needed by interface).\n",
2248 qeth_get_cardname(card),
2249 (card->info.mcl_level[0]) ? " (level: " : "",
2250 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2251 (card->info.mcl_level[0]) ? ")" : "",
2252 qeth_get_cardname_short(card));
2254 dev_info(&card->gdev->dev, "Device is a%s "
2255 "card%s%s%s\nwith link type %s.\n",
2256 qeth_get_cardname(card),
2257 (card->info.mcl_level[0]) ? " (level: " : "",
2258 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2259 (card->info.mcl_level[0]) ? ")" : "",
2260 qeth_get_cardname_short(card));
2263 void qeth_print_status_message(struct qeth_card *card)
2265 switch (card->info.type) {
2266 case QETH_CARD_TYPE_OSAE:
2267 /* VM will use a non-zero first character
2268 * to indicate a HiperSockets like reporting
2269 * of the level OSA sets the first character to zero
2271 if (!card->info.mcl_level[0]) {
2272 sprintf(card->info.mcl_level, "%02x%02x",
2273 card->info.mcl_level[2],
2274 card->info.mcl_level[3]);
2276 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2280 case QETH_CARD_TYPE_IQD:
2281 if ((card->info.guestlan) ||
2282 (card->info.mcl_level[0] & 0x80)) {
2283 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
2284 card->info.mcl_level[0]];
2285 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
2286 card->info.mcl_level[1]];
2287 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
2288 card->info.mcl_level[2]];
2289 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
2290 card->info.mcl_level[3]];
2291 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2295 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
2297 if (card->info.portname_required)
2298 qeth_print_status_with_portname(card);
2300 qeth_print_status_no_portname(card);
2302 EXPORT_SYMBOL_GPL(qeth_print_status_message);
2304 static void qeth_initialize_working_pool_list(struct qeth_card *card)
2306 struct qeth_buffer_pool_entry *entry;
2308 QETH_DBF_TEXT(TRACE, 5, "inwrklst");
2310 list_for_each_entry(entry,
2311 &card->qdio.init_pool.entry_list, init_list) {
2312 qeth_put_buffer_pool_entry(card, entry);
2316 static inline struct qeth_buffer_pool_entry *qeth_find_free_buffer_pool_entry(
2317 struct qeth_card *card)
2319 struct list_head *plh;
2320 struct qeth_buffer_pool_entry *entry;
2324 if (list_empty(&card->qdio.in_buf_pool.entry_list))
2327 list_for_each(plh, &card->qdio.in_buf_pool.entry_list) {
2328 entry = list_entry(plh, struct qeth_buffer_pool_entry, list);
2330 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2331 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2337 list_del_init(&entry->list);
2342 /* no free buffer in pool so take first one and swap pages */
2343 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2344 struct qeth_buffer_pool_entry, list);
2345 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2346 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2347 page = alloc_page(GFP_ATOMIC);
2351 free_page((unsigned long)entry->elements[i]);
2352 entry->elements[i] = page_address(page);
2353 if (card->options.performance_stats)
2354 card->perf_stats.sg_alloc_page_rx++;
2358 list_del_init(&entry->list);
2362 static int qeth_init_input_buffer(struct qeth_card *card,
2363 struct qeth_qdio_buffer *buf)
2365 struct qeth_buffer_pool_entry *pool_entry;
2368 pool_entry = qeth_find_free_buffer_pool_entry(card);
2373 * since the buffer is accessed only from the input_tasklet
2374 * there shouldn't be a need to synchronize; also, since we use
2375 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2379 buf->pool_entry = pool_entry;
2380 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2381 buf->buffer->element[i].length = PAGE_SIZE;
2382 buf->buffer->element[i].addr = pool_entry->elements[i];
2383 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2384 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2386 buf->buffer->element[i].flags = 0;
2391 int qeth_init_qdio_queues(struct qeth_card *card)
2396 QETH_DBF_TEXT(SETUP, 2, "initqdqs");
2399 memset(card->qdio.in_q->qdio_bufs, 0,
2400 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
2401 qeth_initialize_working_pool_list(card);
2402 /*give only as many buffers to hardware as we have buffer pool entries*/
2403 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
2404 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
2405 card->qdio.in_q->next_buf_to_init =
2406 card->qdio.in_buf_pool.buf_count - 1;
2407 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
2408 card->qdio.in_buf_pool.buf_count - 1);
2410 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2413 /* outbound queue */
2414 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2415 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
2416 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
2417 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2418 qeth_clear_output_buffer(card->qdio.out_qs[i],
2419 &card->qdio.out_qs[i]->bufs[j]);
2421 card->qdio.out_qs[i]->card = card;
2422 card->qdio.out_qs[i]->next_buf_to_fill = 0;
2423 card->qdio.out_qs[i]->do_pack = 0;
2424 atomic_set(&card->qdio.out_qs[i]->used_buffers, 0);
2425 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
2426 atomic_set(&card->qdio.out_qs[i]->state,
2427 QETH_OUT_Q_UNLOCKED);
2431 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues);
2433 static inline __u8 qeth_get_ipa_adp_type(enum qeth_link_types link_type)
2435 switch (link_type) {
2436 case QETH_LINK_TYPE_HSTR:
2443 static void qeth_fill_ipacmd_header(struct qeth_card *card,
2444 struct qeth_ipa_cmd *cmd, __u8 command,
2445 enum qeth_prot_versions prot)
2447 memset(cmd, 0, sizeof(struct qeth_ipa_cmd));
2448 cmd->hdr.command = command;
2449 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
2450 cmd->hdr.seqno = card->seqno.ipa;
2451 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
2452 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
2453 if (card->options.layer2)
2454 cmd->hdr.prim_version_no = 2;
2456 cmd->hdr.prim_version_no = 1;
2457 cmd->hdr.param_count = 1;
2458 cmd->hdr.prot_version = prot;
2459 cmd->hdr.ipa_supported = 0;
2460 cmd->hdr.ipa_enabled = 0;
2463 struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *card,
2464 enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
2466 struct qeth_cmd_buffer *iob;
2467 struct qeth_ipa_cmd *cmd;
2469 iob = qeth_wait_for_buffer(&card->write);
2470 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2471 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
2475 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer);
2477 void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2480 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2481 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data), &prot_type, 1);
2482 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2483 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2485 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd);
2487 int qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2488 int (*reply_cb)(struct qeth_card *, struct qeth_reply*,
2495 QETH_DBF_TEXT(TRACE, 4, "sendipa");
2497 if (card->options.layer2)
2498 if (card->info.type == QETH_CARD_TYPE_OSN)
2499 prot_type = QETH_PROT_OSN2;
2501 prot_type = QETH_PROT_LAYER2;
2503 prot_type = QETH_PROT_TCPIP;
2504 qeth_prepare_ipa_cmd(card, iob, prot_type);
2505 rc = qeth_send_control_data(card, IPA_CMD_LENGTH,
2506 iob, reply_cb, reply_param);
2509 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd);
2511 static int qeth_send_startstoplan(struct qeth_card *card,
2512 enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
2515 struct qeth_cmd_buffer *iob;
2517 iob = qeth_get_ipacmd_buffer(card, ipacmd, prot);
2518 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
2523 int qeth_send_startlan(struct qeth_card *card)
2527 QETH_DBF_TEXT(SETUP, 2, "strtlan");
2529 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, 0);
2532 EXPORT_SYMBOL_GPL(qeth_send_startlan);
2534 int qeth_send_stoplan(struct qeth_card *card)
2539 * TODO: according to the IPA format document page 14,
2540 * TCP/IP (we!) never issue a STOPLAN
2543 QETH_DBF_TEXT(SETUP, 2, "stoplan");
2545 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, 0);
2548 EXPORT_SYMBOL_GPL(qeth_send_stoplan);
2550 int qeth_default_setadapterparms_cb(struct qeth_card *card,
2551 struct qeth_reply *reply, unsigned long data)
2553 struct qeth_ipa_cmd *cmd;
2555 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
2557 cmd = (struct qeth_ipa_cmd *) data;
2558 if (cmd->hdr.return_code == 0)
2559 cmd->hdr.return_code =
2560 cmd->data.setadapterparms.hdr.return_code;
2563 EXPORT_SYMBOL_GPL(qeth_default_setadapterparms_cb);
2565 static int qeth_query_setadapterparms_cb(struct qeth_card *card,
2566 struct qeth_reply *reply, unsigned long data)
2568 struct qeth_ipa_cmd *cmd;
2570 QETH_DBF_TEXT(TRACE, 3, "quyadpcb");
2572 cmd = (struct qeth_ipa_cmd *) data;
2573 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
2574 card->info.link_type =
2575 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
2576 card->options.adp.supported_funcs =
2577 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
2578 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
2581 struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
2582 __u32 command, __u32 cmdlen)
2584 struct qeth_cmd_buffer *iob;
2585 struct qeth_ipa_cmd *cmd;
2587 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETADAPTERPARMS,
2589 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2590 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
2591 cmd->data.setadapterparms.hdr.command_code = command;
2592 cmd->data.setadapterparms.hdr.used_total = 1;
2593 cmd->data.setadapterparms.hdr.seq_no = 1;
2597 EXPORT_SYMBOL_GPL(qeth_get_adapter_cmd);
2599 int qeth_query_setadapterparms(struct qeth_card *card)
2602 struct qeth_cmd_buffer *iob;
2604 QETH_DBF_TEXT(TRACE, 3, "queryadp");
2605 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
2606 sizeof(struct qeth_ipacmd_setadpparms));
2607 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
2610 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms);
2612 int qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2613 const char *dbftext)
2616 QETH_DBF_TEXT(TRACE, 2, dbftext);
2617 QETH_DBF_TEXT(QERR, 2, dbftext);
2618 QETH_DBF_TEXT_(QERR, 2, " F15=%02X",
2619 buf->element[15].flags & 0xff);
2620 QETH_DBF_TEXT_(QERR, 2, " F14=%02X",
2621 buf->element[14].flags & 0xff);
2622 QETH_DBF_TEXT_(QERR, 2, " qerr=%X", qdio_error);
2627 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors);
2629 void qeth_queue_input_buffer(struct qeth_card *card, int index)
2631 struct qeth_qdio_q *queue = card->qdio.in_q;
2637 count = (index < queue->next_buf_to_init)?
2638 card->qdio.in_buf_pool.buf_count -
2639 (queue->next_buf_to_init - index) :
2640 card->qdio.in_buf_pool.buf_count -
2641 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2642 /* only requeue at a certain threshold to avoid SIGAs */
2643 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)) {
2644 for (i = queue->next_buf_to_init;
2645 i < queue->next_buf_to_init + count; ++i) {
2646 if (qeth_init_input_buffer(card,
2647 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q])) {
2654 if (newcount < count) {
2655 /* we are in memory shortage so we switch back to
2656 traditional skb allocation and drop packages */
2657 atomic_set(&card->force_alloc_skb, 3);
2660 atomic_add_unless(&card->force_alloc_skb, -1, 0);
2664 * according to old code it should be avoided to requeue all
2665 * 128 buffers in order to benefit from PCI avoidance.
2666 * this function keeps at least one buffer (the buffer at
2667 * 'index') un-requeued -> this buffer is the first buffer that
2668 * will be requeued the next time
2670 if (card->options.performance_stats) {
2671 card->perf_stats.inbound_do_qdio_cnt++;
2672 card->perf_stats.inbound_do_qdio_start_time =
2675 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0,
2676 queue->next_buf_to_init, count);
2677 if (card->options.performance_stats)
2678 card->perf_stats.inbound_do_qdio_time +=
2680 card->perf_stats.inbound_do_qdio_start_time;
2682 dev_warn(&card->gdev->dev,
2683 "QDIO reported an error, rc=%i\n", rc);
2684 QETH_DBF_TEXT(TRACE, 2, "qinberr");
2685 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
2687 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2688 QDIO_MAX_BUFFERS_PER_Q;
2691 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer);
2693 static int qeth_handle_send_error(struct qeth_card *card,
2694 struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err)
2696 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2697 int cc = qdio_err & 3;
2699 QETH_DBF_TEXT(TRACE, 6, "hdsnderr");
2700 qeth_check_qdio_errors(buffer->buffer, qdio_err, "qouterr");
2704 QETH_DBF_TEXT(TRACE, 1, "lnkfail");
2705 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2706 QETH_DBF_TEXT_(TRACE, 1, "%04x %02x",
2707 (u16)qdio_err, (u8)sbalf15);
2708 return QETH_SEND_ERROR_LINK_FAILURE;
2710 return QETH_SEND_ERROR_NONE;
2712 if (qdio_err & QDIO_ERROR_SIGA_BUSY) {
2713 QETH_DBF_TEXT(TRACE, 1, "SIGAcc2B");
2714 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2715 return QETH_SEND_ERROR_KICK_IT;
2717 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2718 return QETH_SEND_ERROR_RETRY;
2719 return QETH_SEND_ERROR_LINK_FAILURE;
2720 /* look at qdio_error and sbalf 15 */
2722 QETH_DBF_TEXT(TRACE, 1, "SIGAcc1");
2723 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2724 return QETH_SEND_ERROR_LINK_FAILURE;
2727 QETH_DBF_TEXT(TRACE, 1, "SIGAcc3");
2728 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2729 return QETH_SEND_ERROR_KICK_IT;
2734 * Switched to packing state if the number of used buffers on a queue
2735 * reaches a certain limit.
2737 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2739 if (!queue->do_pack) {
2740 if (atomic_read(&queue->used_buffers)
2741 >= QETH_HIGH_WATERMARK_PACK){
2742 /* switch non-PACKING -> PACKING */
2743 QETH_DBF_TEXT(TRACE, 6, "np->pack");
2744 if (queue->card->options.performance_stats)
2745 queue->card->perf_stats.sc_dp_p++;
2752 * Switches from packing to non-packing mode. If there is a packing
2753 * buffer on the queue this buffer will be prepared to be flushed.
2754 * In that case 1 is returned to inform the caller. If no buffer
2755 * has to be flushed, zero is returned.
2757 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2759 struct qeth_qdio_out_buffer *buffer;
2760 int flush_count = 0;
2762 if (queue->do_pack) {
2763 if (atomic_read(&queue->used_buffers)
2764 <= QETH_LOW_WATERMARK_PACK) {
2765 /* switch PACKING -> non-PACKING */
2766 QETH_DBF_TEXT(TRACE, 6, "pack->np");
2767 if (queue->card->options.performance_stats)
2768 queue->card->perf_stats.sc_p_dp++;
2770 /* flush packing buffers */
2771 buffer = &queue->bufs[queue->next_buf_to_fill];
2772 if ((atomic_read(&buffer->state) ==
2773 QETH_QDIO_BUF_EMPTY) &&
2774 (buffer->next_element_to_fill > 0)) {
2775 atomic_set(&buffer->state,
2776 QETH_QDIO_BUF_PRIMED);
2778 queue->next_buf_to_fill =
2779 (queue->next_buf_to_fill + 1) %
2780 QDIO_MAX_BUFFERS_PER_Q;
2788 * Called to flush a packing buffer if no more pci flags are on the queue.
2789 * Checks if there is a packing buffer and prepares it to be flushed.
2790 * In that case returns 1, otherwise zero.
2792 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2794 struct qeth_qdio_out_buffer *buffer;
2796 buffer = &queue->bufs[queue->next_buf_to_fill];
2797 if ((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2798 (buffer->next_element_to_fill > 0)) {
2799 /* it's a packing buffer */
2800 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2801 queue->next_buf_to_fill =
2802 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2808 static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
2811 struct qeth_qdio_out_buffer *buf;
2814 unsigned int qdio_flags;
2816 for (i = index; i < index + count; ++i) {
2817 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2818 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2819 SBAL_FLAGS_LAST_ENTRY;
2821 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2824 if (!queue->do_pack) {
2825 if ((atomic_read(&queue->used_buffers) >=
2826 (QETH_HIGH_WATERMARK_PACK -
2827 QETH_WATERMARK_PACK_FUZZ)) &&
2828 !atomic_read(&queue->set_pci_flags_count)) {
2829 /* it's likely that we'll go to packing
2831 atomic_inc(&queue->set_pci_flags_count);
2832 buf->buffer->element[0].flags |= 0x40;
2835 if (!atomic_read(&queue->set_pci_flags_count)) {
2837 * there's no outstanding PCI any more, so we
2838 * have to request a PCI to be sure the the PCI
2839 * will wake at some time in the future then we
2840 * can flush packed buffers that might still be
2841 * hanging around, which can happen if no
2842 * further send was requested by the stack
2844 atomic_inc(&queue->set_pci_flags_count);
2845 buf->buffer->element[0].flags |= 0x40;
2850 queue->card->dev->trans_start = jiffies;
2851 if (queue->card->options.performance_stats) {
2852 queue->card->perf_stats.outbound_do_qdio_cnt++;
2853 queue->card->perf_stats.outbound_do_qdio_start_time =
2856 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
2857 if (atomic_read(&queue->set_pci_flags_count))
2858 qdio_flags |= QDIO_FLAG_PCI_OUT;
2859 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
2860 queue->queue_no, index, count);
2861 if (queue->card->options.performance_stats)
2862 queue->card->perf_stats.outbound_do_qdio_time +=
2864 queue->card->perf_stats.outbound_do_qdio_start_time;
2866 QETH_DBF_TEXT(TRACE, 2, "flushbuf");
2867 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
2868 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_DDEV_ID(queue->card));
2869 queue->card->stats.tx_errors += count;
2870 /* this must not happen under normal circumstances. if it
2871 * happens something is really wrong -> recover */
2872 qeth_schedule_recovery(queue->card);
2875 atomic_add(count, &queue->used_buffers);
2876 if (queue->card->options.performance_stats)
2877 queue->card->perf_stats.bufs_sent += count;
2880 static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2884 int q_was_packing = 0;
2887 * check if weed have to switch to non-packing mode or if
2888 * we have to get a pci flag out on the queue
2890 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2891 !atomic_read(&queue->set_pci_flags_count)) {
2892 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2893 QETH_OUT_Q_UNLOCKED) {
2895 * If we get in here, there was no action in
2896 * do_send_packet. So, we check if there is a
2897 * packing buffer to be flushed here.
2899 netif_stop_queue(queue->card->dev);
2900 index = queue->next_buf_to_fill;
2901 q_was_packing = queue->do_pack;
2902 /* queue->do_pack may change */
2904 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
2906 !atomic_read(&queue->set_pci_flags_count))
2908 qeth_flush_buffers_on_no_pci(queue);
2909 if (queue->card->options.performance_stats &&
2911 queue->card->perf_stats.bufs_sent_pack +=
2914 qeth_flush_buffers(queue, index, flush_cnt);
2915 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
2920 void qeth_qdio_output_handler(struct ccw_device *ccwdev,
2921 unsigned int qdio_error, int __queue, int first_element,
2922 int count, unsigned long card_ptr)
2924 struct qeth_card *card = (struct qeth_card *) card_ptr;
2925 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
2926 struct qeth_qdio_out_buffer *buffer;
2929 QETH_DBF_TEXT(TRACE, 6, "qdouhdl");
2930 if (qdio_error & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
2931 QETH_DBF_TEXT(TRACE, 2, "achkcond");
2932 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
2933 netif_stop_queue(card->dev);
2934 qeth_schedule_recovery(card);
2937 if (card->options.performance_stats) {
2938 card->perf_stats.outbound_handler_cnt++;
2939 card->perf_stats.outbound_handler_start_time =
2942 for (i = first_element; i < (first_element + count); ++i) {
2943 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2944 /*we only handle the KICK_IT error by doing a recovery */
2945 if (qeth_handle_send_error(card, buffer, qdio_error)
2946 == QETH_SEND_ERROR_KICK_IT){
2947 netif_stop_queue(card->dev);
2948 qeth_schedule_recovery(card);
2951 qeth_clear_output_buffer(queue, buffer);
2953 atomic_sub(count, &queue->used_buffers);
2954 /* check if we need to do something on this outbound queue */
2955 if (card->info.type != QETH_CARD_TYPE_IQD)
2956 qeth_check_outbound_queue(queue);
2958 netif_wake_queue(queue->card->dev);
2959 if (card->options.performance_stats)
2960 card->perf_stats.outbound_handler_time += qeth_get_micros() -
2961 card->perf_stats.outbound_handler_start_time;
2963 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler);
2965 int qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2967 int cast_type = RTN_UNSPEC;
2969 if (card->info.type == QETH_CARD_TYPE_OSN)
2972 if (skb->dst && skb->dst->neighbour) {
2973 cast_type = skb->dst->neighbour->type;
2974 if ((cast_type == RTN_BROADCAST) ||
2975 (cast_type == RTN_MULTICAST) ||
2976 (cast_type == RTN_ANYCAST))
2981 /* try something else */
2982 if (skb->protocol == ETH_P_IPV6)
2983 return (skb_network_header(skb)[24] == 0xff) ?
2985 else if (skb->protocol == ETH_P_IP)
2986 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2989 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2990 return RTN_BROADCAST;
2994 hdr_mac = *((u16 *)skb->data);
2996 switch (card->info.link_type) {
2997 case QETH_LINK_TYPE_HSTR:
2998 case QETH_LINK_TYPE_LANE_TR:
2999 if ((hdr_mac == QETH_TR_MAC_NC) ||
3000 (hdr_mac == QETH_TR_MAC_C))
3001 return RTN_MULTICAST;
3003 /* eth or so multicast? */
3005 if ((hdr_mac == QETH_ETH_MAC_V4) ||
3006 (hdr_mac == QETH_ETH_MAC_V6))
3007 return RTN_MULTICAST;
3012 EXPORT_SYMBOL_GPL(qeth_get_cast_type);
3014 int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3015 int ipv, int cast_type)
3017 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3018 return card->qdio.default_out_queue;
3019 switch (card->qdio.no_out_queues) {
3021 if (cast_type && card->info.is_multicast_different)
3022 return card->info.is_multicast_different &
3023 (card->qdio.no_out_queues - 1);
3024 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3025 const u8 tos = ip_hdr(skb)->tos;
3027 if (card->qdio.do_prio_queueing ==
3028 QETH_PRIO_Q_ING_TOS) {
3029 if (tos & IP_TOS_NOTIMPORTANT)
3031 if (tos & IP_TOS_HIGHRELIABILITY)
3033 if (tos & IP_TOS_HIGHTHROUGHPUT)
3035 if (tos & IP_TOS_LOWDELAY)
3038 if (card->qdio.do_prio_queueing ==
3039 QETH_PRIO_Q_ING_PREC)
3040 return 3 - (tos >> 6);
3041 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3044 return card->qdio.default_out_queue;
3045 case 1: /* fallthrough for single-out-queue 1920-device */
3047 return card->qdio.default_out_queue;
3050 EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
3052 int qeth_get_elements_no(struct qeth_card *card, void *hdr,
3053 struct sk_buff *skb, int elems)
3055 int elements_needed = 0;
3057 if (skb_shinfo(skb)->nr_frags > 0)
3058 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
3059 if (elements_needed == 0)
3060 elements_needed = 1 + (((((unsigned long) skb->data) %
3061 PAGE_SIZE) + skb->len) >> PAGE_SHIFT);
3062 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
3063 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3064 "(Number=%d / Length=%d). Discarded.\n",
3065 (elements_needed+elems), skb->len);
3068 return elements_needed;
3070 EXPORT_SYMBOL_GPL(qeth_get_elements_no);
3072 static inline void __qeth_fill_buffer(struct sk_buff *skb,
3073 struct qdio_buffer *buffer, int is_tso, int *next_element_to_fill,
3076 int length = skb->len;
3082 element = *next_element_to_fill;
3084 first_lap = (is_tso == 0 ? 1 : 0);
3087 data = skb->data + offset;
3092 while (length > 0) {
3093 /* length_here is the remaining amount of data in this page */
3094 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
3095 if (length < length_here)
3096 length_here = length;
3098 buffer->element[element].addr = data;
3099 buffer->element[element].length = length_here;
3100 length -= length_here;
3103 buffer->element[element].flags = 0;
3105 buffer->element[element].flags =
3106 SBAL_FLAGS_LAST_FRAG;
3109 buffer->element[element].flags =
3110 SBAL_FLAGS_FIRST_FRAG;
3112 buffer->element[element].flags =
3113 SBAL_FLAGS_MIDDLE_FRAG;
3115 data += length_here;
3119 *next_element_to_fill = element;
3122 static inline int qeth_fill_buffer(struct qeth_qdio_out_q *queue,
3123 struct qeth_qdio_out_buffer *buf, struct sk_buff *skb,
3124 struct qeth_hdr *hdr, int offset, int hd_len)
3126 struct qdio_buffer *buffer;
3127 int flush_cnt = 0, hdr_len, large_send = 0;
3129 buffer = buf->buffer;
3130 atomic_inc(&skb->users);
3131 skb_queue_tail(&buf->skb_list, skb);
3133 /*check first on TSO ....*/
3134 if (hdr->hdr.l3.id == QETH_HEADER_TYPE_TSO) {
3135 int element = buf->next_element_to_fill;
3137 hdr_len = sizeof(struct qeth_hdr_tso) +
3138 ((struct qeth_hdr_tso *)hdr)->ext.dg_hdr_len;
3139 /*fill first buffer entry only with header information */
3140 buffer->element[element].addr = skb->data;
3141 buffer->element[element].length = hdr_len;
3142 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
3143 buf->next_element_to_fill++;
3144 skb->data += hdr_len;
3145 skb->len -= hdr_len;
3150 int element = buf->next_element_to_fill;
3151 buffer->element[element].addr = hdr;
3152 buffer->element[element].length = sizeof(struct qeth_hdr) +
3154 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
3155 buf->is_header[element] = 1;
3156 buf->next_element_to_fill++;
3159 if (skb_shinfo(skb)->nr_frags == 0)
3160 __qeth_fill_buffer(skb, buffer, large_send,
3161 (int *)&buf->next_element_to_fill, offset);
3163 __qeth_fill_buffer_frag(skb, buffer, large_send,
3164 (int *)&buf->next_element_to_fill);
3166 if (!queue->do_pack) {
3167 QETH_DBF_TEXT(TRACE, 6, "fillbfnp");
3168 /* set state to PRIMED -> will be flushed */
3169 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
3172 QETH_DBF_TEXT(TRACE, 6, "fillbfpa");
3173 if (queue->card->options.performance_stats)
3174 queue->card->perf_stats.skbs_sent_pack++;
3175 if (buf->next_element_to_fill >=
3176 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
3178 * packed buffer if full -> set state PRIMED
3179 * -> will be flushed
3181 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
3188 int qeth_do_send_packet_fast(struct qeth_card *card,
3189 struct qeth_qdio_out_q *queue, struct sk_buff *skb,
3190 struct qeth_hdr *hdr, int elements_needed,
3191 struct qeth_eddp_context *ctx, int offset, int hd_len)
3193 struct qeth_qdio_out_buffer *buffer;
3194 int buffers_needed = 0;
3198 /* spin until we get the queue ... */
3199 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3200 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
3201 /* ... now we've got the queue */
3202 index = queue->next_buf_to_fill;
3203 buffer = &queue->bufs[queue->next_buf_to_fill];
3205 * check if buffer is empty to make sure that we do not 'overtake'
3206 * ourselves and try to fill a buffer that is already primed
3208 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
3211 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
3212 QDIO_MAX_BUFFERS_PER_Q;
3214 buffers_needed = qeth_eddp_check_buffers_for_context(queue,
3216 if (buffers_needed < 0)
3218 queue->next_buf_to_fill =
3219 (queue->next_buf_to_fill + buffers_needed) %
3220 QDIO_MAX_BUFFERS_PER_Q;
3222 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3224 qeth_fill_buffer(queue, buffer, skb, hdr, offset, hd_len);
3225 qeth_flush_buffers(queue, index, 1);
3227 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
3228 WARN_ON(buffers_needed != flush_cnt);
3229 qeth_flush_buffers(queue, index, flush_cnt);
3233 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3236 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast);
3238 int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
3239 struct sk_buff *skb, struct qeth_hdr *hdr,
3240 int elements_needed, struct qeth_eddp_context *ctx)
3242 struct qeth_qdio_out_buffer *buffer;
3244 int flush_count = 0;
3249 /* spin until we get the queue ... */
3250 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3251 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
3252 start_index = queue->next_buf_to_fill;
3253 buffer = &queue->bufs[queue->next_buf_to_fill];
3255 * check if buffer is empty to make sure that we do not 'overtake'
3256 * ourselves and try to fill a buffer that is already primed
3258 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
3259 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3262 /* check if we need to switch packing state of this queue */
3263 qeth_switch_to_packing_if_needed(queue);
3264 if (queue->do_pack) {
3267 /* does packet fit in current buffer? */
3268 if ((QETH_MAX_BUFFER_ELEMENTS(card) -
3269 buffer->next_element_to_fill) < elements_needed) {
3270 /* ... no -> set state PRIMED */
3271 atomic_set(&buffer->state,
3272 QETH_QDIO_BUF_PRIMED);
3274 queue->next_buf_to_fill =
3275 (queue->next_buf_to_fill + 1) %
3276 QDIO_MAX_BUFFERS_PER_Q;
3277 buffer = &queue->bufs[queue->next_buf_to_fill];
3278 /* we did a step forward, so check buffer state
3280 if (atomic_read(&buffer->state) !=
3281 QETH_QDIO_BUF_EMPTY){
3282 qeth_flush_buffers(queue, start_index,
3284 atomic_set(&queue->state,
3285 QETH_OUT_Q_UNLOCKED);
3290 /* check if we have enough elements (including following
3291 * free buffers) to handle eddp context */
3292 if (qeth_eddp_check_buffers_for_context(queue, ctx)
3300 tmp = qeth_fill_buffer(queue, buffer, skb, hdr, -1, 0);
3302 tmp = qeth_eddp_fill_buffer(queue, ctx,
3303 queue->next_buf_to_fill);
3309 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
3310 QDIO_MAX_BUFFERS_PER_Q;
3314 qeth_flush_buffers(queue, start_index, flush_count);
3315 else if (!atomic_read(&queue->set_pci_flags_count))
3316 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
3318 * queue->state will go from LOCKED -> UNLOCKED or from
3319 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
3320 * (switch packing state or flush buffer to get another pci flag out).
3321 * In that case we will enter this loop
3323 while (atomic_dec_return(&queue->state)) {
3325 start_index = queue->next_buf_to_fill;
3326 /* check if we can go back to non-packing state */
3327 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
3329 * check if we need to flush a packing buffer to get a pci
3330 * flag out on the queue
3332 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
3333 flush_count += qeth_flush_buffers_on_no_pci(queue);
3335 qeth_flush_buffers(queue, start_index, flush_count);
3337 /* at this point the queue is UNLOCKED again */
3338 if (queue->card->options.performance_stats && do_pack)
3339 queue->card->perf_stats.bufs_sent_pack += flush_count;
3343 EXPORT_SYMBOL_GPL(qeth_do_send_packet);
3345 static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
3346 struct qeth_reply *reply, unsigned long data)
3348 struct qeth_ipa_cmd *cmd;
3349 struct qeth_ipacmd_setadpparms *setparms;
3351 QETH_DBF_TEXT(TRACE, 4, "prmadpcb");
3353 cmd = (struct qeth_ipa_cmd *) data;
3354 setparms = &(cmd->data.setadapterparms);
3356 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
3357 if (cmd->hdr.return_code) {
3358 QETH_DBF_TEXT_(TRACE, 4, "prmrc%2.2x", cmd->hdr.return_code);
3359 setparms->data.mode = SET_PROMISC_MODE_OFF;
3361 card->info.promisc_mode = setparms->data.mode;
3365 void qeth_setadp_promisc_mode(struct qeth_card *card)
3367 enum qeth_ipa_promisc_modes mode;
3368 struct net_device *dev = card->dev;
3369 struct qeth_cmd_buffer *iob;
3370 struct qeth_ipa_cmd *cmd;
3372 QETH_DBF_TEXT(TRACE, 4, "setprom");
3374 if (((dev->flags & IFF_PROMISC) &&
3375 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
3376 (!(dev->flags & IFF_PROMISC) &&
3377 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
3379 mode = SET_PROMISC_MODE_OFF;
3380 if (dev->flags & IFF_PROMISC)
3381 mode = SET_PROMISC_MODE_ON;
3382 QETH_DBF_TEXT_(TRACE, 4, "mode:%x", mode);
3384 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
3385 sizeof(struct qeth_ipacmd_setadpparms));
3386 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
3387 cmd->data.setadapterparms.data.mode = mode;
3388 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
3390 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode);
3392 int qeth_change_mtu(struct net_device *dev, int new_mtu)
3394 struct qeth_card *card;
3397 card = dev->ml_priv;
3399 QETH_DBF_TEXT(TRACE, 4, "chgmtu");
3400 sprintf(dbf_text, "%8x", new_mtu);
3401 QETH_DBF_TEXT(TRACE, 4, dbf_text);
3405 if (new_mtu > 65535)
3407 if ((!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) &&
3408 (!qeth_mtu_is_valid(card, new_mtu)))
3413 EXPORT_SYMBOL_GPL(qeth_change_mtu);
3415 struct net_device_stats *qeth_get_stats(struct net_device *dev)
3417 struct qeth_card *card;
3419 card = dev->ml_priv;
3421 QETH_DBF_TEXT(TRACE, 5, "getstat");
3423 return &card->stats;
3425 EXPORT_SYMBOL_GPL(qeth_get_stats);
3427 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
3428 struct qeth_reply *reply, unsigned long data)
3430 struct qeth_ipa_cmd *cmd;
3432 QETH_DBF_TEXT(TRACE, 4, "chgmaccb");
3434 cmd = (struct qeth_ipa_cmd *) data;
3435 if (!card->options.layer2 ||
3436 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
3437 memcpy(card->dev->dev_addr,
3438 &cmd->data.setadapterparms.data.change_addr.addr,
3440 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
3442 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
3446 int qeth_setadpparms_change_macaddr(struct qeth_card *card)
3449 struct qeth_cmd_buffer *iob;
3450 struct qeth_ipa_cmd *cmd;
3452 QETH_DBF_TEXT(TRACE, 4, "chgmac");
3454 iob = qeth_get_adapter_cmd(card, IPA_SETADP_ALTER_MAC_ADDRESS,
3455 sizeof(struct qeth_ipacmd_setadpparms));
3456 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3457 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
3458 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
3459 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
3460 card->dev->dev_addr, OSA_ADDR_LEN);
3461 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
3465 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
3467 void qeth_tx_timeout(struct net_device *dev)
3469 struct qeth_card *card;
3471 card = dev->ml_priv;
3472 card->stats.tx_errors++;
3473 qeth_schedule_recovery(card);
3475 EXPORT_SYMBOL_GPL(qeth_tx_timeout);
3477 int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
3479 struct qeth_card *card = dev->ml_priv;
3483 case MII_BMCR: /* Basic mode control register */
3485 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH) &&
3486 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
3487 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
3488 rc |= BMCR_SPEED100;
3490 case MII_BMSR: /* Basic mode status register */
3491 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
3492 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
3495 case MII_PHYSID1: /* PHYS ID 1 */
3496 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
3498 rc = (rc >> 5) & 0xFFFF;
3500 case MII_PHYSID2: /* PHYS ID 2 */
3501 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
3503 case MII_ADVERTISE: /* Advertisement control reg */
3506 case MII_LPA: /* Link partner ability reg */
3507 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
3508 LPA_100BASE4 | LPA_LPACK;
3510 case MII_EXPANSION: /* Expansion register */
3512 case MII_DCOUNTER: /* disconnect counter */
3514 case MII_FCSCOUNTER: /* false carrier counter */
3516 case MII_NWAYTEST: /* N-way auto-neg test register */
3518 case MII_RERRCOUNTER: /* rx error counter */
3519 rc = card->stats.rx_errors;
3521 case MII_SREVISION: /* silicon revision */
3523 case MII_RESV1: /* reserved 1 */
3525 case MII_LBRERROR: /* loopback, rx, bypass error */
3527 case MII_PHYADDR: /* physical address */
3529 case MII_RESV2: /* reserved 2 */
3531 case MII_TPISTATUS: /* TPI status for 10mbps */
3533 case MII_NCONFIG: /* network interface config */
3540 EXPORT_SYMBOL_GPL(qeth_mdio_read);
3542 static int qeth_send_ipa_snmp_cmd(struct qeth_card *card,
3543 struct qeth_cmd_buffer *iob, int len,
3544 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
3550 QETH_DBF_TEXT(TRACE, 4, "sendsnmp");
3552 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
3553 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
3554 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3555 /* adjust PDU length fields in IPA_PDU_HEADER */
3556 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
3558 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
3559 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
3560 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
3561 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
3562 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
3563 reply_cb, reply_param);
3566 static int qeth_snmp_command_cb(struct qeth_card *card,
3567 struct qeth_reply *reply, unsigned long sdata)
3569 struct qeth_ipa_cmd *cmd;
3570 struct qeth_arp_query_info *qinfo;
3571 struct qeth_snmp_cmd *snmp;
3572 unsigned char *data;
3575 QETH_DBF_TEXT(TRACE, 3, "snpcmdcb");
3577 cmd = (struct qeth_ipa_cmd *) sdata;
3578 data = (unsigned char *)((char *)cmd - reply->offset);
3579 qinfo = (struct qeth_arp_query_info *) reply->param;
3580 snmp = &cmd->data.setadapterparms.data.snmp;
3582 if (cmd->hdr.return_code) {
3583 QETH_DBF_TEXT_(TRACE, 4, "scer1%i", cmd->hdr.return_code);
3586 if (cmd->data.setadapterparms.hdr.return_code) {
3587 cmd->hdr.return_code =
3588 cmd->data.setadapterparms.hdr.return_code;
3589 QETH_DBF_TEXT_(TRACE, 4, "scer2%i", cmd->hdr.return_code);
3592 data_len = *((__u16 *)QETH_IPA_PDU_LEN_PDU1(data));
3593 if (cmd->data.setadapterparms.hdr.seq_no == 1)
3594 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
3596 data_len -= (__u16)((char *)&snmp->request - (char *)cmd);
3598 /* check if there is enough room in userspace */
3599 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
3600 QETH_DBF_TEXT_(TRACE, 4, "scer3%i", -ENOMEM);
3601 cmd->hdr.return_code = -ENOMEM;
3604 QETH_DBF_TEXT_(TRACE, 4, "snore%i",
3605 cmd->data.setadapterparms.hdr.used_total);
3606 QETH_DBF_TEXT_(TRACE, 4, "sseqn%i",
3607 cmd->data.setadapterparms.hdr.seq_no);
3608 /*copy entries to user buffer*/
3609 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
3610 memcpy(qinfo->udata + qinfo->udata_offset,
3612 data_len + offsetof(struct qeth_snmp_cmd, data));
3613 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
3615 memcpy(qinfo->udata + qinfo->udata_offset,
3616 (char *)&snmp->request, data_len);
3618 qinfo->udata_offset += data_len;
3619 /* check if all replies received ... */
3620 QETH_DBF_TEXT_(TRACE, 4, "srtot%i",
3621 cmd->data.setadapterparms.hdr.used_total);
3622 QETH_DBF_TEXT_(TRACE, 4, "srseq%i",
3623 cmd->data.setadapterparms.hdr.seq_no);
3624 if (cmd->data.setadapterparms.hdr.seq_no <
3625 cmd->data.setadapterparms.hdr.used_total)
3630 int qeth_snmp_command(struct qeth_card *card, char __user *udata)
3632 struct qeth_cmd_buffer *iob;
3633 struct qeth_ipa_cmd *cmd;
3634 struct qeth_snmp_ureq *ureq;
3636 struct qeth_arp_query_info qinfo = {0, };
3639 QETH_DBF_TEXT(TRACE, 3, "snmpcmd");
3641 if (card->info.guestlan)
3644 if ((!qeth_adp_supported(card, IPA_SETADP_SET_SNMP_CONTROL)) &&
3645 (!card->options.layer2)) {
3648 /* skip 4 bytes (data_len struct member) to get req_len */
3649 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
3651 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
3653 QETH_DBF_TEXT(TRACE, 2, "snmpnome");
3656 if (copy_from_user(ureq, udata,
3657 req_len + sizeof(struct qeth_snmp_ureq_hdr))) {
3661 qinfo.udata_len = ureq->hdr.data_len;
3662 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
3667 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
3669 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
3670 QETH_SNMP_SETADP_CMDLENGTH + req_len);
3671 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3672 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
3673 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
3674 qeth_snmp_command_cb, (void *)&qinfo);
3676 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
3677 QETH_CARD_IFNAME(card), rc);
3679 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
3687 EXPORT_SYMBOL_GPL(qeth_snmp_command);
3689 static inline int qeth_get_qdio_q_format(struct qeth_card *card)
3691 switch (card->info.type) {
3692 case QETH_CARD_TYPE_IQD:
3699 static int qeth_qdio_establish(struct qeth_card *card)
3701 struct qdio_initialize init_data;
3702 char *qib_param_field;
3703 struct qdio_buffer **in_sbal_ptrs;
3704 struct qdio_buffer **out_sbal_ptrs;
3708 QETH_DBF_TEXT(SETUP, 2, "qdioest");
3710 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3712 if (!qib_param_field)
3715 qeth_create_qib_param_field(card, qib_param_field);
3716 qeth_create_qib_param_field_blkt(card, qib_param_field);
3718 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3720 if (!in_sbal_ptrs) {
3721 kfree(qib_param_field);
3724 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3725 in_sbal_ptrs[i] = (struct qdio_buffer *)
3726 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3729 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3730 sizeof(void *), GFP_KERNEL);
3731 if (!out_sbal_ptrs) {
3732 kfree(in_sbal_ptrs);
3733 kfree(qib_param_field);
3736 for (i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3737 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k) {
3738 out_sbal_ptrs[k] = (struct qdio_buffer *)virt_to_phys(
3739 card->qdio.out_qs[i]->bufs[j].buffer);
3742 memset(&init_data, 0, sizeof(struct qdio_initialize));
3743 init_data.cdev = CARD_DDEV(card);
3744 init_data.q_format = qeth_get_qdio_q_format(card);
3745 init_data.qib_param_field_format = 0;
3746 init_data.qib_param_field = qib_param_field;
3747 init_data.no_input_qs = 1;
3748 init_data.no_output_qs = card->qdio.no_out_queues;
3749 init_data.input_handler = card->discipline.input_handler;
3750 init_data.output_handler = card->discipline.output_handler;
3751 init_data.int_parm = (unsigned long) card;
3752 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3753 QDIO_OUTBOUND_0COPY_SBALS |
3754 QDIO_USE_OUTBOUND_PCIS;
3755 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3756 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3758 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3759 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
3760 rc = qdio_initialize(&init_data);
3762 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3764 kfree(out_sbal_ptrs);
3765 kfree(in_sbal_ptrs);
3766 kfree(qib_param_field);
3770 static void qeth_core_free_card(struct qeth_card *card)
3773 QETH_DBF_TEXT(SETUP, 2, "freecrd");
3774 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
3775 qeth_clean_channel(&card->read);
3776 qeth_clean_channel(&card->write);
3778 free_netdev(card->dev);
3779 kfree(card->ip_tbd_list);
3780 qeth_free_qdio_buffers(card);
3781 unregister_service_level(&card->qeth_service_level);
3785 static struct ccw_device_id qeth_ids[] = {
3786 {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
3787 {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
3788 {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
3791 MODULE_DEVICE_TABLE(ccw, qeth_ids);
3793 static struct ccw_driver qeth_ccw_driver = {
3796 .probe = ccwgroup_probe_ccwdev,
3797 .remove = ccwgroup_remove_ccwdev,
3800 static int qeth_core_driver_group(const char *buf, struct device *root_dev,
3801 unsigned long driver_id)
3803 return ccwgroup_create_from_string(root_dev, driver_id,
3804 &qeth_ccw_driver, 3, buf);
3807 int qeth_core_hardsetup_card(struct qeth_card *card)
3809 struct qdio_ssqd_desc *ssqd;
3814 QETH_DBF_TEXT(SETUP, 2, "hrdsetup");
3815 atomic_set(&card->force_alloc_skb, 0);
3818 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
3819 dev_name(&card->gdev->dev));
3820 ccw_device_set_offline(CARD_DDEV(card));
3821 ccw_device_set_offline(CARD_WDEV(card));
3822 ccw_device_set_offline(CARD_RDEV(card));
3823 ccw_device_set_online(CARD_RDEV(card));
3824 ccw_device_set_online(CARD_WDEV(card));
3825 ccw_device_set_online(CARD_DDEV(card));
3827 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
3828 if (rc == -ERESTARTSYS) {
3829 QETH_DBF_TEXT(SETUP, 2, "break1");
3832 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3839 rc = qeth_get_unitaddr(card);
3841 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3845 ssqd = kmalloc(sizeof(struct qdio_ssqd_desc), GFP_KERNEL);
3850 rc = qdio_get_ssqd_desc(CARD_DDEV(card), ssqd);
3856 mpno = min(mpno - 1, QETH_MAX_PORTNO);
3857 if (card->info.portno > mpno) {
3858 QETH_DBF_MESSAGE(2, "Device %s does not offer port number %d"
3859 "\n.", CARD_BUS_ID(card), card->info.portno);
3863 qeth_init_tokens(card);
3864 qeth_init_func_level(card);
3865 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
3866 if (rc == -ERESTARTSYS) {
3867 QETH_DBF_TEXT(SETUP, 2, "break2");
3870 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3876 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
3877 if (rc == -ERESTARTSYS) {
3878 QETH_DBF_TEXT(SETUP, 2, "break3");
3881 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3887 rc = qeth_mpc_initialize(card);
3889 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3894 dev_warn(&card->gdev->dev, "The qeth device driver failed to recover "
3895 "an error on the device\n");
3896 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
3897 dev_name(&card->gdev->dev), rc);
3900 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card);
3902 static inline int qeth_create_skb_frag(struct qdio_buffer_element *element,
3903 struct sk_buff **pskb, int offset, int *pfrag, int data_len)
3905 struct page *page = virt_to_page(element->addr);
3906 if (*pskb == NULL) {
3907 /* the upper protocol layers assume that there is data in the
3908 * skb itself. Copy a small amount (64 bytes) to make them
3910 *pskb = dev_alloc_skb(64 + ETH_HLEN);
3913 skb_reserve(*pskb, ETH_HLEN);
3914 if (data_len <= 64) {
3915 memcpy(skb_put(*pskb, data_len), element->addr + offset,
3919 memcpy(skb_put(*pskb, 64), element->addr + offset, 64);
3920 skb_fill_page_desc(*pskb, *pfrag, page, offset + 64,
3922 (*pskb)->data_len += data_len - 64;
3923 (*pskb)->len += data_len - 64;
3924 (*pskb)->truesize += data_len - 64;
3929 skb_fill_page_desc(*pskb, *pfrag, page, offset, data_len);
3930 (*pskb)->data_len += data_len;
3931 (*pskb)->len += data_len;
3932 (*pskb)->truesize += data_len;
3938 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
3939 struct qdio_buffer *buffer,
3940 struct qdio_buffer_element **__element, int *__offset,
3941 struct qeth_hdr **hdr)
3943 struct qdio_buffer_element *element = *__element;
3944 int offset = *__offset;
3945 struct sk_buff *skb = NULL;
3953 /* qeth_hdr must not cross element boundaries */
3954 if (element->length < offset + sizeof(struct qeth_hdr)) {
3955 if (qeth_is_last_sbale(element))
3959 if (element->length < sizeof(struct qeth_hdr))
3962 *hdr = element->addr + offset;
3964 offset += sizeof(struct qeth_hdr);
3965 if (card->options.layer2) {
3966 if (card->info.type == QETH_CARD_TYPE_OSN) {
3967 skb_len = (*hdr)->hdr.osn.pdu_length;
3968 headroom = sizeof(struct qeth_hdr);
3970 skb_len = (*hdr)->hdr.l2.pkt_length;
3973 skb_len = (*hdr)->hdr.l3.length;
3974 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3975 (card->info.link_type == QETH_LINK_TYPE_HSTR))
3978 headroom = ETH_HLEN;
3984 if ((skb_len >= card->options.rx_sg_cb) &&
3985 (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
3986 (!atomic_read(&card->force_alloc_skb))) {
3989 skb = dev_alloc_skb(skb_len + headroom);
3993 skb_reserve(skb, headroom);
3996 data_ptr = element->addr + offset;
3998 data_len = min(skb_len, (int)(element->length - offset));
4001 if (qeth_create_skb_frag(element, &skb, offset,
4005 memcpy(skb_put(skb, data_len), data_ptr,
4009 skb_len -= data_len;
4011 if (qeth_is_last_sbale(element)) {
4012 QETH_DBF_TEXT(TRACE, 4, "unexeob");
4013 QETH_DBF_TEXT_(TRACE, 4, "%s",
4015 QETH_DBF_TEXT(QERR, 2, "unexeob");
4016 QETH_DBF_TEXT_(QERR, 2, "%s",
4018 QETH_DBF_HEX(MISC, 4, buffer, sizeof(*buffer));
4019 dev_kfree_skb_any(skb);
4020 card->stats.rx_errors++;
4025 data_ptr = element->addr;
4030 *__element = element;
4032 if (use_rx_sg && card->options.performance_stats) {
4033 card->perf_stats.sg_skbs_rx++;
4034 card->perf_stats.sg_frags_rx += skb_shinfo(skb)->nr_frags;
4038 if (net_ratelimit()) {
4039 QETH_DBF_TEXT(TRACE, 2, "noskbmem");
4040 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
4042 card->stats.rx_dropped++;
4045 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb);
4047 static void qeth_unregister_dbf_views(void)
4050 for (x = 0; x < QETH_DBF_INFOS; x++) {
4051 debug_unregister(qeth_dbf[x].id);
4052 qeth_dbf[x].id = NULL;
4056 void qeth_dbf_longtext(enum qeth_dbf_names dbf_nix, int level, char *fmt, ...)
4058 char dbf_txt_buf[32];
4061 if (level > (qeth_dbf[dbf_nix].id)->level)
4063 va_start(args, fmt);
4064 vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
4066 debug_text_event(qeth_dbf[dbf_nix].id, level, dbf_txt_buf);
4068 EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
4070 static int qeth_register_dbf_views(void)
4075 for (x = 0; x < QETH_DBF_INFOS; x++) {
4076 /* register the areas */
4077 qeth_dbf[x].id = debug_register(qeth_dbf[x].name,
4081 if (qeth_dbf[x].id == NULL) {
4082 qeth_unregister_dbf_views();
4086 /* register a view */
4087 ret = debug_register_view(qeth_dbf[x].id, qeth_dbf[x].view);
4089 qeth_unregister_dbf_views();
4093 /* set a passing level */
4094 debug_set_level(qeth_dbf[x].id, qeth_dbf[x].level);
4100 int qeth_core_load_discipline(struct qeth_card *card,
4101 enum qeth_discipline_id discipline)
4104 switch (discipline) {
4105 case QETH_DISCIPLINE_LAYER3:
4106 card->discipline.ccwgdriver = try_then_request_module(
4107 symbol_get(qeth_l3_ccwgroup_driver),
4110 case QETH_DISCIPLINE_LAYER2:
4111 card->discipline.ccwgdriver = try_then_request_module(
4112 symbol_get(qeth_l2_ccwgroup_driver),
4116 if (!card->discipline.ccwgdriver) {
4117 dev_err(&card->gdev->dev, "There is no kernel module to "
4118 "support discipline %d\n", discipline);
4124 void qeth_core_free_discipline(struct qeth_card *card)
4126 if (card->options.layer2)
4127 symbol_put(qeth_l2_ccwgroup_driver);
4129 symbol_put(qeth_l3_ccwgroup_driver);
4130 card->discipline.ccwgdriver = NULL;
4133 static int qeth_core_probe_device(struct ccwgroup_device *gdev)
4135 struct qeth_card *card;
4138 unsigned long flags;
4140 QETH_DBF_TEXT(SETUP, 2, "probedev");
4143 if (!get_device(dev))
4146 QETH_DBF_TEXT_(SETUP, 2, "%s", dev_name(&gdev->dev));
4148 card = qeth_alloc_card();
4150 QETH_DBF_TEXT_(SETUP, 2, "1err%d", -ENOMEM);
4154 card->read.ccwdev = gdev->cdev[0];
4155 card->write.ccwdev = gdev->cdev[1];
4156 card->data.ccwdev = gdev->cdev[2];
4157 dev_set_drvdata(&gdev->dev, card);
4159 gdev->cdev[0]->handler = qeth_irq;
4160 gdev->cdev[1]->handler = qeth_irq;
4161 gdev->cdev[2]->handler = qeth_irq;
4163 rc = qeth_determine_card_type(card);
4165 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
4168 rc = qeth_setup_card(card);
4170 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
4174 if (card->info.type == QETH_CARD_TYPE_OSN) {
4175 rc = qeth_core_create_osn_attributes(dev);
4178 rc = qeth_core_load_discipline(card, QETH_DISCIPLINE_LAYER2);
4180 qeth_core_remove_osn_attributes(dev);
4183 rc = card->discipline.ccwgdriver->probe(card->gdev);
4185 qeth_core_free_discipline(card);
4186 qeth_core_remove_osn_attributes(dev);
4190 rc = qeth_core_create_device_attributes(dev);
4195 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
4196 list_add_tail(&card->list, &qeth_core_card_list.list);
4197 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
4201 qeth_core_free_card(card);
4207 static void qeth_core_remove_device(struct ccwgroup_device *gdev)
4209 unsigned long flags;
4210 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4212 QETH_DBF_TEXT(SETUP, 2, "removedv");
4213 if (card->discipline.ccwgdriver) {
4214 card->discipline.ccwgdriver->remove(gdev);
4215 qeth_core_free_discipline(card);
4218 if (card->info.type == QETH_CARD_TYPE_OSN) {
4219 qeth_core_remove_osn_attributes(&gdev->dev);
4221 qeth_core_remove_device_attributes(&gdev->dev);
4223 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
4224 list_del(&card->list);
4225 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
4226 qeth_core_free_card(card);
4227 dev_set_drvdata(&gdev->dev, NULL);
4228 put_device(&gdev->dev);
4232 static int qeth_core_set_online(struct ccwgroup_device *gdev)
4234 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4238 if (!card->discipline.ccwgdriver) {
4239 if (card->info.type == QETH_CARD_TYPE_IQD)
4240 def_discipline = QETH_DISCIPLINE_LAYER3;
4242 def_discipline = QETH_DISCIPLINE_LAYER2;
4243 rc = qeth_core_load_discipline(card, def_discipline);
4246 rc = card->discipline.ccwgdriver->probe(card->gdev);
4250 rc = card->discipline.ccwgdriver->set_online(gdev);
4255 static int qeth_core_set_offline(struct ccwgroup_device *gdev)
4257 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4258 return card->discipline.ccwgdriver->set_offline(gdev);
4261 static void qeth_core_shutdown(struct ccwgroup_device *gdev)
4263 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4264 if (card->discipline.ccwgdriver &&
4265 card->discipline.ccwgdriver->shutdown)
4266 card->discipline.ccwgdriver->shutdown(gdev);
4269 static struct ccwgroup_driver qeth_core_ccwgroup_driver = {
4270 .owner = THIS_MODULE,
4272 .driver_id = 0xD8C5E3C8,
4273 .probe = qeth_core_probe_device,
4274 .remove = qeth_core_remove_device,
4275 .set_online = qeth_core_set_online,
4276 .set_offline = qeth_core_set_offline,
4277 .shutdown = qeth_core_shutdown,
4281 qeth_core_driver_group_store(struct device_driver *ddrv, const char *buf,
4285 err = qeth_core_driver_group(buf, qeth_core_root_dev,
4286 qeth_core_ccwgroup_driver.driver_id);
4293 static DRIVER_ATTR(group, 0200, NULL, qeth_core_driver_group_store);
4296 const char str[ETH_GSTRING_LEN];
4297 } qeth_ethtool_stats_keys[] = {
4302 {"tx skbs no packing"},
4303 {"tx buffers no packing"},
4304 {"tx skbs packing"},
4305 {"tx buffers packing"},
4308 /* 10 */{"rx sg skbs"},
4310 {"rx sg page allocs"},
4311 {"tx large kbytes"},
4313 {"tx pk state ch n->p"},
4314 {"tx pk state ch p->n"},
4315 {"tx pk watermark low"},
4316 {"tx pk watermark high"},
4317 {"queue 0 buffer usage"},
4318 /* 20 */{"queue 1 buffer usage"},
4319 {"queue 2 buffer usage"},
4320 {"queue 3 buffer usage"},
4321 {"rx handler time"},
4322 {"rx handler count"},
4323 {"rx do_QDIO time"},
4324 {"rx do_QDIO count"},
4325 {"tx handler time"},
4326 {"tx handler count"},
4328 /* 30 */{"tx count"},
4329 {"tx do_QDIO time"},
4330 {"tx do_QDIO count"},
4333 int qeth_core_get_stats_count(struct net_device *dev)
4335 return (sizeof(qeth_ethtool_stats_keys) / ETH_GSTRING_LEN);
4337 EXPORT_SYMBOL_GPL(qeth_core_get_stats_count);
4339 void qeth_core_get_ethtool_stats(struct net_device *dev,
4340 struct ethtool_stats *stats, u64 *data)
4342 struct qeth_card *card = dev->ml_priv;
4343 data[0] = card->stats.rx_packets -
4344 card->perf_stats.initial_rx_packets;
4345 data[1] = card->perf_stats.bufs_rec;
4346 data[2] = card->stats.tx_packets -
4347 card->perf_stats.initial_tx_packets;
4348 data[3] = card->perf_stats.bufs_sent;
4349 data[4] = card->stats.tx_packets - card->perf_stats.initial_tx_packets
4350 - card->perf_stats.skbs_sent_pack;
4351 data[5] = card->perf_stats.bufs_sent - card->perf_stats.bufs_sent_pack;
4352 data[6] = card->perf_stats.skbs_sent_pack;
4353 data[7] = card->perf_stats.bufs_sent_pack;
4354 data[8] = card->perf_stats.sg_skbs_sent;
4355 data[9] = card->perf_stats.sg_frags_sent;
4356 data[10] = card->perf_stats.sg_skbs_rx;
4357 data[11] = card->perf_stats.sg_frags_rx;
4358 data[12] = card->perf_stats.sg_alloc_page_rx;
4359 data[13] = (card->perf_stats.large_send_bytes >> 10);
4360 data[14] = card->perf_stats.large_send_cnt;
4361 data[15] = card->perf_stats.sc_dp_p;
4362 data[16] = card->perf_stats.sc_p_dp;
4363 data[17] = QETH_LOW_WATERMARK_PACK;
4364 data[18] = QETH_HIGH_WATERMARK_PACK;
4365 data[19] = atomic_read(&card->qdio.out_qs[0]->used_buffers);
4366 data[20] = (card->qdio.no_out_queues > 1) ?
4367 atomic_read(&card->qdio.out_qs[1]->used_buffers) : 0;
4368 data[21] = (card->qdio.no_out_queues > 2) ?
4369 atomic_read(&card->qdio.out_qs[2]->used_buffers) : 0;
4370 data[22] = (card->qdio.no_out_queues > 3) ?
4371 atomic_read(&card->qdio.out_qs[3]->used_buffers) : 0;
4372 data[23] = card->perf_stats.inbound_time;
4373 data[24] = card->perf_stats.inbound_cnt;
4374 data[25] = card->perf_stats.inbound_do_qdio_time;
4375 data[26] = card->perf_stats.inbound_do_qdio_cnt;
4376 data[27] = card->perf_stats.outbound_handler_time;
4377 data[28] = card->perf_stats.outbound_handler_cnt;
4378 data[29] = card->perf_stats.outbound_time;
4379 data[30] = card->perf_stats.outbound_cnt;
4380 data[31] = card->perf_stats.outbound_do_qdio_time;
4381 data[32] = card->perf_stats.outbound_do_qdio_cnt;
4383 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats);
4385 void qeth_core_get_strings(struct net_device *dev, u32 stringset, u8 *data)
4387 switch (stringset) {
4389 memcpy(data, &qeth_ethtool_stats_keys,
4390 sizeof(qeth_ethtool_stats_keys));
4397 EXPORT_SYMBOL_GPL(qeth_core_get_strings);
4399 void qeth_core_get_drvinfo(struct net_device *dev,
4400 struct ethtool_drvinfo *info)
4402 struct qeth_card *card = dev->ml_priv;
4403 if (card->options.layer2)
4404 strcpy(info->driver, "qeth_l2");
4406 strcpy(info->driver, "qeth_l3");
4408 strcpy(info->version, "1.0");
4409 strcpy(info->fw_version, card->info.mcl_level);
4410 sprintf(info->bus_info, "%s/%s/%s",
4413 CARD_DDEV_ID(card));
4415 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo);
4417 int qeth_core_ethtool_get_settings(struct net_device *netdev,
4418 struct ethtool_cmd *ecmd)
4420 struct qeth_card *card = netdev->ml_priv;
4421 enum qeth_link_types link_type;
4423 if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan))
4424 link_type = QETH_LINK_TYPE_10GBIT_ETH;
4426 link_type = card->info.link_type;
4428 ecmd->transceiver = XCVR_INTERNAL;
4429 ecmd->supported = SUPPORTED_Autoneg;
4430 ecmd->advertising = ADVERTISED_Autoneg;
4431 ecmd->duplex = DUPLEX_FULL;
4432 ecmd->autoneg = AUTONEG_ENABLE;
4434 switch (link_type) {
4435 case QETH_LINK_TYPE_FAST_ETH:
4436 case QETH_LINK_TYPE_LANE_ETH100:
4437 ecmd->supported |= SUPPORTED_10baseT_Half |
4438 SUPPORTED_10baseT_Full |
4439 SUPPORTED_100baseT_Half |
4440 SUPPORTED_100baseT_Full |
4442 ecmd->advertising |= ADVERTISED_10baseT_Half |
4443 ADVERTISED_10baseT_Full |
4444 ADVERTISED_100baseT_Half |
4445 ADVERTISED_100baseT_Full |
4447 ecmd->speed = SPEED_100;
4448 ecmd->port = PORT_TP;
4451 case QETH_LINK_TYPE_GBIT_ETH:
4452 case QETH_LINK_TYPE_LANE_ETH1000:
4453 ecmd->supported |= SUPPORTED_10baseT_Half |
4454 SUPPORTED_10baseT_Full |
4455 SUPPORTED_100baseT_Half |
4456 SUPPORTED_100baseT_Full |
4457 SUPPORTED_1000baseT_Half |
4458 SUPPORTED_1000baseT_Full |
4460 ecmd->advertising |= ADVERTISED_10baseT_Half |
4461 ADVERTISED_10baseT_Full |
4462 ADVERTISED_100baseT_Half |
4463 ADVERTISED_100baseT_Full |
4464 ADVERTISED_1000baseT_Half |
4465 ADVERTISED_1000baseT_Full |
4467 ecmd->speed = SPEED_1000;
4468 ecmd->port = PORT_FIBRE;
4471 case QETH_LINK_TYPE_10GBIT_ETH:
4472 ecmd->supported |= SUPPORTED_10baseT_Half |
4473 SUPPORTED_10baseT_Full |
4474 SUPPORTED_100baseT_Half |
4475 SUPPORTED_100baseT_Full |
4476 SUPPORTED_1000baseT_Half |
4477 SUPPORTED_1000baseT_Full |
4478 SUPPORTED_10000baseT_Full |
4480 ecmd->advertising |= ADVERTISED_10baseT_Half |
4481 ADVERTISED_10baseT_Full |
4482 ADVERTISED_100baseT_Half |
4483 ADVERTISED_100baseT_Full |
4484 ADVERTISED_1000baseT_Half |
4485 ADVERTISED_1000baseT_Full |
4486 ADVERTISED_10000baseT_Full |
4488 ecmd->speed = SPEED_10000;
4489 ecmd->port = PORT_FIBRE;
4493 ecmd->supported |= SUPPORTED_10baseT_Half |
4494 SUPPORTED_10baseT_Full |
4496 ecmd->advertising |= ADVERTISED_10baseT_Half |
4497 ADVERTISED_10baseT_Full |
4499 ecmd->speed = SPEED_10;
4500 ecmd->port = PORT_TP;
4505 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings);
4507 static int __init qeth_core_init(void)
4511 pr_info("loading core functions\n");
4512 INIT_LIST_HEAD(&qeth_core_card_list.list);
4513 rwlock_init(&qeth_core_card_list.rwlock);
4515 rc = qeth_register_dbf_views();
4518 rc = ccw_driver_register(&qeth_ccw_driver);
4521 rc = ccwgroup_driver_register(&qeth_core_ccwgroup_driver);
4524 rc = driver_create_file(&qeth_core_ccwgroup_driver.driver,
4525 &driver_attr_group);
4528 qeth_core_root_dev = s390_root_dev_register("qeth");
4529 rc = IS_ERR(qeth_core_root_dev) ? PTR_ERR(qeth_core_root_dev) : 0;
4533 qeth_core_header_cache = kmem_cache_create("qeth_hdr",
4534 sizeof(struct qeth_hdr) + ETH_HLEN, 64, 0, NULL);
4535 if (!qeth_core_header_cache) {
4542 s390_root_dev_unregister(qeth_core_root_dev);
4544 driver_remove_file(&qeth_core_ccwgroup_driver.driver,
4545 &driver_attr_group);
4547 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
4549 ccw_driver_unregister(&qeth_ccw_driver);
4551 QETH_DBF_MESSAGE(2, "Initialization failed with code %d\n", rc);
4552 qeth_unregister_dbf_views();
4554 pr_err("Initializing the qeth device driver failed\n");
4558 static void __exit qeth_core_exit(void)
4560 s390_root_dev_unregister(qeth_core_root_dev);
4561 driver_remove_file(&qeth_core_ccwgroup_driver.driver,
4562 &driver_attr_group);
4563 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
4564 ccw_driver_unregister(&qeth_ccw_driver);
4565 kmem_cache_destroy(qeth_core_header_cache);
4566 qeth_unregister_dbf_views();
4567 pr_info("core functions removed\n");
4570 module_init(qeth_core_init);
4571 module_exit(qeth_core_exit);
4572 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
4573 MODULE_DESCRIPTION("qeth core functions");
4574 MODULE_LICENSE("GPL");