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 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/string.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
17 #include <linux/ipv6.h>
18 #include <linux/tcp.h>
19 #include <linux/mii.h>
20 #include <linux/kthread.h>
22 #include <asm-s390/ebcdic.h>
23 #include <asm-s390/io.h>
24 #include <asm/s390_rdev.h>
26 #include "qeth_core.h"
27 #include "qeth_core_offl.h"
29 struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
30 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
32 [QETH_DBF_SETUP] = {"qeth_setup",
33 8, 1, 8, 5, &debug_hex_ascii_view, NULL},
34 [QETH_DBF_QERR] = {"qeth_qerr",
35 2, 1, 8, 2, &debug_hex_ascii_view, NULL},
36 [QETH_DBF_TRACE] = {"qeth_trace",
37 4, 1, 8, 3, &debug_hex_ascii_view, NULL},
38 [QETH_DBF_MSG] = {"qeth_msg",
39 8, 1, 128, 3, &debug_sprintf_view, NULL},
40 [QETH_DBF_SENSE] = {"qeth_sense",
41 2, 1, 64, 2, &debug_hex_ascii_view, NULL},
42 [QETH_DBF_MISC] = {"qeth_misc",
43 2, 1, 256, 2, &debug_hex_ascii_view, NULL},
44 [QETH_DBF_CTRL] = {"qeth_control",
45 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
47 EXPORT_SYMBOL_GPL(qeth_dbf);
49 struct qeth_card_list_struct qeth_core_card_list;
50 EXPORT_SYMBOL_GPL(qeth_core_card_list);
52 static struct device *qeth_core_root_dev;
53 static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
54 static struct lock_class_key qdio_out_skb_queue_key;
56 static void qeth_send_control_data_cb(struct qeth_channel *,
57 struct qeth_cmd_buffer *);
58 static int qeth_issue_next_read(struct qeth_card *);
59 static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *);
60 static void qeth_setup_ccw(struct qeth_channel *, unsigned char *, __u32);
61 static void qeth_free_buffer_pool(struct qeth_card *);
62 static int qeth_qdio_establish(struct qeth_card *);
65 static inline void __qeth_fill_buffer_frag(struct sk_buff *skb,
66 struct qdio_buffer *buffer, int is_tso,
67 int *next_element_to_fill)
69 struct skb_frag_struct *frag;
72 int element, cnt, dlen;
74 fragno = skb_shinfo(skb)->nr_frags;
75 element = *next_element_to_fill;
79 buffer->element[element].flags =
80 SBAL_FLAGS_MIDDLE_FRAG;
82 buffer->element[element].flags =
83 SBAL_FLAGS_FIRST_FRAG;
84 dlen = skb->len - skb->data_len;
86 buffer->element[element].addr = skb->data;
87 buffer->element[element].length = dlen;
90 for (cnt = 0; cnt < fragno; cnt++) {
91 frag = &skb_shinfo(skb)->frags[cnt];
92 addr = (page_to_pfn(frag->page) << PAGE_SHIFT) +
94 buffer->element[element].addr = (char *)addr;
95 buffer->element[element].length = frag->size;
96 if (cnt < (fragno - 1))
97 buffer->element[element].flags =
98 SBAL_FLAGS_MIDDLE_FRAG;
100 buffer->element[element].flags =
101 SBAL_FLAGS_LAST_FRAG;
104 *next_element_to_fill = element;
107 static inline const char *qeth_get_cardname(struct qeth_card *card)
109 if (card->info.guestlan) {
110 switch (card->info.type) {
111 case QETH_CARD_TYPE_OSAE:
112 return " Guest LAN QDIO";
113 case QETH_CARD_TYPE_IQD:
114 return " Guest LAN Hiper";
119 switch (card->info.type) {
120 case QETH_CARD_TYPE_OSAE:
121 return " OSD Express";
122 case QETH_CARD_TYPE_IQD:
123 return " HiperSockets";
124 case QETH_CARD_TYPE_OSN:
133 /* max length to be returned: 14 */
134 const char *qeth_get_cardname_short(struct qeth_card *card)
136 if (card->info.guestlan) {
137 switch (card->info.type) {
138 case QETH_CARD_TYPE_OSAE:
139 return "GuestLAN QDIO";
140 case QETH_CARD_TYPE_IQD:
141 return "GuestLAN Hiper";
146 switch (card->info.type) {
147 case QETH_CARD_TYPE_OSAE:
148 switch (card->info.link_type) {
149 case QETH_LINK_TYPE_FAST_ETH:
151 case QETH_LINK_TYPE_HSTR:
153 case QETH_LINK_TYPE_GBIT_ETH:
155 case QETH_LINK_TYPE_10GBIT_ETH:
157 case QETH_LINK_TYPE_LANE_ETH100:
158 return "OSD_FE_LANE";
159 case QETH_LINK_TYPE_LANE_TR:
160 return "OSD_TR_LANE";
161 case QETH_LINK_TYPE_LANE_ETH1000:
162 return "OSD_GbE_LANE";
163 case QETH_LINK_TYPE_LANE:
164 return "OSD_ATM_LANE";
166 return "OSD_Express";
168 case QETH_CARD_TYPE_IQD:
169 return "HiperSockets";
170 case QETH_CARD_TYPE_OSN:
179 void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
180 int clear_start_mask)
184 spin_lock_irqsave(&card->thread_mask_lock, flags);
185 card->thread_allowed_mask = threads;
186 if (clear_start_mask)
187 card->thread_start_mask &= threads;
188 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
189 wake_up(&card->wait_q);
191 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads);
193 int qeth_threads_running(struct qeth_card *card, unsigned long threads)
198 spin_lock_irqsave(&card->thread_mask_lock, flags);
199 rc = (card->thread_running_mask & threads);
200 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
203 EXPORT_SYMBOL_GPL(qeth_threads_running);
205 int qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
207 return wait_event_interruptible(card->wait_q,
208 qeth_threads_running(card, threads) == 0);
210 EXPORT_SYMBOL_GPL(qeth_wait_for_threads);
212 void qeth_clear_working_pool_list(struct qeth_card *card)
214 struct qeth_buffer_pool_entry *pool_entry, *tmp;
216 QETH_DBF_TEXT(TRACE, 5, "clwrklst");
217 list_for_each_entry_safe(pool_entry, tmp,
218 &card->qdio.in_buf_pool.entry_list, list){
219 list_del(&pool_entry->list);
222 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list);
224 static int qeth_alloc_buffer_pool(struct qeth_card *card)
226 struct qeth_buffer_pool_entry *pool_entry;
230 QETH_DBF_TEXT(TRACE, 5, "alocpool");
231 for (i = 0; i < card->qdio.init_pool.buf_count; ++i) {
232 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
234 qeth_free_buffer_pool(card);
237 for (j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j) {
238 ptr = (void *) __get_free_page(GFP_KERNEL);
241 free_page((unsigned long)
242 pool_entry->elements[--j]);
244 qeth_free_buffer_pool(card);
247 pool_entry->elements[j] = ptr;
249 list_add(&pool_entry->init_list,
250 &card->qdio.init_pool.entry_list);
255 int qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
257 QETH_DBF_TEXT(TRACE, 2, "realcbp");
259 if ((card->state != CARD_STATE_DOWN) &&
260 (card->state != CARD_STATE_RECOVER))
263 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
264 qeth_clear_working_pool_list(card);
265 qeth_free_buffer_pool(card);
266 card->qdio.in_buf_pool.buf_count = bufcnt;
267 card->qdio.init_pool.buf_count = bufcnt;
268 return qeth_alloc_buffer_pool(card);
271 int qeth_set_large_send(struct qeth_card *card,
272 enum qeth_large_send_types type)
276 if (card->dev == NULL) {
277 card->options.large_send = type;
280 if (card->state == CARD_STATE_UP)
281 netif_tx_disable(card->dev);
282 card->options.large_send = type;
283 switch (card->options.large_send) {
284 case QETH_LARGE_SEND_EDDP:
285 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
288 case QETH_LARGE_SEND_TSO:
289 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
290 card->dev->features |= NETIF_F_TSO | NETIF_F_SG |
293 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
295 card->options.large_send = QETH_LARGE_SEND_NO;
299 default: /* includes QETH_LARGE_SEND_NO */
300 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG |
304 if (card->state == CARD_STATE_UP)
305 netif_wake_queue(card->dev);
308 EXPORT_SYMBOL_GPL(qeth_set_large_send);
310 static int qeth_issue_next_read(struct qeth_card *card)
313 struct qeth_cmd_buffer *iob;
315 QETH_DBF_TEXT(TRACE, 5, "issnxrd");
316 if (card->read.state != CH_STATE_UP)
318 iob = qeth_get_buffer(&card->read);
320 PRINT_WARN("issue_next_read failed: no iob available!\n");
323 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
324 QETH_DBF_TEXT(TRACE, 6, "noirqpnd");
325 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
328 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
329 atomic_set(&card->read.irq_pending, 0);
330 qeth_schedule_recovery(card);
331 wake_up(&card->wait_q);
336 static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card)
338 struct qeth_reply *reply;
340 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
342 atomic_set(&reply->refcnt, 1);
343 atomic_set(&reply->received, 0);
349 static void qeth_get_reply(struct qeth_reply *reply)
351 WARN_ON(atomic_read(&reply->refcnt) <= 0);
352 atomic_inc(&reply->refcnt);
355 static void qeth_put_reply(struct qeth_reply *reply)
357 WARN_ON(atomic_read(&reply->refcnt) <= 0);
358 if (atomic_dec_and_test(&reply->refcnt))
362 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
363 struct qeth_card *card)
366 int com = cmd->hdr.command;
367 ipa_name = qeth_get_ipa_cmd_name(com);
369 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s returned x%X \"%s\"\n",
370 ipa_name, com, QETH_CARD_IFNAME(card),
371 rc, qeth_get_ipa_msg(rc));
373 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s succeeded\n",
374 ipa_name, com, QETH_CARD_IFNAME(card));
377 static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
378 struct qeth_cmd_buffer *iob)
380 struct qeth_ipa_cmd *cmd = NULL;
382 QETH_DBF_TEXT(TRACE, 5, "chkipad");
383 if (IS_IPA(iob->data)) {
384 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
385 if (IS_IPA_REPLY(cmd)) {
386 if (cmd->hdr.command < IPA_CMD_SETCCID ||
387 cmd->hdr.command > IPA_CMD_MODCCID)
388 qeth_issue_ipa_msg(cmd,
389 cmd->hdr.return_code, card);
392 switch (cmd->hdr.command) {
393 case IPA_CMD_STOPLAN:
394 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
395 "there is a network problem or "
396 "someone pulled the cable or "
397 "disabled the port.\n",
398 QETH_CARD_IFNAME(card),
400 card->lan_online = 0;
401 if (card->dev && netif_carrier_ok(card->dev))
402 netif_carrier_off(card->dev);
404 case IPA_CMD_STARTLAN:
405 PRINT_INFO("Link reestablished on %s "
406 "(CHPID 0x%X). Scheduling "
407 "IP address reset.\n",
408 QETH_CARD_IFNAME(card),
410 netif_carrier_on(card->dev);
411 card->lan_online = 1;
412 qeth_schedule_recovery(card);
414 case IPA_CMD_MODCCID:
416 case IPA_CMD_REGISTER_LOCAL_ADDR:
417 QETH_DBF_TEXT(TRACE, 3, "irla");
419 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
420 QETH_DBF_TEXT(TRACE, 3, "urla");
423 QETH_DBF_MESSAGE(2, "Received data is IPA "
424 "but not a reply!\n");
432 void qeth_clear_ipacmd_list(struct qeth_card *card)
434 struct qeth_reply *reply, *r;
437 QETH_DBF_TEXT(TRACE, 4, "clipalst");
439 spin_lock_irqsave(&card->lock, flags);
440 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
441 qeth_get_reply(reply);
443 atomic_inc(&reply->received);
444 list_del_init(&reply->list);
445 wake_up(&reply->wait_q);
446 qeth_put_reply(reply);
448 spin_unlock_irqrestore(&card->lock, flags);
450 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list);
452 static int qeth_check_idx_response(unsigned char *buffer)
457 QETH_DBF_HEX(CTRL, 2, buffer, QETH_DBF_CTRL_LEN);
458 if ((buffer[2] & 0xc0) == 0xc0) {
459 PRINT_WARN("received an IDX TERMINATE "
460 "with cause code 0x%02x%s\n",
462 ((buffer[4] == 0x22) ?
463 " -- try another portname" : ""));
464 QETH_DBF_TEXT(TRACE, 2, "ckidxres");
465 QETH_DBF_TEXT(TRACE, 2, " idxterm");
466 QETH_DBF_TEXT_(TRACE, 2, " rc%d", -EIO);
472 static void qeth_setup_ccw(struct qeth_channel *channel, unsigned char *iob,
475 struct qeth_card *card;
477 QETH_DBF_TEXT(TRACE, 4, "setupccw");
478 card = CARD_FROM_CDEV(channel->ccwdev);
479 if (channel == &card->read)
480 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
482 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
483 channel->ccw.count = len;
484 channel->ccw.cda = (__u32) __pa(iob);
487 static struct qeth_cmd_buffer *__qeth_get_buffer(struct qeth_channel *channel)
491 QETH_DBF_TEXT(TRACE, 6, "getbuff");
492 index = channel->io_buf_no;
494 if (channel->iob[index].state == BUF_STATE_FREE) {
495 channel->iob[index].state = BUF_STATE_LOCKED;
496 channel->io_buf_no = (channel->io_buf_no + 1) %
498 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
499 return channel->iob + index;
501 index = (index + 1) % QETH_CMD_BUFFER_NO;
502 } while (index != channel->io_buf_no);
507 void qeth_release_buffer(struct qeth_channel *channel,
508 struct qeth_cmd_buffer *iob)
512 QETH_DBF_TEXT(TRACE, 6, "relbuff");
513 spin_lock_irqsave(&channel->iob_lock, flags);
514 memset(iob->data, 0, QETH_BUFSIZE);
515 iob->state = BUF_STATE_FREE;
516 iob->callback = qeth_send_control_data_cb;
518 spin_unlock_irqrestore(&channel->iob_lock, flags);
520 EXPORT_SYMBOL_GPL(qeth_release_buffer);
522 static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *channel)
524 struct qeth_cmd_buffer *buffer = NULL;
527 spin_lock_irqsave(&channel->iob_lock, flags);
528 buffer = __qeth_get_buffer(channel);
529 spin_unlock_irqrestore(&channel->iob_lock, flags);
533 struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *channel)
535 struct qeth_cmd_buffer *buffer;
536 wait_event(channel->wait_q,
537 ((buffer = qeth_get_buffer(channel)) != NULL));
540 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer);
542 void qeth_clear_cmd_buffers(struct qeth_channel *channel)
546 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
547 qeth_release_buffer(channel, &channel->iob[cnt]);
549 channel->io_buf_no = 0;
551 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers);
553 static void qeth_send_control_data_cb(struct qeth_channel *channel,
554 struct qeth_cmd_buffer *iob)
556 struct qeth_card *card;
557 struct qeth_reply *reply, *r;
558 struct qeth_ipa_cmd *cmd;
562 QETH_DBF_TEXT(TRACE, 4, "sndctlcb");
564 card = CARD_FROM_CDEV(channel->ccwdev);
565 if (qeth_check_idx_response(iob->data)) {
566 qeth_clear_ipacmd_list(card);
567 qeth_schedule_recovery(card);
571 cmd = qeth_check_ipa_data(card, iob);
572 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
574 /*in case of OSN : check if cmd is set */
575 if (card->info.type == QETH_CARD_TYPE_OSN &&
577 cmd->hdr.command != IPA_CMD_STARTLAN &&
578 card->osn_info.assist_cb != NULL) {
579 card->osn_info.assist_cb(card->dev, cmd);
583 spin_lock_irqsave(&card->lock, flags);
584 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
585 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
586 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
587 qeth_get_reply(reply);
588 list_del_init(&reply->list);
589 spin_unlock_irqrestore(&card->lock, flags);
591 if (reply->callback != NULL) {
593 reply->offset = (__u16)((char *)cmd -
595 keep_reply = reply->callback(card,
599 keep_reply = reply->callback(card,
604 reply->rc = (u16) cmd->hdr.return_code;
608 spin_lock_irqsave(&card->lock, flags);
609 list_add_tail(&reply->list,
610 &card->cmd_waiter_list);
611 spin_unlock_irqrestore(&card->lock, flags);
613 atomic_inc(&reply->received);
614 wake_up(&reply->wait_q);
616 qeth_put_reply(reply);
620 spin_unlock_irqrestore(&card->lock, flags);
622 memcpy(&card->seqno.pdu_hdr_ack,
623 QETH_PDU_HEADER_SEQ_NO(iob->data),
625 qeth_release_buffer(channel, iob);
628 static int qeth_setup_channel(struct qeth_channel *channel)
632 QETH_DBF_TEXT(SETUP, 2, "setupch");
633 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
634 channel->iob[cnt].data = (char *)
635 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
636 if (channel->iob[cnt].data == NULL)
638 channel->iob[cnt].state = BUF_STATE_FREE;
639 channel->iob[cnt].channel = channel;
640 channel->iob[cnt].callback = qeth_send_control_data_cb;
641 channel->iob[cnt].rc = 0;
643 if (cnt < QETH_CMD_BUFFER_NO) {
645 kfree(channel->iob[cnt].data);
649 channel->io_buf_no = 0;
650 atomic_set(&channel->irq_pending, 0);
651 spin_lock_init(&channel->iob_lock);
653 init_waitqueue_head(&channel->wait_q);
657 static int qeth_set_thread_start_bit(struct qeth_card *card,
658 unsigned long thread)
662 spin_lock_irqsave(&card->thread_mask_lock, flags);
663 if (!(card->thread_allowed_mask & thread) ||
664 (card->thread_start_mask & thread)) {
665 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
668 card->thread_start_mask |= thread;
669 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
673 void qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
677 spin_lock_irqsave(&card->thread_mask_lock, flags);
678 card->thread_start_mask &= ~thread;
679 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
680 wake_up(&card->wait_q);
682 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit);
684 void qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
688 spin_lock_irqsave(&card->thread_mask_lock, flags);
689 card->thread_running_mask &= ~thread;
690 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
691 wake_up(&card->wait_q);
693 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit);
695 static int __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
700 spin_lock_irqsave(&card->thread_mask_lock, flags);
701 if (card->thread_start_mask & thread) {
702 if ((card->thread_allowed_mask & thread) &&
703 !(card->thread_running_mask & thread)) {
705 card->thread_start_mask &= ~thread;
706 card->thread_running_mask |= thread;
710 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
714 int qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
718 wait_event(card->wait_q,
719 (rc = __qeth_do_run_thread(card, thread)) >= 0);
722 EXPORT_SYMBOL_GPL(qeth_do_run_thread);
724 void qeth_schedule_recovery(struct qeth_card *card)
726 QETH_DBF_TEXT(TRACE, 2, "startrec");
727 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
728 schedule_work(&card->kernel_thread_starter);
730 EXPORT_SYMBOL_GPL(qeth_schedule_recovery);
732 static int qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
737 sense = (char *) irb->ecw;
738 cstat = irb->scsw.cmd.cstat;
739 dstat = irb->scsw.cmd.dstat;
741 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
742 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
743 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
744 QETH_DBF_TEXT(TRACE, 2, "CGENCHK");
745 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
746 cdev->dev.bus_id, dstat, cstat);
747 print_hex_dump(KERN_WARNING, "qeth: irb ", DUMP_PREFIX_OFFSET,
752 if (dstat & DEV_STAT_UNIT_CHECK) {
753 if (sense[SENSE_RESETTING_EVENT_BYTE] &
754 SENSE_RESETTING_EVENT_FLAG) {
755 QETH_DBF_TEXT(TRACE, 2, "REVIND");
758 if (sense[SENSE_COMMAND_REJECT_BYTE] &
759 SENSE_COMMAND_REJECT_FLAG) {
760 QETH_DBF_TEXT(TRACE, 2, "CMDREJi");
763 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
764 QETH_DBF_TEXT(TRACE, 2, "AFFE");
767 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
768 QETH_DBF_TEXT(TRACE, 2, "ZEROSEN");
771 QETH_DBF_TEXT(TRACE, 2, "DGENCHK");
777 static long __qeth_check_irb_error(struct ccw_device *cdev,
778 unsigned long intparm, struct irb *irb)
783 switch (PTR_ERR(irb)) {
785 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
786 QETH_DBF_TEXT(TRACE, 2, "ckirberr");
787 QETH_DBF_TEXT_(TRACE, 2, " rc%d", -EIO);
790 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
791 QETH_DBF_TEXT(TRACE, 2, "ckirberr");
792 QETH_DBF_TEXT_(TRACE, 2, " rc%d", -ETIMEDOUT);
793 if (intparm == QETH_RCD_PARM) {
794 struct qeth_card *card = CARD_FROM_CDEV(cdev);
796 if (card && (card->data.ccwdev == cdev)) {
797 card->data.state = CH_STATE_DOWN;
798 wake_up(&card->wait_q);
803 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
805 QETH_DBF_TEXT(TRACE, 2, "ckirberr");
806 QETH_DBF_TEXT(TRACE, 2, " rc???");
811 static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
816 struct qeth_cmd_buffer *buffer;
817 struct qeth_channel *channel;
818 struct qeth_card *card;
819 struct qeth_cmd_buffer *iob;
822 QETH_DBF_TEXT(TRACE, 5, "irq");
824 if (__qeth_check_irb_error(cdev, intparm, irb))
826 cstat = irb->scsw.cmd.cstat;
827 dstat = irb->scsw.cmd.dstat;
829 card = CARD_FROM_CDEV(cdev);
833 if (card->read.ccwdev == cdev) {
834 channel = &card->read;
835 QETH_DBF_TEXT(TRACE, 5, "read");
836 } else if (card->write.ccwdev == cdev) {
837 channel = &card->write;
838 QETH_DBF_TEXT(TRACE, 5, "write");
840 channel = &card->data;
841 QETH_DBF_TEXT(TRACE, 5, "data");
843 atomic_set(&channel->irq_pending, 0);
845 if (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC))
846 channel->state = CH_STATE_STOPPED;
848 if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC))
849 channel->state = CH_STATE_HALTED;
851 /*let's wake up immediately on data channel*/
852 if ((channel == &card->data) && (intparm != 0) &&
853 (intparm != QETH_RCD_PARM))
856 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
857 QETH_DBF_TEXT(TRACE, 6, "clrchpar");
858 /* we don't have to handle this further */
861 if (intparm == QETH_HALT_CHANNEL_PARM) {
862 QETH_DBF_TEXT(TRACE, 6, "hltchpar");
863 /* we don't have to handle this further */
866 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
867 (dstat & DEV_STAT_UNIT_CHECK) ||
869 if (irb->esw.esw0.erw.cons) {
870 /* TODO: we should make this s390dbf */
871 PRINT_WARN("sense data available on channel %s.\n",
872 CHANNEL_ID(channel));
873 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
874 print_hex_dump(KERN_WARNING, "qeth: irb ",
875 DUMP_PREFIX_OFFSET, 16, 1, irb, 32, 1);
876 print_hex_dump(KERN_WARNING, "qeth: sense data ",
877 DUMP_PREFIX_OFFSET, 16, 1, irb->ecw, 32, 1);
879 if (intparm == QETH_RCD_PARM) {
880 channel->state = CH_STATE_DOWN;
883 rc = qeth_get_problem(cdev, irb);
885 qeth_schedule_recovery(card);
890 if (intparm == QETH_RCD_PARM) {
891 channel->state = CH_STATE_RCD_DONE;
895 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
896 buffer->state = BUF_STATE_PROCESSED;
898 if (channel == &card->data)
900 if (channel == &card->read &&
901 channel->state == CH_STATE_UP)
902 qeth_issue_next_read(card);
905 index = channel->buf_no;
906 while (iob[index].state == BUF_STATE_PROCESSED) {
907 if (iob[index].callback != NULL)
908 iob[index].callback(channel, iob + index);
910 index = (index + 1) % QETH_CMD_BUFFER_NO;
912 channel->buf_no = index;
914 wake_up(&card->wait_q);
918 static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
919 struct qeth_qdio_out_buffer *buf)
924 /* is PCI flag set on buffer? */
925 if (buf->buffer->element[0].flags & 0x40)
926 atomic_dec(&queue->set_pci_flags_count);
928 skb = skb_dequeue(&buf->skb_list);
930 atomic_dec(&skb->users);
931 dev_kfree_skb_any(skb);
932 skb = skb_dequeue(&buf->skb_list);
934 qeth_eddp_buf_release_contexts(buf);
935 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i) {
936 buf->buffer->element[i].length = 0;
937 buf->buffer->element[i].addr = NULL;
938 buf->buffer->element[i].flags = 0;
940 buf->next_element_to_fill = 0;
941 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
944 void qeth_clear_qdio_buffers(struct qeth_card *card)
948 QETH_DBF_TEXT(TRACE, 2, "clearqdbf");
949 /* clear outbound buffers to free skbs */
950 for (i = 0; i < card->qdio.no_out_queues; ++i)
951 if (card->qdio.out_qs[i]) {
952 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
953 qeth_clear_output_buffer(card->qdio.out_qs[i],
954 &card->qdio.out_qs[i]->bufs[j]);
957 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers);
959 static void qeth_free_buffer_pool(struct qeth_card *card)
961 struct qeth_buffer_pool_entry *pool_entry, *tmp;
963 QETH_DBF_TEXT(TRACE, 5, "freepool");
964 list_for_each_entry_safe(pool_entry, tmp,
965 &card->qdio.init_pool.entry_list, init_list){
966 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
967 free_page((unsigned long)pool_entry->elements[i]);
968 list_del(&pool_entry->init_list);
973 static void qeth_free_qdio_buffers(struct qeth_card *card)
977 QETH_DBF_TEXT(TRACE, 2, "freeqdbf");
978 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
979 QETH_QDIO_UNINITIALIZED)
981 kfree(card->qdio.in_q);
982 card->qdio.in_q = NULL;
983 /* inbound buffer pool */
984 qeth_free_buffer_pool(card);
985 /* free outbound qdio_qs */
986 if (card->qdio.out_qs) {
987 for (i = 0; i < card->qdio.no_out_queues; ++i) {
988 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
989 qeth_clear_output_buffer(card->qdio.out_qs[i],
990 &card->qdio.out_qs[i]->bufs[j]);
991 kfree(card->qdio.out_qs[i]);
993 kfree(card->qdio.out_qs);
994 card->qdio.out_qs = NULL;
998 static void qeth_clean_channel(struct qeth_channel *channel)
1002 QETH_DBF_TEXT(SETUP, 2, "freech");
1003 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1004 kfree(channel->iob[cnt].data);
1007 static int qeth_is_1920_device(struct qeth_card *card)
1009 int single_queue = 0;
1010 struct ccw_device *ccwdev;
1011 struct channelPath_dsc {
1022 QETH_DBF_TEXT(SETUP, 2, "chk_1920");
1024 ccwdev = card->data.ccwdev;
1025 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1026 if (chp_dsc != NULL) {
1027 /* CHPP field bit 6 == 1 -> single queue */
1028 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1031 QETH_DBF_TEXT_(SETUP, 2, "rc:%x", single_queue);
1032 return single_queue;
1035 static void qeth_init_qdio_info(struct qeth_card *card)
1037 QETH_DBF_TEXT(SETUP, 4, "intqdinf");
1038 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
1040 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1041 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
1042 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
1043 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
1044 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
1047 static void qeth_set_intial_options(struct qeth_card *card)
1049 card->options.route4.type = NO_ROUTER;
1050 card->options.route6.type = NO_ROUTER;
1051 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1052 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1053 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1054 card->options.fake_broadcast = 0;
1055 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1056 card->options.fake_ll = 0;
1057 card->options.performance_stats = 0;
1058 card->options.rx_sg_cb = QETH_RX_SG_CB;
1061 static int qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1063 unsigned long flags;
1066 spin_lock_irqsave(&card->thread_mask_lock, flags);
1067 QETH_DBF_TEXT_(TRACE, 4, " %02x%02x%02x",
1068 (u8) card->thread_start_mask,
1069 (u8) card->thread_allowed_mask,
1070 (u8) card->thread_running_mask);
1071 rc = (card->thread_start_mask & thread);
1072 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1076 static void qeth_start_kernel_thread(struct work_struct *work)
1078 struct qeth_card *card = container_of(work, struct qeth_card,
1079 kernel_thread_starter);
1080 QETH_DBF_TEXT(TRACE , 2, "strthrd");
1082 if (card->read.state != CH_STATE_UP &&
1083 card->write.state != CH_STATE_UP)
1085 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1086 kthread_run(card->discipline.recover, (void *) card,
1090 static int qeth_setup_card(struct qeth_card *card)
1093 QETH_DBF_TEXT(SETUP, 2, "setupcrd");
1094 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1096 card->read.state = CH_STATE_DOWN;
1097 card->write.state = CH_STATE_DOWN;
1098 card->data.state = CH_STATE_DOWN;
1099 card->state = CARD_STATE_DOWN;
1100 card->lan_online = 0;
1101 card->use_hard_stop = 0;
1103 spin_lock_init(&card->vlanlock);
1104 spin_lock_init(&card->mclock);
1105 card->vlangrp = NULL;
1106 spin_lock_init(&card->lock);
1107 spin_lock_init(&card->ip_lock);
1108 spin_lock_init(&card->thread_mask_lock);
1109 card->thread_start_mask = 0;
1110 card->thread_allowed_mask = 0;
1111 card->thread_running_mask = 0;
1112 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1113 INIT_LIST_HEAD(&card->ip_list);
1114 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1115 if (!card->ip_tbd_list) {
1116 QETH_DBF_TEXT(SETUP, 0, "iptbdnom");
1119 INIT_LIST_HEAD(card->ip_tbd_list);
1120 INIT_LIST_HEAD(&card->cmd_waiter_list);
1121 init_waitqueue_head(&card->wait_q);
1122 /* intial options */
1123 qeth_set_intial_options(card);
1124 /* IP address takeover */
1125 INIT_LIST_HEAD(&card->ipato.entries);
1126 card->ipato.enabled = 0;
1127 card->ipato.invert4 = 0;
1128 card->ipato.invert6 = 0;
1129 /* init QDIO stuff */
1130 qeth_init_qdio_info(card);
1134 static struct qeth_card *qeth_alloc_card(void)
1136 struct qeth_card *card;
1138 QETH_DBF_TEXT(SETUP, 2, "alloccrd");
1139 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
1142 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1143 if (qeth_setup_channel(&card->read)) {
1147 if (qeth_setup_channel(&card->write)) {
1148 qeth_clean_channel(&card->read);
1152 card->options.layer2 = -1;
1156 static int qeth_determine_card_type(struct qeth_card *card)
1160 QETH_DBF_TEXT(SETUP, 2, "detcdtyp");
1162 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1163 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1164 while (known_devices[i][4]) {
1165 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1166 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1167 card->info.type = known_devices[i][4];
1168 card->qdio.no_out_queues = known_devices[i][8];
1169 card->info.is_multicast_different = known_devices[i][9];
1170 if (qeth_is_1920_device(card)) {
1171 PRINT_INFO("Priority Queueing not able "
1172 "due to hardware limitations!\n");
1173 card->qdio.no_out_queues = 1;
1174 card->qdio.default_out_queue = 0;
1180 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1181 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1185 static int qeth_clear_channel(struct qeth_channel *channel)
1187 unsigned long flags;
1188 struct qeth_card *card;
1191 QETH_DBF_TEXT(TRACE, 3, "clearch");
1192 card = CARD_FROM_CDEV(channel->ccwdev);
1193 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1194 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
1195 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1199 rc = wait_event_interruptible_timeout(card->wait_q,
1200 channel->state == CH_STATE_STOPPED, QETH_TIMEOUT);
1201 if (rc == -ERESTARTSYS)
1203 if (channel->state != CH_STATE_STOPPED)
1205 channel->state = CH_STATE_DOWN;
1209 static int qeth_halt_channel(struct qeth_channel *channel)
1211 unsigned long flags;
1212 struct qeth_card *card;
1215 QETH_DBF_TEXT(TRACE, 3, "haltch");
1216 card = CARD_FROM_CDEV(channel->ccwdev);
1217 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1218 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
1219 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1223 rc = wait_event_interruptible_timeout(card->wait_q,
1224 channel->state == CH_STATE_HALTED, QETH_TIMEOUT);
1225 if (rc == -ERESTARTSYS)
1227 if (channel->state != CH_STATE_HALTED)
1232 static int qeth_halt_channels(struct qeth_card *card)
1234 int rc1 = 0, rc2 = 0, rc3 = 0;
1236 QETH_DBF_TEXT(TRACE, 3, "haltchs");
1237 rc1 = qeth_halt_channel(&card->read);
1238 rc2 = qeth_halt_channel(&card->write);
1239 rc3 = qeth_halt_channel(&card->data);
1247 static int qeth_clear_channels(struct qeth_card *card)
1249 int rc1 = 0, rc2 = 0, rc3 = 0;
1251 QETH_DBF_TEXT(TRACE, 3, "clearchs");
1252 rc1 = qeth_clear_channel(&card->read);
1253 rc2 = qeth_clear_channel(&card->write);
1254 rc3 = qeth_clear_channel(&card->data);
1262 static int qeth_clear_halt_card(struct qeth_card *card, int halt)
1266 QETH_DBF_TEXT(TRACE, 3, "clhacrd");
1267 QETH_DBF_HEX(TRACE, 3, &card, sizeof(void *));
1270 rc = qeth_halt_channels(card);
1273 return qeth_clear_channels(card);
1276 int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
1280 QETH_DBF_TEXT(TRACE, 3, "qdioclr");
1281 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
1282 QETH_QDIO_CLEANING)) {
1283 case QETH_QDIO_ESTABLISHED:
1284 if (card->info.type == QETH_CARD_TYPE_IQD)
1285 rc = qdio_cleanup(CARD_DDEV(card),
1286 QDIO_FLAG_CLEANUP_USING_HALT);
1288 rc = qdio_cleanup(CARD_DDEV(card),
1289 QDIO_FLAG_CLEANUP_USING_CLEAR);
1291 QETH_DBF_TEXT_(TRACE, 3, "1err%d", rc);
1292 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
1294 case QETH_QDIO_CLEANING:
1299 rc = qeth_clear_halt_card(card, use_halt);
1301 QETH_DBF_TEXT_(TRACE, 3, "2err%d", rc);
1302 card->state = CARD_STATE_DOWN;
1305 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card);
1307 static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
1313 struct qeth_channel *channel = &card->data;
1314 unsigned long flags;
1317 * scan for RCD command in extended SenseID data
1319 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
1320 if (!ciw || ciw->cmd == 0)
1322 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
1326 channel->ccw.cmd_code = ciw->cmd;
1327 channel->ccw.cda = (__u32) __pa(rcd_buf);
1328 channel->ccw.count = ciw->count;
1329 channel->ccw.flags = CCW_FLAG_SLI;
1330 channel->state = CH_STATE_RCD;
1331 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1332 ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1333 QETH_RCD_PARM, LPM_ANYPATH, 0,
1335 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1337 wait_event(card->wait_q,
1338 (channel->state == CH_STATE_RCD_DONE ||
1339 channel->state == CH_STATE_DOWN));
1340 if (channel->state == CH_STATE_DOWN)
1343 channel->state = CH_STATE_DOWN;
1349 *length = ciw->count;
1355 static int qeth_get_unitaddr(struct qeth_card *card)
1361 QETH_DBF_TEXT(SETUP, 2, "getunit");
1362 rc = qeth_read_conf_data(card, (void **) &prcd, &length);
1364 PRINT_ERR("qeth_read_conf_data for device %s returned %i\n",
1365 CARD_DDEV_ID(card), rc);
1368 card->info.chpid = prcd[30];
1369 card->info.unit_addr2 = prcd[31];
1370 card->info.cula = prcd[63];
1371 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1372 (prcd[0x11] == _ascebc['M']));
1377 static void qeth_init_tokens(struct qeth_card *card)
1379 card->token.issuer_rm_w = 0x00010103UL;
1380 card->token.cm_filter_w = 0x00010108UL;
1381 card->token.cm_connection_w = 0x0001010aUL;
1382 card->token.ulp_filter_w = 0x0001010bUL;
1383 card->token.ulp_connection_w = 0x0001010dUL;
1386 static void qeth_init_func_level(struct qeth_card *card)
1388 if (card->ipato.enabled) {
1389 if (card->info.type == QETH_CARD_TYPE_IQD)
1390 card->info.func_level =
1391 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
1393 card->info.func_level =
1394 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
1396 if (card->info.type == QETH_CARD_TYPE_IQD)
1397 /*FIXME:why do we have same values for dis and ena for
1399 card->info.func_level =
1400 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
1402 card->info.func_level =
1403 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
1407 static int qeth_idx_activate_get_answer(struct qeth_channel *channel,
1408 void (*idx_reply_cb)(struct qeth_channel *,
1409 struct qeth_cmd_buffer *))
1411 struct qeth_cmd_buffer *iob;
1412 unsigned long flags;
1414 struct qeth_card *card;
1416 QETH_DBF_TEXT(SETUP, 2, "idxanswr");
1417 card = CARD_FROM_CDEV(channel->ccwdev);
1418 iob = qeth_get_buffer(channel);
1419 iob->callback = idx_reply_cb;
1420 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1421 channel->ccw.count = QETH_BUFSIZE;
1422 channel->ccw.cda = (__u32) __pa(iob->data);
1424 wait_event(card->wait_q,
1425 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1426 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1427 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1428 rc = ccw_device_start(channel->ccwdev,
1429 &channel->ccw, (addr_t) iob, 0, 0);
1430 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1433 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc);
1434 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
1435 atomic_set(&channel->irq_pending, 0);
1436 wake_up(&card->wait_q);
1439 rc = wait_event_interruptible_timeout(card->wait_q,
1440 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1441 if (rc == -ERESTARTSYS)
1443 if (channel->state != CH_STATE_UP) {
1445 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
1446 qeth_clear_cmd_buffers(channel);
1452 static int qeth_idx_activate_channel(struct qeth_channel *channel,
1453 void (*idx_reply_cb)(struct qeth_channel *,
1454 struct qeth_cmd_buffer *))
1456 struct qeth_card *card;
1457 struct qeth_cmd_buffer *iob;
1458 unsigned long flags;
1462 struct ccw_dev_id temp_devid;
1464 card = CARD_FROM_CDEV(channel->ccwdev);
1466 QETH_DBF_TEXT(SETUP, 2, "idxactch");
1468 iob = qeth_get_buffer(channel);
1469 iob->callback = idx_reply_cb;
1470 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1471 channel->ccw.count = IDX_ACTIVATE_SIZE;
1472 channel->ccw.cda = (__u32) __pa(iob->data);
1473 if (channel == &card->write) {
1474 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1475 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1476 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1477 card->seqno.trans_hdr++;
1479 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1480 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1481 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1483 tmp = ((__u8)card->info.portno) | 0x80;
1484 memcpy(QETH_IDX_ACT_PNO(iob->data), &tmp, 1);
1485 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1486 &card->token.issuer_rm_w, QETH_MPC_TOKEN_LENGTH);
1487 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1488 &card->info.func_level, sizeof(__u16));
1489 ccw_device_get_id(CARD_DDEV(card), &temp_devid);
1490 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp_devid.devno, 2);
1491 temp = (card->info.cula << 8) + card->info.unit_addr2;
1492 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1494 wait_event(card->wait_q,
1495 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1496 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1497 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1498 rc = ccw_device_start(channel->ccwdev,
1499 &channel->ccw, (addr_t) iob, 0, 0);
1500 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1503 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1505 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1506 atomic_set(&channel->irq_pending, 0);
1507 wake_up(&card->wait_q);
1510 rc = wait_event_interruptible_timeout(card->wait_q,
1511 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1512 if (rc == -ERESTARTSYS)
1514 if (channel->state != CH_STATE_ACTIVATING) {
1515 PRINT_WARN("IDX activate timed out!\n");
1516 QETH_DBF_TEXT_(SETUP, 2, "2err%d", -ETIME);
1517 qeth_clear_cmd_buffers(channel);
1520 return qeth_idx_activate_get_answer(channel, idx_reply_cb);
1523 static int qeth_peer_func_level(int level)
1525 if ((level & 0xff) == 8)
1526 return (level & 0xff) + 0x400;
1527 if (((level >> 8) & 3) == 1)
1528 return (level & 0xff) + 0x200;
1532 static void qeth_idx_write_cb(struct qeth_channel *channel,
1533 struct qeth_cmd_buffer *iob)
1535 struct qeth_card *card;
1538 QETH_DBF_TEXT(SETUP , 2, "idxwrcb");
1540 if (channel->state == CH_STATE_DOWN) {
1541 channel->state = CH_STATE_ACTIVATING;
1544 card = CARD_FROM_CDEV(channel->ccwdev);
1546 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1547 if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == 0x19)
1548 PRINT_ERR("IDX_ACTIVATE on write channel device %s: "
1549 "adapter exclusively used by another host\n",
1550 CARD_WDEV_ID(card));
1552 PRINT_ERR("IDX_ACTIVATE on write channel device %s: "
1553 "negative reply\n", CARD_WDEV_ID(card));
1556 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1557 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1558 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1559 "function level mismatch "
1560 "(sent: 0x%x, received: 0x%x)\n",
1561 CARD_WDEV_ID(card), card->info.func_level, temp);
1564 channel->state = CH_STATE_UP;
1566 qeth_release_buffer(channel, iob);
1569 static void qeth_idx_read_cb(struct qeth_channel *channel,
1570 struct qeth_cmd_buffer *iob)
1572 struct qeth_card *card;
1575 QETH_DBF_TEXT(SETUP , 2, "idxrdcb");
1576 if (channel->state == CH_STATE_DOWN) {
1577 channel->state = CH_STATE_ACTIVATING;
1581 card = CARD_FROM_CDEV(channel->ccwdev);
1582 if (qeth_check_idx_response(iob->data))
1585 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1586 if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == 0x19)
1587 PRINT_ERR("IDX_ACTIVATE on read channel device %s: "
1588 "adapter exclusively used by another host\n",
1589 CARD_RDEV_ID(card));
1591 PRINT_ERR("IDX_ACTIVATE on read channel device %s: "
1592 "negative reply\n", CARD_RDEV_ID(card));
1597 * temporary fix for microcode bug
1598 * to revert it,replace OR by AND
1600 if ((!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1601 (card->info.type == QETH_CARD_TYPE_OSAE))
1602 card->info.portname_required = 1;
1604 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1605 if (temp != qeth_peer_func_level(card->info.func_level)) {
1606 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1607 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1608 CARD_RDEV_ID(card), card->info.func_level, temp);
1611 memcpy(&card->token.issuer_rm_r,
1612 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1613 QETH_MPC_TOKEN_LENGTH);
1614 memcpy(&card->info.mcl_level[0],
1615 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1616 channel->state = CH_STATE_UP;
1618 qeth_release_buffer(channel, iob);
1621 void qeth_prepare_control_data(struct qeth_card *card, int len,
1622 struct qeth_cmd_buffer *iob)
1624 qeth_setup_ccw(&card->write, iob->data, len);
1625 iob->callback = qeth_release_buffer;
1627 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1628 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1629 card->seqno.trans_hdr++;
1630 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1631 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1632 card->seqno.pdu_hdr++;
1633 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1634 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1635 QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
1637 EXPORT_SYMBOL_GPL(qeth_prepare_control_data);
1639 int qeth_send_control_data(struct qeth_card *card, int len,
1640 struct qeth_cmd_buffer *iob,
1641 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1646 unsigned long flags;
1647 struct qeth_reply *reply = NULL;
1648 unsigned long timeout;
1650 QETH_DBF_TEXT(TRACE, 2, "sendctl");
1652 reply = qeth_alloc_reply(card);
1656 reply->callback = reply_cb;
1657 reply->param = reply_param;
1658 if (card->state == CARD_STATE_DOWN)
1659 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1661 reply->seqno = card->seqno.ipa++;
1662 init_waitqueue_head(&reply->wait_q);
1663 spin_lock_irqsave(&card->lock, flags);
1664 list_add_tail(&reply->list, &card->cmd_waiter_list);
1665 spin_unlock_irqrestore(&card->lock, flags);
1666 QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
1668 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
1669 qeth_prepare_control_data(card, len, iob);
1671 if (IS_IPA(iob->data))
1672 timeout = jiffies + QETH_IPA_TIMEOUT;
1674 timeout = jiffies + QETH_TIMEOUT;
1676 QETH_DBF_TEXT(TRACE, 6, "noirqpnd");
1677 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1678 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1679 (addr_t) iob, 0, 0);
1680 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1682 PRINT_WARN("qeth_send_control_data: "
1683 "ccw_device_start rc = %i\n", rc);
1684 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
1685 spin_lock_irqsave(&card->lock, flags);
1686 list_del_init(&reply->list);
1687 qeth_put_reply(reply);
1688 spin_unlock_irqrestore(&card->lock, flags);
1689 qeth_release_buffer(iob->channel, iob);
1690 atomic_set(&card->write.irq_pending, 0);
1691 wake_up(&card->wait_q);
1694 while (!atomic_read(&reply->received)) {
1695 if (time_after(jiffies, timeout)) {
1696 spin_lock_irqsave(&reply->card->lock, flags);
1697 list_del_init(&reply->list);
1698 spin_unlock_irqrestore(&reply->card->lock, flags);
1700 atomic_inc(&reply->received);
1701 wake_up(&reply->wait_q);
1706 qeth_put_reply(reply);
1709 EXPORT_SYMBOL_GPL(qeth_send_control_data);
1711 static int qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1714 struct qeth_cmd_buffer *iob;
1716 QETH_DBF_TEXT(SETUP, 2, "cmenblcb");
1718 iob = (struct qeth_cmd_buffer *) data;
1719 memcpy(&card->token.cm_filter_r,
1720 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
1721 QETH_MPC_TOKEN_LENGTH);
1722 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1726 static int qeth_cm_enable(struct qeth_card *card)
1729 struct qeth_cmd_buffer *iob;
1731 QETH_DBF_TEXT(SETUP, 2, "cmenable");
1733 iob = qeth_wait_for_buffer(&card->write);
1734 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
1735 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
1736 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1737 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
1738 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
1740 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
1741 qeth_cm_enable_cb, NULL);
1745 static int qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
1749 struct qeth_cmd_buffer *iob;
1751 QETH_DBF_TEXT(SETUP, 2, "cmsetpcb");
1753 iob = (struct qeth_cmd_buffer *) data;
1754 memcpy(&card->token.cm_connection_r,
1755 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
1756 QETH_MPC_TOKEN_LENGTH);
1757 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1761 static int qeth_cm_setup(struct qeth_card *card)
1764 struct qeth_cmd_buffer *iob;
1766 QETH_DBF_TEXT(SETUP, 2, "cmsetup");
1768 iob = qeth_wait_for_buffer(&card->write);
1769 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
1770 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
1771 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
1772 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
1773 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
1774 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
1775 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
1776 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
1777 qeth_cm_setup_cb, NULL);
1782 static inline int qeth_get_initial_mtu_for_card(struct qeth_card *card)
1784 switch (card->info.type) {
1785 case QETH_CARD_TYPE_UNKNOWN:
1787 case QETH_CARD_TYPE_IQD:
1788 return card->info.max_mtu;
1789 case QETH_CARD_TYPE_OSAE:
1790 switch (card->info.link_type) {
1791 case QETH_LINK_TYPE_HSTR:
1792 case QETH_LINK_TYPE_LANE_TR:
1802 static inline int qeth_get_max_mtu_for_card(int cardtype)
1806 case QETH_CARD_TYPE_UNKNOWN:
1807 case QETH_CARD_TYPE_OSAE:
1808 case QETH_CARD_TYPE_OSN:
1810 case QETH_CARD_TYPE_IQD:
1817 static inline int qeth_get_mtu_out_of_mpc(int cardtype)
1820 case QETH_CARD_TYPE_IQD:
1827 static inline int qeth_get_mtu_outof_framesize(int framesize)
1829 switch (framesize) {
1843 static inline int qeth_mtu_is_valid(struct qeth_card *card, int mtu)
1845 switch (card->info.type) {
1846 case QETH_CARD_TYPE_OSAE:
1847 return ((mtu >= 576) && (mtu <= 61440));
1848 case QETH_CARD_TYPE_IQD:
1849 return ((mtu >= 576) &&
1850 (mtu <= card->info.max_mtu + 4096 - 32));
1851 case QETH_CARD_TYPE_OSN:
1852 case QETH_CARD_TYPE_UNKNOWN:
1858 static int qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1862 __u16 mtu, framesize;
1865 struct qeth_cmd_buffer *iob;
1867 QETH_DBF_TEXT(SETUP, 2, "ulpenacb");
1869 iob = (struct qeth_cmd_buffer *) data;
1870 memcpy(&card->token.ulp_filter_r,
1871 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
1872 QETH_MPC_TOKEN_LENGTH);
1873 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
1874 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
1875 mtu = qeth_get_mtu_outof_framesize(framesize);
1878 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1881 card->info.max_mtu = mtu;
1882 card->info.initial_mtu = mtu;
1883 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
1885 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
1886 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
1887 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1890 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
1891 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
1893 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
1894 card->info.link_type = link_type;
1896 card->info.link_type = 0;
1897 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1901 static int qeth_ulp_enable(struct qeth_card *card)
1905 struct qeth_cmd_buffer *iob;
1907 /*FIXME: trace view callbacks*/
1908 QETH_DBF_TEXT(SETUP, 2, "ulpenabl");
1910 iob = qeth_wait_for_buffer(&card->write);
1911 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
1913 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
1914 (__u8) card->info.portno;
1915 if (card->options.layer2)
1916 if (card->info.type == QETH_CARD_TYPE_OSN)
1917 prot_type = QETH_PROT_OSN2;
1919 prot_type = QETH_PROT_LAYER2;
1921 prot_type = QETH_PROT_TCPIP;
1923 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data), &prot_type, 1);
1924 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
1925 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
1926 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
1927 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
1928 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
1929 card->info.portname, 9);
1930 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
1931 qeth_ulp_enable_cb, NULL);
1936 static int qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
1939 struct qeth_cmd_buffer *iob;
1941 QETH_DBF_TEXT(SETUP, 2, "ulpstpcb");
1943 iob = (struct qeth_cmd_buffer *) data;
1944 memcpy(&card->token.ulp_connection_r,
1945 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
1946 QETH_MPC_TOKEN_LENGTH);
1947 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
1951 static int qeth_ulp_setup(struct qeth_card *card)
1955 struct qeth_cmd_buffer *iob;
1956 struct ccw_dev_id dev_id;
1958 QETH_DBF_TEXT(SETUP, 2, "ulpsetup");
1960 iob = qeth_wait_for_buffer(&card->write);
1961 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
1963 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
1964 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
1965 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
1966 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
1967 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
1968 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
1970 ccw_device_get_id(CARD_DDEV(card), &dev_id);
1971 memcpy(QETH_ULP_SETUP_CUA(iob->data), &dev_id.devno, 2);
1972 temp = (card->info.cula << 8) + card->info.unit_addr2;
1973 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
1974 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
1975 qeth_ulp_setup_cb, NULL);
1979 static int qeth_alloc_qdio_buffers(struct qeth_card *card)
1983 QETH_DBF_TEXT(SETUP, 2, "allcqdbf");
1985 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
1986 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
1989 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
1991 if (!card->qdio.in_q)
1993 QETH_DBF_TEXT(SETUP, 2, "inq");
1994 QETH_DBF_HEX(SETUP, 2, &card->qdio.in_q, sizeof(void *));
1995 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
1996 /* give inbound qeth_qdio_buffers their qdio_buffers */
1997 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
1998 card->qdio.in_q->bufs[i].buffer =
1999 &card->qdio.in_q->qdio_bufs[i];
2000 /* inbound buffer pool */
2001 if (qeth_alloc_buffer_pool(card))
2005 kmalloc(card->qdio.no_out_queues *
2006 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
2007 if (!card->qdio.out_qs)
2009 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2010 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
2012 if (!card->qdio.out_qs[i])
2014 QETH_DBF_TEXT_(SETUP, 2, "outq %i", i);
2015 QETH_DBF_HEX(SETUP, 2, &card->qdio.out_qs[i], sizeof(void *));
2016 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
2017 card->qdio.out_qs[i]->queue_no = i;
2018 /* give outbound qeth_qdio_buffers their qdio_buffers */
2019 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2020 card->qdio.out_qs[i]->bufs[j].buffer =
2021 &card->qdio.out_qs[i]->qdio_bufs[j];
2022 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
2025 &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
2026 &qdio_out_skb_queue_key);
2027 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
2034 kfree(card->qdio.out_qs[--i]);
2035 kfree(card->qdio.out_qs);
2036 card->qdio.out_qs = NULL;
2038 qeth_free_buffer_pool(card);
2040 kfree(card->qdio.in_q);
2041 card->qdio.in_q = NULL;
2043 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
2047 static void qeth_create_qib_param_field(struct qeth_card *card,
2051 param_field[0] = _ascebc['P'];
2052 param_field[1] = _ascebc['C'];
2053 param_field[2] = _ascebc['I'];
2054 param_field[3] = _ascebc['T'];
2055 *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card);
2056 *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card);
2057 *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card);
2060 static void qeth_create_qib_param_field_blkt(struct qeth_card *card,
2063 param_field[16] = _ascebc['B'];
2064 param_field[17] = _ascebc['L'];
2065 param_field[18] = _ascebc['K'];
2066 param_field[19] = _ascebc['T'];
2067 *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total;
2068 *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet;
2069 *((unsigned int *) (¶m_field[28])) =
2070 card->info.blkt.inter_packet_jumbo;
2073 static int qeth_qdio_activate(struct qeth_card *card)
2075 QETH_DBF_TEXT(SETUP, 3, "qdioact");
2076 return qdio_activate(CARD_DDEV(card), 0);
2079 static int qeth_dm_act(struct qeth_card *card)
2082 struct qeth_cmd_buffer *iob;
2084 QETH_DBF_TEXT(SETUP, 2, "dmact");
2086 iob = qeth_wait_for_buffer(&card->write);
2087 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
2089 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
2090 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2091 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
2092 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2093 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
2097 static int qeth_mpc_initialize(struct qeth_card *card)
2101 QETH_DBF_TEXT(SETUP, 2, "mpcinit");
2103 rc = qeth_issue_next_read(card);
2105 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2108 rc = qeth_cm_enable(card);
2110 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
2113 rc = qeth_cm_setup(card);
2115 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
2118 rc = qeth_ulp_enable(card);
2120 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
2123 rc = qeth_ulp_setup(card);
2125 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
2128 rc = qeth_alloc_qdio_buffers(card);
2130 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
2133 rc = qeth_qdio_establish(card);
2135 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
2136 qeth_free_qdio_buffers(card);
2139 rc = qeth_qdio_activate(card);
2141 QETH_DBF_TEXT_(SETUP, 2, "7err%d", rc);
2144 rc = qeth_dm_act(card);
2146 QETH_DBF_TEXT_(SETUP, 2, "8err%d", rc);
2152 qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
2156 static void qeth_print_status_with_portname(struct qeth_card *card)
2161 sprintf(dbf_text, "%s", card->info.portname + 1);
2162 for (i = 0; i < 8; i++)
2164 (char) _ebcasc[(__u8) dbf_text[i]];
2166 PRINT_INFO("Device %s/%s/%s is a%s card%s%s%s\n"
2167 "with link type %s (portname: %s)\n",
2171 qeth_get_cardname(card),
2172 (card->info.mcl_level[0]) ? " (level: " : "",
2173 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2174 (card->info.mcl_level[0]) ? ")" : "",
2175 qeth_get_cardname_short(card),
2180 static void qeth_print_status_no_portname(struct qeth_card *card)
2182 if (card->info.portname[0])
2183 PRINT_INFO("Device %s/%s/%s is a%s "
2184 "card%s%s%s\nwith link type %s "
2185 "(no portname needed by interface).\n",
2189 qeth_get_cardname(card),
2190 (card->info.mcl_level[0]) ? " (level: " : "",
2191 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2192 (card->info.mcl_level[0]) ? ")" : "",
2193 qeth_get_cardname_short(card));
2195 PRINT_INFO("Device %s/%s/%s is a%s "
2196 "card%s%s%s\nwith link type %s.\n",
2200 qeth_get_cardname(card),
2201 (card->info.mcl_level[0]) ? " (level: " : "",
2202 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2203 (card->info.mcl_level[0]) ? ")" : "",
2204 qeth_get_cardname_short(card));
2207 void qeth_print_status_message(struct qeth_card *card)
2209 switch (card->info.type) {
2210 case QETH_CARD_TYPE_OSAE:
2211 /* VM will use a non-zero first character
2212 * to indicate a HiperSockets like reporting
2213 * of the level OSA sets the first character to zero
2215 if (!card->info.mcl_level[0]) {
2216 sprintf(card->info.mcl_level, "%02x%02x",
2217 card->info.mcl_level[2],
2218 card->info.mcl_level[3]);
2220 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2224 case QETH_CARD_TYPE_IQD:
2225 if (card->info.guestlan) {
2226 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
2227 card->info.mcl_level[0]];
2228 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
2229 card->info.mcl_level[1]];
2230 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
2231 card->info.mcl_level[2]];
2232 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
2233 card->info.mcl_level[3]];
2234 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2238 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
2240 if (card->info.portname_required)
2241 qeth_print_status_with_portname(card);
2243 qeth_print_status_no_portname(card);
2245 EXPORT_SYMBOL_GPL(qeth_print_status_message);
2247 static void qeth_initialize_working_pool_list(struct qeth_card *card)
2249 struct qeth_buffer_pool_entry *entry;
2251 QETH_DBF_TEXT(TRACE, 5, "inwrklst");
2253 list_for_each_entry(entry,
2254 &card->qdio.init_pool.entry_list, init_list) {
2255 qeth_put_buffer_pool_entry(card, entry);
2259 static inline struct qeth_buffer_pool_entry *qeth_find_free_buffer_pool_entry(
2260 struct qeth_card *card)
2262 struct list_head *plh;
2263 struct qeth_buffer_pool_entry *entry;
2267 if (list_empty(&card->qdio.in_buf_pool.entry_list))
2270 list_for_each(plh, &card->qdio.in_buf_pool.entry_list) {
2271 entry = list_entry(plh, struct qeth_buffer_pool_entry, list);
2273 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2274 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2280 list_del_init(&entry->list);
2285 /* no free buffer in pool so take first one and swap pages */
2286 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2287 struct qeth_buffer_pool_entry, list);
2288 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2289 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2290 page = alloc_page(GFP_ATOMIC);
2294 free_page((unsigned long)entry->elements[i]);
2295 entry->elements[i] = page_address(page);
2296 if (card->options.performance_stats)
2297 card->perf_stats.sg_alloc_page_rx++;
2301 list_del_init(&entry->list);
2305 static int qeth_init_input_buffer(struct qeth_card *card,
2306 struct qeth_qdio_buffer *buf)
2308 struct qeth_buffer_pool_entry *pool_entry;
2311 pool_entry = qeth_find_free_buffer_pool_entry(card);
2316 * since the buffer is accessed only from the input_tasklet
2317 * there shouldn't be a need to synchronize; also, since we use
2318 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2321 BUG_ON(!pool_entry);
2323 buf->pool_entry = pool_entry;
2324 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2325 buf->buffer->element[i].length = PAGE_SIZE;
2326 buf->buffer->element[i].addr = pool_entry->elements[i];
2327 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2328 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2330 buf->buffer->element[i].flags = 0;
2335 int qeth_init_qdio_queues(struct qeth_card *card)
2340 QETH_DBF_TEXT(SETUP, 2, "initqdqs");
2343 memset(card->qdio.in_q->qdio_bufs, 0,
2344 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
2345 qeth_initialize_working_pool_list(card);
2346 /*give only as many buffers to hardware as we have buffer pool entries*/
2347 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
2348 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
2349 card->qdio.in_q->next_buf_to_init =
2350 card->qdio.in_buf_pool.buf_count - 1;
2351 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
2352 card->qdio.in_buf_pool.buf_count - 1, NULL);
2354 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2357 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
2359 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
2362 /* outbound queue */
2363 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2364 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
2365 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
2366 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2367 qeth_clear_output_buffer(card->qdio.out_qs[i],
2368 &card->qdio.out_qs[i]->bufs[j]);
2370 card->qdio.out_qs[i]->card = card;
2371 card->qdio.out_qs[i]->next_buf_to_fill = 0;
2372 card->qdio.out_qs[i]->do_pack = 0;
2373 atomic_set(&card->qdio.out_qs[i]->used_buffers, 0);
2374 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
2375 atomic_set(&card->qdio.out_qs[i]->state,
2376 QETH_OUT_Q_UNLOCKED);
2380 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues);
2382 static inline __u8 qeth_get_ipa_adp_type(enum qeth_link_types link_type)
2384 switch (link_type) {
2385 case QETH_LINK_TYPE_HSTR:
2392 static void qeth_fill_ipacmd_header(struct qeth_card *card,
2393 struct qeth_ipa_cmd *cmd, __u8 command,
2394 enum qeth_prot_versions prot)
2396 memset(cmd, 0, sizeof(struct qeth_ipa_cmd));
2397 cmd->hdr.command = command;
2398 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
2399 cmd->hdr.seqno = card->seqno.ipa;
2400 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
2401 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
2402 if (card->options.layer2)
2403 cmd->hdr.prim_version_no = 2;
2405 cmd->hdr.prim_version_no = 1;
2406 cmd->hdr.param_count = 1;
2407 cmd->hdr.prot_version = prot;
2408 cmd->hdr.ipa_supported = 0;
2409 cmd->hdr.ipa_enabled = 0;
2412 struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *card,
2413 enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
2415 struct qeth_cmd_buffer *iob;
2416 struct qeth_ipa_cmd *cmd;
2418 iob = qeth_wait_for_buffer(&card->write);
2419 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2420 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
2424 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer);
2426 void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2429 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2430 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data), &prot_type, 1);
2431 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2432 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2434 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd);
2436 int qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2437 int (*reply_cb)(struct qeth_card *, struct qeth_reply*,
2444 QETH_DBF_TEXT(TRACE, 4, "sendipa");
2446 if (card->options.layer2)
2447 if (card->info.type == QETH_CARD_TYPE_OSN)
2448 prot_type = QETH_PROT_OSN2;
2450 prot_type = QETH_PROT_LAYER2;
2452 prot_type = QETH_PROT_TCPIP;
2453 qeth_prepare_ipa_cmd(card, iob, prot_type);
2454 rc = qeth_send_control_data(card, IPA_CMD_LENGTH,
2455 iob, reply_cb, reply_param);
2458 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd);
2460 static int qeth_send_startstoplan(struct qeth_card *card,
2461 enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
2464 struct qeth_cmd_buffer *iob;
2466 iob = qeth_get_ipacmd_buffer(card, ipacmd, prot);
2467 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
2472 int qeth_send_startlan(struct qeth_card *card)
2476 QETH_DBF_TEXT(SETUP, 2, "strtlan");
2478 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, 0);
2481 EXPORT_SYMBOL_GPL(qeth_send_startlan);
2483 int qeth_send_stoplan(struct qeth_card *card)
2488 * TODO: according to the IPA format document page 14,
2489 * TCP/IP (we!) never issue a STOPLAN
2492 QETH_DBF_TEXT(SETUP, 2, "stoplan");
2494 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, 0);
2497 EXPORT_SYMBOL_GPL(qeth_send_stoplan);
2499 int qeth_default_setadapterparms_cb(struct qeth_card *card,
2500 struct qeth_reply *reply, unsigned long data)
2502 struct qeth_ipa_cmd *cmd;
2504 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
2506 cmd = (struct qeth_ipa_cmd *) data;
2507 if (cmd->hdr.return_code == 0)
2508 cmd->hdr.return_code =
2509 cmd->data.setadapterparms.hdr.return_code;
2512 EXPORT_SYMBOL_GPL(qeth_default_setadapterparms_cb);
2514 static int qeth_query_setadapterparms_cb(struct qeth_card *card,
2515 struct qeth_reply *reply, unsigned long data)
2517 struct qeth_ipa_cmd *cmd;
2519 QETH_DBF_TEXT(TRACE, 3, "quyadpcb");
2521 cmd = (struct qeth_ipa_cmd *) data;
2522 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
2523 card->info.link_type =
2524 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
2525 card->options.adp.supported_funcs =
2526 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
2527 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
2530 struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
2531 __u32 command, __u32 cmdlen)
2533 struct qeth_cmd_buffer *iob;
2534 struct qeth_ipa_cmd *cmd;
2536 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETADAPTERPARMS,
2538 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2539 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
2540 cmd->data.setadapterparms.hdr.command_code = command;
2541 cmd->data.setadapterparms.hdr.used_total = 1;
2542 cmd->data.setadapterparms.hdr.seq_no = 1;
2546 EXPORT_SYMBOL_GPL(qeth_get_adapter_cmd);
2548 int qeth_query_setadapterparms(struct qeth_card *card)
2551 struct qeth_cmd_buffer *iob;
2553 QETH_DBF_TEXT(TRACE, 3, "queryadp");
2554 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
2555 sizeof(struct qeth_ipacmd_setadpparms));
2556 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
2559 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms);
2561 int qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2562 unsigned int siga_error, const char *dbftext)
2564 if (qdio_error || siga_error) {
2565 QETH_DBF_TEXT(TRACE, 2, dbftext);
2566 QETH_DBF_TEXT(QERR, 2, dbftext);
2567 QETH_DBF_TEXT_(QERR, 2, " F15=%02X",
2568 buf->element[15].flags & 0xff);
2569 QETH_DBF_TEXT_(QERR, 2, " F14=%02X",
2570 buf->element[14].flags & 0xff);
2571 QETH_DBF_TEXT_(QERR, 2, " qerr=%X", qdio_error);
2572 QETH_DBF_TEXT_(QERR, 2, " serr=%X", siga_error);
2577 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors);
2579 void qeth_queue_input_buffer(struct qeth_card *card, int index)
2581 struct qeth_qdio_q *queue = card->qdio.in_q;
2587 count = (index < queue->next_buf_to_init)?
2588 card->qdio.in_buf_pool.buf_count -
2589 (queue->next_buf_to_init - index) :
2590 card->qdio.in_buf_pool.buf_count -
2591 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2592 /* only requeue at a certain threshold to avoid SIGAs */
2593 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)) {
2594 for (i = queue->next_buf_to_init;
2595 i < queue->next_buf_to_init + count; ++i) {
2596 if (qeth_init_input_buffer(card,
2597 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q])) {
2604 if (newcount < count) {
2605 /* we are in memory shortage so we switch back to
2606 traditional skb allocation and drop packages */
2607 atomic_set(&card->force_alloc_skb, 3);
2610 atomic_add_unless(&card->force_alloc_skb, -1, 0);
2614 * according to old code it should be avoided to requeue all
2615 * 128 buffers in order to benefit from PCI avoidance.
2616 * this function keeps at least one buffer (the buffer at
2617 * 'index') un-requeued -> this buffer is the first buffer that
2618 * will be requeued the next time
2620 if (card->options.performance_stats) {
2621 card->perf_stats.inbound_do_qdio_cnt++;
2622 card->perf_stats.inbound_do_qdio_start_time =
2625 rc = do_QDIO(CARD_DDEV(card),
2626 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2627 0, queue->next_buf_to_init, count, NULL);
2628 if (card->options.performance_stats)
2629 card->perf_stats.inbound_do_qdio_time +=
2631 card->perf_stats.inbound_do_qdio_start_time;
2633 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2634 "return %i (device %s).\n",
2635 rc, CARD_DDEV_ID(card));
2636 QETH_DBF_TEXT(TRACE, 2, "qinberr");
2637 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
2639 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2640 QDIO_MAX_BUFFERS_PER_Q;
2643 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer);
2645 static int qeth_handle_send_error(struct qeth_card *card,
2646 struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err,
2647 unsigned int siga_err)
2649 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2650 int cc = siga_err & 3;
2652 QETH_DBF_TEXT(TRACE, 6, "hdsnderr");
2653 qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr");
2657 QETH_DBF_TEXT(TRACE, 1, "lnkfail");
2658 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2659 QETH_DBF_TEXT_(TRACE, 1, "%04x %02x",
2660 (u16)qdio_err, (u8)sbalf15);
2661 return QETH_SEND_ERROR_LINK_FAILURE;
2663 return QETH_SEND_ERROR_NONE;
2665 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2666 QETH_DBF_TEXT(TRACE, 1, "SIGAcc2B");
2667 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2668 return QETH_SEND_ERROR_KICK_IT;
2670 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2671 return QETH_SEND_ERROR_RETRY;
2672 return QETH_SEND_ERROR_LINK_FAILURE;
2673 /* look at qdio_error and sbalf 15 */
2675 QETH_DBF_TEXT(TRACE, 1, "SIGAcc1");
2676 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2677 return QETH_SEND_ERROR_LINK_FAILURE;
2680 QETH_DBF_TEXT(TRACE, 1, "SIGAcc3");
2681 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2682 return QETH_SEND_ERROR_KICK_IT;
2687 * Switched to packing state if the number of used buffers on a queue
2688 * reaches a certain limit.
2690 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2692 if (!queue->do_pack) {
2693 if (atomic_read(&queue->used_buffers)
2694 >= QETH_HIGH_WATERMARK_PACK){
2695 /* switch non-PACKING -> PACKING */
2696 QETH_DBF_TEXT(TRACE, 6, "np->pack");
2697 if (queue->card->options.performance_stats)
2698 queue->card->perf_stats.sc_dp_p++;
2705 * Switches from packing to non-packing mode. If there is a packing
2706 * buffer on the queue this buffer will be prepared to be flushed.
2707 * In that case 1 is returned to inform the caller. If no buffer
2708 * has to be flushed, zero is returned.
2710 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2712 struct qeth_qdio_out_buffer *buffer;
2713 int flush_count = 0;
2715 if (queue->do_pack) {
2716 if (atomic_read(&queue->used_buffers)
2717 <= QETH_LOW_WATERMARK_PACK) {
2718 /* switch PACKING -> non-PACKING */
2719 QETH_DBF_TEXT(TRACE, 6, "pack->np");
2720 if (queue->card->options.performance_stats)
2721 queue->card->perf_stats.sc_p_dp++;
2723 /* flush packing buffers */
2724 buffer = &queue->bufs[queue->next_buf_to_fill];
2725 if ((atomic_read(&buffer->state) ==
2726 QETH_QDIO_BUF_EMPTY) &&
2727 (buffer->next_element_to_fill > 0)) {
2728 atomic_set(&buffer->state,
2729 QETH_QDIO_BUF_PRIMED);
2731 queue->next_buf_to_fill =
2732 (queue->next_buf_to_fill + 1) %
2733 QDIO_MAX_BUFFERS_PER_Q;
2741 * Called to flush a packing buffer if no more pci flags are on the queue.
2742 * Checks if there is a packing buffer and prepares it to be flushed.
2743 * In that case returns 1, otherwise zero.
2745 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2747 struct qeth_qdio_out_buffer *buffer;
2749 buffer = &queue->bufs[queue->next_buf_to_fill];
2750 if ((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2751 (buffer->next_element_to_fill > 0)) {
2752 /* it's a packing buffer */
2753 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2754 queue->next_buf_to_fill =
2755 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2761 static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2762 int index, int count)
2764 struct qeth_qdio_out_buffer *buf;
2767 unsigned int qdio_flags;
2769 for (i = index; i < index + count; ++i) {
2770 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2771 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2772 SBAL_FLAGS_LAST_ENTRY;
2774 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2777 if (!queue->do_pack) {
2778 if ((atomic_read(&queue->used_buffers) >=
2779 (QETH_HIGH_WATERMARK_PACK -
2780 QETH_WATERMARK_PACK_FUZZ)) &&
2781 !atomic_read(&queue->set_pci_flags_count)) {
2782 /* it's likely that we'll go to packing
2784 atomic_inc(&queue->set_pci_flags_count);
2785 buf->buffer->element[0].flags |= 0x40;
2788 if (!atomic_read(&queue->set_pci_flags_count)) {
2790 * there's no outstanding PCI any more, so we
2791 * have to request a PCI to be sure the the PCI
2792 * will wake at some time in the future then we
2793 * can flush packed buffers that might still be
2794 * hanging around, which can happen if no
2795 * further send was requested by the stack
2797 atomic_inc(&queue->set_pci_flags_count);
2798 buf->buffer->element[0].flags |= 0x40;
2803 queue->card->dev->trans_start = jiffies;
2804 if (queue->card->options.performance_stats) {
2805 queue->card->perf_stats.outbound_do_qdio_cnt++;
2806 queue->card->perf_stats.outbound_do_qdio_start_time =
2809 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
2811 qdio_flags |= QDIO_FLAG_UNDER_INTERRUPT;
2812 if (atomic_read(&queue->set_pci_flags_count))
2813 qdio_flags |= QDIO_FLAG_PCI_OUT;
2814 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
2815 queue->queue_no, index, count, NULL);
2816 if (queue->card->options.performance_stats)
2817 queue->card->perf_stats.outbound_do_qdio_time +=
2819 queue->card->perf_stats.outbound_do_qdio_start_time;
2821 QETH_DBF_TEXT(TRACE, 2, "flushbuf");
2822 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
2823 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_DDEV_ID(queue->card));
2824 queue->card->stats.tx_errors += count;
2825 /* this must not happen under normal circumstances. if it
2826 * happens something is really wrong -> recover */
2827 qeth_schedule_recovery(queue->card);
2830 atomic_add(count, &queue->used_buffers);
2831 if (queue->card->options.performance_stats)
2832 queue->card->perf_stats.bufs_sent += count;
2835 static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2839 int q_was_packing = 0;
2842 * check if weed have to switch to non-packing mode or if
2843 * we have to get a pci flag out on the queue
2845 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2846 !atomic_read(&queue->set_pci_flags_count)) {
2847 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2848 QETH_OUT_Q_UNLOCKED) {
2850 * If we get in here, there was no action in
2851 * do_send_packet. So, we check if there is a
2852 * packing buffer to be flushed here.
2854 netif_stop_queue(queue->card->dev);
2855 index = queue->next_buf_to_fill;
2856 q_was_packing = queue->do_pack;
2857 /* queue->do_pack may change */
2859 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
2861 !atomic_read(&queue->set_pci_flags_count))
2863 qeth_flush_buffers_on_no_pci(queue);
2864 if (queue->card->options.performance_stats &&
2866 queue->card->perf_stats.bufs_sent_pack +=
2869 qeth_flush_buffers(queue, 1, index, flush_cnt);
2870 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
2875 void qeth_qdio_output_handler(struct ccw_device *ccwdev, unsigned int status,
2876 unsigned int qdio_error, unsigned int siga_error,
2877 unsigned int __queue, int first_element, int count,
2878 unsigned long card_ptr)
2880 struct qeth_card *card = (struct qeth_card *) card_ptr;
2881 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
2882 struct qeth_qdio_out_buffer *buffer;
2885 QETH_DBF_TEXT(TRACE, 6, "qdouhdl");
2886 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2887 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) {
2888 QETH_DBF_TEXT(TRACE, 2, "achkcond");
2889 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
2890 QETH_DBF_TEXT_(TRACE, 2, "%08x", status);
2891 netif_stop_queue(card->dev);
2892 qeth_schedule_recovery(card);
2896 if (card->options.performance_stats) {
2897 card->perf_stats.outbound_handler_cnt++;
2898 card->perf_stats.outbound_handler_start_time =
2901 for (i = first_element; i < (first_element + count); ++i) {
2902 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2903 /*we only handle the KICK_IT error by doing a recovery */
2904 if (qeth_handle_send_error(card, buffer,
2905 qdio_error, siga_error)
2906 == QETH_SEND_ERROR_KICK_IT){
2907 netif_stop_queue(card->dev);
2908 qeth_schedule_recovery(card);
2911 qeth_clear_output_buffer(queue, buffer);
2913 atomic_sub(count, &queue->used_buffers);
2914 /* check if we need to do something on this outbound queue */
2915 if (card->info.type != QETH_CARD_TYPE_IQD)
2916 qeth_check_outbound_queue(queue);
2918 netif_wake_queue(queue->card->dev);
2919 if (card->options.performance_stats)
2920 card->perf_stats.outbound_handler_time += qeth_get_micros() -
2921 card->perf_stats.outbound_handler_start_time;
2923 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler);
2925 int qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2927 int cast_type = RTN_UNSPEC;
2929 if (card->info.type == QETH_CARD_TYPE_OSN)
2932 if (skb->dst && skb->dst->neighbour) {
2933 cast_type = skb->dst->neighbour->type;
2934 if ((cast_type == RTN_BROADCAST) ||
2935 (cast_type == RTN_MULTICAST) ||
2936 (cast_type == RTN_ANYCAST))
2941 /* try something else */
2942 if (skb->protocol == ETH_P_IPV6)
2943 return (skb_network_header(skb)[24] == 0xff) ?
2945 else if (skb->protocol == ETH_P_IP)
2946 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2949 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2950 return RTN_BROADCAST;
2954 hdr_mac = *((u16 *)skb->data);
2956 switch (card->info.link_type) {
2957 case QETH_LINK_TYPE_HSTR:
2958 case QETH_LINK_TYPE_LANE_TR:
2959 if ((hdr_mac == QETH_TR_MAC_NC) ||
2960 (hdr_mac == QETH_TR_MAC_C))
2961 return RTN_MULTICAST;
2963 /* eth or so multicast? */
2965 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2966 (hdr_mac == QETH_ETH_MAC_V6))
2967 return RTN_MULTICAST;
2972 EXPORT_SYMBOL_GPL(qeth_get_cast_type);
2974 int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
2975 int ipv, int cast_type)
2977 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
2978 return card->qdio.default_out_queue;
2979 switch (card->qdio.no_out_queues) {
2981 if (cast_type && card->info.is_multicast_different)
2982 return card->info.is_multicast_different &
2983 (card->qdio.no_out_queues - 1);
2984 if (card->qdio.do_prio_queueing && (ipv == 4)) {
2985 const u8 tos = ip_hdr(skb)->tos;
2987 if (card->qdio.do_prio_queueing ==
2988 QETH_PRIO_Q_ING_TOS) {
2989 if (tos & IP_TOS_NOTIMPORTANT)
2991 if (tos & IP_TOS_HIGHRELIABILITY)
2993 if (tos & IP_TOS_HIGHTHROUGHPUT)
2995 if (tos & IP_TOS_LOWDELAY)
2998 if (card->qdio.do_prio_queueing ==
2999 QETH_PRIO_Q_ING_PREC)
3000 return 3 - (tos >> 6);
3001 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3004 return card->qdio.default_out_queue;
3005 case 1: /* fallthrough for single-out-queue 1920-device */
3007 return card->qdio.default_out_queue;
3010 EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
3012 int qeth_get_elements_no(struct qeth_card *card, void *hdr,
3013 struct sk_buff *skb, int elems)
3015 int elements_needed = 0;
3017 if (skb_shinfo(skb)->nr_frags > 0)
3018 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
3019 if (elements_needed == 0)
3020 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
3021 + skb->len) >> PAGE_SHIFT);
3022 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
3023 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3024 "(Number=%d / Length=%d). Discarded.\n",
3025 (elements_needed+elems), skb->len);
3028 return elements_needed;
3030 EXPORT_SYMBOL_GPL(qeth_get_elements_no);
3032 static inline void __qeth_fill_buffer(struct sk_buff *skb,
3033 struct qdio_buffer *buffer, int is_tso, int *next_element_to_fill)
3035 int length = skb->len;
3041 element = *next_element_to_fill;
3043 first_lap = (is_tso == 0 ? 1 : 0);
3045 while (length > 0) {
3046 /* length_here is the remaining amount of data in this page */
3047 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
3048 if (length < length_here)
3049 length_here = length;
3051 buffer->element[element].addr = data;
3052 buffer->element[element].length = length_here;
3053 length -= length_here;
3056 buffer->element[element].flags = 0;
3058 buffer->element[element].flags =
3059 SBAL_FLAGS_LAST_FRAG;
3062 buffer->element[element].flags =
3063 SBAL_FLAGS_FIRST_FRAG;
3065 buffer->element[element].flags =
3066 SBAL_FLAGS_MIDDLE_FRAG;
3068 data += length_here;
3072 *next_element_to_fill = element;
3075 static inline int qeth_fill_buffer(struct qeth_qdio_out_q *queue,
3076 struct qeth_qdio_out_buffer *buf, struct sk_buff *skb)
3078 struct qdio_buffer *buffer;
3079 struct qeth_hdr_tso *hdr;
3080 int flush_cnt = 0, hdr_len, large_send = 0;
3082 buffer = buf->buffer;
3083 atomic_inc(&skb->users);
3084 skb_queue_tail(&buf->skb_list, skb);
3086 hdr = (struct qeth_hdr_tso *) skb->data;
3087 /*check first on TSO ....*/
3088 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
3089 int element = buf->next_element_to_fill;
3091 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
3092 /*fill first buffer entry only with header information */
3093 buffer->element[element].addr = skb->data;
3094 buffer->element[element].length = hdr_len;
3095 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
3096 buf->next_element_to_fill++;
3097 skb->data += hdr_len;
3098 skb->len -= hdr_len;
3101 if (skb_shinfo(skb)->nr_frags == 0)
3102 __qeth_fill_buffer(skb, buffer, large_send,
3103 (int *)&buf->next_element_to_fill);
3105 __qeth_fill_buffer_frag(skb, buffer, large_send,
3106 (int *)&buf->next_element_to_fill);
3108 if (!queue->do_pack) {
3109 QETH_DBF_TEXT(TRACE, 6, "fillbfnp");
3110 /* set state to PRIMED -> will be flushed */
3111 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
3114 QETH_DBF_TEXT(TRACE, 6, "fillbfpa");
3115 if (queue->card->options.performance_stats)
3116 queue->card->perf_stats.skbs_sent_pack++;
3117 if (buf->next_element_to_fill >=
3118 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
3120 * packed buffer if full -> set state PRIMED
3121 * -> will be flushed
3123 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
3130 int qeth_do_send_packet_fast(struct qeth_card *card,
3131 struct qeth_qdio_out_q *queue, struct sk_buff *skb,
3132 struct qeth_hdr *hdr, int elements_needed,
3133 struct qeth_eddp_context *ctx)
3135 struct qeth_qdio_out_buffer *buffer;
3136 int buffers_needed = 0;
3140 /* spin until we get the queue ... */
3141 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3142 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
3143 /* ... now we've got the queue */
3144 index = queue->next_buf_to_fill;
3145 buffer = &queue->bufs[queue->next_buf_to_fill];
3147 * check if buffer is empty to make sure that we do not 'overtake'
3148 * ourselves and try to fill a buffer that is already primed
3150 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
3153 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
3154 QDIO_MAX_BUFFERS_PER_Q;
3156 buffers_needed = qeth_eddp_check_buffers_for_context(queue,
3158 if (buffers_needed < 0)
3160 queue->next_buf_to_fill =
3161 (queue->next_buf_to_fill + buffers_needed) %
3162 QDIO_MAX_BUFFERS_PER_Q;
3164 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3166 qeth_fill_buffer(queue, buffer, skb);
3167 qeth_flush_buffers(queue, 0, index, 1);
3169 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
3170 WARN_ON(buffers_needed != flush_cnt);
3171 qeth_flush_buffers(queue, 0, index, flush_cnt);
3175 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3178 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast);
3180 int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
3181 struct sk_buff *skb, struct qeth_hdr *hdr,
3182 int elements_needed, struct qeth_eddp_context *ctx)
3184 struct qeth_qdio_out_buffer *buffer;
3186 int flush_count = 0;
3191 /* spin until we get the queue ... */
3192 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3193 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
3194 start_index = queue->next_buf_to_fill;
3195 buffer = &queue->bufs[queue->next_buf_to_fill];
3197 * check if buffer is empty to make sure that we do not 'overtake'
3198 * ourselves and try to fill a buffer that is already primed
3200 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
3201 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3204 /* check if we need to switch packing state of this queue */
3205 qeth_switch_to_packing_if_needed(queue);
3206 if (queue->do_pack) {
3209 /* does packet fit in current buffer? */
3210 if ((QETH_MAX_BUFFER_ELEMENTS(card) -
3211 buffer->next_element_to_fill) < elements_needed) {
3212 /* ... no -> set state PRIMED */
3213 atomic_set(&buffer->state,
3214 QETH_QDIO_BUF_PRIMED);
3216 queue->next_buf_to_fill =
3217 (queue->next_buf_to_fill + 1) %
3218 QDIO_MAX_BUFFERS_PER_Q;
3219 buffer = &queue->bufs[queue->next_buf_to_fill];
3220 /* we did a step forward, so check buffer state
3222 if (atomic_read(&buffer->state) !=
3223 QETH_QDIO_BUF_EMPTY){
3224 qeth_flush_buffers(queue, 0,
3225 start_index, flush_count);
3226 atomic_set(&queue->state,
3227 QETH_OUT_Q_UNLOCKED);
3232 /* check if we have enough elements (including following
3233 * free buffers) to handle eddp context */
3234 if (qeth_eddp_check_buffers_for_context(queue, ctx)
3242 tmp = qeth_fill_buffer(queue, buffer, skb);
3244 tmp = qeth_eddp_fill_buffer(queue, ctx,
3245 queue->next_buf_to_fill);
3251 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
3252 QDIO_MAX_BUFFERS_PER_Q;
3256 qeth_flush_buffers(queue, 0, start_index, flush_count);
3257 else if (!atomic_read(&queue->set_pci_flags_count))
3258 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
3260 * queue->state will go from LOCKED -> UNLOCKED or from
3261 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
3262 * (switch packing state or flush buffer to get another pci flag out).
3263 * In that case we will enter this loop
3265 while (atomic_dec_return(&queue->state)) {
3267 start_index = queue->next_buf_to_fill;
3268 /* check if we can go back to non-packing state */
3269 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
3271 * check if we need to flush a packing buffer to get a pci
3272 * flag out on the queue
3274 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
3275 flush_count += qeth_flush_buffers_on_no_pci(queue);
3277 qeth_flush_buffers(queue, 0, start_index, flush_count);
3279 /* at this point the queue is UNLOCKED again */
3280 if (queue->card->options.performance_stats && do_pack)
3281 queue->card->perf_stats.bufs_sent_pack += flush_count;
3285 EXPORT_SYMBOL_GPL(qeth_do_send_packet);
3287 static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
3288 struct qeth_reply *reply, unsigned long data)
3290 struct qeth_ipa_cmd *cmd;
3291 struct qeth_ipacmd_setadpparms *setparms;
3293 QETH_DBF_TEXT(TRACE, 4, "prmadpcb");
3295 cmd = (struct qeth_ipa_cmd *) data;
3296 setparms = &(cmd->data.setadapterparms);
3298 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
3299 if (cmd->hdr.return_code) {
3300 QETH_DBF_TEXT_(TRACE, 4, "prmrc%2.2x", cmd->hdr.return_code);
3301 setparms->data.mode = SET_PROMISC_MODE_OFF;
3303 card->info.promisc_mode = setparms->data.mode;
3307 void qeth_setadp_promisc_mode(struct qeth_card *card)
3309 enum qeth_ipa_promisc_modes mode;
3310 struct net_device *dev = card->dev;
3311 struct qeth_cmd_buffer *iob;
3312 struct qeth_ipa_cmd *cmd;
3314 QETH_DBF_TEXT(TRACE, 4, "setprom");
3316 if (((dev->flags & IFF_PROMISC) &&
3317 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
3318 (!(dev->flags & IFF_PROMISC) &&
3319 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
3321 mode = SET_PROMISC_MODE_OFF;
3322 if (dev->flags & IFF_PROMISC)
3323 mode = SET_PROMISC_MODE_ON;
3324 QETH_DBF_TEXT_(TRACE, 4, "mode:%x", mode);
3326 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
3327 sizeof(struct qeth_ipacmd_setadpparms));
3328 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
3329 cmd->data.setadapterparms.data.mode = mode;
3330 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
3332 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode);
3334 int qeth_change_mtu(struct net_device *dev, int new_mtu)
3336 struct qeth_card *card;
3339 card = netdev_priv(dev);
3341 QETH_DBF_TEXT(TRACE, 4, "chgmtu");
3342 sprintf(dbf_text, "%8x", new_mtu);
3343 QETH_DBF_TEXT(TRACE, 4, dbf_text);
3347 if (new_mtu > 65535)
3349 if ((!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) &&
3350 (!qeth_mtu_is_valid(card, new_mtu)))
3355 EXPORT_SYMBOL_GPL(qeth_change_mtu);
3357 struct net_device_stats *qeth_get_stats(struct net_device *dev)
3359 struct qeth_card *card;
3361 card = netdev_priv(dev);
3363 QETH_DBF_TEXT(TRACE, 5, "getstat");
3365 return &card->stats;
3367 EXPORT_SYMBOL_GPL(qeth_get_stats);
3369 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
3370 struct qeth_reply *reply, unsigned long data)
3372 struct qeth_ipa_cmd *cmd;
3374 QETH_DBF_TEXT(TRACE, 4, "chgmaccb");
3376 cmd = (struct qeth_ipa_cmd *) data;
3377 if (!card->options.layer2 ||
3378 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
3379 memcpy(card->dev->dev_addr,
3380 &cmd->data.setadapterparms.data.change_addr.addr,
3382 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
3384 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
3388 int qeth_setadpparms_change_macaddr(struct qeth_card *card)
3391 struct qeth_cmd_buffer *iob;
3392 struct qeth_ipa_cmd *cmd;
3394 QETH_DBF_TEXT(TRACE, 4, "chgmac");
3396 iob = qeth_get_adapter_cmd(card, IPA_SETADP_ALTER_MAC_ADDRESS,
3397 sizeof(struct qeth_ipacmd_setadpparms));
3398 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3399 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
3400 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
3401 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
3402 card->dev->dev_addr, OSA_ADDR_LEN);
3403 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
3407 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
3409 void qeth_tx_timeout(struct net_device *dev)
3411 struct qeth_card *card;
3413 card = netdev_priv(dev);
3414 card->stats.tx_errors++;
3415 qeth_schedule_recovery(card);
3417 EXPORT_SYMBOL_GPL(qeth_tx_timeout);
3419 int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
3421 struct qeth_card *card = netdev_priv(dev);
3425 case MII_BMCR: /* Basic mode control register */
3427 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH) &&
3428 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
3429 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
3430 rc |= BMCR_SPEED100;
3432 case MII_BMSR: /* Basic mode status register */
3433 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
3434 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
3437 case MII_PHYSID1: /* PHYS ID 1 */
3438 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
3440 rc = (rc >> 5) & 0xFFFF;
3442 case MII_PHYSID2: /* PHYS ID 2 */
3443 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
3445 case MII_ADVERTISE: /* Advertisement control reg */
3448 case MII_LPA: /* Link partner ability reg */
3449 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
3450 LPA_100BASE4 | LPA_LPACK;
3452 case MII_EXPANSION: /* Expansion register */
3454 case MII_DCOUNTER: /* disconnect counter */
3456 case MII_FCSCOUNTER: /* false carrier counter */
3458 case MII_NWAYTEST: /* N-way auto-neg test register */
3460 case MII_RERRCOUNTER: /* rx error counter */
3461 rc = card->stats.rx_errors;
3463 case MII_SREVISION: /* silicon revision */
3465 case MII_RESV1: /* reserved 1 */
3467 case MII_LBRERROR: /* loopback, rx, bypass error */
3469 case MII_PHYADDR: /* physical address */
3471 case MII_RESV2: /* reserved 2 */
3473 case MII_TPISTATUS: /* TPI status for 10mbps */
3475 case MII_NCONFIG: /* network interface config */
3482 EXPORT_SYMBOL_GPL(qeth_mdio_read);
3484 static int qeth_send_ipa_snmp_cmd(struct qeth_card *card,
3485 struct qeth_cmd_buffer *iob, int len,
3486 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
3492 QETH_DBF_TEXT(TRACE, 4, "sendsnmp");
3494 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
3495 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
3496 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3497 /* adjust PDU length fields in IPA_PDU_HEADER */
3498 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
3500 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
3501 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
3502 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
3503 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
3504 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
3505 reply_cb, reply_param);
3508 static int qeth_snmp_command_cb(struct qeth_card *card,
3509 struct qeth_reply *reply, unsigned long sdata)
3511 struct qeth_ipa_cmd *cmd;
3512 struct qeth_arp_query_info *qinfo;
3513 struct qeth_snmp_cmd *snmp;
3514 unsigned char *data;
3517 QETH_DBF_TEXT(TRACE, 3, "snpcmdcb");
3519 cmd = (struct qeth_ipa_cmd *) sdata;
3520 data = (unsigned char *)((char *)cmd - reply->offset);
3521 qinfo = (struct qeth_arp_query_info *) reply->param;
3522 snmp = &cmd->data.setadapterparms.data.snmp;
3524 if (cmd->hdr.return_code) {
3525 QETH_DBF_TEXT_(TRACE, 4, "scer1%i", cmd->hdr.return_code);
3528 if (cmd->data.setadapterparms.hdr.return_code) {
3529 cmd->hdr.return_code =
3530 cmd->data.setadapterparms.hdr.return_code;
3531 QETH_DBF_TEXT_(TRACE, 4, "scer2%i", cmd->hdr.return_code);
3534 data_len = *((__u16 *)QETH_IPA_PDU_LEN_PDU1(data));
3535 if (cmd->data.setadapterparms.hdr.seq_no == 1)
3536 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
3538 data_len -= (__u16)((char *)&snmp->request - (char *)cmd);
3540 /* check if there is enough room in userspace */
3541 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
3542 QETH_DBF_TEXT_(TRACE, 4, "scer3%i", -ENOMEM);
3543 cmd->hdr.return_code = -ENOMEM;
3546 QETH_DBF_TEXT_(TRACE, 4, "snore%i",
3547 cmd->data.setadapterparms.hdr.used_total);
3548 QETH_DBF_TEXT_(TRACE, 4, "sseqn%i",
3549 cmd->data.setadapterparms.hdr.seq_no);
3550 /*copy entries to user buffer*/
3551 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
3552 memcpy(qinfo->udata + qinfo->udata_offset,
3554 data_len + offsetof(struct qeth_snmp_cmd, data));
3555 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
3557 memcpy(qinfo->udata + qinfo->udata_offset,
3558 (char *)&snmp->request, data_len);
3560 qinfo->udata_offset += data_len;
3561 /* check if all replies received ... */
3562 QETH_DBF_TEXT_(TRACE, 4, "srtot%i",
3563 cmd->data.setadapterparms.hdr.used_total);
3564 QETH_DBF_TEXT_(TRACE, 4, "srseq%i",
3565 cmd->data.setadapterparms.hdr.seq_no);
3566 if (cmd->data.setadapterparms.hdr.seq_no <
3567 cmd->data.setadapterparms.hdr.used_total)
3572 int qeth_snmp_command(struct qeth_card *card, char __user *udata)
3574 struct qeth_cmd_buffer *iob;
3575 struct qeth_ipa_cmd *cmd;
3576 struct qeth_snmp_ureq *ureq;
3578 struct qeth_arp_query_info qinfo = {0, };
3581 QETH_DBF_TEXT(TRACE, 3, "snmpcmd");
3583 if (card->info.guestlan)
3586 if ((!qeth_adp_supported(card, IPA_SETADP_SET_SNMP_CONTROL)) &&
3587 (!card->options.layer2)) {
3590 /* skip 4 bytes (data_len struct member) to get req_len */
3591 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
3593 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
3595 QETH_DBF_TEXT(TRACE, 2, "snmpnome");
3598 if (copy_from_user(ureq, udata,
3599 req_len + sizeof(struct qeth_snmp_ureq_hdr))) {
3603 qinfo.udata_len = ureq->hdr.data_len;
3604 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
3609 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
3611 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
3612 QETH_SNMP_SETADP_CMDLENGTH + req_len);
3613 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3614 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
3615 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
3616 qeth_snmp_command_cb, (void *)&qinfo);
3618 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
3619 QETH_CARD_IFNAME(card), rc);
3621 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
3629 EXPORT_SYMBOL_GPL(qeth_snmp_command);
3631 static inline int qeth_get_qdio_q_format(struct qeth_card *card)
3633 switch (card->info.type) {
3634 case QETH_CARD_TYPE_IQD:
3641 static int qeth_qdio_establish(struct qeth_card *card)
3643 struct qdio_initialize init_data;
3644 char *qib_param_field;
3645 struct qdio_buffer **in_sbal_ptrs;
3646 struct qdio_buffer **out_sbal_ptrs;
3650 QETH_DBF_TEXT(SETUP, 2, "qdioest");
3652 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3654 if (!qib_param_field)
3657 qeth_create_qib_param_field(card, qib_param_field);
3658 qeth_create_qib_param_field_blkt(card, qib_param_field);
3660 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3662 if (!in_sbal_ptrs) {
3663 kfree(qib_param_field);
3666 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3667 in_sbal_ptrs[i] = (struct qdio_buffer *)
3668 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3671 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3672 sizeof(void *), GFP_KERNEL);
3673 if (!out_sbal_ptrs) {
3674 kfree(in_sbal_ptrs);
3675 kfree(qib_param_field);
3678 for (i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3679 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k) {
3680 out_sbal_ptrs[k] = (struct qdio_buffer *)virt_to_phys(
3681 card->qdio.out_qs[i]->bufs[j].buffer);
3684 memset(&init_data, 0, sizeof(struct qdio_initialize));
3685 init_data.cdev = CARD_DDEV(card);
3686 init_data.q_format = qeth_get_qdio_q_format(card);
3687 init_data.qib_param_field_format = 0;
3688 init_data.qib_param_field = qib_param_field;
3689 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3690 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3691 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3692 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3693 init_data.no_input_qs = 1;
3694 init_data.no_output_qs = card->qdio.no_out_queues;
3695 init_data.input_handler = card->discipline.input_handler;
3696 init_data.output_handler = card->discipline.output_handler;
3697 init_data.int_parm = (unsigned long) card;
3698 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3699 QDIO_OUTBOUND_0COPY_SBALS |
3700 QDIO_USE_OUTBOUND_PCIS;
3701 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3702 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3704 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3705 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
3706 rc = qdio_initialize(&init_data);
3708 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3710 kfree(out_sbal_ptrs);
3711 kfree(in_sbal_ptrs);
3712 kfree(qib_param_field);
3716 static void qeth_core_free_card(struct qeth_card *card)
3719 QETH_DBF_TEXT(SETUP, 2, "freecrd");
3720 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
3721 qeth_clean_channel(&card->read);
3722 qeth_clean_channel(&card->write);
3724 free_netdev(card->dev);
3725 kfree(card->ip_tbd_list);
3726 qeth_free_qdio_buffers(card);
3730 static struct ccw_device_id qeth_ids[] = {
3731 {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
3732 {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
3733 {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
3736 MODULE_DEVICE_TABLE(ccw, qeth_ids);
3738 static struct ccw_driver qeth_ccw_driver = {
3741 .probe = ccwgroup_probe_ccwdev,
3742 .remove = ccwgroup_remove_ccwdev,
3745 static int qeth_core_driver_group(const char *buf, struct device *root_dev,
3746 unsigned long driver_id)
3748 return ccwgroup_create_from_string(root_dev, driver_id,
3749 &qeth_ccw_driver, 3, buf);
3752 int qeth_core_hardsetup_card(struct qeth_card *card)
3758 QETH_DBF_TEXT(SETUP, 2, "hrdsetup");
3759 atomic_set(&card->force_alloc_skb, 0);
3762 PRINT_WARN("Retrying to do IDX activates.\n");
3763 ccw_device_set_offline(CARD_DDEV(card));
3764 ccw_device_set_offline(CARD_WDEV(card));
3765 ccw_device_set_offline(CARD_RDEV(card));
3766 ccw_device_set_online(CARD_RDEV(card));
3767 ccw_device_set_online(CARD_WDEV(card));
3768 ccw_device_set_online(CARD_DDEV(card));
3770 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
3771 if (rc == -ERESTARTSYS) {
3772 QETH_DBF_TEXT(SETUP, 2, "break1");
3775 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3782 rc = qeth_get_unitaddr(card);
3784 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3787 mpno = qdio_get_ssqd_pct(CARD_DDEV(card));
3789 mpno = min(mpno - 1, QETH_MAX_PORTNO);
3790 if (card->info.portno > mpno) {
3791 QETH_DBF_MESSAGE(2, "Device %s does not offer port number %d"
3792 "\n.", CARD_BUS_ID(card), card->info.portno);
3796 qeth_init_tokens(card);
3797 qeth_init_func_level(card);
3798 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
3799 if (rc == -ERESTARTSYS) {
3800 QETH_DBF_TEXT(SETUP, 2, "break2");
3803 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3809 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
3810 if (rc == -ERESTARTSYS) {
3811 QETH_DBF_TEXT(SETUP, 2, "break3");
3814 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3820 rc = qeth_mpc_initialize(card);
3822 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3827 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
3830 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card);
3832 static inline int qeth_create_skb_frag(struct qdio_buffer_element *element,
3833 struct sk_buff **pskb, int offset, int *pfrag, int data_len)
3835 struct page *page = virt_to_page(element->addr);
3836 if (*pskb == NULL) {
3837 /* the upper protocol layers assume that there is data in the
3838 * skb itself. Copy a small amount (64 bytes) to make them
3840 *pskb = dev_alloc_skb(64 + ETH_HLEN);
3843 skb_reserve(*pskb, ETH_HLEN);
3844 if (data_len <= 64) {
3845 memcpy(skb_put(*pskb, data_len), element->addr + offset,
3849 memcpy(skb_put(*pskb, 64), element->addr + offset, 64);
3850 skb_fill_page_desc(*pskb, *pfrag, page, offset + 64,
3852 (*pskb)->data_len += data_len - 64;
3853 (*pskb)->len += data_len - 64;
3854 (*pskb)->truesize += data_len - 64;
3859 skb_fill_page_desc(*pskb, *pfrag, page, offset, data_len);
3860 (*pskb)->data_len += data_len;
3861 (*pskb)->len += data_len;
3862 (*pskb)->truesize += data_len;
3868 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
3869 struct qdio_buffer *buffer,
3870 struct qdio_buffer_element **__element, int *__offset,
3871 struct qeth_hdr **hdr)
3873 struct qdio_buffer_element *element = *__element;
3874 int offset = *__offset;
3875 struct sk_buff *skb = NULL;
3883 /* qeth_hdr must not cross element boundaries */
3884 if (element->length < offset + sizeof(struct qeth_hdr)) {
3885 if (qeth_is_last_sbale(element))
3889 if (element->length < sizeof(struct qeth_hdr))
3892 *hdr = element->addr + offset;
3894 offset += sizeof(struct qeth_hdr);
3895 if (card->options.layer2) {
3896 if (card->info.type == QETH_CARD_TYPE_OSN) {
3897 skb_len = (*hdr)->hdr.osn.pdu_length;
3898 headroom = sizeof(struct qeth_hdr);
3900 skb_len = (*hdr)->hdr.l2.pkt_length;
3903 skb_len = (*hdr)->hdr.l3.length;
3904 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3905 (card->info.link_type == QETH_LINK_TYPE_HSTR))
3908 headroom = ETH_HLEN;
3914 if ((skb_len >= card->options.rx_sg_cb) &&
3915 (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
3916 (!atomic_read(&card->force_alloc_skb))) {
3919 skb = dev_alloc_skb(skb_len + headroom);
3923 skb_reserve(skb, headroom);
3926 data_ptr = element->addr + offset;
3928 data_len = min(skb_len, (int)(element->length - offset));
3931 if (qeth_create_skb_frag(element, &skb, offset,
3935 memcpy(skb_put(skb, data_len), data_ptr,
3939 skb_len -= data_len;
3941 if (qeth_is_last_sbale(element)) {
3942 QETH_DBF_TEXT(TRACE, 4, "unexeob");
3943 QETH_DBF_TEXT_(TRACE, 4, "%s",
3945 QETH_DBF_TEXT(QERR, 2, "unexeob");
3946 QETH_DBF_TEXT_(QERR, 2, "%s",
3948 QETH_DBF_HEX(MISC, 4, buffer, sizeof(*buffer));
3949 dev_kfree_skb_any(skb);
3950 card->stats.rx_errors++;
3955 data_ptr = element->addr;
3960 *__element = element;
3962 if (use_rx_sg && card->options.performance_stats) {
3963 card->perf_stats.sg_skbs_rx++;
3964 card->perf_stats.sg_frags_rx += skb_shinfo(skb)->nr_frags;
3968 if (net_ratelimit()) {
3969 QETH_DBF_TEXT(TRACE, 2, "noskbmem");
3970 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
3972 card->stats.rx_dropped++;
3975 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb);
3977 static void qeth_unregister_dbf_views(void)
3980 for (x = 0; x < QETH_DBF_INFOS; x++) {
3981 debug_unregister(qeth_dbf[x].id);
3982 qeth_dbf[x].id = NULL;
3986 void qeth_dbf_longtext(enum qeth_dbf_names dbf_nix, int level, char *fmt, ...)
3988 char dbf_txt_buf[32];
3991 if (level > (qeth_dbf[dbf_nix].id)->level)
3993 va_start(args, fmt);
3994 vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
3996 debug_text_event(qeth_dbf[dbf_nix].id, level, dbf_txt_buf);
3998 EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
4000 static int qeth_register_dbf_views(void)
4005 for (x = 0; x < QETH_DBF_INFOS; x++) {
4006 /* register the areas */
4007 qeth_dbf[x].id = debug_register(qeth_dbf[x].name,
4011 if (qeth_dbf[x].id == NULL) {
4012 qeth_unregister_dbf_views();
4016 /* register a view */
4017 ret = debug_register_view(qeth_dbf[x].id, qeth_dbf[x].view);
4019 qeth_unregister_dbf_views();
4023 /* set a passing level */
4024 debug_set_level(qeth_dbf[x].id, qeth_dbf[x].level);
4030 int qeth_core_load_discipline(struct qeth_card *card,
4031 enum qeth_discipline_id discipline)
4034 switch (discipline) {
4035 case QETH_DISCIPLINE_LAYER3:
4036 card->discipline.ccwgdriver = try_then_request_module(
4037 symbol_get(qeth_l3_ccwgroup_driver),
4040 case QETH_DISCIPLINE_LAYER2:
4041 card->discipline.ccwgdriver = try_then_request_module(
4042 symbol_get(qeth_l2_ccwgroup_driver),
4046 if (!card->discipline.ccwgdriver) {
4047 PRINT_ERR("Support for discipline %d not present\n",
4054 void qeth_core_free_discipline(struct qeth_card *card)
4056 if (card->options.layer2)
4057 symbol_put(qeth_l2_ccwgroup_driver);
4059 symbol_put(qeth_l3_ccwgroup_driver);
4060 card->discipline.ccwgdriver = NULL;
4063 static int qeth_core_probe_device(struct ccwgroup_device *gdev)
4065 struct qeth_card *card;
4068 unsigned long flags;
4070 QETH_DBF_TEXT(SETUP, 2, "probedev");
4073 if (!get_device(dev))
4076 QETH_DBF_TEXT_(SETUP, 2, "%s", gdev->dev.bus_id);
4078 card = qeth_alloc_card();
4080 QETH_DBF_TEXT_(SETUP, 2, "1err%d", -ENOMEM);
4084 card->read.ccwdev = gdev->cdev[0];
4085 card->write.ccwdev = gdev->cdev[1];
4086 card->data.ccwdev = gdev->cdev[2];
4087 dev_set_drvdata(&gdev->dev, card);
4089 gdev->cdev[0]->handler = qeth_irq;
4090 gdev->cdev[1]->handler = qeth_irq;
4091 gdev->cdev[2]->handler = qeth_irq;
4093 rc = qeth_determine_card_type(card);
4095 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
4098 rc = qeth_setup_card(card);
4100 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
4104 if (card->info.type == QETH_CARD_TYPE_OSN) {
4105 rc = qeth_core_create_osn_attributes(dev);
4108 rc = qeth_core_load_discipline(card, QETH_DISCIPLINE_LAYER2);
4110 qeth_core_remove_osn_attributes(dev);
4113 rc = card->discipline.ccwgdriver->probe(card->gdev);
4115 qeth_core_free_discipline(card);
4116 qeth_core_remove_osn_attributes(dev);
4120 rc = qeth_core_create_device_attributes(dev);
4125 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
4126 list_add_tail(&card->list, &qeth_core_card_list.list);
4127 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
4131 qeth_core_free_card(card);
4137 static void qeth_core_remove_device(struct ccwgroup_device *gdev)
4139 unsigned long flags;
4140 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4142 if (card->discipline.ccwgdriver) {
4143 card->discipline.ccwgdriver->remove(gdev);
4144 qeth_core_free_discipline(card);
4147 if (card->info.type == QETH_CARD_TYPE_OSN) {
4148 qeth_core_remove_osn_attributes(&gdev->dev);
4150 qeth_core_remove_device_attributes(&gdev->dev);
4152 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
4153 list_del(&card->list);
4154 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
4155 qeth_core_free_card(card);
4156 dev_set_drvdata(&gdev->dev, NULL);
4157 put_device(&gdev->dev);
4161 static int qeth_core_set_online(struct ccwgroup_device *gdev)
4163 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4167 if (!card->discipline.ccwgdriver) {
4168 if (card->info.type == QETH_CARD_TYPE_IQD)
4169 def_discipline = QETH_DISCIPLINE_LAYER3;
4171 def_discipline = QETH_DISCIPLINE_LAYER2;
4172 rc = qeth_core_load_discipline(card, def_discipline);
4175 rc = card->discipline.ccwgdriver->probe(card->gdev);
4179 rc = card->discipline.ccwgdriver->set_online(gdev);
4184 static int qeth_core_set_offline(struct ccwgroup_device *gdev)
4186 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4187 return card->discipline.ccwgdriver->set_offline(gdev);
4190 static void qeth_core_shutdown(struct ccwgroup_device *gdev)
4192 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4193 if (card->discipline.ccwgdriver &&
4194 card->discipline.ccwgdriver->shutdown)
4195 card->discipline.ccwgdriver->shutdown(gdev);
4198 static struct ccwgroup_driver qeth_core_ccwgroup_driver = {
4199 .owner = THIS_MODULE,
4201 .driver_id = 0xD8C5E3C8,
4202 .probe = qeth_core_probe_device,
4203 .remove = qeth_core_remove_device,
4204 .set_online = qeth_core_set_online,
4205 .set_offline = qeth_core_set_offline,
4206 .shutdown = qeth_core_shutdown,
4210 qeth_core_driver_group_store(struct device_driver *ddrv, const char *buf,
4214 err = qeth_core_driver_group(buf, qeth_core_root_dev,
4215 qeth_core_ccwgroup_driver.driver_id);
4222 static DRIVER_ATTR(group, 0200, NULL, qeth_core_driver_group_store);
4225 const char str[ETH_GSTRING_LEN];
4226 } qeth_ethtool_stats_keys[] = {
4231 {"tx skbs no packing"},
4232 {"tx buffers no packing"},
4233 {"tx skbs packing"},
4234 {"tx buffers packing"},
4237 /* 10 */{"rx sg skbs"},
4239 {"rx sg page allocs"},
4240 {"tx large kbytes"},
4242 {"tx pk state ch n->p"},
4243 {"tx pk state ch p->n"},
4244 {"tx pk watermark low"},
4245 {"tx pk watermark high"},
4246 {"queue 0 buffer usage"},
4247 /* 20 */{"queue 1 buffer usage"},
4248 {"queue 2 buffer usage"},
4249 {"queue 3 buffer usage"},
4250 {"rx handler time"},
4251 {"rx handler count"},
4252 {"rx do_QDIO time"},
4253 {"rx do_QDIO count"},
4254 {"tx handler time"},
4255 {"tx handler count"},
4257 /* 30 */{"tx count"},
4258 {"tx do_QDIO time"},
4259 {"tx do_QDIO count"},
4262 int qeth_core_get_stats_count(struct net_device *dev)
4264 return (sizeof(qeth_ethtool_stats_keys) / ETH_GSTRING_LEN);
4266 EXPORT_SYMBOL_GPL(qeth_core_get_stats_count);
4268 void qeth_core_get_ethtool_stats(struct net_device *dev,
4269 struct ethtool_stats *stats, u64 *data)
4271 struct qeth_card *card = netdev_priv(dev);
4272 data[0] = card->stats.rx_packets -
4273 card->perf_stats.initial_rx_packets;
4274 data[1] = card->perf_stats.bufs_rec;
4275 data[2] = card->stats.tx_packets -
4276 card->perf_stats.initial_tx_packets;
4277 data[3] = card->perf_stats.bufs_sent;
4278 data[4] = card->stats.tx_packets - card->perf_stats.initial_tx_packets
4279 - card->perf_stats.skbs_sent_pack;
4280 data[5] = card->perf_stats.bufs_sent - card->perf_stats.bufs_sent_pack;
4281 data[6] = card->perf_stats.skbs_sent_pack;
4282 data[7] = card->perf_stats.bufs_sent_pack;
4283 data[8] = card->perf_stats.sg_skbs_sent;
4284 data[9] = card->perf_stats.sg_frags_sent;
4285 data[10] = card->perf_stats.sg_skbs_rx;
4286 data[11] = card->perf_stats.sg_frags_rx;
4287 data[12] = card->perf_stats.sg_alloc_page_rx;
4288 data[13] = (card->perf_stats.large_send_bytes >> 10);
4289 data[14] = card->perf_stats.large_send_cnt;
4290 data[15] = card->perf_stats.sc_dp_p;
4291 data[16] = card->perf_stats.sc_p_dp;
4292 data[17] = QETH_LOW_WATERMARK_PACK;
4293 data[18] = QETH_HIGH_WATERMARK_PACK;
4294 data[19] = atomic_read(&card->qdio.out_qs[0]->used_buffers);
4295 data[20] = (card->qdio.no_out_queues > 1) ?
4296 atomic_read(&card->qdio.out_qs[1]->used_buffers) : 0;
4297 data[21] = (card->qdio.no_out_queues > 2) ?
4298 atomic_read(&card->qdio.out_qs[2]->used_buffers) : 0;
4299 data[22] = (card->qdio.no_out_queues > 3) ?
4300 atomic_read(&card->qdio.out_qs[3]->used_buffers) : 0;
4301 data[23] = card->perf_stats.inbound_time;
4302 data[24] = card->perf_stats.inbound_cnt;
4303 data[25] = card->perf_stats.inbound_do_qdio_time;
4304 data[26] = card->perf_stats.inbound_do_qdio_cnt;
4305 data[27] = card->perf_stats.outbound_handler_time;
4306 data[28] = card->perf_stats.outbound_handler_cnt;
4307 data[29] = card->perf_stats.outbound_time;
4308 data[30] = card->perf_stats.outbound_cnt;
4309 data[31] = card->perf_stats.outbound_do_qdio_time;
4310 data[32] = card->perf_stats.outbound_do_qdio_cnt;
4312 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats);
4314 void qeth_core_get_strings(struct net_device *dev, u32 stringset, u8 *data)
4316 switch (stringset) {
4318 memcpy(data, &qeth_ethtool_stats_keys,
4319 sizeof(qeth_ethtool_stats_keys));
4326 EXPORT_SYMBOL_GPL(qeth_core_get_strings);
4328 void qeth_core_get_drvinfo(struct net_device *dev,
4329 struct ethtool_drvinfo *info)
4331 struct qeth_card *card = netdev_priv(dev);
4332 if (card->options.layer2)
4333 strcpy(info->driver, "qeth_l2");
4335 strcpy(info->driver, "qeth_l3");
4337 strcpy(info->version, "1.0");
4338 strcpy(info->fw_version, card->info.mcl_level);
4339 sprintf(info->bus_info, "%s/%s/%s",
4342 CARD_DDEV_ID(card));
4344 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo);
4346 int qeth_core_ethtool_get_settings(struct net_device *netdev,
4347 struct ethtool_cmd *ecmd)
4349 struct qeth_card *card = netdev_priv(netdev);
4350 enum qeth_link_types link_type;
4352 if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan))
4353 link_type = QETH_LINK_TYPE_10GBIT_ETH;
4355 link_type = card->info.link_type;
4357 ecmd->transceiver = XCVR_INTERNAL;
4358 ecmd->supported = SUPPORTED_Autoneg;
4359 ecmd->advertising = ADVERTISED_Autoneg;
4360 ecmd->duplex = DUPLEX_FULL;
4361 ecmd->autoneg = AUTONEG_ENABLE;
4363 switch (link_type) {
4364 case QETH_LINK_TYPE_FAST_ETH:
4365 case QETH_LINK_TYPE_LANE_ETH100:
4366 ecmd->supported |= SUPPORTED_10baseT_Half |
4367 SUPPORTED_10baseT_Full |
4368 SUPPORTED_100baseT_Half |
4369 SUPPORTED_100baseT_Full |
4371 ecmd->advertising |= ADVERTISED_10baseT_Half |
4372 ADVERTISED_10baseT_Full |
4373 ADVERTISED_100baseT_Half |
4374 ADVERTISED_100baseT_Full |
4376 ecmd->speed = SPEED_100;
4377 ecmd->port = PORT_TP;
4380 case QETH_LINK_TYPE_GBIT_ETH:
4381 case QETH_LINK_TYPE_LANE_ETH1000:
4382 ecmd->supported |= SUPPORTED_10baseT_Half |
4383 SUPPORTED_10baseT_Full |
4384 SUPPORTED_100baseT_Half |
4385 SUPPORTED_100baseT_Full |
4386 SUPPORTED_1000baseT_Half |
4387 SUPPORTED_1000baseT_Full |
4389 ecmd->advertising |= ADVERTISED_10baseT_Half |
4390 ADVERTISED_10baseT_Full |
4391 ADVERTISED_100baseT_Half |
4392 ADVERTISED_100baseT_Full |
4393 ADVERTISED_1000baseT_Half |
4394 ADVERTISED_1000baseT_Full |
4396 ecmd->speed = SPEED_1000;
4397 ecmd->port = PORT_FIBRE;
4400 case QETH_LINK_TYPE_10GBIT_ETH:
4401 ecmd->supported |= SUPPORTED_10baseT_Half |
4402 SUPPORTED_10baseT_Full |
4403 SUPPORTED_100baseT_Half |
4404 SUPPORTED_100baseT_Full |
4405 SUPPORTED_1000baseT_Half |
4406 SUPPORTED_1000baseT_Full |
4407 SUPPORTED_10000baseT_Full |
4409 ecmd->advertising |= ADVERTISED_10baseT_Half |
4410 ADVERTISED_10baseT_Full |
4411 ADVERTISED_100baseT_Half |
4412 ADVERTISED_100baseT_Full |
4413 ADVERTISED_1000baseT_Half |
4414 ADVERTISED_1000baseT_Full |
4415 ADVERTISED_10000baseT_Full |
4417 ecmd->speed = SPEED_10000;
4418 ecmd->port = PORT_FIBRE;
4422 ecmd->supported |= SUPPORTED_10baseT_Half |
4423 SUPPORTED_10baseT_Full |
4425 ecmd->advertising |= ADVERTISED_10baseT_Half |
4426 ADVERTISED_10baseT_Full |
4428 ecmd->speed = SPEED_10;
4429 ecmd->port = PORT_TP;
4434 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings);
4436 static int __init qeth_core_init(void)
4440 PRINT_INFO("loading core functions\n");
4441 INIT_LIST_HEAD(&qeth_core_card_list.list);
4442 rwlock_init(&qeth_core_card_list.rwlock);
4444 rc = qeth_register_dbf_views();
4447 rc = ccw_driver_register(&qeth_ccw_driver);
4450 rc = ccwgroup_driver_register(&qeth_core_ccwgroup_driver);
4453 rc = driver_create_file(&qeth_core_ccwgroup_driver.driver,
4454 &driver_attr_group);
4457 qeth_core_root_dev = s390_root_dev_register("qeth");
4458 rc = IS_ERR(qeth_core_root_dev) ? PTR_ERR(qeth_core_root_dev) : 0;
4464 driver_remove_file(&qeth_core_ccwgroup_driver.driver,
4465 &driver_attr_group);
4467 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
4469 ccw_driver_unregister(&qeth_ccw_driver);
4471 qeth_unregister_dbf_views();
4473 PRINT_ERR("Initialization failed with code %d\n", rc);
4477 static void __exit qeth_core_exit(void)
4479 s390_root_dev_unregister(qeth_core_root_dev);
4480 driver_remove_file(&qeth_core_ccwgroup_driver.driver,
4481 &driver_attr_group);
4482 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
4483 ccw_driver_unregister(&qeth_ccw_driver);
4484 qeth_unregister_dbf_views();
4485 PRINT_INFO("core functions removed\n");
4488 module_init(qeth_core_init);
4489 module_exit(qeth_core_exit);
4490 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
4491 MODULE_DESCRIPTION("qeth core functions");
4492 MODULE_LICENSE("GPL");