sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / s390 / net / qeth_core_main.c
blobe33558313834dc5e118d478fb5595452f2f6c9ed
1 /*
2 * Copyright IBM Corp. 2007, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/string.h>
15 #include <linux/errno.h>
16 #include <linux/kernel.h>
17 #include <linux/ip.h>
18 #include <linux/tcp.h>
19 #include <linux/mii.h>
20 #include <linux/kthread.h>
21 #include <linux/slab.h>
22 #include <net/iucv/af_iucv.h>
23 #include <net/dsfield.h>
25 #include <asm/ebcdic.h>
26 #include <asm/chpid.h>
27 #include <asm/io.h>
28 #include <asm/sysinfo.h>
29 #include <asm/compat.h>
31 #include "qeth_core.h"
33 struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
34 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
35 /* N P A M L V H */
36 [QETH_DBF_SETUP] = {"qeth_setup",
37 8, 1, 8, 5, &debug_hex_ascii_view, NULL},
38 [QETH_DBF_MSG] = {"qeth_msg", 8, 1, 11 * sizeof(long), 3,
39 &debug_sprintf_view, NULL},
40 [QETH_DBF_CTRL] = {"qeth_control",
41 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
43 EXPORT_SYMBOL_GPL(qeth_dbf);
45 struct qeth_card_list_struct qeth_core_card_list;
46 EXPORT_SYMBOL_GPL(qeth_core_card_list);
47 struct kmem_cache *qeth_core_header_cache;
48 EXPORT_SYMBOL_GPL(qeth_core_header_cache);
49 static struct kmem_cache *qeth_qdio_outbuf_cache;
51 static struct device *qeth_core_root_dev;
52 static unsigned int known_devices[][6] = QETH_MODELLIST_ARRAY;
53 static struct lock_class_key qdio_out_skb_queue_key;
54 static struct mutex qeth_mod_mutex;
56 static void qeth_send_control_data_cb(struct qeth_channel *,
57 struct qeth_cmd_buffer *);
58 static int qeth_issue_next_read(struct qeth_card *);
59 static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *);
60 static void qeth_setup_ccw(struct qeth_channel *, unsigned char *, __u32);
61 static void qeth_free_buffer_pool(struct qeth_card *);
62 static int qeth_qdio_establish(struct qeth_card *);
63 static void qeth_free_qdio_buffers(struct qeth_card *);
64 static void qeth_notify_skbs(struct qeth_qdio_out_q *queue,
65 struct qeth_qdio_out_buffer *buf,
66 enum iucv_tx_notify notification);
67 static void qeth_release_skbs(struct qeth_qdio_out_buffer *buf);
68 static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
69 struct qeth_qdio_out_buffer *buf,
70 enum qeth_qdio_buffer_states newbufstate);
71 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q *, int);
73 struct workqueue_struct *qeth_wq;
74 EXPORT_SYMBOL_GPL(qeth_wq);
76 int qeth_card_hw_is_reachable(struct qeth_card *card)
78 return (card->state == CARD_STATE_SOFTSETUP) ||
79 (card->state == CARD_STATE_UP);
81 EXPORT_SYMBOL_GPL(qeth_card_hw_is_reachable);
83 static void qeth_close_dev_handler(struct work_struct *work)
85 struct qeth_card *card;
87 card = container_of(work, struct qeth_card, close_dev_work);
88 QETH_CARD_TEXT(card, 2, "cldevhdl");
89 rtnl_lock();
90 dev_close(card->dev);
91 rtnl_unlock();
92 ccwgroup_set_offline(card->gdev);
95 void qeth_close_dev(struct qeth_card *card)
97 QETH_CARD_TEXT(card, 2, "cldevsubm");
98 queue_work(qeth_wq, &card->close_dev_work);
100 EXPORT_SYMBOL_GPL(qeth_close_dev);
102 static inline const char *qeth_get_cardname(struct qeth_card *card)
104 if (card->info.guestlan) {
105 switch (card->info.type) {
106 case QETH_CARD_TYPE_OSD:
107 return " Virtual NIC QDIO";
108 case QETH_CARD_TYPE_IQD:
109 return " Virtual NIC Hiper";
110 case QETH_CARD_TYPE_OSM:
111 return " Virtual NIC QDIO - OSM";
112 case QETH_CARD_TYPE_OSX:
113 return " Virtual NIC QDIO - OSX";
114 default:
115 return " unknown";
117 } else {
118 switch (card->info.type) {
119 case QETH_CARD_TYPE_OSD:
120 return " OSD Express";
121 case QETH_CARD_TYPE_IQD:
122 return " HiperSockets";
123 case QETH_CARD_TYPE_OSN:
124 return " OSN QDIO";
125 case QETH_CARD_TYPE_OSM:
126 return " OSM QDIO";
127 case QETH_CARD_TYPE_OSX:
128 return " OSX QDIO";
129 default:
130 return " unknown";
133 return " n/a";
136 /* max length to be returned: 14 */
137 const char *qeth_get_cardname_short(struct qeth_card *card)
139 if (card->info.guestlan) {
140 switch (card->info.type) {
141 case QETH_CARD_TYPE_OSD:
142 return "Virt.NIC QDIO";
143 case QETH_CARD_TYPE_IQD:
144 return "Virt.NIC Hiper";
145 case QETH_CARD_TYPE_OSM:
146 return "Virt.NIC OSM";
147 case QETH_CARD_TYPE_OSX:
148 return "Virt.NIC OSX";
149 default:
150 return "unknown";
152 } else {
153 switch (card->info.type) {
154 case QETH_CARD_TYPE_OSD:
155 switch (card->info.link_type) {
156 case QETH_LINK_TYPE_FAST_ETH:
157 return "OSD_100";
158 case QETH_LINK_TYPE_HSTR:
159 return "HSTR";
160 case QETH_LINK_TYPE_GBIT_ETH:
161 return "OSD_1000";
162 case QETH_LINK_TYPE_10GBIT_ETH:
163 return "OSD_10GIG";
164 case QETH_LINK_TYPE_LANE_ETH100:
165 return "OSD_FE_LANE";
166 case QETH_LINK_TYPE_LANE_TR:
167 return "OSD_TR_LANE";
168 case QETH_LINK_TYPE_LANE_ETH1000:
169 return "OSD_GbE_LANE";
170 case QETH_LINK_TYPE_LANE:
171 return "OSD_ATM_LANE";
172 default:
173 return "OSD_Express";
175 case QETH_CARD_TYPE_IQD:
176 return "HiperSockets";
177 case QETH_CARD_TYPE_OSN:
178 return "OSN";
179 case QETH_CARD_TYPE_OSM:
180 return "OSM_1000";
181 case QETH_CARD_TYPE_OSX:
182 return "OSX_10GIG";
183 default:
184 return "unknown";
187 return "n/a";
190 void qeth_set_recovery_task(struct qeth_card *card)
192 card->recovery_task = current;
194 EXPORT_SYMBOL_GPL(qeth_set_recovery_task);
196 void qeth_clear_recovery_task(struct qeth_card *card)
198 card->recovery_task = NULL;
200 EXPORT_SYMBOL_GPL(qeth_clear_recovery_task);
202 static bool qeth_is_recovery_task(const struct qeth_card *card)
204 return card->recovery_task == current;
207 void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
208 int clear_start_mask)
210 unsigned long flags;
212 spin_lock_irqsave(&card->thread_mask_lock, flags);
213 card->thread_allowed_mask = threads;
214 if (clear_start_mask)
215 card->thread_start_mask &= threads;
216 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
217 wake_up(&card->wait_q);
219 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads);
221 int qeth_threads_running(struct qeth_card *card, unsigned long threads)
223 unsigned long flags;
224 int rc = 0;
226 spin_lock_irqsave(&card->thread_mask_lock, flags);
227 rc = (card->thread_running_mask & threads);
228 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
229 return rc;
231 EXPORT_SYMBOL_GPL(qeth_threads_running);
233 int qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
235 if (qeth_is_recovery_task(card))
236 return 0;
237 return wait_event_interruptible(card->wait_q,
238 qeth_threads_running(card, threads) == 0);
240 EXPORT_SYMBOL_GPL(qeth_wait_for_threads);
242 void qeth_clear_working_pool_list(struct qeth_card *card)
244 struct qeth_buffer_pool_entry *pool_entry, *tmp;
246 QETH_CARD_TEXT(card, 5, "clwrklst");
247 list_for_each_entry_safe(pool_entry, tmp,
248 &card->qdio.in_buf_pool.entry_list, list){
249 list_del(&pool_entry->list);
252 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list);
254 static int qeth_alloc_buffer_pool(struct qeth_card *card)
256 struct qeth_buffer_pool_entry *pool_entry;
257 void *ptr;
258 int i, j;
260 QETH_CARD_TEXT(card, 5, "alocpool");
261 for (i = 0; i < card->qdio.init_pool.buf_count; ++i) {
262 pool_entry = kzalloc(sizeof(*pool_entry), GFP_KERNEL);
263 if (!pool_entry) {
264 qeth_free_buffer_pool(card);
265 return -ENOMEM;
267 for (j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j) {
268 ptr = (void *) __get_free_page(GFP_KERNEL);
269 if (!ptr) {
270 while (j > 0)
271 free_page((unsigned long)
272 pool_entry->elements[--j]);
273 kfree(pool_entry);
274 qeth_free_buffer_pool(card);
275 return -ENOMEM;
277 pool_entry->elements[j] = ptr;
279 list_add(&pool_entry->init_list,
280 &card->qdio.init_pool.entry_list);
282 return 0;
285 int qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
287 QETH_CARD_TEXT(card, 2, "realcbp");
289 if ((card->state != CARD_STATE_DOWN) &&
290 (card->state != CARD_STATE_RECOVER))
291 return -EPERM;
293 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
294 qeth_clear_working_pool_list(card);
295 qeth_free_buffer_pool(card);
296 card->qdio.in_buf_pool.buf_count = bufcnt;
297 card->qdio.init_pool.buf_count = bufcnt;
298 return qeth_alloc_buffer_pool(card);
300 EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool);
302 static void qeth_free_qdio_queue(struct qeth_qdio_q *q)
304 if (!q)
305 return;
307 qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
308 kfree(q);
311 static struct qeth_qdio_q *qeth_alloc_qdio_queue(void)
313 struct qeth_qdio_q *q = kzalloc(sizeof(*q), GFP_KERNEL);
314 int i;
316 if (!q)
317 return NULL;
319 if (qdio_alloc_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q)) {
320 kfree(q);
321 return NULL;
324 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
325 q->bufs[i].buffer = q->qdio_bufs[i];
327 QETH_DBF_HEX(SETUP, 2, &q, sizeof(void *));
328 return q;
331 static inline int qeth_cq_init(struct qeth_card *card)
333 int rc;
335 if (card->options.cq == QETH_CQ_ENABLED) {
336 QETH_DBF_TEXT(SETUP, 2, "cqinit");
337 qdio_reset_buffers(card->qdio.c_q->qdio_bufs,
338 QDIO_MAX_BUFFERS_PER_Q);
339 card->qdio.c_q->next_buf_to_init = 127;
340 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT,
341 card->qdio.no_in_queues - 1, 0,
342 127);
343 if (rc) {
344 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
345 goto out;
348 rc = 0;
349 out:
350 return rc;
353 static inline int qeth_alloc_cq(struct qeth_card *card)
355 int rc;
357 if (card->options.cq == QETH_CQ_ENABLED) {
358 int i;
359 struct qdio_outbuf_state *outbuf_states;
361 QETH_DBF_TEXT(SETUP, 2, "cqon");
362 card->qdio.c_q = qeth_alloc_qdio_queue();
363 if (!card->qdio.c_q) {
364 rc = -1;
365 goto kmsg_out;
367 card->qdio.no_in_queues = 2;
368 card->qdio.out_bufstates =
369 kzalloc(card->qdio.no_out_queues *
370 QDIO_MAX_BUFFERS_PER_Q *
371 sizeof(struct qdio_outbuf_state), GFP_KERNEL);
372 outbuf_states = card->qdio.out_bufstates;
373 if (outbuf_states == NULL) {
374 rc = -1;
375 goto free_cq_out;
377 for (i = 0; i < card->qdio.no_out_queues; ++i) {
378 card->qdio.out_qs[i]->bufstates = outbuf_states;
379 outbuf_states += QDIO_MAX_BUFFERS_PER_Q;
381 } else {
382 QETH_DBF_TEXT(SETUP, 2, "nocq");
383 card->qdio.c_q = NULL;
384 card->qdio.no_in_queues = 1;
386 QETH_DBF_TEXT_(SETUP, 2, "iqc%d", card->qdio.no_in_queues);
387 rc = 0;
388 out:
389 return rc;
390 free_cq_out:
391 qeth_free_qdio_queue(card->qdio.c_q);
392 card->qdio.c_q = NULL;
393 kmsg_out:
394 dev_err(&card->gdev->dev, "Failed to create completion queue\n");
395 goto out;
398 static inline void qeth_free_cq(struct qeth_card *card)
400 if (card->qdio.c_q) {
401 --card->qdio.no_in_queues;
402 qeth_free_qdio_queue(card->qdio.c_q);
403 card->qdio.c_q = NULL;
405 kfree(card->qdio.out_bufstates);
406 card->qdio.out_bufstates = NULL;
409 static inline enum iucv_tx_notify qeth_compute_cq_notification(int sbalf15,
410 int delayed) {
411 enum iucv_tx_notify n;
413 switch (sbalf15) {
414 case 0:
415 n = delayed ? TX_NOTIFY_DELAYED_OK : TX_NOTIFY_OK;
416 break;
417 case 4:
418 case 16:
419 case 17:
420 case 18:
421 n = delayed ? TX_NOTIFY_DELAYED_UNREACHABLE :
422 TX_NOTIFY_UNREACHABLE;
423 break;
424 default:
425 n = delayed ? TX_NOTIFY_DELAYED_GENERALERROR :
426 TX_NOTIFY_GENERALERROR;
427 break;
430 return n;
433 static inline void qeth_cleanup_handled_pending(struct qeth_qdio_out_q *q,
434 int bidx, int forced_cleanup)
436 if (q->card->options.cq != QETH_CQ_ENABLED)
437 return;
439 if (q->bufs[bidx]->next_pending != NULL) {
440 struct qeth_qdio_out_buffer *head = q->bufs[bidx];
441 struct qeth_qdio_out_buffer *c = q->bufs[bidx]->next_pending;
443 while (c) {
444 if (forced_cleanup ||
445 atomic_read(&c->state) ==
446 QETH_QDIO_BUF_HANDLED_DELAYED) {
447 struct qeth_qdio_out_buffer *f = c;
448 QETH_CARD_TEXT(f->q->card, 5, "fp");
449 QETH_CARD_TEXT_(f->q->card, 5, "%lx", (long) f);
450 /* release here to avoid interleaving between
451 outbound tasklet and inbound tasklet
452 regarding notifications and lifecycle */
453 qeth_release_skbs(c);
455 c = f->next_pending;
456 WARN_ON_ONCE(head->next_pending != f);
457 head->next_pending = c;
458 kmem_cache_free(qeth_qdio_outbuf_cache, f);
459 } else {
460 head = c;
461 c = c->next_pending;
466 if (forced_cleanup && (atomic_read(&(q->bufs[bidx]->state)) ==
467 QETH_QDIO_BUF_HANDLED_DELAYED)) {
468 /* for recovery situations */
469 q->bufs[bidx]->aob = q->bufstates[bidx].aob;
470 qeth_init_qdio_out_buf(q, bidx);
471 QETH_CARD_TEXT(q->card, 2, "clprecov");
476 static inline void qeth_qdio_handle_aob(struct qeth_card *card,
477 unsigned long phys_aob_addr) {
478 struct qaob *aob;
479 struct qeth_qdio_out_buffer *buffer;
480 enum iucv_tx_notify notification;
482 aob = (struct qaob *) phys_to_virt(phys_aob_addr);
483 QETH_CARD_TEXT(card, 5, "haob");
484 QETH_CARD_TEXT_(card, 5, "%lx", phys_aob_addr);
485 buffer = (struct qeth_qdio_out_buffer *) aob->user1;
486 QETH_CARD_TEXT_(card, 5, "%lx", aob->user1);
488 if (atomic_cmpxchg(&buffer->state, QETH_QDIO_BUF_PRIMED,
489 QETH_QDIO_BUF_IN_CQ) == QETH_QDIO_BUF_PRIMED) {
490 notification = TX_NOTIFY_OK;
491 } else {
492 WARN_ON_ONCE(atomic_read(&buffer->state) !=
493 QETH_QDIO_BUF_PENDING);
494 atomic_set(&buffer->state, QETH_QDIO_BUF_IN_CQ);
495 notification = TX_NOTIFY_DELAYED_OK;
498 if (aob->aorc != 0) {
499 QETH_CARD_TEXT_(card, 2, "aorc%02X", aob->aorc);
500 notification = qeth_compute_cq_notification(aob->aorc, 1);
502 qeth_notify_skbs(buffer->q, buffer, notification);
504 buffer->aob = NULL;
505 qeth_clear_output_buffer(buffer->q, buffer,
506 QETH_QDIO_BUF_HANDLED_DELAYED);
508 /* from here on: do not touch buffer anymore */
509 qdio_release_aob(aob);
512 static inline int qeth_is_cq(struct qeth_card *card, unsigned int queue)
514 return card->options.cq == QETH_CQ_ENABLED &&
515 card->qdio.c_q != NULL &&
516 queue != 0 &&
517 queue == card->qdio.no_in_queues - 1;
521 static int qeth_issue_next_read(struct qeth_card *card)
523 int rc;
524 struct qeth_cmd_buffer *iob;
526 QETH_CARD_TEXT(card, 5, "issnxrd");
527 if (card->read.state != CH_STATE_UP)
528 return -EIO;
529 iob = qeth_get_buffer(&card->read);
530 if (!iob) {
531 dev_warn(&card->gdev->dev, "The qeth device driver "
532 "failed to recover an error on the device\n");
533 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
534 "available\n", dev_name(&card->gdev->dev));
535 return -ENOMEM;
537 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
538 QETH_CARD_TEXT(card, 6, "noirqpnd");
539 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
540 (addr_t) iob, 0, 0);
541 if (rc) {
542 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
543 "rc=%i\n", dev_name(&card->gdev->dev), rc);
544 atomic_set(&card->read.irq_pending, 0);
545 card->read_or_write_problem = 1;
546 qeth_schedule_recovery(card);
547 wake_up(&card->wait_q);
549 return rc;
552 static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card)
554 struct qeth_reply *reply;
556 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
557 if (reply) {
558 atomic_set(&reply->refcnt, 1);
559 atomic_set(&reply->received, 0);
560 reply->card = card;
562 return reply;
565 static void qeth_get_reply(struct qeth_reply *reply)
567 WARN_ON(atomic_read(&reply->refcnt) <= 0);
568 atomic_inc(&reply->refcnt);
571 static void qeth_put_reply(struct qeth_reply *reply)
573 WARN_ON(atomic_read(&reply->refcnt) <= 0);
574 if (atomic_dec_and_test(&reply->refcnt))
575 kfree(reply);
578 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
579 struct qeth_card *card)
581 char *ipa_name;
582 int com = cmd->hdr.command;
583 ipa_name = qeth_get_ipa_cmd_name(com);
584 if (rc)
585 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s/%s returned "
586 "x%X \"%s\"\n",
587 ipa_name, com, dev_name(&card->gdev->dev),
588 QETH_CARD_IFNAME(card), rc,
589 qeth_get_ipa_msg(rc));
590 else
591 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s/%s succeeded\n",
592 ipa_name, com, dev_name(&card->gdev->dev),
593 QETH_CARD_IFNAME(card));
596 static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
597 struct qeth_cmd_buffer *iob)
599 struct qeth_ipa_cmd *cmd = NULL;
601 QETH_CARD_TEXT(card, 5, "chkipad");
602 if (IS_IPA(iob->data)) {
603 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
604 if (IS_IPA_REPLY(cmd)) {
605 if (cmd->hdr.command != IPA_CMD_SETCCID &&
606 cmd->hdr.command != IPA_CMD_DELCCID &&
607 cmd->hdr.command != IPA_CMD_MODCCID &&
608 cmd->hdr.command != IPA_CMD_SET_DIAG_ASS)
609 qeth_issue_ipa_msg(cmd,
610 cmd->hdr.return_code, card);
611 return cmd;
612 } else {
613 switch (cmd->hdr.command) {
614 case IPA_CMD_STOPLAN:
615 if (cmd->hdr.return_code ==
616 IPA_RC_VEPA_TO_VEB_TRANSITION) {
617 dev_err(&card->gdev->dev,
618 "Interface %s is down because the "
619 "adjacent port is no longer in "
620 "reflective relay mode\n",
621 QETH_CARD_IFNAME(card));
622 qeth_close_dev(card);
623 } else {
624 dev_warn(&card->gdev->dev,
625 "The link for interface %s on CHPID"
626 " 0x%X failed\n",
627 QETH_CARD_IFNAME(card),
628 card->info.chpid);
629 qeth_issue_ipa_msg(cmd,
630 cmd->hdr.return_code, card);
632 card->lan_online = 0;
633 if (card->dev && netif_carrier_ok(card->dev))
634 netif_carrier_off(card->dev);
635 return NULL;
636 case IPA_CMD_STARTLAN:
637 dev_info(&card->gdev->dev,
638 "The link for %s on CHPID 0x%X has"
639 " been restored\n",
640 QETH_CARD_IFNAME(card),
641 card->info.chpid);
642 netif_carrier_on(card->dev);
643 card->lan_online = 1;
644 if (card->info.hwtrap)
645 card->info.hwtrap = 2;
646 qeth_schedule_recovery(card);
647 return NULL;
648 case IPA_CMD_SETBRIDGEPORT_IQD:
649 case IPA_CMD_SETBRIDGEPORT_OSA:
650 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
651 if (card->discipline->control_event_handler
652 (card, cmd))
653 return cmd;
654 else
655 return NULL;
656 case IPA_CMD_MODCCID:
657 return cmd;
658 case IPA_CMD_REGISTER_LOCAL_ADDR:
659 QETH_CARD_TEXT(card, 3, "irla");
660 break;
661 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
662 QETH_CARD_TEXT(card, 3, "urla");
663 break;
664 default:
665 QETH_DBF_MESSAGE(2, "Received data is IPA "
666 "but not a reply!\n");
667 break;
671 return cmd;
674 void qeth_clear_ipacmd_list(struct qeth_card *card)
676 struct qeth_reply *reply, *r;
677 unsigned long flags;
679 QETH_CARD_TEXT(card, 4, "clipalst");
681 spin_lock_irqsave(&card->lock, flags);
682 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
683 qeth_get_reply(reply);
684 reply->rc = -EIO;
685 atomic_inc(&reply->received);
686 list_del_init(&reply->list);
687 wake_up(&reply->wait_q);
688 qeth_put_reply(reply);
690 spin_unlock_irqrestore(&card->lock, flags);
691 atomic_set(&card->write.irq_pending, 0);
693 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list);
695 static int qeth_check_idx_response(struct qeth_card *card,
696 unsigned char *buffer)
698 if (!buffer)
699 return 0;
701 QETH_DBF_HEX(CTRL, 2, buffer, QETH_DBF_CTRL_LEN);
702 if ((buffer[2] & 0xc0) == 0xc0) {
703 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
704 "with cause code 0x%02x%s\n",
705 buffer[4],
706 ((buffer[4] == 0x22) ?
707 " -- try another portname" : ""));
708 QETH_CARD_TEXT(card, 2, "ckidxres");
709 QETH_CARD_TEXT(card, 2, " idxterm");
710 QETH_CARD_TEXT_(card, 2, " rc%d", -EIO);
711 if (buffer[4] == 0xf6) {
712 dev_err(&card->gdev->dev,
713 "The qeth device is not configured "
714 "for the OSI layer required by z/VM\n");
715 return -EPERM;
717 return -EIO;
719 return 0;
722 static struct qeth_card *CARD_FROM_CDEV(struct ccw_device *cdev)
724 struct qeth_card *card = dev_get_drvdata(&((struct ccwgroup_device *)
725 dev_get_drvdata(&cdev->dev))->dev);
726 return card;
729 static void qeth_setup_ccw(struct qeth_channel *channel, unsigned char *iob,
730 __u32 len)
732 struct qeth_card *card;
734 card = CARD_FROM_CDEV(channel->ccwdev);
735 QETH_CARD_TEXT(card, 4, "setupccw");
736 if (channel == &card->read)
737 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
738 else
739 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
740 channel->ccw.count = len;
741 channel->ccw.cda = (__u32) __pa(iob);
744 static struct qeth_cmd_buffer *__qeth_get_buffer(struct qeth_channel *channel)
746 __u8 index;
748 QETH_CARD_TEXT(CARD_FROM_CDEV(channel->ccwdev), 6, "getbuff");
749 index = channel->io_buf_no;
750 do {
751 if (channel->iob[index].state == BUF_STATE_FREE) {
752 channel->iob[index].state = BUF_STATE_LOCKED;
753 channel->io_buf_no = (channel->io_buf_no + 1) %
754 QETH_CMD_BUFFER_NO;
755 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
756 return channel->iob + index;
758 index = (index + 1) % QETH_CMD_BUFFER_NO;
759 } while (index != channel->io_buf_no);
761 return NULL;
764 void qeth_release_buffer(struct qeth_channel *channel,
765 struct qeth_cmd_buffer *iob)
767 unsigned long flags;
769 QETH_CARD_TEXT(CARD_FROM_CDEV(channel->ccwdev), 6, "relbuff");
770 spin_lock_irqsave(&channel->iob_lock, flags);
771 memset(iob->data, 0, QETH_BUFSIZE);
772 iob->state = BUF_STATE_FREE;
773 iob->callback = qeth_send_control_data_cb;
774 iob->rc = 0;
775 spin_unlock_irqrestore(&channel->iob_lock, flags);
776 wake_up(&channel->wait_q);
778 EXPORT_SYMBOL_GPL(qeth_release_buffer);
780 static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *channel)
782 struct qeth_cmd_buffer *buffer = NULL;
783 unsigned long flags;
785 spin_lock_irqsave(&channel->iob_lock, flags);
786 buffer = __qeth_get_buffer(channel);
787 spin_unlock_irqrestore(&channel->iob_lock, flags);
788 return buffer;
791 struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *channel)
793 struct qeth_cmd_buffer *buffer;
794 wait_event(channel->wait_q,
795 ((buffer = qeth_get_buffer(channel)) != NULL));
796 return buffer;
798 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer);
800 void qeth_clear_cmd_buffers(struct qeth_channel *channel)
802 int cnt;
804 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
805 qeth_release_buffer(channel, &channel->iob[cnt]);
806 channel->buf_no = 0;
807 channel->io_buf_no = 0;
809 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers);
811 static void qeth_send_control_data_cb(struct qeth_channel *channel,
812 struct qeth_cmd_buffer *iob)
814 struct qeth_card *card;
815 struct qeth_reply *reply, *r;
816 struct qeth_ipa_cmd *cmd;
817 unsigned long flags;
818 int keep_reply;
819 int rc = 0;
821 card = CARD_FROM_CDEV(channel->ccwdev);
822 QETH_CARD_TEXT(card, 4, "sndctlcb");
823 rc = qeth_check_idx_response(card, iob->data);
824 switch (rc) {
825 case 0:
826 break;
827 case -EIO:
828 qeth_clear_ipacmd_list(card);
829 qeth_schedule_recovery(card);
830 /* fall through */
831 default:
832 goto out;
835 cmd = qeth_check_ipa_data(card, iob);
836 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
837 goto out;
838 /*in case of OSN : check if cmd is set */
839 if (card->info.type == QETH_CARD_TYPE_OSN &&
840 cmd &&
841 cmd->hdr.command != IPA_CMD_STARTLAN &&
842 card->osn_info.assist_cb != NULL) {
843 card->osn_info.assist_cb(card->dev, cmd);
844 goto out;
847 spin_lock_irqsave(&card->lock, flags);
848 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
849 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
850 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
851 qeth_get_reply(reply);
852 list_del_init(&reply->list);
853 spin_unlock_irqrestore(&card->lock, flags);
854 keep_reply = 0;
855 if (reply->callback != NULL) {
856 if (cmd) {
857 reply->offset = (__u16)((char *)cmd -
858 (char *)iob->data);
859 keep_reply = reply->callback(card,
860 reply,
861 (unsigned long)cmd);
862 } else
863 keep_reply = reply->callback(card,
864 reply,
865 (unsigned long)iob);
867 if (cmd)
868 reply->rc = (u16) cmd->hdr.return_code;
869 else if (iob->rc)
870 reply->rc = iob->rc;
871 if (keep_reply) {
872 spin_lock_irqsave(&card->lock, flags);
873 list_add_tail(&reply->list,
874 &card->cmd_waiter_list);
875 spin_unlock_irqrestore(&card->lock, flags);
876 } else {
877 atomic_inc(&reply->received);
878 wake_up(&reply->wait_q);
880 qeth_put_reply(reply);
881 goto out;
884 spin_unlock_irqrestore(&card->lock, flags);
885 out:
886 memcpy(&card->seqno.pdu_hdr_ack,
887 QETH_PDU_HEADER_SEQ_NO(iob->data),
888 QETH_SEQ_NO_LENGTH);
889 qeth_release_buffer(channel, iob);
892 static int qeth_setup_channel(struct qeth_channel *channel)
894 int cnt;
896 QETH_DBF_TEXT(SETUP, 2, "setupch");
897 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
898 channel->iob[cnt].data =
899 kzalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
900 if (channel->iob[cnt].data == NULL)
901 break;
902 channel->iob[cnt].state = BUF_STATE_FREE;
903 channel->iob[cnt].channel = channel;
904 channel->iob[cnt].callback = qeth_send_control_data_cb;
905 channel->iob[cnt].rc = 0;
907 if (cnt < QETH_CMD_BUFFER_NO) {
908 while (cnt-- > 0)
909 kfree(channel->iob[cnt].data);
910 return -ENOMEM;
912 channel->buf_no = 0;
913 channel->io_buf_no = 0;
914 atomic_set(&channel->irq_pending, 0);
915 spin_lock_init(&channel->iob_lock);
917 init_waitqueue_head(&channel->wait_q);
918 return 0;
921 static int qeth_set_thread_start_bit(struct qeth_card *card,
922 unsigned long thread)
924 unsigned long flags;
926 spin_lock_irqsave(&card->thread_mask_lock, flags);
927 if (!(card->thread_allowed_mask & thread) ||
928 (card->thread_start_mask & thread)) {
929 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
930 return -EPERM;
932 card->thread_start_mask |= thread;
933 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
934 return 0;
937 void qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
939 unsigned long flags;
941 spin_lock_irqsave(&card->thread_mask_lock, flags);
942 card->thread_start_mask &= ~thread;
943 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
944 wake_up(&card->wait_q);
946 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit);
948 void qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
950 unsigned long flags;
952 spin_lock_irqsave(&card->thread_mask_lock, flags);
953 card->thread_running_mask &= ~thread;
954 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
955 wake_up(&card->wait_q);
957 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit);
959 static int __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
961 unsigned long flags;
962 int rc = 0;
964 spin_lock_irqsave(&card->thread_mask_lock, flags);
965 if (card->thread_start_mask & thread) {
966 if ((card->thread_allowed_mask & thread) &&
967 !(card->thread_running_mask & thread)) {
968 rc = 1;
969 card->thread_start_mask &= ~thread;
970 card->thread_running_mask |= thread;
971 } else
972 rc = -EPERM;
974 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
975 return rc;
978 int qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
980 int rc = 0;
982 wait_event(card->wait_q,
983 (rc = __qeth_do_run_thread(card, thread)) >= 0);
984 return rc;
986 EXPORT_SYMBOL_GPL(qeth_do_run_thread);
988 void qeth_schedule_recovery(struct qeth_card *card)
990 QETH_CARD_TEXT(card, 2, "startrec");
991 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
992 schedule_work(&card->kernel_thread_starter);
994 EXPORT_SYMBOL_GPL(qeth_schedule_recovery);
996 static int qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
998 int dstat, cstat;
999 char *sense;
1000 struct qeth_card *card;
1002 sense = (char *) irb->ecw;
1003 cstat = irb->scsw.cmd.cstat;
1004 dstat = irb->scsw.cmd.dstat;
1005 card = CARD_FROM_CDEV(cdev);
1007 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
1008 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
1009 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
1010 QETH_CARD_TEXT(card, 2, "CGENCHK");
1011 dev_warn(&cdev->dev, "The qeth device driver "
1012 "failed to recover an error on the device\n");
1013 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x\n",
1014 dev_name(&cdev->dev), dstat, cstat);
1015 print_hex_dump(KERN_WARNING, "qeth: irb ", DUMP_PREFIX_OFFSET,
1016 16, 1, irb, 64, 1);
1017 return 1;
1020 if (dstat & DEV_STAT_UNIT_CHECK) {
1021 if (sense[SENSE_RESETTING_EVENT_BYTE] &
1022 SENSE_RESETTING_EVENT_FLAG) {
1023 QETH_CARD_TEXT(card, 2, "REVIND");
1024 return 1;
1026 if (sense[SENSE_COMMAND_REJECT_BYTE] &
1027 SENSE_COMMAND_REJECT_FLAG) {
1028 QETH_CARD_TEXT(card, 2, "CMDREJi");
1029 return 1;
1031 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
1032 QETH_CARD_TEXT(card, 2, "AFFE");
1033 return 1;
1035 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
1036 QETH_CARD_TEXT(card, 2, "ZEROSEN");
1037 return 0;
1039 QETH_CARD_TEXT(card, 2, "DGENCHK");
1040 return 1;
1042 return 0;
1045 static long __qeth_check_irb_error(struct ccw_device *cdev,
1046 unsigned long intparm, struct irb *irb)
1048 struct qeth_card *card;
1050 card = CARD_FROM_CDEV(cdev);
1052 if (!card || !IS_ERR(irb))
1053 return 0;
1055 switch (PTR_ERR(irb)) {
1056 case -EIO:
1057 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
1058 dev_name(&cdev->dev));
1059 QETH_CARD_TEXT(card, 2, "ckirberr");
1060 QETH_CARD_TEXT_(card, 2, " rc%d", -EIO);
1061 break;
1062 case -ETIMEDOUT:
1063 dev_warn(&cdev->dev, "A hardware operation timed out"
1064 " on the device\n");
1065 QETH_CARD_TEXT(card, 2, "ckirberr");
1066 QETH_CARD_TEXT_(card, 2, " rc%d", -ETIMEDOUT);
1067 if (intparm == QETH_RCD_PARM) {
1068 if (card->data.ccwdev == cdev) {
1069 card->data.state = CH_STATE_DOWN;
1070 wake_up(&card->wait_q);
1073 break;
1074 default:
1075 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
1076 dev_name(&cdev->dev), PTR_ERR(irb));
1077 QETH_CARD_TEXT(card, 2, "ckirberr");
1078 QETH_CARD_TEXT(card, 2, " rc???");
1080 return PTR_ERR(irb);
1083 static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1084 struct irb *irb)
1086 int rc;
1087 int cstat, dstat;
1088 struct qeth_cmd_buffer *buffer;
1089 struct qeth_channel *channel;
1090 struct qeth_card *card;
1091 struct qeth_cmd_buffer *iob;
1092 __u8 index;
1094 if (__qeth_check_irb_error(cdev, intparm, irb))
1095 return;
1096 cstat = irb->scsw.cmd.cstat;
1097 dstat = irb->scsw.cmd.dstat;
1099 card = CARD_FROM_CDEV(cdev);
1100 if (!card)
1101 return;
1103 QETH_CARD_TEXT(card, 5, "irq");
1105 if (card->read.ccwdev == cdev) {
1106 channel = &card->read;
1107 QETH_CARD_TEXT(card, 5, "read");
1108 } else if (card->write.ccwdev == cdev) {
1109 channel = &card->write;
1110 QETH_CARD_TEXT(card, 5, "write");
1111 } else {
1112 channel = &card->data;
1113 QETH_CARD_TEXT(card, 5, "data");
1115 atomic_set(&channel->irq_pending, 0);
1117 if (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC))
1118 channel->state = CH_STATE_STOPPED;
1120 if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC))
1121 channel->state = CH_STATE_HALTED;
1123 /*let's wake up immediately on data channel*/
1124 if ((channel == &card->data) && (intparm != 0) &&
1125 (intparm != QETH_RCD_PARM))
1126 goto out;
1128 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
1129 QETH_CARD_TEXT(card, 6, "clrchpar");
1130 /* we don't have to handle this further */
1131 intparm = 0;
1133 if (intparm == QETH_HALT_CHANNEL_PARM) {
1134 QETH_CARD_TEXT(card, 6, "hltchpar");
1135 /* we don't have to handle this further */
1136 intparm = 0;
1138 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
1139 (dstat & DEV_STAT_UNIT_CHECK) ||
1140 (cstat)) {
1141 if (irb->esw.esw0.erw.cons) {
1142 dev_warn(&channel->ccwdev->dev,
1143 "The qeth device driver failed to recover "
1144 "an error on the device\n");
1145 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
1146 "0x%X dstat 0x%X\n",
1147 dev_name(&channel->ccwdev->dev), cstat, dstat);
1148 print_hex_dump(KERN_WARNING, "qeth: irb ",
1149 DUMP_PREFIX_OFFSET, 16, 1, irb, 32, 1);
1150 print_hex_dump(KERN_WARNING, "qeth: sense data ",
1151 DUMP_PREFIX_OFFSET, 16, 1, irb->ecw, 32, 1);
1153 if (intparm == QETH_RCD_PARM) {
1154 channel->state = CH_STATE_DOWN;
1155 goto out;
1157 rc = qeth_get_problem(cdev, irb);
1158 if (rc) {
1159 qeth_clear_ipacmd_list(card);
1160 qeth_schedule_recovery(card);
1161 goto out;
1165 if (intparm == QETH_RCD_PARM) {
1166 channel->state = CH_STATE_RCD_DONE;
1167 goto out;
1169 if (intparm) {
1170 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
1171 buffer->state = BUF_STATE_PROCESSED;
1173 if (channel == &card->data)
1174 return;
1175 if (channel == &card->read &&
1176 channel->state == CH_STATE_UP)
1177 qeth_issue_next_read(card);
1179 iob = channel->iob;
1180 index = channel->buf_no;
1181 while (iob[index].state == BUF_STATE_PROCESSED) {
1182 if (iob[index].callback != NULL)
1183 iob[index].callback(channel, iob + index);
1185 index = (index + 1) % QETH_CMD_BUFFER_NO;
1187 channel->buf_no = index;
1188 out:
1189 wake_up(&card->wait_q);
1190 return;
1193 static void qeth_notify_skbs(struct qeth_qdio_out_q *q,
1194 struct qeth_qdio_out_buffer *buf,
1195 enum iucv_tx_notify notification)
1197 struct sk_buff *skb;
1199 if (skb_queue_empty(&buf->skb_list))
1200 goto out;
1201 skb = skb_peek(&buf->skb_list);
1202 while (skb) {
1203 QETH_CARD_TEXT_(q->card, 5, "skbn%d", notification);
1204 QETH_CARD_TEXT_(q->card, 5, "%lx", (long) skb);
1205 if (skb->protocol == ETH_P_AF_IUCV) {
1206 if (skb->sk) {
1207 struct iucv_sock *iucv = iucv_sk(skb->sk);
1208 iucv->sk_txnotify(skb, notification);
1211 if (skb_queue_is_last(&buf->skb_list, skb))
1212 skb = NULL;
1213 else
1214 skb = skb_queue_next(&buf->skb_list, skb);
1216 out:
1217 return;
1220 static void qeth_release_skbs(struct qeth_qdio_out_buffer *buf)
1222 struct sk_buff *skb;
1223 struct iucv_sock *iucv;
1224 int notify_general_error = 0;
1226 if (atomic_read(&buf->state) == QETH_QDIO_BUF_PENDING)
1227 notify_general_error = 1;
1229 /* release may never happen from within CQ tasklet scope */
1230 WARN_ON_ONCE(atomic_read(&buf->state) == QETH_QDIO_BUF_IN_CQ);
1232 skb = skb_dequeue(&buf->skb_list);
1233 while (skb) {
1234 QETH_CARD_TEXT(buf->q->card, 5, "skbr");
1235 QETH_CARD_TEXT_(buf->q->card, 5, "%lx", (long) skb);
1236 if (notify_general_error && skb->protocol == ETH_P_AF_IUCV) {
1237 if (skb->sk) {
1238 iucv = iucv_sk(skb->sk);
1239 iucv->sk_txnotify(skb, TX_NOTIFY_GENERALERROR);
1242 atomic_dec(&skb->users);
1243 dev_kfree_skb_any(skb);
1244 skb = skb_dequeue(&buf->skb_list);
1248 static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
1249 struct qeth_qdio_out_buffer *buf,
1250 enum qeth_qdio_buffer_states newbufstate)
1252 int i;
1254 /* is PCI flag set on buffer? */
1255 if (buf->buffer->element[0].sflags & SBAL_SFLAGS0_PCI_REQ)
1256 atomic_dec(&queue->set_pci_flags_count);
1258 if (newbufstate == QETH_QDIO_BUF_EMPTY) {
1259 qeth_release_skbs(buf);
1261 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i) {
1262 if (buf->buffer->element[i].addr && buf->is_header[i])
1263 kmem_cache_free(qeth_core_header_cache,
1264 buf->buffer->element[i].addr);
1265 buf->is_header[i] = 0;
1266 buf->buffer->element[i].length = 0;
1267 buf->buffer->element[i].addr = NULL;
1268 buf->buffer->element[i].eflags = 0;
1269 buf->buffer->element[i].sflags = 0;
1271 buf->buffer->element[15].eflags = 0;
1272 buf->buffer->element[15].sflags = 0;
1273 buf->next_element_to_fill = 0;
1274 atomic_set(&buf->state, newbufstate);
1277 static void qeth_clear_outq_buffers(struct qeth_qdio_out_q *q, int free)
1279 int j;
1281 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
1282 if (!q->bufs[j])
1283 continue;
1284 qeth_cleanup_handled_pending(q, j, 1);
1285 qeth_clear_output_buffer(q, q->bufs[j], QETH_QDIO_BUF_EMPTY);
1286 if (free) {
1287 kmem_cache_free(qeth_qdio_outbuf_cache, q->bufs[j]);
1288 q->bufs[j] = NULL;
1293 void qeth_clear_qdio_buffers(struct qeth_card *card)
1295 int i;
1297 QETH_CARD_TEXT(card, 2, "clearqdbf");
1298 /* clear outbound buffers to free skbs */
1299 for (i = 0; i < card->qdio.no_out_queues; ++i) {
1300 if (card->qdio.out_qs[i]) {
1301 qeth_clear_outq_buffers(card->qdio.out_qs[i], 0);
1305 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers);
1307 static void qeth_free_buffer_pool(struct qeth_card *card)
1309 struct qeth_buffer_pool_entry *pool_entry, *tmp;
1310 int i = 0;
1311 list_for_each_entry_safe(pool_entry, tmp,
1312 &card->qdio.init_pool.entry_list, init_list){
1313 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
1314 free_page((unsigned long)pool_entry->elements[i]);
1315 list_del(&pool_entry->init_list);
1316 kfree(pool_entry);
1320 static void qeth_clean_channel(struct qeth_channel *channel)
1322 int cnt;
1324 QETH_DBF_TEXT(SETUP, 2, "freech");
1325 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1326 kfree(channel->iob[cnt].data);
1329 static void qeth_set_single_write_queues(struct qeth_card *card)
1331 if ((atomic_read(&card->qdio.state) != QETH_QDIO_UNINITIALIZED) &&
1332 (card->qdio.no_out_queues == 4))
1333 qeth_free_qdio_buffers(card);
1335 card->qdio.no_out_queues = 1;
1336 if (card->qdio.default_out_queue != 0)
1337 dev_info(&card->gdev->dev, "Priority Queueing not supported\n");
1339 card->qdio.default_out_queue = 0;
1342 static void qeth_set_multiple_write_queues(struct qeth_card *card)
1344 if ((atomic_read(&card->qdio.state) != QETH_QDIO_UNINITIALIZED) &&
1345 (card->qdio.no_out_queues == 1)) {
1346 qeth_free_qdio_buffers(card);
1347 card->qdio.default_out_queue = 2;
1349 card->qdio.no_out_queues = 4;
1352 static void qeth_update_from_chp_desc(struct qeth_card *card)
1354 struct ccw_device *ccwdev;
1355 struct channel_path_desc *chp_dsc;
1357 QETH_DBF_TEXT(SETUP, 2, "chp_desc");
1359 ccwdev = card->data.ccwdev;
1360 chp_dsc = ccw_device_get_chp_desc(ccwdev, 0);
1361 if (!chp_dsc)
1362 goto out;
1364 card->info.func_level = 0x4100 + chp_dsc->desc;
1365 if (card->info.type == QETH_CARD_TYPE_IQD)
1366 goto out;
1368 /* CHPP field bit 6 == 1 -> single queue */
1369 if ((chp_dsc->chpp & 0x02) == 0x02)
1370 qeth_set_single_write_queues(card);
1371 else
1372 qeth_set_multiple_write_queues(card);
1373 out:
1374 kfree(chp_dsc);
1375 QETH_DBF_TEXT_(SETUP, 2, "nr:%x", card->qdio.no_out_queues);
1376 QETH_DBF_TEXT_(SETUP, 2, "lvl:%02x", card->info.func_level);
1379 static void qeth_init_qdio_info(struct qeth_card *card)
1381 QETH_DBF_TEXT(SETUP, 4, "intqdinf");
1382 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
1383 /* inbound */
1384 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1385 if (card->info.type == QETH_CARD_TYPE_IQD)
1386 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_HSDEFAULT;
1387 else
1388 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
1389 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
1390 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
1391 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
1394 static void qeth_set_intial_options(struct qeth_card *card)
1396 card->options.route4.type = NO_ROUTER;
1397 card->options.route6.type = NO_ROUTER;
1398 card->options.fake_broadcast = 0;
1399 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1400 card->options.performance_stats = 0;
1401 card->options.rx_sg_cb = QETH_RX_SG_CB;
1402 card->options.isolation = ISOLATION_MODE_NONE;
1403 card->options.cq = QETH_CQ_DISABLED;
1406 static int qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1408 unsigned long flags;
1409 int rc = 0;
1411 spin_lock_irqsave(&card->thread_mask_lock, flags);
1412 QETH_CARD_TEXT_(card, 4, " %02x%02x%02x",
1413 (u8) card->thread_start_mask,
1414 (u8) card->thread_allowed_mask,
1415 (u8) card->thread_running_mask);
1416 rc = (card->thread_start_mask & thread);
1417 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1418 return rc;
1421 static void qeth_start_kernel_thread(struct work_struct *work)
1423 struct task_struct *ts;
1424 struct qeth_card *card = container_of(work, struct qeth_card,
1425 kernel_thread_starter);
1426 QETH_CARD_TEXT(card , 2, "strthrd");
1428 if (card->read.state != CH_STATE_UP &&
1429 card->write.state != CH_STATE_UP)
1430 return;
1431 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD)) {
1432 ts = kthread_run(card->discipline->recover, (void *)card,
1433 "qeth_recover");
1434 if (IS_ERR(ts)) {
1435 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1436 qeth_clear_thread_running_bit(card,
1437 QETH_RECOVER_THREAD);
1442 static void qeth_buffer_reclaim_work(struct work_struct *);
1443 static int qeth_setup_card(struct qeth_card *card)
1446 QETH_DBF_TEXT(SETUP, 2, "setupcrd");
1447 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1449 card->read.state = CH_STATE_DOWN;
1450 card->write.state = CH_STATE_DOWN;
1451 card->data.state = CH_STATE_DOWN;
1452 card->state = CARD_STATE_DOWN;
1453 card->lan_online = 0;
1454 card->read_or_write_problem = 0;
1455 card->dev = NULL;
1456 spin_lock_init(&card->vlanlock);
1457 spin_lock_init(&card->mclock);
1458 spin_lock_init(&card->lock);
1459 spin_lock_init(&card->ip_lock);
1460 spin_lock_init(&card->thread_mask_lock);
1461 mutex_init(&card->conf_mutex);
1462 mutex_init(&card->discipline_mutex);
1463 card->thread_start_mask = 0;
1464 card->thread_allowed_mask = 0;
1465 card->thread_running_mask = 0;
1466 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1467 INIT_LIST_HEAD(&card->cmd_waiter_list);
1468 init_waitqueue_head(&card->wait_q);
1469 /* initial options */
1470 qeth_set_intial_options(card);
1471 /* IP address takeover */
1472 INIT_LIST_HEAD(&card->ipato.entries);
1473 card->ipato.enabled = 0;
1474 card->ipato.invert4 = 0;
1475 card->ipato.invert6 = 0;
1476 /* init QDIO stuff */
1477 qeth_init_qdio_info(card);
1478 INIT_DELAYED_WORK(&card->buffer_reclaim_work, qeth_buffer_reclaim_work);
1479 INIT_WORK(&card->close_dev_work, qeth_close_dev_handler);
1480 return 0;
1483 static void qeth_core_sl_print(struct seq_file *m, struct service_level *slr)
1485 struct qeth_card *card = container_of(slr, struct qeth_card,
1486 qeth_service_level);
1487 if (card->info.mcl_level[0])
1488 seq_printf(m, "qeth: %s firmware level %s\n",
1489 CARD_BUS_ID(card), card->info.mcl_level);
1492 static struct qeth_card *qeth_alloc_card(void)
1494 struct qeth_card *card;
1496 QETH_DBF_TEXT(SETUP, 2, "alloccrd");
1497 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
1498 if (!card)
1499 goto out;
1500 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1501 if (qeth_setup_channel(&card->read))
1502 goto out_ip;
1503 if (qeth_setup_channel(&card->write))
1504 goto out_channel;
1505 card->options.layer2 = -1;
1506 card->qeth_service_level.seq_print = qeth_core_sl_print;
1507 register_service_level(&card->qeth_service_level);
1508 return card;
1510 out_channel:
1511 qeth_clean_channel(&card->read);
1512 out_ip:
1513 kfree(card);
1514 out:
1515 return NULL;
1518 static int qeth_determine_card_type(struct qeth_card *card)
1520 int i = 0;
1522 QETH_DBF_TEXT(SETUP, 2, "detcdtyp");
1524 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1525 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1526 while (known_devices[i][QETH_DEV_MODEL_IND]) {
1527 if ((CARD_RDEV(card)->id.dev_type ==
1528 known_devices[i][QETH_DEV_TYPE_IND]) &&
1529 (CARD_RDEV(card)->id.dev_model ==
1530 known_devices[i][QETH_DEV_MODEL_IND])) {
1531 card->info.type = known_devices[i][QETH_DEV_MODEL_IND];
1532 card->qdio.no_out_queues =
1533 known_devices[i][QETH_QUEUE_NO_IND];
1534 card->qdio.no_in_queues = 1;
1535 card->info.is_multicast_different =
1536 known_devices[i][QETH_MULTICAST_IND];
1537 qeth_update_from_chp_desc(card);
1538 return 0;
1540 i++;
1542 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1543 dev_err(&card->gdev->dev, "The adapter hardware is of an "
1544 "unknown type\n");
1545 return -ENOENT;
1548 static int qeth_clear_channel(struct qeth_channel *channel)
1550 unsigned long flags;
1551 struct qeth_card *card;
1552 int rc;
1554 card = CARD_FROM_CDEV(channel->ccwdev);
1555 QETH_CARD_TEXT(card, 3, "clearch");
1556 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1557 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
1558 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1560 if (rc)
1561 return rc;
1562 rc = wait_event_interruptible_timeout(card->wait_q,
1563 channel->state == CH_STATE_STOPPED, QETH_TIMEOUT);
1564 if (rc == -ERESTARTSYS)
1565 return rc;
1566 if (channel->state != CH_STATE_STOPPED)
1567 return -ETIME;
1568 channel->state = CH_STATE_DOWN;
1569 return 0;
1572 static int qeth_halt_channel(struct qeth_channel *channel)
1574 unsigned long flags;
1575 struct qeth_card *card;
1576 int rc;
1578 card = CARD_FROM_CDEV(channel->ccwdev);
1579 QETH_CARD_TEXT(card, 3, "haltch");
1580 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1581 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
1582 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1584 if (rc)
1585 return rc;
1586 rc = wait_event_interruptible_timeout(card->wait_q,
1587 channel->state == CH_STATE_HALTED, QETH_TIMEOUT);
1588 if (rc == -ERESTARTSYS)
1589 return rc;
1590 if (channel->state != CH_STATE_HALTED)
1591 return -ETIME;
1592 return 0;
1595 static int qeth_halt_channels(struct qeth_card *card)
1597 int rc1 = 0, rc2 = 0, rc3 = 0;
1599 QETH_CARD_TEXT(card, 3, "haltchs");
1600 rc1 = qeth_halt_channel(&card->read);
1601 rc2 = qeth_halt_channel(&card->write);
1602 rc3 = qeth_halt_channel(&card->data);
1603 if (rc1)
1604 return rc1;
1605 if (rc2)
1606 return rc2;
1607 return rc3;
1610 static int qeth_clear_channels(struct qeth_card *card)
1612 int rc1 = 0, rc2 = 0, rc3 = 0;
1614 QETH_CARD_TEXT(card, 3, "clearchs");
1615 rc1 = qeth_clear_channel(&card->read);
1616 rc2 = qeth_clear_channel(&card->write);
1617 rc3 = qeth_clear_channel(&card->data);
1618 if (rc1)
1619 return rc1;
1620 if (rc2)
1621 return rc2;
1622 return rc3;
1625 static int qeth_clear_halt_card(struct qeth_card *card, int halt)
1627 int rc = 0;
1629 QETH_CARD_TEXT(card, 3, "clhacrd");
1631 if (halt)
1632 rc = qeth_halt_channels(card);
1633 if (rc)
1634 return rc;
1635 return qeth_clear_channels(card);
1638 int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
1640 int rc = 0;
1642 QETH_CARD_TEXT(card, 3, "qdioclr");
1643 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
1644 QETH_QDIO_CLEANING)) {
1645 case QETH_QDIO_ESTABLISHED:
1646 if (card->info.type == QETH_CARD_TYPE_IQD)
1647 rc = qdio_shutdown(CARD_DDEV(card),
1648 QDIO_FLAG_CLEANUP_USING_HALT);
1649 else
1650 rc = qdio_shutdown(CARD_DDEV(card),
1651 QDIO_FLAG_CLEANUP_USING_CLEAR);
1652 if (rc)
1653 QETH_CARD_TEXT_(card, 3, "1err%d", rc);
1654 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
1655 break;
1656 case QETH_QDIO_CLEANING:
1657 return rc;
1658 default:
1659 break;
1661 rc = qeth_clear_halt_card(card, use_halt);
1662 if (rc)
1663 QETH_CARD_TEXT_(card, 3, "2err%d", rc);
1664 card->state = CARD_STATE_DOWN;
1665 return rc;
1667 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card);
1669 static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
1670 int *length)
1672 struct ciw *ciw;
1673 char *rcd_buf;
1674 int ret;
1675 struct qeth_channel *channel = &card->data;
1676 unsigned long flags;
1679 * scan for RCD command in extended SenseID data
1681 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
1682 if (!ciw || ciw->cmd == 0)
1683 return -EOPNOTSUPP;
1684 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
1685 if (!rcd_buf)
1686 return -ENOMEM;
1688 channel->ccw.cmd_code = ciw->cmd;
1689 channel->ccw.cda = (__u32) __pa(rcd_buf);
1690 channel->ccw.count = ciw->count;
1691 channel->ccw.flags = CCW_FLAG_SLI;
1692 channel->state = CH_STATE_RCD;
1693 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1694 ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1695 QETH_RCD_PARM, LPM_ANYPATH, 0,
1696 QETH_RCD_TIMEOUT);
1697 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1698 if (!ret)
1699 wait_event(card->wait_q,
1700 (channel->state == CH_STATE_RCD_DONE ||
1701 channel->state == CH_STATE_DOWN));
1702 if (channel->state == CH_STATE_DOWN)
1703 ret = -EIO;
1704 else
1705 channel->state = CH_STATE_DOWN;
1706 if (ret) {
1707 kfree(rcd_buf);
1708 *buffer = NULL;
1709 *length = 0;
1710 } else {
1711 *length = ciw->count;
1712 *buffer = rcd_buf;
1714 return ret;
1717 static void qeth_configure_unitaddr(struct qeth_card *card, char *prcd)
1719 QETH_DBF_TEXT(SETUP, 2, "cfgunit");
1720 card->info.chpid = prcd[30];
1721 card->info.unit_addr2 = prcd[31];
1722 card->info.cula = prcd[63];
1723 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1724 (prcd[0x11] == _ascebc['M']));
1727 static void qeth_configure_blkt_default(struct qeth_card *card, char *prcd)
1729 QETH_DBF_TEXT(SETUP, 2, "cfgblkt");
1731 if (prcd[74] == 0xF0 && prcd[75] == 0xF0 &&
1732 prcd[76] >= 0xF1 && prcd[76] <= 0xF4) {
1733 card->info.blkt.time_total = 0;
1734 card->info.blkt.inter_packet = 0;
1735 card->info.blkt.inter_packet_jumbo = 0;
1736 } else {
1737 card->info.blkt.time_total = 250;
1738 card->info.blkt.inter_packet = 5;
1739 card->info.blkt.inter_packet_jumbo = 15;
1743 static void qeth_init_tokens(struct qeth_card *card)
1745 card->token.issuer_rm_w = 0x00010103UL;
1746 card->token.cm_filter_w = 0x00010108UL;
1747 card->token.cm_connection_w = 0x0001010aUL;
1748 card->token.ulp_filter_w = 0x0001010bUL;
1749 card->token.ulp_connection_w = 0x0001010dUL;
1752 static void qeth_init_func_level(struct qeth_card *card)
1754 switch (card->info.type) {
1755 case QETH_CARD_TYPE_IQD:
1756 card->info.func_level = QETH_IDX_FUNC_LEVEL_IQD;
1757 break;
1758 case QETH_CARD_TYPE_OSD:
1759 case QETH_CARD_TYPE_OSN:
1760 card->info.func_level = QETH_IDX_FUNC_LEVEL_OSD;
1761 break;
1762 default:
1763 break;
1767 static int qeth_idx_activate_get_answer(struct qeth_channel *channel,
1768 void (*idx_reply_cb)(struct qeth_channel *,
1769 struct qeth_cmd_buffer *))
1771 struct qeth_cmd_buffer *iob;
1772 unsigned long flags;
1773 int rc;
1774 struct qeth_card *card;
1776 QETH_DBF_TEXT(SETUP, 2, "idxanswr");
1777 card = CARD_FROM_CDEV(channel->ccwdev);
1778 iob = qeth_get_buffer(channel);
1779 if (!iob)
1780 return -ENOMEM;
1781 iob->callback = idx_reply_cb;
1782 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1783 channel->ccw.count = QETH_BUFSIZE;
1784 channel->ccw.cda = (__u32) __pa(iob->data);
1786 wait_event(card->wait_q,
1787 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1788 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1789 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1790 rc = ccw_device_start(channel->ccwdev,
1791 &channel->ccw, (addr_t) iob, 0, 0);
1792 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1794 if (rc) {
1795 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc);
1796 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
1797 atomic_set(&channel->irq_pending, 0);
1798 wake_up(&card->wait_q);
1799 return rc;
1801 rc = wait_event_interruptible_timeout(card->wait_q,
1802 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1803 if (rc == -ERESTARTSYS)
1804 return rc;
1805 if (channel->state != CH_STATE_UP) {
1806 rc = -ETIME;
1807 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
1808 qeth_clear_cmd_buffers(channel);
1809 } else
1810 rc = 0;
1811 return rc;
1814 static int qeth_idx_activate_channel(struct qeth_channel *channel,
1815 void (*idx_reply_cb)(struct qeth_channel *,
1816 struct qeth_cmd_buffer *))
1818 struct qeth_card *card;
1819 struct qeth_cmd_buffer *iob;
1820 unsigned long flags;
1821 __u16 temp;
1822 __u8 tmp;
1823 int rc;
1824 struct ccw_dev_id temp_devid;
1826 card = CARD_FROM_CDEV(channel->ccwdev);
1828 QETH_DBF_TEXT(SETUP, 2, "idxactch");
1830 iob = qeth_get_buffer(channel);
1831 if (!iob)
1832 return -ENOMEM;
1833 iob->callback = idx_reply_cb;
1834 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1835 channel->ccw.count = IDX_ACTIVATE_SIZE;
1836 channel->ccw.cda = (__u32) __pa(iob->data);
1837 if (channel == &card->write) {
1838 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1839 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1840 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1841 card->seqno.trans_hdr++;
1842 } else {
1843 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1844 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1845 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1847 tmp = ((__u8)card->info.portno) | 0x80;
1848 memcpy(QETH_IDX_ACT_PNO(iob->data), &tmp, 1);
1849 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1850 &card->token.issuer_rm_w, QETH_MPC_TOKEN_LENGTH);
1851 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1852 &card->info.func_level, sizeof(__u16));
1853 ccw_device_get_id(CARD_DDEV(card), &temp_devid);
1854 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp_devid.devno, 2);
1855 temp = (card->info.cula << 8) + card->info.unit_addr2;
1856 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1858 wait_event(card->wait_q,
1859 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1860 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1861 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1862 rc = ccw_device_start(channel->ccwdev,
1863 &channel->ccw, (addr_t) iob, 0, 0);
1864 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1866 if (rc) {
1867 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1868 rc);
1869 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1870 atomic_set(&channel->irq_pending, 0);
1871 wake_up(&card->wait_q);
1872 return rc;
1874 rc = wait_event_interruptible_timeout(card->wait_q,
1875 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1876 if (rc == -ERESTARTSYS)
1877 return rc;
1878 if (channel->state != CH_STATE_ACTIVATING) {
1879 dev_warn(&channel->ccwdev->dev, "The qeth device driver"
1880 " failed to recover an error on the device\n");
1881 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1882 dev_name(&channel->ccwdev->dev));
1883 QETH_DBF_TEXT_(SETUP, 2, "2err%d", -ETIME);
1884 qeth_clear_cmd_buffers(channel);
1885 return -ETIME;
1887 return qeth_idx_activate_get_answer(channel, idx_reply_cb);
1890 static int qeth_peer_func_level(int level)
1892 if ((level & 0xff) == 8)
1893 return (level & 0xff) + 0x400;
1894 if (((level >> 8) & 3) == 1)
1895 return (level & 0xff) + 0x200;
1896 return level;
1899 static void qeth_idx_write_cb(struct qeth_channel *channel,
1900 struct qeth_cmd_buffer *iob)
1902 struct qeth_card *card;
1903 __u16 temp;
1905 QETH_DBF_TEXT(SETUP , 2, "idxwrcb");
1907 if (channel->state == CH_STATE_DOWN) {
1908 channel->state = CH_STATE_ACTIVATING;
1909 goto out;
1911 card = CARD_FROM_CDEV(channel->ccwdev);
1913 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1914 if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == QETH_IDX_ACT_ERR_EXCL)
1915 dev_err(&card->write.ccwdev->dev,
1916 "The adapter is used exclusively by another "
1917 "host\n");
1918 else
1919 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1920 " negative reply\n",
1921 dev_name(&card->write.ccwdev->dev));
1922 goto out;
1924 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1925 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1926 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
1927 "function level mismatch (sent: 0x%x, received: "
1928 "0x%x)\n", dev_name(&card->write.ccwdev->dev),
1929 card->info.func_level, temp);
1930 goto out;
1932 channel->state = CH_STATE_UP;
1933 out:
1934 qeth_release_buffer(channel, iob);
1937 static void qeth_idx_read_cb(struct qeth_channel *channel,
1938 struct qeth_cmd_buffer *iob)
1940 struct qeth_card *card;
1941 __u16 temp;
1943 QETH_DBF_TEXT(SETUP , 2, "idxrdcb");
1944 if (channel->state == CH_STATE_DOWN) {
1945 channel->state = CH_STATE_ACTIVATING;
1946 goto out;
1949 card = CARD_FROM_CDEV(channel->ccwdev);
1950 if (qeth_check_idx_response(card, iob->data))
1951 goto out;
1953 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1954 switch (QETH_IDX_ACT_CAUSE_CODE(iob->data)) {
1955 case QETH_IDX_ACT_ERR_EXCL:
1956 dev_err(&card->write.ccwdev->dev,
1957 "The adapter is used exclusively by another "
1958 "host\n");
1959 break;
1960 case QETH_IDX_ACT_ERR_AUTH:
1961 case QETH_IDX_ACT_ERR_AUTH_USER:
1962 dev_err(&card->read.ccwdev->dev,
1963 "Setting the device online failed because of "
1964 "insufficient authorization\n");
1965 break;
1966 default:
1967 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
1968 " negative reply\n",
1969 dev_name(&card->read.ccwdev->dev));
1971 QETH_CARD_TEXT_(card, 2, "idxread%c",
1972 QETH_IDX_ACT_CAUSE_CODE(iob->data));
1973 goto out;
1976 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1977 if (temp != qeth_peer_func_level(card->info.func_level)) {
1978 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
1979 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1980 dev_name(&card->read.ccwdev->dev),
1981 card->info.func_level, temp);
1982 goto out;
1984 memcpy(&card->token.issuer_rm_r,
1985 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1986 QETH_MPC_TOKEN_LENGTH);
1987 memcpy(&card->info.mcl_level[0],
1988 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1989 channel->state = CH_STATE_UP;
1990 out:
1991 qeth_release_buffer(channel, iob);
1994 void qeth_prepare_control_data(struct qeth_card *card, int len,
1995 struct qeth_cmd_buffer *iob)
1997 qeth_setup_ccw(&card->write, iob->data, len);
1998 iob->callback = qeth_release_buffer;
2000 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
2001 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
2002 card->seqno.trans_hdr++;
2003 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
2004 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
2005 card->seqno.pdu_hdr++;
2006 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
2007 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
2008 QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
2010 EXPORT_SYMBOL_GPL(qeth_prepare_control_data);
2013 * qeth_send_control_data() - send control command to the card
2014 * @card: qeth_card structure pointer
2015 * @len: size of the command buffer
2016 * @iob: qeth_cmd_buffer pointer
2017 * @reply_cb: callback function pointer
2018 * @cb_card: pointer to the qeth_card structure
2019 * @cb_reply: pointer to the qeth_reply structure
2020 * @cb_cmd: pointer to the original iob for non-IPA
2021 * commands, or to the qeth_ipa_cmd structure
2022 * for the IPA commands.
2023 * @reply_param: private pointer passed to the callback
2025 * Returns the value of the `return_code' field of the response
2026 * block returned from the hardware, or other error indication.
2027 * Value of zero indicates successful execution of the command.
2029 * Callback function gets called one or more times, with cb_cmd
2030 * pointing to the response returned by the hardware. Callback
2031 * function must return non-zero if more reply blocks are expected,
2032 * and zero if the last or only reply block is received. Callback
2033 * function can get the value of the reply_param pointer from the
2034 * field 'param' of the structure qeth_reply.
2037 int qeth_send_control_data(struct qeth_card *card, int len,
2038 struct qeth_cmd_buffer *iob,
2039 int (*reply_cb)(struct qeth_card *cb_card,
2040 struct qeth_reply *cb_reply,
2041 unsigned long cb_cmd),
2042 void *reply_param)
2044 int rc;
2045 unsigned long flags;
2046 struct qeth_reply *reply = NULL;
2047 unsigned long timeout, event_timeout;
2048 struct qeth_ipa_cmd *cmd;
2050 QETH_CARD_TEXT(card, 2, "sendctl");
2052 if (card->read_or_write_problem) {
2053 qeth_release_buffer(iob->channel, iob);
2054 return -EIO;
2056 reply = qeth_alloc_reply(card);
2057 if (!reply) {
2058 return -ENOMEM;
2060 reply->callback = reply_cb;
2061 reply->param = reply_param;
2062 if (card->state == CARD_STATE_DOWN)
2063 reply->seqno = QETH_IDX_COMMAND_SEQNO;
2064 else
2065 reply->seqno = card->seqno.ipa++;
2066 init_waitqueue_head(&reply->wait_q);
2067 spin_lock_irqsave(&card->lock, flags);
2068 list_add_tail(&reply->list, &card->cmd_waiter_list);
2069 spin_unlock_irqrestore(&card->lock, flags);
2070 QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
2072 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
2073 qeth_prepare_control_data(card, len, iob);
2075 if (IS_IPA(iob->data))
2076 event_timeout = QETH_IPA_TIMEOUT;
2077 else
2078 event_timeout = QETH_TIMEOUT;
2079 timeout = jiffies + event_timeout;
2081 QETH_CARD_TEXT(card, 6, "noirqpnd");
2082 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
2083 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
2084 (addr_t) iob, 0, 0);
2085 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
2086 if (rc) {
2087 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
2088 "ccw_device_start rc = %i\n",
2089 dev_name(&card->write.ccwdev->dev), rc);
2090 QETH_CARD_TEXT_(card, 2, " err%d", rc);
2091 spin_lock_irqsave(&card->lock, flags);
2092 list_del_init(&reply->list);
2093 qeth_put_reply(reply);
2094 spin_unlock_irqrestore(&card->lock, flags);
2095 qeth_release_buffer(iob->channel, iob);
2096 atomic_set(&card->write.irq_pending, 0);
2097 wake_up(&card->wait_q);
2098 return rc;
2101 /* we have only one long running ipassist, since we can ensure
2102 process context of this command we can sleep */
2103 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2104 if ((cmd->hdr.command == IPA_CMD_SETIP) &&
2105 (cmd->hdr.prot_version == QETH_PROT_IPV4)) {
2106 if (!wait_event_timeout(reply->wait_q,
2107 atomic_read(&reply->received), event_timeout))
2108 goto time_err;
2109 } else {
2110 while (!atomic_read(&reply->received)) {
2111 if (time_after(jiffies, timeout))
2112 goto time_err;
2113 cpu_relax();
2117 if (reply->rc == -EIO)
2118 goto error;
2119 rc = reply->rc;
2120 qeth_put_reply(reply);
2121 return rc;
2123 time_err:
2124 reply->rc = -ETIME;
2125 spin_lock_irqsave(&reply->card->lock, flags);
2126 list_del_init(&reply->list);
2127 spin_unlock_irqrestore(&reply->card->lock, flags);
2128 atomic_inc(&reply->received);
2129 error:
2130 atomic_set(&card->write.irq_pending, 0);
2131 qeth_release_buffer(iob->channel, iob);
2132 card->write.buf_no = (card->write.buf_no + 1) % QETH_CMD_BUFFER_NO;
2133 rc = reply->rc;
2134 qeth_put_reply(reply);
2135 return rc;
2137 EXPORT_SYMBOL_GPL(qeth_send_control_data);
2139 static int qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2140 unsigned long data)
2142 struct qeth_cmd_buffer *iob;
2144 QETH_DBF_TEXT(SETUP, 2, "cmenblcb");
2146 iob = (struct qeth_cmd_buffer *) data;
2147 memcpy(&card->token.cm_filter_r,
2148 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2149 QETH_MPC_TOKEN_LENGTH);
2150 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2151 return 0;
2154 static int qeth_cm_enable(struct qeth_card *card)
2156 int rc;
2157 struct qeth_cmd_buffer *iob;
2159 QETH_DBF_TEXT(SETUP, 2, "cmenable");
2161 iob = qeth_wait_for_buffer(&card->write);
2162 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2163 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2164 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2165 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2166 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2168 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2169 qeth_cm_enable_cb, NULL);
2170 return rc;
2173 static int qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2174 unsigned long data)
2177 struct qeth_cmd_buffer *iob;
2179 QETH_DBF_TEXT(SETUP, 2, "cmsetpcb");
2181 iob = (struct qeth_cmd_buffer *) data;
2182 memcpy(&card->token.cm_connection_r,
2183 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2184 QETH_MPC_TOKEN_LENGTH);
2185 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2186 return 0;
2189 static int qeth_cm_setup(struct qeth_card *card)
2191 int rc;
2192 struct qeth_cmd_buffer *iob;
2194 QETH_DBF_TEXT(SETUP, 2, "cmsetup");
2196 iob = qeth_wait_for_buffer(&card->write);
2197 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2198 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2199 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2200 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2201 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2202 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2203 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2204 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2205 qeth_cm_setup_cb, NULL);
2206 return rc;
2210 static inline int qeth_get_initial_mtu_for_card(struct qeth_card *card)
2212 switch (card->info.type) {
2213 case QETH_CARD_TYPE_UNKNOWN:
2214 return 1500;
2215 case QETH_CARD_TYPE_IQD:
2216 return card->info.max_mtu;
2217 case QETH_CARD_TYPE_OSD:
2218 switch (card->info.link_type) {
2219 case QETH_LINK_TYPE_HSTR:
2220 case QETH_LINK_TYPE_LANE_TR:
2221 return 2000;
2222 default:
2223 return card->options.layer2 ? 1500 : 1492;
2225 case QETH_CARD_TYPE_OSM:
2226 case QETH_CARD_TYPE_OSX:
2227 return card->options.layer2 ? 1500 : 1492;
2228 default:
2229 return 1500;
2233 static inline int qeth_get_mtu_outof_framesize(int framesize)
2235 switch (framesize) {
2236 case 0x4000:
2237 return 8192;
2238 case 0x6000:
2239 return 16384;
2240 case 0xa000:
2241 return 32768;
2242 case 0xffff:
2243 return 57344;
2244 default:
2245 return 0;
2249 static inline int qeth_mtu_is_valid(struct qeth_card *card, int mtu)
2251 switch (card->info.type) {
2252 case QETH_CARD_TYPE_OSD:
2253 case QETH_CARD_TYPE_OSM:
2254 case QETH_CARD_TYPE_OSX:
2255 case QETH_CARD_TYPE_IQD:
2256 return ((mtu >= 576) &&
2257 (mtu <= card->info.max_mtu));
2258 case QETH_CARD_TYPE_OSN:
2259 case QETH_CARD_TYPE_UNKNOWN:
2260 default:
2261 return 1;
2265 static int qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2266 unsigned long data)
2269 __u16 mtu, framesize;
2270 __u16 len;
2271 __u8 link_type;
2272 struct qeth_cmd_buffer *iob;
2274 QETH_DBF_TEXT(SETUP, 2, "ulpenacb");
2276 iob = (struct qeth_cmd_buffer *) data;
2277 memcpy(&card->token.ulp_filter_r,
2278 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2279 QETH_MPC_TOKEN_LENGTH);
2280 if (card->info.type == QETH_CARD_TYPE_IQD) {
2281 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2282 mtu = qeth_get_mtu_outof_framesize(framesize);
2283 if (!mtu) {
2284 iob->rc = -EINVAL;
2285 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2286 return 0;
2288 if (card->info.initial_mtu && (card->info.initial_mtu != mtu)) {
2289 /* frame size has changed */
2290 if (card->dev &&
2291 ((card->dev->mtu == card->info.initial_mtu) ||
2292 (card->dev->mtu > mtu)))
2293 card->dev->mtu = mtu;
2294 qeth_free_qdio_buffers(card);
2296 card->info.initial_mtu = mtu;
2297 card->info.max_mtu = mtu;
2298 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2299 } else {
2300 card->info.max_mtu = *(__u16 *)QETH_ULP_ENABLE_RESP_MAX_MTU(
2301 iob->data);
2302 card->info.initial_mtu = min(card->info.max_mtu,
2303 qeth_get_initial_mtu_for_card(card));
2304 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2307 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2308 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2309 memcpy(&link_type,
2310 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2311 card->info.link_type = link_type;
2312 } else
2313 card->info.link_type = 0;
2314 QETH_DBF_TEXT_(SETUP, 2, "link%d", card->info.link_type);
2315 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2316 return 0;
2319 static int qeth_ulp_enable(struct qeth_card *card)
2321 int rc;
2322 char prot_type;
2323 struct qeth_cmd_buffer *iob;
2325 /*FIXME: trace view callbacks*/
2326 QETH_DBF_TEXT(SETUP, 2, "ulpenabl");
2328 iob = qeth_wait_for_buffer(&card->write);
2329 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2331 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2332 (__u8) card->info.portno;
2333 if (card->options.layer2)
2334 if (card->info.type == QETH_CARD_TYPE_OSN)
2335 prot_type = QETH_PROT_OSN2;
2336 else
2337 prot_type = QETH_PROT_LAYER2;
2338 else
2339 prot_type = QETH_PROT_TCPIP;
2341 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data), &prot_type, 1);
2342 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2343 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2344 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2345 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2346 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2347 qeth_ulp_enable_cb, NULL);
2348 return rc;
2352 static int qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2353 unsigned long data)
2355 struct qeth_cmd_buffer *iob;
2357 QETH_DBF_TEXT(SETUP, 2, "ulpstpcb");
2359 iob = (struct qeth_cmd_buffer *) data;
2360 memcpy(&card->token.ulp_connection_r,
2361 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2362 QETH_MPC_TOKEN_LENGTH);
2363 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2364 3)) {
2365 QETH_DBF_TEXT(SETUP, 2, "olmlimit");
2366 dev_err(&card->gdev->dev, "A connection could not be "
2367 "established because of an OLM limit\n");
2368 iob->rc = -EMLINK;
2370 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2371 return 0;
2374 static int qeth_ulp_setup(struct qeth_card *card)
2376 int rc;
2377 __u16 temp;
2378 struct qeth_cmd_buffer *iob;
2379 struct ccw_dev_id dev_id;
2381 QETH_DBF_TEXT(SETUP, 2, "ulpsetup");
2383 iob = qeth_wait_for_buffer(&card->write);
2384 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2386 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2387 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2388 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2389 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2390 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2391 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2393 ccw_device_get_id(CARD_DDEV(card), &dev_id);
2394 memcpy(QETH_ULP_SETUP_CUA(iob->data), &dev_id.devno, 2);
2395 temp = (card->info.cula << 8) + card->info.unit_addr2;
2396 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2397 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2398 qeth_ulp_setup_cb, NULL);
2399 return rc;
2402 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q *q, int bidx)
2404 int rc;
2405 struct qeth_qdio_out_buffer *newbuf;
2407 rc = 0;
2408 newbuf = kmem_cache_zalloc(qeth_qdio_outbuf_cache, GFP_ATOMIC);
2409 if (!newbuf) {
2410 rc = -ENOMEM;
2411 goto out;
2413 newbuf->buffer = q->qdio_bufs[bidx];
2414 skb_queue_head_init(&newbuf->skb_list);
2415 lockdep_set_class(&newbuf->skb_list.lock, &qdio_out_skb_queue_key);
2416 newbuf->q = q;
2417 newbuf->aob = NULL;
2418 newbuf->next_pending = q->bufs[bidx];
2419 atomic_set(&newbuf->state, QETH_QDIO_BUF_EMPTY);
2420 q->bufs[bidx] = newbuf;
2421 if (q->bufstates) {
2422 q->bufstates[bidx].user = newbuf;
2423 QETH_CARD_TEXT_(q->card, 2, "nbs%d", bidx);
2424 QETH_CARD_TEXT_(q->card, 2, "%lx", (long) newbuf);
2425 QETH_CARD_TEXT_(q->card, 2, "%lx",
2426 (long) newbuf->next_pending);
2428 out:
2429 return rc;
2432 static void qeth_free_qdio_out_buf(struct qeth_qdio_out_q *q)
2434 if (!q)
2435 return;
2437 qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
2438 kfree(q);
2441 static struct qeth_qdio_out_q *qeth_alloc_qdio_out_buf(void)
2443 struct qeth_qdio_out_q *q = kzalloc(sizeof(*q), GFP_KERNEL);
2445 if (!q)
2446 return NULL;
2448 if (qdio_alloc_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q)) {
2449 kfree(q);
2450 return NULL;
2452 return q;
2455 static int qeth_alloc_qdio_buffers(struct qeth_card *card)
2457 int i, j;
2459 QETH_DBF_TEXT(SETUP, 2, "allcqdbf");
2461 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
2462 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
2463 return 0;
2465 QETH_DBF_TEXT(SETUP, 2, "inq");
2466 card->qdio.in_q = qeth_alloc_qdio_queue();
2467 if (!card->qdio.in_q)
2468 goto out_nomem;
2470 /* inbound buffer pool */
2471 if (qeth_alloc_buffer_pool(card))
2472 goto out_freeinq;
2474 /* outbound */
2475 card->qdio.out_qs =
2476 kzalloc(card->qdio.no_out_queues *
2477 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
2478 if (!card->qdio.out_qs)
2479 goto out_freepool;
2480 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2481 card->qdio.out_qs[i] = qeth_alloc_qdio_out_buf();
2482 if (!card->qdio.out_qs[i])
2483 goto out_freeoutq;
2484 QETH_DBF_TEXT_(SETUP, 2, "outq %i", i);
2485 QETH_DBF_HEX(SETUP, 2, &card->qdio.out_qs[i], sizeof(void *));
2486 card->qdio.out_qs[i]->queue_no = i;
2487 /* give outbound qeth_qdio_buffers their qdio_buffers */
2488 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2489 WARN_ON(card->qdio.out_qs[i]->bufs[j] != NULL);
2490 if (qeth_init_qdio_out_buf(card->qdio.out_qs[i], j))
2491 goto out_freeoutqbufs;
2495 /* completion */
2496 if (qeth_alloc_cq(card))
2497 goto out_freeoutq;
2499 return 0;
2501 out_freeoutqbufs:
2502 while (j > 0) {
2503 --j;
2504 kmem_cache_free(qeth_qdio_outbuf_cache,
2505 card->qdio.out_qs[i]->bufs[j]);
2506 card->qdio.out_qs[i]->bufs[j] = NULL;
2508 out_freeoutq:
2509 while (i > 0) {
2510 qeth_free_qdio_out_buf(card->qdio.out_qs[--i]);
2511 qeth_clear_outq_buffers(card->qdio.out_qs[i], 1);
2513 kfree(card->qdio.out_qs);
2514 card->qdio.out_qs = NULL;
2515 out_freepool:
2516 qeth_free_buffer_pool(card);
2517 out_freeinq:
2518 qeth_free_qdio_queue(card->qdio.in_q);
2519 card->qdio.in_q = NULL;
2520 out_nomem:
2521 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
2522 return -ENOMEM;
2525 static void qeth_free_qdio_buffers(struct qeth_card *card)
2527 int i, j;
2529 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
2530 QETH_QDIO_UNINITIALIZED)
2531 return;
2533 qeth_free_cq(card);
2534 cancel_delayed_work_sync(&card->buffer_reclaim_work);
2535 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2536 if (card->qdio.in_q->bufs[j].rx_skb)
2537 dev_kfree_skb_any(card->qdio.in_q->bufs[j].rx_skb);
2539 qeth_free_qdio_queue(card->qdio.in_q);
2540 card->qdio.in_q = NULL;
2541 /* inbound buffer pool */
2542 qeth_free_buffer_pool(card);
2543 /* free outbound qdio_qs */
2544 if (card->qdio.out_qs) {
2545 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2546 qeth_clear_outq_buffers(card->qdio.out_qs[i], 1);
2547 qeth_free_qdio_out_buf(card->qdio.out_qs[i]);
2549 kfree(card->qdio.out_qs);
2550 card->qdio.out_qs = NULL;
2554 static void qeth_create_qib_param_field(struct qeth_card *card,
2555 char *param_field)
2558 param_field[0] = _ascebc['P'];
2559 param_field[1] = _ascebc['C'];
2560 param_field[2] = _ascebc['I'];
2561 param_field[3] = _ascebc['T'];
2562 *((unsigned int *) (&param_field[4])) = QETH_PCI_THRESHOLD_A(card);
2563 *((unsigned int *) (&param_field[8])) = QETH_PCI_THRESHOLD_B(card);
2564 *((unsigned int *) (&param_field[12])) = QETH_PCI_TIMER_VALUE(card);
2567 static void qeth_create_qib_param_field_blkt(struct qeth_card *card,
2568 char *param_field)
2570 param_field[16] = _ascebc['B'];
2571 param_field[17] = _ascebc['L'];
2572 param_field[18] = _ascebc['K'];
2573 param_field[19] = _ascebc['T'];
2574 *((unsigned int *) (&param_field[20])) = card->info.blkt.time_total;
2575 *((unsigned int *) (&param_field[24])) = card->info.blkt.inter_packet;
2576 *((unsigned int *) (&param_field[28])) =
2577 card->info.blkt.inter_packet_jumbo;
2580 static int qeth_qdio_activate(struct qeth_card *card)
2582 QETH_DBF_TEXT(SETUP, 3, "qdioact");
2583 return qdio_activate(CARD_DDEV(card));
2586 static int qeth_dm_act(struct qeth_card *card)
2588 int rc;
2589 struct qeth_cmd_buffer *iob;
2591 QETH_DBF_TEXT(SETUP, 2, "dmact");
2593 iob = qeth_wait_for_buffer(&card->write);
2594 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
2596 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
2597 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2598 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
2599 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2600 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
2601 return rc;
2604 static int qeth_mpc_initialize(struct qeth_card *card)
2606 int rc;
2608 QETH_DBF_TEXT(SETUP, 2, "mpcinit");
2610 rc = qeth_issue_next_read(card);
2611 if (rc) {
2612 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2613 return rc;
2615 rc = qeth_cm_enable(card);
2616 if (rc) {
2617 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
2618 goto out_qdio;
2620 rc = qeth_cm_setup(card);
2621 if (rc) {
2622 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
2623 goto out_qdio;
2625 rc = qeth_ulp_enable(card);
2626 if (rc) {
2627 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
2628 goto out_qdio;
2630 rc = qeth_ulp_setup(card);
2631 if (rc) {
2632 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
2633 goto out_qdio;
2635 rc = qeth_alloc_qdio_buffers(card);
2636 if (rc) {
2637 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
2638 goto out_qdio;
2640 rc = qeth_qdio_establish(card);
2641 if (rc) {
2642 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
2643 qeth_free_qdio_buffers(card);
2644 goto out_qdio;
2646 rc = qeth_qdio_activate(card);
2647 if (rc) {
2648 QETH_DBF_TEXT_(SETUP, 2, "7err%d", rc);
2649 goto out_qdio;
2651 rc = qeth_dm_act(card);
2652 if (rc) {
2653 QETH_DBF_TEXT_(SETUP, 2, "8err%d", rc);
2654 goto out_qdio;
2657 return 0;
2658 out_qdio:
2659 qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
2660 qdio_free(CARD_DDEV(card));
2661 return rc;
2664 void qeth_print_status_message(struct qeth_card *card)
2666 switch (card->info.type) {
2667 case QETH_CARD_TYPE_OSD:
2668 case QETH_CARD_TYPE_OSM:
2669 case QETH_CARD_TYPE_OSX:
2670 /* VM will use a non-zero first character
2671 * to indicate a HiperSockets like reporting
2672 * of the level OSA sets the first character to zero
2673 * */
2674 if (!card->info.mcl_level[0]) {
2675 sprintf(card->info.mcl_level, "%02x%02x",
2676 card->info.mcl_level[2],
2677 card->info.mcl_level[3]);
2678 break;
2680 /* fallthrough */
2681 case QETH_CARD_TYPE_IQD:
2682 if ((card->info.guestlan) ||
2683 (card->info.mcl_level[0] & 0x80)) {
2684 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
2685 card->info.mcl_level[0]];
2686 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
2687 card->info.mcl_level[1]];
2688 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
2689 card->info.mcl_level[2]];
2690 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
2691 card->info.mcl_level[3]];
2692 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2694 break;
2695 default:
2696 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
2698 dev_info(&card->gdev->dev,
2699 "Device is a%s card%s%s%s\nwith link type %s.\n",
2700 qeth_get_cardname(card),
2701 (card->info.mcl_level[0]) ? " (level: " : "",
2702 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2703 (card->info.mcl_level[0]) ? ")" : "",
2704 qeth_get_cardname_short(card));
2706 EXPORT_SYMBOL_GPL(qeth_print_status_message);
2708 static void qeth_initialize_working_pool_list(struct qeth_card *card)
2710 struct qeth_buffer_pool_entry *entry;
2712 QETH_CARD_TEXT(card, 5, "inwrklst");
2714 list_for_each_entry(entry,
2715 &card->qdio.init_pool.entry_list, init_list) {
2716 qeth_put_buffer_pool_entry(card, entry);
2720 static inline struct qeth_buffer_pool_entry *qeth_find_free_buffer_pool_entry(
2721 struct qeth_card *card)
2723 struct list_head *plh;
2724 struct qeth_buffer_pool_entry *entry;
2725 int i, free;
2726 struct page *page;
2728 if (list_empty(&card->qdio.in_buf_pool.entry_list))
2729 return NULL;
2731 list_for_each(plh, &card->qdio.in_buf_pool.entry_list) {
2732 entry = list_entry(plh, struct qeth_buffer_pool_entry, list);
2733 free = 1;
2734 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2735 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2736 free = 0;
2737 break;
2740 if (free) {
2741 list_del_init(&entry->list);
2742 return entry;
2746 /* no free buffer in pool so take first one and swap pages */
2747 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2748 struct qeth_buffer_pool_entry, list);
2749 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2750 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2751 page = alloc_page(GFP_ATOMIC);
2752 if (!page) {
2753 return NULL;
2754 } else {
2755 free_page((unsigned long)entry->elements[i]);
2756 entry->elements[i] = page_address(page);
2757 if (card->options.performance_stats)
2758 card->perf_stats.sg_alloc_page_rx++;
2762 list_del_init(&entry->list);
2763 return entry;
2766 static int qeth_init_input_buffer(struct qeth_card *card,
2767 struct qeth_qdio_buffer *buf)
2769 struct qeth_buffer_pool_entry *pool_entry;
2770 int i;
2772 if ((card->options.cq == QETH_CQ_ENABLED) && (!buf->rx_skb)) {
2773 buf->rx_skb = dev_alloc_skb(QETH_RX_PULL_LEN + ETH_HLEN);
2774 if (!buf->rx_skb)
2775 return 1;
2778 pool_entry = qeth_find_free_buffer_pool_entry(card);
2779 if (!pool_entry)
2780 return 1;
2783 * since the buffer is accessed only from the input_tasklet
2784 * there shouldn't be a need to synchronize; also, since we use
2785 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2786 * buffers
2789 buf->pool_entry = pool_entry;
2790 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2791 buf->buffer->element[i].length = PAGE_SIZE;
2792 buf->buffer->element[i].addr = pool_entry->elements[i];
2793 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2794 buf->buffer->element[i].eflags = SBAL_EFLAGS_LAST_ENTRY;
2795 else
2796 buf->buffer->element[i].eflags = 0;
2797 buf->buffer->element[i].sflags = 0;
2799 return 0;
2802 int qeth_init_qdio_queues(struct qeth_card *card)
2804 int i, j;
2805 int rc;
2807 QETH_DBF_TEXT(SETUP, 2, "initqdqs");
2809 /* inbound queue */
2810 qdio_reset_buffers(card->qdio.in_q->qdio_bufs,
2811 QDIO_MAX_BUFFERS_PER_Q);
2812 qeth_initialize_working_pool_list(card);
2813 /*give only as many buffers to hardware as we have buffer pool entries*/
2814 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
2815 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
2816 card->qdio.in_q->next_buf_to_init =
2817 card->qdio.in_buf_pool.buf_count - 1;
2818 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
2819 card->qdio.in_buf_pool.buf_count - 1);
2820 if (rc) {
2821 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2822 return rc;
2825 /* completion */
2826 rc = qeth_cq_init(card);
2827 if (rc) {
2828 return rc;
2831 /* outbound queue */
2832 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2833 qdio_reset_buffers(card->qdio.out_qs[i]->qdio_bufs,
2834 QDIO_MAX_BUFFERS_PER_Q);
2835 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2836 qeth_clear_output_buffer(card->qdio.out_qs[i],
2837 card->qdio.out_qs[i]->bufs[j],
2838 QETH_QDIO_BUF_EMPTY);
2840 card->qdio.out_qs[i]->card = card;
2841 card->qdio.out_qs[i]->next_buf_to_fill = 0;
2842 card->qdio.out_qs[i]->do_pack = 0;
2843 atomic_set(&card->qdio.out_qs[i]->used_buffers, 0);
2844 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
2845 atomic_set(&card->qdio.out_qs[i]->state,
2846 QETH_OUT_Q_UNLOCKED);
2848 return 0;
2850 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues);
2852 static inline __u8 qeth_get_ipa_adp_type(enum qeth_link_types link_type)
2854 switch (link_type) {
2855 case QETH_LINK_TYPE_HSTR:
2856 return 2;
2857 default:
2858 return 1;
2862 static void qeth_fill_ipacmd_header(struct qeth_card *card,
2863 struct qeth_ipa_cmd *cmd, __u8 command,
2864 enum qeth_prot_versions prot)
2866 memset(cmd, 0, sizeof(struct qeth_ipa_cmd));
2867 cmd->hdr.command = command;
2868 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
2869 cmd->hdr.seqno = card->seqno.ipa;
2870 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
2871 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
2872 if (card->options.layer2)
2873 cmd->hdr.prim_version_no = 2;
2874 else
2875 cmd->hdr.prim_version_no = 1;
2876 cmd->hdr.param_count = 1;
2877 cmd->hdr.prot_version = prot;
2878 cmd->hdr.ipa_supported = 0;
2879 cmd->hdr.ipa_enabled = 0;
2882 struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *card,
2883 enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
2885 struct qeth_cmd_buffer *iob;
2886 struct qeth_ipa_cmd *cmd;
2888 iob = qeth_get_buffer(&card->write);
2889 if (iob) {
2890 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2891 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
2892 } else {
2893 dev_warn(&card->gdev->dev,
2894 "The qeth driver ran out of channel command buffers\n");
2895 QETH_DBF_MESSAGE(1, "%s The qeth driver ran out of channel command buffers",
2896 dev_name(&card->gdev->dev));
2899 return iob;
2901 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer);
2903 void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2904 char prot_type)
2906 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2907 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data), &prot_type, 1);
2908 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2909 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2911 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd);
2914 * qeth_send_ipa_cmd() - send an IPA command
2916 * See qeth_send_control_data() for explanation of the arguments.
2919 int qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2920 int (*reply_cb)(struct qeth_card *, struct qeth_reply*,
2921 unsigned long),
2922 void *reply_param)
2924 int rc;
2925 char prot_type;
2927 QETH_CARD_TEXT(card, 4, "sendipa");
2929 if (card->options.layer2)
2930 if (card->info.type == QETH_CARD_TYPE_OSN)
2931 prot_type = QETH_PROT_OSN2;
2932 else
2933 prot_type = QETH_PROT_LAYER2;
2934 else
2935 prot_type = QETH_PROT_TCPIP;
2936 qeth_prepare_ipa_cmd(card, iob, prot_type);
2937 rc = qeth_send_control_data(card, IPA_CMD_LENGTH,
2938 iob, reply_cb, reply_param);
2939 if (rc == -ETIME) {
2940 qeth_clear_ipacmd_list(card);
2941 qeth_schedule_recovery(card);
2943 return rc;
2945 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd);
2947 int qeth_send_startlan(struct qeth_card *card)
2949 int rc;
2950 struct qeth_cmd_buffer *iob;
2952 QETH_DBF_TEXT(SETUP, 2, "strtlan");
2954 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_STARTLAN, 0);
2955 if (!iob)
2956 return -ENOMEM;
2957 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
2958 return rc;
2960 EXPORT_SYMBOL_GPL(qeth_send_startlan);
2962 static int qeth_default_setadapterparms_cb(struct qeth_card *card,
2963 struct qeth_reply *reply, unsigned long data)
2965 struct qeth_ipa_cmd *cmd;
2967 QETH_CARD_TEXT(card, 4, "defadpcb");
2969 cmd = (struct qeth_ipa_cmd *) data;
2970 if (cmd->hdr.return_code == 0)
2971 cmd->hdr.return_code =
2972 cmd->data.setadapterparms.hdr.return_code;
2973 return 0;
2976 static int qeth_query_setadapterparms_cb(struct qeth_card *card,
2977 struct qeth_reply *reply, unsigned long data)
2979 struct qeth_ipa_cmd *cmd;
2981 QETH_CARD_TEXT(card, 3, "quyadpcb");
2983 cmd = (struct qeth_ipa_cmd *) data;
2984 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f) {
2985 card->info.link_type =
2986 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
2987 QETH_DBF_TEXT_(SETUP, 2, "lnk %d", card->info.link_type);
2989 card->options.adp.supported_funcs =
2990 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
2991 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
2994 static struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
2995 __u32 command, __u32 cmdlen)
2997 struct qeth_cmd_buffer *iob;
2998 struct qeth_ipa_cmd *cmd;
3000 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETADAPTERPARMS,
3001 QETH_PROT_IPV4);
3002 if (iob) {
3003 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3004 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
3005 cmd->data.setadapterparms.hdr.command_code = command;
3006 cmd->data.setadapterparms.hdr.used_total = 1;
3007 cmd->data.setadapterparms.hdr.seq_no = 1;
3010 return iob;
3013 int qeth_query_setadapterparms(struct qeth_card *card)
3015 int rc;
3016 struct qeth_cmd_buffer *iob;
3018 QETH_CARD_TEXT(card, 3, "queryadp");
3019 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
3020 sizeof(struct qeth_ipacmd_setadpparms));
3021 if (!iob)
3022 return -ENOMEM;
3023 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
3024 return rc;
3026 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms);
3028 static int qeth_query_ipassists_cb(struct qeth_card *card,
3029 struct qeth_reply *reply, unsigned long data)
3031 struct qeth_ipa_cmd *cmd;
3033 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
3035 cmd = (struct qeth_ipa_cmd *) data;
3037 switch (cmd->hdr.return_code) {
3038 case IPA_RC_NOTSUPP:
3039 case IPA_RC_L2_UNSUPPORTED_CMD:
3040 QETH_DBF_TEXT(SETUP, 2, "ipaunsup");
3041 card->options.ipa4.supported_funcs |= IPA_SETADAPTERPARMS;
3042 card->options.ipa6.supported_funcs |= IPA_SETADAPTERPARMS;
3043 return -0;
3044 default:
3045 if (cmd->hdr.return_code) {
3046 QETH_DBF_MESSAGE(1, "%s IPA_CMD_QIPASSIST: Unhandled "
3047 "rc=%d\n",
3048 dev_name(&card->gdev->dev),
3049 cmd->hdr.return_code);
3050 return 0;
3054 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
3055 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
3056 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
3057 } else if (cmd->hdr.prot_version == QETH_PROT_IPV6) {
3058 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
3059 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
3060 } else
3061 QETH_DBF_MESSAGE(1, "%s IPA_CMD_QIPASSIST: Flawed LIC detected"
3062 "\n", dev_name(&card->gdev->dev));
3063 return 0;
3066 int qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
3068 int rc;
3069 struct qeth_cmd_buffer *iob;
3071 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
3072 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
3073 if (!iob)
3074 return -ENOMEM;
3075 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
3076 return rc;
3078 EXPORT_SYMBOL_GPL(qeth_query_ipassists);
3080 static int qeth_query_switch_attributes_cb(struct qeth_card *card,
3081 struct qeth_reply *reply, unsigned long data)
3083 struct qeth_ipa_cmd *cmd;
3084 struct qeth_switch_info *sw_info;
3085 struct qeth_query_switch_attributes *attrs;
3087 QETH_CARD_TEXT(card, 2, "qswiatcb");
3088 cmd = (struct qeth_ipa_cmd *) data;
3089 sw_info = (struct qeth_switch_info *)reply->param;
3090 if (cmd->data.setadapterparms.hdr.return_code == 0) {
3091 attrs = &cmd->data.setadapterparms.data.query_switch_attributes;
3092 sw_info->capabilities = attrs->capabilities;
3093 sw_info->settings = attrs->settings;
3094 QETH_CARD_TEXT_(card, 2, "%04x%04x", sw_info->capabilities,
3095 sw_info->settings);
3097 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
3099 return 0;
3102 int qeth_query_switch_attributes(struct qeth_card *card,
3103 struct qeth_switch_info *sw_info)
3105 struct qeth_cmd_buffer *iob;
3107 QETH_CARD_TEXT(card, 2, "qswiattr");
3108 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES))
3109 return -EOPNOTSUPP;
3110 if (!netif_carrier_ok(card->dev))
3111 return -ENOMEDIUM;
3112 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES,
3113 sizeof(struct qeth_ipacmd_setadpparms_hdr));
3114 if (!iob)
3115 return -ENOMEM;
3116 return qeth_send_ipa_cmd(card, iob,
3117 qeth_query_switch_attributes_cb, sw_info);
3119 EXPORT_SYMBOL_GPL(qeth_query_switch_attributes);
3121 static int qeth_query_setdiagass_cb(struct qeth_card *card,
3122 struct qeth_reply *reply, unsigned long data)
3124 struct qeth_ipa_cmd *cmd;
3125 __u16 rc;
3127 cmd = (struct qeth_ipa_cmd *)data;
3128 rc = cmd->hdr.return_code;
3129 if (rc)
3130 QETH_CARD_TEXT_(card, 2, "diagq:%x", rc);
3131 else
3132 card->info.diagass_support = cmd->data.diagass.ext;
3133 return 0;
3136 static int qeth_query_setdiagass(struct qeth_card *card)
3138 struct qeth_cmd_buffer *iob;
3139 struct qeth_ipa_cmd *cmd;
3141 QETH_DBF_TEXT(SETUP, 2, "qdiagass");
3142 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
3143 if (!iob)
3144 return -ENOMEM;
3145 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3146 cmd->data.diagass.subcmd_len = 16;
3147 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_QUERY;
3148 return qeth_send_ipa_cmd(card, iob, qeth_query_setdiagass_cb, NULL);
3151 static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
3153 unsigned long info = get_zeroed_page(GFP_KERNEL);
3154 struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
3155 struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
3156 struct ccw_dev_id ccwid;
3157 int level;
3159 tid->chpid = card->info.chpid;
3160 ccw_device_get_id(CARD_RDEV(card), &ccwid);
3161 tid->ssid = ccwid.ssid;
3162 tid->devno = ccwid.devno;
3163 if (!info)
3164 return;
3165 level = stsi(NULL, 0, 0, 0);
3166 if ((level >= 2) && (stsi(info222, 2, 2, 2) == 0))
3167 tid->lparnr = info222->lpar_number;
3168 if ((level >= 3) && (stsi(info322, 3, 2, 2) == 0)) {
3169 EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
3170 memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
3172 free_page(info);
3173 return;
3176 static int qeth_hw_trap_cb(struct qeth_card *card,
3177 struct qeth_reply *reply, unsigned long data)
3179 struct qeth_ipa_cmd *cmd;
3180 __u16 rc;
3182 cmd = (struct qeth_ipa_cmd *)data;
3183 rc = cmd->hdr.return_code;
3184 if (rc)
3185 QETH_CARD_TEXT_(card, 2, "trapc:%x", rc);
3186 return 0;
3189 int qeth_hw_trap(struct qeth_card *card, enum qeth_diags_trap_action action)
3191 struct qeth_cmd_buffer *iob;
3192 struct qeth_ipa_cmd *cmd;
3194 QETH_DBF_TEXT(SETUP, 2, "diagtrap");
3195 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
3196 if (!iob)
3197 return -ENOMEM;
3198 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3199 cmd->data.diagass.subcmd_len = 80;
3200 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRAP;
3201 cmd->data.diagass.type = 1;
3202 cmd->data.diagass.action = action;
3203 switch (action) {
3204 case QETH_DIAGS_TRAP_ARM:
3205 cmd->data.diagass.options = 0x0003;
3206 cmd->data.diagass.ext = 0x00010000 +
3207 sizeof(struct qeth_trap_id);
3208 qeth_get_trap_id(card,
3209 (struct qeth_trap_id *)cmd->data.diagass.cdata);
3210 break;
3211 case QETH_DIAGS_TRAP_DISARM:
3212 cmd->data.diagass.options = 0x0001;
3213 break;
3214 case QETH_DIAGS_TRAP_CAPTURE:
3215 break;
3217 return qeth_send_ipa_cmd(card, iob, qeth_hw_trap_cb, NULL);
3219 EXPORT_SYMBOL_GPL(qeth_hw_trap);
3221 int qeth_check_qdio_errors(struct qeth_card *card, struct qdio_buffer *buf,
3222 unsigned int qdio_error, const char *dbftext)
3224 if (qdio_error) {
3225 QETH_CARD_TEXT(card, 2, dbftext);
3226 QETH_CARD_TEXT_(card, 2, " F15=%02X",
3227 buf->element[15].sflags);
3228 QETH_CARD_TEXT_(card, 2, " F14=%02X",
3229 buf->element[14].sflags);
3230 QETH_CARD_TEXT_(card, 2, " qerr=%X", qdio_error);
3231 if ((buf->element[15].sflags) == 0x12) {
3232 card->stats.rx_dropped++;
3233 return 0;
3234 } else
3235 return 1;
3237 return 0;
3239 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors);
3241 static void qeth_buffer_reclaim_work(struct work_struct *work)
3243 struct qeth_card *card = container_of(work, struct qeth_card,
3244 buffer_reclaim_work.work);
3246 QETH_CARD_TEXT_(card, 2, "brw:%x", card->reclaim_index);
3247 qeth_queue_input_buffer(card, card->reclaim_index);
3250 void qeth_queue_input_buffer(struct qeth_card *card, int index)
3252 struct qeth_qdio_q *queue = card->qdio.in_q;
3253 struct list_head *lh;
3254 int count;
3255 int i;
3256 int rc;
3257 int newcount = 0;
3259 count = (index < queue->next_buf_to_init)?
3260 card->qdio.in_buf_pool.buf_count -
3261 (queue->next_buf_to_init - index) :
3262 card->qdio.in_buf_pool.buf_count -
3263 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
3264 /* only requeue at a certain threshold to avoid SIGAs */
3265 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)) {
3266 for (i = queue->next_buf_to_init;
3267 i < queue->next_buf_to_init + count; ++i) {
3268 if (qeth_init_input_buffer(card,
3269 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q])) {
3270 break;
3271 } else {
3272 newcount++;
3276 if (newcount < count) {
3277 /* we are in memory shortage so we switch back to
3278 traditional skb allocation and drop packages */
3279 atomic_set(&card->force_alloc_skb, 3);
3280 count = newcount;
3281 } else {
3282 atomic_add_unless(&card->force_alloc_skb, -1, 0);
3285 if (!count) {
3286 i = 0;
3287 list_for_each(lh, &card->qdio.in_buf_pool.entry_list)
3288 i++;
3289 if (i == card->qdio.in_buf_pool.buf_count) {
3290 QETH_CARD_TEXT(card, 2, "qsarbw");
3291 card->reclaim_index = index;
3292 schedule_delayed_work(
3293 &card->buffer_reclaim_work,
3294 QETH_RECLAIM_WORK_TIME);
3296 return;
3300 * according to old code it should be avoided to requeue all
3301 * 128 buffers in order to benefit from PCI avoidance.
3302 * this function keeps at least one buffer (the buffer at
3303 * 'index') un-requeued -> this buffer is the first buffer that
3304 * will be requeued the next time
3306 if (card->options.performance_stats) {
3307 card->perf_stats.inbound_do_qdio_cnt++;
3308 card->perf_stats.inbound_do_qdio_start_time =
3309 qeth_get_micros();
3311 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0,
3312 queue->next_buf_to_init, count);
3313 if (card->options.performance_stats)
3314 card->perf_stats.inbound_do_qdio_time +=
3315 qeth_get_micros() -
3316 card->perf_stats.inbound_do_qdio_start_time;
3317 if (rc) {
3318 QETH_CARD_TEXT(card, 2, "qinberr");
3320 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
3321 QDIO_MAX_BUFFERS_PER_Q;
3324 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer);
3326 static int qeth_handle_send_error(struct qeth_card *card,
3327 struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err)
3329 int sbalf15 = buffer->buffer->element[15].sflags;
3331 QETH_CARD_TEXT(card, 6, "hdsnderr");
3332 if (card->info.type == QETH_CARD_TYPE_IQD) {
3333 if (sbalf15 == 0) {
3334 qdio_err = 0;
3335 } else {
3336 qdio_err = 1;
3339 qeth_check_qdio_errors(card, buffer->buffer, qdio_err, "qouterr");
3341 if (!qdio_err)
3342 return QETH_SEND_ERROR_NONE;
3344 if ((sbalf15 >= 15) && (sbalf15 <= 31))
3345 return QETH_SEND_ERROR_RETRY;
3347 QETH_CARD_TEXT(card, 1, "lnkfail");
3348 QETH_CARD_TEXT_(card, 1, "%04x %02x",
3349 (u16)qdio_err, (u8)sbalf15);
3350 return QETH_SEND_ERROR_LINK_FAILURE;
3354 * Switched to packing state if the number of used buffers on a queue
3355 * reaches a certain limit.
3357 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
3359 if (!queue->do_pack) {
3360 if (atomic_read(&queue->used_buffers)
3361 >= QETH_HIGH_WATERMARK_PACK){
3362 /* switch non-PACKING -> PACKING */
3363 QETH_CARD_TEXT(queue->card, 6, "np->pack");
3364 if (queue->card->options.performance_stats)
3365 queue->card->perf_stats.sc_dp_p++;
3366 queue->do_pack = 1;
3372 * Switches from packing to non-packing mode. If there is a packing
3373 * buffer on the queue this buffer will be prepared to be flushed.
3374 * In that case 1 is returned to inform the caller. If no buffer
3375 * has to be flushed, zero is returned.
3377 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
3379 struct qeth_qdio_out_buffer *buffer;
3380 int flush_count = 0;
3382 if (queue->do_pack) {
3383 if (atomic_read(&queue->used_buffers)
3384 <= QETH_LOW_WATERMARK_PACK) {
3385 /* switch PACKING -> non-PACKING */
3386 QETH_CARD_TEXT(queue->card, 6, "pack->np");
3387 if (queue->card->options.performance_stats)
3388 queue->card->perf_stats.sc_p_dp++;
3389 queue->do_pack = 0;
3390 /* flush packing buffers */
3391 buffer = queue->bufs[queue->next_buf_to_fill];
3392 if ((atomic_read(&buffer->state) ==
3393 QETH_QDIO_BUF_EMPTY) &&
3394 (buffer->next_element_to_fill > 0)) {
3395 atomic_set(&buffer->state,
3396 QETH_QDIO_BUF_PRIMED);
3397 flush_count++;
3398 queue->next_buf_to_fill =
3399 (queue->next_buf_to_fill + 1) %
3400 QDIO_MAX_BUFFERS_PER_Q;
3404 return flush_count;
3409 * Called to flush a packing buffer if no more pci flags are on the queue.
3410 * Checks if there is a packing buffer and prepares it to be flushed.
3411 * In that case returns 1, otherwise zero.
3413 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
3415 struct qeth_qdio_out_buffer *buffer;
3417 buffer = queue->bufs[queue->next_buf_to_fill];
3418 if ((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
3419 (buffer->next_element_to_fill > 0)) {
3420 /* it's a packing buffer */
3421 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
3422 queue->next_buf_to_fill =
3423 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
3424 return 1;
3426 return 0;
3429 static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
3430 int count)
3432 struct qeth_qdio_out_buffer *buf;
3433 int rc;
3434 int i;
3435 unsigned int qdio_flags;
3437 for (i = index; i < index + count; ++i) {
3438 int bidx = i % QDIO_MAX_BUFFERS_PER_Q;
3439 buf = queue->bufs[bidx];
3440 buf->buffer->element[buf->next_element_to_fill - 1].eflags |=
3441 SBAL_EFLAGS_LAST_ENTRY;
3443 if (queue->bufstates)
3444 queue->bufstates[bidx].user = buf;
3446 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
3447 continue;
3449 if (!queue->do_pack) {
3450 if ((atomic_read(&queue->used_buffers) >=
3451 (QETH_HIGH_WATERMARK_PACK -
3452 QETH_WATERMARK_PACK_FUZZ)) &&
3453 !atomic_read(&queue->set_pci_flags_count)) {
3454 /* it's likely that we'll go to packing
3455 * mode soon */
3456 atomic_inc(&queue->set_pci_flags_count);
3457 buf->buffer->element[0].sflags |= SBAL_SFLAGS0_PCI_REQ;
3459 } else {
3460 if (!atomic_read(&queue->set_pci_flags_count)) {
3462 * there's no outstanding PCI any more, so we
3463 * have to request a PCI to be sure the the PCI
3464 * will wake at some time in the future then we
3465 * can flush packed buffers that might still be
3466 * hanging around, which can happen if no
3467 * further send was requested by the stack
3469 atomic_inc(&queue->set_pci_flags_count);
3470 buf->buffer->element[0].sflags |= SBAL_SFLAGS0_PCI_REQ;
3475 netif_trans_update(queue->card->dev);
3476 if (queue->card->options.performance_stats) {
3477 queue->card->perf_stats.outbound_do_qdio_cnt++;
3478 queue->card->perf_stats.outbound_do_qdio_start_time =
3479 qeth_get_micros();
3481 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
3482 if (atomic_read(&queue->set_pci_flags_count))
3483 qdio_flags |= QDIO_FLAG_PCI_OUT;
3484 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
3485 queue->queue_no, index, count);
3486 if (queue->card->options.performance_stats)
3487 queue->card->perf_stats.outbound_do_qdio_time +=
3488 qeth_get_micros() -
3489 queue->card->perf_stats.outbound_do_qdio_start_time;
3490 atomic_add(count, &queue->used_buffers);
3491 if (rc) {
3492 queue->card->stats.tx_errors += count;
3493 /* ignore temporary SIGA errors without busy condition */
3494 if (rc == -ENOBUFS)
3495 return;
3496 QETH_CARD_TEXT(queue->card, 2, "flushbuf");
3497 QETH_CARD_TEXT_(queue->card, 2, " q%d", queue->queue_no);
3498 QETH_CARD_TEXT_(queue->card, 2, " idx%d", index);
3499 QETH_CARD_TEXT_(queue->card, 2, " c%d", count);
3500 QETH_CARD_TEXT_(queue->card, 2, " err%d", rc);
3502 /* this must not happen under normal circumstances. if it
3503 * happens something is really wrong -> recover */
3504 qeth_schedule_recovery(queue->card);
3505 return;
3507 if (queue->card->options.performance_stats)
3508 queue->card->perf_stats.bufs_sent += count;
3511 static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
3513 int index;
3514 int flush_cnt = 0;
3515 int q_was_packing = 0;
3518 * check if weed have to switch to non-packing mode or if
3519 * we have to get a pci flag out on the queue
3521 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
3522 !atomic_read(&queue->set_pci_flags_count)) {
3523 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
3524 QETH_OUT_Q_UNLOCKED) {
3526 * If we get in here, there was no action in
3527 * do_send_packet. So, we check if there is a
3528 * packing buffer to be flushed here.
3530 netif_stop_queue(queue->card->dev);
3531 index = queue->next_buf_to_fill;
3532 q_was_packing = queue->do_pack;
3533 /* queue->do_pack may change */
3534 barrier();
3535 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
3536 if (!flush_cnt &&
3537 !atomic_read(&queue->set_pci_flags_count))
3538 flush_cnt +=
3539 qeth_flush_buffers_on_no_pci(queue);
3540 if (queue->card->options.performance_stats &&
3541 q_was_packing)
3542 queue->card->perf_stats.bufs_sent_pack +=
3543 flush_cnt;
3544 if (flush_cnt)
3545 qeth_flush_buffers(queue, index, flush_cnt);
3546 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3551 void qeth_qdio_start_poll(struct ccw_device *ccwdev, int queue,
3552 unsigned long card_ptr)
3554 struct qeth_card *card = (struct qeth_card *)card_ptr;
3556 if (card->dev && (card->dev->flags & IFF_UP))
3557 napi_schedule(&card->napi);
3559 EXPORT_SYMBOL_GPL(qeth_qdio_start_poll);
3561 int qeth_configure_cq(struct qeth_card *card, enum qeth_cq cq)
3563 int rc;
3565 if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
3566 rc = -1;
3567 goto out;
3568 } else {
3569 if (card->options.cq == cq) {
3570 rc = 0;
3571 goto out;
3574 if (card->state != CARD_STATE_DOWN &&
3575 card->state != CARD_STATE_RECOVER) {
3576 rc = -1;
3577 goto out;
3580 qeth_free_qdio_buffers(card);
3581 card->options.cq = cq;
3582 rc = 0;
3584 out:
3585 return rc;
3588 EXPORT_SYMBOL_GPL(qeth_configure_cq);
3591 static void qeth_qdio_cq_handler(struct qeth_card *card,
3592 unsigned int qdio_err,
3593 unsigned int queue, int first_element, int count) {
3594 struct qeth_qdio_q *cq = card->qdio.c_q;
3595 int i;
3596 int rc;
3598 if (!qeth_is_cq(card, queue))
3599 goto out;
3601 QETH_CARD_TEXT_(card, 5, "qcqhe%d", first_element);
3602 QETH_CARD_TEXT_(card, 5, "qcqhc%d", count);
3603 QETH_CARD_TEXT_(card, 5, "qcqherr%d", qdio_err);
3605 if (qdio_err) {
3606 netif_stop_queue(card->dev);
3607 qeth_schedule_recovery(card);
3608 goto out;
3611 if (card->options.performance_stats) {
3612 card->perf_stats.cq_cnt++;
3613 card->perf_stats.cq_start_time = qeth_get_micros();
3616 for (i = first_element; i < first_element + count; ++i) {
3617 int bidx = i % QDIO_MAX_BUFFERS_PER_Q;
3618 struct qdio_buffer *buffer = cq->qdio_bufs[bidx];
3619 int e;
3621 e = 0;
3622 while ((e < QDIO_MAX_ELEMENTS_PER_BUFFER) &&
3623 buffer->element[e].addr) {
3624 unsigned long phys_aob_addr;
3626 phys_aob_addr = (unsigned long) buffer->element[e].addr;
3627 qeth_qdio_handle_aob(card, phys_aob_addr);
3628 buffer->element[e].addr = NULL;
3629 buffer->element[e].eflags = 0;
3630 buffer->element[e].sflags = 0;
3631 buffer->element[e].length = 0;
3633 ++e;
3636 buffer->element[15].eflags = 0;
3637 buffer->element[15].sflags = 0;
3639 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, queue,
3640 card->qdio.c_q->next_buf_to_init,
3641 count);
3642 if (rc) {
3643 dev_warn(&card->gdev->dev,
3644 "QDIO reported an error, rc=%i\n", rc);
3645 QETH_CARD_TEXT(card, 2, "qcqherr");
3647 card->qdio.c_q->next_buf_to_init = (card->qdio.c_q->next_buf_to_init
3648 + count) % QDIO_MAX_BUFFERS_PER_Q;
3650 netif_wake_queue(card->dev);
3652 if (card->options.performance_stats) {
3653 int delta_t = qeth_get_micros();
3654 delta_t -= card->perf_stats.cq_start_time;
3655 card->perf_stats.cq_time += delta_t;
3657 out:
3658 return;
3661 void qeth_qdio_input_handler(struct ccw_device *ccwdev, unsigned int qdio_err,
3662 unsigned int queue, int first_elem, int count,
3663 unsigned long card_ptr)
3665 struct qeth_card *card = (struct qeth_card *)card_ptr;
3667 QETH_CARD_TEXT_(card, 2, "qihq%d", queue);
3668 QETH_CARD_TEXT_(card, 2, "qiec%d", qdio_err);
3670 if (qeth_is_cq(card, queue))
3671 qeth_qdio_cq_handler(card, qdio_err, queue, first_elem, count);
3672 else if (qdio_err)
3673 qeth_schedule_recovery(card);
3677 EXPORT_SYMBOL_GPL(qeth_qdio_input_handler);
3679 void qeth_qdio_output_handler(struct ccw_device *ccwdev,
3680 unsigned int qdio_error, int __queue, int first_element,
3681 int count, unsigned long card_ptr)
3683 struct qeth_card *card = (struct qeth_card *) card_ptr;
3684 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3685 struct qeth_qdio_out_buffer *buffer;
3686 int i;
3688 QETH_CARD_TEXT(card, 6, "qdouhdl");
3689 if (qdio_error & QDIO_ERROR_FATAL) {
3690 QETH_CARD_TEXT(card, 2, "achkcond");
3691 netif_stop_queue(card->dev);
3692 qeth_schedule_recovery(card);
3693 return;
3695 if (card->options.performance_stats) {
3696 card->perf_stats.outbound_handler_cnt++;
3697 card->perf_stats.outbound_handler_start_time =
3698 qeth_get_micros();
3700 for (i = first_element; i < (first_element + count); ++i) {
3701 int bidx = i % QDIO_MAX_BUFFERS_PER_Q;
3702 buffer = queue->bufs[bidx];
3703 qeth_handle_send_error(card, buffer, qdio_error);
3705 if (queue->bufstates &&
3706 (queue->bufstates[bidx].flags &
3707 QDIO_OUTBUF_STATE_FLAG_PENDING) != 0) {
3708 WARN_ON_ONCE(card->options.cq != QETH_CQ_ENABLED);
3710 if (atomic_cmpxchg(&buffer->state,
3711 QETH_QDIO_BUF_PRIMED,
3712 QETH_QDIO_BUF_PENDING) ==
3713 QETH_QDIO_BUF_PRIMED) {
3714 qeth_notify_skbs(queue, buffer,
3715 TX_NOTIFY_PENDING);
3717 buffer->aob = queue->bufstates[bidx].aob;
3718 QETH_CARD_TEXT_(queue->card, 5, "pel%d", bidx);
3719 QETH_CARD_TEXT(queue->card, 5, "aob");
3720 QETH_CARD_TEXT_(queue->card, 5, "%lx",
3721 virt_to_phys(buffer->aob));
3722 if (qeth_init_qdio_out_buf(queue, bidx)) {
3723 QETH_CARD_TEXT(card, 2, "outofbuf");
3724 qeth_schedule_recovery(card);
3726 } else {
3727 if (card->options.cq == QETH_CQ_ENABLED) {
3728 enum iucv_tx_notify n;
3730 n = qeth_compute_cq_notification(
3731 buffer->buffer->element[15].sflags, 0);
3732 qeth_notify_skbs(queue, buffer, n);
3735 qeth_clear_output_buffer(queue, buffer,
3736 QETH_QDIO_BUF_EMPTY);
3738 qeth_cleanup_handled_pending(queue, bidx, 0);
3740 atomic_sub(count, &queue->used_buffers);
3741 /* check if we need to do something on this outbound queue */
3742 if (card->info.type != QETH_CARD_TYPE_IQD)
3743 qeth_check_outbound_queue(queue);
3745 netif_wake_queue(queue->card->dev);
3746 if (card->options.performance_stats)
3747 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3748 card->perf_stats.outbound_handler_start_time;
3750 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler);
3752 /* We cannot use outbound queue 3 for unicast packets on HiperSockets */
3753 static inline int qeth_cut_iqd_prio(struct qeth_card *card, int queue_num)
3755 if ((card->info.type == QETH_CARD_TYPE_IQD) && (queue_num == 3))
3756 return 2;
3757 return queue_num;
3761 * Note: Function assumes that we have 4 outbound queues.
3763 int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3764 int ipv, int cast_type)
3766 __be16 *tci;
3767 u8 tos;
3769 if (cast_type && card->info.is_multicast_different)
3770 return card->info.is_multicast_different &
3771 (card->qdio.no_out_queues - 1);
3773 switch (card->qdio.do_prio_queueing) {
3774 case QETH_PRIO_Q_ING_TOS:
3775 case QETH_PRIO_Q_ING_PREC:
3776 switch (ipv) {
3777 case 4:
3778 tos = ipv4_get_dsfield(ip_hdr(skb));
3779 break;
3780 case 6:
3781 tos = ipv6_get_dsfield(ipv6_hdr(skb));
3782 break;
3783 default:
3784 return card->qdio.default_out_queue;
3786 if (card->qdio.do_prio_queueing == QETH_PRIO_Q_ING_PREC)
3787 return qeth_cut_iqd_prio(card, ~tos >> 6 & 3);
3788 if (tos & IPTOS_MINCOST)
3789 return qeth_cut_iqd_prio(card, 3);
3790 if (tos & IPTOS_RELIABILITY)
3791 return 2;
3792 if (tos & IPTOS_THROUGHPUT)
3793 return 1;
3794 if (tos & IPTOS_LOWDELAY)
3795 return 0;
3796 break;
3797 case QETH_PRIO_Q_ING_SKB:
3798 if (skb->priority > 5)
3799 return 0;
3800 return qeth_cut_iqd_prio(card, ~skb->priority >> 1 & 3);
3801 case QETH_PRIO_Q_ING_VLAN:
3802 tci = &((struct ethhdr *)skb->data)->h_proto;
3803 if (*tci == ETH_P_8021Q)
3804 return qeth_cut_iqd_prio(card, ~*(tci + 1) >>
3805 (VLAN_PRIO_SHIFT + 1) & 3);
3806 break;
3807 default:
3808 break;
3810 return card->qdio.default_out_queue;
3812 EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
3815 * qeth_get_elements_for_frags() - find number of SBALEs for skb frags.
3816 * @skb: SKB address
3818 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
3819 * fragmented part of the SKB. Returns zero for linear SKB.
3821 int qeth_get_elements_for_frags(struct sk_buff *skb)
3823 int cnt, elements = 0;
3825 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
3826 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[cnt];
3828 elements += qeth_get_elements_for_range(
3829 (addr_t)skb_frag_address(frag),
3830 (addr_t)skb_frag_address(frag) + skb_frag_size(frag));
3832 return elements;
3834 EXPORT_SYMBOL_GPL(qeth_get_elements_for_frags);
3837 * qeth_get_elements_no() - find number of SBALEs for skb data, inc. frags.
3838 * @card: qeth card structure, to check max. elems.
3839 * @skb: SKB address
3840 * @extra_elems: extra elems needed, to check against max.
3842 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
3843 * skb data, including linear part and fragments. Checks if the result plus
3844 * extra_elems fits under the limit for the card. Returns 0 if it does not.
3845 * Note: extra_elems is not included in the returned result.
3847 int qeth_get_elements_no(struct qeth_card *card,
3848 struct sk_buff *skb, int extra_elems)
3850 int elements = qeth_get_elements_for_range(
3851 (addr_t)skb->data,
3852 (addr_t)skb->data + skb_headlen(skb)) +
3853 qeth_get_elements_for_frags(skb);
3855 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
3856 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3857 "(Number=%d / Length=%d). Discarded.\n",
3858 elements + extra_elems, skb->len);
3859 return 0;
3861 return elements;
3863 EXPORT_SYMBOL_GPL(qeth_get_elements_no);
3865 int qeth_hdr_chk_and_bounce(struct sk_buff *skb, struct qeth_hdr **hdr, int len)
3867 int hroom, inpage, rest;
3869 if (((unsigned long)skb->data & PAGE_MASK) !=
3870 (((unsigned long)skb->data + len - 1) & PAGE_MASK)) {
3871 hroom = skb_headroom(skb);
3872 inpage = PAGE_SIZE - ((unsigned long) skb->data % PAGE_SIZE);
3873 rest = len - inpage;
3874 if (rest > hroom)
3875 return 1;
3876 memmove(skb->data - rest, skb->data, skb_headlen(skb));
3877 skb->data -= rest;
3878 skb->tail -= rest;
3879 *hdr = (struct qeth_hdr *)skb->data;
3880 QETH_DBF_MESSAGE(2, "skb bounce len: %d rest: %d\n", len, rest);
3882 return 0;
3884 EXPORT_SYMBOL_GPL(qeth_hdr_chk_and_bounce);
3886 static inline void __qeth_fill_buffer(struct sk_buff *skb,
3887 struct qdio_buffer *buffer, int is_tso, int *next_element_to_fill,
3888 int offset)
3890 int length = skb_headlen(skb);
3891 int length_here;
3892 int element;
3893 char *data;
3894 int first_lap, cnt;
3895 struct skb_frag_struct *frag;
3897 element = *next_element_to_fill;
3898 data = skb->data;
3899 first_lap = (is_tso == 0 ? 1 : 0);
3901 if (offset >= 0) {
3902 data = skb->data + offset;
3903 length -= offset;
3904 first_lap = 0;
3907 while (length > 0) {
3908 /* length_here is the remaining amount of data in this page */
3909 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
3910 if (length < length_here)
3911 length_here = length;
3913 buffer->element[element].addr = data;
3914 buffer->element[element].length = length_here;
3915 length -= length_here;
3916 if (!length) {
3917 if (first_lap)
3918 if (skb_shinfo(skb)->nr_frags)
3919 buffer->element[element].eflags =
3920 SBAL_EFLAGS_FIRST_FRAG;
3921 else
3922 buffer->element[element].eflags = 0;
3923 else
3924 buffer->element[element].eflags =
3925 SBAL_EFLAGS_MIDDLE_FRAG;
3926 } else {
3927 if (first_lap)
3928 buffer->element[element].eflags =
3929 SBAL_EFLAGS_FIRST_FRAG;
3930 else
3931 buffer->element[element].eflags =
3932 SBAL_EFLAGS_MIDDLE_FRAG;
3934 data += length_here;
3935 element++;
3936 first_lap = 0;
3939 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
3940 frag = &skb_shinfo(skb)->frags[cnt];
3941 data = (char *)page_to_phys(skb_frag_page(frag)) +
3942 frag->page_offset;
3943 length = frag->size;
3944 while (length > 0) {
3945 length_here = PAGE_SIZE -
3946 ((unsigned long) data % PAGE_SIZE);
3947 if (length < length_here)
3948 length_here = length;
3950 buffer->element[element].addr = data;
3951 buffer->element[element].length = length_here;
3952 buffer->element[element].eflags =
3953 SBAL_EFLAGS_MIDDLE_FRAG;
3954 length -= length_here;
3955 data += length_here;
3956 element++;
3960 if (buffer->element[element - 1].eflags)
3961 buffer->element[element - 1].eflags = SBAL_EFLAGS_LAST_FRAG;
3962 *next_element_to_fill = element;
3965 static inline int qeth_fill_buffer(struct qeth_qdio_out_q *queue,
3966 struct qeth_qdio_out_buffer *buf, struct sk_buff *skb,
3967 struct qeth_hdr *hdr, int offset, int hd_len)
3969 struct qdio_buffer *buffer;
3970 int flush_cnt = 0, hdr_len, large_send = 0;
3972 buffer = buf->buffer;
3973 atomic_inc(&skb->users);
3974 skb_queue_tail(&buf->skb_list, skb);
3976 /*check first on TSO ....*/
3977 if (hdr->hdr.l3.id == QETH_HEADER_TYPE_TSO) {
3978 int element = buf->next_element_to_fill;
3980 hdr_len = sizeof(struct qeth_hdr_tso) +
3981 ((struct qeth_hdr_tso *)hdr)->ext.dg_hdr_len;
3982 /*fill first buffer entry only with header information */
3983 buffer->element[element].addr = skb->data;
3984 buffer->element[element].length = hdr_len;
3985 buffer->element[element].eflags = SBAL_EFLAGS_FIRST_FRAG;
3986 buf->next_element_to_fill++;
3987 skb->data += hdr_len;
3988 skb->len -= hdr_len;
3989 large_send = 1;
3992 if (offset >= 0) {
3993 int element = buf->next_element_to_fill;
3994 buffer->element[element].addr = hdr;
3995 buffer->element[element].length = sizeof(struct qeth_hdr) +
3996 hd_len;
3997 buffer->element[element].eflags = SBAL_EFLAGS_FIRST_FRAG;
3998 buf->is_header[element] = 1;
3999 buf->next_element_to_fill++;
4002 __qeth_fill_buffer(skb, buffer, large_send,
4003 (int *)&buf->next_element_to_fill, offset);
4005 if (!queue->do_pack) {
4006 QETH_CARD_TEXT(queue->card, 6, "fillbfnp");
4007 /* set state to PRIMED -> will be flushed */
4008 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4009 flush_cnt = 1;
4010 } else {
4011 QETH_CARD_TEXT(queue->card, 6, "fillbfpa");
4012 if (queue->card->options.performance_stats)
4013 queue->card->perf_stats.skbs_sent_pack++;
4014 if (buf->next_element_to_fill >=
4015 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4017 * packed buffer if full -> set state PRIMED
4018 * -> will be flushed
4020 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4021 flush_cnt = 1;
4024 return flush_cnt;
4027 int qeth_do_send_packet_fast(struct qeth_card *card,
4028 struct qeth_qdio_out_q *queue, struct sk_buff *skb,
4029 struct qeth_hdr *hdr, int elements_needed,
4030 int offset, int hd_len)
4032 struct qeth_qdio_out_buffer *buffer;
4033 int index;
4035 /* spin until we get the queue ... */
4036 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4037 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4038 /* ... now we've got the queue */
4039 index = queue->next_buf_to_fill;
4040 buffer = queue->bufs[queue->next_buf_to_fill];
4042 * check if buffer is empty to make sure that we do not 'overtake'
4043 * ourselves and try to fill a buffer that is already primed
4045 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4046 goto out;
4047 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4048 QDIO_MAX_BUFFERS_PER_Q;
4049 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4050 qeth_fill_buffer(queue, buffer, skb, hdr, offset, hd_len);
4051 qeth_flush_buffers(queue, index, 1);
4052 return 0;
4053 out:
4054 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4055 return -EBUSY;
4057 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast);
4059 int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4060 struct sk_buff *skb, struct qeth_hdr *hdr,
4061 int elements_needed)
4063 struct qeth_qdio_out_buffer *buffer;
4064 int start_index;
4065 int flush_count = 0;
4066 int do_pack = 0;
4067 int tmp;
4068 int rc = 0;
4070 /* spin until we get the queue ... */
4071 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4072 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
4073 start_index = queue->next_buf_to_fill;
4074 buffer = queue->bufs[queue->next_buf_to_fill];
4076 * check if buffer is empty to make sure that we do not 'overtake'
4077 * ourselves and try to fill a buffer that is already primed
4079 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4080 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4081 return -EBUSY;
4083 /* check if we need to switch packing state of this queue */
4084 qeth_switch_to_packing_if_needed(queue);
4085 if (queue->do_pack) {
4086 do_pack = 1;
4087 /* does packet fit in current buffer? */
4088 if ((QETH_MAX_BUFFER_ELEMENTS(card) -
4089 buffer->next_element_to_fill) < elements_needed) {
4090 /* ... no -> set state PRIMED */
4091 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
4092 flush_count++;
4093 queue->next_buf_to_fill =
4094 (queue->next_buf_to_fill + 1) %
4095 QDIO_MAX_BUFFERS_PER_Q;
4096 buffer = queue->bufs[queue->next_buf_to_fill];
4097 /* we did a step forward, so check buffer state
4098 * again */
4099 if (atomic_read(&buffer->state) !=
4100 QETH_QDIO_BUF_EMPTY) {
4101 qeth_flush_buffers(queue, start_index,
4102 flush_count);
4103 atomic_set(&queue->state,
4104 QETH_OUT_Q_UNLOCKED);
4105 return -EBUSY;
4109 tmp = qeth_fill_buffer(queue, buffer, skb, hdr, -1, 0);
4110 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4111 QDIO_MAX_BUFFERS_PER_Q;
4112 flush_count += tmp;
4113 if (flush_count)
4114 qeth_flush_buffers(queue, start_index, flush_count);
4115 else if (!atomic_read(&queue->set_pci_flags_count))
4116 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
4118 * queue->state will go from LOCKED -> UNLOCKED or from
4119 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4120 * (switch packing state or flush buffer to get another pci flag out).
4121 * In that case we will enter this loop
4123 while (atomic_dec_return(&queue->state)) {
4124 flush_count = 0;
4125 start_index = queue->next_buf_to_fill;
4126 /* check if we can go back to non-packing state */
4127 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4129 * check if we need to flush a packing buffer to get a pci
4130 * flag out on the queue
4132 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4133 flush_count += qeth_flush_buffers_on_no_pci(queue);
4134 if (flush_count)
4135 qeth_flush_buffers(queue, start_index, flush_count);
4137 /* at this point the queue is UNLOCKED again */
4138 if (queue->card->options.performance_stats && do_pack)
4139 queue->card->perf_stats.bufs_sent_pack += flush_count;
4141 return rc;
4143 EXPORT_SYMBOL_GPL(qeth_do_send_packet);
4145 static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
4146 struct qeth_reply *reply, unsigned long data)
4148 struct qeth_ipa_cmd *cmd;
4149 struct qeth_ipacmd_setadpparms *setparms;
4151 QETH_CARD_TEXT(card, 4, "prmadpcb");
4153 cmd = (struct qeth_ipa_cmd *) data;
4154 setparms = &(cmd->data.setadapterparms);
4156 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
4157 if (cmd->hdr.return_code) {
4158 QETH_CARD_TEXT_(card, 4, "prmrc%x", cmd->hdr.return_code);
4159 setparms->data.mode = SET_PROMISC_MODE_OFF;
4161 card->info.promisc_mode = setparms->data.mode;
4162 return 0;
4165 void qeth_setadp_promisc_mode(struct qeth_card *card)
4167 enum qeth_ipa_promisc_modes mode;
4168 struct net_device *dev = card->dev;
4169 struct qeth_cmd_buffer *iob;
4170 struct qeth_ipa_cmd *cmd;
4172 QETH_CARD_TEXT(card, 4, "setprom");
4174 if (((dev->flags & IFF_PROMISC) &&
4175 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
4176 (!(dev->flags & IFF_PROMISC) &&
4177 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
4178 return;
4179 mode = SET_PROMISC_MODE_OFF;
4180 if (dev->flags & IFF_PROMISC)
4181 mode = SET_PROMISC_MODE_ON;
4182 QETH_CARD_TEXT_(card, 4, "mode:%x", mode);
4184 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
4185 sizeof(struct qeth_ipacmd_setadpparms_hdr) + 8);
4186 if (!iob)
4187 return;
4188 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
4189 cmd->data.setadapterparms.data.mode = mode;
4190 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
4192 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode);
4194 int qeth_change_mtu(struct net_device *dev, int new_mtu)
4196 struct qeth_card *card;
4197 char dbf_text[15];
4199 card = dev->ml_priv;
4201 QETH_CARD_TEXT(card, 4, "chgmtu");
4202 sprintf(dbf_text, "%8x", new_mtu);
4203 QETH_CARD_TEXT(card, 4, dbf_text);
4205 if ((!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) &&
4206 (!qeth_mtu_is_valid(card, new_mtu)))
4207 return -EINVAL;
4208 dev->mtu = new_mtu;
4209 return 0;
4211 EXPORT_SYMBOL_GPL(qeth_change_mtu);
4213 struct net_device_stats *qeth_get_stats(struct net_device *dev)
4215 struct qeth_card *card;
4217 card = dev->ml_priv;
4219 QETH_CARD_TEXT(card, 5, "getstat");
4221 return &card->stats;
4223 EXPORT_SYMBOL_GPL(qeth_get_stats);
4225 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
4226 struct qeth_reply *reply, unsigned long data)
4228 struct qeth_ipa_cmd *cmd;
4230 QETH_CARD_TEXT(card, 4, "chgmaccb");
4232 cmd = (struct qeth_ipa_cmd *) data;
4233 if (!card->options.layer2 ||
4234 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
4235 memcpy(card->dev->dev_addr,
4236 &cmd->data.setadapterparms.data.change_addr.addr,
4237 OSA_ADDR_LEN);
4238 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
4240 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
4241 return 0;
4244 int qeth_setadpparms_change_macaddr(struct qeth_card *card)
4246 int rc;
4247 struct qeth_cmd_buffer *iob;
4248 struct qeth_ipa_cmd *cmd;
4250 QETH_CARD_TEXT(card, 4, "chgmac");
4252 iob = qeth_get_adapter_cmd(card, IPA_SETADP_ALTER_MAC_ADDRESS,
4253 sizeof(struct qeth_ipacmd_setadpparms_hdr) +
4254 sizeof(struct qeth_change_addr));
4255 if (!iob)
4256 return -ENOMEM;
4257 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4258 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
4259 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
4260 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
4261 card->dev->dev_addr, OSA_ADDR_LEN);
4262 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
4263 NULL);
4264 return rc;
4266 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
4268 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card *card,
4269 struct qeth_reply *reply, unsigned long data)
4271 struct qeth_ipa_cmd *cmd;
4272 struct qeth_set_access_ctrl *access_ctrl_req;
4273 int fallback = *(int *)reply->param;
4275 QETH_CARD_TEXT(card, 4, "setaccb");
4277 cmd = (struct qeth_ipa_cmd *) data;
4278 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4279 QETH_DBF_TEXT_(SETUP, 2, "setaccb");
4280 QETH_DBF_TEXT_(SETUP, 2, "%s", card->gdev->dev.kobj.name);
4281 QETH_DBF_TEXT_(SETUP, 2, "rc=%d",
4282 cmd->data.setadapterparms.hdr.return_code);
4283 if (cmd->data.setadapterparms.hdr.return_code !=
4284 SET_ACCESS_CTRL_RC_SUCCESS)
4285 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
4286 card->gdev->dev.kobj.name,
4287 access_ctrl_req->subcmd_code,
4288 cmd->data.setadapterparms.hdr.return_code);
4289 switch (cmd->data.setadapterparms.hdr.return_code) {
4290 case SET_ACCESS_CTRL_RC_SUCCESS:
4291 if (card->options.isolation == ISOLATION_MODE_NONE) {
4292 dev_info(&card->gdev->dev,
4293 "QDIO data connection isolation is deactivated\n");
4294 } else {
4295 dev_info(&card->gdev->dev,
4296 "QDIO data connection isolation is activated\n");
4298 break;
4299 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED:
4300 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already "
4301 "deactivated\n", dev_name(&card->gdev->dev));
4302 if (fallback)
4303 card->options.isolation = card->options.prev_isolation;
4304 break;
4305 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED:
4306 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already"
4307 " activated\n", dev_name(&card->gdev->dev));
4308 if (fallback)
4309 card->options.isolation = card->options.prev_isolation;
4310 break;
4311 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED:
4312 dev_err(&card->gdev->dev, "Adapter does not "
4313 "support QDIO data connection isolation\n");
4314 break;
4315 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER:
4316 dev_err(&card->gdev->dev,
4317 "Adapter is dedicated. "
4318 "QDIO data connection isolation not supported\n");
4319 if (fallback)
4320 card->options.isolation = card->options.prev_isolation;
4321 break;
4322 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF:
4323 dev_err(&card->gdev->dev,
4324 "TSO does not permit QDIO data connection isolation\n");
4325 if (fallback)
4326 card->options.isolation = card->options.prev_isolation;
4327 break;
4328 case SET_ACCESS_CTRL_RC_REFLREL_UNSUPPORTED:
4329 dev_err(&card->gdev->dev, "The adjacent switch port does not "
4330 "support reflective relay mode\n");
4331 if (fallback)
4332 card->options.isolation = card->options.prev_isolation;
4333 break;
4334 case SET_ACCESS_CTRL_RC_REFLREL_FAILED:
4335 dev_err(&card->gdev->dev, "The reflective relay mode cannot be "
4336 "enabled at the adjacent switch port");
4337 if (fallback)
4338 card->options.isolation = card->options.prev_isolation;
4339 break;
4340 case SET_ACCESS_CTRL_RC_REFLREL_DEACT_FAILED:
4341 dev_warn(&card->gdev->dev, "Turning off reflective relay mode "
4342 "at the adjacent switch failed\n");
4343 break;
4344 default:
4345 /* this should never happen */
4346 if (fallback)
4347 card->options.isolation = card->options.prev_isolation;
4348 break;
4350 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
4351 return 0;
4354 static int qeth_setadpparms_set_access_ctrl(struct qeth_card *card,
4355 enum qeth_ipa_isolation_modes isolation, int fallback)
4357 int rc;
4358 struct qeth_cmd_buffer *iob;
4359 struct qeth_ipa_cmd *cmd;
4360 struct qeth_set_access_ctrl *access_ctrl_req;
4362 QETH_CARD_TEXT(card, 4, "setacctl");
4364 QETH_DBF_TEXT_(SETUP, 2, "setacctl");
4365 QETH_DBF_TEXT_(SETUP, 2, "%s", card->gdev->dev.kobj.name);
4367 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_ACCESS_CONTROL,
4368 sizeof(struct qeth_ipacmd_setadpparms_hdr) +
4369 sizeof(struct qeth_set_access_ctrl));
4370 if (!iob)
4371 return -ENOMEM;
4372 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4373 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4374 access_ctrl_req->subcmd_code = isolation;
4376 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_set_access_ctrl_cb,
4377 &fallback);
4378 QETH_DBF_TEXT_(SETUP, 2, "rc=%d", rc);
4379 return rc;
4382 int qeth_set_access_ctrl_online(struct qeth_card *card, int fallback)
4384 int rc = 0;
4386 QETH_CARD_TEXT(card, 4, "setactlo");
4388 if ((card->info.type == QETH_CARD_TYPE_OSD ||
4389 card->info.type == QETH_CARD_TYPE_OSX) &&
4390 qeth_adp_supported(card, IPA_SETADP_SET_ACCESS_CONTROL)) {
4391 rc = qeth_setadpparms_set_access_ctrl(card,
4392 card->options.isolation, fallback);
4393 if (rc) {
4394 QETH_DBF_MESSAGE(3,
4395 "IPA(SET_ACCESS_CTRL,%s,%d) sent failed\n",
4396 card->gdev->dev.kobj.name,
4397 rc);
4398 rc = -EOPNOTSUPP;
4400 } else if (card->options.isolation != ISOLATION_MODE_NONE) {
4401 card->options.isolation = ISOLATION_MODE_NONE;
4403 dev_err(&card->gdev->dev, "Adapter does not "
4404 "support QDIO data connection isolation\n");
4405 rc = -EOPNOTSUPP;
4407 return rc;
4409 EXPORT_SYMBOL_GPL(qeth_set_access_ctrl_online);
4411 void qeth_tx_timeout(struct net_device *dev)
4413 struct qeth_card *card;
4415 card = dev->ml_priv;
4416 QETH_CARD_TEXT(card, 4, "txtimeo");
4417 card->stats.tx_errors++;
4418 qeth_schedule_recovery(card);
4420 EXPORT_SYMBOL_GPL(qeth_tx_timeout);
4422 int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4424 struct qeth_card *card = dev->ml_priv;
4425 int rc = 0;
4427 switch (regnum) {
4428 case MII_BMCR: /* Basic mode control register */
4429 rc = BMCR_FULLDPLX;
4430 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH) &&
4431 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4432 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4433 rc |= BMCR_SPEED100;
4434 break;
4435 case MII_BMSR: /* Basic mode status register */
4436 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4437 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4438 BMSR_100BASE4;
4439 break;
4440 case MII_PHYSID1: /* PHYS ID 1 */
4441 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4442 dev->dev_addr[2];
4443 rc = (rc >> 5) & 0xFFFF;
4444 break;
4445 case MII_PHYSID2: /* PHYS ID 2 */
4446 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4447 break;
4448 case MII_ADVERTISE: /* Advertisement control reg */
4449 rc = ADVERTISE_ALL;
4450 break;
4451 case MII_LPA: /* Link partner ability reg */
4452 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4453 LPA_100BASE4 | LPA_LPACK;
4454 break;
4455 case MII_EXPANSION: /* Expansion register */
4456 break;
4457 case MII_DCOUNTER: /* disconnect counter */
4458 break;
4459 case MII_FCSCOUNTER: /* false carrier counter */
4460 break;
4461 case MII_NWAYTEST: /* N-way auto-neg test register */
4462 break;
4463 case MII_RERRCOUNTER: /* rx error counter */
4464 rc = card->stats.rx_errors;
4465 break;
4466 case MII_SREVISION: /* silicon revision */
4467 break;
4468 case MII_RESV1: /* reserved 1 */
4469 break;
4470 case MII_LBRERROR: /* loopback, rx, bypass error */
4471 break;
4472 case MII_PHYADDR: /* physical address */
4473 break;
4474 case MII_RESV2: /* reserved 2 */
4475 break;
4476 case MII_TPISTATUS: /* TPI status for 10mbps */
4477 break;
4478 case MII_NCONFIG: /* network interface config */
4479 break;
4480 default:
4481 break;
4483 return rc;
4485 EXPORT_SYMBOL_GPL(qeth_mdio_read);
4487 static int qeth_send_ipa_snmp_cmd(struct qeth_card *card,
4488 struct qeth_cmd_buffer *iob, int len,
4489 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
4490 unsigned long),
4491 void *reply_param)
4493 u16 s1, s2;
4495 QETH_CARD_TEXT(card, 4, "sendsnmp");
4497 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4498 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4499 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4500 /* adjust PDU length fields in IPA_PDU_HEADER */
4501 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4502 s2 = (u32) len;
4503 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4504 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4505 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4506 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4507 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4508 reply_cb, reply_param);
4511 static int qeth_snmp_command_cb(struct qeth_card *card,
4512 struct qeth_reply *reply, unsigned long sdata)
4514 struct qeth_ipa_cmd *cmd;
4515 struct qeth_arp_query_info *qinfo;
4516 struct qeth_snmp_cmd *snmp;
4517 unsigned char *data;
4518 __u16 data_len;
4520 QETH_CARD_TEXT(card, 3, "snpcmdcb");
4522 cmd = (struct qeth_ipa_cmd *) sdata;
4523 data = (unsigned char *)((char *)cmd - reply->offset);
4524 qinfo = (struct qeth_arp_query_info *) reply->param;
4525 snmp = &cmd->data.setadapterparms.data.snmp;
4527 if (cmd->hdr.return_code) {
4528 QETH_CARD_TEXT_(card, 4, "scer1%x", cmd->hdr.return_code);
4529 return 0;
4531 if (cmd->data.setadapterparms.hdr.return_code) {
4532 cmd->hdr.return_code =
4533 cmd->data.setadapterparms.hdr.return_code;
4534 QETH_CARD_TEXT_(card, 4, "scer2%x", cmd->hdr.return_code);
4535 return 0;
4537 data_len = *((__u16 *)QETH_IPA_PDU_LEN_PDU1(data));
4538 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4539 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4540 else
4541 data_len -= (__u16)((char *)&snmp->request - (char *)cmd);
4543 /* check if there is enough room in userspace */
4544 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4545 QETH_CARD_TEXT_(card, 4, "scer3%i", -ENOMEM);
4546 cmd->hdr.return_code = IPA_RC_ENOMEM;
4547 return 0;
4549 QETH_CARD_TEXT_(card, 4, "snore%i",
4550 cmd->data.setadapterparms.hdr.used_total);
4551 QETH_CARD_TEXT_(card, 4, "sseqn%i",
4552 cmd->data.setadapterparms.hdr.seq_no);
4553 /*copy entries to user buffer*/
4554 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4555 memcpy(qinfo->udata + qinfo->udata_offset,
4556 (char *)snmp,
4557 data_len + offsetof(struct qeth_snmp_cmd, data));
4558 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4559 } else {
4560 memcpy(qinfo->udata + qinfo->udata_offset,
4561 (char *)&snmp->request, data_len);
4563 qinfo->udata_offset += data_len;
4564 /* check if all replies received ... */
4565 QETH_CARD_TEXT_(card, 4, "srtot%i",
4566 cmd->data.setadapterparms.hdr.used_total);
4567 QETH_CARD_TEXT_(card, 4, "srseq%i",
4568 cmd->data.setadapterparms.hdr.seq_no);
4569 if (cmd->data.setadapterparms.hdr.seq_no <
4570 cmd->data.setadapterparms.hdr.used_total)
4571 return 1;
4572 return 0;
4575 int qeth_snmp_command(struct qeth_card *card, char __user *udata)
4577 struct qeth_cmd_buffer *iob;
4578 struct qeth_ipa_cmd *cmd;
4579 struct qeth_snmp_ureq *ureq;
4580 unsigned int req_len;
4581 struct qeth_arp_query_info qinfo = {0, };
4582 int rc = 0;
4584 QETH_CARD_TEXT(card, 3, "snmpcmd");
4586 if (card->info.guestlan)
4587 return -EOPNOTSUPP;
4589 if ((!qeth_adp_supported(card, IPA_SETADP_SET_SNMP_CONTROL)) &&
4590 (!card->options.layer2)) {
4591 return -EOPNOTSUPP;
4593 /* skip 4 bytes (data_len struct member) to get req_len */
4594 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4595 return -EFAULT;
4596 if (req_len > (QETH_BUFSIZE - IPA_PDU_HEADER_SIZE -
4597 sizeof(struct qeth_ipacmd_hdr) -
4598 sizeof(struct qeth_ipacmd_setadpparms_hdr)))
4599 return -EINVAL;
4600 ureq = memdup_user(udata, req_len + sizeof(struct qeth_snmp_ureq_hdr));
4601 if (IS_ERR(ureq)) {
4602 QETH_CARD_TEXT(card, 2, "snmpnome");
4603 return PTR_ERR(ureq);
4605 qinfo.udata_len = ureq->hdr.data_len;
4606 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
4607 if (!qinfo.udata) {
4608 kfree(ureq);
4609 return -ENOMEM;
4611 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4613 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
4614 QETH_SNMP_SETADP_CMDLENGTH + req_len);
4615 if (!iob) {
4616 rc = -ENOMEM;
4617 goto out;
4619 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4620 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
4621 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
4622 qeth_snmp_command_cb, (void *)&qinfo);
4623 if (rc)
4624 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
4625 QETH_CARD_IFNAME(card), rc);
4626 else {
4627 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4628 rc = -EFAULT;
4630 out:
4631 kfree(ureq);
4632 kfree(qinfo.udata);
4633 return rc;
4635 EXPORT_SYMBOL_GPL(qeth_snmp_command);
4637 static int qeth_setadpparms_query_oat_cb(struct qeth_card *card,
4638 struct qeth_reply *reply, unsigned long data)
4640 struct qeth_ipa_cmd *cmd;
4641 struct qeth_qoat_priv *priv;
4642 char *resdata;
4643 int resdatalen;
4645 QETH_CARD_TEXT(card, 3, "qoatcb");
4647 cmd = (struct qeth_ipa_cmd *)data;
4648 priv = (struct qeth_qoat_priv *)reply->param;
4649 resdatalen = cmd->data.setadapterparms.hdr.cmdlength;
4650 resdata = (char *)data + 28;
4652 if (resdatalen > (priv->buffer_len - priv->response_len)) {
4653 cmd->hdr.return_code = IPA_RC_FFFF;
4654 return 0;
4657 memcpy((priv->buffer + priv->response_len), resdata,
4658 resdatalen);
4659 priv->response_len += resdatalen;
4661 if (cmd->data.setadapterparms.hdr.seq_no <
4662 cmd->data.setadapterparms.hdr.used_total)
4663 return 1;
4664 return 0;
4667 int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
4669 int rc = 0;
4670 struct qeth_cmd_buffer *iob;
4671 struct qeth_ipa_cmd *cmd;
4672 struct qeth_query_oat *oat_req;
4673 struct qeth_query_oat_data oat_data;
4674 struct qeth_qoat_priv priv;
4675 void __user *tmp;
4677 QETH_CARD_TEXT(card, 3, "qoatcmd");
4679 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_OAT)) {
4680 rc = -EOPNOTSUPP;
4681 goto out;
4684 if (copy_from_user(&oat_data, udata,
4685 sizeof(struct qeth_query_oat_data))) {
4686 rc = -EFAULT;
4687 goto out;
4690 priv.buffer_len = oat_data.buffer_len;
4691 priv.response_len = 0;
4692 priv.buffer = kzalloc(oat_data.buffer_len, GFP_KERNEL);
4693 if (!priv.buffer) {
4694 rc = -ENOMEM;
4695 goto out;
4698 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_OAT,
4699 sizeof(struct qeth_ipacmd_setadpparms_hdr) +
4700 sizeof(struct qeth_query_oat));
4701 if (!iob) {
4702 rc = -ENOMEM;
4703 goto out_free;
4705 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4706 oat_req = &cmd->data.setadapterparms.data.query_oat;
4707 oat_req->subcmd_code = oat_data.command;
4709 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_query_oat_cb,
4710 &priv);
4711 if (!rc) {
4712 if (is_compat_task())
4713 tmp = compat_ptr(oat_data.ptr);
4714 else
4715 tmp = (void __user *)(unsigned long)oat_data.ptr;
4717 if (copy_to_user(tmp, priv.buffer,
4718 priv.response_len)) {
4719 rc = -EFAULT;
4720 goto out_free;
4723 oat_data.response_len = priv.response_len;
4725 if (copy_to_user(udata, &oat_data,
4726 sizeof(struct qeth_query_oat_data)))
4727 rc = -EFAULT;
4728 } else
4729 if (rc == IPA_RC_FFFF)
4730 rc = -EFAULT;
4732 out_free:
4733 kfree(priv.buffer);
4734 out:
4735 return rc;
4737 EXPORT_SYMBOL_GPL(qeth_query_oat_command);
4739 static int qeth_query_card_info_cb(struct qeth_card *card,
4740 struct qeth_reply *reply, unsigned long data)
4742 struct qeth_ipa_cmd *cmd;
4743 struct qeth_query_card_info *card_info;
4744 struct carrier_info *carrier_info;
4746 QETH_CARD_TEXT(card, 2, "qcrdincb");
4747 carrier_info = (struct carrier_info *)reply->param;
4748 cmd = (struct qeth_ipa_cmd *)data;
4749 card_info = &cmd->data.setadapterparms.data.card_info;
4750 if (cmd->data.setadapterparms.hdr.return_code == 0) {
4751 carrier_info->card_type = card_info->card_type;
4752 carrier_info->port_mode = card_info->port_mode;
4753 carrier_info->port_speed = card_info->port_speed;
4756 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
4757 return 0;
4760 static int qeth_query_card_info(struct qeth_card *card,
4761 struct carrier_info *carrier_info)
4763 struct qeth_cmd_buffer *iob;
4765 QETH_CARD_TEXT(card, 2, "qcrdinfo");
4766 if (!qeth_adp_supported(card, IPA_SETADP_QUERY_CARD_INFO))
4767 return -EOPNOTSUPP;
4768 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_CARD_INFO,
4769 sizeof(struct qeth_ipacmd_setadpparms_hdr));
4770 if (!iob)
4771 return -ENOMEM;
4772 return qeth_send_ipa_cmd(card, iob, qeth_query_card_info_cb,
4773 (void *)carrier_info);
4776 static inline int qeth_get_qdio_q_format(struct qeth_card *card)
4778 switch (card->info.type) {
4779 case QETH_CARD_TYPE_IQD:
4780 return 2;
4781 default:
4782 return 0;
4786 static void qeth_determine_capabilities(struct qeth_card *card)
4788 int rc;
4789 int length;
4790 char *prcd;
4791 struct ccw_device *ddev;
4792 int ddev_offline = 0;
4794 QETH_DBF_TEXT(SETUP, 2, "detcapab");
4795 ddev = CARD_DDEV(card);
4796 if (!ddev->online) {
4797 ddev_offline = 1;
4798 rc = ccw_device_set_online(ddev);
4799 if (rc) {
4800 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
4801 goto out;
4805 rc = qeth_read_conf_data(card, (void **) &prcd, &length);
4806 if (rc) {
4807 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
4808 dev_name(&card->gdev->dev), rc);
4809 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
4810 goto out_offline;
4812 qeth_configure_unitaddr(card, prcd);
4813 if (ddev_offline)
4814 qeth_configure_blkt_default(card, prcd);
4815 kfree(prcd);
4817 rc = qdio_get_ssqd_desc(ddev, &card->ssqd);
4818 if (rc)
4819 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
4821 QETH_DBF_TEXT_(SETUP, 2, "qfmt%d", card->ssqd.qfmt);
4822 QETH_DBF_TEXT_(SETUP, 2, "%d", card->ssqd.qdioac1);
4823 QETH_DBF_TEXT_(SETUP, 2, "%d", card->ssqd.qdioac3);
4824 QETH_DBF_TEXT_(SETUP, 2, "icnt%d", card->ssqd.icnt);
4825 if (!((card->ssqd.qfmt != QDIO_IQDIO_QFMT) ||
4826 ((card->ssqd.qdioac1 & CHSC_AC1_INITIATE_INPUTQ) == 0) ||
4827 ((card->ssqd.qdioac3 & CHSC_AC3_FORMAT2_CQ_AVAILABLE) == 0))) {
4828 dev_info(&card->gdev->dev,
4829 "Completion Queueing supported\n");
4830 } else {
4831 card->options.cq = QETH_CQ_NOTAVAILABLE;
4835 out_offline:
4836 if (ddev_offline == 1)
4837 ccw_device_set_offline(ddev);
4838 out:
4839 return;
4842 static inline void qeth_qdio_establish_cq(struct qeth_card *card,
4843 struct qdio_buffer **in_sbal_ptrs,
4844 void (**queue_start_poll) (struct ccw_device *, int, unsigned long)) {
4845 int i;
4847 if (card->options.cq == QETH_CQ_ENABLED) {
4848 int offset = QDIO_MAX_BUFFERS_PER_Q *
4849 (card->qdio.no_in_queues - 1);
4850 i = QDIO_MAX_BUFFERS_PER_Q * (card->qdio.no_in_queues - 1);
4851 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) {
4852 in_sbal_ptrs[offset + i] = (struct qdio_buffer *)
4853 virt_to_phys(card->qdio.c_q->bufs[i].buffer);
4856 queue_start_poll[card->qdio.no_in_queues - 1] = NULL;
4860 static int qeth_qdio_establish(struct qeth_card *card)
4862 struct qdio_initialize init_data;
4863 char *qib_param_field;
4864 struct qdio_buffer **in_sbal_ptrs;
4865 void (**queue_start_poll) (struct ccw_device *, int, unsigned long);
4866 struct qdio_buffer **out_sbal_ptrs;
4867 int i, j, k;
4868 int rc = 0;
4870 QETH_DBF_TEXT(SETUP, 2, "qdioest");
4872 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
4873 GFP_KERNEL);
4874 if (!qib_param_field) {
4875 rc = -ENOMEM;
4876 goto out_free_nothing;
4879 qeth_create_qib_param_field(card, qib_param_field);
4880 qeth_create_qib_param_field_blkt(card, qib_param_field);
4882 in_sbal_ptrs = kzalloc(card->qdio.no_in_queues *
4883 QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
4884 GFP_KERNEL);
4885 if (!in_sbal_ptrs) {
4886 rc = -ENOMEM;
4887 goto out_free_qib_param;
4889 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) {
4890 in_sbal_ptrs[i] = (struct qdio_buffer *)
4891 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
4894 queue_start_poll = kzalloc(sizeof(void *) * card->qdio.no_in_queues,
4895 GFP_KERNEL);
4896 if (!queue_start_poll) {
4897 rc = -ENOMEM;
4898 goto out_free_in_sbals;
4900 for (i = 0; i < card->qdio.no_in_queues; ++i)
4901 queue_start_poll[i] = card->discipline->start_poll;
4903 qeth_qdio_establish_cq(card, in_sbal_ptrs, queue_start_poll);
4905 out_sbal_ptrs =
4906 kzalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
4907 sizeof(void *), GFP_KERNEL);
4908 if (!out_sbal_ptrs) {
4909 rc = -ENOMEM;
4910 goto out_free_queue_start_poll;
4912 for (i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
4913 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k) {
4914 out_sbal_ptrs[k] = (struct qdio_buffer *)virt_to_phys(
4915 card->qdio.out_qs[i]->bufs[j]->buffer);
4918 memset(&init_data, 0, sizeof(struct qdio_initialize));
4919 init_data.cdev = CARD_DDEV(card);
4920 init_data.q_format = qeth_get_qdio_q_format(card);
4921 init_data.qib_param_field_format = 0;
4922 init_data.qib_param_field = qib_param_field;
4923 init_data.no_input_qs = card->qdio.no_in_queues;
4924 init_data.no_output_qs = card->qdio.no_out_queues;
4925 init_data.input_handler = card->discipline->input_handler;
4926 init_data.output_handler = card->discipline->output_handler;
4927 init_data.queue_start_poll_array = queue_start_poll;
4928 init_data.int_parm = (unsigned long) card;
4929 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
4930 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
4931 init_data.output_sbal_state_array = card->qdio.out_bufstates;
4932 init_data.scan_threshold =
4933 (card->info.type == QETH_CARD_TYPE_IQD) ? 1 : 32;
4935 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
4936 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
4937 rc = qdio_allocate(&init_data);
4938 if (rc) {
4939 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
4940 goto out;
4942 rc = qdio_establish(&init_data);
4943 if (rc) {
4944 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
4945 qdio_free(CARD_DDEV(card));
4949 switch (card->options.cq) {
4950 case QETH_CQ_ENABLED:
4951 dev_info(&card->gdev->dev, "Completion Queue support enabled");
4952 break;
4953 case QETH_CQ_DISABLED:
4954 dev_info(&card->gdev->dev, "Completion Queue support disabled");
4955 break;
4956 default:
4957 break;
4959 out:
4960 kfree(out_sbal_ptrs);
4961 out_free_queue_start_poll:
4962 kfree(queue_start_poll);
4963 out_free_in_sbals:
4964 kfree(in_sbal_ptrs);
4965 out_free_qib_param:
4966 kfree(qib_param_field);
4967 out_free_nothing:
4968 return rc;
4971 static void qeth_core_free_card(struct qeth_card *card)
4974 QETH_DBF_TEXT(SETUP, 2, "freecrd");
4975 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
4976 qeth_clean_channel(&card->read);
4977 qeth_clean_channel(&card->write);
4978 if (card->dev)
4979 free_netdev(card->dev);
4980 qeth_free_qdio_buffers(card);
4981 unregister_service_level(&card->qeth_service_level);
4982 kfree(card);
4985 void qeth_trace_features(struct qeth_card *card)
4987 QETH_CARD_TEXT(card, 2, "features");
4988 QETH_CARD_HEX(card, 2, &card->options.ipa4, sizeof(card->options.ipa4));
4989 QETH_CARD_HEX(card, 2, &card->options.ipa6, sizeof(card->options.ipa6));
4990 QETH_CARD_HEX(card, 2, &card->options.adp, sizeof(card->options.adp));
4991 QETH_CARD_HEX(card, 2, &card->info.diagass_support,
4992 sizeof(card->info.diagass_support));
4994 EXPORT_SYMBOL_GPL(qeth_trace_features);
4996 static struct ccw_device_id qeth_ids[] = {
4997 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
4998 .driver_info = QETH_CARD_TYPE_OSD},
4999 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
5000 .driver_info = QETH_CARD_TYPE_IQD},
5001 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
5002 .driver_info = QETH_CARD_TYPE_OSN},
5003 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
5004 .driver_info = QETH_CARD_TYPE_OSM},
5005 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
5006 .driver_info = QETH_CARD_TYPE_OSX},
5009 MODULE_DEVICE_TABLE(ccw, qeth_ids);
5011 static struct ccw_driver qeth_ccw_driver = {
5012 .driver = {
5013 .owner = THIS_MODULE,
5014 .name = "qeth",
5016 .ids = qeth_ids,
5017 .probe = ccwgroup_probe_ccwdev,
5018 .remove = ccwgroup_remove_ccwdev,
5021 int qeth_core_hardsetup_card(struct qeth_card *card)
5023 int retries = 3;
5024 int rc;
5026 QETH_DBF_TEXT(SETUP, 2, "hrdsetup");
5027 atomic_set(&card->force_alloc_skb, 0);
5028 qeth_update_from_chp_desc(card);
5029 retry:
5030 if (retries < 3)
5031 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
5032 dev_name(&card->gdev->dev));
5033 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
5034 ccw_device_set_offline(CARD_DDEV(card));
5035 ccw_device_set_offline(CARD_WDEV(card));
5036 ccw_device_set_offline(CARD_RDEV(card));
5037 qdio_free(CARD_DDEV(card));
5038 rc = ccw_device_set_online(CARD_RDEV(card));
5039 if (rc)
5040 goto retriable;
5041 rc = ccw_device_set_online(CARD_WDEV(card));
5042 if (rc)
5043 goto retriable;
5044 rc = ccw_device_set_online(CARD_DDEV(card));
5045 if (rc)
5046 goto retriable;
5047 retriable:
5048 if (rc == -ERESTARTSYS) {
5049 QETH_DBF_TEXT(SETUP, 2, "break1");
5050 return rc;
5051 } else if (rc) {
5052 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
5053 if (--retries < 0)
5054 goto out;
5055 else
5056 goto retry;
5058 qeth_determine_capabilities(card);
5059 qeth_init_tokens(card);
5060 qeth_init_func_level(card);
5061 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
5062 if (rc == -ERESTARTSYS) {
5063 QETH_DBF_TEXT(SETUP, 2, "break2");
5064 return rc;
5065 } else if (rc) {
5066 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
5067 if (--retries < 0)
5068 goto out;
5069 else
5070 goto retry;
5072 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
5073 if (rc == -ERESTARTSYS) {
5074 QETH_DBF_TEXT(SETUP, 2, "break3");
5075 return rc;
5076 } else if (rc) {
5077 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
5078 if (--retries < 0)
5079 goto out;
5080 else
5081 goto retry;
5083 card->read_or_write_problem = 0;
5084 rc = qeth_mpc_initialize(card);
5085 if (rc) {
5086 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
5087 goto out;
5090 card->options.ipa4.supported_funcs = 0;
5091 card->options.ipa6.supported_funcs = 0;
5092 card->options.adp.supported_funcs = 0;
5093 card->options.sbp.supported_funcs = 0;
5094 card->info.diagass_support = 0;
5095 rc = qeth_query_ipassists(card, QETH_PROT_IPV4);
5096 if (rc == -ENOMEM)
5097 goto out;
5098 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
5099 rc = qeth_query_setadapterparms(card);
5100 if (rc < 0) {
5101 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
5102 goto out;
5105 if (qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
5106 rc = qeth_query_setdiagass(card);
5107 if (rc < 0) {
5108 QETH_DBF_TEXT_(SETUP, 2, "7err%d", rc);
5109 goto out;
5112 return 0;
5113 out:
5114 dev_warn(&card->gdev->dev, "The qeth device driver failed to recover "
5115 "an error on the device\n");
5116 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
5117 dev_name(&card->gdev->dev), rc);
5118 return rc;
5120 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card);
5122 static inline int qeth_create_skb_frag(struct qeth_qdio_buffer *qethbuffer,
5123 struct qdio_buffer_element *element,
5124 struct sk_buff **pskb, int offset, int *pfrag, int data_len)
5126 struct page *page = virt_to_page(element->addr);
5127 if (*pskb == NULL) {
5128 if (qethbuffer->rx_skb) {
5129 /* only if qeth_card.options.cq == QETH_CQ_ENABLED */
5130 *pskb = qethbuffer->rx_skb;
5131 qethbuffer->rx_skb = NULL;
5132 } else {
5133 *pskb = dev_alloc_skb(QETH_RX_PULL_LEN + ETH_HLEN);
5134 if (!(*pskb))
5135 return -ENOMEM;
5138 skb_reserve(*pskb, ETH_HLEN);
5139 if (data_len <= QETH_RX_PULL_LEN) {
5140 memcpy(skb_put(*pskb, data_len), element->addr + offset,
5141 data_len);
5142 } else {
5143 get_page(page);
5144 memcpy(skb_put(*pskb, QETH_RX_PULL_LEN),
5145 element->addr + offset, QETH_RX_PULL_LEN);
5146 skb_fill_page_desc(*pskb, *pfrag, page,
5147 offset + QETH_RX_PULL_LEN,
5148 data_len - QETH_RX_PULL_LEN);
5149 (*pskb)->data_len += data_len - QETH_RX_PULL_LEN;
5150 (*pskb)->len += data_len - QETH_RX_PULL_LEN;
5151 (*pskb)->truesize += data_len - QETH_RX_PULL_LEN;
5152 (*pfrag)++;
5154 } else {
5155 get_page(page);
5156 skb_fill_page_desc(*pskb, *pfrag, page, offset, data_len);
5157 (*pskb)->data_len += data_len;
5158 (*pskb)->len += data_len;
5159 (*pskb)->truesize += data_len;
5160 (*pfrag)++;
5164 return 0;
5167 static inline int qeth_is_last_sbale(struct qdio_buffer_element *sbale)
5169 return (sbale->eflags & SBAL_EFLAGS_LAST_ENTRY);
5172 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
5173 struct qeth_qdio_buffer *qethbuffer,
5174 struct qdio_buffer_element **__element, int *__offset,
5175 struct qeth_hdr **hdr)
5177 struct qdio_buffer_element *element = *__element;
5178 struct qdio_buffer *buffer = qethbuffer->buffer;
5179 int offset = *__offset;
5180 struct sk_buff *skb = NULL;
5181 int skb_len = 0;
5182 void *data_ptr;
5183 int data_len;
5184 int headroom = 0;
5185 int use_rx_sg = 0;
5186 int frag = 0;
5188 /* qeth_hdr must not cross element boundaries */
5189 if (element->length < offset + sizeof(struct qeth_hdr)) {
5190 if (qeth_is_last_sbale(element))
5191 return NULL;
5192 element++;
5193 offset = 0;
5194 if (element->length < sizeof(struct qeth_hdr))
5195 return NULL;
5197 *hdr = element->addr + offset;
5199 offset += sizeof(struct qeth_hdr);
5200 switch ((*hdr)->hdr.l2.id) {
5201 case QETH_HEADER_TYPE_LAYER2:
5202 skb_len = (*hdr)->hdr.l2.pkt_length;
5203 break;
5204 case QETH_HEADER_TYPE_LAYER3:
5205 skb_len = (*hdr)->hdr.l3.length;
5206 headroom = ETH_HLEN;
5207 break;
5208 case QETH_HEADER_TYPE_OSN:
5209 skb_len = (*hdr)->hdr.osn.pdu_length;
5210 headroom = sizeof(struct qeth_hdr);
5211 break;
5212 default:
5213 break;
5216 if (!skb_len)
5217 return NULL;
5219 if (((skb_len >= card->options.rx_sg_cb) &&
5220 (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
5221 (!atomic_read(&card->force_alloc_skb))) ||
5222 (card->options.cq == QETH_CQ_ENABLED)) {
5223 use_rx_sg = 1;
5224 } else {
5225 skb = dev_alloc_skb(skb_len + headroom);
5226 if (!skb)
5227 goto no_mem;
5228 if (headroom)
5229 skb_reserve(skb, headroom);
5232 data_ptr = element->addr + offset;
5233 while (skb_len) {
5234 data_len = min(skb_len, (int)(element->length - offset));
5235 if (data_len) {
5236 if (use_rx_sg) {
5237 if (qeth_create_skb_frag(qethbuffer, element,
5238 &skb, offset, &frag, data_len))
5239 goto no_mem;
5240 } else {
5241 memcpy(skb_put(skb, data_len), data_ptr,
5242 data_len);
5245 skb_len -= data_len;
5246 if (skb_len) {
5247 if (qeth_is_last_sbale(element)) {
5248 QETH_CARD_TEXT(card, 4, "unexeob");
5249 QETH_CARD_HEX(card, 2, buffer, sizeof(void *));
5250 dev_kfree_skb_any(skb);
5251 card->stats.rx_errors++;
5252 return NULL;
5254 element++;
5255 offset = 0;
5256 data_ptr = element->addr;
5257 } else {
5258 offset += data_len;
5261 *__element = element;
5262 *__offset = offset;
5263 if (use_rx_sg && card->options.performance_stats) {
5264 card->perf_stats.sg_skbs_rx++;
5265 card->perf_stats.sg_frags_rx += skb_shinfo(skb)->nr_frags;
5267 return skb;
5268 no_mem:
5269 if (net_ratelimit()) {
5270 QETH_CARD_TEXT(card, 2, "noskbmem");
5272 card->stats.rx_dropped++;
5273 return NULL;
5275 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb);
5277 int qeth_setassparms_cb(struct qeth_card *card,
5278 struct qeth_reply *reply, unsigned long data)
5280 struct qeth_ipa_cmd *cmd;
5282 QETH_CARD_TEXT(card, 4, "defadpcb");
5284 cmd = (struct qeth_ipa_cmd *) data;
5285 if (cmd->hdr.return_code == 0) {
5286 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
5287 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
5288 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
5289 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
5290 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
5292 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
5293 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
5294 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
5295 QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
5297 if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
5298 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
5299 card->info.tx_csum_mask =
5300 cmd->data.setassparms.data.flags_32bit;
5301 QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
5304 return 0;
5306 EXPORT_SYMBOL_GPL(qeth_setassparms_cb);
5308 struct qeth_cmd_buffer *qeth_get_setassparms_cmd(struct qeth_card *card,
5309 enum qeth_ipa_funcs ipa_func,
5310 __u16 cmd_code, __u16 len,
5311 enum qeth_prot_versions prot)
5313 struct qeth_cmd_buffer *iob;
5314 struct qeth_ipa_cmd *cmd;
5316 QETH_CARD_TEXT(card, 4, "getasscm");
5317 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
5319 if (iob) {
5320 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5321 cmd->data.setassparms.hdr.assist_no = ipa_func;
5322 cmd->data.setassparms.hdr.length = 8 + len;
5323 cmd->data.setassparms.hdr.command_code = cmd_code;
5324 cmd->data.setassparms.hdr.return_code = 0;
5325 cmd->data.setassparms.hdr.seq_no = 0;
5328 return iob;
5330 EXPORT_SYMBOL_GPL(qeth_get_setassparms_cmd);
5332 int qeth_send_setassparms(struct qeth_card *card,
5333 struct qeth_cmd_buffer *iob, __u16 len, long data,
5334 int (*reply_cb)(struct qeth_card *,
5335 struct qeth_reply *, unsigned long),
5336 void *reply_param)
5338 int rc;
5339 struct qeth_ipa_cmd *cmd;
5341 QETH_CARD_TEXT(card, 4, "sendassp");
5343 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5344 if (len <= sizeof(__u32))
5345 cmd->data.setassparms.data.flags_32bit = (__u32) data;
5346 else /* (len > sizeof(__u32)) */
5347 memcpy(&cmd->data.setassparms.data, (void *) data, len);
5349 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
5350 return rc;
5352 EXPORT_SYMBOL_GPL(qeth_send_setassparms);
5354 int qeth_send_simple_setassparms(struct qeth_card *card,
5355 enum qeth_ipa_funcs ipa_func,
5356 __u16 cmd_code, long data)
5358 int rc;
5359 int length = 0;
5360 struct qeth_cmd_buffer *iob;
5362 QETH_CARD_TEXT(card, 4, "simassp4");
5363 if (data)
5364 length = sizeof(__u32);
5365 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
5366 length, QETH_PROT_IPV4);
5367 if (!iob)
5368 return -ENOMEM;
5369 rc = qeth_send_setassparms(card, iob, length, data,
5370 qeth_setassparms_cb, NULL);
5371 return rc;
5373 EXPORT_SYMBOL_GPL(qeth_send_simple_setassparms);
5375 static void qeth_unregister_dbf_views(void)
5377 int x;
5378 for (x = 0; x < QETH_DBF_INFOS; x++) {
5379 debug_unregister(qeth_dbf[x].id);
5380 qeth_dbf[x].id = NULL;
5384 void qeth_dbf_longtext(debug_info_t *id, int level, char *fmt, ...)
5386 char dbf_txt_buf[32];
5387 va_list args;
5389 if (!debug_level_enabled(id, level))
5390 return;
5391 va_start(args, fmt);
5392 vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
5393 va_end(args);
5394 debug_text_event(id, level, dbf_txt_buf);
5396 EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
5398 static int qeth_register_dbf_views(void)
5400 int ret;
5401 int x;
5403 for (x = 0; x < QETH_DBF_INFOS; x++) {
5404 /* register the areas */
5405 qeth_dbf[x].id = debug_register(qeth_dbf[x].name,
5406 qeth_dbf[x].pages,
5407 qeth_dbf[x].areas,
5408 qeth_dbf[x].len);
5409 if (qeth_dbf[x].id == NULL) {
5410 qeth_unregister_dbf_views();
5411 return -ENOMEM;
5414 /* register a view */
5415 ret = debug_register_view(qeth_dbf[x].id, qeth_dbf[x].view);
5416 if (ret) {
5417 qeth_unregister_dbf_views();
5418 return ret;
5421 /* set a passing level */
5422 debug_set_level(qeth_dbf[x].id, qeth_dbf[x].level);
5425 return 0;
5428 int qeth_core_load_discipline(struct qeth_card *card,
5429 enum qeth_discipline_id discipline)
5431 int rc = 0;
5432 mutex_lock(&qeth_mod_mutex);
5433 switch (discipline) {
5434 case QETH_DISCIPLINE_LAYER3:
5435 card->discipline = try_then_request_module(
5436 symbol_get(qeth_l3_discipline), "qeth_l3");
5437 break;
5438 case QETH_DISCIPLINE_LAYER2:
5439 card->discipline = try_then_request_module(
5440 symbol_get(qeth_l2_discipline), "qeth_l2");
5441 break;
5443 if (!card->discipline) {
5444 dev_err(&card->gdev->dev, "There is no kernel module to "
5445 "support discipline %d\n", discipline);
5446 rc = -EINVAL;
5448 mutex_unlock(&qeth_mod_mutex);
5449 return rc;
5452 void qeth_core_free_discipline(struct qeth_card *card)
5454 if (card->options.layer2)
5455 symbol_put(qeth_l2_discipline);
5456 else
5457 symbol_put(qeth_l3_discipline);
5458 card->discipline = NULL;
5461 static const struct device_type qeth_generic_devtype = {
5462 .name = "qeth_generic",
5463 .groups = qeth_generic_attr_groups,
5465 static const struct device_type qeth_osn_devtype = {
5466 .name = "qeth_osn",
5467 .groups = qeth_osn_attr_groups,
5470 #define DBF_NAME_LEN 20
5472 struct qeth_dbf_entry {
5473 char dbf_name[DBF_NAME_LEN];
5474 debug_info_t *dbf_info;
5475 struct list_head dbf_list;
5478 static LIST_HEAD(qeth_dbf_list);
5479 static DEFINE_MUTEX(qeth_dbf_list_mutex);
5481 static debug_info_t *qeth_get_dbf_entry(char *name)
5483 struct qeth_dbf_entry *entry;
5484 debug_info_t *rc = NULL;
5486 mutex_lock(&qeth_dbf_list_mutex);
5487 list_for_each_entry(entry, &qeth_dbf_list, dbf_list) {
5488 if (strcmp(entry->dbf_name, name) == 0) {
5489 rc = entry->dbf_info;
5490 break;
5493 mutex_unlock(&qeth_dbf_list_mutex);
5494 return rc;
5497 static int qeth_add_dbf_entry(struct qeth_card *card, char *name)
5499 struct qeth_dbf_entry *new_entry;
5501 card->debug = debug_register(name, 2, 1, 8);
5502 if (!card->debug) {
5503 QETH_DBF_TEXT_(SETUP, 2, "%s", "qcdbf");
5504 goto err;
5506 if (debug_register_view(card->debug, &debug_hex_ascii_view))
5507 goto err_dbg;
5508 new_entry = kzalloc(sizeof(struct qeth_dbf_entry), GFP_KERNEL);
5509 if (!new_entry)
5510 goto err_dbg;
5511 strncpy(new_entry->dbf_name, name, DBF_NAME_LEN);
5512 new_entry->dbf_info = card->debug;
5513 mutex_lock(&qeth_dbf_list_mutex);
5514 list_add(&new_entry->dbf_list, &qeth_dbf_list);
5515 mutex_unlock(&qeth_dbf_list_mutex);
5517 return 0;
5519 err_dbg:
5520 debug_unregister(card->debug);
5521 err:
5522 return -ENOMEM;
5525 static void qeth_clear_dbf_list(void)
5527 struct qeth_dbf_entry *entry, *tmp;
5529 mutex_lock(&qeth_dbf_list_mutex);
5530 list_for_each_entry_safe(entry, tmp, &qeth_dbf_list, dbf_list) {
5531 list_del(&entry->dbf_list);
5532 debug_unregister(entry->dbf_info);
5533 kfree(entry);
5535 mutex_unlock(&qeth_dbf_list_mutex);
5538 static int qeth_core_probe_device(struct ccwgroup_device *gdev)
5540 struct qeth_card *card;
5541 struct device *dev;
5542 int rc;
5543 unsigned long flags;
5544 char dbf_name[DBF_NAME_LEN];
5546 QETH_DBF_TEXT(SETUP, 2, "probedev");
5548 dev = &gdev->dev;
5549 if (!get_device(dev))
5550 return -ENODEV;
5552 QETH_DBF_TEXT_(SETUP, 2, "%s", dev_name(&gdev->dev));
5554 card = qeth_alloc_card();
5555 if (!card) {
5556 QETH_DBF_TEXT_(SETUP, 2, "1err%d", -ENOMEM);
5557 rc = -ENOMEM;
5558 goto err_dev;
5561 snprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s",
5562 dev_name(&gdev->dev));
5563 card->debug = qeth_get_dbf_entry(dbf_name);
5564 if (!card->debug) {
5565 rc = qeth_add_dbf_entry(card, dbf_name);
5566 if (rc)
5567 goto err_card;
5570 card->read.ccwdev = gdev->cdev[0];
5571 card->write.ccwdev = gdev->cdev[1];
5572 card->data.ccwdev = gdev->cdev[2];
5573 dev_set_drvdata(&gdev->dev, card);
5574 card->gdev = gdev;
5575 gdev->cdev[0]->handler = qeth_irq;
5576 gdev->cdev[1]->handler = qeth_irq;
5577 gdev->cdev[2]->handler = qeth_irq;
5579 rc = qeth_determine_card_type(card);
5580 if (rc) {
5581 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
5582 goto err_card;
5584 rc = qeth_setup_card(card);
5585 if (rc) {
5586 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
5587 goto err_card;
5590 if (card->info.type == QETH_CARD_TYPE_OSN)
5591 gdev->dev.type = &qeth_osn_devtype;
5592 else
5593 gdev->dev.type = &qeth_generic_devtype;
5595 switch (card->info.type) {
5596 case QETH_CARD_TYPE_OSN:
5597 case QETH_CARD_TYPE_OSM:
5598 rc = qeth_core_load_discipline(card, QETH_DISCIPLINE_LAYER2);
5599 if (rc)
5600 goto err_card;
5601 rc = card->discipline->setup(card->gdev);
5602 if (rc)
5603 goto err_disc;
5604 case QETH_CARD_TYPE_OSD:
5605 case QETH_CARD_TYPE_OSX:
5606 default:
5607 break;
5610 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
5611 list_add_tail(&card->list, &qeth_core_card_list.list);
5612 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
5614 qeth_determine_capabilities(card);
5615 return 0;
5617 err_disc:
5618 qeth_core_free_discipline(card);
5619 err_card:
5620 qeth_core_free_card(card);
5621 err_dev:
5622 put_device(dev);
5623 return rc;
5626 static void qeth_core_remove_device(struct ccwgroup_device *gdev)
5628 unsigned long flags;
5629 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5631 QETH_DBF_TEXT(SETUP, 2, "removedv");
5633 if (card->discipline) {
5634 card->discipline->remove(gdev);
5635 qeth_core_free_discipline(card);
5638 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
5639 list_del(&card->list);
5640 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
5641 qeth_core_free_card(card);
5642 dev_set_drvdata(&gdev->dev, NULL);
5643 put_device(&gdev->dev);
5644 return;
5647 static int qeth_core_set_online(struct ccwgroup_device *gdev)
5649 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5650 int rc = 0;
5651 int def_discipline;
5653 if (!card->discipline) {
5654 if (card->info.type == QETH_CARD_TYPE_IQD)
5655 def_discipline = QETH_DISCIPLINE_LAYER3;
5656 else
5657 def_discipline = QETH_DISCIPLINE_LAYER2;
5658 rc = qeth_core_load_discipline(card, def_discipline);
5659 if (rc)
5660 goto err;
5661 rc = card->discipline->setup(card->gdev);
5662 if (rc)
5663 goto err;
5665 rc = card->discipline->set_online(gdev);
5666 err:
5667 return rc;
5670 static int qeth_core_set_offline(struct ccwgroup_device *gdev)
5672 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5673 return card->discipline->set_offline(gdev);
5676 static void qeth_core_shutdown(struct ccwgroup_device *gdev)
5678 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5679 if (card->discipline && card->discipline->shutdown)
5680 card->discipline->shutdown(gdev);
5683 static int qeth_core_prepare(struct ccwgroup_device *gdev)
5685 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5686 if (card->discipline && card->discipline->prepare)
5687 return card->discipline->prepare(gdev);
5688 return 0;
5691 static void qeth_core_complete(struct ccwgroup_device *gdev)
5693 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5694 if (card->discipline && card->discipline->complete)
5695 card->discipline->complete(gdev);
5698 static int qeth_core_freeze(struct ccwgroup_device *gdev)
5700 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5701 if (card->discipline && card->discipline->freeze)
5702 return card->discipline->freeze(gdev);
5703 return 0;
5706 static int qeth_core_thaw(struct ccwgroup_device *gdev)
5708 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5709 if (card->discipline && card->discipline->thaw)
5710 return card->discipline->thaw(gdev);
5711 return 0;
5714 static int qeth_core_restore(struct ccwgroup_device *gdev)
5716 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5717 if (card->discipline && card->discipline->restore)
5718 return card->discipline->restore(gdev);
5719 return 0;
5722 static struct ccwgroup_driver qeth_core_ccwgroup_driver = {
5723 .driver = {
5724 .owner = THIS_MODULE,
5725 .name = "qeth",
5727 .setup = qeth_core_probe_device,
5728 .remove = qeth_core_remove_device,
5729 .set_online = qeth_core_set_online,
5730 .set_offline = qeth_core_set_offline,
5731 .shutdown = qeth_core_shutdown,
5732 .prepare = qeth_core_prepare,
5733 .complete = qeth_core_complete,
5734 .freeze = qeth_core_freeze,
5735 .thaw = qeth_core_thaw,
5736 .restore = qeth_core_restore,
5739 static ssize_t qeth_core_driver_group_store(struct device_driver *ddrv,
5740 const char *buf, size_t count)
5742 int err;
5744 err = ccwgroup_create_dev(qeth_core_root_dev,
5745 &qeth_core_ccwgroup_driver, 3, buf);
5747 return err ? err : count;
5749 static DRIVER_ATTR(group, 0200, NULL, qeth_core_driver_group_store);
5751 static struct attribute *qeth_drv_attrs[] = {
5752 &driver_attr_group.attr,
5753 NULL,
5755 static struct attribute_group qeth_drv_attr_group = {
5756 .attrs = qeth_drv_attrs,
5758 static const struct attribute_group *qeth_drv_attr_groups[] = {
5759 &qeth_drv_attr_group,
5760 NULL,
5763 static struct {
5764 const char str[ETH_GSTRING_LEN];
5765 } qeth_ethtool_stats_keys[] = {
5766 /* 0 */{"rx skbs"},
5767 {"rx buffers"},
5768 {"tx skbs"},
5769 {"tx buffers"},
5770 {"tx skbs no packing"},
5771 {"tx buffers no packing"},
5772 {"tx skbs packing"},
5773 {"tx buffers packing"},
5774 {"tx sg skbs"},
5775 {"tx sg frags"},
5776 /* 10 */{"rx sg skbs"},
5777 {"rx sg frags"},
5778 {"rx sg page allocs"},
5779 {"tx large kbytes"},
5780 {"tx large count"},
5781 {"tx pk state ch n->p"},
5782 {"tx pk state ch p->n"},
5783 {"tx pk watermark low"},
5784 {"tx pk watermark high"},
5785 {"queue 0 buffer usage"},
5786 /* 20 */{"queue 1 buffer usage"},
5787 {"queue 2 buffer usage"},
5788 {"queue 3 buffer usage"},
5789 {"rx poll time"},
5790 {"rx poll count"},
5791 {"rx do_QDIO time"},
5792 {"rx do_QDIO count"},
5793 {"tx handler time"},
5794 {"tx handler count"},
5795 {"tx time"},
5796 /* 30 */{"tx count"},
5797 {"tx do_QDIO time"},
5798 {"tx do_QDIO count"},
5799 {"tx csum"},
5800 {"tx lin"},
5801 {"tx linfail"},
5802 {"cq handler count"},
5803 {"cq handler time"}
5806 int qeth_core_get_sset_count(struct net_device *dev, int stringset)
5808 switch (stringset) {
5809 case ETH_SS_STATS:
5810 return (sizeof(qeth_ethtool_stats_keys) / ETH_GSTRING_LEN);
5811 default:
5812 return -EINVAL;
5815 EXPORT_SYMBOL_GPL(qeth_core_get_sset_count);
5817 void qeth_core_get_ethtool_stats(struct net_device *dev,
5818 struct ethtool_stats *stats, u64 *data)
5820 struct qeth_card *card = dev->ml_priv;
5821 data[0] = card->stats.rx_packets -
5822 card->perf_stats.initial_rx_packets;
5823 data[1] = card->perf_stats.bufs_rec;
5824 data[2] = card->stats.tx_packets -
5825 card->perf_stats.initial_tx_packets;
5826 data[3] = card->perf_stats.bufs_sent;
5827 data[4] = card->stats.tx_packets - card->perf_stats.initial_tx_packets
5828 - card->perf_stats.skbs_sent_pack;
5829 data[5] = card->perf_stats.bufs_sent - card->perf_stats.bufs_sent_pack;
5830 data[6] = card->perf_stats.skbs_sent_pack;
5831 data[7] = card->perf_stats.bufs_sent_pack;
5832 data[8] = card->perf_stats.sg_skbs_sent;
5833 data[9] = card->perf_stats.sg_frags_sent;
5834 data[10] = card->perf_stats.sg_skbs_rx;
5835 data[11] = card->perf_stats.sg_frags_rx;
5836 data[12] = card->perf_stats.sg_alloc_page_rx;
5837 data[13] = (card->perf_stats.large_send_bytes >> 10);
5838 data[14] = card->perf_stats.large_send_cnt;
5839 data[15] = card->perf_stats.sc_dp_p;
5840 data[16] = card->perf_stats.sc_p_dp;
5841 data[17] = QETH_LOW_WATERMARK_PACK;
5842 data[18] = QETH_HIGH_WATERMARK_PACK;
5843 data[19] = atomic_read(&card->qdio.out_qs[0]->used_buffers);
5844 data[20] = (card->qdio.no_out_queues > 1) ?
5845 atomic_read(&card->qdio.out_qs[1]->used_buffers) : 0;
5846 data[21] = (card->qdio.no_out_queues > 2) ?
5847 atomic_read(&card->qdio.out_qs[2]->used_buffers) : 0;
5848 data[22] = (card->qdio.no_out_queues > 3) ?
5849 atomic_read(&card->qdio.out_qs[3]->used_buffers) : 0;
5850 data[23] = card->perf_stats.inbound_time;
5851 data[24] = card->perf_stats.inbound_cnt;
5852 data[25] = card->perf_stats.inbound_do_qdio_time;
5853 data[26] = card->perf_stats.inbound_do_qdio_cnt;
5854 data[27] = card->perf_stats.outbound_handler_time;
5855 data[28] = card->perf_stats.outbound_handler_cnt;
5856 data[29] = card->perf_stats.outbound_time;
5857 data[30] = card->perf_stats.outbound_cnt;
5858 data[31] = card->perf_stats.outbound_do_qdio_time;
5859 data[32] = card->perf_stats.outbound_do_qdio_cnt;
5860 data[33] = card->perf_stats.tx_csum;
5861 data[34] = card->perf_stats.tx_lin;
5862 data[35] = card->perf_stats.tx_linfail;
5863 data[36] = card->perf_stats.cq_cnt;
5864 data[37] = card->perf_stats.cq_time;
5866 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats);
5868 void qeth_core_get_strings(struct net_device *dev, u32 stringset, u8 *data)
5870 switch (stringset) {
5871 case ETH_SS_STATS:
5872 memcpy(data, &qeth_ethtool_stats_keys,
5873 sizeof(qeth_ethtool_stats_keys));
5874 break;
5875 default:
5876 WARN_ON(1);
5877 break;
5880 EXPORT_SYMBOL_GPL(qeth_core_get_strings);
5882 void qeth_core_get_drvinfo(struct net_device *dev,
5883 struct ethtool_drvinfo *info)
5885 struct qeth_card *card = dev->ml_priv;
5887 strlcpy(info->driver, card->options.layer2 ? "qeth_l2" : "qeth_l3",
5888 sizeof(info->driver));
5889 strlcpy(info->version, "1.0", sizeof(info->version));
5890 strlcpy(info->fw_version, card->info.mcl_level,
5891 sizeof(info->fw_version));
5892 snprintf(info->bus_info, sizeof(info->bus_info), "%s/%s/%s",
5893 CARD_RDEV_ID(card), CARD_WDEV_ID(card), CARD_DDEV_ID(card));
5895 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo);
5897 /* Helper function to fill 'advertizing' and 'supported' which are the same. */
5898 /* Autoneg and full-duplex are supported and advertized uncondionally. */
5899 /* Always advertize and support all speeds up to specified, and only one */
5900 /* specified port type. */
5901 static void qeth_set_ecmd_adv_sup(struct ethtool_cmd *ecmd,
5902 int maxspeed, int porttype)
5904 int port_sup, port_adv, spd_sup, spd_adv;
5906 switch (porttype) {
5907 case PORT_TP:
5908 port_sup = SUPPORTED_TP;
5909 port_adv = ADVERTISED_TP;
5910 break;
5911 case PORT_FIBRE:
5912 port_sup = SUPPORTED_FIBRE;
5913 port_adv = ADVERTISED_FIBRE;
5914 break;
5915 default:
5916 port_sup = SUPPORTED_TP;
5917 port_adv = ADVERTISED_TP;
5918 WARN_ON_ONCE(1);
5921 /* "Fallthrough" case'es ordered from high to low result in setting */
5922 /* flags cumulatively, starting from the specified speed and down to */
5923 /* the lowest possible. */
5924 spd_sup = 0;
5925 spd_adv = 0;
5926 switch (maxspeed) {
5927 case SPEED_10000:
5928 spd_sup |= SUPPORTED_10000baseT_Full;
5929 spd_adv |= ADVERTISED_10000baseT_Full;
5930 case SPEED_1000:
5931 spd_sup |= SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full;
5932 spd_adv |= ADVERTISED_1000baseT_Half |
5933 ADVERTISED_1000baseT_Full;
5934 case SPEED_100:
5935 spd_sup |= SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full;
5936 spd_adv |= ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
5937 case SPEED_10:
5938 spd_sup |= SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full;
5939 spd_adv |= ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full;
5940 break;
5941 default:
5942 spd_sup = SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full;
5943 spd_adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full;
5944 WARN_ON_ONCE(1);
5946 ecmd->advertising = ADVERTISED_Autoneg | port_adv | spd_adv;
5947 ecmd->supported = SUPPORTED_Autoneg | port_sup | spd_sup;
5950 int qeth_core_ethtool_get_settings(struct net_device *netdev,
5951 struct ethtool_cmd *ecmd)
5953 struct qeth_card *card = netdev->ml_priv;
5954 enum qeth_link_types link_type;
5955 struct carrier_info carrier_info;
5956 int rc;
5957 u32 speed;
5959 if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan))
5960 link_type = QETH_LINK_TYPE_10GBIT_ETH;
5961 else
5962 link_type = card->info.link_type;
5964 ecmd->transceiver = XCVR_INTERNAL;
5965 ecmd->duplex = DUPLEX_FULL;
5966 ecmd->autoneg = AUTONEG_ENABLE;
5968 switch (link_type) {
5969 case QETH_LINK_TYPE_FAST_ETH:
5970 case QETH_LINK_TYPE_LANE_ETH100:
5971 qeth_set_ecmd_adv_sup(ecmd, SPEED_100, PORT_TP);
5972 speed = SPEED_100;
5973 ecmd->port = PORT_TP;
5974 break;
5976 case QETH_LINK_TYPE_GBIT_ETH:
5977 case QETH_LINK_TYPE_LANE_ETH1000:
5978 qeth_set_ecmd_adv_sup(ecmd, SPEED_1000, PORT_FIBRE);
5979 speed = SPEED_1000;
5980 ecmd->port = PORT_FIBRE;
5981 break;
5983 case QETH_LINK_TYPE_10GBIT_ETH:
5984 qeth_set_ecmd_adv_sup(ecmd, SPEED_10000, PORT_FIBRE);
5985 speed = SPEED_10000;
5986 ecmd->port = PORT_FIBRE;
5987 break;
5989 default:
5990 qeth_set_ecmd_adv_sup(ecmd, SPEED_10, PORT_TP);
5991 speed = SPEED_10;
5992 ecmd->port = PORT_TP;
5994 ethtool_cmd_speed_set(ecmd, speed);
5996 /* Check if we can obtain more accurate information. */
5997 /* If QUERY_CARD_INFO command is not supported or fails, */
5998 /* just return the heuristics that was filled above. */
5999 if (!qeth_card_hw_is_reachable(card))
6000 return -ENODEV;
6001 rc = qeth_query_card_info(card, &carrier_info);
6002 if (rc == -EOPNOTSUPP) /* for old hardware, return heuristic */
6003 return 0;
6004 if (rc) /* report error from the hardware operation */
6005 return rc;
6006 /* on success, fill in the information got from the hardware */
6008 netdev_dbg(netdev,
6009 "card info: card_type=0x%02x, port_mode=0x%04x, port_speed=0x%08x\n",
6010 carrier_info.card_type,
6011 carrier_info.port_mode,
6012 carrier_info.port_speed);
6014 /* Update attributes for which we've obtained more authoritative */
6015 /* information, leave the rest the way they where filled above. */
6016 switch (carrier_info.card_type) {
6017 case CARD_INFO_TYPE_1G_COPPER_A:
6018 case CARD_INFO_TYPE_1G_COPPER_B:
6019 qeth_set_ecmd_adv_sup(ecmd, SPEED_1000, PORT_TP);
6020 ecmd->port = PORT_TP;
6021 break;
6022 case CARD_INFO_TYPE_1G_FIBRE_A:
6023 case CARD_INFO_TYPE_1G_FIBRE_B:
6024 qeth_set_ecmd_adv_sup(ecmd, SPEED_1000, PORT_FIBRE);
6025 ecmd->port = PORT_FIBRE;
6026 break;
6027 case CARD_INFO_TYPE_10G_FIBRE_A:
6028 case CARD_INFO_TYPE_10G_FIBRE_B:
6029 qeth_set_ecmd_adv_sup(ecmd, SPEED_10000, PORT_FIBRE);
6030 ecmd->port = PORT_FIBRE;
6031 break;
6034 switch (carrier_info.port_mode) {
6035 case CARD_INFO_PORTM_FULLDUPLEX:
6036 ecmd->duplex = DUPLEX_FULL;
6037 break;
6038 case CARD_INFO_PORTM_HALFDUPLEX:
6039 ecmd->duplex = DUPLEX_HALF;
6040 break;
6043 switch (carrier_info.port_speed) {
6044 case CARD_INFO_PORTS_10M:
6045 speed = SPEED_10;
6046 break;
6047 case CARD_INFO_PORTS_100M:
6048 speed = SPEED_100;
6049 break;
6050 case CARD_INFO_PORTS_1G:
6051 speed = SPEED_1000;
6052 break;
6053 case CARD_INFO_PORTS_10G:
6054 speed = SPEED_10000;
6055 break;
6057 ethtool_cmd_speed_set(ecmd, speed);
6059 return 0;
6061 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings);
6063 static int qeth_send_checksum_on(struct qeth_card *card, int cstype)
6065 long rxtx_arg;
6066 int rc;
6068 rc = qeth_send_simple_setassparms(card, cstype, IPA_CMD_ASS_START, 0);
6069 if (rc) {
6070 dev_warn(&card->gdev->dev,
6071 "Starting HW checksumming for %s failed, using SW checksumming\n",
6072 QETH_CARD_IFNAME(card));
6073 return rc;
6075 rxtx_arg = (cstype == IPA_OUTBOUND_CHECKSUM) ? card->info.tx_csum_mask
6076 : card->info.csum_mask;
6077 rc = qeth_send_simple_setassparms(card, cstype, IPA_CMD_ASS_ENABLE,
6078 rxtx_arg);
6079 if (rc) {
6080 dev_warn(&card->gdev->dev,
6081 "Enabling HW checksumming for %s failed, using SW checksumming\n",
6082 QETH_CARD_IFNAME(card));
6083 return rc;
6086 dev_info(&card->gdev->dev, "HW Checksumming (%sbound) enabled\n",
6087 cstype == IPA_INBOUND_CHECKSUM ? "in" : "out");
6088 return 0;
6091 static int qeth_set_ipa_csum(struct qeth_card *card, int on, int cstype)
6093 int rc;
6095 if (on) {
6096 rc = qeth_send_checksum_on(card, cstype);
6097 if (rc)
6098 return -EIO;
6099 } else {
6100 rc = qeth_send_simple_setassparms(card, cstype,
6101 IPA_CMD_ASS_STOP, 0);
6102 if (rc)
6103 return -EIO;
6105 return 0;
6108 static int qeth_set_ipa_tso(struct qeth_card *card, int on)
6110 int rc;
6112 QETH_CARD_TEXT(card, 3, "sttso");
6114 if (on) {
6115 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
6116 IPA_CMD_ASS_START, 0);
6117 if (rc) {
6118 dev_warn(&card->gdev->dev,
6119 "Starting outbound TCP segmentation offload for %s failed\n",
6120 QETH_CARD_IFNAME(card));
6121 return -EIO;
6123 dev_info(&card->gdev->dev, "Outbound TSO enabled\n");
6124 } else {
6125 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
6126 IPA_CMD_ASS_STOP, 0);
6128 return rc;
6131 /* try to restore device features on a device after recovery */
6132 int qeth_recover_features(struct net_device *dev)
6134 struct qeth_card *card = dev->ml_priv;
6135 netdev_features_t recover = dev->features;
6137 if (recover & NETIF_F_IP_CSUM) {
6138 if (qeth_set_ipa_csum(card, 1, IPA_OUTBOUND_CHECKSUM))
6139 recover ^= NETIF_F_IP_CSUM;
6141 if (recover & NETIF_F_RXCSUM) {
6142 if (qeth_set_ipa_csum(card, 1, IPA_INBOUND_CHECKSUM))
6143 recover ^= NETIF_F_RXCSUM;
6145 if (recover & NETIF_F_TSO) {
6146 if (qeth_set_ipa_tso(card, 1))
6147 recover ^= NETIF_F_TSO;
6150 if (recover == dev->features)
6151 return 0;
6153 dev_warn(&card->gdev->dev,
6154 "Device recovery failed to restore all offload features\n");
6155 dev->features = recover;
6156 return -EIO;
6158 EXPORT_SYMBOL_GPL(qeth_recover_features);
6160 int qeth_set_features(struct net_device *dev, netdev_features_t features)
6162 struct qeth_card *card = dev->ml_priv;
6163 netdev_features_t changed = dev->features ^ features;
6164 int rc = 0;
6166 QETH_DBF_TEXT(SETUP, 2, "setfeat");
6167 QETH_DBF_HEX(SETUP, 2, &features, sizeof(features));
6169 if ((changed & NETIF_F_IP_CSUM)) {
6170 rc = qeth_set_ipa_csum(card,
6171 features & NETIF_F_IP_CSUM ? 1 : 0,
6172 IPA_OUTBOUND_CHECKSUM);
6173 if (rc)
6174 changed ^= NETIF_F_IP_CSUM;
6176 if ((changed & NETIF_F_RXCSUM)) {
6177 rc = qeth_set_ipa_csum(card,
6178 features & NETIF_F_RXCSUM ? 1 : 0,
6179 IPA_INBOUND_CHECKSUM);
6180 if (rc)
6181 changed ^= NETIF_F_RXCSUM;
6183 if ((changed & NETIF_F_TSO)) {
6184 rc = qeth_set_ipa_tso(card, features & NETIF_F_TSO ? 1 : 0);
6185 if (rc)
6186 changed ^= NETIF_F_TSO;
6189 /* everything changed successfully? */
6190 if ((dev->features ^ features) == changed)
6191 return 0;
6192 /* something went wrong. save changed features and return error */
6193 dev->features ^= changed;
6194 return -EIO;
6196 EXPORT_SYMBOL_GPL(qeth_set_features);
6198 netdev_features_t qeth_fix_features(struct net_device *dev,
6199 netdev_features_t features)
6201 struct qeth_card *card = dev->ml_priv;
6203 QETH_DBF_TEXT(SETUP, 2, "fixfeat");
6204 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
6205 features &= ~NETIF_F_IP_CSUM;
6206 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
6207 features &= ~NETIF_F_RXCSUM;
6208 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
6209 features &= ~NETIF_F_TSO;
6210 dev_info(&card->gdev->dev, "Outbound TSO not supported on %s\n",
6211 QETH_CARD_IFNAME(card));
6213 /* if the card isn't up, remove features that require hw changes */
6214 if (card->state == CARD_STATE_DOWN ||
6215 card->state == CARD_STATE_RECOVER)
6216 features = features & ~(NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
6217 NETIF_F_TSO);
6218 QETH_DBF_HEX(SETUP, 2, &features, sizeof(features));
6219 return features;
6221 EXPORT_SYMBOL_GPL(qeth_fix_features);
6223 static int __init qeth_core_init(void)
6225 int rc;
6227 pr_info("loading core functions\n");
6228 INIT_LIST_HEAD(&qeth_core_card_list.list);
6229 INIT_LIST_HEAD(&qeth_dbf_list);
6230 rwlock_init(&qeth_core_card_list.rwlock);
6231 mutex_init(&qeth_mod_mutex);
6233 qeth_wq = create_singlethread_workqueue("qeth_wq");
6235 rc = qeth_register_dbf_views();
6236 if (rc)
6237 goto out_err;
6238 qeth_core_root_dev = root_device_register("qeth");
6239 rc = PTR_ERR_OR_ZERO(qeth_core_root_dev);
6240 if (rc)
6241 goto register_err;
6242 qeth_core_header_cache = kmem_cache_create("qeth_hdr",
6243 sizeof(struct qeth_hdr) + ETH_HLEN, 64, 0, NULL);
6244 if (!qeth_core_header_cache) {
6245 rc = -ENOMEM;
6246 goto slab_err;
6248 qeth_qdio_outbuf_cache = kmem_cache_create("qeth_buf",
6249 sizeof(struct qeth_qdio_out_buffer), 0, 0, NULL);
6250 if (!qeth_qdio_outbuf_cache) {
6251 rc = -ENOMEM;
6252 goto cqslab_err;
6254 rc = ccw_driver_register(&qeth_ccw_driver);
6255 if (rc)
6256 goto ccw_err;
6257 qeth_core_ccwgroup_driver.driver.groups = qeth_drv_attr_groups;
6258 rc = ccwgroup_driver_register(&qeth_core_ccwgroup_driver);
6259 if (rc)
6260 goto ccwgroup_err;
6262 return 0;
6264 ccwgroup_err:
6265 ccw_driver_unregister(&qeth_ccw_driver);
6266 ccw_err:
6267 kmem_cache_destroy(qeth_qdio_outbuf_cache);
6268 cqslab_err:
6269 kmem_cache_destroy(qeth_core_header_cache);
6270 slab_err:
6271 root_device_unregister(qeth_core_root_dev);
6272 register_err:
6273 qeth_unregister_dbf_views();
6274 out_err:
6275 pr_err("Initializing the qeth device driver failed\n");
6276 return rc;
6279 static void __exit qeth_core_exit(void)
6281 qeth_clear_dbf_list();
6282 destroy_workqueue(qeth_wq);
6283 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
6284 ccw_driver_unregister(&qeth_ccw_driver);
6285 kmem_cache_destroy(qeth_qdio_outbuf_cache);
6286 kmem_cache_destroy(qeth_core_header_cache);
6287 root_device_unregister(qeth_core_root_dev);
6288 qeth_unregister_dbf_views();
6289 pr_info("core functions removed\n");
6292 module_init(qeth_core_init);
6293 module_exit(qeth_core_exit);
6294 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
6295 MODULE_DESCRIPTION("qeth core functions");
6296 MODULE_LICENSE("GPL");