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));
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);
2354 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2357 /* outbound queue */
2358 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2359 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
2360 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
2361 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2362 qeth_clear_output_buffer(card->qdio.out_qs[i],
2363 &card->qdio.out_qs[i]->bufs[j]);
2365 card->qdio.out_qs[i]->card = card;
2366 card->qdio.out_qs[i]->next_buf_to_fill = 0;
2367 card->qdio.out_qs[i]->do_pack = 0;
2368 atomic_set(&card->qdio.out_qs[i]->used_buffers, 0);
2369 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
2370 atomic_set(&card->qdio.out_qs[i]->state,
2371 QETH_OUT_Q_UNLOCKED);
2375 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues);
2377 static inline __u8 qeth_get_ipa_adp_type(enum qeth_link_types link_type)
2379 switch (link_type) {
2380 case QETH_LINK_TYPE_HSTR:
2387 static void qeth_fill_ipacmd_header(struct qeth_card *card,
2388 struct qeth_ipa_cmd *cmd, __u8 command,
2389 enum qeth_prot_versions prot)
2391 memset(cmd, 0, sizeof(struct qeth_ipa_cmd));
2392 cmd->hdr.command = command;
2393 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
2394 cmd->hdr.seqno = card->seqno.ipa;
2395 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
2396 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
2397 if (card->options.layer2)
2398 cmd->hdr.prim_version_no = 2;
2400 cmd->hdr.prim_version_no = 1;
2401 cmd->hdr.param_count = 1;
2402 cmd->hdr.prot_version = prot;
2403 cmd->hdr.ipa_supported = 0;
2404 cmd->hdr.ipa_enabled = 0;
2407 struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *card,
2408 enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
2410 struct qeth_cmd_buffer *iob;
2411 struct qeth_ipa_cmd *cmd;
2413 iob = qeth_wait_for_buffer(&card->write);
2414 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2415 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
2419 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer);
2421 void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2424 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2425 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data), &prot_type, 1);
2426 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2427 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2429 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd);
2431 int qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2432 int (*reply_cb)(struct qeth_card *, struct qeth_reply*,
2439 QETH_DBF_TEXT(TRACE, 4, "sendipa");
2441 if (card->options.layer2)
2442 if (card->info.type == QETH_CARD_TYPE_OSN)
2443 prot_type = QETH_PROT_OSN2;
2445 prot_type = QETH_PROT_LAYER2;
2447 prot_type = QETH_PROT_TCPIP;
2448 qeth_prepare_ipa_cmd(card, iob, prot_type);
2449 rc = qeth_send_control_data(card, IPA_CMD_LENGTH,
2450 iob, reply_cb, reply_param);
2453 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd);
2455 static int qeth_send_startstoplan(struct qeth_card *card,
2456 enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
2459 struct qeth_cmd_buffer *iob;
2461 iob = qeth_get_ipacmd_buffer(card, ipacmd, prot);
2462 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
2467 int qeth_send_startlan(struct qeth_card *card)
2471 QETH_DBF_TEXT(SETUP, 2, "strtlan");
2473 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, 0);
2476 EXPORT_SYMBOL_GPL(qeth_send_startlan);
2478 int qeth_send_stoplan(struct qeth_card *card)
2483 * TODO: according to the IPA format document page 14,
2484 * TCP/IP (we!) never issue a STOPLAN
2487 QETH_DBF_TEXT(SETUP, 2, "stoplan");
2489 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, 0);
2492 EXPORT_SYMBOL_GPL(qeth_send_stoplan);
2494 int qeth_default_setadapterparms_cb(struct qeth_card *card,
2495 struct qeth_reply *reply, unsigned long data)
2497 struct qeth_ipa_cmd *cmd;
2499 QETH_DBF_TEXT(TRACE, 4, "defadpcb");
2501 cmd = (struct qeth_ipa_cmd *) data;
2502 if (cmd->hdr.return_code == 0)
2503 cmd->hdr.return_code =
2504 cmd->data.setadapterparms.hdr.return_code;
2507 EXPORT_SYMBOL_GPL(qeth_default_setadapterparms_cb);
2509 static int qeth_query_setadapterparms_cb(struct qeth_card *card,
2510 struct qeth_reply *reply, unsigned long data)
2512 struct qeth_ipa_cmd *cmd;
2514 QETH_DBF_TEXT(TRACE, 3, "quyadpcb");
2516 cmd = (struct qeth_ipa_cmd *) data;
2517 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
2518 card->info.link_type =
2519 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
2520 card->options.adp.supported_funcs =
2521 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
2522 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
2525 struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
2526 __u32 command, __u32 cmdlen)
2528 struct qeth_cmd_buffer *iob;
2529 struct qeth_ipa_cmd *cmd;
2531 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETADAPTERPARMS,
2533 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2534 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
2535 cmd->data.setadapterparms.hdr.command_code = command;
2536 cmd->data.setadapterparms.hdr.used_total = 1;
2537 cmd->data.setadapterparms.hdr.seq_no = 1;
2541 EXPORT_SYMBOL_GPL(qeth_get_adapter_cmd);
2543 int qeth_query_setadapterparms(struct qeth_card *card)
2546 struct qeth_cmd_buffer *iob;
2548 QETH_DBF_TEXT(TRACE, 3, "queryadp");
2549 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
2550 sizeof(struct qeth_ipacmd_setadpparms));
2551 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
2554 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms);
2556 int qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2557 const char *dbftext)
2560 QETH_DBF_TEXT(TRACE, 2, dbftext);
2561 QETH_DBF_TEXT(QERR, 2, dbftext);
2562 QETH_DBF_TEXT_(QERR, 2, " F15=%02X",
2563 buf->element[15].flags & 0xff);
2564 QETH_DBF_TEXT_(QERR, 2, " F14=%02X",
2565 buf->element[14].flags & 0xff);
2566 QETH_DBF_TEXT_(QERR, 2, " qerr=%X", qdio_error);
2571 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors);
2573 void qeth_queue_input_buffer(struct qeth_card *card, int index)
2575 struct qeth_qdio_q *queue = card->qdio.in_q;
2581 count = (index < queue->next_buf_to_init)?
2582 card->qdio.in_buf_pool.buf_count -
2583 (queue->next_buf_to_init - index) :
2584 card->qdio.in_buf_pool.buf_count -
2585 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2586 /* only requeue at a certain threshold to avoid SIGAs */
2587 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)) {
2588 for (i = queue->next_buf_to_init;
2589 i < queue->next_buf_to_init + count; ++i) {
2590 if (qeth_init_input_buffer(card,
2591 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q])) {
2598 if (newcount < count) {
2599 /* we are in memory shortage so we switch back to
2600 traditional skb allocation and drop packages */
2601 atomic_set(&card->force_alloc_skb, 3);
2604 atomic_add_unless(&card->force_alloc_skb, -1, 0);
2608 * according to old code it should be avoided to requeue all
2609 * 128 buffers in order to benefit from PCI avoidance.
2610 * this function keeps at least one buffer (the buffer at
2611 * 'index') un-requeued -> this buffer is the first buffer that
2612 * will be requeued the next time
2614 if (card->options.performance_stats) {
2615 card->perf_stats.inbound_do_qdio_cnt++;
2616 card->perf_stats.inbound_do_qdio_start_time =
2619 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0,
2620 queue->next_buf_to_init, count);
2621 if (card->options.performance_stats)
2622 card->perf_stats.inbound_do_qdio_time +=
2624 card->perf_stats.inbound_do_qdio_start_time;
2626 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2627 "return %i (device %s).\n",
2628 rc, CARD_DDEV_ID(card));
2629 QETH_DBF_TEXT(TRACE, 2, "qinberr");
2630 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
2632 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2633 QDIO_MAX_BUFFERS_PER_Q;
2636 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer);
2638 static int qeth_handle_send_error(struct qeth_card *card,
2639 struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err)
2641 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2642 int cc = qdio_err & 3;
2644 QETH_DBF_TEXT(TRACE, 6, "hdsnderr");
2645 qeth_check_qdio_errors(buffer->buffer, qdio_err, "qouterr");
2649 QETH_DBF_TEXT(TRACE, 1, "lnkfail");
2650 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2651 QETH_DBF_TEXT_(TRACE, 1, "%04x %02x",
2652 (u16)qdio_err, (u8)sbalf15);
2653 return QETH_SEND_ERROR_LINK_FAILURE;
2655 return QETH_SEND_ERROR_NONE;
2657 if (qdio_err & QDIO_ERROR_SIGA_BUSY) {
2658 QETH_DBF_TEXT(TRACE, 1, "SIGAcc2B");
2659 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2660 return QETH_SEND_ERROR_KICK_IT;
2662 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2663 return QETH_SEND_ERROR_RETRY;
2664 return QETH_SEND_ERROR_LINK_FAILURE;
2665 /* look at qdio_error and sbalf 15 */
2667 QETH_DBF_TEXT(TRACE, 1, "SIGAcc1");
2668 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2669 return QETH_SEND_ERROR_LINK_FAILURE;
2672 QETH_DBF_TEXT(TRACE, 1, "SIGAcc3");
2673 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
2674 return QETH_SEND_ERROR_KICK_IT;
2679 * Switched to packing state if the number of used buffers on a queue
2680 * reaches a certain limit.
2682 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2684 if (!queue->do_pack) {
2685 if (atomic_read(&queue->used_buffers)
2686 >= QETH_HIGH_WATERMARK_PACK){
2687 /* switch non-PACKING -> PACKING */
2688 QETH_DBF_TEXT(TRACE, 6, "np->pack");
2689 if (queue->card->options.performance_stats)
2690 queue->card->perf_stats.sc_dp_p++;
2697 * Switches from packing to non-packing mode. If there is a packing
2698 * buffer on the queue this buffer will be prepared to be flushed.
2699 * In that case 1 is returned to inform the caller. If no buffer
2700 * has to be flushed, zero is returned.
2702 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2704 struct qeth_qdio_out_buffer *buffer;
2705 int flush_count = 0;
2707 if (queue->do_pack) {
2708 if (atomic_read(&queue->used_buffers)
2709 <= QETH_LOW_WATERMARK_PACK) {
2710 /* switch PACKING -> non-PACKING */
2711 QETH_DBF_TEXT(TRACE, 6, "pack->np");
2712 if (queue->card->options.performance_stats)
2713 queue->card->perf_stats.sc_p_dp++;
2715 /* flush packing buffers */
2716 buffer = &queue->bufs[queue->next_buf_to_fill];
2717 if ((atomic_read(&buffer->state) ==
2718 QETH_QDIO_BUF_EMPTY) &&
2719 (buffer->next_element_to_fill > 0)) {
2720 atomic_set(&buffer->state,
2721 QETH_QDIO_BUF_PRIMED);
2723 queue->next_buf_to_fill =
2724 (queue->next_buf_to_fill + 1) %
2725 QDIO_MAX_BUFFERS_PER_Q;
2733 * Called to flush a packing buffer if no more pci flags are on the queue.
2734 * Checks if there is a packing buffer and prepares it to be flushed.
2735 * In that case returns 1, otherwise zero.
2737 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2739 struct qeth_qdio_out_buffer *buffer;
2741 buffer = &queue->bufs[queue->next_buf_to_fill];
2742 if ((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2743 (buffer->next_element_to_fill > 0)) {
2744 /* it's a packing buffer */
2745 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2746 queue->next_buf_to_fill =
2747 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2753 static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
2756 struct qeth_qdio_out_buffer *buf;
2759 unsigned int qdio_flags;
2761 for (i = index; i < index + count; ++i) {
2762 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2763 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2764 SBAL_FLAGS_LAST_ENTRY;
2766 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2769 if (!queue->do_pack) {
2770 if ((atomic_read(&queue->used_buffers) >=
2771 (QETH_HIGH_WATERMARK_PACK -
2772 QETH_WATERMARK_PACK_FUZZ)) &&
2773 !atomic_read(&queue->set_pci_flags_count)) {
2774 /* it's likely that we'll go to packing
2776 atomic_inc(&queue->set_pci_flags_count);
2777 buf->buffer->element[0].flags |= 0x40;
2780 if (!atomic_read(&queue->set_pci_flags_count)) {
2782 * there's no outstanding PCI any more, so we
2783 * have to request a PCI to be sure the the PCI
2784 * will wake at some time in the future then we
2785 * can flush packed buffers that might still be
2786 * hanging around, which can happen if no
2787 * further send was requested by the stack
2789 atomic_inc(&queue->set_pci_flags_count);
2790 buf->buffer->element[0].flags |= 0x40;
2795 queue->card->dev->trans_start = jiffies;
2796 if (queue->card->options.performance_stats) {
2797 queue->card->perf_stats.outbound_do_qdio_cnt++;
2798 queue->card->perf_stats.outbound_do_qdio_start_time =
2801 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
2802 if (atomic_read(&queue->set_pci_flags_count))
2803 qdio_flags |= QDIO_FLAG_PCI_OUT;
2804 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
2805 queue->queue_no, index, count);
2806 if (queue->card->options.performance_stats)
2807 queue->card->perf_stats.outbound_do_qdio_time +=
2809 queue->card->perf_stats.outbound_do_qdio_start_time;
2811 QETH_DBF_TEXT(TRACE, 2, "flushbuf");
2812 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
2813 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_DDEV_ID(queue->card));
2814 queue->card->stats.tx_errors += count;
2815 /* this must not happen under normal circumstances. if it
2816 * happens something is really wrong -> recover */
2817 qeth_schedule_recovery(queue->card);
2820 atomic_add(count, &queue->used_buffers);
2821 if (queue->card->options.performance_stats)
2822 queue->card->perf_stats.bufs_sent += count;
2825 static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2829 int q_was_packing = 0;
2832 * check if weed have to switch to non-packing mode or if
2833 * we have to get a pci flag out on the queue
2835 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2836 !atomic_read(&queue->set_pci_flags_count)) {
2837 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2838 QETH_OUT_Q_UNLOCKED) {
2840 * If we get in here, there was no action in
2841 * do_send_packet. So, we check if there is a
2842 * packing buffer to be flushed here.
2844 netif_stop_queue(queue->card->dev);
2845 index = queue->next_buf_to_fill;
2846 q_was_packing = queue->do_pack;
2847 /* queue->do_pack may change */
2849 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
2851 !atomic_read(&queue->set_pci_flags_count))
2853 qeth_flush_buffers_on_no_pci(queue);
2854 if (queue->card->options.performance_stats &&
2856 queue->card->perf_stats.bufs_sent_pack +=
2859 qeth_flush_buffers(queue, index, flush_cnt);
2860 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
2865 void qeth_qdio_output_handler(struct ccw_device *ccwdev,
2866 unsigned int qdio_error, int __queue, int first_element,
2867 int count, unsigned long card_ptr)
2869 struct qeth_card *card = (struct qeth_card *) card_ptr;
2870 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
2871 struct qeth_qdio_out_buffer *buffer;
2874 QETH_DBF_TEXT(TRACE, 6, "qdouhdl");
2875 if (qdio_error & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
2876 QETH_DBF_TEXT(TRACE, 2, "achkcond");
2877 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
2878 netif_stop_queue(card->dev);
2879 qeth_schedule_recovery(card);
2882 if (card->options.performance_stats) {
2883 card->perf_stats.outbound_handler_cnt++;
2884 card->perf_stats.outbound_handler_start_time =
2887 for (i = first_element; i < (first_element + count); ++i) {
2888 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2889 /*we only handle the KICK_IT error by doing a recovery */
2890 if (qeth_handle_send_error(card, buffer, qdio_error)
2891 == QETH_SEND_ERROR_KICK_IT){
2892 netif_stop_queue(card->dev);
2893 qeth_schedule_recovery(card);
2896 qeth_clear_output_buffer(queue, buffer);
2898 atomic_sub(count, &queue->used_buffers);
2899 /* check if we need to do something on this outbound queue */
2900 if (card->info.type != QETH_CARD_TYPE_IQD)
2901 qeth_check_outbound_queue(queue);
2903 netif_wake_queue(queue->card->dev);
2904 if (card->options.performance_stats)
2905 card->perf_stats.outbound_handler_time += qeth_get_micros() -
2906 card->perf_stats.outbound_handler_start_time;
2908 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler);
2910 int qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2912 int cast_type = RTN_UNSPEC;
2914 if (card->info.type == QETH_CARD_TYPE_OSN)
2917 if (skb->dst && skb->dst->neighbour) {
2918 cast_type = skb->dst->neighbour->type;
2919 if ((cast_type == RTN_BROADCAST) ||
2920 (cast_type == RTN_MULTICAST) ||
2921 (cast_type == RTN_ANYCAST))
2926 /* try something else */
2927 if (skb->protocol == ETH_P_IPV6)
2928 return (skb_network_header(skb)[24] == 0xff) ?
2930 else if (skb->protocol == ETH_P_IP)
2931 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2934 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2935 return RTN_BROADCAST;
2939 hdr_mac = *((u16 *)skb->data);
2941 switch (card->info.link_type) {
2942 case QETH_LINK_TYPE_HSTR:
2943 case QETH_LINK_TYPE_LANE_TR:
2944 if ((hdr_mac == QETH_TR_MAC_NC) ||
2945 (hdr_mac == QETH_TR_MAC_C))
2946 return RTN_MULTICAST;
2948 /* eth or so multicast? */
2950 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2951 (hdr_mac == QETH_ETH_MAC_V6))
2952 return RTN_MULTICAST;
2957 EXPORT_SYMBOL_GPL(qeth_get_cast_type);
2959 int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
2960 int ipv, int cast_type)
2962 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
2963 return card->qdio.default_out_queue;
2964 switch (card->qdio.no_out_queues) {
2966 if (cast_type && card->info.is_multicast_different)
2967 return card->info.is_multicast_different &
2968 (card->qdio.no_out_queues - 1);
2969 if (card->qdio.do_prio_queueing && (ipv == 4)) {
2970 const u8 tos = ip_hdr(skb)->tos;
2972 if (card->qdio.do_prio_queueing ==
2973 QETH_PRIO_Q_ING_TOS) {
2974 if (tos & IP_TOS_NOTIMPORTANT)
2976 if (tos & IP_TOS_HIGHRELIABILITY)
2978 if (tos & IP_TOS_HIGHTHROUGHPUT)
2980 if (tos & IP_TOS_LOWDELAY)
2983 if (card->qdio.do_prio_queueing ==
2984 QETH_PRIO_Q_ING_PREC)
2985 return 3 - (tos >> 6);
2986 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
2989 return card->qdio.default_out_queue;
2990 case 1: /* fallthrough for single-out-queue 1920-device */
2992 return card->qdio.default_out_queue;
2995 EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
2997 int qeth_get_elements_no(struct qeth_card *card, void *hdr,
2998 struct sk_buff *skb, int elems)
3000 int elements_needed = 0;
3002 if (skb_shinfo(skb)->nr_frags > 0)
3003 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
3004 if (elements_needed == 0)
3005 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
3006 + skb->len) >> PAGE_SHIFT);
3007 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
3008 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3009 "(Number=%d / Length=%d). Discarded.\n",
3010 (elements_needed+elems), skb->len);
3013 return elements_needed;
3015 EXPORT_SYMBOL_GPL(qeth_get_elements_no);
3017 static inline void __qeth_fill_buffer(struct sk_buff *skb,
3018 struct qdio_buffer *buffer, int is_tso, int *next_element_to_fill)
3020 int length = skb->len;
3026 element = *next_element_to_fill;
3028 first_lap = (is_tso == 0 ? 1 : 0);
3030 while (length > 0) {
3031 /* length_here is the remaining amount of data in this page */
3032 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
3033 if (length < length_here)
3034 length_here = length;
3036 buffer->element[element].addr = data;
3037 buffer->element[element].length = length_here;
3038 length -= length_here;
3041 buffer->element[element].flags = 0;
3043 buffer->element[element].flags =
3044 SBAL_FLAGS_LAST_FRAG;
3047 buffer->element[element].flags =
3048 SBAL_FLAGS_FIRST_FRAG;
3050 buffer->element[element].flags =
3051 SBAL_FLAGS_MIDDLE_FRAG;
3053 data += length_here;
3057 *next_element_to_fill = element;
3060 static inline int qeth_fill_buffer(struct qeth_qdio_out_q *queue,
3061 struct qeth_qdio_out_buffer *buf, struct sk_buff *skb)
3063 struct qdio_buffer *buffer;
3064 struct qeth_hdr_tso *hdr;
3065 int flush_cnt = 0, hdr_len, large_send = 0;
3067 buffer = buf->buffer;
3068 atomic_inc(&skb->users);
3069 skb_queue_tail(&buf->skb_list, skb);
3071 hdr = (struct qeth_hdr_tso *) skb->data;
3072 /*check first on TSO ....*/
3073 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
3074 int element = buf->next_element_to_fill;
3076 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
3077 /*fill first buffer entry only with header information */
3078 buffer->element[element].addr = skb->data;
3079 buffer->element[element].length = hdr_len;
3080 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
3081 buf->next_element_to_fill++;
3082 skb->data += hdr_len;
3083 skb->len -= hdr_len;
3086 if (skb_shinfo(skb)->nr_frags == 0)
3087 __qeth_fill_buffer(skb, buffer, large_send,
3088 (int *)&buf->next_element_to_fill);
3090 __qeth_fill_buffer_frag(skb, buffer, large_send,
3091 (int *)&buf->next_element_to_fill);
3093 if (!queue->do_pack) {
3094 QETH_DBF_TEXT(TRACE, 6, "fillbfnp");
3095 /* set state to PRIMED -> will be flushed */
3096 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
3099 QETH_DBF_TEXT(TRACE, 6, "fillbfpa");
3100 if (queue->card->options.performance_stats)
3101 queue->card->perf_stats.skbs_sent_pack++;
3102 if (buf->next_element_to_fill >=
3103 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
3105 * packed buffer if full -> set state PRIMED
3106 * -> will be flushed
3108 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
3115 int qeth_do_send_packet_fast(struct qeth_card *card,
3116 struct qeth_qdio_out_q *queue, struct sk_buff *skb,
3117 struct qeth_hdr *hdr, int elements_needed,
3118 struct qeth_eddp_context *ctx)
3120 struct qeth_qdio_out_buffer *buffer;
3121 int buffers_needed = 0;
3125 /* spin until we get the queue ... */
3126 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3127 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
3128 /* ... now we've got the queue */
3129 index = queue->next_buf_to_fill;
3130 buffer = &queue->bufs[queue->next_buf_to_fill];
3132 * check if buffer is empty to make sure that we do not 'overtake'
3133 * ourselves and try to fill a buffer that is already primed
3135 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
3138 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
3139 QDIO_MAX_BUFFERS_PER_Q;
3141 buffers_needed = qeth_eddp_check_buffers_for_context(queue,
3143 if (buffers_needed < 0)
3145 queue->next_buf_to_fill =
3146 (queue->next_buf_to_fill + buffers_needed) %
3147 QDIO_MAX_BUFFERS_PER_Q;
3149 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3151 qeth_fill_buffer(queue, buffer, skb);
3152 qeth_flush_buffers(queue, index, 1);
3154 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
3155 WARN_ON(buffers_needed != flush_cnt);
3156 qeth_flush_buffers(queue, index, flush_cnt);
3160 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3163 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast);
3165 int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
3166 struct sk_buff *skb, struct qeth_hdr *hdr,
3167 int elements_needed, struct qeth_eddp_context *ctx)
3169 struct qeth_qdio_out_buffer *buffer;
3171 int flush_count = 0;
3176 /* spin until we get the queue ... */
3177 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3178 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
3179 start_index = queue->next_buf_to_fill;
3180 buffer = &queue->bufs[queue->next_buf_to_fill];
3182 * check if buffer is empty to make sure that we do not 'overtake'
3183 * ourselves and try to fill a buffer that is already primed
3185 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
3186 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3189 /* check if we need to switch packing state of this queue */
3190 qeth_switch_to_packing_if_needed(queue);
3191 if (queue->do_pack) {
3194 /* does packet fit in current buffer? */
3195 if ((QETH_MAX_BUFFER_ELEMENTS(card) -
3196 buffer->next_element_to_fill) < elements_needed) {
3197 /* ... no -> set state PRIMED */
3198 atomic_set(&buffer->state,
3199 QETH_QDIO_BUF_PRIMED);
3201 queue->next_buf_to_fill =
3202 (queue->next_buf_to_fill + 1) %
3203 QDIO_MAX_BUFFERS_PER_Q;
3204 buffer = &queue->bufs[queue->next_buf_to_fill];
3205 /* we did a step forward, so check buffer state
3207 if (atomic_read(&buffer->state) !=
3208 QETH_QDIO_BUF_EMPTY){
3209 qeth_flush_buffers(queue, start_index,
3211 atomic_set(&queue->state,
3212 QETH_OUT_Q_UNLOCKED);
3217 /* check if we have enough elements (including following
3218 * free buffers) to handle eddp context */
3219 if (qeth_eddp_check_buffers_for_context(queue, ctx)
3227 tmp = qeth_fill_buffer(queue, buffer, skb);
3229 tmp = qeth_eddp_fill_buffer(queue, ctx,
3230 queue->next_buf_to_fill);
3236 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
3237 QDIO_MAX_BUFFERS_PER_Q;
3241 qeth_flush_buffers(queue, start_index, flush_count);
3242 else if (!atomic_read(&queue->set_pci_flags_count))
3243 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
3245 * queue->state will go from LOCKED -> UNLOCKED or from
3246 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
3247 * (switch packing state or flush buffer to get another pci flag out).
3248 * In that case we will enter this loop
3250 while (atomic_dec_return(&queue->state)) {
3252 start_index = queue->next_buf_to_fill;
3253 /* check if we can go back to non-packing state */
3254 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
3256 * check if we need to flush a packing buffer to get a pci
3257 * flag out on the queue
3259 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
3260 flush_count += qeth_flush_buffers_on_no_pci(queue);
3262 qeth_flush_buffers(queue, start_index, flush_count);
3264 /* at this point the queue is UNLOCKED again */
3265 if (queue->card->options.performance_stats && do_pack)
3266 queue->card->perf_stats.bufs_sent_pack += flush_count;
3270 EXPORT_SYMBOL_GPL(qeth_do_send_packet);
3272 static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
3273 struct qeth_reply *reply, unsigned long data)
3275 struct qeth_ipa_cmd *cmd;
3276 struct qeth_ipacmd_setadpparms *setparms;
3278 QETH_DBF_TEXT(TRACE, 4, "prmadpcb");
3280 cmd = (struct qeth_ipa_cmd *) data;
3281 setparms = &(cmd->data.setadapterparms);
3283 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
3284 if (cmd->hdr.return_code) {
3285 QETH_DBF_TEXT_(TRACE, 4, "prmrc%2.2x", cmd->hdr.return_code);
3286 setparms->data.mode = SET_PROMISC_MODE_OFF;
3288 card->info.promisc_mode = setparms->data.mode;
3292 void qeth_setadp_promisc_mode(struct qeth_card *card)
3294 enum qeth_ipa_promisc_modes mode;
3295 struct net_device *dev = card->dev;
3296 struct qeth_cmd_buffer *iob;
3297 struct qeth_ipa_cmd *cmd;
3299 QETH_DBF_TEXT(TRACE, 4, "setprom");
3301 if (((dev->flags & IFF_PROMISC) &&
3302 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
3303 (!(dev->flags & IFF_PROMISC) &&
3304 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
3306 mode = SET_PROMISC_MODE_OFF;
3307 if (dev->flags & IFF_PROMISC)
3308 mode = SET_PROMISC_MODE_ON;
3309 QETH_DBF_TEXT_(TRACE, 4, "mode:%x", mode);
3311 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
3312 sizeof(struct qeth_ipacmd_setadpparms));
3313 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
3314 cmd->data.setadapterparms.data.mode = mode;
3315 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
3317 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode);
3319 int qeth_change_mtu(struct net_device *dev, int new_mtu)
3321 struct qeth_card *card;
3324 card = netdev_priv(dev);
3326 QETH_DBF_TEXT(TRACE, 4, "chgmtu");
3327 sprintf(dbf_text, "%8x", new_mtu);
3328 QETH_DBF_TEXT(TRACE, 4, dbf_text);
3332 if (new_mtu > 65535)
3334 if ((!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) &&
3335 (!qeth_mtu_is_valid(card, new_mtu)))
3340 EXPORT_SYMBOL_GPL(qeth_change_mtu);
3342 struct net_device_stats *qeth_get_stats(struct net_device *dev)
3344 struct qeth_card *card;
3346 card = netdev_priv(dev);
3348 QETH_DBF_TEXT(TRACE, 5, "getstat");
3350 return &card->stats;
3352 EXPORT_SYMBOL_GPL(qeth_get_stats);
3354 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
3355 struct qeth_reply *reply, unsigned long data)
3357 struct qeth_ipa_cmd *cmd;
3359 QETH_DBF_TEXT(TRACE, 4, "chgmaccb");
3361 cmd = (struct qeth_ipa_cmd *) data;
3362 if (!card->options.layer2 ||
3363 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
3364 memcpy(card->dev->dev_addr,
3365 &cmd->data.setadapterparms.data.change_addr.addr,
3367 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
3369 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
3373 int qeth_setadpparms_change_macaddr(struct qeth_card *card)
3376 struct qeth_cmd_buffer *iob;
3377 struct qeth_ipa_cmd *cmd;
3379 QETH_DBF_TEXT(TRACE, 4, "chgmac");
3381 iob = qeth_get_adapter_cmd(card, IPA_SETADP_ALTER_MAC_ADDRESS,
3382 sizeof(struct qeth_ipacmd_setadpparms));
3383 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3384 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
3385 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
3386 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
3387 card->dev->dev_addr, OSA_ADDR_LEN);
3388 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
3392 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
3394 void qeth_tx_timeout(struct net_device *dev)
3396 struct qeth_card *card;
3398 card = netdev_priv(dev);
3399 card->stats.tx_errors++;
3400 qeth_schedule_recovery(card);
3402 EXPORT_SYMBOL_GPL(qeth_tx_timeout);
3404 int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
3406 struct qeth_card *card = netdev_priv(dev);
3410 case MII_BMCR: /* Basic mode control register */
3412 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH) &&
3413 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
3414 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
3415 rc |= BMCR_SPEED100;
3417 case MII_BMSR: /* Basic mode status register */
3418 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
3419 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
3422 case MII_PHYSID1: /* PHYS ID 1 */
3423 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
3425 rc = (rc >> 5) & 0xFFFF;
3427 case MII_PHYSID2: /* PHYS ID 2 */
3428 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
3430 case MII_ADVERTISE: /* Advertisement control reg */
3433 case MII_LPA: /* Link partner ability reg */
3434 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
3435 LPA_100BASE4 | LPA_LPACK;
3437 case MII_EXPANSION: /* Expansion register */
3439 case MII_DCOUNTER: /* disconnect counter */
3441 case MII_FCSCOUNTER: /* false carrier counter */
3443 case MII_NWAYTEST: /* N-way auto-neg test register */
3445 case MII_RERRCOUNTER: /* rx error counter */
3446 rc = card->stats.rx_errors;
3448 case MII_SREVISION: /* silicon revision */
3450 case MII_RESV1: /* reserved 1 */
3452 case MII_LBRERROR: /* loopback, rx, bypass error */
3454 case MII_PHYADDR: /* physical address */
3456 case MII_RESV2: /* reserved 2 */
3458 case MII_TPISTATUS: /* TPI status for 10mbps */
3460 case MII_NCONFIG: /* network interface config */
3467 EXPORT_SYMBOL_GPL(qeth_mdio_read);
3469 static int qeth_send_ipa_snmp_cmd(struct qeth_card *card,
3470 struct qeth_cmd_buffer *iob, int len,
3471 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
3477 QETH_DBF_TEXT(TRACE, 4, "sendsnmp");
3479 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
3480 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
3481 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3482 /* adjust PDU length fields in IPA_PDU_HEADER */
3483 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
3485 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
3486 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
3487 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
3488 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
3489 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
3490 reply_cb, reply_param);
3493 static int qeth_snmp_command_cb(struct qeth_card *card,
3494 struct qeth_reply *reply, unsigned long sdata)
3496 struct qeth_ipa_cmd *cmd;
3497 struct qeth_arp_query_info *qinfo;
3498 struct qeth_snmp_cmd *snmp;
3499 unsigned char *data;
3502 QETH_DBF_TEXT(TRACE, 3, "snpcmdcb");
3504 cmd = (struct qeth_ipa_cmd *) sdata;
3505 data = (unsigned char *)((char *)cmd - reply->offset);
3506 qinfo = (struct qeth_arp_query_info *) reply->param;
3507 snmp = &cmd->data.setadapterparms.data.snmp;
3509 if (cmd->hdr.return_code) {
3510 QETH_DBF_TEXT_(TRACE, 4, "scer1%i", cmd->hdr.return_code);
3513 if (cmd->data.setadapterparms.hdr.return_code) {
3514 cmd->hdr.return_code =
3515 cmd->data.setadapterparms.hdr.return_code;
3516 QETH_DBF_TEXT_(TRACE, 4, "scer2%i", cmd->hdr.return_code);
3519 data_len = *((__u16 *)QETH_IPA_PDU_LEN_PDU1(data));
3520 if (cmd->data.setadapterparms.hdr.seq_no == 1)
3521 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
3523 data_len -= (__u16)((char *)&snmp->request - (char *)cmd);
3525 /* check if there is enough room in userspace */
3526 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
3527 QETH_DBF_TEXT_(TRACE, 4, "scer3%i", -ENOMEM);
3528 cmd->hdr.return_code = -ENOMEM;
3531 QETH_DBF_TEXT_(TRACE, 4, "snore%i",
3532 cmd->data.setadapterparms.hdr.used_total);
3533 QETH_DBF_TEXT_(TRACE, 4, "sseqn%i",
3534 cmd->data.setadapterparms.hdr.seq_no);
3535 /*copy entries to user buffer*/
3536 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
3537 memcpy(qinfo->udata + qinfo->udata_offset,
3539 data_len + offsetof(struct qeth_snmp_cmd, data));
3540 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
3542 memcpy(qinfo->udata + qinfo->udata_offset,
3543 (char *)&snmp->request, data_len);
3545 qinfo->udata_offset += data_len;
3546 /* check if all replies received ... */
3547 QETH_DBF_TEXT_(TRACE, 4, "srtot%i",
3548 cmd->data.setadapterparms.hdr.used_total);
3549 QETH_DBF_TEXT_(TRACE, 4, "srseq%i",
3550 cmd->data.setadapterparms.hdr.seq_no);
3551 if (cmd->data.setadapterparms.hdr.seq_no <
3552 cmd->data.setadapterparms.hdr.used_total)
3557 int qeth_snmp_command(struct qeth_card *card, char __user *udata)
3559 struct qeth_cmd_buffer *iob;
3560 struct qeth_ipa_cmd *cmd;
3561 struct qeth_snmp_ureq *ureq;
3563 struct qeth_arp_query_info qinfo = {0, };
3566 QETH_DBF_TEXT(TRACE, 3, "snmpcmd");
3568 if (card->info.guestlan)
3571 if ((!qeth_adp_supported(card, IPA_SETADP_SET_SNMP_CONTROL)) &&
3572 (!card->options.layer2)) {
3575 /* skip 4 bytes (data_len struct member) to get req_len */
3576 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
3578 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
3580 QETH_DBF_TEXT(TRACE, 2, "snmpnome");
3583 if (copy_from_user(ureq, udata,
3584 req_len + sizeof(struct qeth_snmp_ureq_hdr))) {
3588 qinfo.udata_len = ureq->hdr.data_len;
3589 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
3594 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
3596 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
3597 QETH_SNMP_SETADP_CMDLENGTH + req_len);
3598 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3599 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
3600 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
3601 qeth_snmp_command_cb, (void *)&qinfo);
3603 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
3604 QETH_CARD_IFNAME(card), rc);
3606 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
3614 EXPORT_SYMBOL_GPL(qeth_snmp_command);
3616 static inline int qeth_get_qdio_q_format(struct qeth_card *card)
3618 switch (card->info.type) {
3619 case QETH_CARD_TYPE_IQD:
3626 static int qeth_qdio_establish(struct qeth_card *card)
3628 struct qdio_initialize init_data;
3629 char *qib_param_field;
3630 struct qdio_buffer **in_sbal_ptrs;
3631 struct qdio_buffer **out_sbal_ptrs;
3635 QETH_DBF_TEXT(SETUP, 2, "qdioest");
3637 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3639 if (!qib_param_field)
3642 qeth_create_qib_param_field(card, qib_param_field);
3643 qeth_create_qib_param_field_blkt(card, qib_param_field);
3645 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3647 if (!in_sbal_ptrs) {
3648 kfree(qib_param_field);
3651 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3652 in_sbal_ptrs[i] = (struct qdio_buffer *)
3653 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3656 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3657 sizeof(void *), GFP_KERNEL);
3658 if (!out_sbal_ptrs) {
3659 kfree(in_sbal_ptrs);
3660 kfree(qib_param_field);
3663 for (i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3664 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k) {
3665 out_sbal_ptrs[k] = (struct qdio_buffer *)virt_to_phys(
3666 card->qdio.out_qs[i]->bufs[j].buffer);
3669 memset(&init_data, 0, sizeof(struct qdio_initialize));
3670 init_data.cdev = CARD_DDEV(card);
3671 init_data.q_format = qeth_get_qdio_q_format(card);
3672 init_data.qib_param_field_format = 0;
3673 init_data.qib_param_field = qib_param_field;
3674 init_data.no_input_qs = 1;
3675 init_data.no_output_qs = card->qdio.no_out_queues;
3676 init_data.input_handler = card->discipline.input_handler;
3677 init_data.output_handler = card->discipline.output_handler;
3678 init_data.int_parm = (unsigned long) card;
3679 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3680 QDIO_OUTBOUND_0COPY_SBALS |
3681 QDIO_USE_OUTBOUND_PCIS;
3682 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3683 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3685 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3686 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
3687 rc = qdio_initialize(&init_data);
3689 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3691 kfree(out_sbal_ptrs);
3692 kfree(in_sbal_ptrs);
3693 kfree(qib_param_field);
3697 static void qeth_core_free_card(struct qeth_card *card)
3700 QETH_DBF_TEXT(SETUP, 2, "freecrd");
3701 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
3702 qeth_clean_channel(&card->read);
3703 qeth_clean_channel(&card->write);
3705 free_netdev(card->dev);
3706 kfree(card->ip_tbd_list);
3707 qeth_free_qdio_buffers(card);
3711 static struct ccw_device_id qeth_ids[] = {
3712 {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
3713 {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
3714 {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
3717 MODULE_DEVICE_TABLE(ccw, qeth_ids);
3719 static struct ccw_driver qeth_ccw_driver = {
3722 .probe = ccwgroup_probe_ccwdev,
3723 .remove = ccwgroup_remove_ccwdev,
3726 static int qeth_core_driver_group(const char *buf, struct device *root_dev,
3727 unsigned long driver_id)
3729 return ccwgroup_create_from_string(root_dev, driver_id,
3730 &qeth_ccw_driver, 3, buf);
3733 int qeth_core_hardsetup_card(struct qeth_card *card)
3735 struct qdio_ssqd_desc *qdio_ssqd;
3740 QETH_DBF_TEXT(SETUP, 2, "hrdsetup");
3741 atomic_set(&card->force_alloc_skb, 0);
3744 PRINT_WARN("Retrying to do IDX activates.\n");
3745 ccw_device_set_offline(CARD_DDEV(card));
3746 ccw_device_set_offline(CARD_WDEV(card));
3747 ccw_device_set_offline(CARD_RDEV(card));
3748 ccw_device_set_online(CARD_RDEV(card));
3749 ccw_device_set_online(CARD_WDEV(card));
3750 ccw_device_set_online(CARD_DDEV(card));
3752 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
3753 if (rc == -ERESTARTSYS) {
3754 QETH_DBF_TEXT(SETUP, 2, "break1");
3757 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3764 rc = qeth_get_unitaddr(card);
3766 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3770 qdio_ssqd = qdio_get_ssqd_desc(CARD_DDEV(card));
3772 mpno = qdio_ssqd->pcnt;
3774 mpno = min(mpno - 1, QETH_MAX_PORTNO);
3775 if (card->info.portno > mpno) {
3776 QETH_DBF_MESSAGE(2, "Device %s does not offer port number %d"
3777 "\n.", CARD_BUS_ID(card), card->info.portno);
3781 qeth_init_tokens(card);
3782 qeth_init_func_level(card);
3783 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
3784 if (rc == -ERESTARTSYS) {
3785 QETH_DBF_TEXT(SETUP, 2, "break2");
3788 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
3794 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
3795 if (rc == -ERESTARTSYS) {
3796 QETH_DBF_TEXT(SETUP, 2, "break3");
3799 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
3805 rc = qeth_mpc_initialize(card);
3807 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
3812 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
3815 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card);
3817 static inline int qeth_create_skb_frag(struct qdio_buffer_element *element,
3818 struct sk_buff **pskb, int offset, int *pfrag, int data_len)
3820 struct page *page = virt_to_page(element->addr);
3821 if (*pskb == NULL) {
3822 /* the upper protocol layers assume that there is data in the
3823 * skb itself. Copy a small amount (64 bytes) to make them
3825 *pskb = dev_alloc_skb(64 + ETH_HLEN);
3828 skb_reserve(*pskb, ETH_HLEN);
3829 if (data_len <= 64) {
3830 memcpy(skb_put(*pskb, data_len), element->addr + offset,
3834 memcpy(skb_put(*pskb, 64), element->addr + offset, 64);
3835 skb_fill_page_desc(*pskb, *pfrag, page, offset + 64,
3837 (*pskb)->data_len += data_len - 64;
3838 (*pskb)->len += data_len - 64;
3839 (*pskb)->truesize += data_len - 64;
3844 skb_fill_page_desc(*pskb, *pfrag, page, offset, data_len);
3845 (*pskb)->data_len += data_len;
3846 (*pskb)->len += data_len;
3847 (*pskb)->truesize += data_len;
3853 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
3854 struct qdio_buffer *buffer,
3855 struct qdio_buffer_element **__element, int *__offset,
3856 struct qeth_hdr **hdr)
3858 struct qdio_buffer_element *element = *__element;
3859 int offset = *__offset;
3860 struct sk_buff *skb = NULL;
3868 /* qeth_hdr must not cross element boundaries */
3869 if (element->length < offset + sizeof(struct qeth_hdr)) {
3870 if (qeth_is_last_sbale(element))
3874 if (element->length < sizeof(struct qeth_hdr))
3877 *hdr = element->addr + offset;
3879 offset += sizeof(struct qeth_hdr);
3880 if (card->options.layer2) {
3881 if (card->info.type == QETH_CARD_TYPE_OSN) {
3882 skb_len = (*hdr)->hdr.osn.pdu_length;
3883 headroom = sizeof(struct qeth_hdr);
3885 skb_len = (*hdr)->hdr.l2.pkt_length;
3888 skb_len = (*hdr)->hdr.l3.length;
3889 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3890 (card->info.link_type == QETH_LINK_TYPE_HSTR))
3893 headroom = ETH_HLEN;
3899 if ((skb_len >= card->options.rx_sg_cb) &&
3900 (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
3901 (!atomic_read(&card->force_alloc_skb))) {
3904 skb = dev_alloc_skb(skb_len + headroom);
3908 skb_reserve(skb, headroom);
3911 data_ptr = element->addr + offset;
3913 data_len = min(skb_len, (int)(element->length - offset));
3916 if (qeth_create_skb_frag(element, &skb, offset,
3920 memcpy(skb_put(skb, data_len), data_ptr,
3924 skb_len -= data_len;
3926 if (qeth_is_last_sbale(element)) {
3927 QETH_DBF_TEXT(TRACE, 4, "unexeob");
3928 QETH_DBF_TEXT_(TRACE, 4, "%s",
3930 QETH_DBF_TEXT(QERR, 2, "unexeob");
3931 QETH_DBF_TEXT_(QERR, 2, "%s",
3933 QETH_DBF_HEX(MISC, 4, buffer, sizeof(*buffer));
3934 dev_kfree_skb_any(skb);
3935 card->stats.rx_errors++;
3940 data_ptr = element->addr;
3945 *__element = element;
3947 if (use_rx_sg && card->options.performance_stats) {
3948 card->perf_stats.sg_skbs_rx++;
3949 card->perf_stats.sg_frags_rx += skb_shinfo(skb)->nr_frags;
3953 if (net_ratelimit()) {
3954 QETH_DBF_TEXT(TRACE, 2, "noskbmem");
3955 QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card));
3957 card->stats.rx_dropped++;
3960 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb);
3962 static void qeth_unregister_dbf_views(void)
3965 for (x = 0; x < QETH_DBF_INFOS; x++) {
3966 debug_unregister(qeth_dbf[x].id);
3967 qeth_dbf[x].id = NULL;
3971 void qeth_dbf_longtext(enum qeth_dbf_names dbf_nix, int level, char *fmt, ...)
3973 char dbf_txt_buf[32];
3976 if (level > (qeth_dbf[dbf_nix].id)->level)
3978 va_start(args, fmt);
3979 vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
3981 debug_text_event(qeth_dbf[dbf_nix].id, level, dbf_txt_buf);
3983 EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
3985 static int qeth_register_dbf_views(void)
3990 for (x = 0; x < QETH_DBF_INFOS; x++) {
3991 /* register the areas */
3992 qeth_dbf[x].id = debug_register(qeth_dbf[x].name,
3996 if (qeth_dbf[x].id == NULL) {
3997 qeth_unregister_dbf_views();
4001 /* register a view */
4002 ret = debug_register_view(qeth_dbf[x].id, qeth_dbf[x].view);
4004 qeth_unregister_dbf_views();
4008 /* set a passing level */
4009 debug_set_level(qeth_dbf[x].id, qeth_dbf[x].level);
4015 int qeth_core_load_discipline(struct qeth_card *card,
4016 enum qeth_discipline_id discipline)
4019 switch (discipline) {
4020 case QETH_DISCIPLINE_LAYER3:
4021 card->discipline.ccwgdriver = try_then_request_module(
4022 symbol_get(qeth_l3_ccwgroup_driver),
4025 case QETH_DISCIPLINE_LAYER2:
4026 card->discipline.ccwgdriver = try_then_request_module(
4027 symbol_get(qeth_l2_ccwgroup_driver),
4031 if (!card->discipline.ccwgdriver) {
4032 PRINT_ERR("Support for discipline %d not present\n",
4039 void qeth_core_free_discipline(struct qeth_card *card)
4041 if (card->options.layer2)
4042 symbol_put(qeth_l2_ccwgroup_driver);
4044 symbol_put(qeth_l3_ccwgroup_driver);
4045 card->discipline.ccwgdriver = NULL;
4048 static int qeth_core_probe_device(struct ccwgroup_device *gdev)
4050 struct qeth_card *card;
4053 unsigned long flags;
4055 QETH_DBF_TEXT(SETUP, 2, "probedev");
4058 if (!get_device(dev))
4061 QETH_DBF_TEXT_(SETUP, 2, "%s", gdev->dev.bus_id);
4063 card = qeth_alloc_card();
4065 QETH_DBF_TEXT_(SETUP, 2, "1err%d", -ENOMEM);
4069 card->read.ccwdev = gdev->cdev[0];
4070 card->write.ccwdev = gdev->cdev[1];
4071 card->data.ccwdev = gdev->cdev[2];
4072 dev_set_drvdata(&gdev->dev, card);
4074 gdev->cdev[0]->handler = qeth_irq;
4075 gdev->cdev[1]->handler = qeth_irq;
4076 gdev->cdev[2]->handler = qeth_irq;
4078 rc = qeth_determine_card_type(card);
4080 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
4083 rc = qeth_setup_card(card);
4085 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
4089 if (card->info.type == QETH_CARD_TYPE_OSN) {
4090 rc = qeth_core_create_osn_attributes(dev);
4093 rc = qeth_core_load_discipline(card, QETH_DISCIPLINE_LAYER2);
4095 qeth_core_remove_osn_attributes(dev);
4098 rc = card->discipline.ccwgdriver->probe(card->gdev);
4100 qeth_core_free_discipline(card);
4101 qeth_core_remove_osn_attributes(dev);
4105 rc = qeth_core_create_device_attributes(dev);
4110 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
4111 list_add_tail(&card->list, &qeth_core_card_list.list);
4112 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
4116 qeth_core_free_card(card);
4122 static void qeth_core_remove_device(struct ccwgroup_device *gdev)
4124 unsigned long flags;
4125 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4127 if (card->discipline.ccwgdriver) {
4128 card->discipline.ccwgdriver->remove(gdev);
4129 qeth_core_free_discipline(card);
4132 if (card->info.type == QETH_CARD_TYPE_OSN) {
4133 qeth_core_remove_osn_attributes(&gdev->dev);
4135 qeth_core_remove_device_attributes(&gdev->dev);
4137 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
4138 list_del(&card->list);
4139 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
4140 qeth_core_free_card(card);
4141 dev_set_drvdata(&gdev->dev, NULL);
4142 put_device(&gdev->dev);
4146 static int qeth_core_set_online(struct ccwgroup_device *gdev)
4148 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4152 if (!card->discipline.ccwgdriver) {
4153 if (card->info.type == QETH_CARD_TYPE_IQD)
4154 def_discipline = QETH_DISCIPLINE_LAYER3;
4156 def_discipline = QETH_DISCIPLINE_LAYER2;
4157 rc = qeth_core_load_discipline(card, def_discipline);
4160 rc = card->discipline.ccwgdriver->probe(card->gdev);
4164 rc = card->discipline.ccwgdriver->set_online(gdev);
4169 static int qeth_core_set_offline(struct ccwgroup_device *gdev)
4171 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4172 return card->discipline.ccwgdriver->set_offline(gdev);
4175 static void qeth_core_shutdown(struct ccwgroup_device *gdev)
4177 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
4178 if (card->discipline.ccwgdriver &&
4179 card->discipline.ccwgdriver->shutdown)
4180 card->discipline.ccwgdriver->shutdown(gdev);
4183 static struct ccwgroup_driver qeth_core_ccwgroup_driver = {
4184 .owner = THIS_MODULE,
4186 .driver_id = 0xD8C5E3C8,
4187 .probe = qeth_core_probe_device,
4188 .remove = qeth_core_remove_device,
4189 .set_online = qeth_core_set_online,
4190 .set_offline = qeth_core_set_offline,
4191 .shutdown = qeth_core_shutdown,
4195 qeth_core_driver_group_store(struct device_driver *ddrv, const char *buf,
4199 err = qeth_core_driver_group(buf, qeth_core_root_dev,
4200 qeth_core_ccwgroup_driver.driver_id);
4207 static DRIVER_ATTR(group, 0200, NULL, qeth_core_driver_group_store);
4210 const char str[ETH_GSTRING_LEN];
4211 } qeth_ethtool_stats_keys[] = {
4216 {"tx skbs no packing"},
4217 {"tx buffers no packing"},
4218 {"tx skbs packing"},
4219 {"tx buffers packing"},
4222 /* 10 */{"rx sg skbs"},
4224 {"rx sg page allocs"},
4225 {"tx large kbytes"},
4227 {"tx pk state ch n->p"},
4228 {"tx pk state ch p->n"},
4229 {"tx pk watermark low"},
4230 {"tx pk watermark high"},
4231 {"queue 0 buffer usage"},
4232 /* 20 */{"queue 1 buffer usage"},
4233 {"queue 2 buffer usage"},
4234 {"queue 3 buffer usage"},
4235 {"rx handler time"},
4236 {"rx handler count"},
4237 {"rx do_QDIO time"},
4238 {"rx do_QDIO count"},
4239 {"tx handler time"},
4240 {"tx handler count"},
4242 /* 30 */{"tx count"},
4243 {"tx do_QDIO time"},
4244 {"tx do_QDIO count"},
4247 int qeth_core_get_stats_count(struct net_device *dev)
4249 return (sizeof(qeth_ethtool_stats_keys) / ETH_GSTRING_LEN);
4251 EXPORT_SYMBOL_GPL(qeth_core_get_stats_count);
4253 void qeth_core_get_ethtool_stats(struct net_device *dev,
4254 struct ethtool_stats *stats, u64 *data)
4256 struct qeth_card *card = netdev_priv(dev);
4257 data[0] = card->stats.rx_packets -
4258 card->perf_stats.initial_rx_packets;
4259 data[1] = card->perf_stats.bufs_rec;
4260 data[2] = card->stats.tx_packets -
4261 card->perf_stats.initial_tx_packets;
4262 data[3] = card->perf_stats.bufs_sent;
4263 data[4] = card->stats.tx_packets - card->perf_stats.initial_tx_packets
4264 - card->perf_stats.skbs_sent_pack;
4265 data[5] = card->perf_stats.bufs_sent - card->perf_stats.bufs_sent_pack;
4266 data[6] = card->perf_stats.skbs_sent_pack;
4267 data[7] = card->perf_stats.bufs_sent_pack;
4268 data[8] = card->perf_stats.sg_skbs_sent;
4269 data[9] = card->perf_stats.sg_frags_sent;
4270 data[10] = card->perf_stats.sg_skbs_rx;
4271 data[11] = card->perf_stats.sg_frags_rx;
4272 data[12] = card->perf_stats.sg_alloc_page_rx;
4273 data[13] = (card->perf_stats.large_send_bytes >> 10);
4274 data[14] = card->perf_stats.large_send_cnt;
4275 data[15] = card->perf_stats.sc_dp_p;
4276 data[16] = card->perf_stats.sc_p_dp;
4277 data[17] = QETH_LOW_WATERMARK_PACK;
4278 data[18] = QETH_HIGH_WATERMARK_PACK;
4279 data[19] = atomic_read(&card->qdio.out_qs[0]->used_buffers);
4280 data[20] = (card->qdio.no_out_queues > 1) ?
4281 atomic_read(&card->qdio.out_qs[1]->used_buffers) : 0;
4282 data[21] = (card->qdio.no_out_queues > 2) ?
4283 atomic_read(&card->qdio.out_qs[2]->used_buffers) : 0;
4284 data[22] = (card->qdio.no_out_queues > 3) ?
4285 atomic_read(&card->qdio.out_qs[3]->used_buffers) : 0;
4286 data[23] = card->perf_stats.inbound_time;
4287 data[24] = card->perf_stats.inbound_cnt;
4288 data[25] = card->perf_stats.inbound_do_qdio_time;
4289 data[26] = card->perf_stats.inbound_do_qdio_cnt;
4290 data[27] = card->perf_stats.outbound_handler_time;
4291 data[28] = card->perf_stats.outbound_handler_cnt;
4292 data[29] = card->perf_stats.outbound_time;
4293 data[30] = card->perf_stats.outbound_cnt;
4294 data[31] = card->perf_stats.outbound_do_qdio_time;
4295 data[32] = card->perf_stats.outbound_do_qdio_cnt;
4297 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats);
4299 void qeth_core_get_strings(struct net_device *dev, u32 stringset, u8 *data)
4301 switch (stringset) {
4303 memcpy(data, &qeth_ethtool_stats_keys,
4304 sizeof(qeth_ethtool_stats_keys));
4311 EXPORT_SYMBOL_GPL(qeth_core_get_strings);
4313 void qeth_core_get_drvinfo(struct net_device *dev,
4314 struct ethtool_drvinfo *info)
4316 struct qeth_card *card = netdev_priv(dev);
4317 if (card->options.layer2)
4318 strcpy(info->driver, "qeth_l2");
4320 strcpy(info->driver, "qeth_l3");
4322 strcpy(info->version, "1.0");
4323 strcpy(info->fw_version, card->info.mcl_level);
4324 sprintf(info->bus_info, "%s/%s/%s",
4327 CARD_DDEV_ID(card));
4329 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo);
4331 int qeth_core_ethtool_get_settings(struct net_device *netdev,
4332 struct ethtool_cmd *ecmd)
4334 struct qeth_card *card = netdev_priv(netdev);
4335 enum qeth_link_types link_type;
4337 if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan))
4338 link_type = QETH_LINK_TYPE_10GBIT_ETH;
4340 link_type = card->info.link_type;
4342 ecmd->transceiver = XCVR_INTERNAL;
4343 ecmd->supported = SUPPORTED_Autoneg;
4344 ecmd->advertising = ADVERTISED_Autoneg;
4345 ecmd->duplex = DUPLEX_FULL;
4346 ecmd->autoneg = AUTONEG_ENABLE;
4348 switch (link_type) {
4349 case QETH_LINK_TYPE_FAST_ETH:
4350 case QETH_LINK_TYPE_LANE_ETH100:
4351 ecmd->supported |= SUPPORTED_10baseT_Half |
4352 SUPPORTED_10baseT_Full |
4353 SUPPORTED_100baseT_Half |
4354 SUPPORTED_100baseT_Full |
4356 ecmd->advertising |= ADVERTISED_10baseT_Half |
4357 ADVERTISED_10baseT_Full |
4358 ADVERTISED_100baseT_Half |
4359 ADVERTISED_100baseT_Full |
4361 ecmd->speed = SPEED_100;
4362 ecmd->port = PORT_TP;
4365 case QETH_LINK_TYPE_GBIT_ETH:
4366 case QETH_LINK_TYPE_LANE_ETH1000:
4367 ecmd->supported |= SUPPORTED_10baseT_Half |
4368 SUPPORTED_10baseT_Full |
4369 SUPPORTED_100baseT_Half |
4370 SUPPORTED_100baseT_Full |
4371 SUPPORTED_1000baseT_Half |
4372 SUPPORTED_1000baseT_Full |
4374 ecmd->advertising |= ADVERTISED_10baseT_Half |
4375 ADVERTISED_10baseT_Full |
4376 ADVERTISED_100baseT_Half |
4377 ADVERTISED_100baseT_Full |
4378 ADVERTISED_1000baseT_Half |
4379 ADVERTISED_1000baseT_Full |
4381 ecmd->speed = SPEED_1000;
4382 ecmd->port = PORT_FIBRE;
4385 case QETH_LINK_TYPE_10GBIT_ETH:
4386 ecmd->supported |= SUPPORTED_10baseT_Half |
4387 SUPPORTED_10baseT_Full |
4388 SUPPORTED_100baseT_Half |
4389 SUPPORTED_100baseT_Full |
4390 SUPPORTED_1000baseT_Half |
4391 SUPPORTED_1000baseT_Full |
4392 SUPPORTED_10000baseT_Full |
4394 ecmd->advertising |= ADVERTISED_10baseT_Half |
4395 ADVERTISED_10baseT_Full |
4396 ADVERTISED_100baseT_Half |
4397 ADVERTISED_100baseT_Full |
4398 ADVERTISED_1000baseT_Half |
4399 ADVERTISED_1000baseT_Full |
4400 ADVERTISED_10000baseT_Full |
4402 ecmd->speed = SPEED_10000;
4403 ecmd->port = PORT_FIBRE;
4407 ecmd->supported |= SUPPORTED_10baseT_Half |
4408 SUPPORTED_10baseT_Full |
4410 ecmd->advertising |= ADVERTISED_10baseT_Half |
4411 ADVERTISED_10baseT_Full |
4413 ecmd->speed = SPEED_10;
4414 ecmd->port = PORT_TP;
4419 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings);
4421 static int __init qeth_core_init(void)
4425 PRINT_INFO("loading core functions\n");
4426 INIT_LIST_HEAD(&qeth_core_card_list.list);
4427 rwlock_init(&qeth_core_card_list.rwlock);
4429 rc = qeth_register_dbf_views();
4432 rc = ccw_driver_register(&qeth_ccw_driver);
4435 rc = ccwgroup_driver_register(&qeth_core_ccwgroup_driver);
4438 rc = driver_create_file(&qeth_core_ccwgroup_driver.driver,
4439 &driver_attr_group);
4442 qeth_core_root_dev = s390_root_dev_register("qeth");
4443 rc = IS_ERR(qeth_core_root_dev) ? PTR_ERR(qeth_core_root_dev) : 0;
4449 driver_remove_file(&qeth_core_ccwgroup_driver.driver,
4450 &driver_attr_group);
4452 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
4454 ccw_driver_unregister(&qeth_ccw_driver);
4456 qeth_unregister_dbf_views();
4458 PRINT_ERR("Initialization failed with code %d\n", rc);
4462 static void __exit qeth_core_exit(void)
4464 s390_root_dev_unregister(qeth_core_root_dev);
4465 driver_remove_file(&qeth_core_ccwgroup_driver.driver,
4466 &driver_attr_group);
4467 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
4468 ccw_driver_unregister(&qeth_ccw_driver);
4469 qeth_unregister_dbf_views();
4470 PRINT_INFO("core functions removed\n");
4473 module_init(qeth_core_init);
4474 module_exit(qeth_core_exit);
4475 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
4476 MODULE_DESCRIPTION("qeth core functions");
4477 MODULE_LICENSE("GPL");