1
2
3
4
5
6
7
8
9
10#define KMSG_COMPONENT "qeth"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
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>
20#include <linux/io.h>
21#include <linux/ip.h>
22#include <linux/tcp.h>
23#include <linux/mii.h>
24#include <linux/mm.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>
33
34#include <net/iucv/af_iucv.h>
35#include <net/dsfield.h>
36#include <net/sock.h>
37
38#include <asm/ebcdic.h>
39#include <asm/chpid.h>
40#include <asm/sysinfo.h>
41#include <asm/diag.h>
42#include <asm/cio.h>
43#include <asm/ccwdev.h>
44#include <asm/cpcmd.h>
45
46#include "qeth_core.h"
47
48struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
49
50
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},
57};
58EXPORT_SYMBOL_GPL(qeth_dbf);
59
60struct kmem_cache *qeth_core_header_cache;
61EXPORT_SYMBOL_GPL(qeth_core_header_cache);
62static struct kmem_cache *qeth_qdio_outbuf_cache;
63
64static struct device *qeth_core_root_dev;
65static struct dentry *qeth_debugfs_root;
66static struct lock_class_key qdio_out_skb_queue_key;
67
68static void qeth_issue_next_read_cb(struct qeth_card *card,
69 struct qeth_cmd_buffer *iob,
70 unsigned int data_length);
71static int qeth_qdio_establish(struct qeth_card *);
72static void qeth_free_qdio_queues(struct qeth_card *card);
73static void qeth_notify_skbs(struct qeth_qdio_out_q *queue,
74 struct qeth_qdio_out_buffer *buf,
75 enum iucv_tx_notify notification);
76static void qeth_tx_complete_buf(struct qeth_qdio_out_buffer *buf, bool error,
77 int budget);
78static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q *, int);
79
80static void qeth_close_dev_handler(struct work_struct *work)
81{
82 struct qeth_card *card;
83
84 card = container_of(work, struct qeth_card, close_dev_work);
85 QETH_CARD_TEXT(card, 2, "cldevhdl");
86 ccwgroup_set_offline(card->gdev);
87}
88
89static const char *qeth_get_cardname(struct qeth_card *card)
90{
91 if (IS_VM_NIC(card)) {
92 switch (card->info.type) {
93 case QETH_CARD_TYPE_OSD:
94 return " Virtual NIC QDIO";
95 case QETH_CARD_TYPE_IQD:
96 return " Virtual NIC Hiper";
97 case QETH_CARD_TYPE_OSM:
98 return " Virtual NIC QDIO - OSM";
99 case QETH_CARD_TYPE_OSX:
100 return " Virtual NIC QDIO - OSX";
101 default:
102 return " unknown";
103 }
104 } else {
105 switch (card->info.type) {
106 case QETH_CARD_TYPE_OSD:
107 return " OSD Express";
108 case QETH_CARD_TYPE_IQD:
109 return " HiperSockets";
110 case QETH_CARD_TYPE_OSN:
111 return " OSN QDIO";
112 case QETH_CARD_TYPE_OSM:
113 return " OSM QDIO";
114 case QETH_CARD_TYPE_OSX:
115 return " OSX QDIO";
116 default:
117 return " unknown";
118 }
119 }
120 return " n/a";
121}
122
123
124const char *qeth_get_cardname_short(struct qeth_card *card)
125{
126 if (IS_VM_NIC(card)) {
127 switch (card->info.type) {
128 case QETH_CARD_TYPE_OSD:
129 return "Virt.NIC QDIO";
130 case QETH_CARD_TYPE_IQD:
131 return "Virt.NIC Hiper";
132 case QETH_CARD_TYPE_OSM:
133 return "Virt.NIC OSM";
134 case QETH_CARD_TYPE_OSX:
135 return "Virt.NIC OSX";
136 default:
137 return "unknown";
138 }
139 } else {
140 switch (card->info.type) {
141 case QETH_CARD_TYPE_OSD:
142 switch (card->info.link_type) {
143 case QETH_LINK_TYPE_FAST_ETH:
144 return "OSD_100";
145 case QETH_LINK_TYPE_HSTR:
146 return "HSTR";
147 case QETH_LINK_TYPE_GBIT_ETH:
148 return "OSD_1000";
149 case QETH_LINK_TYPE_10GBIT_ETH:
150 return "OSD_10GIG";
151 case QETH_LINK_TYPE_25GBIT_ETH:
152 return "OSD_25GIG";
153 case QETH_LINK_TYPE_LANE_ETH100:
154 return "OSD_FE_LANE";
155 case QETH_LINK_TYPE_LANE_TR:
156 return "OSD_TR_LANE";
157 case QETH_LINK_TYPE_LANE_ETH1000:
158 return "OSD_GbE_LANE";
159 case QETH_LINK_TYPE_LANE:
160 return "OSD_ATM_LANE";
161 default:
162 return "OSD_Express";
163 }
164 case QETH_CARD_TYPE_IQD:
165 return "HiperSockets";
166 case QETH_CARD_TYPE_OSN:
167 return "OSN";
168 case QETH_CARD_TYPE_OSM:
169 return "OSM_1000";
170 case QETH_CARD_TYPE_OSX:
171 return "OSX_10GIG";
172 default:
173 return "unknown";
174 }
175 }
176 return "n/a";
177}
178
179void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
180 int clear_start_mask)
181{
182 unsigned long flags;
183
184 spin_lock_irqsave(&card->thread_mask_lock, flags);
185 card->thread_allowed_mask = threads;
186 if (clear_start_mask)
187 card->thread_start_mask &= threads;
188 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
189 wake_up(&card->wait_q);
190}
191EXPORT_SYMBOL_GPL(qeth_set_allowed_threads);
192
193int qeth_threads_running(struct qeth_card *card, unsigned long threads)
194{
195 unsigned long flags;
196 int rc = 0;
197
198 spin_lock_irqsave(&card->thread_mask_lock, flags);
199 rc = (card->thread_running_mask & threads);
200 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
201 return rc;
202}
203EXPORT_SYMBOL_GPL(qeth_threads_running);
204
205static void qeth_clear_working_pool_list(struct qeth_card *card)
206{
207 struct qeth_buffer_pool_entry *pool_entry, *tmp;
208 struct qeth_qdio_q *queue = card->qdio.in_q;
209 unsigned int i;
210
211 QETH_CARD_TEXT(card, 5, "clwrklst");
212 list_for_each_entry_safe(pool_entry, tmp,
213 &card->qdio.in_buf_pool.entry_list, list)
214 list_del(&pool_entry->list);
215
216 for (i = 0; i < ARRAY_SIZE(queue->bufs); i++)
217 queue->bufs[i].pool_entry = NULL;
218}
219
220static void qeth_free_pool_entry(struct qeth_buffer_pool_entry *entry)
221{
222 unsigned int i;
223
224 for (i = 0; i < ARRAY_SIZE(entry->elements); i++) {
225 if (entry->elements[i])
226 __free_page(entry->elements[i]);
227 }
228
229 kfree(entry);
230}
231
232static void qeth_free_buffer_pool(struct qeth_card *card)
233{
234 struct qeth_buffer_pool_entry *entry, *tmp;
235
236 list_for_each_entry_safe(entry, tmp, &card->qdio.init_pool.entry_list,
237 init_list) {
238 list_del(&entry->init_list);
239 qeth_free_pool_entry(entry);
240 }
241}
242
243static struct qeth_buffer_pool_entry *qeth_alloc_pool_entry(unsigned int pages)
244{
245 struct qeth_buffer_pool_entry *entry;
246 unsigned int i;
247
248 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
249 if (!entry)
250 return NULL;
251
252 for (i = 0; i < pages; i++) {
253 entry->elements[i] = __dev_alloc_page(GFP_KERNEL);
254
255 if (!entry->elements[i]) {
256 qeth_free_pool_entry(entry);
257 return NULL;
258 }
259 }
260
261 return entry;
262}
263
264static int qeth_alloc_buffer_pool(struct qeth_card *card)
265{
266 unsigned int buf_elements = QETH_MAX_BUFFER_ELEMENTS(card);
267 unsigned int i;
268
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;
272
273 entry = qeth_alloc_pool_entry(buf_elements);
274 if (!entry) {
275 qeth_free_buffer_pool(card);
276 return -ENOMEM;
277 }
278
279 list_add(&entry->init_list, &card->qdio.init_pool.entry_list);
280 }
281 return 0;
282}
283
284int qeth_resize_buffer_pool(struct qeth_card *card, unsigned int count)
285{
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;
290 LIST_HEAD(entries);
291
292 QETH_CARD_TEXT(card, 2, "realcbp");
293
294
295 if (!card->qdio.in_q)
296 goto out;
297
298
299 while (delta < 0) {
300 entry = list_first_entry(&pool->entry_list,
301 struct qeth_buffer_pool_entry,
302 init_list);
303 list_del(&entry->init_list);
304 qeth_free_pool_entry(entry);
305
306 delta++;
307 }
308
309
310 while (delta > 0) {
311 entry = qeth_alloc_pool_entry(buf_elements);
312 if (!entry) {
313 list_for_each_entry_safe(entry, tmp, &entries,
314 init_list) {
315 list_del(&entry->init_list);
316 qeth_free_pool_entry(entry);
317 }
318
319 return -ENOMEM;
320 }
321
322 list_add(&entry->init_list, &entries);
323
324 delta--;
325 }
326
327 list_splice(&entries, &pool->entry_list);
328
329out:
330 card->qdio.in_buf_pool.buf_count = count;
331 pool->buf_count = count;
332 return 0;
333}
334EXPORT_SYMBOL_GPL(qeth_resize_buffer_pool);
335
336static void qeth_free_qdio_queue(struct qeth_qdio_q *q)
337{
338 if (!q)
339 return;
340
341 qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
342 kfree(q);
343}
344
345static struct qeth_qdio_q *qeth_alloc_qdio_queue(void)
346{
347 struct qeth_qdio_q *q = kzalloc(sizeof(*q), GFP_KERNEL);
348 int i;
349
350 if (!q)
351 return NULL;
352
353 if (qdio_alloc_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q)) {
354 kfree(q);
355 return NULL;
356 }
357
358 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
359 q->bufs[i].buffer = q->qdio_bufs[i];
360
361 QETH_DBF_HEX(SETUP, 2, &q, sizeof(void *));
362 return q;
363}
364
365static int qeth_cq_init(struct qeth_card *card)
366{
367 int rc;
368
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,
376 127);
377 if (rc) {
378 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
379 goto out;
380 }
381 }
382 rc = 0;
383out:
384 return rc;
385}
386
387static int qeth_alloc_cq(struct qeth_card *card)
388{
389 int rc;
390
391 if (card->options.cq == QETH_CQ_ENABLED) {
392 int i;
393 struct qdio_outbuf_state *outbuf_states;
394
395 QETH_CARD_TEXT(card, 2, "cqon");
396 card->qdio.c_q = qeth_alloc_qdio_queue();
397 if (!card->qdio.c_q) {
398 rc = -1;
399 goto kmsg_out;
400 }
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),
406 GFP_KERNEL);
407 outbuf_states = card->qdio.out_bufstates;
408 if (outbuf_states == NULL) {
409 rc = -1;
410 goto free_cq_out;
411 }
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;
415 }
416 } else {
417 QETH_CARD_TEXT(card, 2, "nocq");
418 card->qdio.c_q = NULL;
419 card->qdio.no_in_queues = 1;
420 }
421 QETH_CARD_TEXT_(card, 2, "iqc%d", card->qdio.no_in_queues);
422 rc = 0;
423out:
424 return rc;
425free_cq_out:
426 qeth_free_qdio_queue(card->qdio.c_q);
427 card->qdio.c_q = NULL;
428kmsg_out:
429 dev_err(&card->gdev->dev, "Failed to create completion queue\n");
430 goto out;
431}
432
433static void qeth_free_cq(struct qeth_card *card)
434{
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;
439 }
440 kfree(card->qdio.out_bufstates);
441 card->qdio.out_bufstates = NULL;
442}
443
444static enum iucv_tx_notify qeth_compute_cq_notification(int sbalf15,
445 int delayed)
446{
447 enum iucv_tx_notify n;
448
449 switch (sbalf15) {
450 case 0:
451 n = delayed ? TX_NOTIFY_DELAYED_OK : TX_NOTIFY_OK;
452 break;
453 case 4:
454 case 16:
455 case 17:
456 case 18:
457 n = delayed ? TX_NOTIFY_DELAYED_UNREACHABLE :
458 TX_NOTIFY_UNREACHABLE;
459 break;
460 default:
461 n = delayed ? TX_NOTIFY_DELAYED_GENERALERROR :
462 TX_NOTIFY_GENERALERROR;
463 break;
464 }
465
466 return n;
467}
468
469static void qeth_cleanup_handled_pending(struct qeth_qdio_out_q *q, int bidx,
470 int forced_cleanup)
471{
472 if (q->card->options.cq != QETH_CQ_ENABLED)
473 return;
474
475 if (q->bufs[bidx]->next_pending != NULL) {
476 struct qeth_qdio_out_buffer *head = q->bufs[bidx];
477 struct qeth_qdio_out_buffer *c = q->bufs[bidx]->next_pending;
478
479 while (c) {
480 if (forced_cleanup ||
481 atomic_read(&c->state) ==
482 QETH_QDIO_BUF_HANDLED_DELAYED) {
483 struct qeth_qdio_out_buffer *f = c;
484
485 QETH_CARD_TEXT(f->q->card, 5, "fp");
486 QETH_CARD_TEXT_(f->q->card, 5, "%lx", (long) f);
487
488
489
490 qeth_tx_complete_buf(c, forced_cleanup, 0);
491
492 c = f->next_pending;
493 WARN_ON_ONCE(head->next_pending != f);
494 head->next_pending = c;
495 kmem_cache_free(qeth_qdio_outbuf_cache, f);
496 } else {
497 head = c;
498 c = c->next_pending;
499 }
500
501 }
502 }
503}
504
505static void qeth_qdio_handle_aob(struct qeth_card *card,
506 unsigned long phys_aob_addr)
507{
508 enum qeth_qdio_out_buffer_state new_state = QETH_QDIO_BUF_QAOB_OK;
509 struct qaob *aob;
510 struct qeth_qdio_out_buffer *buffer;
511 enum iucv_tx_notify notification;
512 unsigned int i;
513
514 aob = (struct qaob *) phys_to_virt(phys_aob_addr);
515 QETH_CARD_TEXT(card, 5, "haob");
516 QETH_CARD_TEXT_(card, 5, "%lx", phys_aob_addr);
517 buffer = (struct qeth_qdio_out_buffer *) aob->user1;
518 QETH_CARD_TEXT_(card, 5, "%lx", aob->user1);
519
520
521
522
523 for (i = 0;
524 i < aob->sb_count && i < QETH_MAX_BUFFER_ELEMENTS(card);
525 i++) {
526 void *data = phys_to_virt(aob->sba[i]);
527
528 if (data && buffer->is_header[i])
529 kmem_cache_free(qeth_core_header_cache, data);
530 }
531
532 if (aob->aorc) {
533 QETH_CARD_TEXT_(card, 2, "aorc%02X", aob->aorc);
534 new_state = QETH_QDIO_BUF_QAOB_ERROR;
535 }
536
537 switch (atomic_xchg(&buffer->state, new_state)) {
538 case QETH_QDIO_BUF_PRIMED:
539
540 notification = qeth_compute_cq_notification(aob->aorc, 0);
541 qeth_notify_skbs(buffer->q, buffer, notification);
542 atomic_set(&buffer->state, QETH_QDIO_BUF_HANDLED_DELAYED);
543 break;
544 case QETH_QDIO_BUF_PENDING:
545
546
547
548 break;
549 case QETH_QDIO_BUF_NEED_QAOB:
550
551 notification = qeth_compute_cq_notification(aob->aorc, 1);
552 qeth_notify_skbs(buffer->q, buffer, notification);
553 atomic_set(&buffer->state, QETH_QDIO_BUF_HANDLED_DELAYED);
554 break;
555 default:
556 WARN_ON_ONCE(1);
557 }
558
559 qdio_release_aob(aob);
560}
561
562static void qeth_setup_ccw(struct ccw1 *ccw, u8 cmd_code, u8 flags, u32 len,
563 void *data)
564{
565 ccw->cmd_code = cmd_code;
566 ccw->flags = flags | CCW_FLAG_SLI;
567 ccw->count = len;
568 ccw->cda = (__u32) __pa(data);
569}
570
571static int __qeth_issue_next_read(struct qeth_card *card)
572{
573 struct qeth_cmd_buffer *iob = card->read_cmd;
574 struct qeth_channel *channel = iob->channel;
575 struct ccw1 *ccw = __ccw_from_cmd(iob);
576 int rc;
577
578 QETH_CARD_TEXT(card, 5, "issnxrd");
579 if (channel->state != CH_STATE_UP)
580 return -EIO;
581
582 memset(iob->data, 0, iob->length);
583 qeth_setup_ccw(ccw, CCW_CMD_READ, 0, iob->length, iob->data);
584 iob->callback = qeth_issue_next_read_cb;
585
586 qeth_get_cmd(iob);
587
588 QETH_CARD_TEXT(card, 6, "noirqpnd");
589 rc = ccw_device_start(channel->ccwdev, ccw, (addr_t) iob, 0, 0);
590 if (!rc) {
591 channel->active_cmd = iob;
592 } else {
593 QETH_DBF_MESSAGE(2, "error %i on device %x when starting next read ccw!\n",
594 rc, CARD_DEVID(card));
595 qeth_unlock_channel(card, channel);
596 qeth_put_cmd(iob);
597 card->read_or_write_problem = 1;
598 qeth_schedule_recovery(card);
599 }
600 return rc;
601}
602
603static int qeth_issue_next_read(struct qeth_card *card)
604{
605 int ret;
606
607 spin_lock_irq(get_ccwdev_lock(CARD_RDEV(card)));
608 ret = __qeth_issue_next_read(card);
609 spin_unlock_irq(get_ccwdev_lock(CARD_RDEV(card)));
610
611 return ret;
612}
613
614static void qeth_enqueue_cmd(struct qeth_card *card,
615 struct qeth_cmd_buffer *iob)
616{
617 spin_lock_irq(&card->lock);
618 list_add_tail(&iob->list, &card->cmd_waiter_list);
619 spin_unlock_irq(&card->lock);
620}
621
622static void qeth_dequeue_cmd(struct qeth_card *card,
623 struct qeth_cmd_buffer *iob)
624{
625 spin_lock_irq(&card->lock);
626 list_del(&iob->list);
627 spin_unlock_irq(&card->lock);
628}
629
630void qeth_notify_cmd(struct qeth_cmd_buffer *iob, int reason)
631{
632 iob->rc = reason;
633 complete(&iob->done);
634}
635EXPORT_SYMBOL_GPL(qeth_notify_cmd);
636
637static void qeth_flush_local_addrs4(struct qeth_card *card)
638{
639 struct qeth_local_addr *addr;
640 struct hlist_node *tmp;
641 unsigned int i;
642
643 spin_lock_irq(&card->local_addrs4_lock);
644 hash_for_each_safe(card->local_addrs4, i, tmp, addr, hnode) {
645 hash_del_rcu(&addr->hnode);
646 kfree_rcu(addr, rcu);
647 }
648 spin_unlock_irq(&card->local_addrs4_lock);
649}
650
651static void qeth_flush_local_addrs6(struct qeth_card *card)
652{
653 struct qeth_local_addr *addr;
654 struct hlist_node *tmp;
655 unsigned int i;
656
657 spin_lock_irq(&card->local_addrs6_lock);
658 hash_for_each_safe(card->local_addrs6, i, tmp, addr, hnode) {
659 hash_del_rcu(&addr->hnode);
660 kfree_rcu(addr, rcu);
661 }
662 spin_unlock_irq(&card->local_addrs6_lock);
663}
664
665static void qeth_flush_local_addrs(struct qeth_card *card)
666{
667 qeth_flush_local_addrs4(card);
668 qeth_flush_local_addrs6(card);
669}
670
671static void qeth_add_local_addrs4(struct qeth_card *card,
672 struct qeth_ipacmd_local_addrs4 *cmd)
673{
674 unsigned int i;
675
676 if (cmd->addr_length !=
677 sizeof_field(struct qeth_ipacmd_local_addr4, addr)) {
678 dev_err_ratelimited(&card->gdev->dev,
679 "Dropped IPv4 ADD LOCAL ADDR event with bad length %u\n",
680 cmd->addr_length);
681 return;
682 }
683
684 spin_lock(&card->local_addrs4_lock);
685 for (i = 0; i < cmd->count; i++) {
686 unsigned int key = ipv4_addr_hash(cmd->addrs[i].addr);
687 struct qeth_local_addr *addr;
688 bool duplicate = false;
689
690 hash_for_each_possible(card->local_addrs4, addr, hnode, key) {
691 if (addr->addr.s6_addr32[3] == cmd->addrs[i].addr) {
692 duplicate = true;
693 break;
694 }
695 }
696
697 if (duplicate)
698 continue;
699
700 addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
701 if (!addr) {
702 dev_err(&card->gdev->dev,
703 "Failed to allocate local addr object. Traffic to %pI4 might suffer.\n",
704 &cmd->addrs[i].addr);
705 continue;
706 }
707
708 ipv6_addr_set(&addr->addr, 0, 0, 0, cmd->addrs[i].addr);
709 hash_add_rcu(card->local_addrs4, &addr->hnode, key);
710 }
711 spin_unlock(&card->local_addrs4_lock);
712}
713
714static void qeth_add_local_addrs6(struct qeth_card *card,
715 struct qeth_ipacmd_local_addrs6 *cmd)
716{
717 unsigned int i;
718
719 if (cmd->addr_length !=
720 sizeof_field(struct qeth_ipacmd_local_addr6, addr)) {
721 dev_err_ratelimited(&card->gdev->dev,
722 "Dropped IPv6 ADD LOCAL ADDR event with bad length %u\n",
723 cmd->addr_length);
724 return;
725 }
726
727 spin_lock(&card->local_addrs6_lock);
728 for (i = 0; i < cmd->count; i++) {
729 u32 key = ipv6_addr_hash(&cmd->addrs[i].addr);
730 struct qeth_local_addr *addr;
731 bool duplicate = false;
732
733 hash_for_each_possible(card->local_addrs6, addr, hnode, key) {
734 if (ipv6_addr_equal(&addr->addr, &cmd->addrs[i].addr)) {
735 duplicate = true;
736 break;
737 }
738 }
739
740 if (duplicate)
741 continue;
742
743 addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
744 if (!addr) {
745 dev_err(&card->gdev->dev,
746 "Failed to allocate local addr object. Traffic to %pI6c might suffer.\n",
747 &cmd->addrs[i].addr);
748 continue;
749 }
750
751 addr->addr = cmd->addrs[i].addr;
752 hash_add_rcu(card->local_addrs6, &addr->hnode, key);
753 }
754 spin_unlock(&card->local_addrs6_lock);
755}
756
757static void qeth_del_local_addrs4(struct qeth_card *card,
758 struct qeth_ipacmd_local_addrs4 *cmd)
759{
760 unsigned int i;
761
762 if (cmd->addr_length !=
763 sizeof_field(struct qeth_ipacmd_local_addr4, addr)) {
764 dev_err_ratelimited(&card->gdev->dev,
765 "Dropped IPv4 DEL LOCAL ADDR event with bad length %u\n",
766 cmd->addr_length);
767 return;
768 }
769
770 spin_lock(&card->local_addrs4_lock);
771 for (i = 0; i < cmd->count; i++) {
772 struct qeth_ipacmd_local_addr4 *addr = &cmd->addrs[i];
773 unsigned int key = ipv4_addr_hash(addr->addr);
774 struct qeth_local_addr *tmp;
775
776 hash_for_each_possible(card->local_addrs4, tmp, hnode, key) {
777 if (tmp->addr.s6_addr32[3] == addr->addr) {
778 hash_del_rcu(&tmp->hnode);
779 kfree_rcu(tmp, rcu);
780 break;
781 }
782 }
783 }
784 spin_unlock(&card->local_addrs4_lock);
785}
786
787static void qeth_del_local_addrs6(struct qeth_card *card,
788 struct qeth_ipacmd_local_addrs6 *cmd)
789{
790 unsigned int i;
791
792 if (cmd->addr_length !=
793 sizeof_field(struct qeth_ipacmd_local_addr6, addr)) {
794 dev_err_ratelimited(&card->gdev->dev,
795 "Dropped IPv6 DEL LOCAL ADDR event with bad length %u\n",
796 cmd->addr_length);
797 return;
798 }
799
800 spin_lock(&card->local_addrs6_lock);
801 for (i = 0; i < cmd->count; i++) {
802 struct qeth_ipacmd_local_addr6 *addr = &cmd->addrs[i];
803 u32 key = ipv6_addr_hash(&addr->addr);
804 struct qeth_local_addr *tmp;
805
806 hash_for_each_possible(card->local_addrs6, tmp, hnode, key) {
807 if (ipv6_addr_equal(&tmp->addr, &addr->addr)) {
808 hash_del_rcu(&tmp->hnode);
809 kfree_rcu(tmp, rcu);
810 break;
811 }
812 }
813 }
814 spin_unlock(&card->local_addrs6_lock);
815}
816
817static bool qeth_next_hop_is_local_v4(struct qeth_card *card,
818 struct sk_buff *skb)
819{
820 struct qeth_local_addr *tmp;
821 bool is_local = false;
822 unsigned int key;
823 __be32 next_hop;
824
825 if (hash_empty(card->local_addrs4))
826 return false;
827
828 rcu_read_lock();
829 next_hop = qeth_next_hop_v4_rcu(skb, qeth_dst_check_rcu(skb, 4));
830 key = ipv4_addr_hash(next_hop);
831
832 hash_for_each_possible_rcu(card->local_addrs4, tmp, hnode, key) {
833 if (tmp->addr.s6_addr32[3] == next_hop) {
834 is_local = true;
835 break;
836 }
837 }
838 rcu_read_unlock();
839
840 return is_local;
841}
842
843static bool qeth_next_hop_is_local_v6(struct qeth_card *card,
844 struct sk_buff *skb)
845{
846 struct qeth_local_addr *tmp;
847 struct in6_addr *next_hop;
848 bool is_local = false;
849 u32 key;
850
851 if (hash_empty(card->local_addrs6))
852 return false;
853
854 rcu_read_lock();
855 next_hop = qeth_next_hop_v6_rcu(skb, qeth_dst_check_rcu(skb, 6));
856 key = ipv6_addr_hash(next_hop);
857
858 hash_for_each_possible_rcu(card->local_addrs6, tmp, hnode, key) {
859 if (ipv6_addr_equal(&tmp->addr, next_hop)) {
860 is_local = true;
861 break;
862 }
863 }
864 rcu_read_unlock();
865
866 return is_local;
867}
868
869static int qeth_debugfs_local_addr_show(struct seq_file *m, void *v)
870{
871 struct qeth_card *card = m->private;
872 struct qeth_local_addr *tmp;
873 unsigned int i;
874
875 rcu_read_lock();
876 hash_for_each_rcu(card->local_addrs4, i, tmp, hnode)
877 seq_printf(m, "%pI4\n", &tmp->addr.s6_addr32[3]);
878 hash_for_each_rcu(card->local_addrs6, i, tmp, hnode)
879 seq_printf(m, "%pI6c\n", &tmp->addr);
880 rcu_read_unlock();
881
882 return 0;
883}
884
885DEFINE_SHOW_ATTRIBUTE(qeth_debugfs_local_addr);
886
887static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
888 struct qeth_card *card)
889{
890 const char *ipa_name;
891 int com = cmd->hdr.command;
892
893 ipa_name = qeth_get_ipa_cmd_name(com);
894
895 if (rc)
896 QETH_DBF_MESSAGE(2, "IPA: %s(%#x) for device %x returned %#x \"%s\"\n",
897 ipa_name, com, CARD_DEVID(card), rc,
898 qeth_get_ipa_msg(rc));
899 else
900 QETH_DBF_MESSAGE(5, "IPA: %s(%#x) for device %x succeeded\n",
901 ipa_name, com, CARD_DEVID(card));
902}
903
904static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
905 struct qeth_ipa_cmd *cmd)
906{
907 QETH_CARD_TEXT(card, 5, "chkipad");
908
909 if (IS_IPA_REPLY(cmd)) {
910 if (cmd->hdr.command != IPA_CMD_SETCCID &&
911 cmd->hdr.command != IPA_CMD_DELCCID &&
912 cmd->hdr.command != IPA_CMD_MODCCID &&
913 cmd->hdr.command != IPA_CMD_SET_DIAG_ASS)
914 qeth_issue_ipa_msg(cmd, cmd->hdr.return_code, card);
915 return cmd;
916 }
917
918
919 switch (cmd->hdr.command) {
920 case IPA_CMD_STOPLAN:
921 if (cmd->hdr.return_code == IPA_RC_VEPA_TO_VEB_TRANSITION) {
922 dev_err(&card->gdev->dev,
923 "Interface %s is down because the adjacent port is no longer in reflective relay mode\n",
924 netdev_name(card->dev));
925 schedule_work(&card->close_dev_work);
926 } else {
927 dev_warn(&card->gdev->dev,
928 "The link for interface %s on CHPID 0x%X failed\n",
929 netdev_name(card->dev), card->info.chpid);
930 qeth_issue_ipa_msg(cmd, cmd->hdr.return_code, card);
931 netif_carrier_off(card->dev);
932 }
933 return NULL;
934 case IPA_CMD_STARTLAN:
935 dev_info(&card->gdev->dev,
936 "The link for %s on CHPID 0x%X has been restored\n",
937 netdev_name(card->dev), card->info.chpid);
938 if (card->info.hwtrap)
939 card->info.hwtrap = 2;
940 qeth_schedule_recovery(card);
941 return NULL;
942 case IPA_CMD_SETBRIDGEPORT_IQD:
943 case IPA_CMD_SETBRIDGEPORT_OSA:
944 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
945 if (card->discipline->control_event_handler(card, cmd))
946 return cmd;
947 return NULL;
948 case IPA_CMD_MODCCID:
949 return cmd;
950 case IPA_CMD_REGISTER_LOCAL_ADDR:
951 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
952 qeth_add_local_addrs4(card, &cmd->data.local_addrs4);
953 else if (cmd->hdr.prot_version == QETH_PROT_IPV6)
954 qeth_add_local_addrs6(card, &cmd->data.local_addrs6);
955
956 QETH_CARD_TEXT(card, 3, "irla");
957 return NULL;
958 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
959 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
960 qeth_del_local_addrs4(card, &cmd->data.local_addrs4);
961 else if (cmd->hdr.prot_version == QETH_PROT_IPV6)
962 qeth_del_local_addrs6(card, &cmd->data.local_addrs6);
963
964 QETH_CARD_TEXT(card, 3, "urla");
965 return NULL;
966 default:
967 QETH_DBF_MESSAGE(2, "Received data is IPA but not a reply!\n");
968 return cmd;
969 }
970}
971
972static void qeth_clear_ipacmd_list(struct qeth_card *card)
973{
974 struct qeth_cmd_buffer *iob;
975 unsigned long flags;
976
977 QETH_CARD_TEXT(card, 4, "clipalst");
978
979 spin_lock_irqsave(&card->lock, flags);
980 list_for_each_entry(iob, &card->cmd_waiter_list, list)
981 qeth_notify_cmd(iob, -ECANCELED);
982 spin_unlock_irqrestore(&card->lock, flags);
983}
984
985static int qeth_check_idx_response(struct qeth_card *card,
986 unsigned char *buffer)
987{
988 QETH_DBF_HEX(CTRL, 2, buffer, QETH_DBF_CTRL_LEN);
989 if ((buffer[2] & QETH_IDX_TERMINATE_MASK) == QETH_IDX_TERMINATE) {
990 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE with cause code %#04x\n",
991 buffer[4]);
992 QETH_CARD_TEXT(card, 2, "ckidxres");
993 QETH_CARD_TEXT(card, 2, " idxterm");
994 QETH_CARD_TEXT_(card, 2, "rc%x", buffer[4]);
995 if (buffer[4] == QETH_IDX_TERM_BAD_TRANSPORT ||
996 buffer[4] == QETH_IDX_TERM_BAD_TRANSPORT_VM) {
997 dev_err(&card->gdev->dev,
998 "The device does not support the configured transport mode\n");
999 return -EPROTONOSUPPORT;
1000 }
1001 return -EIO;
1002 }
1003 return 0;
1004}
1005
1006void qeth_put_cmd(struct qeth_cmd_buffer *iob)
1007{
1008 if (refcount_dec_and_test(&iob->ref_count)) {
1009 kfree(iob->data);
1010 kfree(iob);
1011 }
1012}
1013EXPORT_SYMBOL_GPL(qeth_put_cmd);
1014
1015static void qeth_release_buffer_cb(struct qeth_card *card,
1016 struct qeth_cmd_buffer *iob,
1017 unsigned int data_length)
1018{
1019 qeth_put_cmd(iob);
1020}
1021
1022static void qeth_cancel_cmd(struct qeth_cmd_buffer *iob, int rc)
1023{
1024 qeth_notify_cmd(iob, rc);
1025 qeth_put_cmd(iob);
1026}
1027
1028struct qeth_cmd_buffer *qeth_alloc_cmd(struct qeth_channel *channel,
1029 unsigned int length, unsigned int ccws,
1030 long timeout)
1031{
1032 struct qeth_cmd_buffer *iob;
1033
1034 if (length > QETH_BUFSIZE)
1035 return NULL;
1036
1037 iob = kzalloc(sizeof(*iob), GFP_KERNEL);
1038 if (!iob)
1039 return NULL;
1040
1041 iob->data = kzalloc(ALIGN(length, 8) + ccws * sizeof(struct ccw1),
1042 GFP_KERNEL | GFP_DMA);
1043 if (!iob->data) {
1044 kfree(iob);
1045 return NULL;
1046 }
1047
1048 init_completion(&iob->done);
1049 spin_lock_init(&iob->lock);
1050 INIT_LIST_HEAD(&iob->list);
1051 refcount_set(&iob->ref_count, 1);
1052 iob->channel = channel;
1053 iob->timeout = timeout;
1054 iob->length = length;
1055 return iob;
1056}
1057EXPORT_SYMBOL_GPL(qeth_alloc_cmd);
1058
1059static void qeth_issue_next_read_cb(struct qeth_card *card,
1060 struct qeth_cmd_buffer *iob,
1061 unsigned int data_length)
1062{
1063 struct qeth_cmd_buffer *request = NULL;
1064 struct qeth_ipa_cmd *cmd = NULL;
1065 struct qeth_reply *reply = NULL;
1066 struct qeth_cmd_buffer *tmp;
1067 unsigned long flags;
1068 int rc = 0;
1069
1070 QETH_CARD_TEXT(card, 4, "sndctlcb");
1071 rc = qeth_check_idx_response(card, iob->data);
1072 switch (rc) {
1073 case 0:
1074 break;
1075 case -EIO:
1076 qeth_schedule_recovery(card);
1077 fallthrough;
1078 default:
1079 qeth_clear_ipacmd_list(card);
1080 goto err_idx;
1081 }
1082
1083 cmd = __ipa_reply(iob);
1084 if (cmd) {
1085 cmd = qeth_check_ipa_data(card, cmd);
1086 if (!cmd)
1087 goto out;
1088 if (IS_OSN(card) && card->osn_info.assist_cb &&
1089 cmd->hdr.command != IPA_CMD_STARTLAN) {
1090 card->osn_info.assist_cb(card->dev, cmd);
1091 goto out;
1092 }
1093 }
1094
1095
1096 spin_lock_irqsave(&card->lock, flags);
1097 list_for_each_entry(tmp, &card->cmd_waiter_list, list) {
1098 if (tmp->match && tmp->match(tmp, iob)) {
1099 request = tmp;
1100
1101 qeth_get_cmd(request);
1102 break;
1103 }
1104 }
1105 spin_unlock_irqrestore(&card->lock, flags);
1106
1107 if (!request)
1108 goto out;
1109
1110 reply = &request->reply;
1111 if (!reply->callback) {
1112 rc = 0;
1113 goto no_callback;
1114 }
1115
1116 spin_lock_irqsave(&request->lock, flags);
1117 if (request->rc)
1118
1119 rc = request->rc;
1120 else
1121 rc = reply->callback(card, reply, cmd ? (unsigned long)cmd :
1122 (unsigned long)iob);
1123 spin_unlock_irqrestore(&request->lock, flags);
1124
1125no_callback:
1126 if (rc <= 0)
1127 qeth_notify_cmd(request, rc);
1128 qeth_put_cmd(request);
1129out:
1130 memcpy(&card->seqno.pdu_hdr_ack,
1131 QETH_PDU_HEADER_SEQ_NO(iob->data),
1132 QETH_SEQ_NO_LENGTH);
1133 __qeth_issue_next_read(card);
1134err_idx:
1135 qeth_put_cmd(iob);
1136}
1137
1138static int qeth_set_thread_start_bit(struct qeth_card *card,
1139 unsigned long thread)
1140{
1141 unsigned long flags;
1142 int rc = 0;
1143
1144 spin_lock_irqsave(&card->thread_mask_lock, flags);
1145 if (!(card->thread_allowed_mask & thread))
1146 rc = -EPERM;
1147 else if (card->thread_start_mask & thread)
1148 rc = -EBUSY;
1149 else
1150 card->thread_start_mask |= thread;
1151 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1152
1153 return rc;
1154}
1155
1156static void qeth_clear_thread_start_bit(struct qeth_card *card,
1157 unsigned long thread)
1158{
1159 unsigned long flags;
1160
1161 spin_lock_irqsave(&card->thread_mask_lock, flags);
1162 card->thread_start_mask &= ~thread;
1163 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1164 wake_up(&card->wait_q);
1165}
1166
1167static void qeth_clear_thread_running_bit(struct qeth_card *card,
1168 unsigned long thread)
1169{
1170 unsigned long flags;
1171
1172 spin_lock_irqsave(&card->thread_mask_lock, flags);
1173 card->thread_running_mask &= ~thread;
1174 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1175 wake_up_all(&card->wait_q);
1176}
1177
1178static int __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
1179{
1180 unsigned long flags;
1181 int rc = 0;
1182
1183 spin_lock_irqsave(&card->thread_mask_lock, flags);
1184 if (card->thread_start_mask & thread) {
1185 if ((card->thread_allowed_mask & thread) &&
1186 !(card->thread_running_mask & thread)) {
1187 rc = 1;
1188 card->thread_start_mask &= ~thread;
1189 card->thread_running_mask |= thread;
1190 } else
1191 rc = -EPERM;
1192 }
1193 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1194 return rc;
1195}
1196
1197static int qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
1198{
1199 int rc = 0;
1200
1201 wait_event(card->wait_q,
1202 (rc = __qeth_do_run_thread(card, thread)) >= 0);
1203 return rc;
1204}
1205
1206int qeth_schedule_recovery(struct qeth_card *card)
1207{
1208 int rc;
1209
1210 QETH_CARD_TEXT(card, 2, "startrec");
1211
1212 rc = qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD);
1213 if (!rc)
1214 schedule_work(&card->kernel_thread_starter);
1215
1216 return rc;
1217}
1218
1219static int qeth_get_problem(struct qeth_card *card, struct ccw_device *cdev,
1220 struct irb *irb)
1221{
1222 int dstat, cstat;
1223 char *sense;
1224
1225 sense = (char *) irb->ecw;
1226 cstat = irb->scsw.cmd.cstat;
1227 dstat = irb->scsw.cmd.dstat;
1228
1229 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
1230 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
1231 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
1232 QETH_CARD_TEXT(card, 2, "CGENCHK");
1233 dev_warn(&cdev->dev, "The qeth device driver "
1234 "failed to recover an error on the device\n");
1235 QETH_DBF_MESSAGE(2, "check on channel %x with dstat=%#x, cstat=%#x\n",
1236 CCW_DEVID(cdev), dstat, cstat);
1237 print_hex_dump(KERN_WARNING, "qeth: irb ", DUMP_PREFIX_OFFSET,
1238 16, 1, irb, 64, 1);
1239 return -EIO;
1240 }
1241
1242 if (dstat & DEV_STAT_UNIT_CHECK) {
1243 if (sense[SENSE_RESETTING_EVENT_BYTE] &
1244 SENSE_RESETTING_EVENT_FLAG) {
1245 QETH_CARD_TEXT(card, 2, "REVIND");
1246 return -EIO;
1247 }
1248 if (sense[SENSE_COMMAND_REJECT_BYTE] &
1249 SENSE_COMMAND_REJECT_FLAG) {
1250 QETH_CARD_TEXT(card, 2, "CMDREJi");
1251 return -EIO;
1252 }
1253 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
1254 QETH_CARD_TEXT(card, 2, "AFFE");
1255 return -EIO;
1256 }
1257 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
1258 QETH_CARD_TEXT(card, 2, "ZEROSEN");
1259 return 0;
1260 }
1261 QETH_CARD_TEXT(card, 2, "DGENCHK");
1262 return -EIO;
1263 }
1264 return 0;
1265}
1266
1267static int qeth_check_irb_error(struct qeth_card *card, struct ccw_device *cdev,
1268 struct irb *irb)
1269{
1270 if (!IS_ERR(irb))
1271 return 0;
1272
1273 switch (PTR_ERR(irb)) {
1274 case -EIO:
1275 QETH_DBF_MESSAGE(2, "i/o-error on channel %x\n",
1276 CCW_DEVID(cdev));
1277 QETH_CARD_TEXT(card, 2, "ckirberr");
1278 QETH_CARD_TEXT_(card, 2, " rc%d", -EIO);
1279 return -EIO;
1280 case -ETIMEDOUT:
1281 dev_warn(&cdev->dev, "A hardware operation timed out"
1282 " on the device\n");
1283 QETH_CARD_TEXT(card, 2, "ckirberr");
1284 QETH_CARD_TEXT_(card, 2, " rc%d", -ETIMEDOUT);
1285 return -ETIMEDOUT;
1286 default:
1287 QETH_DBF_MESSAGE(2, "unknown error %ld on channel %x\n",
1288 PTR_ERR(irb), CCW_DEVID(cdev));
1289 QETH_CARD_TEXT(card, 2, "ckirberr");
1290 QETH_CARD_TEXT(card, 2, " rc???");
1291 return PTR_ERR(irb);
1292 }
1293}
1294
1295static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1296 struct irb *irb)
1297{
1298 int rc;
1299 int cstat, dstat;
1300 struct qeth_cmd_buffer *iob = NULL;
1301 struct ccwgroup_device *gdev;
1302 struct qeth_channel *channel;
1303 struct qeth_card *card;
1304
1305
1306 gdev = dev_get_drvdata(&cdev->dev);
1307 card = dev_get_drvdata(&gdev->dev);
1308
1309 QETH_CARD_TEXT(card, 5, "irq");
1310
1311 if (card->read.ccwdev == cdev) {
1312 channel = &card->read;
1313 QETH_CARD_TEXT(card, 5, "read");
1314 } else if (card->write.ccwdev == cdev) {
1315 channel = &card->write;
1316 QETH_CARD_TEXT(card, 5, "write");
1317 } else {
1318 channel = &card->data;
1319 QETH_CARD_TEXT(card, 5, "data");
1320 }
1321
1322 if (intparm == 0) {
1323 QETH_CARD_TEXT(card, 5, "irqunsol");
1324 } else if ((addr_t)intparm != (addr_t)channel->active_cmd) {
1325 QETH_CARD_TEXT(card, 5, "irqunexp");
1326
1327 dev_err(&cdev->dev,
1328 "Received IRQ with intparm %lx, expected %px\n",
1329 intparm, channel->active_cmd);
1330 if (channel->active_cmd)
1331 qeth_cancel_cmd(channel->active_cmd, -EIO);
1332 } else {
1333 iob = (struct qeth_cmd_buffer *) (addr_t)intparm;
1334 }
1335
1336 channel->active_cmd = NULL;
1337 qeth_unlock_channel(card, channel);
1338
1339 rc = qeth_check_irb_error(card, cdev, irb);
1340 if (rc) {
1341
1342 if (iob)
1343 qeth_cancel_cmd(iob, rc);
1344 return;
1345 }
1346
1347 if (irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC) {
1348 channel->state = CH_STATE_STOPPED;
1349 wake_up(&card->wait_q);
1350 }
1351
1352 if (irb->scsw.cmd.fctl & SCSW_FCTL_HALT_FUNC) {
1353 channel->state = CH_STATE_HALTED;
1354 wake_up(&card->wait_q);
1355 }
1356
1357 if (iob && (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC |
1358 SCSW_FCTL_HALT_FUNC))) {
1359 qeth_cancel_cmd(iob, -ECANCELED);
1360 iob = NULL;
1361 }
1362
1363 cstat = irb->scsw.cmd.cstat;
1364 dstat = irb->scsw.cmd.dstat;
1365
1366 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
1367 (dstat & DEV_STAT_UNIT_CHECK) ||
1368 (cstat)) {
1369 if (irb->esw.esw0.erw.cons) {
1370 dev_warn(&channel->ccwdev->dev,
1371 "The qeth device driver failed to recover "
1372 "an error on the device\n");
1373 QETH_DBF_MESSAGE(2, "sense data available on channel %x: cstat %#X dstat %#X\n",
1374 CCW_DEVID(channel->ccwdev), cstat,
1375 dstat);
1376 print_hex_dump(KERN_WARNING, "qeth: irb ",
1377 DUMP_PREFIX_OFFSET, 16, 1, irb, 32, 1);
1378 print_hex_dump(KERN_WARNING, "qeth: sense data ",
1379 DUMP_PREFIX_OFFSET, 16, 1, irb->ecw, 32, 1);
1380 }
1381
1382 rc = qeth_get_problem(card, cdev, irb);
1383 if (rc) {
1384 card->read_or_write_problem = 1;
1385 if (iob)
1386 qeth_cancel_cmd(iob, rc);
1387 qeth_clear_ipacmd_list(card);
1388 qeth_schedule_recovery(card);
1389 return;
1390 }
1391 }
1392
1393 if (iob) {
1394
1395 if (irb->scsw.cmd.count > iob->length) {
1396 qeth_cancel_cmd(iob, -EIO);
1397 return;
1398 }
1399 if (iob->callback)
1400 iob->callback(card, iob,
1401 iob->length - irb->scsw.cmd.count);
1402 }
1403}
1404
1405static void qeth_notify_skbs(struct qeth_qdio_out_q *q,
1406 struct qeth_qdio_out_buffer *buf,
1407 enum iucv_tx_notify notification)
1408{
1409 struct sk_buff *skb;
1410
1411 skb_queue_walk(&buf->skb_list, skb) {
1412 QETH_CARD_TEXT_(q->card, 5, "skbn%d", notification);
1413 QETH_CARD_TEXT_(q->card, 5, "%lx", (long) skb);
1414 if (skb->sk && skb->sk->sk_family == PF_IUCV)
1415 iucv_sk(skb->sk)->sk_txnotify(skb, notification);
1416 }
1417}
1418
1419static void qeth_tx_complete_buf(struct qeth_qdio_out_buffer *buf, bool error,
1420 int budget)
1421{
1422 struct qeth_qdio_out_q *queue = buf->q;
1423 struct sk_buff *skb;
1424
1425 if (atomic_read(&buf->state) == QETH_QDIO_BUF_PENDING)
1426 qeth_notify_skbs(queue, buf, TX_NOTIFY_GENERALERROR);
1427
1428
1429 if (buf->next_element_to_fill == 0)
1430 return;
1431
1432 QETH_TXQ_STAT_INC(queue, bufs);
1433 QETH_TXQ_STAT_ADD(queue, buf_elements, buf->next_element_to_fill);
1434 if (error) {
1435 QETH_TXQ_STAT_ADD(queue, tx_errors, buf->frames);
1436 } else {
1437 QETH_TXQ_STAT_ADD(queue, tx_packets, buf->frames);
1438 QETH_TXQ_STAT_ADD(queue, tx_bytes, buf->bytes);
1439 }
1440
1441 while ((skb = __skb_dequeue(&buf->skb_list)) != NULL) {
1442 unsigned int bytes = qdisc_pkt_len(skb);
1443 bool is_tso = skb_is_gso(skb);
1444 unsigned int packets;
1445
1446 packets = is_tso ? skb_shinfo(skb)->gso_segs : 1;
1447 if (!error) {
1448 if (skb->ip_summed == CHECKSUM_PARTIAL)
1449 QETH_TXQ_STAT_ADD(queue, skbs_csum, packets);
1450 if (skb_is_nonlinear(skb))
1451 QETH_TXQ_STAT_INC(queue, skbs_sg);
1452 if (is_tso) {
1453 QETH_TXQ_STAT_INC(queue, skbs_tso);
1454 QETH_TXQ_STAT_ADD(queue, tso_bytes, bytes);
1455 }
1456 }
1457
1458 napi_consume_skb(skb, budget);
1459 }
1460}
1461
1462static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
1463 struct qeth_qdio_out_buffer *buf,
1464 bool error, int budget)
1465{
1466 int i;
1467
1468
1469 if (buf->buffer->element[0].sflags & SBAL_SFLAGS0_PCI_REQ)
1470 atomic_dec(&queue->set_pci_flags_count);
1471
1472 qeth_tx_complete_buf(buf, error, budget);
1473
1474 for (i = 0; i < queue->max_elements; ++i) {
1475 void *data = phys_to_virt(buf->buffer->element[i].addr);
1476
1477 if (data && buf->is_header[i])
1478 kmem_cache_free(qeth_core_header_cache, data);
1479 buf->is_header[i] = 0;
1480 }
1481
1482 qeth_scrub_qdio_buffer(buf->buffer, queue->max_elements);
1483 buf->next_element_to_fill = 0;
1484 buf->frames = 0;
1485 buf->bytes = 0;
1486 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
1487}
1488
1489static void qeth_drain_output_queue(struct qeth_qdio_out_q *q, bool free)
1490{
1491 int j;
1492
1493 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
1494 if (!q->bufs[j])
1495 continue;
1496 qeth_cleanup_handled_pending(q, j, 1);
1497 qeth_clear_output_buffer(q, q->bufs[j], true, 0);
1498 if (free) {
1499 kmem_cache_free(qeth_qdio_outbuf_cache, q->bufs[j]);
1500 q->bufs[j] = NULL;
1501 }
1502 }
1503}
1504
1505static void qeth_drain_output_queues(struct qeth_card *card)
1506{
1507 int i;
1508
1509 QETH_CARD_TEXT(card, 2, "clearqdbf");
1510
1511 for (i = 0; i < card->qdio.no_out_queues; ++i) {
1512 if (card->qdio.out_qs[i])
1513 qeth_drain_output_queue(card->qdio.out_qs[i], false);
1514 }
1515}
1516
1517static void qeth_osa_set_output_queues(struct qeth_card *card, bool single)
1518{
1519 unsigned int max = single ? 1 : card->dev->num_tx_queues;
1520
1521 if (card->qdio.no_out_queues == max)
1522 return;
1523
1524 if (atomic_read(&card->qdio.state) != QETH_QDIO_UNINITIALIZED)
1525 qeth_free_qdio_queues(card);
1526
1527 if (max == 1 && card->qdio.do_prio_queueing != QETH_PRIOQ_DEFAULT)
1528 dev_info(&card->gdev->dev, "Priority Queueing not supported\n");
1529
1530 card->qdio.no_out_queues = max;
1531}
1532
1533static int qeth_update_from_chp_desc(struct qeth_card *card)
1534{
1535 struct ccw_device *ccwdev;
1536 struct channel_path_desc_fmt0 *chp_dsc;
1537
1538 QETH_CARD_TEXT(card, 2, "chp_desc");
1539
1540 ccwdev = card->data.ccwdev;
1541 chp_dsc = ccw_device_get_chp_desc(ccwdev, 0);
1542 if (!chp_dsc)
1543 return -ENOMEM;
1544
1545 card->info.func_level = 0x4100 + chp_dsc->desc;
1546
1547 if (IS_OSD(card) || IS_OSX(card))
1548
1549 qeth_osa_set_output_queues(card, chp_dsc->chpp & 0x02);
1550
1551 kfree(chp_dsc);
1552 QETH_CARD_TEXT_(card, 2, "nr:%x", card->qdio.no_out_queues);
1553 QETH_CARD_TEXT_(card, 2, "lvl:%02x", card->info.func_level);
1554 return 0;
1555}
1556
1557static void qeth_init_qdio_info(struct qeth_card *card)
1558{
1559 QETH_CARD_TEXT(card, 4, "intqdinf");
1560 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
1561 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1562 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1563
1564
1565 card->qdio.no_in_queues = 1;
1566 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1567 if (IS_IQD(card))
1568 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_HSDEFAULT;
1569 else
1570 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
1571 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
1572 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
1573 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
1574}
1575
1576static void qeth_set_initial_options(struct qeth_card *card)
1577{
1578 card->options.route4.type = NO_ROUTER;
1579 card->options.route6.type = NO_ROUTER;
1580 card->options.isolation = ISOLATION_MODE_NONE;
1581 card->options.cq = QETH_CQ_DISABLED;
1582 card->options.layer = QETH_DISCIPLINE_UNDETERMINED;
1583}
1584
1585static int qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1586{
1587 unsigned long flags;
1588 int rc = 0;
1589
1590 spin_lock_irqsave(&card->thread_mask_lock, flags);
1591 QETH_CARD_TEXT_(card, 4, " %02x%02x%02x",
1592 (u8) card->thread_start_mask,
1593 (u8) card->thread_allowed_mask,
1594 (u8) card->thread_running_mask);
1595 rc = (card->thread_start_mask & thread);
1596 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1597 return rc;
1598}
1599
1600static int qeth_do_reset(void *data);
1601static void qeth_start_kernel_thread(struct work_struct *work)
1602{
1603 struct task_struct *ts;
1604 struct qeth_card *card = container_of(work, struct qeth_card,
1605 kernel_thread_starter);
1606 QETH_CARD_TEXT(card, 2, "strthrd");
1607
1608 if (card->read.state != CH_STATE_UP &&
1609 card->write.state != CH_STATE_UP)
1610 return;
1611 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD)) {
1612 ts = kthread_run(qeth_do_reset, card, "qeth_recover");
1613 if (IS_ERR(ts)) {
1614 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1615 qeth_clear_thread_running_bit(card,
1616 QETH_RECOVER_THREAD);
1617 }
1618 }
1619}
1620
1621static void qeth_buffer_reclaim_work(struct work_struct *);
1622static void qeth_setup_card(struct qeth_card *card)
1623{
1624 QETH_CARD_TEXT(card, 2, "setupcrd");
1625
1626 card->info.type = CARD_RDEV(card)->id.driver_info;
1627 card->state = CARD_STATE_DOWN;
1628 spin_lock_init(&card->lock);
1629 spin_lock_init(&card->thread_mask_lock);
1630 mutex_init(&card->conf_mutex);
1631 mutex_init(&card->discipline_mutex);
1632 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1633 INIT_LIST_HEAD(&card->cmd_waiter_list);
1634 init_waitqueue_head(&card->wait_q);
1635 qeth_set_initial_options(card);
1636
1637 INIT_LIST_HEAD(&card->ipato.entries);
1638 qeth_init_qdio_info(card);
1639 INIT_DELAYED_WORK(&card->buffer_reclaim_work, qeth_buffer_reclaim_work);
1640 INIT_WORK(&card->close_dev_work, qeth_close_dev_handler);
1641 hash_init(card->rx_mode_addrs);
1642 hash_init(card->local_addrs4);
1643 hash_init(card->local_addrs6);
1644 spin_lock_init(&card->local_addrs4_lock);
1645 spin_lock_init(&card->local_addrs6_lock);
1646}
1647
1648static void qeth_core_sl_print(struct seq_file *m, struct service_level *slr)
1649{
1650 struct qeth_card *card = container_of(slr, struct qeth_card,
1651 qeth_service_level);
1652 if (card->info.mcl_level[0])
1653 seq_printf(m, "qeth: %s firmware level %s\n",
1654 CARD_BUS_ID(card), card->info.mcl_level);
1655}
1656
1657static struct qeth_card *qeth_alloc_card(struct ccwgroup_device *gdev)
1658{
1659 struct qeth_card *card;
1660
1661 QETH_DBF_TEXT(SETUP, 2, "alloccrd");
1662 card = kzalloc(sizeof(*card), GFP_KERNEL);
1663 if (!card)
1664 goto out;
1665 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1666
1667 card->gdev = gdev;
1668 dev_set_drvdata(&gdev->dev, card);
1669 CARD_RDEV(card) = gdev->cdev[0];
1670 CARD_WDEV(card) = gdev->cdev[1];
1671 CARD_DDEV(card) = gdev->cdev[2];
1672
1673 card->event_wq = alloc_ordered_workqueue("%s_event", 0,
1674 dev_name(&gdev->dev));
1675 if (!card->event_wq)
1676 goto out_wq;
1677
1678 card->read_cmd = qeth_alloc_cmd(&card->read, QETH_BUFSIZE, 1, 0);
1679 if (!card->read_cmd)
1680 goto out_read_cmd;
1681
1682 card->debugfs = debugfs_create_dir(dev_name(&gdev->dev),
1683 qeth_debugfs_root);
1684 debugfs_create_file("local_addrs", 0400, card->debugfs, card,
1685 &qeth_debugfs_local_addr_fops);
1686
1687 card->qeth_service_level.seq_print = qeth_core_sl_print;
1688 register_service_level(&card->qeth_service_level);
1689 return card;
1690
1691out_read_cmd:
1692 destroy_workqueue(card->event_wq);
1693out_wq:
1694 dev_set_drvdata(&gdev->dev, NULL);
1695 kfree(card);
1696out:
1697 return NULL;
1698}
1699
1700static int qeth_clear_channel(struct qeth_card *card,
1701 struct qeth_channel *channel)
1702{
1703 int rc;
1704
1705 QETH_CARD_TEXT(card, 3, "clearch");
1706 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
1707 rc = ccw_device_clear(channel->ccwdev, (addr_t)channel->active_cmd);
1708 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
1709
1710 if (rc)
1711 return rc;
1712 rc = wait_event_interruptible_timeout(card->wait_q,
1713 channel->state == CH_STATE_STOPPED, QETH_TIMEOUT);
1714 if (rc == -ERESTARTSYS)
1715 return rc;
1716 if (channel->state != CH_STATE_STOPPED)
1717 return -ETIME;
1718 channel->state = CH_STATE_DOWN;
1719 return 0;
1720}
1721
1722static int qeth_halt_channel(struct qeth_card *card,
1723 struct qeth_channel *channel)
1724{
1725 int rc;
1726
1727 QETH_CARD_TEXT(card, 3, "haltch");
1728 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
1729 rc = ccw_device_halt(channel->ccwdev, (addr_t)channel->active_cmd);
1730 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
1731
1732 if (rc)
1733 return rc;
1734 rc = wait_event_interruptible_timeout(card->wait_q,
1735 channel->state == CH_STATE_HALTED, QETH_TIMEOUT);
1736 if (rc == -ERESTARTSYS)
1737 return rc;
1738 if (channel->state != CH_STATE_HALTED)
1739 return -ETIME;
1740 return 0;
1741}
1742
1743static int qeth_stop_channel(struct qeth_channel *channel)
1744{
1745 struct ccw_device *cdev = channel->ccwdev;
1746 int rc;
1747
1748 rc = ccw_device_set_offline(cdev);
1749
1750 spin_lock_irq(get_ccwdev_lock(cdev));
1751 if (channel->active_cmd) {
1752 dev_err(&cdev->dev, "Stopped channel while cmd %px was still active\n",
1753 channel->active_cmd);
1754 channel->active_cmd = NULL;
1755 }
1756 cdev->handler = NULL;
1757 spin_unlock_irq(get_ccwdev_lock(cdev));
1758
1759 return rc;
1760}
1761
1762static int qeth_start_channel(struct qeth_channel *channel)
1763{
1764 struct ccw_device *cdev = channel->ccwdev;
1765 int rc;
1766
1767 channel->state = CH_STATE_DOWN;
1768 atomic_set(&channel->irq_pending, 0);
1769
1770 spin_lock_irq(get_ccwdev_lock(cdev));
1771 cdev->handler = qeth_irq;
1772 spin_unlock_irq(get_ccwdev_lock(cdev));
1773
1774 rc = ccw_device_set_online(cdev);
1775 if (rc)
1776 goto err;
1777
1778 return 0;
1779
1780err:
1781 spin_lock_irq(get_ccwdev_lock(cdev));
1782 cdev->handler = NULL;
1783 spin_unlock_irq(get_ccwdev_lock(cdev));
1784 return rc;
1785}
1786
1787static int qeth_halt_channels(struct qeth_card *card)
1788{
1789 int rc1 = 0, rc2 = 0, rc3 = 0;
1790
1791 QETH_CARD_TEXT(card, 3, "haltchs");
1792 rc1 = qeth_halt_channel(card, &card->read);
1793 rc2 = qeth_halt_channel(card, &card->write);
1794 rc3 = qeth_halt_channel(card, &card->data);
1795 if (rc1)
1796 return rc1;
1797 if (rc2)
1798 return rc2;
1799 return rc3;
1800}
1801
1802static int qeth_clear_channels(struct qeth_card *card)
1803{
1804 int rc1 = 0, rc2 = 0, rc3 = 0;
1805
1806 QETH_CARD_TEXT(card, 3, "clearchs");
1807 rc1 = qeth_clear_channel(card, &card->read);
1808 rc2 = qeth_clear_channel(card, &card->write);
1809 rc3 = qeth_clear_channel(card, &card->data);
1810 if (rc1)
1811 return rc1;
1812 if (rc2)
1813 return rc2;
1814 return rc3;
1815}
1816
1817static int qeth_clear_halt_card(struct qeth_card *card, int halt)
1818{
1819 int rc = 0;
1820
1821 QETH_CARD_TEXT(card, 3, "clhacrd");
1822
1823 if (halt)
1824 rc = qeth_halt_channels(card);
1825 if (rc)
1826 return rc;
1827 return qeth_clear_channels(card);
1828}
1829
1830static int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
1831{
1832 int rc = 0;
1833
1834 QETH_CARD_TEXT(card, 3, "qdioclr");
1835 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
1836 QETH_QDIO_CLEANING)) {
1837 case QETH_QDIO_ESTABLISHED:
1838 if (IS_IQD(card))
1839 rc = qdio_shutdown(CARD_DDEV(card),
1840 QDIO_FLAG_CLEANUP_USING_HALT);
1841 else
1842 rc = qdio_shutdown(CARD_DDEV(card),
1843 QDIO_FLAG_CLEANUP_USING_CLEAR);
1844 if (rc)
1845 QETH_CARD_TEXT_(card, 3, "1err%d", rc);
1846 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
1847 break;
1848 case QETH_QDIO_CLEANING:
1849 return rc;
1850 default:
1851 break;
1852 }
1853 rc = qeth_clear_halt_card(card, use_halt);
1854 if (rc)
1855 QETH_CARD_TEXT_(card, 3, "2err%d", rc);
1856 return rc;
1857}
1858
1859static enum qeth_discipline_id qeth_vm_detect_layer(struct qeth_card *card)
1860{
1861 enum qeth_discipline_id disc = QETH_DISCIPLINE_UNDETERMINED;
1862 struct diag26c_vnic_resp *response = NULL;
1863 struct diag26c_vnic_req *request = NULL;
1864 struct ccw_dev_id id;
1865 char userid[80];
1866 int rc = 0;
1867
1868 QETH_CARD_TEXT(card, 2, "vmlayer");
1869
1870 cpcmd("QUERY USERID", userid, sizeof(userid), &rc);
1871 if (rc)
1872 goto out;
1873
1874 request = kzalloc(sizeof(*request), GFP_KERNEL | GFP_DMA);
1875 response = kzalloc(sizeof(*response), GFP_KERNEL | GFP_DMA);
1876 if (!request || !response) {
1877 rc = -ENOMEM;
1878 goto out;
1879 }
1880
1881 ccw_device_get_id(CARD_RDEV(card), &id);
1882 request->resp_buf_len = sizeof(*response);
1883 request->resp_version = DIAG26C_VERSION6_VM65918;
1884 request->req_format = DIAG26C_VNIC_INFO;
1885 ASCEBC(userid, 8);
1886 memcpy(&request->sys_name, userid, 8);
1887 request->devno = id.devno;
1888
1889 QETH_DBF_HEX(CTRL, 2, request, sizeof(*request));
1890 rc = diag26c(request, response, DIAG26C_PORT_VNIC);
1891 QETH_DBF_HEX(CTRL, 2, request, sizeof(*request));
1892 if (rc)
1893 goto out;
1894 QETH_DBF_HEX(CTRL, 2, response, sizeof(*response));
1895
1896 if (request->resp_buf_len < sizeof(*response) ||
1897 response->version != request->resp_version) {
1898 rc = -EIO;
1899 goto out;
1900 }
1901
1902 if (response->protocol == VNIC_INFO_PROT_L2)
1903 disc = QETH_DISCIPLINE_LAYER2;
1904 else if (response->protocol == VNIC_INFO_PROT_L3)
1905 disc = QETH_DISCIPLINE_LAYER3;
1906
1907out:
1908 kfree(response);
1909 kfree(request);
1910 if (rc)
1911 QETH_CARD_TEXT_(card, 2, "err%x", rc);
1912 return disc;
1913}
1914
1915
1916static enum qeth_discipline_id qeth_enforce_discipline(struct qeth_card *card)
1917{
1918 enum qeth_discipline_id disc = QETH_DISCIPLINE_UNDETERMINED;
1919
1920 if (IS_OSM(card) || IS_OSN(card))
1921 disc = QETH_DISCIPLINE_LAYER2;
1922 else if (IS_VM_NIC(card))
1923 disc = IS_IQD(card) ? QETH_DISCIPLINE_LAYER3 :
1924 qeth_vm_detect_layer(card);
1925
1926 switch (disc) {
1927 case QETH_DISCIPLINE_LAYER2:
1928 QETH_CARD_TEXT(card, 3, "force l2");
1929 break;
1930 case QETH_DISCIPLINE_LAYER3:
1931 QETH_CARD_TEXT(card, 3, "force l3");
1932 break;
1933 default:
1934 QETH_CARD_TEXT(card, 3, "force no");
1935 }
1936
1937 return disc;
1938}
1939
1940static void qeth_set_blkt_defaults(struct qeth_card *card)
1941{
1942 QETH_CARD_TEXT(card, 2, "cfgblkt");
1943
1944 if (card->info.use_v1_blkt) {
1945 card->info.blkt.time_total = 0;
1946 card->info.blkt.inter_packet = 0;
1947 card->info.blkt.inter_packet_jumbo = 0;
1948 } else {
1949 card->info.blkt.time_total = 250;
1950 card->info.blkt.inter_packet = 5;
1951 card->info.blkt.inter_packet_jumbo = 15;
1952 }
1953}
1954
1955static void qeth_idx_init(struct qeth_card *card)
1956{
1957 memset(&card->seqno, 0, sizeof(card->seqno));
1958
1959 card->token.issuer_rm_w = 0x00010103UL;
1960 card->token.cm_filter_w = 0x00010108UL;
1961 card->token.cm_connection_w = 0x0001010aUL;
1962 card->token.ulp_filter_w = 0x0001010bUL;
1963 card->token.ulp_connection_w = 0x0001010dUL;
1964
1965 switch (card->info.type) {
1966 case QETH_CARD_TYPE_IQD:
1967 card->info.func_level = QETH_IDX_FUNC_LEVEL_IQD;
1968 break;
1969 case QETH_CARD_TYPE_OSD:
1970 case QETH_CARD_TYPE_OSN:
1971 card->info.func_level = QETH_IDX_FUNC_LEVEL_OSD;
1972 break;
1973 default:
1974 break;
1975 }
1976}
1977
1978static void qeth_idx_finalize_cmd(struct qeth_card *card,
1979 struct qeth_cmd_buffer *iob)
1980{
1981 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data), &card->seqno.trans_hdr,
1982 QETH_SEQ_NO_LENGTH);
1983 if (iob->channel == &card->write)
1984 card->seqno.trans_hdr++;
1985}
1986
1987static int qeth_peer_func_level(int level)
1988{
1989 if ((level & 0xff) == 8)
1990 return (level & 0xff) + 0x400;
1991 if (((level >> 8) & 3) == 1)
1992 return (level & 0xff) + 0x200;
1993 return level;
1994}
1995
1996static void qeth_mpc_finalize_cmd(struct qeth_card *card,
1997 struct qeth_cmd_buffer *iob)
1998{
1999 qeth_idx_finalize_cmd(card, iob);
2000
2001 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
2002 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
2003 card->seqno.pdu_hdr++;
2004 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
2005 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
2006
2007 iob->callback = qeth_release_buffer_cb;
2008}
2009
2010static bool qeth_mpc_match_reply(struct qeth_cmd_buffer *iob,
2011 struct qeth_cmd_buffer *reply)
2012{
2013
2014 return !IS_IPA(reply->data);
2015}
2016
2017static struct qeth_cmd_buffer *qeth_mpc_alloc_cmd(struct qeth_card *card,
2018 const void *data,
2019 unsigned int data_length)
2020{
2021 struct qeth_cmd_buffer *iob;
2022
2023 iob = qeth_alloc_cmd(&card->write, data_length, 1, QETH_TIMEOUT);
2024 if (!iob)
2025 return NULL;
2026
2027 memcpy(iob->data, data, data_length);
2028 qeth_setup_ccw(__ccw_from_cmd(iob), CCW_CMD_WRITE, 0, data_length,
2029 iob->data);
2030 iob->finalize = qeth_mpc_finalize_cmd;
2031 iob->match = qeth_mpc_match_reply;
2032 return iob;
2033}
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057static int qeth_send_control_data(struct qeth_card *card,
2058 struct qeth_cmd_buffer *iob,
2059 int (*reply_cb)(struct qeth_card *cb_card,
2060 struct qeth_reply *cb_reply,
2061 unsigned long cb_cmd),
2062 void *reply_param)
2063{
2064 struct qeth_channel *channel = iob->channel;
2065 struct qeth_reply *reply = &iob->reply;
2066 long timeout = iob->timeout;
2067 int rc;
2068
2069 QETH_CARD_TEXT(card, 2, "sendctl");
2070
2071 reply->callback = reply_cb;
2072 reply->param = reply_param;
2073
2074 timeout = wait_event_interruptible_timeout(card->wait_q,
2075 qeth_trylock_channel(channel),
2076 timeout);
2077 if (timeout <= 0) {
2078 qeth_put_cmd(iob);
2079 return (timeout == -ERESTARTSYS) ? -EINTR : -ETIME;
2080 }
2081
2082 if (iob->finalize)
2083 iob->finalize(card, iob);
2084 QETH_DBF_HEX(CTRL, 2, iob->data, min(iob->length, QETH_DBF_CTRL_LEN));
2085
2086 qeth_enqueue_cmd(card, iob);
2087
2088
2089 qeth_get_cmd(iob);
2090
2091 QETH_CARD_TEXT(card, 6, "noirqpnd");
2092 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
2093 rc = ccw_device_start_timeout(channel->ccwdev, __ccw_from_cmd(iob),
2094 (addr_t) iob, 0, 0, timeout);
2095 if (!rc)
2096 channel->active_cmd = iob;
2097 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
2098 if (rc) {
2099 QETH_DBF_MESSAGE(2, "qeth_send_control_data on device %x: ccw_device_start rc = %i\n",
2100 CARD_DEVID(card), rc);
2101 QETH_CARD_TEXT_(card, 2, " err%d", rc);
2102 qeth_dequeue_cmd(card, iob);
2103 qeth_put_cmd(iob);
2104 qeth_unlock_channel(card, channel);
2105 goto out;
2106 }
2107
2108 timeout = wait_for_completion_interruptible_timeout(&iob->done,
2109 timeout);
2110 if (timeout <= 0)
2111 rc = (timeout == -ERESTARTSYS) ? -EINTR : -ETIME;
2112
2113 qeth_dequeue_cmd(card, iob);
2114
2115 if (reply_cb) {
2116
2117 spin_lock_irq(&iob->lock);
2118 if (rc)
2119
2120 iob->rc = rc;
2121 spin_unlock_irq(&iob->lock);
2122 }
2123
2124 if (!rc)
2125 rc = iob->rc;
2126
2127out:
2128 qeth_put_cmd(iob);
2129 return rc;
2130}
2131
2132struct qeth_node_desc {
2133 struct node_descriptor nd1;
2134 struct node_descriptor nd2;
2135 struct node_descriptor nd3;
2136};
2137
2138static void qeth_read_conf_data_cb(struct qeth_card *card,
2139 struct qeth_cmd_buffer *iob,
2140 unsigned int data_length)
2141{
2142 struct qeth_node_desc *nd = (struct qeth_node_desc *) iob->data;
2143 int rc = 0;
2144 u8 *tag;
2145
2146 QETH_CARD_TEXT(card, 2, "cfgunit");
2147
2148 if (data_length < sizeof(*nd)) {
2149 rc = -EINVAL;
2150 goto out;
2151 }
2152
2153 card->info.is_vm_nic = nd->nd1.plant[0] == _ascebc['V'] &&
2154 nd->nd1.plant[1] == _ascebc['M'];
2155 tag = (u8 *)&nd->nd1.tag;
2156 card->info.chpid = tag[0];
2157 card->info.unit_addr2 = tag[1];
2158
2159 tag = (u8 *)&nd->nd2.tag;
2160 card->info.cula = tag[1];
2161
2162 card->info.use_v1_blkt = nd->nd3.model[0] == 0xF0 &&
2163 nd->nd3.model[1] == 0xF0 &&
2164 nd->nd3.model[2] >= 0xF1 &&
2165 nd->nd3.model[2] <= 0xF4;
2166
2167out:
2168 qeth_notify_cmd(iob, rc);
2169 qeth_put_cmd(iob);
2170}
2171
2172static int qeth_read_conf_data(struct qeth_card *card)
2173{
2174 struct qeth_channel *channel = &card->data;
2175 struct qeth_cmd_buffer *iob;
2176 struct ciw *ciw;
2177
2178
2179 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
2180 if (!ciw || ciw->cmd == 0)
2181 return -EOPNOTSUPP;
2182 if (ciw->count < sizeof(struct qeth_node_desc))
2183 return -EINVAL;
2184
2185 iob = qeth_alloc_cmd(channel, ciw->count, 1, QETH_RCD_TIMEOUT);
2186 if (!iob)
2187 return -ENOMEM;
2188
2189 iob->callback = qeth_read_conf_data_cb;
2190 qeth_setup_ccw(__ccw_from_cmd(iob), ciw->cmd, 0, iob->length,
2191 iob->data);
2192
2193 return qeth_send_control_data(card, iob, NULL, NULL);
2194}
2195
2196static int qeth_idx_check_activate_response(struct qeth_card *card,
2197 struct qeth_channel *channel,
2198 struct qeth_cmd_buffer *iob)
2199{
2200 int rc;
2201
2202 rc = qeth_check_idx_response(card, iob->data);
2203 if (rc)
2204 return rc;
2205
2206 if (QETH_IS_IDX_ACT_POS_REPLY(iob->data))
2207 return 0;
2208
2209
2210 QETH_CARD_TEXT_(card, 2, "idxneg%c",
2211 QETH_IDX_ACT_CAUSE_CODE(iob->data));
2212
2213 switch (QETH_IDX_ACT_CAUSE_CODE(iob->data)) {
2214 case QETH_IDX_ACT_ERR_EXCL:
2215 dev_err(&channel->ccwdev->dev,
2216 "The adapter is used exclusively by another host\n");
2217 return -EBUSY;
2218 case QETH_IDX_ACT_ERR_AUTH:
2219 case QETH_IDX_ACT_ERR_AUTH_USER:
2220 dev_err(&channel->ccwdev->dev,
2221 "Setting the device online failed because of insufficient authorization\n");
2222 return -EPERM;
2223 default:
2224 QETH_DBF_MESSAGE(2, "IDX_ACTIVATE on channel %x: negative reply\n",
2225 CCW_DEVID(channel->ccwdev));
2226 return -EIO;
2227 }
2228}
2229
2230static void qeth_idx_activate_read_channel_cb(struct qeth_card *card,
2231 struct qeth_cmd_buffer *iob,
2232 unsigned int data_length)
2233{
2234 struct qeth_channel *channel = iob->channel;
2235 u16 peer_level;
2236 int rc;
2237
2238 QETH_CARD_TEXT(card, 2, "idxrdcb");
2239
2240 rc = qeth_idx_check_activate_response(card, channel, iob);
2241 if (rc)
2242 goto out;
2243
2244 memcpy(&peer_level, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
2245 if (peer_level != qeth_peer_func_level(card->info.func_level)) {
2246 QETH_DBF_MESSAGE(2, "IDX_ACTIVATE on channel %x: function level mismatch (sent: %#x, received: %#x)\n",
2247 CCW_DEVID(channel->ccwdev),
2248 card->info.func_level, peer_level);
2249 rc = -EINVAL;
2250 goto out;
2251 }
2252
2253 memcpy(&card->token.issuer_rm_r,
2254 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
2255 QETH_MPC_TOKEN_LENGTH);
2256 memcpy(&card->info.mcl_level[0],
2257 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
2258
2259out:
2260 qeth_notify_cmd(iob, rc);
2261 qeth_put_cmd(iob);
2262}
2263
2264static void qeth_idx_activate_write_channel_cb(struct qeth_card *card,
2265 struct qeth_cmd_buffer *iob,
2266 unsigned int data_length)
2267{
2268 struct qeth_channel *channel = iob->channel;
2269 u16 peer_level;
2270 int rc;
2271
2272 QETH_CARD_TEXT(card, 2, "idxwrcb");
2273
2274 rc = qeth_idx_check_activate_response(card, channel, iob);
2275 if (rc)
2276 goto out;
2277
2278 memcpy(&peer_level, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
2279 if ((peer_level & ~0x0100) !=
2280 qeth_peer_func_level(card->info.func_level)) {
2281 QETH_DBF_MESSAGE(2, "IDX_ACTIVATE on channel %x: function level mismatch (sent: %#x, received: %#x)\n",
2282 CCW_DEVID(channel->ccwdev),
2283 card->info.func_level, peer_level);
2284 rc = -EINVAL;
2285 }
2286
2287out:
2288 qeth_notify_cmd(iob, rc);
2289 qeth_put_cmd(iob);
2290}
2291
2292static void qeth_idx_setup_activate_cmd(struct qeth_card *card,
2293 struct qeth_cmd_buffer *iob)
2294{
2295 u16 addr = (card->info.cula << 8) + card->info.unit_addr2;
2296 u8 port = ((u8)card->dev->dev_port) | 0x80;
2297 struct ccw1 *ccw = __ccw_from_cmd(iob);
2298
2299 qeth_setup_ccw(&ccw[0], CCW_CMD_WRITE, CCW_FLAG_CC, IDX_ACTIVATE_SIZE,
2300 iob->data);
2301 qeth_setup_ccw(&ccw[1], CCW_CMD_READ, 0, iob->length, iob->data);
2302 iob->finalize = qeth_idx_finalize_cmd;
2303
2304 port |= QETH_IDX_ACT_INVAL_FRAME;
2305 memcpy(QETH_IDX_ACT_PNO(iob->data), &port, 1);
2306 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
2307 &card->token.issuer_rm_w, QETH_MPC_TOKEN_LENGTH);
2308 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
2309 &card->info.func_level, 2);
2310 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &card->info.ddev_devno, 2);
2311 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &addr, 2);
2312}
2313
2314static int qeth_idx_activate_read_channel(struct qeth_card *card)
2315{
2316 struct qeth_channel *channel = &card->read;
2317 struct qeth_cmd_buffer *iob;
2318 int rc;
2319
2320 QETH_CARD_TEXT(card, 2, "idxread");
2321
2322 iob = qeth_alloc_cmd(channel, QETH_BUFSIZE, 2, QETH_TIMEOUT);
2323 if (!iob)
2324 return -ENOMEM;
2325
2326 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
2327 qeth_idx_setup_activate_cmd(card, iob);
2328 iob->callback = qeth_idx_activate_read_channel_cb;
2329
2330 rc = qeth_send_control_data(card, iob, NULL, NULL);
2331 if (rc)
2332 return rc;
2333
2334 channel->state = CH_STATE_UP;
2335 return 0;
2336}
2337
2338static int qeth_idx_activate_write_channel(struct qeth_card *card)
2339{
2340 struct qeth_channel *channel = &card->write;
2341 struct qeth_cmd_buffer *iob;
2342 int rc;
2343
2344 QETH_CARD_TEXT(card, 2, "idxwrite");
2345
2346 iob = qeth_alloc_cmd(channel, QETH_BUFSIZE, 2, QETH_TIMEOUT);
2347 if (!iob)
2348 return -ENOMEM;
2349
2350 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
2351 qeth_idx_setup_activate_cmd(card, iob);
2352 iob->callback = qeth_idx_activate_write_channel_cb;
2353
2354 rc = qeth_send_control_data(card, iob, NULL, NULL);
2355 if (rc)
2356 return rc;
2357
2358 channel->state = CH_STATE_UP;
2359 return 0;
2360}
2361
2362static int qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2363 unsigned long data)
2364{
2365 struct qeth_cmd_buffer *iob;
2366
2367 QETH_CARD_TEXT(card, 2, "cmenblcb");
2368
2369 iob = (struct qeth_cmd_buffer *) data;
2370 memcpy(&card->token.cm_filter_r,
2371 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2372 QETH_MPC_TOKEN_LENGTH);
2373 return 0;
2374}
2375
2376static int qeth_cm_enable(struct qeth_card *card)
2377{
2378 struct qeth_cmd_buffer *iob;
2379
2380 QETH_CARD_TEXT(card, 2, "cmenable");
2381
2382 iob = qeth_mpc_alloc_cmd(card, CM_ENABLE, CM_ENABLE_SIZE);
2383 if (!iob)
2384 return -ENOMEM;
2385
2386 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2387 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2388 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2389 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2390
2391 return qeth_send_control_data(card, iob, qeth_cm_enable_cb, NULL);
2392}
2393
2394static int qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2395 unsigned long data)
2396{
2397 struct qeth_cmd_buffer *iob;
2398
2399 QETH_CARD_TEXT(card, 2, "cmsetpcb");
2400
2401 iob = (struct qeth_cmd_buffer *) data;
2402 memcpy(&card->token.cm_connection_r,
2403 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2404 QETH_MPC_TOKEN_LENGTH);
2405 return 0;
2406}
2407
2408static int qeth_cm_setup(struct qeth_card *card)
2409{
2410 struct qeth_cmd_buffer *iob;
2411
2412 QETH_CARD_TEXT(card, 2, "cmsetup");
2413
2414 iob = qeth_mpc_alloc_cmd(card, CM_SETUP, CM_SETUP_SIZE);
2415 if (!iob)
2416 return -ENOMEM;
2417
2418 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2419 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2420 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2421 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2422 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2423 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2424 return qeth_send_control_data(card, iob, qeth_cm_setup_cb, NULL);
2425}
2426
2427static bool qeth_is_supported_link_type(struct qeth_card *card, u8 link_type)
2428{
2429 if (link_type == QETH_LINK_TYPE_LANE_TR ||
2430 link_type == QETH_LINK_TYPE_HSTR) {
2431 dev_err(&card->gdev->dev, "Unsupported Token Ring device\n");
2432 return false;
2433 }
2434
2435 return true;
2436}
2437
2438static int qeth_update_max_mtu(struct qeth_card *card, unsigned int max_mtu)
2439{
2440 struct net_device *dev = card->dev;
2441 unsigned int new_mtu;
2442
2443 if (!max_mtu) {
2444
2445 if (IS_IQD(card))
2446 return -EINVAL;
2447
2448 max_mtu = ETH_MAX_MTU;
2449 }
2450
2451 rtnl_lock();
2452 if (IS_IQD(card)) {
2453
2454 new_mtu = (dev->mtu == dev->max_mtu) ? max_mtu : dev->mtu;
2455
2456
2457 card->qdio.in_buf_size = max_mtu + 2 * PAGE_SIZE;
2458 if (dev->max_mtu && dev->max_mtu != max_mtu)
2459 qeth_free_qdio_queues(card);
2460 } else {
2461 if (dev->mtu)
2462 new_mtu = dev->mtu;
2463
2464 else if (IS_LAYER2(card))
2465 new_mtu = ETH_DATA_LEN;
2466 else
2467 new_mtu = ETH_DATA_LEN - 8;
2468 }
2469
2470 dev->max_mtu = max_mtu;
2471 dev->mtu = min(new_mtu, max_mtu);
2472 rtnl_unlock();
2473 return 0;
2474}
2475
2476static int qeth_get_mtu_outof_framesize(int framesize)
2477{
2478 switch (framesize) {
2479 case 0x4000:
2480 return 8192;
2481 case 0x6000:
2482 return 16384;
2483 case 0xa000:
2484 return 32768;
2485 case 0xffff:
2486 return 57344;
2487 default:
2488 return 0;
2489 }
2490}
2491
2492static int qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2493 unsigned long data)
2494{
2495 __u16 mtu, framesize;
2496 __u16 len;
2497 struct qeth_cmd_buffer *iob;
2498 u8 link_type = 0;
2499
2500 QETH_CARD_TEXT(card, 2, "ulpenacb");
2501
2502 iob = (struct qeth_cmd_buffer *) data;
2503 memcpy(&card->token.ulp_filter_r,
2504 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2505 QETH_MPC_TOKEN_LENGTH);
2506 if (IS_IQD(card)) {
2507 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2508 mtu = qeth_get_mtu_outof_framesize(framesize);
2509 } else {
2510 mtu = *(__u16 *)QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data);
2511 }
2512 *(u16 *)reply->param = mtu;
2513
2514 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2515 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2516 memcpy(&link_type,
2517 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2518 if (!qeth_is_supported_link_type(card, link_type))
2519 return -EPROTONOSUPPORT;
2520 }
2521
2522 card->info.link_type = link_type;
2523 QETH_CARD_TEXT_(card, 2, "link%d", card->info.link_type);
2524 return 0;
2525}
2526
2527static u8 qeth_mpc_select_prot_type(struct qeth_card *card)
2528{
2529 if (IS_OSN(card))
2530 return QETH_PROT_OSN2;
2531 return IS_LAYER2(card) ? QETH_PROT_LAYER2 : QETH_PROT_TCPIP;
2532}
2533
2534static int qeth_ulp_enable(struct qeth_card *card)
2535{
2536 u8 prot_type = qeth_mpc_select_prot_type(card);
2537 struct qeth_cmd_buffer *iob;
2538 u16 max_mtu;
2539 int rc;
2540
2541 QETH_CARD_TEXT(card, 2, "ulpenabl");
2542
2543 iob = qeth_mpc_alloc_cmd(card, ULP_ENABLE, ULP_ENABLE_SIZE);
2544 if (!iob)
2545 return -ENOMEM;
2546
2547 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) = (u8) card->dev->dev_port;
2548 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data), &prot_type, 1);
2549 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2550 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2551 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2552 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2553 rc = qeth_send_control_data(card, iob, qeth_ulp_enable_cb, &max_mtu);
2554 if (rc)
2555 return rc;
2556 return qeth_update_max_mtu(card, max_mtu);
2557}
2558
2559static int qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2560 unsigned long data)
2561{
2562 struct qeth_cmd_buffer *iob;
2563
2564 QETH_CARD_TEXT(card, 2, "ulpstpcb");
2565
2566 iob = (struct qeth_cmd_buffer *) data;
2567 memcpy(&card->token.ulp_connection_r,
2568 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2569 QETH_MPC_TOKEN_LENGTH);
2570 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2571 3)) {
2572 QETH_CARD_TEXT(card, 2, "olmlimit");
2573 dev_err(&card->gdev->dev, "A connection could not be "
2574 "established because of an OLM limit\n");
2575 return -EMLINK;
2576 }
2577 return 0;
2578}
2579
2580static int qeth_ulp_setup(struct qeth_card *card)
2581{
2582 __u16 temp;
2583 struct qeth_cmd_buffer *iob;
2584
2585 QETH_CARD_TEXT(card, 2, "ulpsetup");
2586
2587 iob = qeth_mpc_alloc_cmd(card, ULP_SETUP, ULP_SETUP_SIZE);
2588 if (!iob)
2589 return -ENOMEM;
2590
2591 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2592 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2593 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2594 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2595 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2596 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2597
2598 memcpy(QETH_ULP_SETUP_CUA(iob->data), &card->info.ddev_devno, 2);
2599 temp = (card->info.cula << 8) + card->info.unit_addr2;
2600 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2601 return qeth_send_control_data(card, iob, qeth_ulp_setup_cb, NULL);
2602}
2603
2604static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q *q, int bidx)
2605{
2606 struct qeth_qdio_out_buffer *newbuf;
2607
2608 newbuf = kmem_cache_zalloc(qeth_qdio_outbuf_cache, GFP_ATOMIC);
2609 if (!newbuf)
2610 return -ENOMEM;
2611
2612 newbuf->buffer = q->qdio_bufs[bidx];
2613 skb_queue_head_init(&newbuf->skb_list);
2614 lockdep_set_class(&newbuf->skb_list.lock, &qdio_out_skb_queue_key);
2615 newbuf->q = q;
2616 newbuf->next_pending = q->bufs[bidx];
2617 atomic_set(&newbuf->state, QETH_QDIO_BUF_EMPTY);
2618 q->bufs[bidx] = newbuf;
2619 return 0;
2620}
2621
2622static void qeth_free_output_queue(struct qeth_qdio_out_q *q)
2623{
2624 if (!q)
2625 return;
2626
2627 qeth_drain_output_queue(q, true);
2628 qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
2629 kfree(q);
2630}
2631
2632static struct qeth_qdio_out_q *qeth_alloc_output_queue(void)
2633{
2634 struct qeth_qdio_out_q *q = kzalloc(sizeof(*q), GFP_KERNEL);
2635
2636 if (!q)
2637 return NULL;
2638
2639 if (qdio_alloc_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q)) {
2640 kfree(q);
2641 return NULL;
2642 }
2643 return q;
2644}
2645
2646static void qeth_tx_completion_timer(struct timer_list *timer)
2647{
2648 struct qeth_qdio_out_q *queue = from_timer(queue, timer, timer);
2649
2650 napi_schedule(&queue->napi);
2651 QETH_TXQ_STAT_INC(queue, completion_timer);
2652}
2653
2654static int qeth_alloc_qdio_queues(struct qeth_card *card)
2655{
2656 int i, j;
2657
2658 QETH_CARD_TEXT(card, 2, "allcqdbf");
2659
2660 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
2661 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
2662 return 0;
2663
2664 QETH_CARD_TEXT(card, 2, "inq");
2665 card->qdio.in_q = qeth_alloc_qdio_queue();
2666 if (!card->qdio.in_q)
2667 goto out_nomem;
2668
2669
2670 if (qeth_alloc_buffer_pool(card))
2671 goto out_freeinq;
2672
2673
2674 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2675 struct qeth_qdio_out_q *queue;
2676
2677 queue = qeth_alloc_output_queue();
2678 if (!queue)
2679 goto out_freeoutq;
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;
2683 queue->card = card;
2684 queue->queue_no = i;
2685 spin_lock_init(&queue->lock);
2686 timer_setup(&queue->timer, qeth_tx_completion_timer, 0);
2687 queue->coalesce_usecs = QETH_TX_COALESCE_USECS;
2688 queue->max_coalesced_frames = QETH_TX_MAX_COALESCED_FRAMES;
2689 queue->priority = QETH_QIB_PQUE_PRIO_DEFAULT;
2690
2691
2692 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2693 WARN_ON(queue->bufs[j]);
2694 if (qeth_init_qdio_out_buf(queue, j))
2695 goto out_freeoutqbufs;
2696 }
2697 }
2698
2699
2700 if (qeth_alloc_cq(card))
2701 goto out_freeoutq;
2702
2703 return 0;
2704
2705out_freeoutqbufs:
2706 while (j > 0) {
2707 --j;
2708 kmem_cache_free(qeth_qdio_outbuf_cache,
2709 card->qdio.out_qs[i]->bufs[j]);
2710 card->qdio.out_qs[i]->bufs[j] = NULL;
2711 }
2712out_freeoutq:
2713 while (i > 0) {
2714 qeth_free_output_queue(card->qdio.out_qs[--i]);
2715 card->qdio.out_qs[i] = NULL;
2716 }
2717 qeth_free_buffer_pool(card);
2718out_freeinq:
2719 qeth_free_qdio_queue(card->qdio.in_q);
2720 card->qdio.in_q = NULL;
2721out_nomem:
2722 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
2723 return -ENOMEM;
2724}
2725
2726static void qeth_free_qdio_queues(struct qeth_card *card)
2727{
2728 int i, j;
2729
2730 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
2731 QETH_QDIO_UNINITIALIZED)
2732 return;
2733
2734 qeth_free_cq(card);
2735 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2736 if (card->qdio.in_q->bufs[j].rx_skb)
2737 dev_kfree_skb_any(card->qdio.in_q->bufs[j].rx_skb);
2738 }
2739 qeth_free_qdio_queue(card->qdio.in_q);
2740 card->qdio.in_q = NULL;
2741
2742 qeth_free_buffer_pool(card);
2743
2744 for (i = 0; i < card->qdio.no_out_queues; i++) {
2745 qeth_free_output_queue(card->qdio.out_qs[i]);
2746 card->qdio.out_qs[i] = NULL;
2747 }
2748}
2749
2750static void qeth_fill_qib_parms(struct qeth_card *card,
2751 struct qeth_qib_parms *parms)
2752{
2753 struct qeth_qdio_out_q *queue;
2754 unsigned int i;
2755
2756 parms->pcit_magic[0] = 'P';
2757 parms->pcit_magic[1] = 'C';
2758 parms->pcit_magic[2] = 'I';
2759 parms->pcit_magic[3] = 'T';
2760 ASCEBC(parms->pcit_magic, sizeof(parms->pcit_magic));
2761 parms->pcit_a = QETH_PCI_THRESHOLD_A(card);
2762 parms->pcit_b = QETH_PCI_THRESHOLD_B(card);
2763 parms->pcit_c = QETH_PCI_TIMER_VALUE(card);
2764
2765 parms->blkt_magic[0] = 'B';
2766 parms->blkt_magic[1] = 'L';
2767 parms->blkt_magic[2] = 'K';
2768 parms->blkt_magic[3] = 'T';
2769 ASCEBC(parms->blkt_magic, sizeof(parms->blkt_magic));
2770 parms->blkt_total = card->info.blkt.time_total;
2771 parms->blkt_inter_packet = card->info.blkt.inter_packet;
2772 parms->blkt_inter_packet_jumbo = card->info.blkt.inter_packet_jumbo;
2773
2774
2775 if (qeth_uses_tx_prio_queueing(card) || card->qdio.no_out_queues == 1)
2776 return;
2777
2778 parms->pque_magic[0] = 'P';
2779 parms->pque_magic[1] = 'Q';
2780 parms->pque_magic[2] = 'U';
2781 parms->pque_magic[3] = 'E';
2782 ASCEBC(parms->pque_magic, sizeof(parms->pque_magic));
2783 parms->pque_order = QETH_QIB_PQUE_ORDER_RR;
2784 parms->pque_units = QETH_QIB_PQUE_UNITS_SBAL;
2785
2786 qeth_for_each_output_queue(card, queue, i)
2787 parms->pque_priority[i] = queue->priority;
2788}
2789
2790static int qeth_qdio_activate(struct qeth_card *card)
2791{
2792 QETH_CARD_TEXT(card, 3, "qdioact");
2793 return qdio_activate(CARD_DDEV(card));
2794}
2795
2796static int qeth_dm_act(struct qeth_card *card)
2797{
2798 struct qeth_cmd_buffer *iob;
2799
2800 QETH_CARD_TEXT(card, 2, "dmact");
2801
2802 iob = qeth_mpc_alloc_cmd(card, DM_ACT, DM_ACT_SIZE);
2803 if (!iob)
2804 return -ENOMEM;
2805
2806 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
2807 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2808 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
2809 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2810 return qeth_send_control_data(card, iob, NULL, NULL);
2811}
2812
2813static int qeth_mpc_initialize(struct qeth_card *card)
2814{
2815 int rc;
2816
2817 QETH_CARD_TEXT(card, 2, "mpcinit");
2818
2819 rc = qeth_issue_next_read(card);
2820 if (rc) {
2821 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
2822 return rc;
2823 }
2824 rc = qeth_cm_enable(card);
2825 if (rc) {
2826 QETH_CARD_TEXT_(card, 2, "2err%d", rc);
2827 return rc;
2828 }
2829 rc = qeth_cm_setup(card);
2830 if (rc) {
2831 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
2832 return rc;
2833 }
2834 rc = qeth_ulp_enable(card);
2835 if (rc) {
2836 QETH_CARD_TEXT_(card, 2, "4err%d", rc);
2837 return rc;
2838 }
2839 rc = qeth_ulp_setup(card);
2840 if (rc) {
2841 QETH_CARD_TEXT_(card, 2, "5err%d", rc);
2842 return rc;
2843 }
2844 rc = qeth_alloc_qdio_queues(card);
2845 if (rc) {
2846 QETH_CARD_TEXT_(card, 2, "5err%d", rc);
2847 return rc;
2848 }
2849 rc = qeth_qdio_establish(card);
2850 if (rc) {
2851 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
2852 qeth_free_qdio_queues(card);
2853 return rc;
2854 }
2855 rc = qeth_qdio_activate(card);
2856 if (rc) {
2857 QETH_CARD_TEXT_(card, 2, "7err%d", rc);
2858 return rc;
2859 }
2860 rc = qeth_dm_act(card);
2861 if (rc) {
2862 QETH_CARD_TEXT_(card, 2, "8err%d", rc);
2863 return rc;
2864 }
2865
2866 return 0;
2867}
2868
2869static void qeth_print_status_message(struct qeth_card *card)
2870{
2871 switch (card->info.type) {
2872 case QETH_CARD_TYPE_OSD:
2873 case QETH_CARD_TYPE_OSM:
2874 case QETH_CARD_TYPE_OSX:
2875
2876
2877
2878
2879 if (!card->info.mcl_level[0]) {
2880 sprintf(card->info.mcl_level, "%02x%02x",
2881 card->info.mcl_level[2],
2882 card->info.mcl_level[3]);
2883 break;
2884 }
2885 fallthrough;
2886 case QETH_CARD_TYPE_IQD:
2887 if (IS_VM_NIC(card) || (card->info.mcl_level[0] & 0x80)) {
2888 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
2889 card->info.mcl_level[0]];
2890 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
2891 card->info.mcl_level[1]];
2892 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
2893 card->info.mcl_level[2]];
2894 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
2895 card->info.mcl_level[3]];
2896 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2897 }
2898 break;
2899 default:
2900 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
2901 }
2902 dev_info(&card->gdev->dev,
2903 "Device is a%s card%s%s%s\nwith link type %s.\n",
2904 qeth_get_cardname(card),
2905 (card->info.mcl_level[0]) ? " (level: " : "",
2906 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2907 (card->info.mcl_level[0]) ? ")" : "",
2908 qeth_get_cardname_short(card));
2909}
2910
2911static void qeth_initialize_working_pool_list(struct qeth_card *card)
2912{
2913 struct qeth_buffer_pool_entry *entry;
2914
2915 QETH_CARD_TEXT(card, 5, "inwrklst");
2916
2917 list_for_each_entry(entry,
2918 &card->qdio.init_pool.entry_list, init_list) {
2919 qeth_put_buffer_pool_entry(card, entry);
2920 }
2921}
2922
2923static struct qeth_buffer_pool_entry *qeth_find_free_buffer_pool_entry(
2924 struct qeth_card *card)
2925{
2926 struct qeth_buffer_pool_entry *entry;
2927 int i, free;
2928
2929 if (list_empty(&card->qdio.in_buf_pool.entry_list))
2930 return NULL;
2931
2932 list_for_each_entry(entry, &card->qdio.in_buf_pool.entry_list, list) {
2933 free = 1;
2934 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2935 if (page_count(entry->elements[i]) > 1) {
2936 free = 0;
2937 break;
2938 }
2939 }
2940 if (free) {
2941 list_del_init(&entry->list);
2942 return entry;
2943 }
2944 }
2945
2946
2947 entry = list_first_entry(&card->qdio.in_buf_pool.entry_list,
2948 struct qeth_buffer_pool_entry, list);
2949 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2950 if (page_count(entry->elements[i]) > 1) {
2951 struct page *page = dev_alloc_page();
2952
2953 if (!page)
2954 return NULL;
2955
2956 __free_page(entry->elements[i]);
2957 entry->elements[i] = page;
2958 QETH_CARD_STAT_INC(card, rx_sg_alloc_page);
2959 }
2960 }
2961 list_del_init(&entry->list);
2962 return entry;
2963}
2964
2965static int qeth_init_input_buffer(struct qeth_card *card,
2966 struct qeth_qdio_buffer *buf)
2967{
2968 struct qeth_buffer_pool_entry *pool_entry = buf->pool_entry;
2969 int i;
2970
2971 if ((card->options.cq == QETH_CQ_ENABLED) && (!buf->rx_skb)) {
2972 buf->rx_skb = netdev_alloc_skb(card->dev,
2973 ETH_HLEN +
2974 sizeof(struct ipv6hdr));
2975 if (!buf->rx_skb)
2976 return -ENOMEM;
2977 }
2978
2979 if (!pool_entry) {
2980 pool_entry = qeth_find_free_buffer_pool_entry(card);
2981 if (!pool_entry)
2982 return -ENOBUFS;
2983
2984 buf->pool_entry = pool_entry;
2985 }
2986
2987
2988
2989
2990
2991
2992
2993 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2994 buf->buffer->element[i].length = PAGE_SIZE;
2995 buf->buffer->element[i].addr =
2996 page_to_phys(pool_entry->elements[i]);
2997 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2998 buf->buffer->element[i].eflags = SBAL_EFLAGS_LAST_ENTRY;
2999 else
3000 buf->buffer->element[i].eflags = 0;
3001 buf->buffer->element[i].sflags = 0;
3002 }
3003 return 0;
3004}
3005
3006static unsigned int qeth_tx_select_bulk_max(struct qeth_card *card,
3007 struct qeth_qdio_out_q *queue)
3008{
3009 if (!IS_IQD(card) ||
3010 qeth_iqd_is_mcast_queue(card, queue) ||
3011 card->options.cq == QETH_CQ_ENABLED ||
3012 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd))
3013 return 1;
3014
3015 return card->ssqd.mmwc ? card->ssqd.mmwc : 1;
3016}
3017
3018static int qeth_init_qdio_queues(struct qeth_card *card)
3019{
3020 unsigned int rx_bufs = card->qdio.in_buf_pool.buf_count;
3021 unsigned int i;
3022 int rc;
3023
3024 QETH_CARD_TEXT(card, 2, "initqdqs");
3025
3026
3027 qdio_reset_buffers(card->qdio.in_q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
3028 memset(&card->rx, 0, sizeof(struct qeth_rx));
3029
3030 qeth_initialize_working_pool_list(card);
3031
3032 for (i = 0; i < rx_bufs; i++) {
3033 rc = qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3034 if (rc)
3035 return rc;
3036 }
3037
3038 card->qdio.in_q->next_buf_to_init = QDIO_BUFNR(rx_bufs);
3039 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0, rx_bufs);
3040 if (rc) {
3041 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
3042 return rc;
3043 }
3044
3045
3046 rc = qeth_cq_init(card);
3047 if (rc) {
3048 return rc;
3049 }
3050
3051
3052 for (i = 0; i < card->qdio.no_out_queues; ++i) {
3053 struct qeth_qdio_out_q *queue = card->qdio.out_qs[i];
3054
3055 qdio_reset_buffers(queue->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
3056 queue->max_elements = QETH_MAX_BUFFER_ELEMENTS(card);
3057 queue->next_buf_to_fill = 0;
3058 queue->do_pack = 0;
3059 queue->prev_hdr = NULL;
3060 queue->coalesced_frames = 0;
3061 queue->bulk_start = 0;
3062 queue->bulk_count = 0;
3063 queue->bulk_max = qeth_tx_select_bulk_max(card, queue);
3064 atomic_set(&queue->used_buffers, 0);
3065 atomic_set(&queue->set_pci_flags_count, 0);
3066 netdev_tx_reset_queue(netdev_get_tx_queue(card->dev, i));
3067 }
3068 return 0;
3069}
3070
3071static void qeth_ipa_finalize_cmd(struct qeth_card *card,
3072 struct qeth_cmd_buffer *iob)
3073{
3074 qeth_mpc_finalize_cmd(card, iob);
3075
3076
3077 __ipa_cmd(iob)->hdr.seqno = card->seqno.ipa++;
3078}
3079
3080void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
3081 u16 cmd_length,
3082 bool (*match)(struct qeth_cmd_buffer *iob,
3083 struct qeth_cmd_buffer *reply))
3084{
3085 u8 prot_type = qeth_mpc_select_prot_type(card);
3086 u16 total_length = iob->length;
3087
3088 qeth_setup_ccw(__ccw_from_cmd(iob), CCW_CMD_WRITE, 0, total_length,
3089 iob->data);
3090 iob->finalize = qeth_ipa_finalize_cmd;
3091 iob->match = match;
3092
3093 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
3094 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &total_length, 2);
3095 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data), &prot_type, 1);
3096 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &cmd_length, 2);
3097 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &cmd_length, 2);
3098 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
3099 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3100 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &cmd_length, 2);
3101}
3102EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd);
3103
3104static bool qeth_ipa_match_reply(struct qeth_cmd_buffer *iob,
3105 struct qeth_cmd_buffer *reply)
3106{
3107 struct qeth_ipa_cmd *ipa_reply = __ipa_reply(reply);
3108
3109 return ipa_reply && (__ipa_cmd(iob)->hdr.seqno == ipa_reply->hdr.seqno);
3110}
3111
3112struct qeth_cmd_buffer *qeth_ipa_alloc_cmd(struct qeth_card *card,
3113 enum qeth_ipa_cmds cmd_code,
3114 enum qeth_prot_versions prot,
3115 unsigned int data_length)
3116{
3117 struct qeth_cmd_buffer *iob;
3118 struct qeth_ipacmd_hdr *hdr;
3119
3120 data_length += offsetof(struct qeth_ipa_cmd, data);
3121 iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_length, 1,
3122 QETH_IPA_TIMEOUT);
3123 if (!iob)
3124 return NULL;
3125
3126 qeth_prepare_ipa_cmd(card, iob, data_length, qeth_ipa_match_reply);
3127
3128 hdr = &__ipa_cmd(iob)->hdr;
3129 hdr->command = cmd_code;
3130 hdr->initiator = IPA_CMD_INITIATOR_HOST;
3131
3132 hdr->adapter_type = QETH_LINK_TYPE_FAST_ETH;
3133 hdr->rel_adapter_no = (u8) card->dev->dev_port;
3134 hdr->prim_version_no = IS_LAYER2(card) ? 2 : 1;
3135 hdr->param_count = 1;
3136 hdr->prot_version = prot;
3137 return iob;
3138}
3139EXPORT_SYMBOL_GPL(qeth_ipa_alloc_cmd);
3140
3141static int qeth_send_ipa_cmd_cb(struct qeth_card *card,
3142 struct qeth_reply *reply, unsigned long data)
3143{
3144 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3145
3146 return (cmd->hdr.return_code) ? -EIO : 0;
3147}
3148
3149
3150
3151
3152
3153
3154
3155int qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
3156 int (*reply_cb)(struct qeth_card *, struct qeth_reply*,
3157 unsigned long),
3158 void *reply_param)
3159{
3160 int rc;
3161
3162 QETH_CARD_TEXT(card, 4, "sendipa");
3163
3164 if (card->read_or_write_problem) {
3165 qeth_put_cmd(iob);
3166 return -EIO;
3167 }
3168
3169 if (reply_cb == NULL)
3170 reply_cb = qeth_send_ipa_cmd_cb;
3171 rc = qeth_send_control_data(card, iob, reply_cb, reply_param);
3172 if (rc == -ETIME) {
3173 qeth_clear_ipacmd_list(card);
3174 qeth_schedule_recovery(card);
3175 }
3176 return rc;
3177}
3178EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd);
3179
3180static int qeth_send_startlan_cb(struct qeth_card *card,
3181 struct qeth_reply *reply, unsigned long data)
3182{
3183 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3184
3185 if (cmd->hdr.return_code == IPA_RC_LAN_OFFLINE)
3186 return -ENETDOWN;
3187
3188 return (cmd->hdr.return_code) ? -EIO : 0;
3189}
3190
3191static int qeth_send_startlan(struct qeth_card *card)
3192{
3193 struct qeth_cmd_buffer *iob;
3194
3195 QETH_CARD_TEXT(card, 2, "strtlan");
3196
3197 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_STARTLAN, QETH_PROT_NONE, 0);
3198 if (!iob)
3199 return -ENOMEM;
3200 return qeth_send_ipa_cmd(card, iob, qeth_send_startlan_cb, NULL);
3201}
3202
3203static int qeth_setadpparms_inspect_rc(struct qeth_ipa_cmd *cmd)
3204{
3205 if (!cmd->hdr.return_code)
3206 cmd->hdr.return_code =
3207 cmd->data.setadapterparms.hdr.return_code;
3208 return cmd->hdr.return_code;
3209}
3210
3211static int qeth_query_setadapterparms_cb(struct qeth_card *card,
3212 struct qeth_reply *reply, unsigned long data)
3213{
3214 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3215 struct qeth_query_cmds_supp *query_cmd;
3216
3217 QETH_CARD_TEXT(card, 3, "quyadpcb");
3218 if (qeth_setadpparms_inspect_rc(cmd))
3219 return -EIO;
3220
3221 query_cmd = &cmd->data.setadapterparms.data.query_cmds_supp;
3222 if (query_cmd->lan_type & 0x7f) {
3223 if (!qeth_is_supported_link_type(card, query_cmd->lan_type))
3224 return -EPROTONOSUPPORT;
3225
3226 card->info.link_type = query_cmd->lan_type;
3227 QETH_CARD_TEXT_(card, 2, "lnk %d", card->info.link_type);
3228 }
3229
3230 card->options.adp.supported = query_cmd->supported_cmds;
3231 return 0;
3232}
3233
3234static struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
3235 enum qeth_ipa_setadp_cmd adp_cmd,
3236 unsigned int data_length)
3237{
3238 struct qeth_ipacmd_setadpparms_hdr *hdr;
3239 struct qeth_cmd_buffer *iob;
3240
3241 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SETADAPTERPARMS, QETH_PROT_IPV4,
3242 data_length +
3243 offsetof(struct qeth_ipacmd_setadpparms,
3244 data));
3245 if (!iob)
3246 return NULL;
3247
3248 hdr = &__ipa_cmd(iob)->data.setadapterparms.hdr;
3249 hdr->cmdlength = sizeof(*hdr) + data_length;
3250 hdr->command_code = adp_cmd;
3251 hdr->used_total = 1;
3252 hdr->seq_no = 1;
3253 return iob;
3254}
3255
3256static int qeth_query_setadapterparms(struct qeth_card *card)
3257{
3258 int rc;
3259 struct qeth_cmd_buffer *iob;
3260
3261 QETH_CARD_TEXT(card, 3, "queryadp");
3262 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
3263 SETADP_DATA_SIZEOF(query_cmds_supp));
3264 if (!iob)
3265 return -ENOMEM;
3266 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
3267 return rc;
3268}
3269
3270static int qeth_query_ipassists_cb(struct qeth_card *card,
3271 struct qeth_reply *reply, unsigned long data)
3272{
3273 struct qeth_ipa_cmd *cmd;
3274
3275 QETH_CARD_TEXT(card, 2, "qipasscb");
3276
3277 cmd = (struct qeth_ipa_cmd *) data;
3278
3279 switch (cmd->hdr.return_code) {
3280 case IPA_RC_SUCCESS:
3281 break;
3282 case IPA_RC_NOTSUPP:
3283 case IPA_RC_L2_UNSUPPORTED_CMD:
3284 QETH_CARD_TEXT(card, 2, "ipaunsup");
3285 card->options.ipa4.supported |= IPA_SETADAPTERPARMS;
3286 card->options.ipa6.supported |= IPA_SETADAPTERPARMS;
3287 return -EOPNOTSUPP;
3288 default:
3289 QETH_DBF_MESSAGE(1, "IPA_CMD_QIPASSIST on device %x: Unhandled rc=%#x\n",
3290 CARD_DEVID(card), cmd->hdr.return_code);
3291 return -EIO;
3292 }
3293
3294 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
3295 card->options.ipa4 = cmd->hdr.assists;
3296 else if (cmd->hdr.prot_version == QETH_PROT_IPV6)
3297 card->options.ipa6 = cmd->hdr.assists;
3298 else
3299 QETH_DBF_MESSAGE(1, "IPA_CMD_QIPASSIST on device %x: Flawed LIC detected\n",
3300 CARD_DEVID(card));
3301 return 0;
3302}
3303
3304static int qeth_query_ipassists(struct qeth_card *card,
3305 enum qeth_prot_versions prot)
3306{
3307 int rc;
3308 struct qeth_cmd_buffer *iob;
3309
3310 QETH_CARD_TEXT_(card, 2, "qipassi%i", prot);
3311 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_QIPASSIST, prot, 0);
3312 if (!iob)
3313 return -ENOMEM;
3314 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
3315 return rc;
3316}
3317
3318static int qeth_query_switch_attributes_cb(struct qeth_card *card,
3319 struct qeth_reply *reply, unsigned long data)
3320{
3321 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3322 struct qeth_query_switch_attributes *attrs;
3323 struct qeth_switch_info *sw_info;
3324
3325 QETH_CARD_TEXT(card, 2, "qswiatcb");
3326 if (qeth_setadpparms_inspect_rc(cmd))
3327 return -EIO;
3328
3329 sw_info = (struct qeth_switch_info *)reply->param;
3330 attrs = &cmd->data.setadapterparms.data.query_switch_attributes;
3331 sw_info->capabilities = attrs->capabilities;
3332 sw_info->settings = attrs->settings;
3333 QETH_CARD_TEXT_(card, 2, "%04x%04x", sw_info->capabilities,
3334 sw_info->settings);
3335 return 0;
3336}
3337
3338int qeth_query_switch_attributes(struct qeth_card *card,
3339 struct qeth_switch_info *sw_info)
3340{
3341 struct qeth_cmd_buffer *iob;
3342
3343 QETH_CARD_TEXT(card, 2, "qswiattr");
3344 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES))
3345 return -EOPNOTSUPP;
3346 if (!netif_carrier_ok(card->dev))
3347 return -ENOMEDIUM;
3348 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES, 0);
3349 if (!iob)
3350 return -ENOMEM;
3351 return qeth_send_ipa_cmd(card, iob,
3352 qeth_query_switch_attributes_cb, sw_info);
3353}
3354
3355struct qeth_cmd_buffer *qeth_get_diag_cmd(struct qeth_card *card,
3356 enum qeth_diags_cmds sub_cmd,
3357 unsigned int data_length)
3358{
3359 struct qeth_ipacmd_diagass *cmd;
3360 struct qeth_cmd_buffer *iob;
3361
3362 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SET_DIAG_ASS, QETH_PROT_NONE,
3363 DIAG_HDR_LEN + data_length);
3364 if (!iob)
3365 return NULL;
3366
3367 cmd = &__ipa_cmd(iob)->data.diagass;
3368 cmd->subcmd_len = DIAG_SUB_HDR_LEN + data_length;
3369 cmd->subcmd = sub_cmd;
3370 return iob;
3371}
3372EXPORT_SYMBOL_GPL(qeth_get_diag_cmd);
3373
3374static int qeth_query_setdiagass_cb(struct qeth_card *card,
3375 struct qeth_reply *reply, unsigned long data)
3376{
3377 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3378 u16 rc = cmd->hdr.return_code;
3379
3380 if (rc) {
3381 QETH_CARD_TEXT_(card, 2, "diagq:%x", rc);
3382 return -EIO;
3383 }
3384
3385 card->info.diagass_support = cmd->data.diagass.ext;
3386 return 0;
3387}
3388
3389static int qeth_query_setdiagass(struct qeth_card *card)
3390{
3391 struct qeth_cmd_buffer *iob;
3392
3393 QETH_CARD_TEXT(card, 2, "qdiagass");
3394 iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_QUERY, 0);
3395 if (!iob)
3396 return -ENOMEM;
3397 return qeth_send_ipa_cmd(card, iob, qeth_query_setdiagass_cb, NULL);
3398}
3399
3400static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
3401{
3402 unsigned long info = get_zeroed_page(GFP_KERNEL);
3403 struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
3404 struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
3405 struct ccw_dev_id ccwid;
3406 int level;
3407
3408 tid->chpid = card->info.chpid;
3409 ccw_device_get_id(CARD_RDEV(card), &ccwid);
3410 tid->ssid = ccwid.ssid;
3411 tid->devno = ccwid.devno;
3412 if (!info)
3413 return;
3414 level = stsi(NULL, 0, 0, 0);
3415 if ((level >= 2) && (stsi(info222, 2, 2, 2) == 0))
3416 tid->lparnr = info222->lpar_number;
3417 if ((level >= 3) && (stsi(info322, 3, 2, 2) == 0)) {
3418 EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
3419 memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
3420 }
3421 free_page(info);
3422}
3423
3424static int qeth_hw_trap_cb(struct qeth_card *card,
3425 struct qeth_reply *reply, unsigned long data)
3426{
3427 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3428 u16 rc = cmd->hdr.return_code;
3429
3430 if (rc) {
3431 QETH_CARD_TEXT_(card, 2, "trapc:%x", rc);
3432 return -EIO;
3433 }
3434 return 0;
3435}
3436
3437int qeth_hw_trap(struct qeth_card *card, enum qeth_diags_trap_action action)
3438{
3439 struct qeth_cmd_buffer *iob;
3440 struct qeth_ipa_cmd *cmd;
3441
3442 QETH_CARD_TEXT(card, 2, "diagtrap");
3443 iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_TRAP, 64);
3444 if (!iob)
3445 return -ENOMEM;
3446 cmd = __ipa_cmd(iob);
3447 cmd->data.diagass.type = 1;
3448 cmd->data.diagass.action = action;
3449 switch (action) {
3450 case QETH_DIAGS_TRAP_ARM:
3451 cmd->data.diagass.options = 0x0003;
3452 cmd->data.diagass.ext = 0x00010000 +
3453 sizeof(struct qeth_trap_id);
3454 qeth_get_trap_id(card,
3455 (struct qeth_trap_id *)cmd->data.diagass.cdata);
3456 break;
3457 case QETH_DIAGS_TRAP_DISARM:
3458 cmd->data.diagass.options = 0x0001;
3459 break;
3460 case QETH_DIAGS_TRAP_CAPTURE:
3461 break;
3462 }
3463 return qeth_send_ipa_cmd(card, iob, qeth_hw_trap_cb, NULL);
3464}
3465
3466static int qeth_check_qdio_errors(struct qeth_card *card,
3467 struct qdio_buffer *buf,
3468 unsigned int qdio_error,
3469 const char *dbftext)
3470{
3471 if (qdio_error) {
3472 QETH_CARD_TEXT(card, 2, dbftext);
3473 QETH_CARD_TEXT_(card, 2, " F15=%02X",
3474 buf->element[15].sflags);
3475 QETH_CARD_TEXT_(card, 2, " F14=%02X",
3476 buf->element[14].sflags);
3477 QETH_CARD_TEXT_(card, 2, " qerr=%X", qdio_error);
3478 if ((buf->element[15].sflags) == 0x12) {
3479 QETH_CARD_STAT_INC(card, rx_fifo_errors);
3480 return 0;
3481 } else
3482 return 1;
3483 }
3484 return 0;
3485}
3486
3487static unsigned int qeth_rx_refill_queue(struct qeth_card *card,
3488 unsigned int count)
3489{
3490 struct qeth_qdio_q *queue = card->qdio.in_q;
3491 struct list_head *lh;
3492 int i;
3493 int rc;
3494 int newcount = 0;
3495
3496
3497 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)) {
3498 for (i = queue->next_buf_to_init;
3499 i < queue->next_buf_to_init + count; ++i) {
3500 if (qeth_init_input_buffer(card,
3501 &queue->bufs[QDIO_BUFNR(i)])) {
3502 break;
3503 } else {
3504 newcount++;
3505 }
3506 }
3507
3508 if (newcount < count) {
3509
3510
3511 atomic_set(&card->force_alloc_skb, 3);
3512 count = newcount;
3513 } else {
3514 atomic_add_unless(&card->force_alloc_skb, -1, 0);
3515 }
3516
3517 if (!count) {
3518 i = 0;
3519 list_for_each(lh, &card->qdio.in_buf_pool.entry_list)
3520 i++;
3521 if (i == card->qdio.in_buf_pool.buf_count) {
3522 QETH_CARD_TEXT(card, 2, "qsarbw");
3523 schedule_delayed_work(
3524 &card->buffer_reclaim_work,
3525 QETH_RECLAIM_WORK_TIME);
3526 }
3527 return 0;
3528 }
3529
3530 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0,
3531 queue->next_buf_to_init, count);
3532 if (rc) {
3533 QETH_CARD_TEXT(card, 2, "qinberr");
3534 }
3535 queue->next_buf_to_init = QDIO_BUFNR(queue->next_buf_to_init +
3536 count);
3537 return count;
3538 }
3539
3540 return 0;
3541}
3542
3543static void qeth_buffer_reclaim_work(struct work_struct *work)
3544{
3545 struct qeth_card *card = container_of(to_delayed_work(work),
3546 struct qeth_card,
3547 buffer_reclaim_work);
3548
3549 local_bh_disable();
3550 napi_schedule(&card->napi);
3551
3552 local_bh_enable();
3553}
3554
3555static void qeth_handle_send_error(struct qeth_card *card,
3556 struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err)
3557{
3558 int sbalf15 = buffer->buffer->element[15].sflags;
3559
3560 QETH_CARD_TEXT(card, 6, "hdsnderr");
3561 qeth_check_qdio_errors(card, buffer->buffer, qdio_err, "qouterr");
3562
3563 if (!qdio_err)
3564 return;
3565
3566 if ((sbalf15 >= 15) && (sbalf15 <= 31))
3567 return;
3568
3569 QETH_CARD_TEXT(card, 1, "lnkfail");
3570 QETH_CARD_TEXT_(card, 1, "%04x %02x",
3571 (u16)qdio_err, (u8)sbalf15);
3572}
3573
3574
3575
3576
3577
3578
3579
3580static int qeth_prep_flush_pack_buffer(struct qeth_qdio_out_q *queue)
3581{
3582 struct qeth_qdio_out_buffer *buffer;
3583
3584 buffer = queue->bufs[queue->next_buf_to_fill];
3585 if ((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
3586 (buffer->next_element_to_fill > 0)) {
3587
3588 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
3589 queue->next_buf_to_fill =
3590 QDIO_BUFNR(queue->next_buf_to_fill + 1);
3591 return 1;
3592 }
3593 return 0;
3594}
3595
3596
3597
3598
3599
3600static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
3601{
3602 if (!queue->do_pack) {
3603 if (atomic_read(&queue->used_buffers)
3604 >= QETH_HIGH_WATERMARK_PACK){
3605
3606 QETH_CARD_TEXT(queue->card, 6, "np->pack");
3607 QETH_TXQ_STAT_INC(queue, packing_mode_switch);
3608 queue->do_pack = 1;
3609 }
3610 }
3611}
3612
3613
3614
3615
3616
3617
3618
3619static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
3620{
3621 if (queue->do_pack) {
3622 if (atomic_read(&queue->used_buffers)
3623 <= QETH_LOW_WATERMARK_PACK) {
3624
3625 QETH_CARD_TEXT(queue->card, 6, "pack->np");
3626 QETH_TXQ_STAT_INC(queue, packing_mode_switch);
3627 queue->do_pack = 0;
3628 return qeth_prep_flush_pack_buffer(queue);
3629 }
3630 }
3631 return 0;
3632}
3633
3634static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
3635 int count)
3636{
3637 struct qeth_qdio_out_buffer *buf = queue->bufs[index];
3638 unsigned int qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
3639 struct qeth_card *card = queue->card;
3640 int rc;
3641 int i;
3642
3643 for (i = index; i < index + count; ++i) {
3644 unsigned int bidx = QDIO_BUFNR(i);
3645 struct sk_buff *skb;
3646
3647 buf = queue->bufs[bidx];
3648 buf->buffer->element[buf->next_element_to_fill - 1].eflags |=
3649 SBAL_EFLAGS_LAST_ENTRY;
3650 queue->coalesced_frames += buf->frames;
3651
3652 if (queue->bufstates)
3653 queue->bufstates[bidx].user = buf;
3654
3655 if (IS_IQD(card)) {
3656 skb_queue_walk(&buf->skb_list, skb)
3657 skb_tx_timestamp(skb);
3658 }
3659 }
3660
3661 if (!IS_IQD(card)) {
3662 if (!queue->do_pack) {
3663 if ((atomic_read(&queue->used_buffers) >=
3664 (QETH_HIGH_WATERMARK_PACK -
3665 QETH_WATERMARK_PACK_FUZZ)) &&
3666 !atomic_read(&queue->set_pci_flags_count)) {
3667
3668
3669 atomic_inc(&queue->set_pci_flags_count);
3670 buf->buffer->element[0].sflags |= SBAL_SFLAGS0_PCI_REQ;
3671 }
3672 } else {
3673 if (!atomic_read(&queue->set_pci_flags_count)) {
3674
3675
3676
3677
3678
3679
3680
3681
3682 atomic_inc(&queue->set_pci_flags_count);
3683 buf->buffer->element[0].sflags |= SBAL_SFLAGS0_PCI_REQ;
3684 }
3685 }
3686
3687 if (atomic_read(&queue->set_pci_flags_count))
3688 qdio_flags |= QDIO_FLAG_PCI_OUT;
3689 }
3690
3691 QETH_TXQ_STAT_INC(queue, doorbell);
3692 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
3693 queue->queue_no, index, count);
3694
3695
3696 if (IS_IQD(card)) {
3697 unsigned int frames = READ_ONCE(queue->max_coalesced_frames);
3698 unsigned int usecs = READ_ONCE(queue->coalesce_usecs);
3699
3700 if (frames && queue->coalesced_frames >= frames) {
3701 napi_schedule(&queue->napi);
3702 queue->coalesced_frames = 0;
3703 QETH_TXQ_STAT_INC(queue, coal_frames);
3704 } else if (usecs) {
3705 qeth_tx_arm_timer(queue, usecs);
3706 }
3707 }
3708
3709 if (rc) {
3710
3711 if (rc == -ENOBUFS)
3712 return;
3713 QETH_CARD_TEXT(queue->card, 2, "flushbuf");
3714 QETH_CARD_TEXT_(queue->card, 2, " q%d", queue->queue_no);
3715 QETH_CARD_TEXT_(queue->card, 2, " idx%d", index);
3716 QETH_CARD_TEXT_(queue->card, 2, " c%d", count);
3717 QETH_CARD_TEXT_(queue->card, 2, " err%d", rc);
3718
3719
3720
3721 qeth_schedule_recovery(queue->card);
3722 return;
3723 }
3724}
3725
3726static void qeth_flush_queue(struct qeth_qdio_out_q *queue)
3727{
3728 qeth_flush_buffers(queue, queue->bulk_start, queue->bulk_count);
3729
3730 queue->bulk_start = QDIO_BUFNR(queue->bulk_start + queue->bulk_count);
3731 queue->prev_hdr = NULL;
3732 queue->bulk_count = 0;
3733}
3734
3735static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
3736{
3737
3738
3739
3740
3741 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
3742 !atomic_read(&queue->set_pci_flags_count)) {
3743 unsigned int index, flush_cnt;
3744 bool q_was_packing;
3745
3746 spin_lock(&queue->lock);
3747
3748 index = queue->next_buf_to_fill;
3749 q_was_packing = queue->do_pack;
3750
3751 flush_cnt = qeth_switch_to_nonpacking_if_needed(queue);
3752 if (!flush_cnt && !atomic_read(&queue->set_pci_flags_count))
3753 flush_cnt = qeth_prep_flush_pack_buffer(queue);
3754
3755 if (flush_cnt) {
3756 qeth_flush_buffers(queue, index, flush_cnt);
3757 if (q_was_packing)
3758 QETH_TXQ_STAT_ADD(queue, bufs_pack, flush_cnt);
3759 }
3760
3761 spin_unlock(&queue->lock);
3762 }
3763}
3764
3765static void qeth_qdio_poll(struct ccw_device *cdev, unsigned long card_ptr)
3766{
3767 struct qeth_card *card = (struct qeth_card *)card_ptr;
3768
3769 napi_schedule_irqoff(&card->napi);
3770}
3771
3772int qeth_configure_cq(struct qeth_card *card, enum qeth_cq cq)
3773{
3774 int rc;
3775
3776 if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
3777 rc = -1;
3778 goto out;
3779 } else {
3780 if (card->options.cq == cq) {
3781 rc = 0;
3782 goto out;
3783 }
3784
3785 qeth_free_qdio_queues(card);
3786 card->options.cq = cq;
3787 rc = 0;
3788 }
3789out:
3790 return rc;
3791
3792}
3793EXPORT_SYMBOL_GPL(qeth_configure_cq);
3794
3795static void qeth_qdio_cq_handler(struct qeth_card *card, unsigned int qdio_err,
3796 unsigned int queue, int first_element,
3797 int count)
3798{
3799 struct qeth_qdio_q *cq = card->qdio.c_q;
3800 int i;
3801 int rc;
3802
3803 QETH_CARD_TEXT_(card, 5, "qcqhe%d", first_element);
3804 QETH_CARD_TEXT_(card, 5, "qcqhc%d", count);
3805 QETH_CARD_TEXT_(card, 5, "qcqherr%d", qdio_err);
3806
3807 if (qdio_err) {
3808 netif_tx_stop_all_queues(card->dev);
3809 qeth_schedule_recovery(card);
3810 return;
3811 }
3812
3813 for (i = first_element; i < first_element + count; ++i) {
3814 struct qdio_buffer *buffer = cq->qdio_bufs[QDIO_BUFNR(i)];
3815 int e = 0;
3816
3817 while ((e < QDIO_MAX_ELEMENTS_PER_BUFFER) &&
3818 buffer->element[e].addr) {
3819 unsigned long phys_aob_addr = buffer->element[e].addr;
3820
3821 qeth_qdio_handle_aob(card, phys_aob_addr);
3822 ++e;
3823 }
3824 qeth_scrub_qdio_buffer(buffer, QDIO_MAX_ELEMENTS_PER_BUFFER);
3825 }
3826 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, queue,
3827 card->qdio.c_q->next_buf_to_init,
3828 count);
3829 if (rc) {
3830 dev_warn(&card->gdev->dev,
3831 "QDIO reported an error, rc=%i\n", rc);
3832 QETH_CARD_TEXT(card, 2, "qcqherr");
3833 }
3834
3835 cq->next_buf_to_init = QDIO_BUFNR(cq->next_buf_to_init + count);
3836}
3837
3838static void qeth_qdio_input_handler(struct ccw_device *ccwdev,
3839 unsigned int qdio_err, int queue,
3840 int first_elem, int count,
3841 unsigned long card_ptr)
3842{
3843 struct qeth_card *card = (struct qeth_card *)card_ptr;
3844
3845 QETH_CARD_TEXT_(card, 2, "qihq%d", queue);
3846 QETH_CARD_TEXT_(card, 2, "qiec%d", qdio_err);
3847
3848 if (qdio_err)
3849 qeth_schedule_recovery(card);
3850}
3851
3852static void qeth_qdio_output_handler(struct ccw_device *ccwdev,
3853 unsigned int qdio_error, int __queue,
3854 int first_element, int count,
3855 unsigned long card_ptr)
3856{
3857 struct qeth_card *card = (struct qeth_card *) card_ptr;
3858 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3859 struct net_device *dev = card->dev;
3860 struct netdev_queue *txq;
3861 int i;
3862
3863 QETH_CARD_TEXT(card, 6, "qdouhdl");
3864 if (qdio_error & QDIO_ERROR_FATAL) {
3865 QETH_CARD_TEXT(card, 2, "achkcond");
3866 netif_tx_stop_all_queues(dev);
3867 qeth_schedule_recovery(card);
3868 return;
3869 }
3870
3871 for (i = first_element; i < (first_element + count); ++i) {
3872 struct qeth_qdio_out_buffer *buf = queue->bufs[QDIO_BUFNR(i)];
3873
3874 qeth_handle_send_error(card, buf, qdio_error);
3875 qeth_clear_output_buffer(queue, buf, qdio_error, 0);
3876 }
3877
3878 atomic_sub(count, &queue->used_buffers);
3879 qeth_check_outbound_queue(queue);
3880
3881 txq = netdev_get_tx_queue(dev, __queue);
3882
3883
3884
3885
3886 if (netif_tx_queue_stopped(txq) && !qeth_out_queue_is_full(queue))
3887 netif_tx_wake_queue(txq);
3888}
3889
3890
3891
3892
3893int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb)
3894{
3895 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
3896 u8 tos;
3897
3898 switch (card->qdio.do_prio_queueing) {
3899 case QETH_PRIO_Q_ING_TOS:
3900 case QETH_PRIO_Q_ING_PREC:
3901 switch (qeth_get_ip_version(skb)) {
3902 case 4:
3903 tos = ipv4_get_dsfield(ip_hdr(skb));
3904 break;
3905 case 6:
3906 tos = ipv6_get_dsfield(ipv6_hdr(skb));
3907 break;
3908 default:
3909 return card->qdio.default_out_queue;
3910 }
3911 if (card->qdio.do_prio_queueing == QETH_PRIO_Q_ING_PREC)
3912 return ~tos >> 6 & 3;
3913 if (tos & IPTOS_MINCOST)
3914 return 3;
3915 if (tos & IPTOS_RELIABILITY)
3916 return 2;
3917 if (tos & IPTOS_THROUGHPUT)
3918 return 1;
3919 if (tos & IPTOS_LOWDELAY)
3920 return 0;
3921 break;
3922 case QETH_PRIO_Q_ING_SKB:
3923 if (skb->priority > 5)
3924 return 0;
3925 return ~skb->priority >> 1 & 3;
3926 case QETH_PRIO_Q_ING_VLAN:
3927 if (veth->h_vlan_proto == htons(ETH_P_8021Q))
3928 return ~ntohs(veth->h_vlan_TCI) >>
3929 (VLAN_PRIO_SHIFT + 1) & 3;
3930 break;
3931 case QETH_PRIO_Q_ING_FIXED:
3932 return card->qdio.default_out_queue;
3933 default:
3934 break;
3935 }
3936 return card->qdio.default_out_queue;
3937}
3938EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
3939
3940
3941
3942
3943
3944
3945
3946
3947static int qeth_get_elements_for_frags(struct sk_buff *skb)
3948{
3949 int cnt, elements = 0;
3950
3951 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
3952 skb_frag_t *frag = &skb_shinfo(skb)->frags[cnt];
3953
3954 elements += qeth_get_elements_for_range(
3955 (addr_t)skb_frag_address(frag),
3956 (addr_t)skb_frag_address(frag) + skb_frag_size(frag));
3957 }
3958 return elements;
3959}
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970unsigned int qeth_count_elements(struct sk_buff *skb, unsigned int data_offset)
3971{
3972 unsigned int elements = qeth_get_elements_for_frags(skb);
3973 addr_t end = (addr_t)skb->data + skb_headlen(skb);
3974 addr_t start = (addr_t)skb->data + data_offset;
3975
3976 if (start != end)
3977 elements += qeth_get_elements_for_range(start, end);
3978 return elements;
3979}
3980EXPORT_SYMBOL_GPL(qeth_count_elements);
3981
3982#define QETH_HDR_CACHE_OBJ_SIZE (sizeof(struct qeth_hdr_tso) + \
3983 MAX_TCP_HEADER)
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000static int qeth_add_hw_header(struct qeth_qdio_out_q *queue,
4001 struct sk_buff *skb, struct qeth_hdr **hdr,
4002 unsigned int hdr_len, unsigned int proto_len,
4003 unsigned int *elements)
4004{
4005 gfp_t gfp = GFP_ATOMIC | (skb_pfmemalloc(skb) ? __GFP_MEMALLOC : 0);
4006 const unsigned int contiguous = proto_len ? proto_len : 1;
4007 const unsigned int max_elements = queue->max_elements;
4008 unsigned int __elements;
4009 addr_t start, end;
4010 bool push_ok;
4011 int rc;
4012
4013check_layout:
4014 start = (addr_t)skb->data - hdr_len;
4015 end = (addr_t)skb->data;
4016
4017 if (qeth_get_elements_for_range(start, end + contiguous) == 1) {
4018
4019 push_ok = true;
4020
4021 if (skb_is_gso(skb))
4022 __elements = 1 + qeth_count_elements(skb, proto_len);
4023 else
4024 __elements = qeth_count_elements(skb, 0);
4025 } else if (!proto_len && PAGE_ALIGNED(skb->data)) {
4026
4027 push_ok = true;
4028 __elements = 1 + qeth_count_elements(skb, 0);
4029 } else {
4030
4031 push_ok = false;
4032 __elements = 1 + qeth_count_elements(skb, proto_len);
4033 }
4034
4035
4036 if (__elements > max_elements) {
4037 if (!skb_is_nonlinear(skb)) {
4038
4039 QETH_DBF_MESSAGE(2, "Dropped an oversized skb (Max Elements=%u / Actual=%u / Length=%u).\n",
4040 max_elements, __elements, skb->len);
4041 return -E2BIG;
4042 }
4043
4044 rc = skb_linearize(skb);
4045 if (rc) {
4046 QETH_TXQ_STAT_INC(queue, skbs_linearized_fail);
4047 return rc;
4048 }
4049
4050 QETH_TXQ_STAT_INC(queue, skbs_linearized);
4051
4052 goto check_layout;
4053 }
4054
4055 *elements = __elements;
4056
4057 if (push_ok) {
4058 *hdr = skb_push(skb, hdr_len);
4059 return hdr_len;
4060 }
4061
4062
4063 if (hdr_len + proto_len > QETH_HDR_CACHE_OBJ_SIZE)
4064 return -E2BIG;
4065 *hdr = kmem_cache_alloc(qeth_core_header_cache, gfp);
4066 if (!*hdr)
4067 return -ENOMEM;
4068
4069 skb_copy_from_linear_data(skb, ((char *)*hdr) + hdr_len, proto_len);
4070 return 0;
4071}
4072
4073static bool qeth_iqd_may_bulk(struct qeth_qdio_out_q *queue,
4074 struct sk_buff *curr_skb,
4075 struct qeth_hdr *curr_hdr)
4076{
4077 struct qeth_qdio_out_buffer *buffer = queue->bufs[queue->bulk_start];
4078 struct qeth_hdr *prev_hdr = queue->prev_hdr;
4079
4080 if (!prev_hdr)
4081 return true;
4082
4083
4084 if (curr_hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2) {
4085 struct sk_buff *prev_skb = skb_peek(&buffer->skb_list);
4086
4087 return ether_addr_equal(eth_hdr(prev_skb)->h_dest,
4088 eth_hdr(curr_skb)->h_dest) &&
4089 qeth_l2_same_vlan(&prev_hdr->hdr.l2, &curr_hdr->hdr.l2);
4090 }
4091
4092 return qeth_l3_same_next_hop(&prev_hdr->hdr.l3, &curr_hdr->hdr.l3) &&
4093 qeth_l3_iqd_same_vlan(&prev_hdr->hdr.l3, &curr_hdr->hdr.l3);
4094}
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105static unsigned int qeth_fill_buffer(struct qeth_qdio_out_buffer *buf,
4106 struct sk_buff *skb, struct qeth_hdr *hdr,
4107 unsigned int offset, unsigned int hd_len)
4108{
4109 struct qdio_buffer *buffer = buf->buffer;
4110 int element = buf->next_element_to_fill;
4111 int length = skb_headlen(skb) - offset;
4112 char *data = skb->data + offset;
4113 unsigned int elem_length, cnt;
4114 bool is_first_elem = true;
4115
4116 __skb_queue_tail(&buf->skb_list, skb);
4117
4118
4119 if (hd_len) {
4120 is_first_elem = false;
4121
4122 buffer->element[element].addr = virt_to_phys(hdr);
4123 buffer->element[element].length = hd_len;
4124 buffer->element[element].eflags = SBAL_EFLAGS_FIRST_FRAG;
4125
4126
4127 if ((void *)hdr != skb->data)
4128 buf->is_header[element] = 1;
4129
4130 else if (length > 0 && !PAGE_ALIGNED(data) &&
4131 (data == (char *)hdr + hd_len))
4132 buffer->element[element].eflags |=
4133 SBAL_EFLAGS_CONTIGUOUS;
4134
4135 element++;
4136 }
4137
4138
4139 while (length > 0) {
4140 elem_length = min_t(unsigned int, length,
4141 PAGE_SIZE - offset_in_page(data));
4142
4143 buffer->element[element].addr = virt_to_phys(data);
4144 buffer->element[element].length = elem_length;
4145 length -= elem_length;
4146 if (is_first_elem) {
4147 is_first_elem = false;
4148 if (length || skb_is_nonlinear(skb))
4149
4150 buffer->element[element].eflags =
4151 SBAL_EFLAGS_FIRST_FRAG;
4152 else
4153 buffer->element[element].eflags = 0;
4154 } else {
4155 buffer->element[element].eflags =
4156 SBAL_EFLAGS_MIDDLE_FRAG;
4157 }
4158
4159 data += elem_length;
4160 element++;
4161 }
4162
4163
4164 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
4165 skb_frag_t *frag = &skb_shinfo(skb)->frags[cnt];
4166
4167 data = skb_frag_address(frag);
4168 length = skb_frag_size(frag);
4169 while (length > 0) {
4170 elem_length = min_t(unsigned int, length,
4171 PAGE_SIZE - offset_in_page(data));
4172
4173 buffer->element[element].addr = virt_to_phys(data);
4174 buffer->element[element].length = elem_length;
4175 buffer->element[element].eflags =
4176 SBAL_EFLAGS_MIDDLE_FRAG;
4177
4178 length -= elem_length;
4179 data += elem_length;
4180 element++;
4181 }
4182 }
4183
4184 if (buffer->element[element - 1].eflags)
4185 buffer->element[element - 1].eflags = SBAL_EFLAGS_LAST_FRAG;
4186 buf->next_element_to_fill = element;
4187 return element;
4188}
4189
4190static int __qeth_xmit(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4191 struct sk_buff *skb, unsigned int elements,
4192 struct qeth_hdr *hdr, unsigned int offset,
4193 unsigned int hd_len)
4194{
4195 unsigned int bytes = qdisc_pkt_len(skb);
4196 struct qeth_qdio_out_buffer *buffer;
4197 unsigned int next_element;
4198 struct netdev_queue *txq;
4199 bool stopped = false;
4200 bool flush;
4201
4202 buffer = queue->bufs[QDIO_BUFNR(queue->bulk_start + queue->bulk_count)];
4203 txq = netdev_get_tx_queue(card->dev, skb_get_queue_mapping(skb));
4204
4205
4206
4207
4208 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4209 return -EBUSY;
4210
4211 flush = !qeth_iqd_may_bulk(queue, skb, hdr);
4212
4213 if (flush ||
4214 (buffer->next_element_to_fill + elements > queue->max_elements)) {
4215 if (buffer->next_element_to_fill > 0) {
4216 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4217 queue->bulk_count++;
4218 }
4219
4220 if (queue->bulk_count >= queue->bulk_max)
4221 flush = true;
4222
4223 if (flush)
4224 qeth_flush_queue(queue);
4225
4226 buffer = queue->bufs[QDIO_BUFNR(queue->bulk_start +
4227 queue->bulk_count)];
4228
4229
4230 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4231 return -EBUSY;
4232 }
4233
4234 if (buffer->next_element_to_fill == 0 &&
4235 atomic_inc_return(&queue->used_buffers) >= QDIO_MAX_BUFFERS_PER_Q) {
4236
4237
4238
4239 QETH_TXQ_STAT_INC(queue, stopped);
4240 netif_tx_stop_queue(txq);
4241 stopped = true;
4242 }
4243
4244 next_element = qeth_fill_buffer(buffer, skb, hdr, offset, hd_len);
4245 buffer->bytes += bytes;
4246 buffer->frames += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1;
4247 queue->prev_hdr = hdr;
4248
4249 flush = __netdev_tx_sent_queue(txq, bytes,
4250 !stopped && netdev_xmit_more());
4251
4252 if (flush || next_element >= queue->max_elements) {
4253 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4254 queue->bulk_count++;
4255
4256 if (queue->bulk_count >= queue->bulk_max)
4257 flush = true;
4258
4259 if (flush)
4260 qeth_flush_queue(queue);
4261 }
4262
4263 if (stopped && !qeth_out_queue_is_full(queue))
4264 netif_tx_start_queue(txq);
4265 return 0;
4266}
4267
4268int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4269 struct sk_buff *skb, struct qeth_hdr *hdr,
4270 unsigned int offset, unsigned int hd_len,
4271 int elements_needed)
4272{
4273 unsigned int start_index = queue->next_buf_to_fill;
4274 struct qeth_qdio_out_buffer *buffer;
4275 unsigned int next_element;
4276 struct netdev_queue *txq;
4277 bool stopped = false;
4278 int flush_count = 0;
4279 int do_pack = 0;
4280 int rc = 0;
4281
4282 buffer = queue->bufs[queue->next_buf_to_fill];
4283
4284
4285
4286
4287 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4288 return -EBUSY;
4289
4290 txq = netdev_get_tx_queue(card->dev, skb_get_queue_mapping(skb));
4291
4292
4293 qeth_switch_to_packing_if_needed(queue);
4294 if (queue->do_pack) {
4295 do_pack = 1;
4296
4297 if (buffer->next_element_to_fill + elements_needed >
4298 queue->max_elements) {
4299
4300 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4301 flush_count++;
4302 queue->next_buf_to_fill =
4303 QDIO_BUFNR(queue->next_buf_to_fill + 1);
4304 buffer = queue->bufs[queue->next_buf_to_fill];
4305
4306
4307 if (atomic_read(&buffer->state) !=
4308 QETH_QDIO_BUF_EMPTY) {
4309 qeth_flush_buffers(queue, start_index,
4310 flush_count);
4311 rc = -EBUSY;
4312 goto out;
4313 }
4314 }
4315 }
4316
4317 if (buffer->next_element_to_fill == 0 &&
4318 atomic_inc_return(&queue->used_buffers) >= QDIO_MAX_BUFFERS_PER_Q) {
4319
4320
4321
4322 QETH_TXQ_STAT_INC(queue, stopped);
4323 netif_tx_stop_queue(txq);
4324 stopped = true;
4325 }
4326
4327 next_element = qeth_fill_buffer(buffer, skb, hdr, offset, hd_len);
4328 buffer->bytes += qdisc_pkt_len(skb);
4329 buffer->frames += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1;
4330
4331 if (queue->do_pack)
4332 QETH_TXQ_STAT_INC(queue, skbs_pack);
4333 if (!queue->do_pack || stopped || next_element >= queue->max_elements) {
4334 flush_count++;
4335 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4336 queue->next_buf_to_fill =
4337 QDIO_BUFNR(queue->next_buf_to_fill + 1);
4338 }
4339
4340 if (flush_count)
4341 qeth_flush_buffers(queue, start_index, flush_count);
4342
4343out:
4344 if (do_pack)
4345 QETH_TXQ_STAT_ADD(queue, bufs_pack, flush_count);
4346
4347 if (stopped && !qeth_out_queue_is_full(queue))
4348 netif_tx_start_queue(txq);
4349 return rc;
4350}
4351EXPORT_SYMBOL_GPL(qeth_do_send_packet);
4352
4353static void qeth_fill_tso_ext(struct qeth_hdr_tso *hdr,
4354 unsigned int payload_len, struct sk_buff *skb,
4355 unsigned int proto_len)
4356{
4357 struct qeth_hdr_ext_tso *ext = &hdr->ext;
4358
4359 ext->hdr_tot_len = sizeof(*ext);
4360 ext->imb_hdr_no = 1;
4361 ext->hdr_type = 1;
4362 ext->hdr_version = 1;
4363 ext->hdr_len = 28;
4364 ext->payload_len = payload_len;
4365 ext->mss = skb_shinfo(skb)->gso_size;
4366 ext->dg_hdr_len = proto_len;
4367}
4368
4369int qeth_xmit(struct qeth_card *card, struct sk_buff *skb,
4370 struct qeth_qdio_out_q *queue, int ipv,
4371 void (*fill_header)(struct qeth_qdio_out_q *queue,
4372 struct qeth_hdr *hdr, struct sk_buff *skb,
4373 int ipv, unsigned int data_len))
4374{
4375 unsigned int proto_len, hw_hdr_len;
4376 unsigned int frame_len = skb->len;
4377 bool is_tso = skb_is_gso(skb);
4378 unsigned int data_offset = 0;
4379 struct qeth_hdr *hdr = NULL;
4380 unsigned int hd_len = 0;
4381 unsigned int elements;
4382 int push_len, rc;
4383
4384 if (is_tso) {
4385 hw_hdr_len = sizeof(struct qeth_hdr_tso);
4386 proto_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4387 } else {
4388 hw_hdr_len = sizeof(struct qeth_hdr);
4389 proto_len = (IS_IQD(card) && IS_LAYER2(card)) ? ETH_HLEN : 0;
4390 }
4391
4392 rc = skb_cow_head(skb, hw_hdr_len);
4393 if (rc)
4394 return rc;
4395
4396 push_len = qeth_add_hw_header(queue, skb, &hdr, hw_hdr_len, proto_len,
4397 &elements);
4398 if (push_len < 0)
4399 return push_len;
4400 if (is_tso || !push_len) {
4401
4402 hd_len = hw_hdr_len + proto_len;
4403 data_offset = push_len + proto_len;
4404 }
4405 memset(hdr, 0, hw_hdr_len);
4406 fill_header(queue, hdr, skb, ipv, frame_len);
4407 if (is_tso)
4408 qeth_fill_tso_ext((struct qeth_hdr_tso *) hdr,
4409 frame_len - proto_len, skb, proto_len);
4410
4411 if (IS_IQD(card)) {
4412 rc = __qeth_xmit(card, queue, skb, elements, hdr, data_offset,
4413 hd_len);
4414 } else {
4415
4416 skb_orphan(skb);
4417 spin_lock(&queue->lock);
4418 rc = qeth_do_send_packet(card, queue, skb, hdr, data_offset,
4419 hd_len, elements);
4420 spin_unlock(&queue->lock);
4421 }
4422
4423 if (rc && !push_len)
4424 kmem_cache_free(qeth_core_header_cache, hdr);
4425
4426 return rc;
4427}
4428EXPORT_SYMBOL_GPL(qeth_xmit);
4429
4430static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
4431 struct qeth_reply *reply, unsigned long data)
4432{
4433 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4434 struct qeth_ipacmd_setadpparms *setparms;
4435
4436 QETH_CARD_TEXT(card, 4, "prmadpcb");
4437
4438 setparms = &(cmd->data.setadapterparms);
4439 if (qeth_setadpparms_inspect_rc(cmd)) {
4440 QETH_CARD_TEXT_(card, 4, "prmrc%x", cmd->hdr.return_code);
4441 setparms->data.mode = SET_PROMISC_MODE_OFF;
4442 }
4443 card->info.promisc_mode = setparms->data.mode;
4444 return (cmd->hdr.return_code) ? -EIO : 0;
4445}
4446
4447void qeth_setadp_promisc_mode(struct qeth_card *card, bool enable)
4448{
4449 enum qeth_ipa_promisc_modes mode = enable ? SET_PROMISC_MODE_ON :
4450 SET_PROMISC_MODE_OFF;
4451 struct qeth_cmd_buffer *iob;
4452 struct qeth_ipa_cmd *cmd;
4453
4454 QETH_CARD_TEXT(card, 4, "setprom");
4455 QETH_CARD_TEXT_(card, 4, "mode:%x", mode);
4456
4457 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
4458 SETADP_DATA_SIZEOF(mode));
4459 if (!iob)
4460 return;
4461 cmd = __ipa_cmd(iob);
4462 cmd->data.setadapterparms.data.mode = mode;
4463 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
4464}
4465EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode);
4466
4467static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
4468 struct qeth_reply *reply, unsigned long data)
4469{
4470 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4471 struct qeth_ipacmd_setadpparms *adp_cmd;
4472
4473 QETH_CARD_TEXT(card, 4, "chgmaccb");
4474 if (qeth_setadpparms_inspect_rc(cmd))
4475 return -EIO;
4476
4477 adp_cmd = &cmd->data.setadapterparms;
4478 if (!is_valid_ether_addr(adp_cmd->data.change_addr.addr))
4479 return -EADDRNOTAVAIL;
4480
4481 if (IS_LAYER2(card) && IS_OSD(card) && !IS_VM_NIC(card) &&
4482 !(adp_cmd->hdr.flags & QETH_SETADP_FLAGS_VIRTUAL_MAC))
4483 return -EADDRNOTAVAIL;
4484
4485 ether_addr_copy(card->dev->dev_addr, adp_cmd->data.change_addr.addr);
4486 return 0;
4487}
4488
4489int qeth_setadpparms_change_macaddr(struct qeth_card *card)
4490{
4491 int rc;
4492 struct qeth_cmd_buffer *iob;
4493 struct qeth_ipa_cmd *cmd;
4494
4495 QETH_CARD_TEXT(card, 4, "chgmac");
4496
4497 iob = qeth_get_adapter_cmd(card, IPA_SETADP_ALTER_MAC_ADDRESS,
4498 SETADP_DATA_SIZEOF(change_addr));
4499 if (!iob)
4500 return -ENOMEM;
4501 cmd = __ipa_cmd(iob);
4502 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
4503 cmd->data.setadapterparms.data.change_addr.addr_size = ETH_ALEN;
4504 ether_addr_copy(cmd->data.setadapterparms.data.change_addr.addr,
4505 card->dev->dev_addr);
4506 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
4507 NULL);
4508 return rc;
4509}
4510EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
4511
4512static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card *card,
4513 struct qeth_reply *reply, unsigned long data)
4514{
4515 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4516 struct qeth_set_access_ctrl *access_ctrl_req;
4517
4518 QETH_CARD_TEXT(card, 4, "setaccb");
4519
4520 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4521 QETH_CARD_TEXT_(card, 2, "rc=%d",
4522 cmd->data.setadapterparms.hdr.return_code);
4523 if (cmd->data.setadapterparms.hdr.return_code !=
4524 SET_ACCESS_CTRL_RC_SUCCESS)
4525 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%#x) on device %x: %#x\n",
4526 access_ctrl_req->subcmd_code, CARD_DEVID(card),
4527 cmd->data.setadapterparms.hdr.return_code);
4528 switch (qeth_setadpparms_inspect_rc(cmd)) {
4529 case SET_ACCESS_CTRL_RC_SUCCESS:
4530 if (access_ctrl_req->subcmd_code == ISOLATION_MODE_NONE)
4531 dev_info(&card->gdev->dev,
4532 "QDIO data connection isolation is deactivated\n");
4533 else
4534 dev_info(&card->gdev->dev,
4535 "QDIO data connection isolation is activated\n");
4536 return 0;
4537 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED:
4538 QETH_DBF_MESSAGE(2, "QDIO data connection isolation on device %x already deactivated\n",
4539 CARD_DEVID(card));
4540 return 0;
4541 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED:
4542 QETH_DBF_MESSAGE(2, "QDIO data connection isolation on device %x already activated\n",
4543 CARD_DEVID(card));
4544 return 0;
4545 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED:
4546 dev_err(&card->gdev->dev, "Adapter does not "
4547 "support QDIO data connection isolation\n");
4548 return -EOPNOTSUPP;
4549 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER:
4550 dev_err(&card->gdev->dev,
4551 "Adapter is dedicated. "
4552 "QDIO data connection isolation not supported\n");
4553 return -EOPNOTSUPP;
4554 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF:
4555 dev_err(&card->gdev->dev,
4556 "TSO does not permit QDIO data connection isolation\n");
4557 return -EPERM;
4558 case SET_ACCESS_CTRL_RC_REFLREL_UNSUPPORTED:
4559 dev_err(&card->gdev->dev, "The adjacent switch port does not "
4560 "support reflective relay mode\n");
4561 return -EOPNOTSUPP;
4562 case SET_ACCESS_CTRL_RC_REFLREL_FAILED:
4563 dev_err(&card->gdev->dev, "The reflective relay mode cannot be "
4564 "enabled at the adjacent switch port");
4565 return -EREMOTEIO;
4566 case SET_ACCESS_CTRL_RC_REFLREL_DEACT_FAILED:
4567 dev_warn(&card->gdev->dev, "Turning off reflective relay mode "
4568 "at the adjacent switch failed\n");
4569
4570 return 0;
4571 default:
4572 return -EIO;
4573 }
4574}
4575
4576int qeth_setadpparms_set_access_ctrl(struct qeth_card *card,
4577 enum qeth_ipa_isolation_modes mode)
4578{
4579 int rc;
4580 struct qeth_cmd_buffer *iob;
4581 struct qeth_ipa_cmd *cmd;
4582 struct qeth_set_access_ctrl *access_ctrl_req;
4583
4584 QETH_CARD_TEXT(card, 4, "setacctl");
4585
4586 if (!qeth_adp_supported(card, IPA_SETADP_SET_ACCESS_CONTROL)) {
4587 dev_err(&card->gdev->dev,
4588 "Adapter does not support QDIO data connection isolation\n");
4589 return -EOPNOTSUPP;
4590 }
4591
4592 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_ACCESS_CONTROL,
4593 SETADP_DATA_SIZEOF(set_access_ctrl));
4594 if (!iob)
4595 return -ENOMEM;
4596 cmd = __ipa_cmd(iob);
4597 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4598 access_ctrl_req->subcmd_code = mode;
4599
4600 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_set_access_ctrl_cb,
4601 NULL);
4602 if (rc) {
4603 QETH_CARD_TEXT_(card, 2, "rc=%d", rc);
4604 QETH_DBF_MESSAGE(3, "IPA(SET_ACCESS_CTRL(%d) on device %x: sent failed\n",
4605 rc, CARD_DEVID(card));
4606 }
4607
4608 return rc;
4609}
4610
4611void qeth_tx_timeout(struct net_device *dev, unsigned int txqueue)
4612{
4613 struct qeth_card *card;
4614
4615 card = dev->ml_priv;
4616 QETH_CARD_TEXT(card, 4, "txtimeo");
4617 qeth_schedule_recovery(card);
4618}
4619EXPORT_SYMBOL_GPL(qeth_tx_timeout);
4620
4621static int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4622{
4623 struct qeth_card *card = dev->ml_priv;
4624 int rc = 0;
4625
4626 switch (regnum) {
4627 case MII_BMCR:
4628 rc = BMCR_FULLDPLX;
4629 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH) &&
4630 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4631 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH) &&
4632 (card->info.link_type != QETH_LINK_TYPE_25GBIT_ETH))
4633 rc |= BMCR_SPEED100;
4634 break;
4635 case MII_BMSR:
4636 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4637 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4638 BMSR_100BASE4;
4639 break;
4640 case MII_PHYSID1:
4641 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4642 dev->dev_addr[2];
4643 rc = (rc >> 5) & 0xFFFF;
4644 break;
4645 case MII_PHYSID2:
4646 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4647 break;
4648 case MII_ADVERTISE:
4649 rc = ADVERTISE_ALL;
4650 break;
4651 case MII_LPA:
4652 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4653 LPA_100BASE4 | LPA_LPACK;
4654 break;
4655 case MII_EXPANSION:
4656 break;
4657 case MII_DCOUNTER:
4658 break;
4659 case MII_FCSCOUNTER:
4660 break;
4661 case MII_NWAYTEST:
4662 break;
4663 case MII_RERRCOUNTER:
4664 rc = card->stats.rx_length_errors +
4665 card->stats.rx_frame_errors +
4666 card->stats.rx_fifo_errors;
4667 break;
4668 case MII_SREVISION:
4669 break;
4670 case MII_RESV1:
4671 break;
4672 case MII_LBRERROR:
4673 break;
4674 case MII_PHYADDR:
4675 break;
4676 case MII_RESV2:
4677 break;
4678 case MII_TPISTATUS:
4679 break;
4680 case MII_NCONFIG:
4681 break;
4682 default:
4683 break;
4684 }
4685 return rc;
4686}
4687
4688static int qeth_snmp_command_cb(struct qeth_card *card,
4689 struct qeth_reply *reply, unsigned long data)
4690{
4691 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4692 struct qeth_arp_query_info *qinfo = reply->param;
4693 struct qeth_ipacmd_setadpparms *adp_cmd;
4694 unsigned int data_len;
4695 void *snmp_data;
4696
4697 QETH_CARD_TEXT(card, 3, "snpcmdcb");
4698
4699 if (cmd->hdr.return_code) {
4700 QETH_CARD_TEXT_(card, 4, "scer1%x", cmd->hdr.return_code);
4701 return -EIO;
4702 }
4703 if (cmd->data.setadapterparms.hdr.return_code) {
4704 cmd->hdr.return_code =
4705 cmd->data.setadapterparms.hdr.return_code;
4706 QETH_CARD_TEXT_(card, 4, "scer2%x", cmd->hdr.return_code);
4707 return -EIO;
4708 }
4709
4710 adp_cmd = &cmd->data.setadapterparms;
4711 data_len = adp_cmd->hdr.cmdlength - sizeof(adp_cmd->hdr);
4712 if (adp_cmd->hdr.seq_no == 1) {
4713 snmp_data = &adp_cmd->data.snmp;
4714 } else {
4715 snmp_data = &adp_cmd->data.snmp.request;
4716 data_len -= offsetof(struct qeth_snmp_cmd, request);
4717 }
4718
4719
4720 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4721 QETH_CARD_TEXT_(card, 4, "scer3%i", -ENOSPC);
4722 return -ENOSPC;
4723 }
4724 QETH_CARD_TEXT_(card, 4, "snore%i",
4725 cmd->data.setadapterparms.hdr.used_total);
4726 QETH_CARD_TEXT_(card, 4, "sseqn%i",
4727 cmd->data.setadapterparms.hdr.seq_no);
4728
4729 memcpy(qinfo->udata + qinfo->udata_offset, snmp_data, data_len);
4730 qinfo->udata_offset += data_len;
4731
4732 if (cmd->data.setadapterparms.hdr.seq_no <
4733 cmd->data.setadapterparms.hdr.used_total)
4734 return 1;
4735 return 0;
4736}
4737
4738static int qeth_snmp_command(struct qeth_card *card, char __user *udata)
4739{
4740 struct qeth_snmp_ureq __user *ureq;
4741 struct qeth_cmd_buffer *iob;
4742 unsigned int req_len;
4743 struct qeth_arp_query_info qinfo = {0, };
4744 int rc = 0;
4745
4746 QETH_CARD_TEXT(card, 3, "snmpcmd");
4747
4748 if (IS_VM_NIC(card))
4749 return -EOPNOTSUPP;
4750
4751 if ((!qeth_adp_supported(card, IPA_SETADP_SET_SNMP_CONTROL)) &&
4752 IS_LAYER3(card))
4753 return -EOPNOTSUPP;
4754
4755 ureq = (struct qeth_snmp_ureq __user *) udata;
4756 if (get_user(qinfo.udata_len, &ureq->hdr.data_len) ||
4757 get_user(req_len, &ureq->hdr.req_len))
4758 return -EFAULT;
4759
4760
4761 if (req_len > QETH_BUFSIZE)
4762 return -EINVAL;
4763
4764 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL, req_len);
4765 if (!iob)
4766 return -ENOMEM;
4767
4768 if (copy_from_user(&__ipa_cmd(iob)->data.setadapterparms.data.snmp,
4769 &ureq->cmd, req_len)) {
4770 qeth_put_cmd(iob);
4771 return -EFAULT;
4772 }
4773
4774 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
4775 if (!qinfo.udata) {
4776 qeth_put_cmd(iob);
4777 return -ENOMEM;
4778 }
4779 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4780
4781 rc = qeth_send_ipa_cmd(card, iob, qeth_snmp_command_cb, &qinfo);
4782 if (rc)
4783 QETH_DBF_MESSAGE(2, "SNMP command failed on device %x: (%#x)\n",
4784 CARD_DEVID(card), rc);
4785 else {
4786 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4787 rc = -EFAULT;
4788 }
4789
4790 kfree(qinfo.udata);
4791 return rc;
4792}
4793
4794static int qeth_setadpparms_query_oat_cb(struct qeth_card *card,
4795 struct qeth_reply *reply,
4796 unsigned long data)
4797{
4798 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
4799 struct qeth_qoat_priv *priv = reply->param;
4800 int resdatalen;
4801
4802 QETH_CARD_TEXT(card, 3, "qoatcb");
4803 if (qeth_setadpparms_inspect_rc(cmd))
4804 return -EIO;
4805
4806 resdatalen = cmd->data.setadapterparms.hdr.cmdlength;
4807
4808 if (resdatalen > (priv->buffer_len - priv->response_len))
4809 return -ENOSPC;
4810
4811 memcpy(priv->buffer + priv->response_len,
4812 &cmd->data.setadapterparms.hdr, resdatalen);
4813 priv->response_len += resdatalen;
4814
4815 if (cmd->data.setadapterparms.hdr.seq_no <
4816 cmd->data.setadapterparms.hdr.used_total)
4817 return 1;
4818 return 0;
4819}
4820
4821static int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
4822{
4823 int rc = 0;
4824 struct qeth_cmd_buffer *iob;
4825 struct qeth_ipa_cmd *cmd;
4826 struct qeth_query_oat *oat_req;
4827 struct qeth_query_oat_data oat_data;
4828 struct qeth_qoat_priv priv;
4829 void __user *tmp;
4830
4831 QETH_CARD_TEXT(card, 3, "qoatcmd");
4832
4833 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_OAT))
4834 return -EOPNOTSUPP;
4835
4836 if (copy_from_user(&oat_data, udata, sizeof(oat_data)))
4837 return -EFAULT;
4838
4839 priv.buffer_len = oat_data.buffer_len;
4840 priv.response_len = 0;
4841 priv.buffer = vzalloc(oat_data.buffer_len);
4842 if (!priv.buffer)
4843 return -ENOMEM;
4844
4845 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_OAT,
4846 SETADP_DATA_SIZEOF(query_oat));
4847 if (!iob) {
4848 rc = -ENOMEM;
4849 goto out_free;
4850 }
4851 cmd = __ipa_cmd(iob);
4852 oat_req = &cmd->data.setadapterparms.data.query_oat;
4853 oat_req->subcmd_code = oat_data.command;
4854
4855 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_query_oat_cb, &priv);
4856 if (!rc) {
4857 tmp = is_compat_task() ? compat_ptr(oat_data.ptr) :
4858 u64_to_user_ptr(oat_data.ptr);
4859 oat_data.response_len = priv.response_len;
4860
4861 if (copy_to_user(tmp, priv.buffer, priv.response_len) ||
4862 copy_to_user(udata, &oat_data, sizeof(oat_data)))
4863 rc = -EFAULT;
4864 }
4865
4866out_free:
4867 vfree(priv.buffer);
4868 return rc;
4869}
4870
4871static int qeth_query_card_info_cb(struct qeth_card *card,
4872 struct qeth_reply *reply, unsigned long data)
4873{
4874 struct carrier_info *carrier_info = (struct carrier_info *)reply->param;
4875 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
4876 struct qeth_query_card_info *card_info;
4877
4878 QETH_CARD_TEXT(card, 2, "qcrdincb");
4879 if (qeth_setadpparms_inspect_rc(cmd))
4880 return -EIO;
4881
4882 card_info = &cmd->data.setadapterparms.data.card_info;
4883 carrier_info->card_type = card_info->card_type;
4884 carrier_info->port_mode = card_info->port_mode;
4885 carrier_info->port_speed = card_info->port_speed;
4886 return 0;
4887}
4888
4889int qeth_query_card_info(struct qeth_card *card,
4890 struct carrier_info *carrier_info)
4891{
4892 struct qeth_cmd_buffer *iob;
4893
4894 QETH_CARD_TEXT(card, 2, "qcrdinfo");
4895 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_CARD_INFO))
4896 return -EOPNOTSUPP;
4897 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_CARD_INFO, 0);
4898 if (!iob)
4899 return -ENOMEM;
4900 return qeth_send_ipa_cmd(card, iob, qeth_query_card_info_cb,
4901 (void *)carrier_info);
4902}
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912int qeth_vm_request_mac(struct qeth_card *card)
4913{
4914 struct diag26c_mac_resp *response;
4915 struct diag26c_mac_req *request;
4916 int rc;
4917
4918 QETH_CARD_TEXT(card, 2, "vmreqmac");
4919
4920 request = kzalloc(sizeof(*request), GFP_KERNEL | GFP_DMA);
4921 response = kzalloc(sizeof(*response), GFP_KERNEL | GFP_DMA);
4922 if (!request || !response) {
4923 rc = -ENOMEM;
4924 goto out;
4925 }
4926
4927 request->resp_buf_len = sizeof(*response);
4928 request->resp_version = DIAG26C_VERSION2;
4929 request->op_code = DIAG26C_GET_MAC;
4930 request->devno = card->info.ddev_devno;
4931
4932 QETH_DBF_HEX(CTRL, 2, request, sizeof(*request));
4933 rc = diag26c(request, response, DIAG26C_MAC_SERVICES);
4934 QETH_DBF_HEX(CTRL, 2, request, sizeof(*request));
4935 if (rc)
4936 goto out;
4937 QETH_DBF_HEX(CTRL, 2, response, sizeof(*response));
4938
4939 if (request->resp_buf_len < sizeof(*response) ||
4940 response->version != request->resp_version) {
4941 rc = -EIO;
4942 QETH_CARD_TEXT(card, 2, "badresp");
4943 QETH_CARD_HEX(card, 2, &request->resp_buf_len,
4944 sizeof(request->resp_buf_len));
4945 } else if (!is_valid_ether_addr(response->mac)) {
4946 rc = -EINVAL;
4947 QETH_CARD_TEXT(card, 2, "badmac");
4948 QETH_CARD_HEX(card, 2, response->mac, ETH_ALEN);
4949 } else {
4950 ether_addr_copy(card->dev->dev_addr, response->mac);
4951 }
4952
4953out:
4954 kfree(response);
4955 kfree(request);
4956 return rc;
4957}
4958EXPORT_SYMBOL_GPL(qeth_vm_request_mac);
4959
4960static void qeth_determine_capabilities(struct qeth_card *card)
4961{
4962 struct qeth_channel *channel = &card->data;
4963 struct ccw_device *ddev = channel->ccwdev;
4964 int rc;
4965 int ddev_offline = 0;
4966
4967 QETH_CARD_TEXT(card, 2, "detcapab");
4968 if (!ddev->online) {
4969 ddev_offline = 1;
4970 rc = qeth_start_channel(channel);
4971 if (rc) {
4972 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
4973 goto out;
4974 }
4975 }
4976
4977 rc = qeth_read_conf_data(card);
4978 if (rc) {
4979 QETH_DBF_MESSAGE(2, "qeth_read_conf_data on device %x returned %i\n",
4980 CARD_DEVID(card), rc);
4981 QETH_CARD_TEXT_(card, 2, "5err%d", rc);
4982 goto out_offline;
4983 }
4984
4985 rc = qdio_get_ssqd_desc(ddev, &card->ssqd);
4986 if (rc)
4987 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
4988
4989 QETH_CARD_TEXT_(card, 2, "qfmt%d", card->ssqd.qfmt);
4990 QETH_CARD_TEXT_(card, 2, "ac1:%02x", card->ssqd.qdioac1);
4991 QETH_CARD_TEXT_(card, 2, "ac2:%04x", card->ssqd.qdioac2);
4992 QETH_CARD_TEXT_(card, 2, "ac3:%04x", card->ssqd.qdioac3);
4993 QETH_CARD_TEXT_(card, 2, "icnt%d", card->ssqd.icnt);
4994 if (!((card->ssqd.qfmt != QDIO_IQDIO_QFMT) ||
4995 ((card->ssqd.qdioac1 & CHSC_AC1_INITIATE_INPUTQ) == 0) ||
4996 ((card->ssqd.qdioac3 & CHSC_AC3_FORMAT2_CQ_AVAILABLE) == 0))) {
4997 dev_info(&card->gdev->dev,
4998 "Completion Queueing supported\n");
4999 } else {
5000 card->options.cq = QETH_CQ_NOTAVAILABLE;
5001 }
5002
5003out_offline:
5004 if (ddev_offline == 1)
5005 qeth_stop_channel(channel);
5006out:
5007 return;
5008}
5009
5010static void qeth_read_ccw_conf_data(struct qeth_card *card)
5011{
5012 struct qeth_card_info *info = &card->info;
5013 struct ccw_device *cdev = CARD_DDEV(card);
5014 struct ccw_dev_id dev_id;
5015
5016 QETH_CARD_TEXT(card, 2, "ccwconfd");
5017 ccw_device_get_id(cdev, &dev_id);
5018
5019 info->ddev_devno = dev_id.devno;
5020 info->ids_valid = !ccw_device_get_cssid(cdev, &info->cssid) &&
5021 !ccw_device_get_iid(cdev, &info->iid) &&
5022 !ccw_device_get_chid(cdev, 0, &info->chid);
5023 info->ssid = dev_id.ssid;
5024
5025 dev_info(&card->gdev->dev, "CHID: %x CHPID: %x\n",
5026 info->chid, info->chpid);
5027
5028 QETH_CARD_TEXT_(card, 3, "devn%x", info->ddev_devno);
5029 QETH_CARD_TEXT_(card, 3, "cssid:%x", info->cssid);
5030 QETH_CARD_TEXT_(card, 3, "iid:%x", info->iid);
5031 QETH_CARD_TEXT_(card, 3, "ssid:%x", info->ssid);
5032 QETH_CARD_TEXT_(card, 3, "chpid:%x", info->chpid);
5033 QETH_CARD_TEXT_(card, 3, "chid:%x", info->chid);
5034 QETH_CARD_TEXT_(card, 3, "idval%x", info->ids_valid);
5035}
5036
5037static int qeth_qdio_establish(struct qeth_card *card)
5038{
5039 struct qdio_buffer **out_sbal_ptrs[QETH_MAX_OUT_QUEUES];
5040 struct qdio_buffer **in_sbal_ptrs[QETH_MAX_IN_QUEUES];
5041 struct qeth_qib_parms *qib_parms = NULL;
5042 struct qdio_initialize init_data;
5043 unsigned int i;
5044 int rc = 0;
5045
5046 QETH_CARD_TEXT(card, 2, "qdioest");
5047
5048 if (!IS_IQD(card) && !IS_VM_NIC(card)) {
5049 qib_parms = kzalloc(sizeof_field(struct qib, parm), GFP_KERNEL);
5050 if (!qib_parms)
5051 return -ENOMEM;
5052
5053 qeth_fill_qib_parms(card, qib_parms);
5054 }
5055
5056 in_sbal_ptrs[0] = card->qdio.in_q->qdio_bufs;
5057 if (card->options.cq == QETH_CQ_ENABLED)
5058 in_sbal_ptrs[1] = card->qdio.c_q->qdio_bufs;
5059
5060 for (i = 0; i < card->qdio.no_out_queues; i++)
5061 out_sbal_ptrs[i] = card->qdio.out_qs[i]->qdio_bufs;
5062
5063 memset(&init_data, 0, sizeof(struct qdio_initialize));
5064 init_data.q_format = IS_IQD(card) ? QDIO_IQDIO_QFMT :
5065 QDIO_QETH_QFMT;
5066 init_data.qib_param_field_format = 0;
5067 init_data.qib_param_field = (void *)qib_parms;
5068 init_data.no_input_qs = card->qdio.no_in_queues;
5069 init_data.no_output_qs = card->qdio.no_out_queues;
5070 init_data.input_handler = qeth_qdio_input_handler;
5071 init_data.output_handler = qeth_qdio_output_handler;
5072 init_data.irq_poll = qeth_qdio_poll;
5073 init_data.int_parm = (unsigned long) card;
5074 init_data.input_sbal_addr_array = in_sbal_ptrs;
5075 init_data.output_sbal_addr_array = out_sbal_ptrs;
5076 init_data.output_sbal_state_array = card->qdio.out_bufstates;
5077 init_data.scan_threshold = IS_IQD(card) ? 0 : 32;
5078
5079 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
5080 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
5081 rc = qdio_allocate(CARD_DDEV(card), init_data.no_input_qs,
5082 init_data.no_output_qs);
5083 if (rc) {
5084 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
5085 goto out;
5086 }
5087 rc = qdio_establish(CARD_DDEV(card), &init_data);
5088 if (rc) {
5089 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
5090 qdio_free(CARD_DDEV(card));
5091 }
5092 }
5093
5094 switch (card->options.cq) {
5095 case QETH_CQ_ENABLED:
5096 dev_info(&card->gdev->dev, "Completion Queue support enabled");
5097 break;
5098 case QETH_CQ_DISABLED:
5099 dev_info(&card->gdev->dev, "Completion Queue support disabled");
5100 break;
5101 default:
5102 break;
5103 }
5104
5105out:
5106 kfree(qib_parms);
5107 return rc;
5108}
5109
5110static void qeth_core_free_card(struct qeth_card *card)
5111{
5112 QETH_CARD_TEXT(card, 2, "freecrd");
5113
5114 unregister_service_level(&card->qeth_service_level);
5115 debugfs_remove_recursive(card->debugfs);
5116 qeth_put_cmd(card->read_cmd);
5117 destroy_workqueue(card->event_wq);
5118 dev_set_drvdata(&card->gdev->dev, NULL);
5119 kfree(card);
5120}
5121
5122static void qeth_trace_features(struct qeth_card *card)
5123{
5124 QETH_CARD_TEXT(card, 2, "features");
5125 QETH_CARD_HEX(card, 2, &card->options.ipa4, sizeof(card->options.ipa4));
5126 QETH_CARD_HEX(card, 2, &card->options.ipa6, sizeof(card->options.ipa6));
5127 QETH_CARD_HEX(card, 2, &card->options.adp, sizeof(card->options.adp));
5128 QETH_CARD_HEX(card, 2, &card->info.diagass_support,
5129 sizeof(card->info.diagass_support));
5130}
5131
5132static struct ccw_device_id qeth_ids[] = {
5133 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
5134 .driver_info = QETH_CARD_TYPE_OSD},
5135 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
5136 .driver_info = QETH_CARD_TYPE_IQD},
5137#ifdef CONFIG_QETH_OSN
5138 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
5139 .driver_info = QETH_CARD_TYPE_OSN},
5140#endif
5141 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
5142 .driver_info = QETH_CARD_TYPE_OSM},
5143#ifdef CONFIG_QETH_OSX
5144 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
5145 .driver_info = QETH_CARD_TYPE_OSX},
5146#endif
5147 {},
5148};
5149MODULE_DEVICE_TABLE(ccw, qeth_ids);
5150
5151static struct ccw_driver qeth_ccw_driver = {
5152 .driver = {
5153 .owner = THIS_MODULE,
5154 .name = "qeth",
5155 },
5156 .ids = qeth_ids,
5157 .probe = ccwgroup_probe_ccwdev,
5158 .remove = ccwgroup_remove_ccwdev,
5159};
5160
5161static int qeth_hardsetup_card(struct qeth_card *card, bool *carrier_ok)
5162{
5163 int retries = 3;
5164 int rc;
5165
5166 QETH_CARD_TEXT(card, 2, "hrdsetup");
5167 atomic_set(&card->force_alloc_skb, 0);
5168 rc = qeth_update_from_chp_desc(card);
5169 if (rc)
5170 return rc;
5171retry:
5172 if (retries < 3)
5173 QETH_DBF_MESSAGE(2, "Retrying to do IDX activates on device %x.\n",
5174 CARD_DEVID(card));
5175 rc = qeth_qdio_clear_card(card, !IS_IQD(card));
5176 qeth_stop_channel(&card->data);
5177 qeth_stop_channel(&card->write);
5178 qeth_stop_channel(&card->read);
5179 qdio_free(CARD_DDEV(card));
5180
5181 rc = qeth_start_channel(&card->read);
5182 if (rc)
5183 goto retriable;
5184 rc = qeth_start_channel(&card->write);
5185 if (rc)
5186 goto retriable;
5187 rc = qeth_start_channel(&card->data);
5188 if (rc)
5189 goto retriable;
5190retriable:
5191 if (rc == -ERESTARTSYS) {
5192 QETH_CARD_TEXT(card, 2, "break1");
5193 return rc;
5194 } else if (rc) {
5195 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
5196 if (--retries < 0)
5197 goto out;
5198 else
5199 goto retry;
5200 }
5201
5202 qeth_determine_capabilities(card);
5203 qeth_read_ccw_conf_data(card);
5204 qeth_idx_init(card);
5205
5206 rc = qeth_idx_activate_read_channel(card);
5207 if (rc == -EINTR) {
5208 QETH_CARD_TEXT(card, 2, "break2");
5209 return rc;
5210 } else if (rc) {
5211 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
5212 if (--retries < 0)
5213 goto out;
5214 else
5215 goto retry;
5216 }
5217
5218 rc = qeth_idx_activate_write_channel(card);
5219 if (rc == -EINTR) {
5220 QETH_CARD_TEXT(card, 2, "break3");
5221 return rc;
5222 } else if (rc) {
5223 QETH_CARD_TEXT_(card, 2, "4err%d", rc);
5224 if (--retries < 0)
5225 goto out;
5226 else
5227 goto retry;
5228 }
5229 card->read_or_write_problem = 0;
5230 rc = qeth_mpc_initialize(card);
5231 if (rc) {
5232 QETH_CARD_TEXT_(card, 2, "5err%d", rc);
5233 goto out;
5234 }
5235
5236 rc = qeth_send_startlan(card);
5237 if (rc) {
5238 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
5239 if (rc == -ENETDOWN) {
5240 dev_warn(&card->gdev->dev, "The LAN is offline\n");
5241 *carrier_ok = false;
5242 } else {
5243 goto out;
5244 }
5245 } else {
5246 *carrier_ok = true;
5247 }
5248
5249 card->options.ipa4.supported = 0;
5250 card->options.ipa6.supported = 0;
5251 card->options.adp.supported = 0;
5252 card->options.sbp.supported_funcs = 0;
5253 card->info.diagass_support = 0;
5254 rc = qeth_query_ipassists(card, QETH_PROT_IPV4);
5255 if (rc == -ENOMEM)
5256 goto out;
5257 if (qeth_is_supported(card, IPA_IPV6)) {
5258 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
5259 if (rc == -ENOMEM)
5260 goto out;
5261 }
5262 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
5263 rc = qeth_query_setadapterparms(card);
5264 if (rc < 0) {
5265 QETH_CARD_TEXT_(card, 2, "7err%d", rc);
5266 goto out;
5267 }
5268 }
5269 if (qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
5270 rc = qeth_query_setdiagass(card);
5271 if (rc)
5272 QETH_CARD_TEXT_(card, 2, "8err%d", rc);
5273 }
5274
5275 qeth_trace_features(card);
5276
5277 if (!qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP) ||
5278 (card->info.hwtrap && qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)))
5279 card->info.hwtrap = 0;
5280
5281 if (card->options.isolation != ISOLATION_MODE_NONE) {
5282 rc = qeth_setadpparms_set_access_ctrl(card,
5283 card->options.isolation);
5284 if (rc)
5285 goto out;
5286 }
5287
5288 rc = qeth_init_qdio_queues(card);
5289 if (rc) {
5290 QETH_CARD_TEXT_(card, 2, "9err%d", rc);
5291 goto out;
5292 }
5293
5294 return 0;
5295out:
5296 dev_warn(&card->gdev->dev, "The qeth device driver failed to recover "
5297 "an error on the device\n");
5298 QETH_DBF_MESSAGE(2, "Initialization for device %x failed in hardsetup! rc=%d\n",
5299 CARD_DEVID(card), rc);
5300 return rc;
5301}
5302
5303static int qeth_set_online(struct qeth_card *card)
5304{
5305 bool carrier_ok;
5306 int rc;
5307
5308 mutex_lock(&card->discipline_mutex);
5309 mutex_lock(&card->conf_mutex);
5310 QETH_CARD_TEXT(card, 2, "setonlin");
5311
5312 rc = qeth_hardsetup_card(card, &carrier_ok);
5313 if (rc) {
5314 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
5315 rc = -ENODEV;
5316 goto err_hardsetup;
5317 }
5318
5319 qeth_print_status_message(card);
5320
5321 if (card->dev->reg_state != NETREG_REGISTERED)
5322
5323 qeth_set_real_num_tx_queues(card, qeth_tx_actual_queues(card));
5324
5325 rc = card->discipline->set_online(card, carrier_ok);
5326 if (rc)
5327 goto err_online;
5328
5329
5330 kobject_uevent(&card->gdev->dev.kobj, KOBJ_CHANGE);
5331
5332 mutex_unlock(&card->conf_mutex);
5333 mutex_unlock(&card->discipline_mutex);
5334 return 0;
5335
5336err_online:
5337err_hardsetup:
5338 qeth_qdio_clear_card(card, 0);
5339 qeth_clear_working_pool_list(card);
5340 qeth_flush_local_addrs(card);
5341
5342 qeth_stop_channel(&card->data);
5343 qeth_stop_channel(&card->write);
5344 qeth_stop_channel(&card->read);
5345 qdio_free(CARD_DDEV(card));
5346
5347 mutex_unlock(&card->conf_mutex);
5348 mutex_unlock(&card->discipline_mutex);
5349 return rc;
5350}
5351
5352int qeth_set_offline(struct qeth_card *card, bool resetting)
5353{
5354 int rc, rc2, rc3;
5355
5356 mutex_lock(&card->discipline_mutex);
5357 mutex_lock(&card->conf_mutex);
5358 QETH_CARD_TEXT(card, 3, "setoffl");
5359
5360 if ((!resetting && card->info.hwtrap) || card->info.hwtrap == 2) {
5361 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
5362 card->info.hwtrap = 1;
5363 }
5364
5365
5366 qeth_clear_ipacmd_list(card);
5367
5368 rtnl_lock();
5369 card->info.open_when_online = card->dev->flags & IFF_UP;
5370 dev_close(card->dev);
5371 netif_device_detach(card->dev);
5372 netif_carrier_off(card->dev);
5373 rtnl_unlock();
5374
5375 cancel_work_sync(&card->rx_mode_work);
5376
5377 card->discipline->set_offline(card);
5378
5379 qeth_qdio_clear_card(card, 0);
5380 qeth_drain_output_queues(card);
5381 qeth_clear_working_pool_list(card);
5382 qeth_flush_local_addrs(card);
5383 card->info.promisc_mode = 0;
5384
5385 rc = qeth_stop_channel(&card->data);
5386 rc2 = qeth_stop_channel(&card->write);
5387 rc3 = qeth_stop_channel(&card->read);
5388 if (!rc)
5389 rc = (rc2) ? rc2 : rc3;
5390 if (rc)
5391 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
5392 qdio_free(CARD_DDEV(card));
5393
5394
5395 kobject_uevent(&card->gdev->dev.kobj, KOBJ_CHANGE);
5396
5397 mutex_unlock(&card->conf_mutex);
5398 mutex_unlock(&card->discipline_mutex);
5399 return 0;
5400}
5401EXPORT_SYMBOL_GPL(qeth_set_offline);
5402
5403static int qeth_do_reset(void *data)
5404{
5405 struct qeth_card *card = data;
5406 int rc;
5407
5408 QETH_CARD_TEXT(card, 2, "recover1");
5409 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
5410 return 0;
5411 QETH_CARD_TEXT(card, 2, "recover2");
5412 dev_warn(&card->gdev->dev,
5413 "A recovery process has been started for the device\n");
5414
5415 qeth_set_offline(card, true);
5416 rc = qeth_set_online(card);
5417 if (!rc) {
5418 dev_info(&card->gdev->dev,
5419 "Device successfully recovered!\n");
5420 } else {
5421 ccwgroup_set_offline(card->gdev);
5422 dev_warn(&card->gdev->dev,
5423 "The qeth device driver failed to recover an error on the device\n");
5424 }
5425 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
5426 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
5427 return 0;
5428}
5429
5430#if IS_ENABLED(CONFIG_QETH_L3)
5431static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
5432 struct qeth_hdr *hdr)
5433{
5434 struct af_iucv_trans_hdr *iucv = (struct af_iucv_trans_hdr *) skb->data;
5435 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3;
5436 struct net_device *dev = skb->dev;
5437
5438 if (IS_IQD(card) && iucv->magic == ETH_P_AF_IUCV) {
5439 dev_hard_header(skb, dev, ETH_P_AF_IUCV, dev->dev_addr,
5440 "FAKELL", skb->len);
5441 return;
5442 }
5443
5444 if (!(l3_hdr->flags & QETH_HDR_PASSTHRU)) {
5445 u16 prot = (l3_hdr->flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
5446 ETH_P_IP;
5447 unsigned char tg_addr[ETH_ALEN];
5448
5449 skb_reset_network_header(skb);
5450 switch (l3_hdr->flags & QETH_HDR_CAST_MASK) {
5451 case QETH_CAST_MULTICAST:
5452 if (prot == ETH_P_IP)
5453 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
5454 else
5455 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
5456 QETH_CARD_STAT_INC(card, rx_multicast);
5457 break;
5458 case QETH_CAST_BROADCAST:
5459 ether_addr_copy(tg_addr, dev->broadcast);
5460 QETH_CARD_STAT_INC(card, rx_multicast);
5461 break;
5462 default:
5463 if (card->options.sniffer)
5464 skb->pkt_type = PACKET_OTHERHOST;
5465 ether_addr_copy(tg_addr, dev->dev_addr);
5466 }
5467
5468 if (l3_hdr->ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
5469 dev_hard_header(skb, dev, prot, tg_addr,
5470 &l3_hdr->next_hop.rx.src_mac, skb->len);
5471 else
5472 dev_hard_header(skb, dev, prot, tg_addr, "FAKELL",
5473 skb->len);
5474 }
5475
5476
5477 if (!card->options.sniffer &&
5478 (l3_hdr->ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
5479 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
5480 u16 tag = (l3_hdr->ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
5481 l3_hdr->vlan_id :
5482 l3_hdr->next_hop.rx.vlan_id;
5483
5484 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
5485 }
5486}
5487#endif
5488
5489static void qeth_receive_skb(struct qeth_card *card, struct sk_buff *skb,
5490 struct qeth_hdr *hdr, bool uses_frags)
5491{
5492 struct napi_struct *napi = &card->napi;
5493 bool is_cso;
5494
5495 switch (hdr->hdr.l2.id) {
5496 case QETH_HEADER_TYPE_OSN:
5497 skb_push(skb, sizeof(*hdr));
5498 skb_copy_to_linear_data(skb, hdr, sizeof(*hdr));
5499 QETH_CARD_STAT_ADD(card, rx_bytes, skb->len);
5500 QETH_CARD_STAT_INC(card, rx_packets);
5501
5502 card->osn_info.data_cb(skb);
5503 return;
5504#if IS_ENABLED(CONFIG_QETH_L3)
5505 case QETH_HEADER_TYPE_LAYER3:
5506 qeth_l3_rebuild_skb(card, skb, hdr);
5507 is_cso = hdr->hdr.l3.ext_flags & QETH_HDR_EXT_CSUM_TRANSP_REQ;
5508 break;
5509#endif
5510 case QETH_HEADER_TYPE_LAYER2:
5511 is_cso = hdr->hdr.l2.flags[1] & QETH_HDR_EXT_CSUM_TRANSP_REQ;
5512 break;
5513 default:
5514
5515 if (uses_frags)
5516 napi_free_frags(napi);
5517 else
5518 dev_kfree_skb_any(skb);
5519 return;
5520 }
5521
5522 if (is_cso && (card->dev->features & NETIF_F_RXCSUM)) {
5523 skb->ip_summed = CHECKSUM_UNNECESSARY;
5524 QETH_CARD_STAT_INC(card, rx_skb_csum);
5525 } else {
5526 skb->ip_summed = CHECKSUM_NONE;
5527 }
5528
5529 QETH_CARD_STAT_ADD(card, rx_bytes, skb->len);
5530 QETH_CARD_STAT_INC(card, rx_packets);
5531 if (skb_is_nonlinear(skb)) {
5532 QETH_CARD_STAT_INC(card, rx_sg_skbs);
5533 QETH_CARD_STAT_ADD(card, rx_sg_frags,
5534 skb_shinfo(skb)->nr_frags);
5535 }
5536
5537 if (uses_frags) {
5538 napi_gro_frags(napi);
5539 } else {
5540 skb->protocol = eth_type_trans(skb, skb->dev);
5541 napi_gro_receive(napi, skb);
5542 }
5543}
5544
5545static void qeth_create_skb_frag(struct sk_buff *skb, char *data, int data_len)
5546{
5547 struct page *page = virt_to_page(data);
5548 unsigned int next_frag;
5549
5550 next_frag = skb_shinfo(skb)->nr_frags;
5551 get_page(page);
5552 skb_add_rx_frag(skb, next_frag, page, offset_in_page(data), data_len,
5553 data_len);
5554}
5555
5556static inline int qeth_is_last_sbale(struct qdio_buffer_element *sbale)
5557{
5558 return (sbale->eflags & SBAL_EFLAGS_LAST_ENTRY);
5559}
5560
5561static int qeth_extract_skb(struct qeth_card *card,
5562 struct qeth_qdio_buffer *qethbuffer, u8 *element_no,
5563 int *__offset)
5564{
5565 struct qeth_priv *priv = netdev_priv(card->dev);
5566 struct qdio_buffer *buffer = qethbuffer->buffer;
5567 struct napi_struct *napi = &card->napi;
5568 struct qdio_buffer_element *element;
5569 unsigned int linear_len = 0;
5570 bool uses_frags = false;
5571 int offset = *__offset;
5572 bool use_rx_sg = false;
5573 unsigned int headroom;
5574 struct qeth_hdr *hdr;
5575 struct sk_buff *skb;
5576 int skb_len = 0;
5577
5578 element = &buffer->element[*element_no];
5579
5580next_packet:
5581
5582 while (element->length < offset + sizeof(struct qeth_hdr)) {
5583 if (qeth_is_last_sbale(element))
5584 return -ENODATA;
5585 element++;
5586 offset = 0;
5587 }
5588
5589 hdr = phys_to_virt(element->addr) + offset;
5590 offset += sizeof(*hdr);
5591 skb = NULL;
5592
5593 switch (hdr->hdr.l2.id) {
5594 case QETH_HEADER_TYPE_LAYER2:
5595 skb_len = hdr->hdr.l2.pkt_length;
5596 linear_len = ETH_HLEN;
5597 headroom = 0;
5598 break;
5599 case QETH_HEADER_TYPE_LAYER3:
5600 skb_len = hdr->hdr.l3.length;
5601 if (!IS_LAYER3(card)) {
5602 QETH_CARD_STAT_INC(card, rx_dropped_notsupp);
5603 goto walk_packet;
5604 }
5605
5606 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
5607 linear_len = ETH_HLEN;
5608 headroom = 0;
5609 break;
5610 }
5611
5612 if (hdr->hdr.l3.flags & QETH_HDR_IPV6)
5613 linear_len = sizeof(struct ipv6hdr);
5614 else
5615 linear_len = sizeof(struct iphdr);
5616 headroom = ETH_HLEN;
5617 break;
5618 case QETH_HEADER_TYPE_OSN:
5619 skb_len = hdr->hdr.osn.pdu_length;
5620 if (!IS_OSN(card)) {
5621 QETH_CARD_STAT_INC(card, rx_dropped_notsupp);
5622 goto walk_packet;
5623 }
5624
5625 linear_len = skb_len;
5626 headroom = sizeof(struct qeth_hdr);
5627 break;
5628 default:
5629 if (hdr->hdr.l2.id & QETH_HEADER_MASK_INVAL)
5630 QETH_CARD_STAT_INC(card, rx_frame_errors);
5631 else
5632 QETH_CARD_STAT_INC(card, rx_dropped_notsupp);
5633
5634
5635 return -EPROTONOSUPPORT;
5636 }
5637
5638 if (skb_len < linear_len) {
5639 QETH_CARD_STAT_INC(card, rx_dropped_runt);
5640 goto walk_packet;
5641 }
5642
5643 use_rx_sg = (card->options.cq == QETH_CQ_ENABLED) ||
5644 (skb_len > READ_ONCE(priv->rx_copybreak) &&
5645 !atomic_read(&card->force_alloc_skb) &&
5646 !IS_OSN(card));
5647
5648 if (use_rx_sg) {
5649
5650 if (qethbuffer->rx_skb &&
5651 skb_tailroom(qethbuffer->rx_skb) >= linear_len + headroom) {
5652 skb = qethbuffer->rx_skb;
5653 qethbuffer->rx_skb = NULL;
5654 goto use_skb;
5655 }
5656
5657 skb = napi_get_frags(napi);
5658 if (!skb) {
5659
5660 QETH_CARD_STAT_INC(card, rx_dropped_nomem);
5661 goto walk_packet;
5662 }
5663
5664 if (skb_tailroom(skb) >= linear_len + headroom) {
5665 uses_frags = true;
5666 goto use_skb;
5667 }
5668
5669 netdev_info_once(card->dev,
5670 "Insufficient linear space in NAPI frags skb, need %u but have %u\n",
5671 linear_len + headroom, skb_tailroom(skb));
5672
5673 }
5674
5675 linear_len = skb_len;
5676 skb = napi_alloc_skb(napi, linear_len + headroom);
5677 if (!skb) {
5678 QETH_CARD_STAT_INC(card, rx_dropped_nomem);
5679 goto walk_packet;
5680 }
5681
5682use_skb:
5683 if (headroom)
5684 skb_reserve(skb, headroom);
5685walk_packet:
5686 while (skb_len) {
5687 int data_len = min(skb_len, (int)(element->length - offset));
5688 char *data = phys_to_virt(element->addr) + offset;
5689
5690 skb_len -= data_len;
5691 offset += data_len;
5692
5693
5694 if (skb && data_len) {
5695 if (linear_len) {
5696 unsigned int copy_len;
5697
5698 copy_len = min_t(unsigned int, linear_len,
5699 data_len);
5700
5701 skb_put_data(skb, data, copy_len);
5702 linear_len -= copy_len;
5703 data_len -= copy_len;
5704 data += copy_len;
5705 }
5706
5707 if (data_len)
5708 qeth_create_skb_frag(skb, data, data_len);
5709 }
5710
5711
5712 if (skb_len) {
5713 if (qeth_is_last_sbale(element)) {
5714 QETH_CARD_TEXT(card, 4, "unexeob");
5715 QETH_CARD_HEX(card, 2, buffer, sizeof(void *));
5716 if (skb) {
5717 if (uses_frags)
5718 napi_free_frags(napi);
5719 else
5720 dev_kfree_skb_any(skb);
5721 QETH_CARD_STAT_INC(card,
5722 rx_length_errors);
5723 }
5724 return -EMSGSIZE;
5725 }
5726 element++;
5727 offset = 0;
5728 }
5729 }
5730
5731
5732 if (!skb)
5733 goto next_packet;
5734
5735 *element_no = element - &buffer->element[0];
5736 *__offset = offset;
5737
5738 qeth_receive_skb(card, skb, hdr, uses_frags);
5739 return 0;
5740}
5741
5742static unsigned int qeth_extract_skbs(struct qeth_card *card, int budget,
5743 struct qeth_qdio_buffer *buf, bool *done)
5744{
5745 unsigned int work_done = 0;
5746
5747 while (budget) {
5748 if (qeth_extract_skb(card, buf, &card->rx.buf_element,
5749 &card->rx.e_offset)) {
5750 *done = true;
5751 break;
5752 }
5753
5754 work_done++;
5755 budget--;
5756 }
5757
5758 return work_done;
5759}
5760
5761static unsigned int qeth_rx_poll(struct qeth_card *card, int budget)
5762{
5763 struct qeth_rx *ctx = &card->rx;
5764 unsigned int work_done = 0;
5765
5766 while (budget > 0) {
5767 struct qeth_qdio_buffer *buffer;
5768 unsigned int skbs_done = 0;
5769 bool done = false;
5770
5771
5772 if (!card->rx.b_count) {
5773 card->rx.qdio_err = 0;
5774 card->rx.b_count = qdio_get_next_buffers(
5775 card->data.ccwdev, 0, &card->rx.b_index,
5776 &card->rx.qdio_err);
5777 if (card->rx.b_count <= 0) {
5778 card->rx.b_count = 0;
5779 break;
5780 }
5781 }
5782
5783
5784 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
5785 if (!(card->rx.qdio_err &&
5786 qeth_check_qdio_errors(card, buffer->buffer,
5787 card->rx.qdio_err, "qinerr")))
5788 skbs_done = qeth_extract_skbs(card, budget, buffer,
5789 &done);
5790 else
5791 done = true;
5792
5793 work_done += skbs_done;
5794 budget -= skbs_done;
5795
5796 if (done) {
5797 QETH_CARD_STAT_INC(card, rx_bufs);
5798 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
5799 buffer->pool_entry = NULL;
5800 card->rx.b_count--;
5801 ctx->bufs_refill++;
5802 ctx->bufs_refill -= qeth_rx_refill_queue(card,
5803 ctx->bufs_refill);
5804
5805
5806 card->rx.b_index = QDIO_BUFNR(card->rx.b_index + 1);
5807 card->rx.buf_element = 0;
5808 card->rx.e_offset = 0;
5809 }
5810 }
5811
5812 return work_done;
5813}
5814
5815static void qeth_cq_poll(struct qeth_card *card)
5816{
5817 unsigned int work_done = 0;
5818
5819 while (work_done < QDIO_MAX_BUFFERS_PER_Q) {
5820 unsigned int start, error;
5821 int completed;
5822
5823 completed = qdio_inspect_queue(CARD_DDEV(card), 1, true, &start,
5824 &error);
5825 if (completed <= 0)
5826 return;
5827
5828 qeth_qdio_cq_handler(card, error, 1, start, completed);
5829 work_done += completed;
5830 }
5831}
5832
5833int qeth_poll(struct napi_struct *napi, int budget)
5834{
5835 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
5836 unsigned int work_done;
5837
5838 work_done = qeth_rx_poll(card, budget);
5839
5840 if (card->options.cq == QETH_CQ_ENABLED)
5841 qeth_cq_poll(card);
5842
5843 if (budget) {
5844 struct qeth_rx *ctx = &card->rx;
5845
5846
5847 ctx->bufs_refill -= qeth_rx_refill_queue(card, ctx->bufs_refill);
5848
5849
5850 if (work_done >= budget)
5851 return work_done;
5852 }
5853
5854 if (napi_complete_done(napi, work_done) &&
5855 qdio_start_irq(CARD_DDEV(card)))
5856 napi_schedule(napi);
5857
5858 return work_done;
5859}
5860EXPORT_SYMBOL_GPL(qeth_poll);
5861
5862static void qeth_iqd_tx_complete(struct qeth_qdio_out_q *queue,
5863 unsigned int bidx, bool error, int budget)
5864{
5865 struct qeth_qdio_out_buffer *buffer = queue->bufs[bidx];
5866 u8 sflags = buffer->buffer->element[15].sflags;
5867 struct qeth_card *card = queue->card;
5868
5869 if (queue->bufstates && (queue->bufstates[bidx].flags &
5870 QDIO_OUTBUF_STATE_FLAG_PENDING)) {
5871 WARN_ON_ONCE(card->options.cq != QETH_CQ_ENABLED);
5872
5873 if (atomic_cmpxchg(&buffer->state, QETH_QDIO_BUF_PRIMED,
5874 QETH_QDIO_BUF_PENDING) ==
5875 QETH_QDIO_BUF_PRIMED) {
5876 qeth_notify_skbs(queue, buffer, TX_NOTIFY_PENDING);
5877
5878
5879 switch (atomic_xchg(&buffer->state,
5880 QETH_QDIO_BUF_NEED_QAOB)) {
5881 case QETH_QDIO_BUF_PENDING:
5882
5883 break;
5884 case QETH_QDIO_BUF_QAOB_OK:
5885 qeth_notify_skbs(queue, buffer,
5886 TX_NOTIFY_DELAYED_OK);
5887 atomic_set(&buffer->state,
5888 QETH_QDIO_BUF_HANDLED_DELAYED);
5889 break;
5890 case QETH_QDIO_BUF_QAOB_ERROR:
5891 qeth_notify_skbs(queue, buffer,
5892 TX_NOTIFY_DELAYED_GENERALERROR);
5893 atomic_set(&buffer->state,
5894 QETH_QDIO_BUF_HANDLED_DELAYED);
5895 break;
5896 default:
5897 WARN_ON_ONCE(1);
5898 }
5899 }
5900
5901 QETH_CARD_TEXT_(card, 5, "pel%u", bidx);
5902
5903
5904 qeth_scrub_qdio_buffer(buffer->buffer, queue->max_elements);
5905 if (qeth_init_qdio_out_buf(queue, bidx)) {
5906 QETH_CARD_TEXT(card, 2, "outofbuf");
5907 qeth_schedule_recovery(card);
5908 }
5909
5910 return;
5911 }
5912
5913 if (card->options.cq == QETH_CQ_ENABLED)
5914 qeth_notify_skbs(queue, buffer,
5915 qeth_compute_cq_notification(sflags, 0));
5916 qeth_clear_output_buffer(queue, buffer, error, budget);
5917}
5918
5919static int qeth_tx_poll(struct napi_struct *napi, int budget)
5920{
5921 struct qeth_qdio_out_q *queue = qeth_napi_to_out_queue(napi);
5922 unsigned int queue_no = queue->queue_no;
5923 struct qeth_card *card = queue->card;
5924 struct net_device *dev = card->dev;
5925 unsigned int work_done = 0;
5926 struct netdev_queue *txq;
5927
5928 txq = netdev_get_tx_queue(dev, qeth_iqd_translate_txq(dev, queue_no));
5929
5930 while (1) {
5931 unsigned int start, error, i;
5932 unsigned int packets = 0;
5933 unsigned int bytes = 0;
5934 int completed;
5935
5936 if (qeth_out_queue_is_empty(queue)) {
5937 napi_complete(napi);
5938 return 0;
5939 }
5940
5941
5942 if (work_done >= QDIO_MAX_BUFFERS_PER_Q) {
5943 QETH_TXQ_STAT_INC(queue, completion_yield);
5944 if (napi_complete_done(napi, 0))
5945 napi_schedule(napi);
5946 return 0;
5947 }
5948
5949 completed = qdio_inspect_queue(CARD_DDEV(card), queue_no, false,
5950 &start, &error);
5951 if (completed <= 0) {
5952
5953 if (napi_complete_done(napi, 0))
5954 qeth_tx_arm_timer(queue, QETH_TX_TIMER_USECS);
5955 return 0;
5956 }
5957
5958 for (i = start; i < start + completed; i++) {
5959 struct qeth_qdio_out_buffer *buffer;
5960 unsigned int bidx = QDIO_BUFNR(i);
5961
5962 buffer = queue->bufs[bidx];
5963 packets += buffer->frames;
5964 bytes += buffer->bytes;
5965
5966 qeth_handle_send_error(card, buffer, error);
5967 qeth_iqd_tx_complete(queue, bidx, error, budget);
5968 qeth_cleanup_handled_pending(queue, bidx, false);
5969 }
5970
5971 netdev_tx_completed_queue(txq, packets, bytes);
5972 atomic_sub(completed, &queue->used_buffers);
5973 work_done += completed;
5974
5975
5976
5977
5978
5979
5980 if (netif_tx_queue_stopped(txq) &&
5981 !qeth_out_queue_is_full(queue))
5982 netif_tx_wake_queue(txq);
5983 }
5984}
5985
5986static int qeth_setassparms_inspect_rc(struct qeth_ipa_cmd *cmd)
5987{
5988 if (!cmd->hdr.return_code)
5989 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
5990 return cmd->hdr.return_code;
5991}
5992
5993static int qeth_setassparms_get_caps_cb(struct qeth_card *card,
5994 struct qeth_reply *reply,
5995 unsigned long data)
5996{
5997 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
5998 struct qeth_ipa_caps *caps = reply->param;
5999
6000 if (qeth_setassparms_inspect_rc(cmd))
6001 return -EIO;
6002
6003 caps->supported = cmd->data.setassparms.data.caps.supported;
6004 caps->enabled = cmd->data.setassparms.data.caps.enabled;
6005 return 0;
6006}
6007
6008int qeth_setassparms_cb(struct qeth_card *card,
6009 struct qeth_reply *reply, unsigned long data)
6010{
6011 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
6012
6013 QETH_CARD_TEXT(card, 4, "defadpcb");
6014
6015 if (cmd->hdr.return_code)
6016 return -EIO;
6017
6018 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6019 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6020 card->options.ipa4.enabled = cmd->hdr.assists.enabled;
6021 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6022 card->options.ipa6.enabled = cmd->hdr.assists.enabled;
6023 return 0;
6024}
6025EXPORT_SYMBOL_GPL(qeth_setassparms_cb);
6026
6027struct qeth_cmd_buffer *qeth_get_setassparms_cmd(struct qeth_card *card,
6028 enum qeth_ipa_funcs ipa_func,
6029 u16 cmd_code,
6030 unsigned int data_length,
6031 enum qeth_prot_versions prot)
6032{
6033 struct qeth_ipacmd_setassparms *setassparms;
6034 struct qeth_ipacmd_setassparms_hdr *hdr;
6035 struct qeth_cmd_buffer *iob;
6036
6037 QETH_CARD_TEXT(card, 4, "getasscm");
6038 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SETASSPARMS, prot,
6039 data_length +
6040 offsetof(struct qeth_ipacmd_setassparms,
6041 data));
6042 if (!iob)
6043 return NULL;
6044
6045 setassparms = &__ipa_cmd(iob)->data.setassparms;
6046 setassparms->assist_no = ipa_func;
6047
6048 hdr = &setassparms->hdr;
6049 hdr->length = sizeof(*hdr) + data_length;
6050 hdr->command_code = cmd_code;
6051 return iob;
6052}
6053EXPORT_SYMBOL_GPL(qeth_get_setassparms_cmd);
6054
6055int qeth_send_simple_setassparms_prot(struct qeth_card *card,
6056 enum qeth_ipa_funcs ipa_func,
6057 u16 cmd_code, u32 *data,
6058 enum qeth_prot_versions prot)
6059{
6060 unsigned int length = data ? SETASS_DATA_SIZEOF(flags_32bit) : 0;
6061 struct qeth_cmd_buffer *iob;
6062
6063 QETH_CARD_TEXT_(card, 4, "simassp%i", prot);
6064 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code, length, prot);
6065 if (!iob)
6066 return -ENOMEM;
6067
6068 if (data)
6069 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = *data;
6070 return qeth_send_ipa_cmd(card, iob, qeth_setassparms_cb, NULL);
6071}
6072EXPORT_SYMBOL_GPL(qeth_send_simple_setassparms_prot);
6073
6074static void qeth_unregister_dbf_views(void)
6075{
6076 int x;
6077
6078 for (x = 0; x < QETH_DBF_INFOS; x++) {
6079 debug_unregister(qeth_dbf[x].id);
6080 qeth_dbf[x].id = NULL;
6081 }
6082}
6083
6084void qeth_dbf_longtext(debug_info_t *id, int level, char *fmt, ...)
6085{
6086 char dbf_txt_buf[32];
6087 va_list args;
6088
6089 if (!debug_level_enabled(id, level))
6090 return;
6091 va_start(args, fmt);
6092 vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
6093 va_end(args);
6094 debug_text_event(id, level, dbf_txt_buf);
6095}
6096EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
6097
6098static int qeth_register_dbf_views(void)
6099{
6100 int ret;
6101 int x;
6102
6103 for (x = 0; x < QETH_DBF_INFOS; x++) {
6104
6105 qeth_dbf[x].id = debug_register(qeth_dbf[x].name,
6106 qeth_dbf[x].pages,
6107 qeth_dbf[x].areas,
6108 qeth_dbf[x].len);
6109 if (qeth_dbf[x].id == NULL) {
6110 qeth_unregister_dbf_views();
6111 return -ENOMEM;
6112 }
6113
6114
6115 ret = debug_register_view(qeth_dbf[x].id, qeth_dbf[x].view);
6116 if (ret) {
6117 qeth_unregister_dbf_views();
6118 return ret;
6119 }
6120
6121
6122 debug_set_level(qeth_dbf[x].id, qeth_dbf[x].level);
6123 }
6124
6125 return 0;
6126}
6127
6128static DEFINE_MUTEX(qeth_mod_mutex);
6129
6130int qeth_core_load_discipline(struct qeth_card *card,
6131 enum qeth_discipline_id discipline)
6132{
6133 mutex_lock(&qeth_mod_mutex);
6134 switch (discipline) {
6135 case QETH_DISCIPLINE_LAYER3:
6136 card->discipline = try_then_request_module(
6137 symbol_get(qeth_l3_discipline), "qeth_l3");
6138 break;
6139 case QETH_DISCIPLINE_LAYER2:
6140 card->discipline = try_then_request_module(
6141 symbol_get(qeth_l2_discipline), "qeth_l2");
6142 break;
6143 default:
6144 break;
6145 }
6146 mutex_unlock(&qeth_mod_mutex);
6147
6148 if (!card->discipline) {
6149 dev_err(&card->gdev->dev, "There is no kernel module to "
6150 "support discipline %d\n", discipline);
6151 return -EINVAL;
6152 }
6153
6154 card->options.layer = discipline;
6155 return 0;
6156}
6157
6158void qeth_core_free_discipline(struct qeth_card *card)
6159{
6160 if (IS_LAYER2(card))
6161 symbol_put(qeth_l2_discipline);
6162 else
6163 symbol_put(qeth_l3_discipline);
6164 card->options.layer = QETH_DISCIPLINE_UNDETERMINED;
6165 card->discipline = NULL;
6166}
6167
6168const struct device_type qeth_generic_devtype = {
6169 .name = "qeth_generic",
6170 .groups = qeth_generic_attr_groups,
6171};
6172EXPORT_SYMBOL_GPL(qeth_generic_devtype);
6173
6174static const struct device_type qeth_osn_devtype = {
6175 .name = "qeth_osn",
6176 .groups = qeth_osn_attr_groups,
6177};
6178
6179#define DBF_NAME_LEN 20
6180
6181struct qeth_dbf_entry {
6182 char dbf_name[DBF_NAME_LEN];
6183 debug_info_t *dbf_info;
6184 struct list_head dbf_list;
6185};
6186
6187static LIST_HEAD(qeth_dbf_list);
6188static DEFINE_MUTEX(qeth_dbf_list_mutex);
6189
6190static debug_info_t *qeth_get_dbf_entry(char *name)
6191{
6192 struct qeth_dbf_entry *entry;
6193 debug_info_t *rc = NULL;
6194
6195 mutex_lock(&qeth_dbf_list_mutex);
6196 list_for_each_entry(entry, &qeth_dbf_list, dbf_list) {
6197 if (strcmp(entry->dbf_name, name) == 0) {
6198 rc = entry->dbf_info;
6199 break;
6200 }
6201 }
6202 mutex_unlock(&qeth_dbf_list_mutex);
6203 return rc;
6204}
6205
6206static int qeth_add_dbf_entry(struct qeth_card *card, char *name)
6207{
6208 struct qeth_dbf_entry *new_entry;
6209
6210 card->debug = debug_register(name, 2, 1, 8);
6211 if (!card->debug) {
6212 QETH_DBF_TEXT_(SETUP, 2, "%s", "qcdbf");
6213 goto err;
6214 }
6215 if (debug_register_view(card->debug, &debug_hex_ascii_view))
6216 goto err_dbg;
6217 new_entry = kzalloc(sizeof(struct qeth_dbf_entry), GFP_KERNEL);
6218 if (!new_entry)
6219 goto err_dbg;
6220 strncpy(new_entry->dbf_name, name, DBF_NAME_LEN);
6221 new_entry->dbf_info = card->debug;
6222 mutex_lock(&qeth_dbf_list_mutex);
6223 list_add(&new_entry->dbf_list, &qeth_dbf_list);
6224 mutex_unlock(&qeth_dbf_list_mutex);
6225
6226 return 0;
6227
6228err_dbg:
6229 debug_unregister(card->debug);
6230err:
6231 return -ENOMEM;
6232}
6233
6234static void qeth_clear_dbf_list(void)
6235{
6236 struct qeth_dbf_entry *entry, *tmp;
6237
6238 mutex_lock(&qeth_dbf_list_mutex);
6239 list_for_each_entry_safe(entry, tmp, &qeth_dbf_list, dbf_list) {
6240 list_del(&entry->dbf_list);
6241 debug_unregister(entry->dbf_info);
6242 kfree(entry);
6243 }
6244 mutex_unlock(&qeth_dbf_list_mutex);
6245}
6246
6247static struct net_device *qeth_alloc_netdev(struct qeth_card *card)
6248{
6249 struct net_device *dev;
6250 struct qeth_priv *priv;
6251
6252 switch (card->info.type) {
6253 case QETH_CARD_TYPE_IQD:
6254 dev = alloc_netdev_mqs(sizeof(*priv), "hsi%d", NET_NAME_UNKNOWN,
6255 ether_setup, QETH_MAX_OUT_QUEUES, 1);
6256 break;
6257 case QETH_CARD_TYPE_OSM:
6258 dev = alloc_etherdev(sizeof(*priv));
6259 break;
6260 case QETH_CARD_TYPE_OSN:
6261 dev = alloc_netdev(sizeof(*priv), "osn%d", NET_NAME_UNKNOWN,
6262 ether_setup);
6263 break;
6264 default:
6265 dev = alloc_etherdev_mqs(sizeof(*priv), QETH_MAX_OUT_QUEUES, 1);
6266 }
6267
6268 if (!dev)
6269 return NULL;
6270
6271 priv = netdev_priv(dev);
6272 priv->rx_copybreak = QETH_RX_COPYBREAK;
6273 priv->tx_wanted_queues = IS_IQD(card) ? QETH_IQD_MIN_TXQ : 1;
6274
6275 dev->ml_priv = card;
6276 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6277 dev->min_mtu = IS_OSN(card) ? 64 : 576;
6278
6279 dev->max_mtu = 0;
6280 dev->mtu = 0;
6281 SET_NETDEV_DEV(dev, &card->gdev->dev);
6282 netif_carrier_off(dev);
6283
6284 if (IS_OSN(card)) {
6285 dev->ethtool_ops = &qeth_osn_ethtool_ops;
6286 } else {
6287 dev->ethtool_ops = &qeth_ethtool_ops;
6288 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
6289 dev->hw_features |= NETIF_F_SG;
6290 dev->vlan_features |= NETIF_F_SG;
6291 if (IS_IQD(card))
6292 dev->features |= NETIF_F_SG;
6293 }
6294
6295 return dev;
6296}
6297
6298struct net_device *qeth_clone_netdev(struct net_device *orig)
6299{
6300 struct net_device *clone = qeth_alloc_netdev(orig->ml_priv);
6301
6302 if (!clone)
6303 return NULL;
6304
6305 clone->dev_port = orig->dev_port;
6306 return clone;
6307}
6308
6309static int qeth_core_probe_device(struct ccwgroup_device *gdev)
6310{
6311 struct qeth_card *card;
6312 struct device *dev;
6313 int rc;
6314 enum qeth_discipline_id enforced_disc;
6315 char dbf_name[DBF_NAME_LEN];
6316
6317 QETH_DBF_TEXT(SETUP, 2, "probedev");
6318
6319 dev = &gdev->dev;
6320 if (!get_device(dev))
6321 return -ENODEV;
6322
6323 QETH_DBF_TEXT_(SETUP, 2, "%s", dev_name(&gdev->dev));
6324
6325 card = qeth_alloc_card(gdev);
6326 if (!card) {
6327 QETH_DBF_TEXT_(SETUP, 2, "1err%d", -ENOMEM);
6328 rc = -ENOMEM;
6329 goto err_dev;
6330 }
6331
6332 snprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s",
6333 dev_name(&gdev->dev));
6334 card->debug = qeth_get_dbf_entry(dbf_name);
6335 if (!card->debug) {
6336 rc = qeth_add_dbf_entry(card, dbf_name);
6337 if (rc)
6338 goto err_card;
6339 }
6340
6341 qeth_setup_card(card);
6342 card->dev = qeth_alloc_netdev(card);
6343 if (!card->dev) {
6344 rc = -ENOMEM;
6345 goto err_card;
6346 }
6347
6348 qeth_determine_capabilities(card);
6349 qeth_set_blkt_defaults(card);
6350
6351 card->qdio.no_out_queues = card->dev->num_tx_queues;
6352 rc = qeth_update_from_chp_desc(card);
6353 if (rc)
6354 goto err_chp_desc;
6355
6356 enforced_disc = qeth_enforce_discipline(card);
6357 switch (enforced_disc) {
6358 case QETH_DISCIPLINE_UNDETERMINED:
6359 gdev->dev.type = &qeth_generic_devtype;
6360 break;
6361 default:
6362 card->info.layer_enforced = true;
6363 rc = qeth_core_load_discipline(card, enforced_disc);
6364 if (rc)
6365 goto err_load;
6366
6367 gdev->dev.type = IS_OSN(card) ? &qeth_osn_devtype :
6368 card->discipline->devtype;
6369 rc = card->discipline->setup(card->gdev);
6370 if (rc)
6371 goto err_disc;
6372 break;
6373 }
6374
6375 return 0;
6376
6377err_disc:
6378 qeth_core_free_discipline(card);
6379err_load:
6380err_chp_desc:
6381 free_netdev(card->dev);
6382err_card:
6383 qeth_core_free_card(card);
6384err_dev:
6385 put_device(dev);
6386 return rc;
6387}
6388
6389static void qeth_core_remove_device(struct ccwgroup_device *gdev)
6390{
6391 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
6392
6393 QETH_CARD_TEXT(card, 2, "removedv");
6394
6395 if (card->discipline) {
6396 card->discipline->remove(gdev);
6397 qeth_core_free_discipline(card);
6398 }
6399
6400 qeth_free_qdio_queues(card);
6401
6402 free_netdev(card->dev);
6403 qeth_core_free_card(card);
6404 put_device(&gdev->dev);
6405}
6406
6407static int qeth_core_set_online(struct ccwgroup_device *gdev)
6408{
6409 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
6410 int rc = 0;
6411 enum qeth_discipline_id def_discipline;
6412
6413 if (!card->discipline) {
6414 def_discipline = IS_IQD(card) ? QETH_DISCIPLINE_LAYER3 :
6415 QETH_DISCIPLINE_LAYER2;
6416 rc = qeth_core_load_discipline(card, def_discipline);
6417 if (rc)
6418 goto err;
6419 rc = card->discipline->setup(card->gdev);
6420 if (rc) {
6421 qeth_core_free_discipline(card);
6422 goto err;
6423 }
6424 }
6425
6426 rc = qeth_set_online(card);
6427err:
6428 return rc;
6429}
6430
6431static int qeth_core_set_offline(struct ccwgroup_device *gdev)
6432{
6433 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
6434
6435 return qeth_set_offline(card, false);
6436}
6437
6438static void qeth_core_shutdown(struct ccwgroup_device *gdev)
6439{
6440 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
6441
6442 qeth_set_allowed_threads(card, 0, 1);
6443 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
6444 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
6445 qeth_qdio_clear_card(card, 0);
6446 qeth_drain_output_queues(card);
6447 qdio_free(CARD_DDEV(card));
6448}
6449
6450static ssize_t group_store(struct device_driver *ddrv, const char *buf,
6451 size_t count)
6452{
6453 int err;
6454
6455 err = ccwgroup_create_dev(qeth_core_root_dev, to_ccwgroupdrv(ddrv), 3,
6456 buf);
6457
6458 return err ? err : count;
6459}
6460static DRIVER_ATTR_WO(group);
6461
6462static struct attribute *qeth_drv_attrs[] = {
6463 &driver_attr_group.attr,
6464 NULL,
6465};
6466static struct attribute_group qeth_drv_attr_group = {
6467 .attrs = qeth_drv_attrs,
6468};
6469static const struct attribute_group *qeth_drv_attr_groups[] = {
6470 &qeth_drv_attr_group,
6471 NULL,
6472};
6473
6474static struct ccwgroup_driver qeth_core_ccwgroup_driver = {
6475 .driver = {
6476 .groups = qeth_drv_attr_groups,
6477 .owner = THIS_MODULE,
6478 .name = "qeth",
6479 },
6480 .ccw_driver = &qeth_ccw_driver,
6481 .setup = qeth_core_probe_device,
6482 .remove = qeth_core_remove_device,
6483 .set_online = qeth_core_set_online,
6484 .set_offline = qeth_core_set_offline,
6485 .shutdown = qeth_core_shutdown,
6486};
6487
6488struct qeth_card *qeth_get_card_by_busid(char *bus_id)
6489{
6490 struct ccwgroup_device *gdev;
6491 struct qeth_card *card;
6492
6493 gdev = get_ccwgroupdev_by_busid(&qeth_core_ccwgroup_driver, bus_id);
6494 if (!gdev)
6495 return NULL;
6496
6497 card = dev_get_drvdata(&gdev->dev);
6498 put_device(&gdev->dev);
6499 return card;
6500}
6501EXPORT_SYMBOL_GPL(qeth_get_card_by_busid);
6502
6503int qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6504{
6505 struct qeth_card *card = dev->ml_priv;
6506 struct mii_ioctl_data *mii_data;
6507 int rc = 0;
6508
6509 switch (cmd) {
6510 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
6511 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
6512 break;
6513 case SIOC_QETH_GET_CARD_TYPE:
6514 if ((IS_OSD(card) || IS_OSM(card) || IS_OSX(card)) &&
6515 !IS_VM_NIC(card))
6516 return 1;
6517 return 0;
6518 case SIOCGMIIPHY:
6519 mii_data = if_mii(rq);
6520 mii_data->phy_id = 0;
6521 break;
6522 case SIOCGMIIREG:
6523 mii_data = if_mii(rq);
6524 if (mii_data->phy_id != 0)
6525 rc = -EINVAL;
6526 else
6527 mii_data->val_out = qeth_mdio_read(dev,
6528 mii_data->phy_id, mii_data->reg_num);
6529 break;
6530 case SIOC_QETH_QUERY_OAT:
6531 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
6532 break;
6533 default:
6534 if (card->discipline->do_ioctl)
6535 rc = card->discipline->do_ioctl(dev, rq, cmd);
6536 else
6537 rc = -EOPNOTSUPP;
6538 }
6539 if (rc)
6540 QETH_CARD_TEXT_(card, 2, "ioce%x", rc);
6541 return rc;
6542}
6543EXPORT_SYMBOL_GPL(qeth_do_ioctl);
6544
6545static int qeth_start_csum_cb(struct qeth_card *card, struct qeth_reply *reply,
6546 unsigned long data)
6547{
6548 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
6549 u32 *features = reply->param;
6550
6551 if (qeth_setassparms_inspect_rc(cmd))
6552 return -EIO;
6553
6554 *features = cmd->data.setassparms.data.flags_32bit;
6555 return 0;
6556}
6557
6558static int qeth_set_csum_off(struct qeth_card *card, enum qeth_ipa_funcs cstype,
6559 enum qeth_prot_versions prot)
6560{
6561 return qeth_send_simple_setassparms_prot(card, cstype, IPA_CMD_ASS_STOP,
6562 NULL, prot);
6563}
6564
6565static int qeth_set_csum_on(struct qeth_card *card, enum qeth_ipa_funcs cstype,
6566 enum qeth_prot_versions prot, u8 *lp2lp)
6567{
6568 u32 required_features = QETH_IPA_CHECKSUM_UDP | QETH_IPA_CHECKSUM_TCP;
6569 struct qeth_cmd_buffer *iob;
6570 struct qeth_ipa_caps caps;
6571 u32 features;
6572 int rc;
6573
6574
6575 if (IS_LAYER3(card) && prot == QETH_PROT_IPV4 &&
6576 cstype == IPA_OUTBOUND_CHECKSUM)
6577 required_features |= QETH_IPA_CHECKSUM_IP_HDR;
6578
6579 iob = qeth_get_setassparms_cmd(card, cstype, IPA_CMD_ASS_START, 0,
6580 prot);
6581 if (!iob)
6582 return -ENOMEM;
6583
6584 rc = qeth_send_ipa_cmd(card, iob, qeth_start_csum_cb, &features);
6585 if (rc)
6586 return rc;
6587
6588 if ((required_features & features) != required_features) {
6589 qeth_set_csum_off(card, cstype, prot);
6590 return -EOPNOTSUPP;
6591 }
6592
6593 iob = qeth_get_setassparms_cmd(card, cstype, IPA_CMD_ASS_ENABLE,
6594 SETASS_DATA_SIZEOF(flags_32bit),
6595 prot);
6596 if (!iob) {
6597 qeth_set_csum_off(card, cstype, prot);
6598 return -ENOMEM;
6599 }
6600
6601 if (features & QETH_IPA_CHECKSUM_LP2LP)
6602 required_features |= QETH_IPA_CHECKSUM_LP2LP;
6603 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = required_features;
6604 rc = qeth_send_ipa_cmd(card, iob, qeth_setassparms_get_caps_cb, &caps);
6605 if (rc) {
6606 qeth_set_csum_off(card, cstype, prot);
6607 return rc;
6608 }
6609
6610 if (!qeth_ipa_caps_supported(&caps, required_features) ||
6611 !qeth_ipa_caps_enabled(&caps, required_features)) {
6612 qeth_set_csum_off(card, cstype, prot);
6613 return -EOPNOTSUPP;
6614 }
6615
6616 dev_info(&card->gdev->dev, "HW Checksumming (%sbound IPv%d) enabled\n",
6617 cstype == IPA_INBOUND_CHECKSUM ? "in" : "out", prot);
6618
6619 if (lp2lp)
6620 *lp2lp = qeth_ipa_caps_enabled(&caps, QETH_IPA_CHECKSUM_LP2LP);
6621
6622 return 0;
6623}
6624
6625static int qeth_set_ipa_csum(struct qeth_card *card, bool on, int cstype,
6626 enum qeth_prot_versions prot, u8 *lp2lp)
6627{
6628 return on ? qeth_set_csum_on(card, cstype, prot, lp2lp) :
6629 qeth_set_csum_off(card, cstype, prot);
6630}
6631
6632static int qeth_start_tso_cb(struct qeth_card *card, struct qeth_reply *reply,
6633 unsigned long data)
6634{
6635 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
6636 struct qeth_tso_start_data *tso_data = reply->param;
6637
6638 if (qeth_setassparms_inspect_rc(cmd))
6639 return -EIO;
6640
6641 tso_data->mss = cmd->data.setassparms.data.tso.mss;
6642 tso_data->supported = cmd->data.setassparms.data.tso.supported;
6643 return 0;
6644}
6645
6646static int qeth_set_tso_off(struct qeth_card *card,
6647 enum qeth_prot_versions prot)
6648{
6649 return qeth_send_simple_setassparms_prot(card, IPA_OUTBOUND_TSO,
6650 IPA_CMD_ASS_STOP, NULL, prot);
6651}
6652
6653static int qeth_set_tso_on(struct qeth_card *card,
6654 enum qeth_prot_versions prot)
6655{
6656 struct qeth_tso_start_data tso_data;
6657 struct qeth_cmd_buffer *iob;
6658 struct qeth_ipa_caps caps;
6659 int rc;
6660
6661 iob = qeth_get_setassparms_cmd(card, IPA_OUTBOUND_TSO,
6662 IPA_CMD_ASS_START, 0, prot);
6663 if (!iob)
6664 return -ENOMEM;
6665
6666 rc = qeth_send_ipa_cmd(card, iob, qeth_start_tso_cb, &tso_data);
6667 if (rc)
6668 return rc;
6669
6670 if (!tso_data.mss || !(tso_data.supported & QETH_IPA_LARGE_SEND_TCP)) {
6671 qeth_set_tso_off(card, prot);
6672 return -EOPNOTSUPP;
6673 }
6674
6675 iob = qeth_get_setassparms_cmd(card, IPA_OUTBOUND_TSO,
6676 IPA_CMD_ASS_ENABLE,
6677 SETASS_DATA_SIZEOF(caps), prot);
6678 if (!iob) {
6679 qeth_set_tso_off(card, prot);
6680 return -ENOMEM;
6681 }
6682
6683
6684 __ipa_cmd(iob)->data.setassparms.data.caps.enabled =
6685 QETH_IPA_LARGE_SEND_TCP;
6686 rc = qeth_send_ipa_cmd(card, iob, qeth_setassparms_get_caps_cb, &caps);
6687 if (rc) {
6688 qeth_set_tso_off(card, prot);
6689 return rc;
6690 }
6691
6692 if (!qeth_ipa_caps_supported(&caps, QETH_IPA_LARGE_SEND_TCP) ||
6693 !qeth_ipa_caps_enabled(&caps, QETH_IPA_LARGE_SEND_TCP)) {
6694 qeth_set_tso_off(card, prot);
6695 return -EOPNOTSUPP;
6696 }
6697
6698 dev_info(&card->gdev->dev, "TSOv%u enabled (MSS: %u)\n", prot,
6699 tso_data.mss);
6700 return 0;
6701}
6702
6703static int qeth_set_ipa_tso(struct qeth_card *card, bool on,
6704 enum qeth_prot_versions prot)
6705{
6706 return on ? qeth_set_tso_on(card, prot) : qeth_set_tso_off(card, prot);
6707}
6708
6709static int qeth_set_ipa_rx_csum(struct qeth_card *card, bool on)
6710{
6711 int rc_ipv4 = (on) ? -EOPNOTSUPP : 0;
6712 int rc_ipv6;
6713
6714 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
6715 rc_ipv4 = qeth_set_ipa_csum(card, on, IPA_INBOUND_CHECKSUM,
6716 QETH_PROT_IPV4, NULL);
6717 if (!qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6))
6718
6719 return rc_ipv4;
6720
6721 rc_ipv6 = qeth_set_ipa_csum(card, on, IPA_INBOUND_CHECKSUM,
6722 QETH_PROT_IPV6, NULL);
6723
6724 if (on)
6725
6726 return (rc_ipv6) ? rc_ipv4 : 0;
6727
6728
6729 return (rc_ipv6) ? rc_ipv6 : rc_ipv4;
6730}
6731
6732
6733
6734
6735
6736void qeth_enable_hw_features(struct net_device *dev)
6737{
6738 struct qeth_card *card = dev->ml_priv;
6739 netdev_features_t features;
6740
6741 features = dev->features;
6742
6743
6744
6745 dev->features &= ~dev->hw_features;
6746
6747 if (IS_LAYER2(card) && IS_VM_NIC(card)) {
6748 dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
6749 dev->wanted_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
6750 }
6751 netdev_update_features(dev);
6752 if (features != dev->features)
6753 dev_warn(&card->gdev->dev,
6754 "Device recovery failed to restore all offload features\n");
6755}
6756EXPORT_SYMBOL_GPL(qeth_enable_hw_features);
6757
6758static void qeth_check_restricted_features(struct qeth_card *card,
6759 netdev_features_t changed,
6760 netdev_features_t actual)
6761{
6762 netdev_features_t ipv6_features = NETIF_F_TSO6;
6763 netdev_features_t ipv4_features = NETIF_F_TSO;
6764
6765 if (!card->info.has_lp2lp_cso_v6)
6766 ipv6_features |= NETIF_F_IPV6_CSUM;
6767 if (!card->info.has_lp2lp_cso_v4)
6768 ipv4_features |= NETIF_F_IP_CSUM;
6769
6770 if ((changed & ipv6_features) && !(actual & ipv6_features))
6771 qeth_flush_local_addrs6(card);
6772 if ((changed & ipv4_features) && !(actual & ipv4_features))
6773 qeth_flush_local_addrs4(card);
6774}
6775
6776int qeth_set_features(struct net_device *dev, netdev_features_t features)
6777{
6778 struct qeth_card *card = dev->ml_priv;
6779 netdev_features_t changed = dev->features ^ features;
6780 int rc = 0;
6781
6782 QETH_CARD_TEXT(card, 2, "setfeat");
6783 QETH_CARD_HEX(card, 2, &features, sizeof(features));
6784
6785 if ((changed & NETIF_F_IP_CSUM)) {
6786 rc = qeth_set_ipa_csum(card, features & NETIF_F_IP_CSUM,
6787 IPA_OUTBOUND_CHECKSUM, QETH_PROT_IPV4,
6788 &card->info.has_lp2lp_cso_v4);
6789 if (rc)
6790 changed ^= NETIF_F_IP_CSUM;
6791 }
6792 if (changed & NETIF_F_IPV6_CSUM) {
6793 rc = qeth_set_ipa_csum(card, features & NETIF_F_IPV6_CSUM,
6794 IPA_OUTBOUND_CHECKSUM, QETH_PROT_IPV6,
6795 &card->info.has_lp2lp_cso_v6);
6796 if (rc)
6797 changed ^= NETIF_F_IPV6_CSUM;
6798 }
6799 if (changed & NETIF_F_RXCSUM) {
6800 rc = qeth_set_ipa_rx_csum(card, features & NETIF_F_RXCSUM);
6801 if (rc)
6802 changed ^= NETIF_F_RXCSUM;
6803 }
6804 if (changed & NETIF_F_TSO) {
6805 rc = qeth_set_ipa_tso(card, features & NETIF_F_TSO,
6806 QETH_PROT_IPV4);
6807 if (rc)
6808 changed ^= NETIF_F_TSO;
6809 }
6810 if (changed & NETIF_F_TSO6) {
6811 rc = qeth_set_ipa_tso(card, features & NETIF_F_TSO6,
6812 QETH_PROT_IPV6);
6813 if (rc)
6814 changed ^= NETIF_F_TSO6;
6815 }
6816
6817 qeth_check_restricted_features(card, dev->features ^ features,
6818 dev->features ^ changed);
6819
6820
6821 if ((dev->features ^ features) == changed)
6822 return 0;
6823
6824 dev->features ^= changed;
6825 return -EIO;
6826}
6827EXPORT_SYMBOL_GPL(qeth_set_features);
6828
6829netdev_features_t qeth_fix_features(struct net_device *dev,
6830 netdev_features_t features)
6831{
6832 struct qeth_card *card = dev->ml_priv;
6833
6834 QETH_CARD_TEXT(card, 2, "fixfeat");
6835 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
6836 features &= ~NETIF_F_IP_CSUM;
6837 if (!qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6))
6838 features &= ~NETIF_F_IPV6_CSUM;
6839 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM) &&
6840 !qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6))
6841 features &= ~NETIF_F_RXCSUM;
6842 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
6843 features &= ~NETIF_F_TSO;
6844 if (!qeth_is_supported6(card, IPA_OUTBOUND_TSO))
6845 features &= ~NETIF_F_TSO6;
6846
6847 QETH_CARD_HEX(card, 2, &features, sizeof(features));
6848 return features;
6849}
6850EXPORT_SYMBOL_GPL(qeth_fix_features);
6851
6852netdev_features_t qeth_features_check(struct sk_buff *skb,
6853 struct net_device *dev,
6854 netdev_features_t features)
6855{
6856 struct qeth_card *card = dev->ml_priv;
6857
6858
6859 if (skb->ip_summed == CHECKSUM_PARTIAL &&
6860 READ_ONCE(card->options.isolation) != ISOLATION_MODE_FWD) {
6861 netdev_features_t restricted = 0;
6862
6863 if (skb_is_gso(skb) && !netif_needs_gso(skb, features))
6864 restricted |= NETIF_F_ALL_TSO;
6865
6866 switch (vlan_get_protocol(skb)) {
6867 case htons(ETH_P_IP):
6868 if (!card->info.has_lp2lp_cso_v4)
6869 restricted |= NETIF_F_IP_CSUM;
6870
6871 if (restricted && qeth_next_hop_is_local_v4(card, skb))
6872 features &= ~restricted;
6873 break;
6874 case htons(ETH_P_IPV6):
6875 if (!card->info.has_lp2lp_cso_v6)
6876 restricted |= NETIF_F_IPV6_CSUM;
6877
6878 if (restricted && qeth_next_hop_is_local_v6(card, skb))
6879 features &= ~restricted;
6880 break;
6881 default:
6882 break;
6883 }
6884 }
6885
6886
6887
6888
6889
6890
6891
6892
6893 if (netif_needs_gso(skb, features)) {
6894
6895 unsigned int doffset = skb->data - skb_mac_header(skb);
6896 unsigned int hsize = skb_shinfo(skb)->gso_size;
6897 unsigned int hroom = skb_headroom(skb);
6898
6899
6900 if (SKB_DATA_ALIGN(hroom + doffset + hsize) <= SKB_MAX_HEAD(0))
6901 features &= ~NETIF_F_SG;
6902 }
6903
6904 return vlan_features_check(skb, features);
6905}
6906EXPORT_SYMBOL_GPL(qeth_features_check);
6907
6908void qeth_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
6909{
6910 struct qeth_card *card = dev->ml_priv;
6911 struct qeth_qdio_out_q *queue;
6912 unsigned int i;
6913
6914 QETH_CARD_TEXT(card, 5, "getstat");
6915
6916 stats->rx_packets = card->stats.rx_packets;
6917 stats->rx_bytes = card->stats.rx_bytes;
6918 stats->rx_errors = card->stats.rx_length_errors +
6919 card->stats.rx_frame_errors +
6920 card->stats.rx_fifo_errors;
6921 stats->rx_dropped = card->stats.rx_dropped_nomem +
6922 card->stats.rx_dropped_notsupp +
6923 card->stats.rx_dropped_runt;
6924 stats->multicast = card->stats.rx_multicast;
6925 stats->rx_length_errors = card->stats.rx_length_errors;
6926 stats->rx_frame_errors = card->stats.rx_frame_errors;
6927 stats->rx_fifo_errors = card->stats.rx_fifo_errors;
6928
6929 for (i = 0; i < card->qdio.no_out_queues; i++) {
6930 queue = card->qdio.out_qs[i];
6931
6932 stats->tx_packets += queue->stats.tx_packets;
6933 stats->tx_bytes += queue->stats.tx_bytes;
6934 stats->tx_errors += queue->stats.tx_errors;
6935 stats->tx_dropped += queue->stats.tx_dropped;
6936 }
6937}
6938EXPORT_SYMBOL_GPL(qeth_get_stats64);
6939
6940#define TC_IQD_UCAST 0
6941static void qeth_iqd_set_prio_tc_map(struct net_device *dev,
6942 unsigned int ucast_txqs)
6943{
6944 unsigned int prio;
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955 netdev_set_num_tc(dev, 1);
6956 netdev_set_tc_queue(dev, TC_IQD_UCAST, ucast_txqs,
6957 QETH_IQD_MIN_UCAST_TXQ);
6958
6959
6960 for (prio = 0; prio <= TC_BITMASK; prio++)
6961 netdev_set_prio_tc_map(dev, prio, TC_IQD_UCAST);
6962}
6963
6964int qeth_set_real_num_tx_queues(struct qeth_card *card, unsigned int count)
6965{
6966 struct net_device *dev = card->dev;
6967 int rc;
6968
6969
6970 if (IS_IQD(card))
6971 qeth_iqd_set_prio_tc_map(dev, count - 1);
6972
6973 rc = netif_set_real_num_tx_queues(dev, count);
6974
6975 if (rc && IS_IQD(card))
6976 qeth_iqd_set_prio_tc_map(dev, dev->real_num_tx_queues - 1);
6977
6978 return rc;
6979}
6980EXPORT_SYMBOL_GPL(qeth_set_real_num_tx_queues);
6981
6982u16 qeth_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
6983 u8 cast_type, struct net_device *sb_dev)
6984{
6985 u16 txq;
6986
6987 if (cast_type != RTN_UNICAST)
6988 return QETH_IQD_MCAST_TXQ;
6989 if (dev->real_num_tx_queues == QETH_IQD_MIN_TXQ)
6990 return QETH_IQD_MIN_UCAST_TXQ;
6991
6992 txq = netdev_pick_tx(dev, skb, sb_dev);
6993 return (txq == QETH_IQD_MCAST_TXQ) ? QETH_IQD_MIN_UCAST_TXQ : txq;
6994}
6995EXPORT_SYMBOL_GPL(qeth_iqd_select_queue);
6996
6997int qeth_open(struct net_device *dev)
6998{
6999 struct qeth_card *card = dev->ml_priv;
7000
7001 QETH_CARD_TEXT(card, 4, "qethopen");
7002
7003 card->data.state = CH_STATE_UP;
7004 netif_tx_start_all_queues(dev);
7005
7006 napi_enable(&card->napi);
7007 local_bh_disable();
7008 napi_schedule(&card->napi);
7009 if (IS_IQD(card)) {
7010 struct qeth_qdio_out_q *queue;
7011 unsigned int i;
7012
7013 qeth_for_each_output_queue(card, queue, i) {
7014 netif_tx_napi_add(dev, &queue->napi, qeth_tx_poll,
7015 QETH_NAPI_WEIGHT);
7016 napi_enable(&queue->napi);
7017 napi_schedule(&queue->napi);
7018 }
7019 }
7020
7021 local_bh_enable();
7022 return 0;
7023}
7024EXPORT_SYMBOL_GPL(qeth_open);
7025
7026int qeth_stop(struct net_device *dev)
7027{
7028 struct qeth_card *card = dev->ml_priv;
7029
7030 QETH_CARD_TEXT(card, 4, "qethstop");
7031 if (IS_IQD(card)) {
7032 struct qeth_qdio_out_q *queue;
7033 unsigned int i;
7034
7035
7036 qeth_for_each_output_queue(card, queue, i)
7037 napi_disable(&queue->napi);
7038
7039
7040 netif_tx_disable(dev);
7041
7042 qeth_for_each_output_queue(card, queue, i) {
7043 del_timer_sync(&queue->timer);
7044
7045 netif_napi_del(&queue->napi);
7046 }
7047 } else {
7048 netif_tx_disable(dev);
7049 }
7050
7051 napi_disable(&card->napi);
7052 cancel_delayed_work_sync(&card->buffer_reclaim_work);
7053 qdio_stop_irq(CARD_DDEV(card));
7054
7055 return 0;
7056}
7057EXPORT_SYMBOL_GPL(qeth_stop);
7058
7059static int __init qeth_core_init(void)
7060{
7061 int rc;
7062
7063 pr_info("loading core functions\n");
7064
7065 qeth_debugfs_root = debugfs_create_dir("qeth", NULL);
7066
7067 rc = qeth_register_dbf_views();
7068 if (rc)
7069 goto dbf_err;
7070 qeth_core_root_dev = root_device_register("qeth");
7071 rc = PTR_ERR_OR_ZERO(qeth_core_root_dev);
7072 if (rc)
7073 goto register_err;
7074 qeth_core_header_cache =
7075 kmem_cache_create("qeth_hdr", QETH_HDR_CACHE_OBJ_SIZE,
7076 roundup_pow_of_two(QETH_HDR_CACHE_OBJ_SIZE),
7077 0, NULL);
7078 if (!qeth_core_header_cache) {
7079 rc = -ENOMEM;
7080 goto slab_err;
7081 }
7082 qeth_qdio_outbuf_cache = kmem_cache_create("qeth_buf",
7083 sizeof(struct qeth_qdio_out_buffer), 0, 0, NULL);
7084 if (!qeth_qdio_outbuf_cache) {
7085 rc = -ENOMEM;
7086 goto cqslab_err;
7087 }
7088 rc = ccw_driver_register(&qeth_ccw_driver);
7089 if (rc)
7090 goto ccw_err;
7091 rc = ccwgroup_driver_register(&qeth_core_ccwgroup_driver);
7092 if (rc)
7093 goto ccwgroup_err;
7094
7095 return 0;
7096
7097ccwgroup_err:
7098 ccw_driver_unregister(&qeth_ccw_driver);
7099ccw_err:
7100 kmem_cache_destroy(qeth_qdio_outbuf_cache);
7101cqslab_err:
7102 kmem_cache_destroy(qeth_core_header_cache);
7103slab_err:
7104 root_device_unregister(qeth_core_root_dev);
7105register_err:
7106 qeth_unregister_dbf_views();
7107dbf_err:
7108 debugfs_remove_recursive(qeth_debugfs_root);
7109 pr_err("Initializing the qeth device driver failed\n");
7110 return rc;
7111}
7112
7113static void __exit qeth_core_exit(void)
7114{
7115 qeth_clear_dbf_list();
7116 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
7117 ccw_driver_unregister(&qeth_ccw_driver);
7118 kmem_cache_destroy(qeth_qdio_outbuf_cache);
7119 kmem_cache_destroy(qeth_core_header_cache);
7120 root_device_unregister(qeth_core_root_dev);
7121 qeth_unregister_dbf_views();
7122 debugfs_remove_recursive(qeth_debugfs_root);
7123 pr_info("core functions removed\n");
7124}
7125
7126module_init(qeth_core_init);
7127module_exit(qeth_core_exit);
7128MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
7129MODULE_DESCRIPTION("qeth core functions");
7130MODULE_LICENSE("GPL");
7131