1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2007, 2009
4 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
10 #define KMSG_COMPONENT "qeth"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/compat.h>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/log2.h>
22 #include <linux/tcp.h>
23 #include <linux/mii.h>
25 #include <linux/kthread.h>
26 #include <linux/slab.h>
27 #include <linux/if_vlan.h>
28 #include <linux/netdevice.h>
29 #include <linux/netdev_features.h>
30 #include <linux/rcutree.h>
31 #include <linux/skbuff.h>
32 #include <linux/vmalloc.h>
34 #include <net/iucv/af_iucv.h>
35 #include <net/dsfield.h>
38 #include <asm/ebcdic.h>
39 #include <asm/chpid.h>
40 #include <asm/sysinfo.h>
43 #include <asm/ccwdev.h>
44 #include <asm/cpcmd.h>
46 #include "qeth_core.h"
48 struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
49 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
51 [QETH_DBF_SETUP] = {"qeth_setup",
52 8, 1, 8, 5, &debug_hex_ascii_view, NULL},
53 [QETH_DBF_MSG] = {"qeth_msg", 8, 1, 11 * sizeof(long), 3,
54 &debug_sprintf_view, NULL},
55 [QETH_DBF_CTRL] = {"qeth_control",
56 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
58 EXPORT_SYMBOL_GPL(qeth_dbf);
60 struct kmem_cache *qeth_core_header_cache;
61 EXPORT_SYMBOL_GPL(qeth_core_header_cache);
62 static struct kmem_cache *qeth_qdio_outbuf_cache;
64 static struct device *qeth_core_root_dev;
65 static struct dentry *qeth_debugfs_root;
66 static struct lock_class_key qdio_out_skb_queue_key;
68 static void qeth_issue_next_read_cb(struct qeth_card *card,
69 struct qeth_cmd_buffer *iob,
70 unsigned int data_length);
71 static int qeth_qdio_establish(struct qeth_card *);
72 static void qeth_free_qdio_queues(struct qeth_card *card);
73 static void qeth_notify_skbs(struct qeth_qdio_out_q *queue,
74 struct qeth_qdio_out_buffer *buf,
75 enum iucv_tx_notify notification);
77 static void qeth_close_dev_handler(struct work_struct *work)
79 struct qeth_card *card;
81 card = container_of(work, struct qeth_card, close_dev_work);
82 QETH_CARD_TEXT(card, 2, "cldevhdl");
83 ccwgroup_set_offline(card->gdev);
86 static const char *qeth_get_cardname(struct qeth_card *card)
88 if (IS_VM_NIC(card)) {
89 switch (card->info.type) {
90 case QETH_CARD_TYPE_OSD:
91 return " Virtual NIC QDIO";
92 case QETH_CARD_TYPE_IQD:
93 return " Virtual NIC Hiper";
94 case QETH_CARD_TYPE_OSM:
95 return " Virtual NIC QDIO - OSM";
96 case QETH_CARD_TYPE_OSX:
97 return " Virtual NIC QDIO - OSX";
102 switch (card->info.type) {
103 case QETH_CARD_TYPE_OSD:
104 return " OSD Express";
105 case QETH_CARD_TYPE_IQD:
106 return " HiperSockets";
107 case QETH_CARD_TYPE_OSN:
109 case QETH_CARD_TYPE_OSM:
111 case QETH_CARD_TYPE_OSX:
120 /* max length to be returned: 14 */
121 const char *qeth_get_cardname_short(struct qeth_card *card)
123 if (IS_VM_NIC(card)) {
124 switch (card->info.type) {
125 case QETH_CARD_TYPE_OSD:
126 return "Virt.NIC QDIO";
127 case QETH_CARD_TYPE_IQD:
128 return "Virt.NIC Hiper";
129 case QETH_CARD_TYPE_OSM:
130 return "Virt.NIC OSM";
131 case QETH_CARD_TYPE_OSX:
132 return "Virt.NIC OSX";
137 switch (card->info.type) {
138 case QETH_CARD_TYPE_OSD:
139 switch (card->info.link_type) {
140 case QETH_LINK_TYPE_FAST_ETH:
142 case QETH_LINK_TYPE_HSTR:
144 case QETH_LINK_TYPE_GBIT_ETH:
146 case QETH_LINK_TYPE_10GBIT_ETH:
148 case QETH_LINK_TYPE_25GBIT_ETH:
150 case QETH_LINK_TYPE_LANE_ETH100:
151 return "OSD_FE_LANE";
152 case QETH_LINK_TYPE_LANE_TR:
153 return "OSD_TR_LANE";
154 case QETH_LINK_TYPE_LANE_ETH1000:
155 return "OSD_GbE_LANE";
156 case QETH_LINK_TYPE_LANE:
157 return "OSD_ATM_LANE";
159 return "OSD_Express";
161 case QETH_CARD_TYPE_IQD:
162 return "HiperSockets";
163 case QETH_CARD_TYPE_OSN:
165 case QETH_CARD_TYPE_OSM:
167 case QETH_CARD_TYPE_OSX:
176 void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
177 int clear_start_mask)
181 spin_lock_irqsave(&card->thread_mask_lock, flags);
182 card->thread_allowed_mask = threads;
183 if (clear_start_mask)
184 card->thread_start_mask &= threads;
185 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
186 wake_up(&card->wait_q);
188 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads);
190 int qeth_threads_running(struct qeth_card *card, unsigned long threads)
195 spin_lock_irqsave(&card->thread_mask_lock, flags);
196 rc = (card->thread_running_mask & threads);
197 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
200 EXPORT_SYMBOL_GPL(qeth_threads_running);
202 static void qeth_clear_working_pool_list(struct qeth_card *card)
204 struct qeth_buffer_pool_entry *pool_entry, *tmp;
205 struct qeth_qdio_q *queue = card->qdio.in_q;
208 QETH_CARD_TEXT(card, 5, "clwrklst");
209 list_for_each_entry_safe(pool_entry, tmp,
210 &card->qdio.in_buf_pool.entry_list, list)
211 list_del(&pool_entry->list);
216 for (i = 0; i < ARRAY_SIZE(queue->bufs); i++)
217 queue->bufs[i].pool_entry = NULL;
220 static void qeth_free_pool_entry(struct qeth_buffer_pool_entry *entry)
224 for (i = 0; i < ARRAY_SIZE(entry->elements); i++) {
225 if (entry->elements[i])
226 __free_page(entry->elements[i]);
232 static void qeth_free_buffer_pool(struct qeth_card *card)
234 struct qeth_buffer_pool_entry *entry, *tmp;
236 list_for_each_entry_safe(entry, tmp, &card->qdio.init_pool.entry_list,
238 list_del(&entry->init_list);
239 qeth_free_pool_entry(entry);
243 static struct qeth_buffer_pool_entry *qeth_alloc_pool_entry(unsigned int pages)
245 struct qeth_buffer_pool_entry *entry;
248 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
252 for (i = 0; i < pages; i++) {
253 entry->elements[i] = __dev_alloc_page(GFP_KERNEL);
255 if (!entry->elements[i]) {
256 qeth_free_pool_entry(entry);
264 static int qeth_alloc_buffer_pool(struct qeth_card *card)
266 unsigned int buf_elements = QETH_MAX_BUFFER_ELEMENTS(card);
269 QETH_CARD_TEXT(card, 5, "alocpool");
270 for (i = 0; i < card->qdio.init_pool.buf_count; ++i) {
271 struct qeth_buffer_pool_entry *entry;
273 entry = qeth_alloc_pool_entry(buf_elements);
275 qeth_free_buffer_pool(card);
279 list_add(&entry->init_list, &card->qdio.init_pool.entry_list);
284 int qeth_resize_buffer_pool(struct qeth_card *card, unsigned int count)
286 unsigned int buf_elements = QETH_MAX_BUFFER_ELEMENTS(card);
287 struct qeth_qdio_buffer_pool *pool = &card->qdio.init_pool;
288 struct qeth_buffer_pool_entry *entry, *tmp;
289 int delta = count - pool->buf_count;
292 QETH_CARD_TEXT(card, 2, "realcbp");
294 /* Defer until queue is allocated: */
295 if (!card->qdio.in_q)
298 /* Remove entries from the pool: */
300 entry = list_first_entry(&pool->entry_list,
301 struct qeth_buffer_pool_entry,
303 list_del(&entry->init_list);
304 qeth_free_pool_entry(entry);
309 /* Allocate additional entries: */
311 entry = qeth_alloc_pool_entry(buf_elements);
313 list_for_each_entry_safe(entry, tmp, &entries,
315 list_del(&entry->init_list);
316 qeth_free_pool_entry(entry);
322 list_add(&entry->init_list, &entries);
327 list_splice(&entries, &pool->entry_list);
330 card->qdio.in_buf_pool.buf_count = count;
331 pool->buf_count = count;
334 EXPORT_SYMBOL_GPL(qeth_resize_buffer_pool);
336 static void qeth_free_qdio_queue(struct qeth_qdio_q *q)
341 qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
345 static struct qeth_qdio_q *qeth_alloc_qdio_queue(void)
347 struct qeth_qdio_q *q = kzalloc(sizeof(*q), GFP_KERNEL);
353 if (qdio_alloc_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q)) {
358 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
359 q->bufs[i].buffer = q->qdio_bufs[i];
361 QETH_DBF_HEX(SETUP, 2, &q, sizeof(void *));
365 static int qeth_cq_init(struct qeth_card *card)
369 if (card->options.cq == QETH_CQ_ENABLED) {
370 QETH_CARD_TEXT(card, 2, "cqinit");
371 qdio_reset_buffers(card->qdio.c_q->qdio_bufs,
372 QDIO_MAX_BUFFERS_PER_Q);
373 card->qdio.c_q->next_buf_to_init = 127;
374 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT,
375 card->qdio.no_in_queues - 1, 0,
378 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
387 static int qeth_alloc_cq(struct qeth_card *card)
391 if (card->options.cq == QETH_CQ_ENABLED) {
393 struct qdio_outbuf_state *outbuf_states;
395 QETH_CARD_TEXT(card, 2, "cqon");
396 card->qdio.c_q = qeth_alloc_qdio_queue();
397 if (!card->qdio.c_q) {
401 card->qdio.no_in_queues = 2;
402 card->qdio.out_bufstates =
403 kcalloc(card->qdio.no_out_queues *
404 QDIO_MAX_BUFFERS_PER_Q,
405 sizeof(struct qdio_outbuf_state),
407 outbuf_states = card->qdio.out_bufstates;
408 if (outbuf_states == NULL) {
412 for (i = 0; i < card->qdio.no_out_queues; ++i) {
413 card->qdio.out_qs[i]->bufstates = outbuf_states;
414 outbuf_states += QDIO_MAX_BUFFERS_PER_Q;
417 QETH_CARD_TEXT(card, 2, "nocq");
418 card->qdio.c_q = NULL;
419 card->qdio.no_in_queues = 1;
421 QETH_CARD_TEXT_(card, 2, "iqc%d", card->qdio.no_in_queues);
426 qeth_free_qdio_queue(card->qdio.c_q);
427 card->qdio.c_q = NULL;
429 dev_err(&card->gdev->dev, "Failed to create completion queue\n");
433 static void qeth_free_cq(struct qeth_card *card)
435 if (card->qdio.c_q) {
436 --card->qdio.no_in_queues;
437 qeth_free_qdio_queue(card->qdio.c_q);
438 card->qdio.c_q = NULL;
440 kfree(card->qdio.out_bufstates);
441 card->qdio.out_bufstates = NULL;
444 static enum iucv_tx_notify qeth_compute_cq_notification(int sbalf15,
447 enum iucv_tx_notify n;
451 n = delayed ? TX_NOTIFY_DELAYED_OK : TX_NOTIFY_OK;
457 n = delayed ? TX_NOTIFY_DELAYED_UNREACHABLE :
458 TX_NOTIFY_UNREACHABLE;
461 n = delayed ? TX_NOTIFY_DELAYED_GENERALERROR :
462 TX_NOTIFY_GENERALERROR;
469 static void qeth_qdio_handle_aob(struct qeth_card *card,
470 unsigned long phys_aob_addr)
472 enum qeth_qdio_out_buffer_state new_state = QETH_QDIO_BUF_QAOB_OK;
474 struct qeth_qdio_out_buffer *buffer;
475 enum iucv_tx_notify notification;
476 struct qeth_qdio_out_q *queue;
479 aob = (struct qaob *) phys_to_virt(phys_aob_addr);
480 QETH_CARD_TEXT(card, 5, "haob");
481 QETH_CARD_TEXT_(card, 5, "%lx", phys_aob_addr);
482 buffer = (struct qeth_qdio_out_buffer *) aob->user1;
483 QETH_CARD_TEXT_(card, 5, "%lx", aob->user1);
486 QETH_CARD_TEXT_(card, 2, "aorc%02X", aob->aorc);
487 new_state = QETH_QDIO_BUF_QAOB_ERROR;
490 switch (atomic_xchg(&buffer->state, new_state)) {
491 case QETH_QDIO_BUF_PRIMED:
492 /* Faster than TX completion code, let it handle the async
496 case QETH_QDIO_BUF_PENDING:
497 /* TX completion code is active and will handle the async
501 case QETH_QDIO_BUF_NEED_QAOB:
502 /* TX completion code is already finished. */
503 notification = qeth_compute_cq_notification(aob->aorc, 1);
504 qeth_notify_skbs(buffer->q, buffer, notification);
506 /* Free dangling allocations. The attached skbs are handled by
507 * qeth_tx_complete_pending_bufs().
510 i < aob->sb_count && i < QETH_MAX_BUFFER_ELEMENTS(card);
512 void *data = phys_to_virt(aob->sba[i]);
514 if (data && buffer->is_header[i])
515 kmem_cache_free(qeth_core_header_cache, data);
519 atomic_set(&buffer->state, QETH_QDIO_BUF_EMPTY);
520 napi_schedule(&queue->napi);
526 qdio_release_aob(aob);
529 static void qeth_setup_ccw(struct ccw1 *ccw, u8 cmd_code, u8 flags, u32 len,
532 ccw->cmd_code = cmd_code;
533 ccw->flags = flags | CCW_FLAG_SLI;
535 ccw->cda = (__u32) __pa(data);
538 static int __qeth_issue_next_read(struct qeth_card *card)
540 struct qeth_cmd_buffer *iob = card->read_cmd;
541 struct qeth_channel *channel = iob->channel;
542 struct ccw1 *ccw = __ccw_from_cmd(iob);
545 QETH_CARD_TEXT(card, 5, "issnxrd");
546 if (channel->state != CH_STATE_UP)
549 memset(iob->data, 0, iob->length);
550 qeth_setup_ccw(ccw, CCW_CMD_READ, 0, iob->length, iob->data);
551 iob->callback = qeth_issue_next_read_cb;
552 /* keep the cmd alive after completion: */
555 QETH_CARD_TEXT(card, 6, "noirqpnd");
556 rc = ccw_device_start(channel->ccwdev, ccw, (addr_t) iob, 0, 0);
558 channel->active_cmd = iob;
560 QETH_DBF_MESSAGE(2, "error %i on device %x when starting next read ccw!\n",
561 rc, CARD_DEVID(card));
562 qeth_unlock_channel(card, channel);
564 card->read_or_write_problem = 1;
565 qeth_schedule_recovery(card);
570 static int qeth_issue_next_read(struct qeth_card *card)
574 spin_lock_irq(get_ccwdev_lock(CARD_RDEV(card)));
575 ret = __qeth_issue_next_read(card);
576 spin_unlock_irq(get_ccwdev_lock(CARD_RDEV(card)));
581 static void qeth_enqueue_cmd(struct qeth_card *card,
582 struct qeth_cmd_buffer *iob)
584 spin_lock_irq(&card->lock);
585 list_add_tail(&iob->list, &card->cmd_waiter_list);
586 spin_unlock_irq(&card->lock);
589 static void qeth_dequeue_cmd(struct qeth_card *card,
590 struct qeth_cmd_buffer *iob)
592 spin_lock_irq(&card->lock);
593 list_del(&iob->list);
594 spin_unlock_irq(&card->lock);
597 void qeth_notify_cmd(struct qeth_cmd_buffer *iob, int reason)
600 complete(&iob->done);
602 EXPORT_SYMBOL_GPL(qeth_notify_cmd);
604 static void qeth_flush_local_addrs4(struct qeth_card *card)
606 struct qeth_local_addr *addr;
607 struct hlist_node *tmp;
610 spin_lock_irq(&card->local_addrs4_lock);
611 hash_for_each_safe(card->local_addrs4, i, tmp, addr, hnode) {
612 hash_del_rcu(&addr->hnode);
613 kfree_rcu(addr, rcu);
615 spin_unlock_irq(&card->local_addrs4_lock);
618 static void qeth_flush_local_addrs6(struct qeth_card *card)
620 struct qeth_local_addr *addr;
621 struct hlist_node *tmp;
624 spin_lock_irq(&card->local_addrs6_lock);
625 hash_for_each_safe(card->local_addrs6, i, tmp, addr, hnode) {
626 hash_del_rcu(&addr->hnode);
627 kfree_rcu(addr, rcu);
629 spin_unlock_irq(&card->local_addrs6_lock);
632 static void qeth_flush_local_addrs(struct qeth_card *card)
634 qeth_flush_local_addrs4(card);
635 qeth_flush_local_addrs6(card);
638 static void qeth_add_local_addrs4(struct qeth_card *card,
639 struct qeth_ipacmd_local_addrs4 *cmd)
643 if (cmd->addr_length !=
644 sizeof_field(struct qeth_ipacmd_local_addr4, addr)) {
645 dev_err_ratelimited(&card->gdev->dev,
646 "Dropped IPv4 ADD LOCAL ADDR event with bad length %u\n",
651 spin_lock(&card->local_addrs4_lock);
652 for (i = 0; i < cmd->count; i++) {
653 unsigned int key = ipv4_addr_hash(cmd->addrs[i].addr);
654 struct qeth_local_addr *addr;
655 bool duplicate = false;
657 hash_for_each_possible(card->local_addrs4, addr, hnode, key) {
658 if (addr->addr.s6_addr32[3] == cmd->addrs[i].addr) {
667 addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
669 dev_err(&card->gdev->dev,
670 "Failed to allocate local addr object. Traffic to %pI4 might suffer.\n",
671 &cmd->addrs[i].addr);
675 ipv6_addr_set(&addr->addr, 0, 0, 0, cmd->addrs[i].addr);
676 hash_add_rcu(card->local_addrs4, &addr->hnode, key);
678 spin_unlock(&card->local_addrs4_lock);
681 static void qeth_add_local_addrs6(struct qeth_card *card,
682 struct qeth_ipacmd_local_addrs6 *cmd)
686 if (cmd->addr_length !=
687 sizeof_field(struct qeth_ipacmd_local_addr6, addr)) {
688 dev_err_ratelimited(&card->gdev->dev,
689 "Dropped IPv6 ADD LOCAL ADDR event with bad length %u\n",
694 spin_lock(&card->local_addrs6_lock);
695 for (i = 0; i < cmd->count; i++) {
696 u32 key = ipv6_addr_hash(&cmd->addrs[i].addr);
697 struct qeth_local_addr *addr;
698 bool duplicate = false;
700 hash_for_each_possible(card->local_addrs6, addr, hnode, key) {
701 if (ipv6_addr_equal(&addr->addr, &cmd->addrs[i].addr)) {
710 addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
712 dev_err(&card->gdev->dev,
713 "Failed to allocate local addr object. Traffic to %pI6c might suffer.\n",
714 &cmd->addrs[i].addr);
718 addr->addr = cmd->addrs[i].addr;
719 hash_add_rcu(card->local_addrs6, &addr->hnode, key);
721 spin_unlock(&card->local_addrs6_lock);
724 static void qeth_del_local_addrs4(struct qeth_card *card,
725 struct qeth_ipacmd_local_addrs4 *cmd)
729 if (cmd->addr_length !=
730 sizeof_field(struct qeth_ipacmd_local_addr4, addr)) {
731 dev_err_ratelimited(&card->gdev->dev,
732 "Dropped IPv4 DEL LOCAL ADDR event with bad length %u\n",
737 spin_lock(&card->local_addrs4_lock);
738 for (i = 0; i < cmd->count; i++) {
739 struct qeth_ipacmd_local_addr4 *addr = &cmd->addrs[i];
740 unsigned int key = ipv4_addr_hash(addr->addr);
741 struct qeth_local_addr *tmp;
743 hash_for_each_possible(card->local_addrs4, tmp, hnode, key) {
744 if (tmp->addr.s6_addr32[3] == addr->addr) {
745 hash_del_rcu(&tmp->hnode);
751 spin_unlock(&card->local_addrs4_lock);
754 static void qeth_del_local_addrs6(struct qeth_card *card,
755 struct qeth_ipacmd_local_addrs6 *cmd)
759 if (cmd->addr_length !=
760 sizeof_field(struct qeth_ipacmd_local_addr6, addr)) {
761 dev_err_ratelimited(&card->gdev->dev,
762 "Dropped IPv6 DEL LOCAL ADDR event with bad length %u\n",
767 spin_lock(&card->local_addrs6_lock);
768 for (i = 0; i < cmd->count; i++) {
769 struct qeth_ipacmd_local_addr6 *addr = &cmd->addrs[i];
770 u32 key = ipv6_addr_hash(&addr->addr);
771 struct qeth_local_addr *tmp;
773 hash_for_each_possible(card->local_addrs6, tmp, hnode, key) {
774 if (ipv6_addr_equal(&tmp->addr, &addr->addr)) {
775 hash_del_rcu(&tmp->hnode);
781 spin_unlock(&card->local_addrs6_lock);
784 static bool qeth_next_hop_is_local_v4(struct qeth_card *card,
787 struct qeth_local_addr *tmp;
788 bool is_local = false;
792 if (hash_empty(card->local_addrs4))
796 next_hop = qeth_next_hop_v4_rcu(skb, qeth_dst_check_rcu(skb, 4));
797 key = ipv4_addr_hash(next_hop);
799 hash_for_each_possible_rcu(card->local_addrs4, tmp, hnode, key) {
800 if (tmp->addr.s6_addr32[3] == next_hop) {
810 static bool qeth_next_hop_is_local_v6(struct qeth_card *card,
813 struct qeth_local_addr *tmp;
814 struct in6_addr *next_hop;
815 bool is_local = false;
818 if (hash_empty(card->local_addrs6))
822 next_hop = qeth_next_hop_v6_rcu(skb, qeth_dst_check_rcu(skb, 6));
823 key = ipv6_addr_hash(next_hop);
825 hash_for_each_possible_rcu(card->local_addrs6, tmp, hnode, key) {
826 if (ipv6_addr_equal(&tmp->addr, next_hop)) {
836 static int qeth_debugfs_local_addr_show(struct seq_file *m, void *v)
838 struct qeth_card *card = m->private;
839 struct qeth_local_addr *tmp;
843 hash_for_each_rcu(card->local_addrs4, i, tmp, hnode)
844 seq_printf(m, "%pI4\n", &tmp->addr.s6_addr32[3]);
845 hash_for_each_rcu(card->local_addrs6, i, tmp, hnode)
846 seq_printf(m, "%pI6c\n", &tmp->addr);
852 DEFINE_SHOW_ATTRIBUTE(qeth_debugfs_local_addr);
854 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
855 struct qeth_card *card)
857 const char *ipa_name;
858 int com = cmd->hdr.command;
860 ipa_name = qeth_get_ipa_cmd_name(com);
863 QETH_DBF_MESSAGE(2, "IPA: %s(%#x) for device %x returned %#x \"%s\"\n",
864 ipa_name, com, CARD_DEVID(card), rc,
865 qeth_get_ipa_msg(rc));
867 QETH_DBF_MESSAGE(5, "IPA: %s(%#x) for device %x succeeded\n",
868 ipa_name, com, CARD_DEVID(card));
871 static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
872 struct qeth_ipa_cmd *cmd)
874 QETH_CARD_TEXT(card, 5, "chkipad");
876 if (IS_IPA_REPLY(cmd)) {
877 if (cmd->hdr.command != IPA_CMD_SETCCID &&
878 cmd->hdr.command != IPA_CMD_DELCCID &&
879 cmd->hdr.command != IPA_CMD_MODCCID &&
880 cmd->hdr.command != IPA_CMD_SET_DIAG_ASS)
881 qeth_issue_ipa_msg(cmd, cmd->hdr.return_code, card);
885 /* handle unsolicited event: */
886 switch (cmd->hdr.command) {
887 case IPA_CMD_STOPLAN:
888 if (cmd->hdr.return_code == IPA_RC_VEPA_TO_VEB_TRANSITION) {
889 dev_err(&card->gdev->dev,
890 "Interface %s is down because the adjacent port is no longer in reflective relay mode\n",
891 netdev_name(card->dev));
892 schedule_work(&card->close_dev_work);
894 dev_warn(&card->gdev->dev,
895 "The link for interface %s on CHPID 0x%X failed\n",
896 netdev_name(card->dev), card->info.chpid);
897 qeth_issue_ipa_msg(cmd, cmd->hdr.return_code, card);
898 netif_carrier_off(card->dev);
901 case IPA_CMD_STARTLAN:
902 dev_info(&card->gdev->dev,
903 "The link for %s on CHPID 0x%X has been restored\n",
904 netdev_name(card->dev), card->info.chpid);
905 if (card->info.hwtrap)
906 card->info.hwtrap = 2;
907 qeth_schedule_recovery(card);
909 case IPA_CMD_SETBRIDGEPORT_IQD:
910 case IPA_CMD_SETBRIDGEPORT_OSA:
911 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
912 if (card->discipline->control_event_handler(card, cmd))
915 case IPA_CMD_MODCCID:
917 case IPA_CMD_REGISTER_LOCAL_ADDR:
918 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
919 qeth_add_local_addrs4(card, &cmd->data.local_addrs4);
920 else if (cmd->hdr.prot_version == QETH_PROT_IPV6)
921 qeth_add_local_addrs6(card, &cmd->data.local_addrs6);
923 QETH_CARD_TEXT(card, 3, "irla");
925 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
926 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
927 qeth_del_local_addrs4(card, &cmd->data.local_addrs4);
928 else if (cmd->hdr.prot_version == QETH_PROT_IPV6)
929 qeth_del_local_addrs6(card, &cmd->data.local_addrs6);
931 QETH_CARD_TEXT(card, 3, "urla");
934 QETH_DBF_MESSAGE(2, "Received data is IPA but not a reply!\n");
939 static void qeth_clear_ipacmd_list(struct qeth_card *card)
941 struct qeth_cmd_buffer *iob;
944 QETH_CARD_TEXT(card, 4, "clipalst");
946 spin_lock_irqsave(&card->lock, flags);
947 list_for_each_entry(iob, &card->cmd_waiter_list, list)
948 qeth_notify_cmd(iob, -ECANCELED);
949 spin_unlock_irqrestore(&card->lock, flags);
952 static int qeth_check_idx_response(struct qeth_card *card,
953 unsigned char *buffer)
955 QETH_DBF_HEX(CTRL, 2, buffer, QETH_DBF_CTRL_LEN);
956 if ((buffer[2] & QETH_IDX_TERMINATE_MASK) == QETH_IDX_TERMINATE) {
957 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE with cause code %#04x\n",
959 QETH_CARD_TEXT(card, 2, "ckidxres");
960 QETH_CARD_TEXT(card, 2, " idxterm");
961 QETH_CARD_TEXT_(card, 2, "rc%x", buffer[4]);
962 if (buffer[4] == QETH_IDX_TERM_BAD_TRANSPORT ||
963 buffer[4] == QETH_IDX_TERM_BAD_TRANSPORT_VM) {
964 dev_err(&card->gdev->dev,
965 "The device does not support the configured transport mode\n");
966 return -EPROTONOSUPPORT;
973 void qeth_put_cmd(struct qeth_cmd_buffer *iob)
975 if (refcount_dec_and_test(&iob->ref_count)) {
980 EXPORT_SYMBOL_GPL(qeth_put_cmd);
982 static void qeth_release_buffer_cb(struct qeth_card *card,
983 struct qeth_cmd_buffer *iob,
984 unsigned int data_length)
989 static void qeth_cancel_cmd(struct qeth_cmd_buffer *iob, int rc)
991 qeth_notify_cmd(iob, rc);
995 struct qeth_cmd_buffer *qeth_alloc_cmd(struct qeth_channel *channel,
996 unsigned int length, unsigned int ccws,
999 struct qeth_cmd_buffer *iob;
1001 if (length > QETH_BUFSIZE)
1004 iob = kzalloc(sizeof(*iob), GFP_KERNEL);
1008 iob->data = kzalloc(ALIGN(length, 8) + ccws * sizeof(struct ccw1),
1009 GFP_KERNEL | GFP_DMA);
1015 init_completion(&iob->done);
1016 spin_lock_init(&iob->lock);
1017 INIT_LIST_HEAD(&iob->list);
1018 refcount_set(&iob->ref_count, 1);
1019 iob->channel = channel;
1020 iob->timeout = timeout;
1021 iob->length = length;
1024 EXPORT_SYMBOL_GPL(qeth_alloc_cmd);
1026 static void qeth_issue_next_read_cb(struct qeth_card *card,
1027 struct qeth_cmd_buffer *iob,
1028 unsigned int data_length)
1030 struct qeth_cmd_buffer *request = NULL;
1031 struct qeth_ipa_cmd *cmd = NULL;
1032 struct qeth_reply *reply = NULL;
1033 struct qeth_cmd_buffer *tmp;
1034 unsigned long flags;
1037 QETH_CARD_TEXT(card, 4, "sndctlcb");
1038 rc = qeth_check_idx_response(card, iob->data);
1043 qeth_schedule_recovery(card);
1046 qeth_clear_ipacmd_list(card);
1050 cmd = __ipa_reply(iob);
1052 cmd = qeth_check_ipa_data(card, cmd);
1055 if (IS_OSN(card) && card->osn_info.assist_cb &&
1056 cmd->hdr.command != IPA_CMD_STARTLAN) {
1057 card->osn_info.assist_cb(card->dev, cmd);
1062 /* match against pending cmd requests */
1063 spin_lock_irqsave(&card->lock, flags);
1064 list_for_each_entry(tmp, &card->cmd_waiter_list, list) {
1065 if (tmp->match && tmp->match(tmp, iob)) {
1067 /* take the object outside the lock */
1068 qeth_get_cmd(request);
1072 spin_unlock_irqrestore(&card->lock, flags);
1077 reply = &request->reply;
1078 if (!reply->callback) {
1083 spin_lock_irqsave(&request->lock, flags);
1085 /* Bail out when the requestor has already left: */
1088 rc = reply->callback(card, reply, cmd ? (unsigned long)cmd :
1089 (unsigned long)iob);
1090 spin_unlock_irqrestore(&request->lock, flags);
1094 qeth_notify_cmd(request, rc);
1095 qeth_put_cmd(request);
1097 memcpy(&card->seqno.pdu_hdr_ack,
1098 QETH_PDU_HEADER_SEQ_NO(iob->data),
1099 QETH_SEQ_NO_LENGTH);
1100 __qeth_issue_next_read(card);
1105 static int qeth_set_thread_start_bit(struct qeth_card *card,
1106 unsigned long thread)
1108 unsigned long flags;
1111 spin_lock_irqsave(&card->thread_mask_lock, flags);
1112 if (!(card->thread_allowed_mask & thread))
1114 else if (card->thread_start_mask & thread)
1117 card->thread_start_mask |= thread;
1118 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1123 static void qeth_clear_thread_start_bit(struct qeth_card *card,
1124 unsigned long thread)
1126 unsigned long flags;
1128 spin_lock_irqsave(&card->thread_mask_lock, flags);
1129 card->thread_start_mask &= ~thread;
1130 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1131 wake_up(&card->wait_q);
1134 static void qeth_clear_thread_running_bit(struct qeth_card *card,
1135 unsigned long thread)
1137 unsigned long flags;
1139 spin_lock_irqsave(&card->thread_mask_lock, flags);
1140 card->thread_running_mask &= ~thread;
1141 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1142 wake_up_all(&card->wait_q);
1145 static int __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
1147 unsigned long flags;
1150 spin_lock_irqsave(&card->thread_mask_lock, flags);
1151 if (card->thread_start_mask & thread) {
1152 if ((card->thread_allowed_mask & thread) &&
1153 !(card->thread_running_mask & thread)) {
1155 card->thread_start_mask &= ~thread;
1156 card->thread_running_mask |= thread;
1160 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1164 static int qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
1168 wait_event(card->wait_q,
1169 (rc = __qeth_do_run_thread(card, thread)) >= 0);
1173 int qeth_schedule_recovery(struct qeth_card *card)
1177 QETH_CARD_TEXT(card, 2, "startrec");
1179 rc = qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD);
1181 schedule_work(&card->kernel_thread_starter);
1186 static int qeth_get_problem(struct qeth_card *card, struct ccw_device *cdev,
1192 sense = (char *) irb->ecw;
1193 cstat = irb->scsw.cmd.cstat;
1194 dstat = irb->scsw.cmd.dstat;
1196 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
1197 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
1198 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
1199 QETH_CARD_TEXT(card, 2, "CGENCHK");
1200 dev_warn(&cdev->dev, "The qeth device driver "
1201 "failed to recover an error on the device\n");
1202 QETH_DBF_MESSAGE(2, "check on channel %x with dstat=%#x, cstat=%#x\n",
1203 CCW_DEVID(cdev), dstat, cstat);
1204 print_hex_dump(KERN_WARNING, "qeth: irb ", DUMP_PREFIX_OFFSET,
1209 if (dstat & DEV_STAT_UNIT_CHECK) {
1210 if (sense[SENSE_RESETTING_EVENT_BYTE] &
1211 SENSE_RESETTING_EVENT_FLAG) {
1212 QETH_CARD_TEXT(card, 2, "REVIND");
1215 if (sense[SENSE_COMMAND_REJECT_BYTE] &
1216 SENSE_COMMAND_REJECT_FLAG) {
1217 QETH_CARD_TEXT(card, 2, "CMDREJi");
1220 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
1221 QETH_CARD_TEXT(card, 2, "AFFE");
1224 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
1225 QETH_CARD_TEXT(card, 2, "ZEROSEN");
1228 QETH_CARD_TEXT(card, 2, "DGENCHK");
1234 static int qeth_check_irb_error(struct qeth_card *card, struct ccw_device *cdev,
1240 switch (PTR_ERR(irb)) {
1242 QETH_DBF_MESSAGE(2, "i/o-error on channel %x\n",
1244 QETH_CARD_TEXT(card, 2, "ckirberr");
1245 QETH_CARD_TEXT_(card, 2, " rc%d", -EIO);
1248 dev_warn(&cdev->dev, "A hardware operation timed out"
1249 " on the device\n");
1250 QETH_CARD_TEXT(card, 2, "ckirberr");
1251 QETH_CARD_TEXT_(card, 2, " rc%d", -ETIMEDOUT);
1254 QETH_DBF_MESSAGE(2, "unknown error %ld on channel %x\n",
1255 PTR_ERR(irb), CCW_DEVID(cdev));
1256 QETH_CARD_TEXT(card, 2, "ckirberr");
1257 QETH_CARD_TEXT(card, 2, " rc???");
1258 return PTR_ERR(irb);
1262 static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1267 struct qeth_cmd_buffer *iob = NULL;
1268 struct ccwgroup_device *gdev;
1269 struct qeth_channel *channel;
1270 struct qeth_card *card;
1272 /* while we hold the ccwdev lock, this stays valid: */
1273 gdev = dev_get_drvdata(&cdev->dev);
1274 card = dev_get_drvdata(&gdev->dev);
1276 QETH_CARD_TEXT(card, 5, "irq");
1278 if (card->read.ccwdev == cdev) {
1279 channel = &card->read;
1280 QETH_CARD_TEXT(card, 5, "read");
1281 } else if (card->write.ccwdev == cdev) {
1282 channel = &card->write;
1283 QETH_CARD_TEXT(card, 5, "write");
1285 channel = &card->data;
1286 QETH_CARD_TEXT(card, 5, "data");
1290 QETH_CARD_TEXT(card, 5, "irqunsol");
1291 } else if ((addr_t)intparm != (addr_t)channel->active_cmd) {
1292 QETH_CARD_TEXT(card, 5, "irqunexp");
1295 "Received IRQ with intparm %lx, expected %px\n",
1296 intparm, channel->active_cmd);
1297 if (channel->active_cmd)
1298 qeth_cancel_cmd(channel->active_cmd, -EIO);
1300 iob = (struct qeth_cmd_buffer *) (addr_t)intparm;
1303 channel->active_cmd = NULL;
1304 qeth_unlock_channel(card, channel);
1306 rc = qeth_check_irb_error(card, cdev, irb);
1308 /* IO was terminated, free its resources. */
1310 qeth_cancel_cmd(iob, rc);
1314 if (irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC) {
1315 channel->state = CH_STATE_STOPPED;
1316 wake_up(&card->wait_q);
1319 if (irb->scsw.cmd.fctl & SCSW_FCTL_HALT_FUNC) {
1320 channel->state = CH_STATE_HALTED;
1321 wake_up(&card->wait_q);
1324 if (iob && (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC |
1325 SCSW_FCTL_HALT_FUNC))) {
1326 qeth_cancel_cmd(iob, -ECANCELED);
1330 cstat = irb->scsw.cmd.cstat;
1331 dstat = irb->scsw.cmd.dstat;
1333 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
1334 (dstat & DEV_STAT_UNIT_CHECK) ||
1336 if (irb->esw.esw0.erw.cons) {
1337 dev_warn(&channel->ccwdev->dev,
1338 "The qeth device driver failed to recover "
1339 "an error on the device\n");
1340 QETH_DBF_MESSAGE(2, "sense data available on channel %x: cstat %#X dstat %#X\n",
1341 CCW_DEVID(channel->ccwdev), cstat,
1343 print_hex_dump(KERN_WARNING, "qeth: irb ",
1344 DUMP_PREFIX_OFFSET, 16, 1, irb, 32, 1);
1345 print_hex_dump(KERN_WARNING, "qeth: sense data ",
1346 DUMP_PREFIX_OFFSET, 16, 1, irb->ecw, 32, 1);
1349 rc = qeth_get_problem(card, cdev, irb);
1351 card->read_or_write_problem = 1;
1353 qeth_cancel_cmd(iob, rc);
1354 qeth_clear_ipacmd_list(card);
1355 qeth_schedule_recovery(card);
1362 if (irb->scsw.cmd.count > iob->length) {
1363 qeth_cancel_cmd(iob, -EIO);
1367 iob->callback(card, iob,
1368 iob->length - irb->scsw.cmd.count);
1372 static void qeth_notify_skbs(struct qeth_qdio_out_q *q,
1373 struct qeth_qdio_out_buffer *buf,
1374 enum iucv_tx_notify notification)
1376 struct sk_buff *skb;
1378 skb_queue_walk(&buf->skb_list, skb) {
1379 QETH_CARD_TEXT_(q->card, 5, "skbn%d", notification);
1380 QETH_CARD_TEXT_(q->card, 5, "%lx", (long) skb);
1381 if (skb->sk && skb->sk->sk_family == PF_IUCV)
1382 iucv_sk(skb->sk)->sk_txnotify(skb, notification);
1386 static void qeth_tx_complete_buf(struct qeth_qdio_out_buffer *buf, bool error,
1389 struct qeth_qdio_out_q *queue = buf->q;
1390 struct sk_buff *skb;
1393 if (buf->next_element_to_fill == 0)
1396 QETH_TXQ_STAT_INC(queue, bufs);
1397 QETH_TXQ_STAT_ADD(queue, buf_elements, buf->next_element_to_fill);
1399 QETH_TXQ_STAT_ADD(queue, tx_errors, buf->frames);
1401 QETH_TXQ_STAT_ADD(queue, tx_packets, buf->frames);
1402 QETH_TXQ_STAT_ADD(queue, tx_bytes, buf->bytes);
1405 while ((skb = __skb_dequeue(&buf->skb_list)) != NULL) {
1406 unsigned int bytes = qdisc_pkt_len(skb);
1407 bool is_tso = skb_is_gso(skb);
1408 unsigned int packets;
1410 packets = is_tso ? skb_shinfo(skb)->gso_segs : 1;
1412 if (skb->ip_summed == CHECKSUM_PARTIAL)
1413 QETH_TXQ_STAT_ADD(queue, skbs_csum, packets);
1414 if (skb_is_nonlinear(skb))
1415 QETH_TXQ_STAT_INC(queue, skbs_sg);
1417 QETH_TXQ_STAT_INC(queue, skbs_tso);
1418 QETH_TXQ_STAT_ADD(queue, tso_bytes, bytes);
1422 napi_consume_skb(skb, budget);
1426 static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
1427 struct qeth_qdio_out_buffer *buf,
1428 bool error, int budget)
1432 /* is PCI flag set on buffer? */
1433 if (buf->buffer->element[0].sflags & SBAL_SFLAGS0_PCI_REQ)
1434 atomic_dec(&queue->set_pci_flags_count);
1436 qeth_tx_complete_buf(buf, error, budget);
1438 for (i = 0; i < queue->max_elements; ++i) {
1439 void *data = phys_to_virt(buf->buffer->element[i].addr);
1441 if (data && buf->is_header[i])
1442 kmem_cache_free(qeth_core_header_cache, data);
1443 buf->is_header[i] = 0;
1446 qeth_scrub_qdio_buffer(buf->buffer, queue->max_elements);
1447 buf->next_element_to_fill = 0;
1450 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
1453 static void qeth_tx_complete_pending_bufs(struct qeth_card *card,
1454 struct qeth_qdio_out_q *queue,
1457 struct qeth_qdio_out_buffer *buf, *tmp;
1459 list_for_each_entry_safe(buf, tmp, &queue->pending_bufs, list_entry) {
1460 if (drain || atomic_read(&buf->state) == QETH_QDIO_BUF_EMPTY) {
1461 QETH_CARD_TEXT(card, 5, "fp");
1462 QETH_CARD_TEXT_(card, 5, "%lx", (long) buf);
1465 qeth_notify_skbs(queue, buf,
1466 TX_NOTIFY_GENERALERROR);
1467 qeth_tx_complete_buf(buf, drain, 0);
1469 list_del(&buf->list_entry);
1470 kmem_cache_free(qeth_qdio_outbuf_cache, buf);
1475 static void qeth_drain_output_queue(struct qeth_qdio_out_q *q, bool free)
1479 qeth_tx_complete_pending_bufs(q->card, q, true);
1481 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
1485 qeth_clear_output_buffer(q, q->bufs[j], true, 0);
1487 kmem_cache_free(qeth_qdio_outbuf_cache, q->bufs[j]);
1493 static void qeth_drain_output_queues(struct qeth_card *card)
1497 QETH_CARD_TEXT(card, 2, "clearqdbf");
1498 /* clear outbound buffers to free skbs */
1499 for (i = 0; i < card->qdio.no_out_queues; ++i) {
1500 if (card->qdio.out_qs[i])
1501 qeth_drain_output_queue(card->qdio.out_qs[i], false);
1505 static void qeth_osa_set_output_queues(struct qeth_card *card, bool single)
1507 unsigned int max = single ? 1 : card->dev->num_tx_queues;
1509 if (card->qdio.no_out_queues == max)
1512 if (atomic_read(&card->qdio.state) != QETH_QDIO_UNINITIALIZED)
1513 qeth_free_qdio_queues(card);
1515 if (max == 1 && card->qdio.do_prio_queueing != QETH_PRIOQ_DEFAULT)
1516 dev_info(&card->gdev->dev, "Priority Queueing not supported\n");
1518 card->qdio.no_out_queues = max;
1521 static int qeth_update_from_chp_desc(struct qeth_card *card)
1523 struct ccw_device *ccwdev;
1524 struct channel_path_desc_fmt0 *chp_dsc;
1526 QETH_CARD_TEXT(card, 2, "chp_desc");
1528 ccwdev = card->data.ccwdev;
1529 chp_dsc = ccw_device_get_chp_desc(ccwdev, 0);
1533 card->info.func_level = 0x4100 + chp_dsc->desc;
1535 if (IS_OSD(card) || IS_OSX(card))
1536 /* CHPP field bit 6 == 1 -> single queue */
1537 qeth_osa_set_output_queues(card, chp_dsc->chpp & 0x02);
1540 QETH_CARD_TEXT_(card, 2, "nr:%x", card->qdio.no_out_queues);
1541 QETH_CARD_TEXT_(card, 2, "lvl:%02x", card->info.func_level);
1545 static void qeth_init_qdio_info(struct qeth_card *card)
1547 QETH_CARD_TEXT(card, 4, "intqdinf");
1548 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
1549 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1550 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1553 card->qdio.no_in_queues = 1;
1554 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1556 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_HSDEFAULT;
1558 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
1559 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
1560 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
1561 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
1564 static void qeth_set_initial_options(struct qeth_card *card)
1566 card->options.route4.type = NO_ROUTER;
1567 card->options.route6.type = NO_ROUTER;
1568 card->options.isolation = ISOLATION_MODE_NONE;
1569 card->options.cq = QETH_CQ_DISABLED;
1570 card->options.layer = QETH_DISCIPLINE_UNDETERMINED;
1573 static int qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1575 unsigned long flags;
1578 spin_lock_irqsave(&card->thread_mask_lock, flags);
1579 QETH_CARD_TEXT_(card, 4, " %02x%02x%02x",
1580 (u8) card->thread_start_mask,
1581 (u8) card->thread_allowed_mask,
1582 (u8) card->thread_running_mask);
1583 rc = (card->thread_start_mask & thread);
1584 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1588 static int qeth_do_reset(void *data);
1589 static void qeth_start_kernel_thread(struct work_struct *work)
1591 struct task_struct *ts;
1592 struct qeth_card *card = container_of(work, struct qeth_card,
1593 kernel_thread_starter);
1594 QETH_CARD_TEXT(card, 2, "strthrd");
1596 if (card->read.state != CH_STATE_UP &&
1597 card->write.state != CH_STATE_UP)
1599 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD)) {
1600 ts = kthread_run(qeth_do_reset, card, "qeth_recover");
1602 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1603 qeth_clear_thread_running_bit(card,
1604 QETH_RECOVER_THREAD);
1609 static void qeth_buffer_reclaim_work(struct work_struct *);
1610 static void qeth_setup_card(struct qeth_card *card)
1612 QETH_CARD_TEXT(card, 2, "setupcrd");
1614 card->info.type = CARD_RDEV(card)->id.driver_info;
1615 card->state = CARD_STATE_DOWN;
1616 spin_lock_init(&card->lock);
1617 spin_lock_init(&card->thread_mask_lock);
1618 mutex_init(&card->conf_mutex);
1619 mutex_init(&card->discipline_mutex);
1620 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1621 INIT_LIST_HEAD(&card->cmd_waiter_list);
1622 init_waitqueue_head(&card->wait_q);
1623 qeth_set_initial_options(card);
1624 /* IP address takeover */
1625 INIT_LIST_HEAD(&card->ipato.entries);
1626 qeth_init_qdio_info(card);
1627 INIT_DELAYED_WORK(&card->buffer_reclaim_work, qeth_buffer_reclaim_work);
1628 INIT_WORK(&card->close_dev_work, qeth_close_dev_handler);
1629 hash_init(card->rx_mode_addrs);
1630 hash_init(card->local_addrs4);
1631 hash_init(card->local_addrs6);
1632 spin_lock_init(&card->local_addrs4_lock);
1633 spin_lock_init(&card->local_addrs6_lock);
1636 static void qeth_core_sl_print(struct seq_file *m, struct service_level *slr)
1638 struct qeth_card *card = container_of(slr, struct qeth_card,
1639 qeth_service_level);
1640 if (card->info.mcl_level[0])
1641 seq_printf(m, "qeth: %s firmware level %s\n",
1642 CARD_BUS_ID(card), card->info.mcl_level);
1645 static struct qeth_card *qeth_alloc_card(struct ccwgroup_device *gdev)
1647 struct qeth_card *card;
1649 QETH_DBF_TEXT(SETUP, 2, "alloccrd");
1650 card = kzalloc(sizeof(*card), GFP_KERNEL);
1653 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1656 dev_set_drvdata(&gdev->dev, card);
1657 CARD_RDEV(card) = gdev->cdev[0];
1658 CARD_WDEV(card) = gdev->cdev[1];
1659 CARD_DDEV(card) = gdev->cdev[2];
1661 card->event_wq = alloc_ordered_workqueue("%s_event", 0,
1662 dev_name(&gdev->dev));
1663 if (!card->event_wq)
1666 card->read_cmd = qeth_alloc_cmd(&card->read, QETH_BUFSIZE, 1, 0);
1667 if (!card->read_cmd)
1670 card->debugfs = debugfs_create_dir(dev_name(&gdev->dev),
1672 debugfs_create_file("local_addrs", 0400, card->debugfs, card,
1673 &qeth_debugfs_local_addr_fops);
1675 card->qeth_service_level.seq_print = qeth_core_sl_print;
1676 register_service_level(&card->qeth_service_level);
1680 destroy_workqueue(card->event_wq);
1682 dev_set_drvdata(&gdev->dev, NULL);
1688 static int qeth_clear_channel(struct qeth_card *card,
1689 struct qeth_channel *channel)
1693 QETH_CARD_TEXT(card, 3, "clearch");
1694 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
1695 rc = ccw_device_clear(channel->ccwdev, (addr_t)channel->active_cmd);
1696 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
1700 rc = wait_event_interruptible_timeout(card->wait_q,
1701 channel->state == CH_STATE_STOPPED, QETH_TIMEOUT);
1702 if (rc == -ERESTARTSYS)
1704 if (channel->state != CH_STATE_STOPPED)
1706 channel->state = CH_STATE_DOWN;
1710 static int qeth_halt_channel(struct qeth_card *card,
1711 struct qeth_channel *channel)
1715 QETH_CARD_TEXT(card, 3, "haltch");
1716 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
1717 rc = ccw_device_halt(channel->ccwdev, (addr_t)channel->active_cmd);
1718 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
1722 rc = wait_event_interruptible_timeout(card->wait_q,
1723 channel->state == CH_STATE_HALTED, QETH_TIMEOUT);
1724 if (rc == -ERESTARTSYS)
1726 if (channel->state != CH_STATE_HALTED)
1731 static int qeth_stop_channel(struct qeth_channel *channel)
1733 struct ccw_device *cdev = channel->ccwdev;
1736 rc = ccw_device_set_offline(cdev);
1738 spin_lock_irq(get_ccwdev_lock(cdev));
1739 if (channel->active_cmd) {
1740 dev_err(&cdev->dev, "Stopped channel while cmd %px was still active\n",
1741 channel->active_cmd);
1742 channel->active_cmd = NULL;
1744 cdev->handler = NULL;
1745 spin_unlock_irq(get_ccwdev_lock(cdev));
1750 static int qeth_start_channel(struct qeth_channel *channel)
1752 struct ccw_device *cdev = channel->ccwdev;
1755 channel->state = CH_STATE_DOWN;
1756 atomic_set(&channel->irq_pending, 0);
1758 spin_lock_irq(get_ccwdev_lock(cdev));
1759 cdev->handler = qeth_irq;
1760 spin_unlock_irq(get_ccwdev_lock(cdev));
1762 rc = ccw_device_set_online(cdev);
1769 spin_lock_irq(get_ccwdev_lock(cdev));
1770 cdev->handler = NULL;
1771 spin_unlock_irq(get_ccwdev_lock(cdev));
1775 static int qeth_halt_channels(struct qeth_card *card)
1777 int rc1 = 0, rc2 = 0, rc3 = 0;
1779 QETH_CARD_TEXT(card, 3, "haltchs");
1780 rc1 = qeth_halt_channel(card, &card->read);
1781 rc2 = qeth_halt_channel(card, &card->write);
1782 rc3 = qeth_halt_channel(card, &card->data);
1790 static int qeth_clear_channels(struct qeth_card *card)
1792 int rc1 = 0, rc2 = 0, rc3 = 0;
1794 QETH_CARD_TEXT(card, 3, "clearchs");
1795 rc1 = qeth_clear_channel(card, &card->read);
1796 rc2 = qeth_clear_channel(card, &card->write);
1797 rc3 = qeth_clear_channel(card, &card->data);
1805 static int qeth_clear_halt_card(struct qeth_card *card, int halt)
1809 QETH_CARD_TEXT(card, 3, "clhacrd");
1812 rc = qeth_halt_channels(card);
1815 return qeth_clear_channels(card);
1818 static int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
1822 QETH_CARD_TEXT(card, 3, "qdioclr");
1823 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
1824 QETH_QDIO_CLEANING)) {
1825 case QETH_QDIO_ESTABLISHED:
1827 rc = qdio_shutdown(CARD_DDEV(card),
1828 QDIO_FLAG_CLEANUP_USING_HALT);
1830 rc = qdio_shutdown(CARD_DDEV(card),
1831 QDIO_FLAG_CLEANUP_USING_CLEAR);
1833 QETH_CARD_TEXT_(card, 3, "1err%d", rc);
1834 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
1836 case QETH_QDIO_CLEANING:
1841 rc = qeth_clear_halt_card(card, use_halt);
1843 QETH_CARD_TEXT_(card, 3, "2err%d", rc);
1847 static enum qeth_discipline_id qeth_vm_detect_layer(struct qeth_card *card)
1849 enum qeth_discipline_id disc = QETH_DISCIPLINE_UNDETERMINED;
1850 struct diag26c_vnic_resp *response = NULL;
1851 struct diag26c_vnic_req *request = NULL;
1852 struct ccw_dev_id id;
1856 QETH_CARD_TEXT(card, 2, "vmlayer");
1858 cpcmd("QUERY USERID", userid, sizeof(userid), &rc);
1862 request = kzalloc(sizeof(*request), GFP_KERNEL | GFP_DMA);
1863 response = kzalloc(sizeof(*response), GFP_KERNEL | GFP_DMA);
1864 if (!request || !response) {
1869 ccw_device_get_id(CARD_RDEV(card), &id);
1870 request->resp_buf_len = sizeof(*response);
1871 request->resp_version = DIAG26C_VERSION6_VM65918;
1872 request->req_format = DIAG26C_VNIC_INFO;
1874 memcpy(&request->sys_name, userid, 8);
1875 request->devno = id.devno;
1877 QETH_DBF_HEX(CTRL, 2, request, sizeof(*request));
1878 rc = diag26c(request, response, DIAG26C_PORT_VNIC);
1879 QETH_DBF_HEX(CTRL, 2, request, sizeof(*request));
1882 QETH_DBF_HEX(CTRL, 2, response, sizeof(*response));
1884 if (request->resp_buf_len < sizeof(*response) ||
1885 response->version != request->resp_version) {
1890 if (response->protocol == VNIC_INFO_PROT_L2)
1891 disc = QETH_DISCIPLINE_LAYER2;
1892 else if (response->protocol == VNIC_INFO_PROT_L3)
1893 disc = QETH_DISCIPLINE_LAYER3;
1899 QETH_CARD_TEXT_(card, 2, "err%x", rc);
1903 /* Determine whether the device requires a specific layer discipline */
1904 static enum qeth_discipline_id qeth_enforce_discipline(struct qeth_card *card)
1906 enum qeth_discipline_id disc = QETH_DISCIPLINE_UNDETERMINED;
1908 if (IS_OSM(card) || IS_OSN(card))
1909 disc = QETH_DISCIPLINE_LAYER2;
1910 else if (IS_VM_NIC(card))
1911 disc = IS_IQD(card) ? QETH_DISCIPLINE_LAYER3 :
1912 qeth_vm_detect_layer(card);
1915 case QETH_DISCIPLINE_LAYER2:
1916 QETH_CARD_TEXT(card, 3, "force l2");
1918 case QETH_DISCIPLINE_LAYER3:
1919 QETH_CARD_TEXT(card, 3, "force l3");
1922 QETH_CARD_TEXT(card, 3, "force no");
1928 static void qeth_set_blkt_defaults(struct qeth_card *card)
1930 QETH_CARD_TEXT(card, 2, "cfgblkt");
1932 if (card->info.use_v1_blkt) {
1933 card->info.blkt.time_total = 0;
1934 card->info.blkt.inter_packet = 0;
1935 card->info.blkt.inter_packet_jumbo = 0;
1937 card->info.blkt.time_total = 250;
1938 card->info.blkt.inter_packet = 5;
1939 card->info.blkt.inter_packet_jumbo = 15;
1943 static void qeth_idx_init(struct qeth_card *card)
1945 memset(&card->seqno, 0, sizeof(card->seqno));
1947 card->token.issuer_rm_w = 0x00010103UL;
1948 card->token.cm_filter_w = 0x00010108UL;
1949 card->token.cm_connection_w = 0x0001010aUL;
1950 card->token.ulp_filter_w = 0x0001010bUL;
1951 card->token.ulp_connection_w = 0x0001010dUL;
1953 switch (card->info.type) {
1954 case QETH_CARD_TYPE_IQD:
1955 card->info.func_level = QETH_IDX_FUNC_LEVEL_IQD;
1957 case QETH_CARD_TYPE_OSD:
1958 case QETH_CARD_TYPE_OSN:
1959 card->info.func_level = QETH_IDX_FUNC_LEVEL_OSD;
1966 static void qeth_idx_finalize_cmd(struct qeth_card *card,
1967 struct qeth_cmd_buffer *iob)
1969 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data), &card->seqno.trans_hdr,
1970 QETH_SEQ_NO_LENGTH);
1971 if (iob->channel == &card->write)
1972 card->seqno.trans_hdr++;
1975 static int qeth_peer_func_level(int level)
1977 if ((level & 0xff) == 8)
1978 return (level & 0xff) + 0x400;
1979 if (((level >> 8) & 3) == 1)
1980 return (level & 0xff) + 0x200;
1984 static void qeth_mpc_finalize_cmd(struct qeth_card *card,
1985 struct qeth_cmd_buffer *iob)
1987 qeth_idx_finalize_cmd(card, iob);
1989 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1990 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1991 card->seqno.pdu_hdr++;
1992 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1993 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1995 iob->callback = qeth_release_buffer_cb;
1998 static bool qeth_mpc_match_reply(struct qeth_cmd_buffer *iob,
1999 struct qeth_cmd_buffer *reply)
2001 /* MPC cmds are issued strictly in sequence. */
2002 return !IS_IPA(reply->data);
2005 static struct qeth_cmd_buffer *qeth_mpc_alloc_cmd(struct qeth_card *card,
2007 unsigned int data_length)
2009 struct qeth_cmd_buffer *iob;
2011 iob = qeth_alloc_cmd(&card->write, data_length, 1, QETH_TIMEOUT);
2015 memcpy(iob->data, data, data_length);
2016 qeth_setup_ccw(__ccw_from_cmd(iob), CCW_CMD_WRITE, 0, data_length,
2018 iob->finalize = qeth_mpc_finalize_cmd;
2019 iob->match = qeth_mpc_match_reply;
2024 * qeth_send_control_data() - send control command to the card
2025 * @card: qeth_card structure pointer
2026 * @iob: qeth_cmd_buffer pointer
2027 * @reply_cb: callback function pointer
2028 * @cb_card: pointer to the qeth_card structure
2029 * @cb_reply: pointer to the qeth_reply structure
2030 * @cb_cmd: pointer to the original iob for non-IPA
2031 * commands, or to the qeth_ipa_cmd structure
2032 * for the IPA commands.
2033 * @reply_param: private pointer passed to the callback
2035 * Callback function gets called one or more times, with cb_cmd
2036 * pointing to the response returned by the hardware. Callback
2037 * function must return
2038 * > 0 if more reply blocks are expected,
2039 * 0 if the last or only reply block is received, and
2041 * Callback function can get the value of the reply_param pointer from the
2042 * field 'param' of the structure qeth_reply.
2045 static int qeth_send_control_data(struct qeth_card *card,
2046 struct qeth_cmd_buffer *iob,
2047 int (*reply_cb)(struct qeth_card *cb_card,
2048 struct qeth_reply *cb_reply,
2049 unsigned long cb_cmd),
2052 struct qeth_channel *channel = iob->channel;
2053 struct qeth_reply *reply = &iob->reply;
2054 long timeout = iob->timeout;
2057 QETH_CARD_TEXT(card, 2, "sendctl");
2059 reply->callback = reply_cb;
2060 reply->param = reply_param;
2062 timeout = wait_event_interruptible_timeout(card->wait_q,
2063 qeth_trylock_channel(channel),
2067 return (timeout == -ERESTARTSYS) ? -EINTR : -ETIME;
2071 iob->finalize(card, iob);
2072 QETH_DBF_HEX(CTRL, 2, iob->data, min(iob->length, QETH_DBF_CTRL_LEN));
2074 qeth_enqueue_cmd(card, iob);
2076 /* This pairs with iob->callback, and keeps the iob alive after IO: */
2079 QETH_CARD_TEXT(card, 6, "noirqpnd");
2080 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
2081 rc = ccw_device_start_timeout(channel->ccwdev, __ccw_from_cmd(iob),
2082 (addr_t) iob, 0, 0, timeout);
2084 channel->active_cmd = iob;
2085 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
2087 QETH_DBF_MESSAGE(2, "qeth_send_control_data on device %x: ccw_device_start rc = %i\n",
2088 CARD_DEVID(card), rc);
2089 QETH_CARD_TEXT_(card, 2, " err%d", rc);
2090 qeth_dequeue_cmd(card, iob);
2092 qeth_unlock_channel(card, channel);
2096 timeout = wait_for_completion_interruptible_timeout(&iob->done,
2099 rc = (timeout == -ERESTARTSYS) ? -EINTR : -ETIME;
2101 qeth_dequeue_cmd(card, iob);
2104 /* Wait until the callback for a late reply has completed: */
2105 spin_lock_irq(&iob->lock);
2107 /* Zap any callback that's still pending: */
2109 spin_unlock_irq(&iob->lock);
2120 struct qeth_node_desc {
2121 struct node_descriptor nd1;
2122 struct node_descriptor nd2;
2123 struct node_descriptor nd3;
2126 static void qeth_read_conf_data_cb(struct qeth_card *card,
2127 struct qeth_cmd_buffer *iob,
2128 unsigned int data_length)
2130 struct qeth_node_desc *nd = (struct qeth_node_desc *) iob->data;
2134 QETH_CARD_TEXT(card, 2, "cfgunit");
2136 if (data_length < sizeof(*nd)) {
2141 card->info.is_vm_nic = nd->nd1.plant[0] == _ascebc['V'] &&
2142 nd->nd1.plant[1] == _ascebc['M'];
2143 tag = (u8 *)&nd->nd1.tag;
2144 card->info.chpid = tag[0];
2145 card->info.unit_addr2 = tag[1];
2147 tag = (u8 *)&nd->nd2.tag;
2148 card->info.cula = tag[1];
2150 card->info.use_v1_blkt = nd->nd3.model[0] == 0xF0 &&
2151 nd->nd3.model[1] == 0xF0 &&
2152 nd->nd3.model[2] >= 0xF1 &&
2153 nd->nd3.model[2] <= 0xF4;
2156 qeth_notify_cmd(iob, rc);
2160 static int qeth_read_conf_data(struct qeth_card *card)
2162 struct qeth_channel *channel = &card->data;
2163 struct qeth_cmd_buffer *iob;
2166 /* scan for RCD command in extended SenseID data */
2167 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
2168 if (!ciw || ciw->cmd == 0)
2170 if (ciw->count < sizeof(struct qeth_node_desc))
2173 iob = qeth_alloc_cmd(channel, ciw->count, 1, QETH_RCD_TIMEOUT);
2177 iob->callback = qeth_read_conf_data_cb;
2178 qeth_setup_ccw(__ccw_from_cmd(iob), ciw->cmd, 0, iob->length,
2181 return qeth_send_control_data(card, iob, NULL, NULL);
2184 static int qeth_idx_check_activate_response(struct qeth_card *card,
2185 struct qeth_channel *channel,
2186 struct qeth_cmd_buffer *iob)
2190 rc = qeth_check_idx_response(card, iob->data);
2194 if (QETH_IS_IDX_ACT_POS_REPLY(iob->data))
2197 /* negative reply: */
2198 QETH_CARD_TEXT_(card, 2, "idxneg%c",
2199 QETH_IDX_ACT_CAUSE_CODE(iob->data));
2201 switch (QETH_IDX_ACT_CAUSE_CODE(iob->data)) {
2202 case QETH_IDX_ACT_ERR_EXCL:
2203 dev_err(&channel->ccwdev->dev,
2204 "The adapter is used exclusively by another host\n");
2206 case QETH_IDX_ACT_ERR_AUTH:
2207 case QETH_IDX_ACT_ERR_AUTH_USER:
2208 dev_err(&channel->ccwdev->dev,
2209 "Setting the device online failed because of insufficient authorization\n");
2212 QETH_DBF_MESSAGE(2, "IDX_ACTIVATE on channel %x: negative reply\n",
2213 CCW_DEVID(channel->ccwdev));
2218 static void qeth_idx_activate_read_channel_cb(struct qeth_card *card,
2219 struct qeth_cmd_buffer *iob,
2220 unsigned int data_length)
2222 struct qeth_channel *channel = iob->channel;
2226 QETH_CARD_TEXT(card, 2, "idxrdcb");
2228 rc = qeth_idx_check_activate_response(card, channel, iob);
2232 memcpy(&peer_level, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
2233 if (peer_level != qeth_peer_func_level(card->info.func_level)) {
2234 QETH_DBF_MESSAGE(2, "IDX_ACTIVATE on channel %x: function level mismatch (sent: %#x, received: %#x)\n",
2235 CCW_DEVID(channel->ccwdev),
2236 card->info.func_level, peer_level);
2241 memcpy(&card->token.issuer_rm_r,
2242 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
2243 QETH_MPC_TOKEN_LENGTH);
2244 memcpy(&card->info.mcl_level[0],
2245 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
2248 qeth_notify_cmd(iob, rc);
2252 static void qeth_idx_activate_write_channel_cb(struct qeth_card *card,
2253 struct qeth_cmd_buffer *iob,
2254 unsigned int data_length)
2256 struct qeth_channel *channel = iob->channel;
2260 QETH_CARD_TEXT(card, 2, "idxwrcb");
2262 rc = qeth_idx_check_activate_response(card, channel, iob);
2266 memcpy(&peer_level, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
2267 if ((peer_level & ~0x0100) !=
2268 qeth_peer_func_level(card->info.func_level)) {
2269 QETH_DBF_MESSAGE(2, "IDX_ACTIVATE on channel %x: function level mismatch (sent: %#x, received: %#x)\n",
2270 CCW_DEVID(channel->ccwdev),
2271 card->info.func_level, peer_level);
2276 qeth_notify_cmd(iob, rc);
2280 static void qeth_idx_setup_activate_cmd(struct qeth_card *card,
2281 struct qeth_cmd_buffer *iob)
2283 u16 addr = (card->info.cula << 8) + card->info.unit_addr2;
2284 u8 port = ((u8)card->dev->dev_port) | 0x80;
2285 struct ccw1 *ccw = __ccw_from_cmd(iob);
2287 qeth_setup_ccw(&ccw[0], CCW_CMD_WRITE, CCW_FLAG_CC, IDX_ACTIVATE_SIZE,
2289 qeth_setup_ccw(&ccw[1], CCW_CMD_READ, 0, iob->length, iob->data);
2290 iob->finalize = qeth_idx_finalize_cmd;
2292 port |= QETH_IDX_ACT_INVAL_FRAME;
2293 memcpy(QETH_IDX_ACT_PNO(iob->data), &port, 1);
2294 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
2295 &card->token.issuer_rm_w, QETH_MPC_TOKEN_LENGTH);
2296 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
2297 &card->info.func_level, 2);
2298 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &card->info.ddev_devno, 2);
2299 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &addr, 2);
2302 static int qeth_idx_activate_read_channel(struct qeth_card *card)
2304 struct qeth_channel *channel = &card->read;
2305 struct qeth_cmd_buffer *iob;
2308 QETH_CARD_TEXT(card, 2, "idxread");
2310 iob = qeth_alloc_cmd(channel, QETH_BUFSIZE, 2, QETH_TIMEOUT);
2314 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
2315 qeth_idx_setup_activate_cmd(card, iob);
2316 iob->callback = qeth_idx_activate_read_channel_cb;
2318 rc = qeth_send_control_data(card, iob, NULL, NULL);
2322 channel->state = CH_STATE_UP;
2326 static int qeth_idx_activate_write_channel(struct qeth_card *card)
2328 struct qeth_channel *channel = &card->write;
2329 struct qeth_cmd_buffer *iob;
2332 QETH_CARD_TEXT(card, 2, "idxwrite");
2334 iob = qeth_alloc_cmd(channel, QETH_BUFSIZE, 2, QETH_TIMEOUT);
2338 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
2339 qeth_idx_setup_activate_cmd(card, iob);
2340 iob->callback = qeth_idx_activate_write_channel_cb;
2342 rc = qeth_send_control_data(card, iob, NULL, NULL);
2346 channel->state = CH_STATE_UP;
2350 static int qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2353 struct qeth_cmd_buffer *iob;
2355 QETH_CARD_TEXT(card, 2, "cmenblcb");
2357 iob = (struct qeth_cmd_buffer *) data;
2358 memcpy(&card->token.cm_filter_r,
2359 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2360 QETH_MPC_TOKEN_LENGTH);
2364 static int qeth_cm_enable(struct qeth_card *card)
2366 struct qeth_cmd_buffer *iob;
2368 QETH_CARD_TEXT(card, 2, "cmenable");
2370 iob = qeth_mpc_alloc_cmd(card, CM_ENABLE, CM_ENABLE_SIZE);
2374 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2375 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2376 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2377 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2379 return qeth_send_control_data(card, iob, qeth_cm_enable_cb, NULL);
2382 static int qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2385 struct qeth_cmd_buffer *iob;
2387 QETH_CARD_TEXT(card, 2, "cmsetpcb");
2389 iob = (struct qeth_cmd_buffer *) data;
2390 memcpy(&card->token.cm_connection_r,
2391 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2392 QETH_MPC_TOKEN_LENGTH);
2396 static int qeth_cm_setup(struct qeth_card *card)
2398 struct qeth_cmd_buffer *iob;
2400 QETH_CARD_TEXT(card, 2, "cmsetup");
2402 iob = qeth_mpc_alloc_cmd(card, CM_SETUP, CM_SETUP_SIZE);
2406 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2407 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2408 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2409 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2410 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2411 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2412 return qeth_send_control_data(card, iob, qeth_cm_setup_cb, NULL);
2415 static bool qeth_is_supported_link_type(struct qeth_card *card, u8 link_type)
2417 if (link_type == QETH_LINK_TYPE_LANE_TR ||
2418 link_type == QETH_LINK_TYPE_HSTR) {
2419 dev_err(&card->gdev->dev, "Unsupported Token Ring device\n");
2426 static int qeth_update_max_mtu(struct qeth_card *card, unsigned int max_mtu)
2428 struct net_device *dev = card->dev;
2429 unsigned int new_mtu;
2432 /* IQD needs accurate max MTU to set up its RX buffers: */
2435 /* tolerate quirky HW: */
2436 max_mtu = ETH_MAX_MTU;
2441 /* move any device with default MTU to new max MTU: */
2442 new_mtu = (dev->mtu == dev->max_mtu) ? max_mtu : dev->mtu;
2444 /* adjust RX buffer size to new max MTU: */
2445 card->qdio.in_buf_size = max_mtu + 2 * PAGE_SIZE;
2446 if (dev->max_mtu && dev->max_mtu != max_mtu)
2447 qeth_free_qdio_queues(card);
2451 /* default MTUs for first setup: */
2452 else if (IS_LAYER2(card))
2453 new_mtu = ETH_DATA_LEN;
2455 new_mtu = ETH_DATA_LEN - 8; /* allow for LLC + SNAP */
2458 dev->max_mtu = max_mtu;
2459 dev->mtu = min(new_mtu, max_mtu);
2464 static int qeth_get_mtu_outof_framesize(int framesize)
2466 switch (framesize) {
2480 static int qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2483 __u16 mtu, framesize;
2485 struct qeth_cmd_buffer *iob;
2488 QETH_CARD_TEXT(card, 2, "ulpenacb");
2490 iob = (struct qeth_cmd_buffer *) data;
2491 memcpy(&card->token.ulp_filter_r,
2492 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2493 QETH_MPC_TOKEN_LENGTH);
2495 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2496 mtu = qeth_get_mtu_outof_framesize(framesize);
2498 mtu = *(__u16 *)QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data);
2500 *(u16 *)reply->param = mtu;
2502 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2503 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2505 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2506 if (!qeth_is_supported_link_type(card, link_type))
2507 return -EPROTONOSUPPORT;
2510 card->info.link_type = link_type;
2511 QETH_CARD_TEXT_(card, 2, "link%d", card->info.link_type);
2515 static u8 qeth_mpc_select_prot_type(struct qeth_card *card)
2518 return QETH_PROT_OSN2;
2519 return IS_LAYER2(card) ? QETH_PROT_LAYER2 : QETH_PROT_TCPIP;
2522 static int qeth_ulp_enable(struct qeth_card *card)
2524 u8 prot_type = qeth_mpc_select_prot_type(card);
2525 struct qeth_cmd_buffer *iob;
2529 QETH_CARD_TEXT(card, 2, "ulpenabl");
2531 iob = qeth_mpc_alloc_cmd(card, ULP_ENABLE, ULP_ENABLE_SIZE);
2535 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) = (u8) card->dev->dev_port;
2536 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data), &prot_type, 1);
2537 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2538 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2539 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2540 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2541 rc = qeth_send_control_data(card, iob, qeth_ulp_enable_cb, &max_mtu);
2544 return qeth_update_max_mtu(card, max_mtu);
2547 static int qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2550 struct qeth_cmd_buffer *iob;
2552 QETH_CARD_TEXT(card, 2, "ulpstpcb");
2554 iob = (struct qeth_cmd_buffer *) data;
2555 memcpy(&card->token.ulp_connection_r,
2556 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2557 QETH_MPC_TOKEN_LENGTH);
2558 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2560 QETH_CARD_TEXT(card, 2, "olmlimit");
2561 dev_err(&card->gdev->dev, "A connection could not be "
2562 "established because of an OLM limit\n");
2568 static int qeth_ulp_setup(struct qeth_card *card)
2571 struct qeth_cmd_buffer *iob;
2573 QETH_CARD_TEXT(card, 2, "ulpsetup");
2575 iob = qeth_mpc_alloc_cmd(card, ULP_SETUP, ULP_SETUP_SIZE);
2579 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2580 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2581 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2582 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2583 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2584 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2586 memcpy(QETH_ULP_SETUP_CUA(iob->data), &card->info.ddev_devno, 2);
2587 temp = (card->info.cula << 8) + card->info.unit_addr2;
2588 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2589 return qeth_send_control_data(card, iob, qeth_ulp_setup_cb, NULL);
2592 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q *q, int bidx)
2594 struct qeth_qdio_out_buffer *newbuf;
2596 newbuf = kmem_cache_zalloc(qeth_qdio_outbuf_cache, GFP_ATOMIC);
2600 newbuf->buffer = q->qdio_bufs[bidx];
2601 skb_queue_head_init(&newbuf->skb_list);
2602 lockdep_set_class(&newbuf->skb_list.lock, &qdio_out_skb_queue_key);
2604 atomic_set(&newbuf->state, QETH_QDIO_BUF_EMPTY);
2605 q->bufs[bidx] = newbuf;
2609 static void qeth_free_output_queue(struct qeth_qdio_out_q *q)
2614 qeth_drain_output_queue(q, true);
2615 qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
2619 static struct qeth_qdio_out_q *qeth_alloc_output_queue(void)
2621 struct qeth_qdio_out_q *q = kzalloc(sizeof(*q), GFP_KERNEL);
2627 if (qdio_alloc_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q))
2630 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2631 if (qeth_init_qdio_out_buf(q, i))
2639 kmem_cache_free(qeth_qdio_outbuf_cache, q->bufs[--i]);
2640 qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
2646 static void qeth_tx_completion_timer(struct timer_list *timer)
2648 struct qeth_qdio_out_q *queue = from_timer(queue, timer, timer);
2650 napi_schedule(&queue->napi);
2651 QETH_TXQ_STAT_INC(queue, completion_timer);
2654 static int qeth_alloc_qdio_queues(struct qeth_card *card)
2658 QETH_CARD_TEXT(card, 2, "allcqdbf");
2660 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
2661 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
2664 QETH_CARD_TEXT(card, 2, "inq");
2665 card->qdio.in_q = qeth_alloc_qdio_queue();
2666 if (!card->qdio.in_q)
2669 /* inbound buffer pool */
2670 if (qeth_alloc_buffer_pool(card))
2674 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2675 struct qeth_qdio_out_q *queue;
2677 queue = qeth_alloc_output_queue();
2680 QETH_CARD_TEXT_(card, 2, "outq %i", i);
2681 QETH_CARD_HEX(card, 2, &queue, sizeof(void *));
2682 card->qdio.out_qs[i] = queue;
2684 queue->queue_no = i;
2685 INIT_LIST_HEAD(&queue->pending_bufs);
2686 spin_lock_init(&queue->lock);
2687 timer_setup(&queue->timer, qeth_tx_completion_timer, 0);
2688 queue->coalesce_usecs = QETH_TX_COALESCE_USECS;
2689 queue->max_coalesced_frames = QETH_TX_MAX_COALESCED_FRAMES;
2690 queue->priority = QETH_QIB_PQUE_PRIO_DEFAULT;
2694 if (qeth_alloc_cq(card))
2701 qeth_free_output_queue(card->qdio.out_qs[--i]);
2702 card->qdio.out_qs[i] = NULL;
2704 qeth_free_buffer_pool(card);
2706 qeth_free_qdio_queue(card->qdio.in_q);
2707 card->qdio.in_q = NULL;
2709 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
2713 static void qeth_free_qdio_queues(struct qeth_card *card)
2717 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
2718 QETH_QDIO_UNINITIALIZED)
2722 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2723 if (card->qdio.in_q->bufs[j].rx_skb)
2724 dev_kfree_skb_any(card->qdio.in_q->bufs[j].rx_skb);
2726 qeth_free_qdio_queue(card->qdio.in_q);
2727 card->qdio.in_q = NULL;
2728 /* inbound buffer pool */
2729 qeth_free_buffer_pool(card);
2730 /* free outbound qdio_qs */
2731 for (i = 0; i < card->qdio.no_out_queues; i++) {
2732 qeth_free_output_queue(card->qdio.out_qs[i]);
2733 card->qdio.out_qs[i] = NULL;
2737 static void qeth_fill_qib_parms(struct qeth_card *card,
2738 struct qeth_qib_parms *parms)
2740 struct qeth_qdio_out_q *queue;
2743 parms->pcit_magic[0] = 'P';
2744 parms->pcit_magic[1] = 'C';
2745 parms->pcit_magic[2] = 'I';
2746 parms->pcit_magic[3] = 'T';
2747 ASCEBC(parms->pcit_magic, sizeof(parms->pcit_magic));
2748 parms->pcit_a = QETH_PCI_THRESHOLD_A(card);
2749 parms->pcit_b = QETH_PCI_THRESHOLD_B(card);
2750 parms->pcit_c = QETH_PCI_TIMER_VALUE(card);
2752 parms->blkt_magic[0] = 'B';
2753 parms->blkt_magic[1] = 'L';
2754 parms->blkt_magic[2] = 'K';
2755 parms->blkt_magic[3] = 'T';
2756 ASCEBC(parms->blkt_magic, sizeof(parms->blkt_magic));
2757 parms->blkt_total = card->info.blkt.time_total;
2758 parms->blkt_inter_packet = card->info.blkt.inter_packet;
2759 parms->blkt_inter_packet_jumbo = card->info.blkt.inter_packet_jumbo;
2761 /* Prio-queueing implicitly uses the default priorities: */
2762 if (qeth_uses_tx_prio_queueing(card) || card->qdio.no_out_queues == 1)
2765 parms->pque_magic[0] = 'P';
2766 parms->pque_magic[1] = 'Q';
2767 parms->pque_magic[2] = 'U';
2768 parms->pque_magic[3] = 'E';
2769 ASCEBC(parms->pque_magic, sizeof(parms->pque_magic));
2770 parms->pque_order = QETH_QIB_PQUE_ORDER_RR;
2771 parms->pque_units = QETH_QIB_PQUE_UNITS_SBAL;
2773 qeth_for_each_output_queue(card, queue, i)
2774 parms->pque_priority[i] = queue->priority;
2777 static int qeth_qdio_activate(struct qeth_card *card)
2779 QETH_CARD_TEXT(card, 3, "qdioact");
2780 return qdio_activate(CARD_DDEV(card));
2783 static int qeth_dm_act(struct qeth_card *card)
2785 struct qeth_cmd_buffer *iob;
2787 QETH_CARD_TEXT(card, 2, "dmact");
2789 iob = qeth_mpc_alloc_cmd(card, DM_ACT, DM_ACT_SIZE);
2793 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
2794 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2795 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
2796 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2797 return qeth_send_control_data(card, iob, NULL, NULL);
2800 static int qeth_mpc_initialize(struct qeth_card *card)
2804 QETH_CARD_TEXT(card, 2, "mpcinit");
2806 rc = qeth_issue_next_read(card);
2808 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
2811 rc = qeth_cm_enable(card);
2813 QETH_CARD_TEXT_(card, 2, "2err%d", rc);
2816 rc = qeth_cm_setup(card);
2818 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
2821 rc = qeth_ulp_enable(card);
2823 QETH_CARD_TEXT_(card, 2, "4err%d", rc);
2826 rc = qeth_ulp_setup(card);
2828 QETH_CARD_TEXT_(card, 2, "5err%d", rc);
2831 rc = qeth_alloc_qdio_queues(card);
2833 QETH_CARD_TEXT_(card, 2, "5err%d", rc);
2836 rc = qeth_qdio_establish(card);
2838 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
2839 qeth_free_qdio_queues(card);
2842 rc = qeth_qdio_activate(card);
2844 QETH_CARD_TEXT_(card, 2, "7err%d", rc);
2847 rc = qeth_dm_act(card);
2849 QETH_CARD_TEXT_(card, 2, "8err%d", rc);
2856 static void qeth_print_status_message(struct qeth_card *card)
2858 switch (card->info.type) {
2859 case QETH_CARD_TYPE_OSD:
2860 case QETH_CARD_TYPE_OSM:
2861 case QETH_CARD_TYPE_OSX:
2862 /* VM will use a non-zero first character
2863 * to indicate a HiperSockets like reporting
2864 * of the level OSA sets the first character to zero
2866 if (!card->info.mcl_level[0]) {
2867 sprintf(card->info.mcl_level, "%02x%02x",
2868 card->info.mcl_level[2],
2869 card->info.mcl_level[3]);
2873 case QETH_CARD_TYPE_IQD:
2874 if (IS_VM_NIC(card) || (card->info.mcl_level[0] & 0x80)) {
2875 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
2876 card->info.mcl_level[0]];
2877 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
2878 card->info.mcl_level[1]];
2879 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
2880 card->info.mcl_level[2]];
2881 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
2882 card->info.mcl_level[3]];
2883 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2887 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
2889 dev_info(&card->gdev->dev,
2890 "Device is a%s card%s%s%s\nwith link type %s.\n",
2891 qeth_get_cardname(card),
2892 (card->info.mcl_level[0]) ? " (level: " : "",
2893 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2894 (card->info.mcl_level[0]) ? ")" : "",
2895 qeth_get_cardname_short(card));
2898 static void qeth_initialize_working_pool_list(struct qeth_card *card)
2900 struct qeth_buffer_pool_entry *entry;
2902 QETH_CARD_TEXT(card, 5, "inwrklst");
2904 list_for_each_entry(entry,
2905 &card->qdio.init_pool.entry_list, init_list) {
2906 qeth_put_buffer_pool_entry(card, entry);
2910 static struct qeth_buffer_pool_entry *qeth_find_free_buffer_pool_entry(
2911 struct qeth_card *card)
2913 struct qeth_buffer_pool_entry *entry;
2916 if (list_empty(&card->qdio.in_buf_pool.entry_list))
2919 list_for_each_entry(entry, &card->qdio.in_buf_pool.entry_list, list) {
2921 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2922 if (page_count(entry->elements[i]) > 1) {
2928 list_del_init(&entry->list);
2933 /* no free buffer in pool so take first one and swap pages */
2934 entry = list_first_entry(&card->qdio.in_buf_pool.entry_list,
2935 struct qeth_buffer_pool_entry, list);
2936 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2937 if (page_count(entry->elements[i]) > 1) {
2938 struct page *page = dev_alloc_page();
2943 __free_page(entry->elements[i]);
2944 entry->elements[i] = page;
2945 QETH_CARD_STAT_INC(card, rx_sg_alloc_page);
2948 list_del_init(&entry->list);
2952 static int qeth_init_input_buffer(struct qeth_card *card,
2953 struct qeth_qdio_buffer *buf)
2955 struct qeth_buffer_pool_entry *pool_entry = buf->pool_entry;
2958 if ((card->options.cq == QETH_CQ_ENABLED) && (!buf->rx_skb)) {
2959 buf->rx_skb = netdev_alloc_skb(card->dev,
2961 sizeof(struct ipv6hdr));
2967 pool_entry = qeth_find_free_buffer_pool_entry(card);
2971 buf->pool_entry = pool_entry;
2975 * since the buffer is accessed only from the input_tasklet
2976 * there shouldn't be a need to synchronize; also, since we use
2977 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2980 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2981 buf->buffer->element[i].length = PAGE_SIZE;
2982 buf->buffer->element[i].addr =
2983 page_to_phys(pool_entry->elements[i]);
2984 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2985 buf->buffer->element[i].eflags = SBAL_EFLAGS_LAST_ENTRY;
2987 buf->buffer->element[i].eflags = 0;
2988 buf->buffer->element[i].sflags = 0;
2993 static unsigned int qeth_tx_select_bulk_max(struct qeth_card *card,
2994 struct qeth_qdio_out_q *queue)
2996 if (!IS_IQD(card) ||
2997 qeth_iqd_is_mcast_queue(card, queue) ||
2998 card->options.cq == QETH_CQ_ENABLED ||
2999 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd))
3002 return card->ssqd.mmwc ? card->ssqd.mmwc : 1;
3005 static int qeth_init_qdio_queues(struct qeth_card *card)
3007 unsigned int rx_bufs = card->qdio.in_buf_pool.buf_count;
3011 QETH_CARD_TEXT(card, 2, "initqdqs");
3014 qdio_reset_buffers(card->qdio.in_q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
3015 memset(&card->rx, 0, sizeof(struct qeth_rx));
3017 qeth_initialize_working_pool_list(card);
3018 /*give only as many buffers to hardware as we have buffer pool entries*/
3019 for (i = 0; i < rx_bufs; i++) {
3020 rc = qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3025 card->qdio.in_q->next_buf_to_init = QDIO_BUFNR(rx_bufs);
3026 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0, rx_bufs);
3028 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
3033 rc = qeth_cq_init(card);
3038 /* outbound queue */
3039 for (i = 0; i < card->qdio.no_out_queues; ++i) {
3040 struct qeth_qdio_out_q *queue = card->qdio.out_qs[i];
3042 qdio_reset_buffers(queue->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
3043 queue->max_elements = QETH_MAX_BUFFER_ELEMENTS(card);
3044 queue->next_buf_to_fill = 0;
3046 queue->prev_hdr = NULL;
3047 queue->coalesced_frames = 0;
3048 queue->bulk_start = 0;
3049 queue->bulk_count = 0;
3050 queue->bulk_max = qeth_tx_select_bulk_max(card, queue);
3051 atomic_set(&queue->used_buffers, 0);
3052 atomic_set(&queue->set_pci_flags_count, 0);
3053 netdev_tx_reset_queue(netdev_get_tx_queue(card->dev, i));
3058 static void qeth_ipa_finalize_cmd(struct qeth_card *card,
3059 struct qeth_cmd_buffer *iob)
3061 qeth_mpc_finalize_cmd(card, iob);
3063 /* override with IPA-specific values: */
3064 __ipa_cmd(iob)->hdr.seqno = card->seqno.ipa++;
3067 void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
3069 bool (*match)(struct qeth_cmd_buffer *iob,
3070 struct qeth_cmd_buffer *reply))
3072 u8 prot_type = qeth_mpc_select_prot_type(card);
3073 u16 total_length = iob->length;
3075 qeth_setup_ccw(__ccw_from_cmd(iob), CCW_CMD_WRITE, 0, total_length,
3077 iob->finalize = qeth_ipa_finalize_cmd;
3080 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
3081 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &total_length, 2);
3082 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data), &prot_type, 1);
3083 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &cmd_length, 2);
3084 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &cmd_length, 2);
3085 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
3086 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3087 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &cmd_length, 2);
3089 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd);
3091 static bool qeth_ipa_match_reply(struct qeth_cmd_buffer *iob,
3092 struct qeth_cmd_buffer *reply)
3094 struct qeth_ipa_cmd *ipa_reply = __ipa_reply(reply);
3096 return ipa_reply && (__ipa_cmd(iob)->hdr.seqno == ipa_reply->hdr.seqno);
3099 struct qeth_cmd_buffer *qeth_ipa_alloc_cmd(struct qeth_card *card,
3100 enum qeth_ipa_cmds cmd_code,
3101 enum qeth_prot_versions prot,
3102 unsigned int data_length)
3104 struct qeth_cmd_buffer *iob;
3105 struct qeth_ipacmd_hdr *hdr;
3107 data_length += offsetof(struct qeth_ipa_cmd, data);
3108 iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_length, 1,
3113 qeth_prepare_ipa_cmd(card, iob, data_length, qeth_ipa_match_reply);
3115 hdr = &__ipa_cmd(iob)->hdr;
3116 hdr->command = cmd_code;
3117 hdr->initiator = IPA_CMD_INITIATOR_HOST;
3118 /* hdr->seqno is set by qeth_send_control_data() */
3119 hdr->adapter_type = QETH_LINK_TYPE_FAST_ETH;
3120 hdr->rel_adapter_no = (u8) card->dev->dev_port;
3121 hdr->prim_version_no = IS_LAYER2(card) ? 2 : 1;
3122 hdr->param_count = 1;
3123 hdr->prot_version = prot;
3126 EXPORT_SYMBOL_GPL(qeth_ipa_alloc_cmd);
3128 static int qeth_send_ipa_cmd_cb(struct qeth_card *card,
3129 struct qeth_reply *reply, unsigned long data)
3131 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3133 return (cmd->hdr.return_code) ? -EIO : 0;
3137 * qeth_send_ipa_cmd() - send an IPA command
3139 * See qeth_send_control_data() for explanation of the arguments.
3142 int qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
3143 int (*reply_cb)(struct qeth_card *, struct qeth_reply*,
3149 QETH_CARD_TEXT(card, 4, "sendipa");
3151 if (card->read_or_write_problem) {
3156 if (reply_cb == NULL)
3157 reply_cb = qeth_send_ipa_cmd_cb;
3158 rc = qeth_send_control_data(card, iob, reply_cb, reply_param);
3160 qeth_clear_ipacmd_list(card);
3161 qeth_schedule_recovery(card);
3165 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd);
3167 static int qeth_send_startlan_cb(struct qeth_card *card,
3168 struct qeth_reply *reply, unsigned long data)
3170 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3172 if (cmd->hdr.return_code == IPA_RC_LAN_OFFLINE)
3175 return (cmd->hdr.return_code) ? -EIO : 0;
3178 static int qeth_send_startlan(struct qeth_card *card)
3180 struct qeth_cmd_buffer *iob;
3182 QETH_CARD_TEXT(card, 2, "strtlan");
3184 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_STARTLAN, QETH_PROT_NONE, 0);
3187 return qeth_send_ipa_cmd(card, iob, qeth_send_startlan_cb, NULL);
3190 static int qeth_setadpparms_inspect_rc(struct qeth_ipa_cmd *cmd)
3192 if (!cmd->hdr.return_code)
3193 cmd->hdr.return_code =
3194 cmd->data.setadapterparms.hdr.return_code;
3195 return cmd->hdr.return_code;
3198 static int qeth_query_setadapterparms_cb(struct qeth_card *card,
3199 struct qeth_reply *reply, unsigned long data)
3201 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3202 struct qeth_query_cmds_supp *query_cmd;
3204 QETH_CARD_TEXT(card, 3, "quyadpcb");
3205 if (qeth_setadpparms_inspect_rc(cmd))
3208 query_cmd = &cmd->data.setadapterparms.data.query_cmds_supp;
3209 if (query_cmd->lan_type & 0x7f) {
3210 if (!qeth_is_supported_link_type(card, query_cmd->lan_type))
3211 return -EPROTONOSUPPORT;
3213 card->info.link_type = query_cmd->lan_type;
3214 QETH_CARD_TEXT_(card, 2, "lnk %d", card->info.link_type);
3217 card->options.adp.supported = query_cmd->supported_cmds;
3221 static struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
3222 enum qeth_ipa_setadp_cmd adp_cmd,
3223 unsigned int data_length)
3225 struct qeth_ipacmd_setadpparms_hdr *hdr;
3226 struct qeth_cmd_buffer *iob;
3228 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SETADAPTERPARMS, QETH_PROT_IPV4,
3230 offsetof(struct qeth_ipacmd_setadpparms,
3235 hdr = &__ipa_cmd(iob)->data.setadapterparms.hdr;
3236 hdr->cmdlength = sizeof(*hdr) + data_length;
3237 hdr->command_code = adp_cmd;
3238 hdr->used_total = 1;
3243 static int qeth_query_setadapterparms(struct qeth_card *card)
3246 struct qeth_cmd_buffer *iob;
3248 QETH_CARD_TEXT(card, 3, "queryadp");
3249 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
3250 SETADP_DATA_SIZEOF(query_cmds_supp));
3253 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
3257 static int qeth_query_ipassists_cb(struct qeth_card *card,
3258 struct qeth_reply *reply, unsigned long data)
3260 struct qeth_ipa_cmd *cmd;
3262 QETH_CARD_TEXT(card, 2, "qipasscb");
3264 cmd = (struct qeth_ipa_cmd *) data;
3266 switch (cmd->hdr.return_code) {
3267 case IPA_RC_SUCCESS:
3269 case IPA_RC_NOTSUPP:
3270 case IPA_RC_L2_UNSUPPORTED_CMD:
3271 QETH_CARD_TEXT(card, 2, "ipaunsup");
3272 card->options.ipa4.supported |= IPA_SETADAPTERPARMS;
3273 card->options.ipa6.supported |= IPA_SETADAPTERPARMS;
3276 QETH_DBF_MESSAGE(1, "IPA_CMD_QIPASSIST on device %x: Unhandled rc=%#x\n",
3277 CARD_DEVID(card), cmd->hdr.return_code);
3281 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
3282 card->options.ipa4 = cmd->hdr.assists;
3283 else if (cmd->hdr.prot_version == QETH_PROT_IPV6)
3284 card->options.ipa6 = cmd->hdr.assists;
3286 QETH_DBF_MESSAGE(1, "IPA_CMD_QIPASSIST on device %x: Flawed LIC detected\n",
3291 static int qeth_query_ipassists(struct qeth_card *card,
3292 enum qeth_prot_versions prot)
3295 struct qeth_cmd_buffer *iob;
3297 QETH_CARD_TEXT_(card, 2, "qipassi%i", prot);
3298 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_QIPASSIST, prot, 0);
3301 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
3305 static int qeth_query_switch_attributes_cb(struct qeth_card *card,
3306 struct qeth_reply *reply, unsigned long data)
3308 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3309 struct qeth_query_switch_attributes *attrs;
3310 struct qeth_switch_info *sw_info;
3312 QETH_CARD_TEXT(card, 2, "qswiatcb");
3313 if (qeth_setadpparms_inspect_rc(cmd))
3316 sw_info = (struct qeth_switch_info *)reply->param;
3317 attrs = &cmd->data.setadapterparms.data.query_switch_attributes;
3318 sw_info->capabilities = attrs->capabilities;
3319 sw_info->settings = attrs->settings;
3320 QETH_CARD_TEXT_(card, 2, "%04x%04x", sw_info->capabilities,
3325 int qeth_query_switch_attributes(struct qeth_card *card,
3326 struct qeth_switch_info *sw_info)
3328 struct qeth_cmd_buffer *iob;
3330 QETH_CARD_TEXT(card, 2, "qswiattr");
3331 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES))
3333 if (!netif_carrier_ok(card->dev))
3335 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES, 0);
3338 return qeth_send_ipa_cmd(card, iob,
3339 qeth_query_switch_attributes_cb, sw_info);
3342 struct qeth_cmd_buffer *qeth_get_diag_cmd(struct qeth_card *card,
3343 enum qeth_diags_cmds sub_cmd,
3344 unsigned int data_length)
3346 struct qeth_ipacmd_diagass *cmd;
3347 struct qeth_cmd_buffer *iob;
3349 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SET_DIAG_ASS, QETH_PROT_NONE,
3350 DIAG_HDR_LEN + data_length);
3354 cmd = &__ipa_cmd(iob)->data.diagass;
3355 cmd->subcmd_len = DIAG_SUB_HDR_LEN + data_length;
3356 cmd->subcmd = sub_cmd;
3359 EXPORT_SYMBOL_GPL(qeth_get_diag_cmd);
3361 static int qeth_query_setdiagass_cb(struct qeth_card *card,
3362 struct qeth_reply *reply, unsigned long data)
3364 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3365 u16 rc = cmd->hdr.return_code;
3368 QETH_CARD_TEXT_(card, 2, "diagq:%x", rc);
3372 card->info.diagass_support = cmd->data.diagass.ext;
3376 static int qeth_query_setdiagass(struct qeth_card *card)
3378 struct qeth_cmd_buffer *iob;
3380 QETH_CARD_TEXT(card, 2, "qdiagass");
3381 iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_QUERY, 0);
3384 return qeth_send_ipa_cmd(card, iob, qeth_query_setdiagass_cb, NULL);
3387 static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
3389 unsigned long info = get_zeroed_page(GFP_KERNEL);
3390 struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
3391 struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
3392 struct ccw_dev_id ccwid;
3395 tid->chpid = card->info.chpid;
3396 ccw_device_get_id(CARD_RDEV(card), &ccwid);
3397 tid->ssid = ccwid.ssid;
3398 tid->devno = ccwid.devno;
3401 level = stsi(NULL, 0, 0, 0);
3402 if ((level >= 2) && (stsi(info222, 2, 2, 2) == 0))
3403 tid->lparnr = info222->lpar_number;
3404 if ((level >= 3) && (stsi(info322, 3, 2, 2) == 0)) {
3405 EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
3406 memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
3411 static int qeth_hw_trap_cb(struct qeth_card *card,
3412 struct qeth_reply *reply, unsigned long data)
3414 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3415 u16 rc = cmd->hdr.return_code;
3418 QETH_CARD_TEXT_(card, 2, "trapc:%x", rc);
3424 int qeth_hw_trap(struct qeth_card *card, enum qeth_diags_trap_action action)
3426 struct qeth_cmd_buffer *iob;
3427 struct qeth_ipa_cmd *cmd;
3429 QETH_CARD_TEXT(card, 2, "diagtrap");
3430 iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_TRAP, 64);
3433 cmd = __ipa_cmd(iob);
3434 cmd->data.diagass.type = 1;
3435 cmd->data.diagass.action = action;
3437 case QETH_DIAGS_TRAP_ARM:
3438 cmd->data.diagass.options = 0x0003;
3439 cmd->data.diagass.ext = 0x00010000 +
3440 sizeof(struct qeth_trap_id);
3441 qeth_get_trap_id(card,
3442 (struct qeth_trap_id *)cmd->data.diagass.cdata);
3444 case QETH_DIAGS_TRAP_DISARM:
3445 cmd->data.diagass.options = 0x0001;
3447 case QETH_DIAGS_TRAP_CAPTURE:
3450 return qeth_send_ipa_cmd(card, iob, qeth_hw_trap_cb, NULL);
3453 static int qeth_check_qdio_errors(struct qeth_card *card,
3454 struct qdio_buffer *buf,
3455 unsigned int qdio_error,
3456 const char *dbftext)
3459 QETH_CARD_TEXT(card, 2, dbftext);
3460 QETH_CARD_TEXT_(card, 2, " F15=%02X",
3461 buf->element[15].sflags);
3462 QETH_CARD_TEXT_(card, 2, " F14=%02X",
3463 buf->element[14].sflags);
3464 QETH_CARD_TEXT_(card, 2, " qerr=%X", qdio_error);
3465 if ((buf->element[15].sflags) == 0x12) {
3466 QETH_CARD_STAT_INC(card, rx_fifo_errors);
3474 static unsigned int qeth_rx_refill_queue(struct qeth_card *card,
3477 struct qeth_qdio_q *queue = card->qdio.in_q;
3478 struct list_head *lh;
3483 /* only requeue at a certain threshold to avoid SIGAs */
3484 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)) {
3485 for (i = queue->next_buf_to_init;
3486 i < queue->next_buf_to_init + count; ++i) {
3487 if (qeth_init_input_buffer(card,
3488 &queue->bufs[QDIO_BUFNR(i)])) {
3495 if (newcount < count) {
3496 /* we are in memory shortage so we switch back to
3497 traditional skb allocation and drop packages */
3498 atomic_set(&card->force_alloc_skb, 3);
3501 atomic_add_unless(&card->force_alloc_skb, -1, 0);
3506 list_for_each(lh, &card->qdio.in_buf_pool.entry_list)
3508 if (i == card->qdio.in_buf_pool.buf_count) {
3509 QETH_CARD_TEXT(card, 2, "qsarbw");
3510 schedule_delayed_work(
3511 &card->buffer_reclaim_work,
3512 QETH_RECLAIM_WORK_TIME);
3517 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0,
3518 queue->next_buf_to_init, count);
3520 QETH_CARD_TEXT(card, 2, "qinberr");
3522 queue->next_buf_to_init = QDIO_BUFNR(queue->next_buf_to_init +
3530 static void qeth_buffer_reclaim_work(struct work_struct *work)
3532 struct qeth_card *card = container_of(to_delayed_work(work),
3534 buffer_reclaim_work);
3537 napi_schedule(&card->napi);
3538 /* kick-start the NAPI softirq: */
3542 static void qeth_handle_send_error(struct qeth_card *card,
3543 struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err)
3545 int sbalf15 = buffer->buffer->element[15].sflags;
3547 QETH_CARD_TEXT(card, 6, "hdsnderr");
3548 qeth_check_qdio_errors(card, buffer->buffer, qdio_err, "qouterr");
3553 if ((sbalf15 >= 15) && (sbalf15 <= 31))
3556 QETH_CARD_TEXT(card, 1, "lnkfail");
3557 QETH_CARD_TEXT_(card, 1, "%04x %02x",
3558 (u16)qdio_err, (u8)sbalf15);
3562 * qeth_prep_flush_pack_buffer - Prepares flushing of a packing buffer.
3563 * @queue: queue to check for packing buffer
3565 * Returns number of buffers that were prepared for flush.
3567 static int qeth_prep_flush_pack_buffer(struct qeth_qdio_out_q *queue)
3569 struct qeth_qdio_out_buffer *buffer;
3571 buffer = queue->bufs[queue->next_buf_to_fill];
3572 if ((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
3573 (buffer->next_element_to_fill > 0)) {
3574 /* it's a packing buffer */
3575 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
3576 queue->next_buf_to_fill =
3577 QDIO_BUFNR(queue->next_buf_to_fill + 1);
3584 * Switched to packing state if the number of used buffers on a queue
3585 * reaches a certain limit.
3587 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
3589 if (!queue->do_pack) {
3590 if (atomic_read(&queue->used_buffers)
3591 >= QETH_HIGH_WATERMARK_PACK){
3592 /* switch non-PACKING -> PACKING */
3593 QETH_CARD_TEXT(queue->card, 6, "np->pack");
3594 QETH_TXQ_STAT_INC(queue, packing_mode_switch);
3601 * Switches from packing to non-packing mode. If there is a packing
3602 * buffer on the queue this buffer will be prepared to be flushed.
3603 * In that case 1 is returned to inform the caller. If no buffer
3604 * has to be flushed, zero is returned.
3606 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
3608 if (queue->do_pack) {
3609 if (atomic_read(&queue->used_buffers)
3610 <= QETH_LOW_WATERMARK_PACK) {
3611 /* switch PACKING -> non-PACKING */
3612 QETH_CARD_TEXT(queue->card, 6, "pack->np");
3613 QETH_TXQ_STAT_INC(queue, packing_mode_switch);
3615 return qeth_prep_flush_pack_buffer(queue);
3621 static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
3624 struct qeth_qdio_out_buffer *buf = queue->bufs[index];
3625 unsigned int qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
3626 struct qeth_card *card = queue->card;
3630 for (i = index; i < index + count; ++i) {
3631 unsigned int bidx = QDIO_BUFNR(i);
3632 struct sk_buff *skb;
3634 buf = queue->bufs[bidx];
3635 buf->buffer->element[buf->next_element_to_fill - 1].eflags |=
3636 SBAL_EFLAGS_LAST_ENTRY;
3637 queue->coalesced_frames += buf->frames;
3639 if (queue->bufstates)
3640 queue->bufstates[bidx].user = buf;
3643 skb_queue_walk(&buf->skb_list, skb)
3644 skb_tx_timestamp(skb);
3648 if (!IS_IQD(card)) {
3649 if (!queue->do_pack) {
3650 if ((atomic_read(&queue->used_buffers) >=
3651 (QETH_HIGH_WATERMARK_PACK -
3652 QETH_WATERMARK_PACK_FUZZ)) &&
3653 !atomic_read(&queue->set_pci_flags_count)) {
3654 /* it's likely that we'll go to packing
3656 atomic_inc(&queue->set_pci_flags_count);
3657 buf->buffer->element[0].sflags |= SBAL_SFLAGS0_PCI_REQ;
3660 if (!atomic_read(&queue->set_pci_flags_count)) {
3662 * there's no outstanding PCI any more, so we
3663 * have to request a PCI to be sure the the PCI
3664 * will wake at some time in the future then we
3665 * can flush packed buffers that might still be
3666 * hanging around, which can happen if no
3667 * further send was requested by the stack
3669 atomic_inc(&queue->set_pci_flags_count);
3670 buf->buffer->element[0].sflags |= SBAL_SFLAGS0_PCI_REQ;
3674 if (atomic_read(&queue->set_pci_flags_count))
3675 qdio_flags |= QDIO_FLAG_PCI_OUT;
3678 QETH_TXQ_STAT_INC(queue, doorbell);
3679 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
3680 queue->queue_no, index, count);
3682 /* Fake the TX completion interrupt: */
3684 unsigned int frames = READ_ONCE(queue->max_coalesced_frames);
3685 unsigned int usecs = READ_ONCE(queue->coalesce_usecs);
3687 if (frames && queue->coalesced_frames >= frames) {
3688 napi_schedule(&queue->napi);
3689 queue->coalesced_frames = 0;
3690 QETH_TXQ_STAT_INC(queue, coal_frames);
3692 qeth_tx_arm_timer(queue, usecs);
3697 /* ignore temporary SIGA errors without busy condition */
3700 QETH_CARD_TEXT(queue->card, 2, "flushbuf");
3701 QETH_CARD_TEXT_(queue->card, 2, " q%d", queue->queue_no);
3702 QETH_CARD_TEXT_(queue->card, 2, " idx%d", index);
3703 QETH_CARD_TEXT_(queue->card, 2, " c%d", count);
3704 QETH_CARD_TEXT_(queue->card, 2, " err%d", rc);
3706 /* this must not happen under normal circumstances. if it
3707 * happens something is really wrong -> recover */
3708 qeth_schedule_recovery(queue->card);
3713 static void qeth_flush_queue(struct qeth_qdio_out_q *queue)
3715 qeth_flush_buffers(queue, queue->bulk_start, queue->bulk_count);
3717 queue->bulk_start = QDIO_BUFNR(queue->bulk_start + queue->bulk_count);
3718 queue->prev_hdr = NULL;
3719 queue->bulk_count = 0;
3722 static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
3725 * check if weed have to switch to non-packing mode or if
3726 * we have to get a pci flag out on the queue
3728 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
3729 !atomic_read(&queue->set_pci_flags_count)) {
3730 unsigned int index, flush_cnt;
3733 spin_lock(&queue->lock);
3735 index = queue->next_buf_to_fill;
3736 q_was_packing = queue->do_pack;
3738 flush_cnt = qeth_switch_to_nonpacking_if_needed(queue);
3739 if (!flush_cnt && !atomic_read(&queue->set_pci_flags_count))
3740 flush_cnt = qeth_prep_flush_pack_buffer(queue);
3743 qeth_flush_buffers(queue, index, flush_cnt);
3745 QETH_TXQ_STAT_ADD(queue, bufs_pack, flush_cnt);
3748 spin_unlock(&queue->lock);
3752 static void qeth_qdio_poll(struct ccw_device *cdev, unsigned long card_ptr)
3754 struct qeth_card *card = (struct qeth_card *)card_ptr;
3756 napi_schedule_irqoff(&card->napi);
3759 int qeth_configure_cq(struct qeth_card *card, enum qeth_cq cq)
3763 if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
3767 if (card->options.cq == cq) {
3772 qeth_free_qdio_queues(card);
3773 card->options.cq = cq;
3780 EXPORT_SYMBOL_GPL(qeth_configure_cq);
3782 static void qeth_qdio_cq_handler(struct qeth_card *card, unsigned int qdio_err,
3783 unsigned int queue, int first_element,
3786 struct qeth_qdio_q *cq = card->qdio.c_q;
3790 QETH_CARD_TEXT_(card, 5, "qcqhe%d", first_element);
3791 QETH_CARD_TEXT_(card, 5, "qcqhc%d", count);
3792 QETH_CARD_TEXT_(card, 5, "qcqherr%d", qdio_err);
3795 netif_tx_stop_all_queues(card->dev);
3796 qeth_schedule_recovery(card);
3800 for (i = first_element; i < first_element + count; ++i) {
3801 struct qdio_buffer *buffer = cq->qdio_bufs[QDIO_BUFNR(i)];
3804 while ((e < QDIO_MAX_ELEMENTS_PER_BUFFER) &&
3805 buffer->element[e].addr) {
3806 unsigned long phys_aob_addr = buffer->element[e].addr;
3808 qeth_qdio_handle_aob(card, phys_aob_addr);
3811 qeth_scrub_qdio_buffer(buffer, QDIO_MAX_ELEMENTS_PER_BUFFER);
3813 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, queue,
3814 card->qdio.c_q->next_buf_to_init,
3817 dev_warn(&card->gdev->dev,
3818 "QDIO reported an error, rc=%i\n", rc);
3819 QETH_CARD_TEXT(card, 2, "qcqherr");
3822 cq->next_buf_to_init = QDIO_BUFNR(cq->next_buf_to_init + count);
3825 static void qeth_qdio_input_handler(struct ccw_device *ccwdev,
3826 unsigned int qdio_err, int queue,
3827 int first_elem, int count,
3828 unsigned long card_ptr)
3830 struct qeth_card *card = (struct qeth_card *)card_ptr;
3832 QETH_CARD_TEXT_(card, 2, "qihq%d", queue);
3833 QETH_CARD_TEXT_(card, 2, "qiec%d", qdio_err);
3836 qeth_schedule_recovery(card);
3839 static void qeth_qdio_output_handler(struct ccw_device *ccwdev,
3840 unsigned int qdio_error, int __queue,
3841 int first_element, int count,
3842 unsigned long card_ptr)
3844 struct qeth_card *card = (struct qeth_card *) card_ptr;
3845 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3846 struct net_device *dev = card->dev;
3847 struct netdev_queue *txq;
3850 QETH_CARD_TEXT(card, 6, "qdouhdl");
3851 if (qdio_error & QDIO_ERROR_FATAL) {
3852 QETH_CARD_TEXT(card, 2, "achkcond");
3853 netif_tx_stop_all_queues(dev);
3854 qeth_schedule_recovery(card);
3858 for (i = first_element; i < (first_element + count); ++i) {
3859 struct qeth_qdio_out_buffer *buf = queue->bufs[QDIO_BUFNR(i)];
3861 qeth_handle_send_error(card, buf, qdio_error);
3862 qeth_clear_output_buffer(queue, buf, qdio_error, 0);
3865 atomic_sub(count, &queue->used_buffers);
3866 qeth_check_outbound_queue(queue);
3868 txq = netdev_get_tx_queue(dev, __queue);
3869 /* xmit may have observed the full-condition, but not yet stopped the
3870 * txq. In which case the code below won't trigger. So before returning,
3871 * xmit will re-check the txq's fill level and wake it up if needed.
3873 if (netif_tx_queue_stopped(txq) && !qeth_out_queue_is_full(queue))
3874 netif_tx_wake_queue(txq);
3878 * Note: Function assumes that we have 4 outbound queues.
3880 int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb)
3882 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
3885 switch (card->qdio.do_prio_queueing) {
3886 case QETH_PRIO_Q_ING_TOS:
3887 case QETH_PRIO_Q_ING_PREC:
3888 switch (qeth_get_ip_version(skb)) {
3890 tos = ipv4_get_dsfield(ip_hdr(skb));
3893 tos = ipv6_get_dsfield(ipv6_hdr(skb));
3896 return card->qdio.default_out_queue;
3898 if (card->qdio.do_prio_queueing == QETH_PRIO_Q_ING_PREC)
3899 return ~tos >> 6 & 3;
3900 if (tos & IPTOS_MINCOST)
3902 if (tos & IPTOS_RELIABILITY)
3904 if (tos & IPTOS_THROUGHPUT)
3906 if (tos & IPTOS_LOWDELAY)
3909 case QETH_PRIO_Q_ING_SKB:
3910 if (skb->priority > 5)
3912 return ~skb->priority >> 1 & 3;
3913 case QETH_PRIO_Q_ING_VLAN:
3914 if (veth->h_vlan_proto == htons(ETH_P_8021Q))
3915 return ~ntohs(veth->h_vlan_TCI) >>
3916 (VLAN_PRIO_SHIFT + 1) & 3;
3918 case QETH_PRIO_Q_ING_FIXED:
3919 return card->qdio.default_out_queue;
3923 return card->qdio.default_out_queue;
3925 EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
3928 * qeth_get_elements_for_frags() - find number of SBALEs for skb frags.
3931 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
3932 * fragmented part of the SKB. Returns zero for linear SKB.
3934 static int qeth_get_elements_for_frags(struct sk_buff *skb)
3936 int cnt, elements = 0;
3938 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
3939 skb_frag_t *frag = &skb_shinfo(skb)->frags[cnt];
3941 elements += qeth_get_elements_for_range(
3942 (addr_t)skb_frag_address(frag),
3943 (addr_t)skb_frag_address(frag) + skb_frag_size(frag));
3949 * qeth_count_elements() - Counts the number of QDIO buffer elements needed
3950 * to transmit an skb.
3951 * @skb: the skb to operate on.
3952 * @data_offset: skip this part of the skb's linear data
3954 * Returns the number of pages, and thus QDIO buffer elements, needed to map the
3955 * skb's data (both its linear part and paged fragments).
3957 unsigned int qeth_count_elements(struct sk_buff *skb, unsigned int data_offset)
3959 unsigned int elements = qeth_get_elements_for_frags(skb);
3960 addr_t end = (addr_t)skb->data + skb_headlen(skb);
3961 addr_t start = (addr_t)skb->data + data_offset;
3964 elements += qeth_get_elements_for_range(start, end);
3967 EXPORT_SYMBOL_GPL(qeth_count_elements);
3969 #define QETH_HDR_CACHE_OBJ_SIZE (sizeof(struct qeth_hdr_tso) + \
3973 * qeth_add_hw_header() - add a HW header to an skb.
3974 * @skb: skb that the HW header should be added to.
3975 * @hdr: double pointer to a qeth_hdr. When returning with >= 0,
3976 * it contains a valid pointer to a qeth_hdr.
3977 * @hdr_len: length of the HW header.
3978 * @proto_len: length of protocol headers that need to be in same page as the
3981 * Returns the pushed length. If the header can't be pushed on
3982 * (eg. because it would cross a page boundary), it is allocated from
3983 * the cache instead and 0 is returned.
3984 * The number of needed buffer elements is returned in @elements.
3985 * Error to create the hdr is indicated by returning with < 0.
3987 static int qeth_add_hw_header(struct qeth_qdio_out_q *queue,
3988 struct sk_buff *skb, struct qeth_hdr **hdr,
3989 unsigned int hdr_len, unsigned int proto_len,
3990 unsigned int *elements)
3992 gfp_t gfp = GFP_ATOMIC | (skb_pfmemalloc(skb) ? __GFP_MEMALLOC : 0);
3993 const unsigned int contiguous = proto_len ? proto_len : 1;
3994 const unsigned int max_elements = queue->max_elements;
3995 unsigned int __elements;
4001 start = (addr_t)skb->data - hdr_len;
4002 end = (addr_t)skb->data;
4004 if (qeth_get_elements_for_range(start, end + contiguous) == 1) {
4005 /* Push HW header into same page as first protocol header. */
4007 /* ... but TSO always needs a separate element for headers: */
4008 if (skb_is_gso(skb))
4009 __elements = 1 + qeth_count_elements(skb, proto_len);
4011 __elements = qeth_count_elements(skb, 0);
4012 } else if (!proto_len && PAGE_ALIGNED(skb->data)) {
4013 /* Push HW header into preceding page, flush with skb->data. */
4015 __elements = 1 + qeth_count_elements(skb, 0);
4017 /* Use header cache, copy protocol headers up. */
4019 __elements = 1 + qeth_count_elements(skb, proto_len);
4022 /* Compress skb to fit into one IO buffer: */
4023 if (__elements > max_elements) {
4024 if (!skb_is_nonlinear(skb)) {
4025 /* Drop it, no easy way of shrinking it further. */
4026 QETH_DBF_MESSAGE(2, "Dropped an oversized skb (Max Elements=%u / Actual=%u / Length=%u).\n",
4027 max_elements, __elements, skb->len);
4031 rc = skb_linearize(skb);
4033 QETH_TXQ_STAT_INC(queue, skbs_linearized_fail);
4037 QETH_TXQ_STAT_INC(queue, skbs_linearized);
4038 /* Linearization changed the layout, re-evaluate: */
4042 *elements = __elements;
4043 /* Add the header: */
4045 *hdr = skb_push(skb, hdr_len);
4049 /* Fall back to cache element with known-good alignment: */
4050 if (hdr_len + proto_len > QETH_HDR_CACHE_OBJ_SIZE)
4052 *hdr = kmem_cache_alloc(qeth_core_header_cache, gfp);
4055 /* Copy protocol headers behind HW header: */
4056 skb_copy_from_linear_data(skb, ((char *)*hdr) + hdr_len, proto_len);
4060 static bool qeth_iqd_may_bulk(struct qeth_qdio_out_q *queue,
4061 struct sk_buff *curr_skb,
4062 struct qeth_hdr *curr_hdr)
4064 struct qeth_qdio_out_buffer *buffer = queue->bufs[queue->bulk_start];
4065 struct qeth_hdr *prev_hdr = queue->prev_hdr;
4070 /* All packets must have the same target: */
4071 if (curr_hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2) {
4072 struct sk_buff *prev_skb = skb_peek(&buffer->skb_list);
4074 return ether_addr_equal(eth_hdr(prev_skb)->h_dest,
4075 eth_hdr(curr_skb)->h_dest) &&
4076 qeth_l2_same_vlan(&prev_hdr->hdr.l2, &curr_hdr->hdr.l2);
4079 return qeth_l3_same_next_hop(&prev_hdr->hdr.l3, &curr_hdr->hdr.l3) &&
4080 qeth_l3_iqd_same_vlan(&prev_hdr->hdr.l3, &curr_hdr->hdr.l3);
4084 * qeth_fill_buffer() - map skb into an output buffer
4085 * @buf: buffer to transport the skb
4086 * @skb: skb to map into the buffer
4087 * @hdr: qeth_hdr for this skb. Either at skb->data, or allocated
4088 * from qeth_core_header_cache.
4089 * @offset: when mapping the skb, start at skb->data + offset
4090 * @hd_len: if > 0, build a dedicated header element of this size
4092 static unsigned int qeth_fill_buffer(struct qeth_qdio_out_buffer *buf,
4093 struct sk_buff *skb, struct qeth_hdr *hdr,
4094 unsigned int offset, unsigned int hd_len)
4096 struct qdio_buffer *buffer = buf->buffer;
4097 int element = buf->next_element_to_fill;
4098 int length = skb_headlen(skb) - offset;
4099 char *data = skb->data + offset;
4100 unsigned int elem_length, cnt;
4101 bool is_first_elem = true;
4103 __skb_queue_tail(&buf->skb_list, skb);
4105 /* build dedicated element for HW Header */
4107 is_first_elem = false;
4109 buffer->element[element].addr = virt_to_phys(hdr);
4110 buffer->element[element].length = hd_len;
4111 buffer->element[element].eflags = SBAL_EFLAGS_FIRST_FRAG;
4113 /* HW header is allocated from cache: */
4114 if ((void *)hdr != skb->data)
4115 buf->is_header[element] = 1;
4116 /* HW header was pushed and is contiguous with linear part: */
4117 else if (length > 0 && !PAGE_ALIGNED(data) &&
4118 (data == (char *)hdr + hd_len))
4119 buffer->element[element].eflags |=
4120 SBAL_EFLAGS_CONTIGUOUS;
4125 /* map linear part into buffer element(s) */
4126 while (length > 0) {
4127 elem_length = min_t(unsigned int, length,
4128 PAGE_SIZE - offset_in_page(data));
4130 buffer->element[element].addr = virt_to_phys(data);
4131 buffer->element[element].length = elem_length;
4132 length -= elem_length;
4133 if (is_first_elem) {
4134 is_first_elem = false;
4135 if (length || skb_is_nonlinear(skb))
4136 /* skb needs additional elements */
4137 buffer->element[element].eflags =
4138 SBAL_EFLAGS_FIRST_FRAG;
4140 buffer->element[element].eflags = 0;
4142 buffer->element[element].eflags =
4143 SBAL_EFLAGS_MIDDLE_FRAG;
4146 data += elem_length;
4150 /* map page frags into buffer element(s) */
4151 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
4152 skb_frag_t *frag = &skb_shinfo(skb)->frags[cnt];
4154 data = skb_frag_address(frag);
4155 length = skb_frag_size(frag);
4156 while (length > 0) {
4157 elem_length = min_t(unsigned int, length,
4158 PAGE_SIZE - offset_in_page(data));
4160 buffer->element[element].addr = virt_to_phys(data);
4161 buffer->element[element].length = elem_length;
4162 buffer->element[element].eflags =
4163 SBAL_EFLAGS_MIDDLE_FRAG;
4165 length -= elem_length;
4166 data += elem_length;
4171 if (buffer->element[element - 1].eflags)
4172 buffer->element[element - 1].eflags = SBAL_EFLAGS_LAST_FRAG;
4173 buf->next_element_to_fill = element;
4177 static int __qeth_xmit(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4178 struct sk_buff *skb, unsigned int elements,
4179 struct qeth_hdr *hdr, unsigned int offset,
4180 unsigned int hd_len)
4182 unsigned int bytes = qdisc_pkt_len(skb);
4183 struct qeth_qdio_out_buffer *buffer;
4184 unsigned int next_element;
4185 struct netdev_queue *txq;
4186 bool stopped = false;
4189 buffer = queue->bufs[QDIO_BUFNR(queue->bulk_start + queue->bulk_count)];
4190 txq = netdev_get_tx_queue(card->dev, skb_get_queue_mapping(skb));
4192 /* Just a sanity check, the wake/stop logic should ensure that we always
4193 * get a free buffer.
4195 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4198 flush = !qeth_iqd_may_bulk(queue, skb, hdr);
4201 (buffer->next_element_to_fill + elements > queue->max_elements)) {
4202 if (buffer->next_element_to_fill > 0) {
4203 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4204 queue->bulk_count++;
4207 if (queue->bulk_count >= queue->bulk_max)
4211 qeth_flush_queue(queue);
4213 buffer = queue->bufs[QDIO_BUFNR(queue->bulk_start +
4214 queue->bulk_count)];
4216 /* Sanity-check again: */
4217 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4221 if (buffer->next_element_to_fill == 0 &&
4222 atomic_inc_return(&queue->used_buffers) >= QDIO_MAX_BUFFERS_PER_Q) {
4223 /* If a TX completion happens right _here_ and misses to wake
4224 * the txq, then our re-check below will catch the race.
4226 QETH_TXQ_STAT_INC(queue, stopped);
4227 netif_tx_stop_queue(txq);
4231 next_element = qeth_fill_buffer(buffer, skb, hdr, offset, hd_len);
4232 buffer->bytes += bytes;
4233 buffer->frames += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1;
4234 queue->prev_hdr = hdr;
4236 flush = __netdev_tx_sent_queue(txq, bytes,
4237 !stopped && netdev_xmit_more());
4239 if (flush || next_element >= queue->max_elements) {
4240 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4241 queue->bulk_count++;
4243 if (queue->bulk_count >= queue->bulk_max)
4247 qeth_flush_queue(queue);
4250 if (stopped && !qeth_out_queue_is_full(queue))
4251 netif_tx_start_queue(txq);
4255 int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4256 struct sk_buff *skb, struct qeth_hdr *hdr,
4257 unsigned int offset, unsigned int hd_len,
4258 int elements_needed)
4260 unsigned int start_index = queue->next_buf_to_fill;
4261 struct qeth_qdio_out_buffer *buffer;
4262 unsigned int next_element;
4263 struct netdev_queue *txq;
4264 bool stopped = false;
4265 int flush_count = 0;
4269 buffer = queue->bufs[queue->next_buf_to_fill];
4271 /* Just a sanity check, the wake/stop logic should ensure that we always
4272 * get a free buffer.
4274 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4277 txq = netdev_get_tx_queue(card->dev, skb_get_queue_mapping(skb));
4279 /* check if we need to switch packing state of this queue */
4280 qeth_switch_to_packing_if_needed(queue);
4281 if (queue->do_pack) {
4283 /* does packet fit in current buffer? */
4284 if (buffer->next_element_to_fill + elements_needed >
4285 queue->max_elements) {
4286 /* ... no -> set state PRIMED */
4287 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4289 queue->next_buf_to_fill =
4290 QDIO_BUFNR(queue->next_buf_to_fill + 1);
4291 buffer = queue->bufs[queue->next_buf_to_fill];
4293 /* We stepped forward, so sanity-check again: */
4294 if (atomic_read(&buffer->state) !=
4295 QETH_QDIO_BUF_EMPTY) {
4296 qeth_flush_buffers(queue, start_index,
4304 if (buffer->next_element_to_fill == 0 &&
4305 atomic_inc_return(&queue->used_buffers) >= QDIO_MAX_BUFFERS_PER_Q) {
4306 /* If a TX completion happens right _here_ and misses to wake
4307 * the txq, then our re-check below will catch the race.
4309 QETH_TXQ_STAT_INC(queue, stopped);
4310 netif_tx_stop_queue(txq);
4314 next_element = qeth_fill_buffer(buffer, skb, hdr, offset, hd_len);
4315 buffer->bytes += qdisc_pkt_len(skb);
4316 buffer->frames += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1;
4319 QETH_TXQ_STAT_INC(queue, skbs_pack);
4320 if (!queue->do_pack || stopped || next_element >= queue->max_elements) {
4322 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4323 queue->next_buf_to_fill =
4324 QDIO_BUFNR(queue->next_buf_to_fill + 1);
4328 qeth_flush_buffers(queue, start_index, flush_count);
4332 QETH_TXQ_STAT_ADD(queue, bufs_pack, flush_count);
4334 if (stopped && !qeth_out_queue_is_full(queue))
4335 netif_tx_start_queue(txq);
4338 EXPORT_SYMBOL_GPL(qeth_do_send_packet);
4340 static void qeth_fill_tso_ext(struct qeth_hdr_tso *hdr,
4341 unsigned int payload_len, struct sk_buff *skb,
4342 unsigned int proto_len)
4344 struct qeth_hdr_ext_tso *ext = &hdr->ext;
4346 ext->hdr_tot_len = sizeof(*ext);
4347 ext->imb_hdr_no = 1;
4349 ext->hdr_version = 1;
4351 ext->payload_len = payload_len;
4352 ext->mss = skb_shinfo(skb)->gso_size;
4353 ext->dg_hdr_len = proto_len;
4356 int qeth_xmit(struct qeth_card *card, struct sk_buff *skb,
4357 struct qeth_qdio_out_q *queue, int ipv,
4358 void (*fill_header)(struct qeth_qdio_out_q *queue,
4359 struct qeth_hdr *hdr, struct sk_buff *skb,
4360 int ipv, unsigned int data_len))
4362 unsigned int proto_len, hw_hdr_len;
4363 unsigned int frame_len = skb->len;
4364 bool is_tso = skb_is_gso(skb);
4365 unsigned int data_offset = 0;
4366 struct qeth_hdr *hdr = NULL;
4367 unsigned int hd_len = 0;
4368 unsigned int elements;
4372 hw_hdr_len = sizeof(struct qeth_hdr_tso);
4373 proto_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4375 hw_hdr_len = sizeof(struct qeth_hdr);
4376 proto_len = (IS_IQD(card) && IS_LAYER2(card)) ? ETH_HLEN : 0;
4379 rc = skb_cow_head(skb, hw_hdr_len);
4383 push_len = qeth_add_hw_header(queue, skb, &hdr, hw_hdr_len, proto_len,
4387 if (is_tso || !push_len) {
4388 /* HW header needs its own buffer element. */
4389 hd_len = hw_hdr_len + proto_len;
4390 data_offset = push_len + proto_len;
4392 memset(hdr, 0, hw_hdr_len);
4393 fill_header(queue, hdr, skb, ipv, frame_len);
4395 qeth_fill_tso_ext((struct qeth_hdr_tso *) hdr,
4396 frame_len - proto_len, skb, proto_len);
4399 rc = __qeth_xmit(card, queue, skb, elements, hdr, data_offset,
4402 /* TODO: drop skb_orphan() once TX completion is fast enough */
4404 spin_lock(&queue->lock);
4405 rc = qeth_do_send_packet(card, queue, skb, hdr, data_offset,
4407 spin_unlock(&queue->lock);
4410 if (rc && !push_len)
4411 kmem_cache_free(qeth_core_header_cache, hdr);
4415 EXPORT_SYMBOL_GPL(qeth_xmit);
4417 static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
4418 struct qeth_reply *reply, unsigned long data)
4420 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4421 struct qeth_ipacmd_setadpparms *setparms;
4423 QETH_CARD_TEXT(card, 4, "prmadpcb");
4425 setparms = &(cmd->data.setadapterparms);
4426 if (qeth_setadpparms_inspect_rc(cmd)) {
4427 QETH_CARD_TEXT_(card, 4, "prmrc%x", cmd->hdr.return_code);
4428 setparms->data.mode = SET_PROMISC_MODE_OFF;
4430 card->info.promisc_mode = setparms->data.mode;
4431 return (cmd->hdr.return_code) ? -EIO : 0;
4434 void qeth_setadp_promisc_mode(struct qeth_card *card, bool enable)
4436 enum qeth_ipa_promisc_modes mode = enable ? SET_PROMISC_MODE_ON :
4437 SET_PROMISC_MODE_OFF;
4438 struct qeth_cmd_buffer *iob;
4439 struct qeth_ipa_cmd *cmd;
4441 QETH_CARD_TEXT(card, 4, "setprom");
4442 QETH_CARD_TEXT_(card, 4, "mode:%x", mode);
4444 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
4445 SETADP_DATA_SIZEOF(mode));
4448 cmd = __ipa_cmd(iob);
4449 cmd->data.setadapterparms.data.mode = mode;
4450 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
4452 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode);
4454 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
4455 struct qeth_reply *reply, unsigned long data)
4457 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4458 struct qeth_ipacmd_setadpparms *adp_cmd;
4460 QETH_CARD_TEXT(card, 4, "chgmaccb");
4461 if (qeth_setadpparms_inspect_rc(cmd))
4464 adp_cmd = &cmd->data.setadapterparms;
4465 if (!is_valid_ether_addr(adp_cmd->data.change_addr.addr))
4466 return -EADDRNOTAVAIL;
4468 if (IS_LAYER2(card) && IS_OSD(card) && !IS_VM_NIC(card) &&
4469 !(adp_cmd->hdr.flags & QETH_SETADP_FLAGS_VIRTUAL_MAC))
4470 return -EADDRNOTAVAIL;
4472 ether_addr_copy(card->dev->dev_addr, adp_cmd->data.change_addr.addr);
4476 int qeth_setadpparms_change_macaddr(struct qeth_card *card)
4479 struct qeth_cmd_buffer *iob;
4480 struct qeth_ipa_cmd *cmd;
4482 QETH_CARD_TEXT(card, 4, "chgmac");
4484 iob = qeth_get_adapter_cmd(card, IPA_SETADP_ALTER_MAC_ADDRESS,
4485 SETADP_DATA_SIZEOF(change_addr));
4488 cmd = __ipa_cmd(iob);
4489 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
4490 cmd->data.setadapterparms.data.change_addr.addr_size = ETH_ALEN;
4491 ether_addr_copy(cmd->data.setadapterparms.data.change_addr.addr,
4492 card->dev->dev_addr);
4493 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
4497 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
4499 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card *card,
4500 struct qeth_reply *reply, unsigned long data)
4502 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4503 struct qeth_set_access_ctrl *access_ctrl_req;
4505 QETH_CARD_TEXT(card, 4, "setaccb");
4507 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4508 QETH_CARD_TEXT_(card, 2, "rc=%d",
4509 cmd->data.setadapterparms.hdr.return_code);
4510 if (cmd->data.setadapterparms.hdr.return_code !=
4511 SET_ACCESS_CTRL_RC_SUCCESS)
4512 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%#x) on device %x: %#x\n",
4513 access_ctrl_req->subcmd_code, CARD_DEVID(card),
4514 cmd->data.setadapterparms.hdr.return_code);
4515 switch (qeth_setadpparms_inspect_rc(cmd)) {
4516 case SET_ACCESS_CTRL_RC_SUCCESS:
4517 if (access_ctrl_req->subcmd_code == ISOLATION_MODE_NONE)
4518 dev_info(&card->gdev->dev,
4519 "QDIO data connection isolation is deactivated\n");
4521 dev_info(&card->gdev->dev,
4522 "QDIO data connection isolation is activated\n");
4524 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED:
4525 QETH_DBF_MESSAGE(2, "QDIO data connection isolation on device %x already deactivated\n",
4528 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED:
4529 QETH_DBF_MESSAGE(2, "QDIO data connection isolation on device %x already activated\n",
4532 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED:
4533 dev_err(&card->gdev->dev, "Adapter does not "
4534 "support QDIO data connection isolation\n");
4536 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER:
4537 dev_err(&card->gdev->dev,
4538 "Adapter is dedicated. "
4539 "QDIO data connection isolation not supported\n");
4541 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF:
4542 dev_err(&card->gdev->dev,
4543 "TSO does not permit QDIO data connection isolation\n");
4545 case SET_ACCESS_CTRL_RC_REFLREL_UNSUPPORTED:
4546 dev_err(&card->gdev->dev, "The adjacent switch port does not "
4547 "support reflective relay mode\n");
4549 case SET_ACCESS_CTRL_RC_REFLREL_FAILED:
4550 dev_err(&card->gdev->dev, "The reflective relay mode cannot be "
4551 "enabled at the adjacent switch port");
4553 case SET_ACCESS_CTRL_RC_REFLREL_DEACT_FAILED:
4554 dev_warn(&card->gdev->dev, "Turning off reflective relay mode "
4555 "at the adjacent switch failed\n");
4556 /* benign error while disabling ISOLATION_MODE_FWD */
4563 int qeth_setadpparms_set_access_ctrl(struct qeth_card *card,
4564 enum qeth_ipa_isolation_modes mode)
4567 struct qeth_cmd_buffer *iob;
4568 struct qeth_ipa_cmd *cmd;
4569 struct qeth_set_access_ctrl *access_ctrl_req;
4571 QETH_CARD_TEXT(card, 4, "setacctl");
4573 if (!qeth_adp_supported(card, IPA_SETADP_SET_ACCESS_CONTROL)) {
4574 dev_err(&card->gdev->dev,
4575 "Adapter does not support QDIO data connection isolation\n");
4579 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_ACCESS_CONTROL,
4580 SETADP_DATA_SIZEOF(set_access_ctrl));
4583 cmd = __ipa_cmd(iob);
4584 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4585 access_ctrl_req->subcmd_code = mode;
4587 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_set_access_ctrl_cb,
4590 QETH_CARD_TEXT_(card, 2, "rc=%d", rc);
4591 QETH_DBF_MESSAGE(3, "IPA(SET_ACCESS_CTRL(%d) on device %x: sent failed\n",
4592 rc, CARD_DEVID(card));
4598 void qeth_tx_timeout(struct net_device *dev, unsigned int txqueue)
4600 struct qeth_card *card;
4602 card = dev->ml_priv;
4603 QETH_CARD_TEXT(card, 4, "txtimeo");
4604 qeth_schedule_recovery(card);
4606 EXPORT_SYMBOL_GPL(qeth_tx_timeout);
4608 static int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4610 struct qeth_card *card = dev->ml_priv;
4614 case MII_BMCR: /* Basic mode control register */
4616 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH) &&
4617 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4618 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH) &&
4619 (card->info.link_type != QETH_LINK_TYPE_25GBIT_ETH))
4620 rc |= BMCR_SPEED100;
4622 case MII_BMSR: /* Basic mode status register */
4623 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4624 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4627 case MII_PHYSID1: /* PHYS ID 1 */
4628 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4630 rc = (rc >> 5) & 0xFFFF;
4632 case MII_PHYSID2: /* PHYS ID 2 */
4633 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4635 case MII_ADVERTISE: /* Advertisement control reg */
4638 case MII_LPA: /* Link partner ability reg */
4639 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4640 LPA_100BASE4 | LPA_LPACK;
4642 case MII_EXPANSION: /* Expansion register */
4644 case MII_DCOUNTER: /* disconnect counter */
4646 case MII_FCSCOUNTER: /* false carrier counter */
4648 case MII_NWAYTEST: /* N-way auto-neg test register */
4650 case MII_RERRCOUNTER: /* rx error counter */
4651 rc = card->stats.rx_length_errors +
4652 card->stats.rx_frame_errors +
4653 card->stats.rx_fifo_errors;
4655 case MII_SREVISION: /* silicon revision */
4657 case MII_RESV1: /* reserved 1 */
4659 case MII_LBRERROR: /* loopback, rx, bypass error */
4661 case MII_PHYADDR: /* physical address */
4663 case MII_RESV2: /* reserved 2 */
4665 case MII_TPISTATUS: /* TPI status for 10mbps */
4667 case MII_NCONFIG: /* network interface config */
4675 static int qeth_snmp_command_cb(struct qeth_card *card,
4676 struct qeth_reply *reply, unsigned long data)
4678 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4679 struct qeth_arp_query_info *qinfo = reply->param;
4680 struct qeth_ipacmd_setadpparms *adp_cmd;
4681 unsigned int data_len;
4684 QETH_CARD_TEXT(card, 3, "snpcmdcb");
4686 if (cmd->hdr.return_code) {
4687 QETH_CARD_TEXT_(card, 4, "scer1%x", cmd->hdr.return_code);
4690 if (cmd->data.setadapterparms.hdr.return_code) {
4691 cmd->hdr.return_code =
4692 cmd->data.setadapterparms.hdr.return_code;
4693 QETH_CARD_TEXT_(card, 4, "scer2%x", cmd->hdr.return_code);
4697 adp_cmd = &cmd->data.setadapterparms;
4698 data_len = adp_cmd->hdr.cmdlength - sizeof(adp_cmd->hdr);
4699 if (adp_cmd->hdr.seq_no == 1) {
4700 snmp_data = &adp_cmd->data.snmp;
4702 snmp_data = &adp_cmd->data.snmp.request;
4703 data_len -= offsetof(struct qeth_snmp_cmd, request);
4706 /* check if there is enough room in userspace */
4707 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4708 QETH_CARD_TEXT_(card, 4, "scer3%i", -ENOSPC);
4711 QETH_CARD_TEXT_(card, 4, "snore%i",
4712 cmd->data.setadapterparms.hdr.used_total);
4713 QETH_CARD_TEXT_(card, 4, "sseqn%i",
4714 cmd->data.setadapterparms.hdr.seq_no);
4715 /*copy entries to user buffer*/
4716 memcpy(qinfo->udata + qinfo->udata_offset, snmp_data, data_len);
4717 qinfo->udata_offset += data_len;
4719 if (cmd->data.setadapterparms.hdr.seq_no <
4720 cmd->data.setadapterparms.hdr.used_total)
4725 static int qeth_snmp_command(struct qeth_card *card, char __user *udata)
4727 struct qeth_snmp_ureq __user *ureq;
4728 struct qeth_cmd_buffer *iob;
4729 unsigned int req_len;
4730 struct qeth_arp_query_info qinfo = {0, };
4733 QETH_CARD_TEXT(card, 3, "snmpcmd");
4735 if (IS_VM_NIC(card))
4738 if ((!qeth_adp_supported(card, IPA_SETADP_SET_SNMP_CONTROL)) &&
4742 ureq = (struct qeth_snmp_ureq __user *) udata;
4743 if (get_user(qinfo.udata_len, &ureq->hdr.data_len) ||
4744 get_user(req_len, &ureq->hdr.req_len))
4747 /* Sanitize user input, to avoid overflows in iob size calculation: */
4748 if (req_len > QETH_BUFSIZE)
4751 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL, req_len);
4755 if (copy_from_user(&__ipa_cmd(iob)->data.setadapterparms.data.snmp,
4756 &ureq->cmd, req_len)) {
4761 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
4766 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4768 rc = qeth_send_ipa_cmd(card, iob, qeth_snmp_command_cb, &qinfo);
4770 QETH_DBF_MESSAGE(2, "SNMP command failed on device %x: (%#x)\n",
4771 CARD_DEVID(card), rc);
4773 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4781 static int qeth_setadpparms_query_oat_cb(struct qeth_card *card,
4782 struct qeth_reply *reply,
4785 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
4786 struct qeth_qoat_priv *priv = reply->param;
4789 QETH_CARD_TEXT(card, 3, "qoatcb");
4790 if (qeth_setadpparms_inspect_rc(cmd))
4793 resdatalen = cmd->data.setadapterparms.hdr.cmdlength;
4795 if (resdatalen > (priv->buffer_len - priv->response_len))
4798 memcpy(priv->buffer + priv->response_len,
4799 &cmd->data.setadapterparms.hdr, resdatalen);
4800 priv->response_len += resdatalen;
4802 if (cmd->data.setadapterparms.hdr.seq_no <
4803 cmd->data.setadapterparms.hdr.used_total)
4808 static int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
4811 struct qeth_cmd_buffer *iob;
4812 struct qeth_ipa_cmd *cmd;
4813 struct qeth_query_oat *oat_req;
4814 struct qeth_query_oat_data oat_data;
4815 struct qeth_qoat_priv priv;
4818 QETH_CARD_TEXT(card, 3, "qoatcmd");
4820 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_OAT))
4823 if (copy_from_user(&oat_data, udata, sizeof(oat_data)))
4826 priv.buffer_len = oat_data.buffer_len;
4827 priv.response_len = 0;
4828 priv.buffer = vzalloc(oat_data.buffer_len);
4832 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_OAT,
4833 SETADP_DATA_SIZEOF(query_oat));
4838 cmd = __ipa_cmd(iob);
4839 oat_req = &cmd->data.setadapterparms.data.query_oat;
4840 oat_req->subcmd_code = oat_data.command;
4842 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_query_oat_cb, &priv);
4844 tmp = is_compat_task() ? compat_ptr(oat_data.ptr) :
4845 u64_to_user_ptr(oat_data.ptr);
4846 oat_data.response_len = priv.response_len;
4848 if (copy_to_user(tmp, priv.buffer, priv.response_len) ||
4849 copy_to_user(udata, &oat_data, sizeof(oat_data)))
4858 static int qeth_query_card_info_cb(struct qeth_card *card,
4859 struct qeth_reply *reply, unsigned long data)
4861 struct carrier_info *carrier_info = (struct carrier_info *)reply->param;
4862 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
4863 struct qeth_query_card_info *card_info;
4865 QETH_CARD_TEXT(card, 2, "qcrdincb");
4866 if (qeth_setadpparms_inspect_rc(cmd))
4869 card_info = &cmd->data.setadapterparms.data.card_info;
4870 carrier_info->card_type = card_info->card_type;
4871 carrier_info->port_mode = card_info->port_mode;
4872 carrier_info->port_speed = card_info->port_speed;
4876 int qeth_query_card_info(struct qeth_card *card,
4877 struct carrier_info *carrier_info)
4879 struct qeth_cmd_buffer *iob;
4881 QETH_CARD_TEXT(card, 2, "qcrdinfo");
4882 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_CARD_INFO))
4884 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_CARD_INFO, 0);
4887 return qeth_send_ipa_cmd(card, iob, qeth_query_card_info_cb,
4888 (void *)carrier_info);
4892 * qeth_vm_request_mac() - Request a hypervisor-managed MAC address
4893 * @card: pointer to a qeth_card
4896 * 0, if a MAC address has been set for the card's netdevice
4897 * a return code, for various error conditions
4899 int qeth_vm_request_mac(struct qeth_card *card)
4901 struct diag26c_mac_resp *response;
4902 struct diag26c_mac_req *request;
4905 QETH_CARD_TEXT(card, 2, "vmreqmac");
4907 request = kzalloc(sizeof(*request), GFP_KERNEL | GFP_DMA);
4908 response = kzalloc(sizeof(*response), GFP_KERNEL | GFP_DMA);
4909 if (!request || !response) {
4914 request->resp_buf_len = sizeof(*response);
4915 request->resp_version = DIAG26C_VERSION2;
4916 request->op_code = DIAG26C_GET_MAC;
4917 request->devno = card->info.ddev_devno;
4919 QETH_DBF_HEX(CTRL, 2, request, sizeof(*request));
4920 rc = diag26c(request, response, DIAG26C_MAC_SERVICES);
4921 QETH_DBF_HEX(CTRL, 2, request, sizeof(*request));
4924 QETH_DBF_HEX(CTRL, 2, response, sizeof(*response));
4926 if (request->resp_buf_len < sizeof(*response) ||
4927 response->version != request->resp_version) {
4929 QETH_CARD_TEXT(card, 2, "badresp");
4930 QETH_CARD_HEX(card, 2, &request->resp_buf_len,
4931 sizeof(request->resp_buf_len));
4932 } else if (!is_valid_ether_addr(response->mac)) {
4934 QETH_CARD_TEXT(card, 2, "badmac");
4935 QETH_CARD_HEX(card, 2, response->mac, ETH_ALEN);
4937 ether_addr_copy(card->dev->dev_addr, response->mac);
4945 EXPORT_SYMBOL_GPL(qeth_vm_request_mac);
4947 static void qeth_determine_capabilities(struct qeth_card *card)
4949 struct qeth_channel *channel = &card->data;
4950 struct ccw_device *ddev = channel->ccwdev;
4952 int ddev_offline = 0;
4954 QETH_CARD_TEXT(card, 2, "detcapab");
4955 if (!ddev->online) {
4957 rc = qeth_start_channel(channel);
4959 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
4964 rc = qeth_read_conf_data(card);
4966 QETH_DBF_MESSAGE(2, "qeth_read_conf_data on device %x returned %i\n",
4967 CARD_DEVID(card), rc);
4968 QETH_CARD_TEXT_(card, 2, "5err%d", rc);
4972 rc = qdio_get_ssqd_desc(ddev, &card->ssqd);
4974 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
4976 QETH_CARD_TEXT_(card, 2, "qfmt%d", card->ssqd.qfmt);
4977 QETH_CARD_TEXT_(card, 2, "ac1:%02x", card->ssqd.qdioac1);
4978 QETH_CARD_TEXT_(card, 2, "ac2:%04x", card->ssqd.qdioac2);
4979 QETH_CARD_TEXT_(card, 2, "ac3:%04x", card->ssqd.qdioac3);
4980 QETH_CARD_TEXT_(card, 2, "icnt%d", card->ssqd.icnt);
4981 if (!((card->ssqd.qfmt != QDIO_IQDIO_QFMT) ||
4982 ((card->ssqd.qdioac1 & CHSC_AC1_INITIATE_INPUTQ) == 0) ||
4983 ((card->ssqd.qdioac3 & CHSC_AC3_FORMAT2_CQ_AVAILABLE) == 0))) {
4984 dev_info(&card->gdev->dev,
4985 "Completion Queueing supported\n");
4987 card->options.cq = QETH_CQ_NOTAVAILABLE;
4991 if (ddev_offline == 1)
4992 qeth_stop_channel(channel);
4997 static void qeth_read_ccw_conf_data(struct qeth_card *card)
4999 struct qeth_card_info *info = &card->info;
5000 struct ccw_device *cdev = CARD_DDEV(card);
5001 struct ccw_dev_id dev_id;
5003 QETH_CARD_TEXT(card, 2, "ccwconfd");
5004 ccw_device_get_id(cdev, &dev_id);
5006 info->ddev_devno = dev_id.devno;
5007 info->ids_valid = !ccw_device_get_cssid(cdev, &info->cssid) &&
5008 !ccw_device_get_iid(cdev, &info->iid) &&
5009 !ccw_device_get_chid(cdev, 0, &info->chid);
5010 info->ssid = dev_id.ssid;
5012 dev_info(&card->gdev->dev, "CHID: %x CHPID: %x\n",
5013 info->chid, info->chpid);
5015 QETH_CARD_TEXT_(card, 3, "devn%x", info->ddev_devno);
5016 QETH_CARD_TEXT_(card, 3, "cssid:%x", info->cssid);
5017 QETH_CARD_TEXT_(card, 3, "iid:%x", info->iid);
5018 QETH_CARD_TEXT_(card, 3, "ssid:%x", info->ssid);
5019 QETH_CARD_TEXT_(card, 3, "chpid:%x", info->chpid);
5020 QETH_CARD_TEXT_(card, 3, "chid:%x", info->chid);
5021 QETH_CARD_TEXT_(card, 3, "idval%x", info->ids_valid);
5024 static int qeth_qdio_establish(struct qeth_card *card)
5026 struct qdio_buffer **out_sbal_ptrs[QETH_MAX_OUT_QUEUES];
5027 struct qdio_buffer **in_sbal_ptrs[QETH_MAX_IN_QUEUES];
5028 struct qeth_qib_parms *qib_parms = NULL;
5029 struct qdio_initialize init_data;
5033 QETH_CARD_TEXT(card, 2, "qdioest");
5035 if (!IS_IQD(card) && !IS_VM_NIC(card)) {
5036 qib_parms = kzalloc(sizeof_field(struct qib, parm), GFP_KERNEL);
5040 qeth_fill_qib_parms(card, qib_parms);
5043 in_sbal_ptrs[0] = card->qdio.in_q->qdio_bufs;
5044 if (card->options.cq == QETH_CQ_ENABLED)
5045 in_sbal_ptrs[1] = card->qdio.c_q->qdio_bufs;
5047 for (i = 0; i < card->qdio.no_out_queues; i++)
5048 out_sbal_ptrs[i] = card->qdio.out_qs[i]->qdio_bufs;
5050 memset(&init_data, 0, sizeof(struct qdio_initialize));
5051 init_data.q_format = IS_IQD(card) ? QDIO_IQDIO_QFMT :
5053 init_data.qib_param_field_format = 0;
5054 init_data.qib_param_field = (void *)qib_parms;
5055 init_data.no_input_qs = card->qdio.no_in_queues;
5056 init_data.no_output_qs = card->qdio.no_out_queues;
5057 init_data.input_handler = qeth_qdio_input_handler;
5058 init_data.output_handler = qeth_qdio_output_handler;
5059 init_data.irq_poll = qeth_qdio_poll;
5060 init_data.int_parm = (unsigned long) card;
5061 init_data.input_sbal_addr_array = in_sbal_ptrs;
5062 init_data.output_sbal_addr_array = out_sbal_ptrs;
5063 init_data.output_sbal_state_array = card->qdio.out_bufstates;
5064 init_data.scan_threshold = IS_IQD(card) ? 0 : 32;
5066 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
5067 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
5068 rc = qdio_allocate(CARD_DDEV(card), init_data.no_input_qs,
5069 init_data.no_output_qs);
5071 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
5074 rc = qdio_establish(CARD_DDEV(card), &init_data);
5076 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
5077 qdio_free(CARD_DDEV(card));
5081 switch (card->options.cq) {
5082 case QETH_CQ_ENABLED:
5083 dev_info(&card->gdev->dev, "Completion Queue support enabled");
5085 case QETH_CQ_DISABLED:
5086 dev_info(&card->gdev->dev, "Completion Queue support disabled");
5097 static void qeth_core_free_card(struct qeth_card *card)
5099 QETH_CARD_TEXT(card, 2, "freecrd");
5101 unregister_service_level(&card->qeth_service_level);
5102 debugfs_remove_recursive(card->debugfs);
5103 qeth_put_cmd(card->read_cmd);
5104 destroy_workqueue(card->event_wq);
5105 dev_set_drvdata(&card->gdev->dev, NULL);
5109 static void qeth_trace_features(struct qeth_card *card)
5111 QETH_CARD_TEXT(card, 2, "features");
5112 QETH_CARD_HEX(card, 2, &card->options.ipa4, sizeof(card->options.ipa4));
5113 QETH_CARD_HEX(card, 2, &card->options.ipa6, sizeof(card->options.ipa6));
5114 QETH_CARD_HEX(card, 2, &card->options.adp, sizeof(card->options.adp));
5115 QETH_CARD_HEX(card, 2, &card->info.diagass_support,
5116 sizeof(card->info.diagass_support));
5119 static struct ccw_device_id qeth_ids[] = {
5120 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
5121 .driver_info = QETH_CARD_TYPE_OSD},
5122 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
5123 .driver_info = QETH_CARD_TYPE_IQD},
5124 #ifdef CONFIG_QETH_OSN
5125 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
5126 .driver_info = QETH_CARD_TYPE_OSN},
5128 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
5129 .driver_info = QETH_CARD_TYPE_OSM},
5130 #ifdef CONFIG_QETH_OSX
5131 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
5132 .driver_info = QETH_CARD_TYPE_OSX},
5136 MODULE_DEVICE_TABLE(ccw, qeth_ids);
5138 static struct ccw_driver qeth_ccw_driver = {
5140 .owner = THIS_MODULE,
5144 .probe = ccwgroup_probe_ccwdev,
5145 .remove = ccwgroup_remove_ccwdev,
5148 static int qeth_hardsetup_card(struct qeth_card *card, bool *carrier_ok)
5153 QETH_CARD_TEXT(card, 2, "hrdsetup");
5154 atomic_set(&card->force_alloc_skb, 0);
5155 rc = qeth_update_from_chp_desc(card);
5160 QETH_DBF_MESSAGE(2, "Retrying to do IDX activates on device %x.\n",
5162 rc = qeth_qdio_clear_card(card, !IS_IQD(card));
5163 qeth_stop_channel(&card->data);
5164 qeth_stop_channel(&card->write);
5165 qeth_stop_channel(&card->read);
5166 qdio_free(CARD_DDEV(card));
5168 rc = qeth_start_channel(&card->read);
5171 rc = qeth_start_channel(&card->write);
5174 rc = qeth_start_channel(&card->data);
5178 if (rc == -ERESTARTSYS) {
5179 QETH_CARD_TEXT(card, 2, "break1");
5182 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
5189 qeth_determine_capabilities(card);
5190 qeth_read_ccw_conf_data(card);
5191 qeth_idx_init(card);
5193 rc = qeth_idx_activate_read_channel(card);
5195 QETH_CARD_TEXT(card, 2, "break2");
5198 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
5205 rc = qeth_idx_activate_write_channel(card);
5207 QETH_CARD_TEXT(card, 2, "break3");
5210 QETH_CARD_TEXT_(card, 2, "4err%d", rc);
5216 card->read_or_write_problem = 0;
5217 rc = qeth_mpc_initialize(card);
5219 QETH_CARD_TEXT_(card, 2, "5err%d", rc);
5223 rc = qeth_send_startlan(card);
5225 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
5226 if (rc == -ENETDOWN) {
5227 dev_warn(&card->gdev->dev, "The LAN is offline\n");
5228 *carrier_ok = false;
5236 card->options.ipa4.supported = 0;
5237 card->options.ipa6.supported = 0;
5238 card->options.adp.supported = 0;
5239 card->options.sbp.supported_funcs = 0;
5240 card->info.diagass_support = 0;
5241 rc = qeth_query_ipassists(card, QETH_PROT_IPV4);
5244 if (qeth_is_supported(card, IPA_IPV6)) {
5245 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
5249 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
5250 rc = qeth_query_setadapterparms(card);
5252 QETH_CARD_TEXT_(card, 2, "7err%d", rc);
5256 if (qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
5257 rc = qeth_query_setdiagass(card);
5259 QETH_CARD_TEXT_(card, 2, "8err%d", rc);
5262 qeth_trace_features(card);
5264 if (!qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP) ||
5265 (card->info.hwtrap && qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)))
5266 card->info.hwtrap = 0;
5268 if (card->options.isolation != ISOLATION_MODE_NONE) {
5269 rc = qeth_setadpparms_set_access_ctrl(card,
5270 card->options.isolation);
5275 rc = qeth_init_qdio_queues(card);
5277 QETH_CARD_TEXT_(card, 2, "9err%d", rc);
5283 dev_warn(&card->gdev->dev, "The qeth device driver failed to recover "
5284 "an error on the device\n");
5285 QETH_DBF_MESSAGE(2, "Initialization for device %x failed in hardsetup! rc=%d\n",
5286 CARD_DEVID(card), rc);
5290 static int qeth_set_online(struct qeth_card *card,
5291 const struct qeth_discipline *disc)
5296 mutex_lock(&card->conf_mutex);
5297 QETH_CARD_TEXT(card, 2, "setonlin");
5299 rc = qeth_hardsetup_card(card, &carrier_ok);
5301 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
5306 qeth_print_status_message(card);
5308 if (card->dev->reg_state != NETREG_REGISTERED)
5309 /* no need for locking / error handling at this early stage: */
5310 qeth_set_real_num_tx_queues(card, qeth_tx_actual_queues(card));
5312 rc = disc->set_online(card, carrier_ok);
5316 /* let user_space know that device is online */
5317 kobject_uevent(&card->gdev->dev.kobj, KOBJ_CHANGE);
5319 mutex_unlock(&card->conf_mutex);
5324 qeth_qdio_clear_card(card, 0);
5325 qeth_clear_working_pool_list(card);
5326 qeth_flush_local_addrs(card);
5328 qeth_stop_channel(&card->data);
5329 qeth_stop_channel(&card->write);
5330 qeth_stop_channel(&card->read);
5331 qdio_free(CARD_DDEV(card));
5333 mutex_unlock(&card->conf_mutex);
5337 int qeth_set_offline(struct qeth_card *card, const struct qeth_discipline *disc,
5342 mutex_lock(&card->conf_mutex);
5343 QETH_CARD_TEXT(card, 3, "setoffl");
5345 if ((!resetting && card->info.hwtrap) || card->info.hwtrap == 2) {
5346 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
5347 card->info.hwtrap = 1;
5350 /* cancel any stalled cmd that might block the rtnl: */
5351 qeth_clear_ipacmd_list(card);
5354 netif_device_detach(card->dev);
5355 netif_carrier_off(card->dev);
5358 cancel_work_sync(&card->rx_mode_work);
5360 disc->set_offline(card);
5362 qeth_qdio_clear_card(card, 0);
5363 qeth_drain_output_queues(card);
5364 qeth_clear_working_pool_list(card);
5365 qeth_flush_local_addrs(card);
5366 card->info.promisc_mode = 0;
5368 rc = qeth_stop_channel(&card->data);
5369 rc2 = qeth_stop_channel(&card->write);
5370 rc3 = qeth_stop_channel(&card->read);
5372 rc = (rc2) ? rc2 : rc3;
5374 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
5375 qdio_free(CARD_DDEV(card));
5377 /* let user_space know that device is offline */
5378 kobject_uevent(&card->gdev->dev.kobj, KOBJ_CHANGE);
5380 mutex_unlock(&card->conf_mutex);
5383 EXPORT_SYMBOL_GPL(qeth_set_offline);
5385 static int qeth_do_reset(void *data)
5387 const struct qeth_discipline *disc;
5388 struct qeth_card *card = data;
5391 /* Lock-free, other users will block until we are done. */
5392 disc = card->discipline;
5394 QETH_CARD_TEXT(card, 2, "recover1");
5395 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
5397 QETH_CARD_TEXT(card, 2, "recover2");
5398 dev_warn(&card->gdev->dev,
5399 "A recovery process has been started for the device\n");
5401 qeth_set_offline(card, disc, true);
5402 rc = qeth_set_online(card, disc);
5404 dev_info(&card->gdev->dev,
5405 "Device successfully recovered!\n");
5407 ccwgroup_set_offline(card->gdev);
5408 dev_warn(&card->gdev->dev,
5409 "The qeth device driver failed to recover an error on the device\n");
5411 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
5412 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
5416 #if IS_ENABLED(CONFIG_QETH_L3)
5417 static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
5418 struct qeth_hdr *hdr)
5420 struct af_iucv_trans_hdr *iucv = (struct af_iucv_trans_hdr *) skb->data;
5421 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3;
5422 struct net_device *dev = skb->dev;
5424 if (IS_IQD(card) && iucv->magic == ETH_P_AF_IUCV) {
5425 dev_hard_header(skb, dev, ETH_P_AF_IUCV, dev->dev_addr,
5426 "FAKELL", skb->len);
5430 if (!(l3_hdr->flags & QETH_HDR_PASSTHRU)) {
5431 u16 prot = (l3_hdr->flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
5433 unsigned char tg_addr[ETH_ALEN];
5435 skb_reset_network_header(skb);
5436 switch (l3_hdr->flags & QETH_HDR_CAST_MASK) {
5437 case QETH_CAST_MULTICAST:
5438 if (prot == ETH_P_IP)
5439 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
5441 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
5442 QETH_CARD_STAT_INC(card, rx_multicast);
5444 case QETH_CAST_BROADCAST:
5445 ether_addr_copy(tg_addr, dev->broadcast);
5446 QETH_CARD_STAT_INC(card, rx_multicast);
5449 if (card->options.sniffer)
5450 skb->pkt_type = PACKET_OTHERHOST;
5451 ether_addr_copy(tg_addr, dev->dev_addr);
5454 if (l3_hdr->ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
5455 dev_hard_header(skb, dev, prot, tg_addr,
5456 &l3_hdr->next_hop.rx.src_mac, skb->len);
5458 dev_hard_header(skb, dev, prot, tg_addr, "FAKELL",
5462 /* copy VLAN tag from hdr into skb */
5463 if (!card->options.sniffer &&
5464 (l3_hdr->ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
5465 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
5466 u16 tag = (l3_hdr->ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
5468 l3_hdr->next_hop.rx.vlan_id;
5470 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
5475 static void qeth_receive_skb(struct qeth_card *card, struct sk_buff *skb,
5476 struct qeth_hdr *hdr, bool uses_frags)
5478 struct napi_struct *napi = &card->napi;
5481 switch (hdr->hdr.l2.id) {
5482 case QETH_HEADER_TYPE_OSN:
5483 skb_push(skb, sizeof(*hdr));
5484 skb_copy_to_linear_data(skb, hdr, sizeof(*hdr));
5485 QETH_CARD_STAT_ADD(card, rx_bytes, skb->len);
5486 QETH_CARD_STAT_INC(card, rx_packets);
5488 card->osn_info.data_cb(skb);
5490 #if IS_ENABLED(CONFIG_QETH_L3)
5491 case QETH_HEADER_TYPE_LAYER3:
5492 qeth_l3_rebuild_skb(card, skb, hdr);
5493 is_cso = hdr->hdr.l3.ext_flags & QETH_HDR_EXT_CSUM_TRANSP_REQ;
5496 case QETH_HEADER_TYPE_LAYER2:
5497 is_cso = hdr->hdr.l2.flags[1] & QETH_HDR_EXT_CSUM_TRANSP_REQ;
5502 napi_free_frags(napi);
5504 dev_kfree_skb_any(skb);
5508 if (is_cso && (card->dev->features & NETIF_F_RXCSUM)) {
5509 skb->ip_summed = CHECKSUM_UNNECESSARY;
5510 QETH_CARD_STAT_INC(card, rx_skb_csum);
5512 skb->ip_summed = CHECKSUM_NONE;
5515 QETH_CARD_STAT_ADD(card, rx_bytes, skb->len);
5516 QETH_CARD_STAT_INC(card, rx_packets);
5517 if (skb_is_nonlinear(skb)) {
5518 QETH_CARD_STAT_INC(card, rx_sg_skbs);
5519 QETH_CARD_STAT_ADD(card, rx_sg_frags,
5520 skb_shinfo(skb)->nr_frags);
5524 napi_gro_frags(napi);
5526 skb->protocol = eth_type_trans(skb, skb->dev);
5527 napi_gro_receive(napi, skb);
5531 static void qeth_create_skb_frag(struct sk_buff *skb, char *data, int data_len)
5533 struct page *page = virt_to_page(data);
5534 unsigned int next_frag;
5536 next_frag = skb_shinfo(skb)->nr_frags;
5538 skb_add_rx_frag(skb, next_frag, page, offset_in_page(data), data_len,
5542 static inline int qeth_is_last_sbale(struct qdio_buffer_element *sbale)
5544 return (sbale->eflags & SBAL_EFLAGS_LAST_ENTRY);
5547 static int qeth_extract_skb(struct qeth_card *card,
5548 struct qeth_qdio_buffer *qethbuffer, u8 *element_no,
5551 struct qeth_priv *priv = netdev_priv(card->dev);
5552 struct qdio_buffer *buffer = qethbuffer->buffer;
5553 struct napi_struct *napi = &card->napi;
5554 struct qdio_buffer_element *element;
5555 unsigned int linear_len = 0;
5556 bool uses_frags = false;
5557 int offset = *__offset;
5558 bool use_rx_sg = false;
5559 unsigned int headroom;
5560 struct qeth_hdr *hdr;
5561 struct sk_buff *skb;
5564 element = &buffer->element[*element_no];
5567 /* qeth_hdr must not cross element boundaries */
5568 while (element->length < offset + sizeof(struct qeth_hdr)) {
5569 if (qeth_is_last_sbale(element))
5575 hdr = phys_to_virt(element->addr) + offset;
5576 offset += sizeof(*hdr);
5579 switch (hdr->hdr.l2.id) {
5580 case QETH_HEADER_TYPE_LAYER2:
5581 skb_len = hdr->hdr.l2.pkt_length;
5582 linear_len = ETH_HLEN;
5585 case QETH_HEADER_TYPE_LAYER3:
5586 skb_len = hdr->hdr.l3.length;
5587 if (!IS_LAYER3(card)) {
5588 QETH_CARD_STAT_INC(card, rx_dropped_notsupp);
5592 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
5593 linear_len = ETH_HLEN;
5598 if (hdr->hdr.l3.flags & QETH_HDR_IPV6)
5599 linear_len = sizeof(struct ipv6hdr);
5601 linear_len = sizeof(struct iphdr);
5602 headroom = ETH_HLEN;
5604 case QETH_HEADER_TYPE_OSN:
5605 skb_len = hdr->hdr.osn.pdu_length;
5606 if (!IS_OSN(card)) {
5607 QETH_CARD_STAT_INC(card, rx_dropped_notsupp);
5611 linear_len = skb_len;
5612 headroom = sizeof(struct qeth_hdr);
5615 if (hdr->hdr.l2.id & QETH_HEADER_MASK_INVAL)
5616 QETH_CARD_STAT_INC(card, rx_frame_errors);
5618 QETH_CARD_STAT_INC(card, rx_dropped_notsupp);
5620 /* Can't determine packet length, drop the whole buffer. */
5621 return -EPROTONOSUPPORT;
5624 if (skb_len < linear_len) {
5625 QETH_CARD_STAT_INC(card, rx_dropped_runt);
5629 use_rx_sg = (card->options.cq == QETH_CQ_ENABLED) ||
5630 (skb_len > READ_ONCE(priv->rx_copybreak) &&
5631 !atomic_read(&card->force_alloc_skb) &&
5635 /* QETH_CQ_ENABLED only: */
5636 if (qethbuffer->rx_skb &&
5637 skb_tailroom(qethbuffer->rx_skb) >= linear_len + headroom) {
5638 skb = qethbuffer->rx_skb;
5639 qethbuffer->rx_skb = NULL;
5643 skb = napi_get_frags(napi);
5645 /* -ENOMEM, no point in falling back further. */
5646 QETH_CARD_STAT_INC(card, rx_dropped_nomem);
5650 if (skb_tailroom(skb) >= linear_len + headroom) {
5655 netdev_info_once(card->dev,
5656 "Insufficient linear space in NAPI frags skb, need %u but have %u\n",
5657 linear_len + headroom, skb_tailroom(skb));
5658 /* Shouldn't happen. Don't optimize, fall back to linear skb. */
5661 linear_len = skb_len;
5662 skb = napi_alloc_skb(napi, linear_len + headroom);
5664 QETH_CARD_STAT_INC(card, rx_dropped_nomem);
5670 skb_reserve(skb, headroom);
5673 int data_len = min(skb_len, (int)(element->length - offset));
5674 char *data = phys_to_virt(element->addr) + offset;
5676 skb_len -= data_len;
5679 /* Extract data from current element: */
5680 if (skb && data_len) {
5682 unsigned int copy_len;
5684 copy_len = min_t(unsigned int, linear_len,
5687 skb_put_data(skb, data, copy_len);
5688 linear_len -= copy_len;
5689 data_len -= copy_len;
5694 qeth_create_skb_frag(skb, data, data_len);
5697 /* Step forward to next element: */
5699 if (qeth_is_last_sbale(element)) {
5700 QETH_CARD_TEXT(card, 4, "unexeob");
5701 QETH_CARD_HEX(card, 2, buffer, sizeof(void *));
5704 napi_free_frags(napi);
5706 dev_kfree_skb_any(skb);
5707 QETH_CARD_STAT_INC(card,
5717 /* This packet was skipped, go get another one: */
5721 *element_no = element - &buffer->element[0];
5724 qeth_receive_skb(card, skb, hdr, uses_frags);
5728 static unsigned int qeth_extract_skbs(struct qeth_card *card, int budget,
5729 struct qeth_qdio_buffer *buf, bool *done)
5731 unsigned int work_done = 0;
5734 if (qeth_extract_skb(card, buf, &card->rx.buf_element,
5735 &card->rx.e_offset)) {
5747 static unsigned int qeth_rx_poll(struct qeth_card *card, int budget)
5749 struct qeth_rx *ctx = &card->rx;
5750 unsigned int work_done = 0;
5752 while (budget > 0) {
5753 struct qeth_qdio_buffer *buffer;
5754 unsigned int skbs_done = 0;
5757 /* Fetch completed RX buffers: */
5758 if (!card->rx.b_count) {
5759 card->rx.qdio_err = 0;
5760 card->rx.b_count = qdio_get_next_buffers(
5761 card->data.ccwdev, 0, &card->rx.b_index,
5762 &card->rx.qdio_err);
5763 if (card->rx.b_count <= 0) {
5764 card->rx.b_count = 0;
5769 /* Process one completed RX buffer: */
5770 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
5771 if (!(card->rx.qdio_err &&
5772 qeth_check_qdio_errors(card, buffer->buffer,
5773 card->rx.qdio_err, "qinerr")))
5774 skbs_done = qeth_extract_skbs(card, budget, buffer,
5779 work_done += skbs_done;
5780 budget -= skbs_done;
5783 QETH_CARD_STAT_INC(card, rx_bufs);
5784 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
5785 buffer->pool_entry = NULL;
5788 ctx->bufs_refill -= qeth_rx_refill_queue(card,
5791 /* Step forward to next buffer: */
5792 card->rx.b_index = QDIO_BUFNR(card->rx.b_index + 1);
5793 card->rx.buf_element = 0;
5794 card->rx.e_offset = 0;
5801 static void qeth_cq_poll(struct qeth_card *card)
5803 unsigned int work_done = 0;
5805 while (work_done < QDIO_MAX_BUFFERS_PER_Q) {
5806 unsigned int start, error;
5809 completed = qdio_inspect_queue(CARD_DDEV(card), 1, true, &start,
5814 qeth_qdio_cq_handler(card, error, 1, start, completed);
5815 work_done += completed;
5819 int qeth_poll(struct napi_struct *napi, int budget)
5821 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
5822 unsigned int work_done;
5824 work_done = qeth_rx_poll(card, budget);
5826 if (card->options.cq == QETH_CQ_ENABLED)
5830 struct qeth_rx *ctx = &card->rx;
5832 /* Process any substantial refill backlog: */
5833 ctx->bufs_refill -= qeth_rx_refill_queue(card, ctx->bufs_refill);
5835 /* Exhausted the RX budget. Keep IRQ disabled, we get called again. */
5836 if (work_done >= budget)
5840 if (napi_complete_done(napi, work_done) &&
5841 qdio_start_irq(CARD_DDEV(card)))
5842 napi_schedule(napi);
5846 EXPORT_SYMBOL_GPL(qeth_poll);
5848 static void qeth_iqd_tx_complete(struct qeth_qdio_out_q *queue,
5849 unsigned int bidx, bool error, int budget)
5851 struct qeth_qdio_out_buffer *buffer = queue->bufs[bidx];
5852 u8 sflags = buffer->buffer->element[15].sflags;
5853 struct qeth_card *card = queue->card;
5855 if (queue->bufstates && (queue->bufstates[bidx].flags &
5856 QDIO_OUTBUF_STATE_FLAG_PENDING)) {
5857 WARN_ON_ONCE(card->options.cq != QETH_CQ_ENABLED);
5859 QETH_CARD_TEXT_(card, 5, "pel%u", bidx);
5861 switch (atomic_cmpxchg(&buffer->state,
5862 QETH_QDIO_BUF_PRIMED,
5863 QETH_QDIO_BUF_PENDING)) {
5864 case QETH_QDIO_BUF_PRIMED:
5865 /* We have initial ownership, no QAOB (yet): */
5866 qeth_notify_skbs(queue, buffer, TX_NOTIFY_PENDING);
5868 /* Handle race with qeth_qdio_handle_aob(): */
5869 switch (atomic_xchg(&buffer->state,
5870 QETH_QDIO_BUF_NEED_QAOB)) {
5871 case QETH_QDIO_BUF_PENDING:
5872 /* No concurrent QAOB notification. */
5874 /* Prepare the queue slot for immediate re-use: */
5875 qeth_scrub_qdio_buffer(buffer->buffer, queue->max_elements);
5876 if (qeth_init_qdio_out_buf(queue, bidx)) {
5877 QETH_CARD_TEXT(card, 2, "outofbuf");
5878 qeth_schedule_recovery(card);
5881 list_add(&buffer->list_entry,
5882 &queue->pending_bufs);
5883 /* Skip clearing the buffer: */
5885 case QETH_QDIO_BUF_QAOB_OK:
5886 qeth_notify_skbs(queue, buffer,
5887 TX_NOTIFY_DELAYED_OK);
5890 case QETH_QDIO_BUF_QAOB_ERROR:
5891 qeth_notify_skbs(queue, buffer,
5892 TX_NOTIFY_DELAYED_GENERALERROR);
5900 case QETH_QDIO_BUF_QAOB_OK:
5901 /* qeth_qdio_handle_aob() already received a QAOB: */
5902 qeth_notify_skbs(queue, buffer, TX_NOTIFY_OK);
5905 case QETH_QDIO_BUF_QAOB_ERROR:
5906 /* qeth_qdio_handle_aob() already received a QAOB: */
5907 qeth_notify_skbs(queue, buffer, TX_NOTIFY_GENERALERROR);
5913 } else if (card->options.cq == QETH_CQ_ENABLED) {
5914 qeth_notify_skbs(queue, buffer,
5915 qeth_compute_cq_notification(sflags, 0));
5918 qeth_clear_output_buffer(queue, buffer, error, budget);
5921 static int qeth_tx_poll(struct napi_struct *napi, int budget)
5923 struct qeth_qdio_out_q *queue = qeth_napi_to_out_queue(napi);
5924 unsigned int queue_no = queue->queue_no;
5925 struct qeth_card *card = queue->card;
5926 struct net_device *dev = card->dev;
5927 unsigned int work_done = 0;
5928 struct netdev_queue *txq;
5930 txq = netdev_get_tx_queue(dev, qeth_iqd_translate_txq(dev, queue_no));
5933 unsigned int start, error, i;
5934 unsigned int packets = 0;
5935 unsigned int bytes = 0;
5938 qeth_tx_complete_pending_bufs(card, queue, false);
5940 if (qeth_out_queue_is_empty(queue)) {
5941 napi_complete(napi);
5945 /* Give the CPU a breather: */
5946 if (work_done >= QDIO_MAX_BUFFERS_PER_Q) {
5947 QETH_TXQ_STAT_INC(queue, completion_yield);
5948 if (napi_complete_done(napi, 0))
5949 napi_schedule(napi);
5953 completed = qdio_inspect_queue(CARD_DDEV(card), queue_no, false,
5955 if (completed <= 0) {
5956 /* Ensure we see TX completion for pending work: */
5957 if (napi_complete_done(napi, 0))
5958 qeth_tx_arm_timer(queue, QETH_TX_TIMER_USECS);
5962 for (i = start; i < start + completed; i++) {
5963 struct qeth_qdio_out_buffer *buffer;
5964 unsigned int bidx = QDIO_BUFNR(i);
5966 buffer = queue->bufs[bidx];
5967 packets += buffer->frames;
5968 bytes += buffer->bytes;
5970 qeth_handle_send_error(card, buffer, error);
5971 qeth_iqd_tx_complete(queue, bidx, error, budget);
5974 netdev_tx_completed_queue(txq, packets, bytes);
5975 atomic_sub(completed, &queue->used_buffers);
5976 work_done += completed;
5978 /* xmit may have observed the full-condition, but not yet
5979 * stopped the txq. In which case the code below won't trigger.
5980 * So before returning, xmit will re-check the txq's fill level
5981 * and wake it up if needed.
5983 if (netif_tx_queue_stopped(txq) &&
5984 !qeth_out_queue_is_full(queue))
5985 netif_tx_wake_queue(txq);
5989 static int qeth_setassparms_inspect_rc(struct qeth_ipa_cmd *cmd)
5991 if (!cmd->hdr.return_code)
5992 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
5993 return cmd->hdr.return_code;
5996 static int qeth_setassparms_get_caps_cb(struct qeth_card *card,
5997 struct qeth_reply *reply,
6000 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
6001 struct qeth_ipa_caps *caps = reply->param;
6003 if (qeth_setassparms_inspect_rc(cmd))
6006 caps->supported = cmd->data.setassparms.data.caps.supported;
6007 caps->enabled = cmd->data.setassparms.data.caps.enabled;
6011 int qeth_setassparms_cb(struct qeth_card *card,
6012 struct qeth_reply *reply, unsigned long data)
6014 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
6016 QETH_CARD_TEXT(card, 4, "defadpcb");
6018 if (cmd->hdr.return_code)
6021 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6022 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6023 card->options.ipa4.enabled = cmd->hdr.assists.enabled;
6024 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6025 card->options.ipa6.enabled = cmd->hdr.assists.enabled;
6028 EXPORT_SYMBOL_GPL(qeth_setassparms_cb);
6030 struct qeth_cmd_buffer *qeth_get_setassparms_cmd(struct qeth_card *card,
6031 enum qeth_ipa_funcs ipa_func,
6033 unsigned int data_length,
6034 enum qeth_prot_versions prot)
6036 struct qeth_ipacmd_setassparms *setassparms;
6037 struct qeth_ipacmd_setassparms_hdr *hdr;
6038 struct qeth_cmd_buffer *iob;
6040 QETH_CARD_TEXT(card, 4, "getasscm");
6041 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SETASSPARMS, prot,
6043 offsetof(struct qeth_ipacmd_setassparms,
6048 setassparms = &__ipa_cmd(iob)->data.setassparms;
6049 setassparms->assist_no = ipa_func;
6051 hdr = &setassparms->hdr;
6052 hdr->length = sizeof(*hdr) + data_length;
6053 hdr->command_code = cmd_code;
6056 EXPORT_SYMBOL_GPL(qeth_get_setassparms_cmd);
6058 int qeth_send_simple_setassparms_prot(struct qeth_card *card,
6059 enum qeth_ipa_funcs ipa_func,
6060 u16 cmd_code, u32 *data,
6061 enum qeth_prot_versions prot)
6063 unsigned int length = data ? SETASS_DATA_SIZEOF(flags_32bit) : 0;
6064 struct qeth_cmd_buffer *iob;
6066 QETH_CARD_TEXT_(card, 4, "simassp%i", prot);
6067 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code, length, prot);
6072 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = *data;
6073 return qeth_send_ipa_cmd(card, iob, qeth_setassparms_cb, NULL);
6075 EXPORT_SYMBOL_GPL(qeth_send_simple_setassparms_prot);
6077 static void qeth_unregister_dbf_views(void)
6081 for (x = 0; x < QETH_DBF_INFOS; x++) {
6082 debug_unregister(qeth_dbf[x].id);
6083 qeth_dbf[x].id = NULL;
6087 void qeth_dbf_longtext(debug_info_t *id, int level, char *fmt, ...)
6089 char dbf_txt_buf[32];
6092 if (!debug_level_enabled(id, level))
6094 va_start(args, fmt);
6095 vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
6097 debug_text_event(id, level, dbf_txt_buf);
6099 EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
6101 static int qeth_register_dbf_views(void)
6106 for (x = 0; x < QETH_DBF_INFOS; x++) {
6107 /* register the areas */
6108 qeth_dbf[x].id = debug_register(qeth_dbf[x].name,
6112 if (qeth_dbf[x].id == NULL) {
6113 qeth_unregister_dbf_views();
6117 /* register a view */
6118 ret = debug_register_view(qeth_dbf[x].id, qeth_dbf[x].view);
6120 qeth_unregister_dbf_views();
6124 /* set a passing level */
6125 debug_set_level(qeth_dbf[x].id, qeth_dbf[x].level);
6131 static DEFINE_MUTEX(qeth_mod_mutex); /* for synchronized module loading */
6133 int qeth_core_load_discipline(struct qeth_card *card,
6134 enum qeth_discipline_id discipline)
6136 mutex_lock(&qeth_mod_mutex);
6137 switch (discipline) {
6138 case QETH_DISCIPLINE_LAYER3:
6139 card->discipline = try_then_request_module(
6140 symbol_get(qeth_l3_discipline), "qeth_l3");
6142 case QETH_DISCIPLINE_LAYER2:
6143 card->discipline = try_then_request_module(
6144 symbol_get(qeth_l2_discipline), "qeth_l2");
6149 mutex_unlock(&qeth_mod_mutex);
6151 if (!card->discipline) {
6152 dev_err(&card->gdev->dev, "There is no kernel module to "
6153 "support discipline %d\n", discipline);
6157 card->options.layer = discipline;
6161 void qeth_core_free_discipline(struct qeth_card *card)
6163 if (IS_LAYER2(card))
6164 symbol_put(qeth_l2_discipline);
6166 symbol_put(qeth_l3_discipline);
6167 card->options.layer = QETH_DISCIPLINE_UNDETERMINED;
6168 card->discipline = NULL;
6171 const struct device_type qeth_generic_devtype = {
6172 .name = "qeth_generic",
6173 .groups = qeth_generic_attr_groups,
6175 EXPORT_SYMBOL_GPL(qeth_generic_devtype);
6177 static const struct device_type qeth_osn_devtype = {
6179 .groups = qeth_osn_attr_groups,
6182 #define DBF_NAME_LEN 20
6184 struct qeth_dbf_entry {
6185 char dbf_name[DBF_NAME_LEN];
6186 debug_info_t *dbf_info;
6187 struct list_head dbf_list;
6190 static LIST_HEAD(qeth_dbf_list);
6191 static DEFINE_MUTEX(qeth_dbf_list_mutex);
6193 static debug_info_t *qeth_get_dbf_entry(char *name)
6195 struct qeth_dbf_entry *entry;
6196 debug_info_t *rc = NULL;
6198 mutex_lock(&qeth_dbf_list_mutex);
6199 list_for_each_entry(entry, &qeth_dbf_list, dbf_list) {
6200 if (strcmp(entry->dbf_name, name) == 0) {
6201 rc = entry->dbf_info;
6205 mutex_unlock(&qeth_dbf_list_mutex);
6209 static int qeth_add_dbf_entry(struct qeth_card *card, char *name)
6211 struct qeth_dbf_entry *new_entry;
6213 card->debug = debug_register(name, 2, 1, 8);
6215 QETH_DBF_TEXT_(SETUP, 2, "%s", "qcdbf");
6218 if (debug_register_view(card->debug, &debug_hex_ascii_view))
6220 new_entry = kzalloc(sizeof(struct qeth_dbf_entry), GFP_KERNEL);
6223 strncpy(new_entry->dbf_name, name, DBF_NAME_LEN);
6224 new_entry->dbf_info = card->debug;
6225 mutex_lock(&qeth_dbf_list_mutex);
6226 list_add(&new_entry->dbf_list, &qeth_dbf_list);
6227 mutex_unlock(&qeth_dbf_list_mutex);
6232 debug_unregister(card->debug);
6237 static void qeth_clear_dbf_list(void)
6239 struct qeth_dbf_entry *entry, *tmp;
6241 mutex_lock(&qeth_dbf_list_mutex);
6242 list_for_each_entry_safe(entry, tmp, &qeth_dbf_list, dbf_list) {
6243 list_del(&entry->dbf_list);
6244 debug_unregister(entry->dbf_info);
6247 mutex_unlock(&qeth_dbf_list_mutex);
6250 static struct net_device *qeth_alloc_netdev(struct qeth_card *card)
6252 struct net_device *dev;
6253 struct qeth_priv *priv;
6255 switch (card->info.type) {
6256 case QETH_CARD_TYPE_IQD:
6257 dev = alloc_netdev_mqs(sizeof(*priv), "hsi%d", NET_NAME_UNKNOWN,
6258 ether_setup, QETH_MAX_OUT_QUEUES, 1);
6260 case QETH_CARD_TYPE_OSM:
6261 dev = alloc_etherdev(sizeof(*priv));
6263 case QETH_CARD_TYPE_OSN:
6264 dev = alloc_netdev(sizeof(*priv), "osn%d", NET_NAME_UNKNOWN,
6268 dev = alloc_etherdev_mqs(sizeof(*priv), QETH_MAX_OUT_QUEUES, 1);
6274 priv = netdev_priv(dev);
6275 priv->rx_copybreak = QETH_RX_COPYBREAK;
6276 priv->tx_wanted_queues = IS_IQD(card) ? QETH_IQD_MIN_TXQ : 1;
6278 dev->ml_priv = card;
6279 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6280 dev->min_mtu = IS_OSN(card) ? 64 : 576;
6281 /* initialized when device first goes online: */
6284 SET_NETDEV_DEV(dev, &card->gdev->dev);
6285 netif_carrier_off(dev);
6288 dev->ethtool_ops = &qeth_osn_ethtool_ops;
6290 dev->ethtool_ops = &qeth_ethtool_ops;
6291 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
6292 dev->hw_features |= NETIF_F_SG;
6293 dev->vlan_features |= NETIF_F_SG;
6295 dev->features |= NETIF_F_SG;
6301 struct net_device *qeth_clone_netdev(struct net_device *orig)
6303 struct net_device *clone = qeth_alloc_netdev(orig->ml_priv);
6308 clone->dev_port = orig->dev_port;
6312 static int qeth_core_probe_device(struct ccwgroup_device *gdev)
6314 struct qeth_card *card;
6317 enum qeth_discipline_id enforced_disc;
6318 char dbf_name[DBF_NAME_LEN];
6320 QETH_DBF_TEXT(SETUP, 2, "probedev");
6323 if (!get_device(dev))
6326 QETH_DBF_TEXT_(SETUP, 2, "%s", dev_name(&gdev->dev));
6328 card = qeth_alloc_card(gdev);
6330 QETH_DBF_TEXT_(SETUP, 2, "1err%d", -ENOMEM);
6335 snprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s",
6336 dev_name(&gdev->dev));
6337 card->debug = qeth_get_dbf_entry(dbf_name);
6339 rc = qeth_add_dbf_entry(card, dbf_name);
6344 qeth_setup_card(card);
6345 card->dev = qeth_alloc_netdev(card);
6351 qeth_determine_capabilities(card);
6352 qeth_set_blkt_defaults(card);
6354 card->qdio.no_out_queues = card->dev->num_tx_queues;
6355 rc = qeth_update_from_chp_desc(card);
6359 enforced_disc = qeth_enforce_discipline(card);
6360 switch (enforced_disc) {
6361 case QETH_DISCIPLINE_UNDETERMINED:
6362 gdev->dev.type = &qeth_generic_devtype;
6365 card->info.layer_enforced = true;
6366 /* It's so early that we don't need the discipline_mutex yet. */
6367 rc = qeth_core_load_discipline(card, enforced_disc);
6371 gdev->dev.type = IS_OSN(card) ? &qeth_osn_devtype :
6372 card->discipline->devtype;
6373 rc = card->discipline->setup(card->gdev);
6382 qeth_core_free_discipline(card);
6385 free_netdev(card->dev);
6387 qeth_core_free_card(card);
6393 static void qeth_core_remove_device(struct ccwgroup_device *gdev)
6395 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
6397 QETH_CARD_TEXT(card, 2, "removedv");
6399 mutex_lock(&card->discipline_mutex);
6400 if (card->discipline) {
6401 card->discipline->remove(gdev);
6402 qeth_core_free_discipline(card);
6404 mutex_unlock(&card->discipline_mutex);
6406 qeth_free_qdio_queues(card);
6408 free_netdev(card->dev);
6409 qeth_core_free_card(card);
6410 put_device(&gdev->dev);
6413 static int qeth_core_set_online(struct ccwgroup_device *gdev)
6415 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
6417 enum qeth_discipline_id def_discipline;
6419 mutex_lock(&card->discipline_mutex);
6420 if (!card->discipline) {
6421 def_discipline = IS_IQD(card) ? QETH_DISCIPLINE_LAYER3 :
6422 QETH_DISCIPLINE_LAYER2;
6423 rc = qeth_core_load_discipline(card, def_discipline);
6426 rc = card->discipline->setup(card->gdev);
6428 qeth_core_free_discipline(card);
6433 rc = qeth_set_online(card, card->discipline);
6436 mutex_unlock(&card->discipline_mutex);
6440 static int qeth_core_set_offline(struct ccwgroup_device *gdev)
6442 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
6445 mutex_lock(&card->discipline_mutex);
6446 rc = qeth_set_offline(card, card->discipline, false);
6447 mutex_unlock(&card->discipline_mutex);
6452 static void qeth_core_shutdown(struct ccwgroup_device *gdev)
6454 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
6456 qeth_set_allowed_threads(card, 0, 1);
6457 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
6458 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
6459 qeth_qdio_clear_card(card, 0);
6460 qeth_drain_output_queues(card);
6461 qdio_free(CARD_DDEV(card));
6464 static ssize_t group_store(struct device_driver *ddrv, const char *buf,
6469 err = ccwgroup_create_dev(qeth_core_root_dev, to_ccwgroupdrv(ddrv), 3,
6472 return err ? err : count;
6474 static DRIVER_ATTR_WO(group);
6476 static struct attribute *qeth_drv_attrs[] = {
6477 &driver_attr_group.attr,
6480 static struct attribute_group qeth_drv_attr_group = {
6481 .attrs = qeth_drv_attrs,
6483 static const struct attribute_group *qeth_drv_attr_groups[] = {
6484 &qeth_drv_attr_group,
6488 static struct ccwgroup_driver qeth_core_ccwgroup_driver = {
6490 .groups = qeth_drv_attr_groups,
6491 .owner = THIS_MODULE,
6494 .ccw_driver = &qeth_ccw_driver,
6495 .setup = qeth_core_probe_device,
6496 .remove = qeth_core_remove_device,
6497 .set_online = qeth_core_set_online,
6498 .set_offline = qeth_core_set_offline,
6499 .shutdown = qeth_core_shutdown,
6502 struct qeth_card *qeth_get_card_by_busid(char *bus_id)
6504 struct ccwgroup_device *gdev;
6505 struct qeth_card *card;
6507 gdev = get_ccwgroupdev_by_busid(&qeth_core_ccwgroup_driver, bus_id);
6511 card = dev_get_drvdata(&gdev->dev);
6512 put_device(&gdev->dev);
6515 EXPORT_SYMBOL_GPL(qeth_get_card_by_busid);
6517 int qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6519 struct qeth_card *card = dev->ml_priv;
6520 struct mii_ioctl_data *mii_data;
6524 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
6525 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
6527 case SIOC_QETH_GET_CARD_TYPE:
6528 if ((IS_OSD(card) || IS_OSM(card) || IS_OSX(card)) &&
6533 mii_data = if_mii(rq);
6534 mii_data->phy_id = 0;
6537 mii_data = if_mii(rq);
6538 if (mii_data->phy_id != 0)
6541 mii_data->val_out = qeth_mdio_read(dev,
6542 mii_data->phy_id, mii_data->reg_num);
6544 case SIOC_QETH_QUERY_OAT:
6545 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
6548 if (card->discipline->do_ioctl)
6549 rc = card->discipline->do_ioctl(dev, rq, cmd);
6554 QETH_CARD_TEXT_(card, 2, "ioce%x", rc);
6557 EXPORT_SYMBOL_GPL(qeth_do_ioctl);
6559 static int qeth_start_csum_cb(struct qeth_card *card, struct qeth_reply *reply,
6562 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
6563 u32 *features = reply->param;
6565 if (qeth_setassparms_inspect_rc(cmd))
6568 *features = cmd->data.setassparms.data.flags_32bit;
6572 static int qeth_set_csum_off(struct qeth_card *card, enum qeth_ipa_funcs cstype,
6573 enum qeth_prot_versions prot)
6575 return qeth_send_simple_setassparms_prot(card, cstype, IPA_CMD_ASS_STOP,
6579 static int qeth_set_csum_on(struct qeth_card *card, enum qeth_ipa_funcs cstype,
6580 enum qeth_prot_versions prot, u8 *lp2lp)
6582 u32 required_features = QETH_IPA_CHECKSUM_UDP | QETH_IPA_CHECKSUM_TCP;
6583 struct qeth_cmd_buffer *iob;
6584 struct qeth_ipa_caps caps;
6588 /* some L3 HW requires combined L3+L4 csum offload: */
6589 if (IS_LAYER3(card) && prot == QETH_PROT_IPV4 &&
6590 cstype == IPA_OUTBOUND_CHECKSUM)
6591 required_features |= QETH_IPA_CHECKSUM_IP_HDR;
6593 iob = qeth_get_setassparms_cmd(card, cstype, IPA_CMD_ASS_START, 0,
6598 rc = qeth_send_ipa_cmd(card, iob, qeth_start_csum_cb, &features);
6602 if ((required_features & features) != required_features) {
6603 qeth_set_csum_off(card, cstype, prot);
6607 iob = qeth_get_setassparms_cmd(card, cstype, IPA_CMD_ASS_ENABLE,
6608 SETASS_DATA_SIZEOF(flags_32bit),
6611 qeth_set_csum_off(card, cstype, prot);
6615 if (features & QETH_IPA_CHECKSUM_LP2LP)
6616 required_features |= QETH_IPA_CHECKSUM_LP2LP;
6617 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = required_features;
6618 rc = qeth_send_ipa_cmd(card, iob, qeth_setassparms_get_caps_cb, &caps);
6620 qeth_set_csum_off(card, cstype, prot);
6624 if (!qeth_ipa_caps_supported(&caps, required_features) ||
6625 !qeth_ipa_caps_enabled(&caps, required_features)) {
6626 qeth_set_csum_off(card, cstype, prot);
6630 dev_info(&card->gdev->dev, "HW Checksumming (%sbound IPv%d) enabled\n",
6631 cstype == IPA_INBOUND_CHECKSUM ? "in" : "out", prot);
6634 *lp2lp = qeth_ipa_caps_enabled(&caps, QETH_IPA_CHECKSUM_LP2LP);
6639 static int qeth_set_ipa_csum(struct qeth_card *card, bool on, int cstype,
6640 enum qeth_prot_versions prot, u8 *lp2lp)
6642 return on ? qeth_set_csum_on(card, cstype, prot, lp2lp) :
6643 qeth_set_csum_off(card, cstype, prot);
6646 static int qeth_start_tso_cb(struct qeth_card *card, struct qeth_reply *reply,
6649 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
6650 struct qeth_tso_start_data *tso_data = reply->param;
6652 if (qeth_setassparms_inspect_rc(cmd))
6655 tso_data->mss = cmd->data.setassparms.data.tso.mss;
6656 tso_data->supported = cmd->data.setassparms.data.tso.supported;
6660 static int qeth_set_tso_off(struct qeth_card *card,
6661 enum qeth_prot_versions prot)
6663 return qeth_send_simple_setassparms_prot(card, IPA_OUTBOUND_TSO,
6664 IPA_CMD_ASS_STOP, NULL, prot);
6667 static int qeth_set_tso_on(struct qeth_card *card,
6668 enum qeth_prot_versions prot)
6670 struct qeth_tso_start_data tso_data;
6671 struct qeth_cmd_buffer *iob;
6672 struct qeth_ipa_caps caps;
6675 iob = qeth_get_setassparms_cmd(card, IPA_OUTBOUND_TSO,
6676 IPA_CMD_ASS_START, 0, prot);
6680 rc = qeth_send_ipa_cmd(card, iob, qeth_start_tso_cb, &tso_data);
6684 if (!tso_data.mss || !(tso_data.supported & QETH_IPA_LARGE_SEND_TCP)) {
6685 qeth_set_tso_off(card, prot);
6689 iob = qeth_get_setassparms_cmd(card, IPA_OUTBOUND_TSO,
6691 SETASS_DATA_SIZEOF(caps), prot);
6693 qeth_set_tso_off(card, prot);
6697 /* enable TSO capability */
6698 __ipa_cmd(iob)->data.setassparms.data.caps.enabled =
6699 QETH_IPA_LARGE_SEND_TCP;
6700 rc = qeth_send_ipa_cmd(card, iob, qeth_setassparms_get_caps_cb, &caps);
6702 qeth_set_tso_off(card, prot);
6706 if (!qeth_ipa_caps_supported(&caps, QETH_IPA_LARGE_SEND_TCP) ||
6707 !qeth_ipa_caps_enabled(&caps, QETH_IPA_LARGE_SEND_TCP)) {
6708 qeth_set_tso_off(card, prot);
6712 dev_info(&card->gdev->dev, "TSOv%u enabled (MSS: %u)\n", prot,
6717 static int qeth_set_ipa_tso(struct qeth_card *card, bool on,
6718 enum qeth_prot_versions prot)
6720 return on ? qeth_set_tso_on(card, prot) : qeth_set_tso_off(card, prot);
6723 static int qeth_set_ipa_rx_csum(struct qeth_card *card, bool on)
6725 int rc_ipv4 = (on) ? -EOPNOTSUPP : 0;
6728 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
6729 rc_ipv4 = qeth_set_ipa_csum(card, on, IPA_INBOUND_CHECKSUM,
6730 QETH_PROT_IPV4, NULL);
6731 if (!qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6))
6732 /* no/one Offload Assist available, so the rc is trivial */
6735 rc_ipv6 = qeth_set_ipa_csum(card, on, IPA_INBOUND_CHECKSUM,
6736 QETH_PROT_IPV6, NULL);
6739 /* enable: success if any Assist is active */
6740 return (rc_ipv6) ? rc_ipv4 : 0;
6742 /* disable: failure if any Assist is still active */
6743 return (rc_ipv6) ? rc_ipv6 : rc_ipv4;
6747 * qeth_enable_hw_features() - (Re-)Enable HW functions for device features
6748 * @dev: a net_device
6750 void qeth_enable_hw_features(struct net_device *dev)
6752 struct qeth_card *card = dev->ml_priv;
6753 netdev_features_t features;
6755 features = dev->features;
6756 /* force-off any feature that might need an IPA sequence.
6757 * netdev_update_features() will restart them.
6759 dev->features &= ~dev->hw_features;
6760 /* toggle VLAN filter, so that VIDs are re-programmed: */
6761 if (IS_LAYER2(card) && IS_VM_NIC(card)) {
6762 dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
6763 dev->wanted_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
6765 netdev_update_features(dev);
6766 if (features != dev->features)
6767 dev_warn(&card->gdev->dev,
6768 "Device recovery failed to restore all offload features\n");
6770 EXPORT_SYMBOL_GPL(qeth_enable_hw_features);
6772 static void qeth_check_restricted_features(struct qeth_card *card,
6773 netdev_features_t changed,
6774 netdev_features_t actual)
6776 netdev_features_t ipv6_features = NETIF_F_TSO6;
6777 netdev_features_t ipv4_features = NETIF_F_TSO;
6779 if (!card->info.has_lp2lp_cso_v6)
6780 ipv6_features |= NETIF_F_IPV6_CSUM;
6781 if (!card->info.has_lp2lp_cso_v4)
6782 ipv4_features |= NETIF_F_IP_CSUM;
6784 if ((changed & ipv6_features) && !(actual & ipv6_features))
6785 qeth_flush_local_addrs6(card);
6786 if ((changed & ipv4_features) && !(actual & ipv4_features))
6787 qeth_flush_local_addrs4(card);
6790 int qeth_set_features(struct net_device *dev, netdev_features_t features)
6792 struct qeth_card *card = dev->ml_priv;
6793 netdev_features_t changed = dev->features ^ features;
6796 QETH_CARD_TEXT(card, 2, "setfeat");
6797 QETH_CARD_HEX(card, 2, &features, sizeof(features));
6799 if ((changed & NETIF_F_IP_CSUM)) {
6800 rc = qeth_set_ipa_csum(card, features & NETIF_F_IP_CSUM,
6801 IPA_OUTBOUND_CHECKSUM, QETH_PROT_IPV4,
6802 &card->info.has_lp2lp_cso_v4);
6804 changed ^= NETIF_F_IP_CSUM;
6806 if (changed & NETIF_F_IPV6_CSUM) {
6807 rc = qeth_set_ipa_csum(card, features & NETIF_F_IPV6_CSUM,
6808 IPA_OUTBOUND_CHECKSUM, QETH_PROT_IPV6,
6809 &card->info.has_lp2lp_cso_v6);
6811 changed ^= NETIF_F_IPV6_CSUM;
6813 if (changed & NETIF_F_RXCSUM) {
6814 rc = qeth_set_ipa_rx_csum(card, features & NETIF_F_RXCSUM);
6816 changed ^= NETIF_F_RXCSUM;
6818 if (changed & NETIF_F_TSO) {
6819 rc = qeth_set_ipa_tso(card, features & NETIF_F_TSO,
6822 changed ^= NETIF_F_TSO;
6824 if (changed & NETIF_F_TSO6) {
6825 rc = qeth_set_ipa_tso(card, features & NETIF_F_TSO6,
6828 changed ^= NETIF_F_TSO6;
6831 qeth_check_restricted_features(card, dev->features ^ features,
6832 dev->features ^ changed);
6834 /* everything changed successfully? */
6835 if ((dev->features ^ features) == changed)
6837 /* something went wrong. save changed features and return error */
6838 dev->features ^= changed;
6841 EXPORT_SYMBOL_GPL(qeth_set_features);
6843 netdev_features_t qeth_fix_features(struct net_device *dev,
6844 netdev_features_t features)
6846 struct qeth_card *card = dev->ml_priv;
6848 QETH_CARD_TEXT(card, 2, "fixfeat");
6849 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
6850 features &= ~NETIF_F_IP_CSUM;
6851 if (!qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6))
6852 features &= ~NETIF_F_IPV6_CSUM;
6853 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM) &&
6854 !qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6))
6855 features &= ~NETIF_F_RXCSUM;
6856 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
6857 features &= ~NETIF_F_TSO;
6858 if (!qeth_is_supported6(card, IPA_OUTBOUND_TSO))
6859 features &= ~NETIF_F_TSO6;
6861 QETH_CARD_HEX(card, 2, &features, sizeof(features));
6864 EXPORT_SYMBOL_GPL(qeth_fix_features);
6866 netdev_features_t qeth_features_check(struct sk_buff *skb,
6867 struct net_device *dev,
6868 netdev_features_t features)
6870 struct qeth_card *card = dev->ml_priv;
6872 /* Traffic with local next-hop is not eligible for some offloads: */
6873 if (skb->ip_summed == CHECKSUM_PARTIAL &&
6874 READ_ONCE(card->options.isolation) != ISOLATION_MODE_FWD) {
6875 netdev_features_t restricted = 0;
6877 if (skb_is_gso(skb) && !netif_needs_gso(skb, features))
6878 restricted |= NETIF_F_ALL_TSO;
6880 switch (vlan_get_protocol(skb)) {
6881 case htons(ETH_P_IP):
6882 if (!card->info.has_lp2lp_cso_v4)
6883 restricted |= NETIF_F_IP_CSUM;
6885 if (restricted && qeth_next_hop_is_local_v4(card, skb))
6886 features &= ~restricted;
6888 case htons(ETH_P_IPV6):
6889 if (!card->info.has_lp2lp_cso_v6)
6890 restricted |= NETIF_F_IPV6_CSUM;
6892 if (restricted && qeth_next_hop_is_local_v6(card, skb))
6893 features &= ~restricted;
6900 /* GSO segmentation builds skbs with
6901 * a (small) linear part for the headers, and
6902 * page frags for the data.
6903 * Compared to a linear skb, the header-only part consumes an
6904 * additional buffer element. This reduces buffer utilization, and
6905 * hurts throughput. So compress small segments into one element.
6907 if (netif_needs_gso(skb, features)) {
6908 /* match skb_segment(): */
6909 unsigned int doffset = skb->data - skb_mac_header(skb);
6910 unsigned int hsize = skb_shinfo(skb)->gso_size;
6911 unsigned int hroom = skb_headroom(skb);
6913 /* linearize only if resulting skb allocations are order-0: */
6914 if (SKB_DATA_ALIGN(hroom + doffset + hsize) <= SKB_MAX_HEAD(0))
6915 features &= ~NETIF_F_SG;
6918 return vlan_features_check(skb, features);
6920 EXPORT_SYMBOL_GPL(qeth_features_check);
6922 void qeth_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
6924 struct qeth_card *card = dev->ml_priv;
6925 struct qeth_qdio_out_q *queue;
6928 QETH_CARD_TEXT(card, 5, "getstat");
6930 stats->rx_packets = card->stats.rx_packets;
6931 stats->rx_bytes = card->stats.rx_bytes;
6932 stats->rx_errors = card->stats.rx_length_errors +
6933 card->stats.rx_frame_errors +
6934 card->stats.rx_fifo_errors;
6935 stats->rx_dropped = card->stats.rx_dropped_nomem +
6936 card->stats.rx_dropped_notsupp +
6937 card->stats.rx_dropped_runt;
6938 stats->multicast = card->stats.rx_multicast;
6939 stats->rx_length_errors = card->stats.rx_length_errors;
6940 stats->rx_frame_errors = card->stats.rx_frame_errors;
6941 stats->rx_fifo_errors = card->stats.rx_fifo_errors;
6943 for (i = 0; i < card->qdio.no_out_queues; i++) {
6944 queue = card->qdio.out_qs[i];
6946 stats->tx_packets += queue->stats.tx_packets;
6947 stats->tx_bytes += queue->stats.tx_bytes;
6948 stats->tx_errors += queue->stats.tx_errors;
6949 stats->tx_dropped += queue->stats.tx_dropped;
6952 EXPORT_SYMBOL_GPL(qeth_get_stats64);
6954 #define TC_IQD_UCAST 0
6955 static void qeth_iqd_set_prio_tc_map(struct net_device *dev,
6956 unsigned int ucast_txqs)
6960 /* IQD requires mcast traffic to be placed on a dedicated queue, and
6961 * qeth_iqd_select_queue() deals with this.
6962 * For unicast traffic, we defer the queue selection to the stack.
6963 * By installing a trivial prio map that spans over only the unicast
6964 * queues, we can encourage the stack to spread the ucast traffic evenly
6965 * without selecting the mcast queue.
6968 /* One traffic class, spanning over all active ucast queues: */
6969 netdev_set_num_tc(dev, 1);
6970 netdev_set_tc_queue(dev, TC_IQD_UCAST, ucast_txqs,
6971 QETH_IQD_MIN_UCAST_TXQ);
6973 /* Map all priorities to this traffic class: */
6974 for (prio = 0; prio <= TC_BITMASK; prio++)
6975 netdev_set_prio_tc_map(dev, prio, TC_IQD_UCAST);
6978 int qeth_set_real_num_tx_queues(struct qeth_card *card, unsigned int count)
6980 struct net_device *dev = card->dev;
6983 /* Per netif_setup_tc(), adjust the mapping first: */
6985 qeth_iqd_set_prio_tc_map(dev, count - 1);
6987 rc = netif_set_real_num_tx_queues(dev, count);
6989 if (rc && IS_IQD(card))
6990 qeth_iqd_set_prio_tc_map(dev, dev->real_num_tx_queues - 1);
6994 EXPORT_SYMBOL_GPL(qeth_set_real_num_tx_queues);
6996 u16 qeth_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
6997 u8 cast_type, struct net_device *sb_dev)
7001 if (cast_type != RTN_UNICAST)
7002 return QETH_IQD_MCAST_TXQ;
7003 if (dev->real_num_tx_queues == QETH_IQD_MIN_TXQ)
7004 return QETH_IQD_MIN_UCAST_TXQ;
7006 txq = netdev_pick_tx(dev, skb, sb_dev);
7007 return (txq == QETH_IQD_MCAST_TXQ) ? QETH_IQD_MIN_UCAST_TXQ : txq;
7009 EXPORT_SYMBOL_GPL(qeth_iqd_select_queue);
7011 int qeth_open(struct net_device *dev)
7013 struct qeth_card *card = dev->ml_priv;
7015 QETH_CARD_TEXT(card, 4, "qethopen");
7017 card->data.state = CH_STATE_UP;
7018 netif_tx_start_all_queues(dev);
7022 struct qeth_qdio_out_q *queue;
7025 qeth_for_each_output_queue(card, queue, i) {
7026 netif_tx_napi_add(dev, &queue->napi, qeth_tx_poll,
7028 napi_enable(&queue->napi);
7029 napi_schedule(&queue->napi);
7033 napi_enable(&card->napi);
7034 napi_schedule(&card->napi);
7035 /* kick-start the NAPI softirq: */
7040 EXPORT_SYMBOL_GPL(qeth_open);
7042 int qeth_stop(struct net_device *dev)
7044 struct qeth_card *card = dev->ml_priv;
7046 QETH_CARD_TEXT(card, 4, "qethstop");
7048 napi_disable(&card->napi);
7049 cancel_delayed_work_sync(&card->buffer_reclaim_work);
7050 qdio_stop_irq(CARD_DDEV(card));
7053 struct qeth_qdio_out_q *queue;
7056 /* Quiesce the NAPI instances: */
7057 qeth_for_each_output_queue(card, queue, i)
7058 napi_disable(&queue->napi);
7060 /* Stop .ndo_start_xmit, might still access queue->napi. */
7061 netif_tx_disable(dev);
7063 qeth_for_each_output_queue(card, queue, i) {
7064 del_timer_sync(&queue->timer);
7065 /* Queues may get re-allocated, so remove the NAPIs. */
7066 netif_napi_del(&queue->napi);
7069 netif_tx_disable(dev);
7074 EXPORT_SYMBOL_GPL(qeth_stop);
7076 static int __init qeth_core_init(void)
7080 pr_info("loading core functions\n");
7082 qeth_debugfs_root = debugfs_create_dir("qeth", NULL);
7084 rc = qeth_register_dbf_views();
7087 qeth_core_root_dev = root_device_register("qeth");
7088 rc = PTR_ERR_OR_ZERO(qeth_core_root_dev);
7091 qeth_core_header_cache =
7092 kmem_cache_create("qeth_hdr", QETH_HDR_CACHE_OBJ_SIZE,
7093 roundup_pow_of_two(QETH_HDR_CACHE_OBJ_SIZE),
7095 if (!qeth_core_header_cache) {
7099 qeth_qdio_outbuf_cache = kmem_cache_create("qeth_buf",
7100 sizeof(struct qeth_qdio_out_buffer), 0, 0, NULL);
7101 if (!qeth_qdio_outbuf_cache) {
7105 rc = ccw_driver_register(&qeth_ccw_driver);
7108 rc = ccwgroup_driver_register(&qeth_core_ccwgroup_driver);
7115 ccw_driver_unregister(&qeth_ccw_driver);
7117 kmem_cache_destroy(qeth_qdio_outbuf_cache);
7119 kmem_cache_destroy(qeth_core_header_cache);
7121 root_device_unregister(qeth_core_root_dev);
7123 qeth_unregister_dbf_views();
7125 debugfs_remove_recursive(qeth_debugfs_root);
7126 pr_err("Initializing the qeth device driver failed\n");
7130 static void __exit qeth_core_exit(void)
7132 qeth_clear_dbf_list();
7133 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
7134 ccw_driver_unregister(&qeth_ccw_driver);
7135 kmem_cache_destroy(qeth_qdio_outbuf_cache);
7136 kmem_cache_destroy(qeth_core_header_cache);
7137 root_device_unregister(qeth_core_root_dev);
7138 qeth_unregister_dbf_views();
7139 debugfs_remove_recursive(qeth_debugfs_root);
7140 pr_info("core functions removed\n");
7143 module_init(qeth_core_init);
7144 module_exit(qeth_core_exit);
7145 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
7146 MODULE_DESCRIPTION("qeth core functions");
7147 MODULE_LICENSE("GPL");