Add linux-next specific files for 20110831
[linux-2.6/next.git] / drivers / s390 / net / qeth_core_main.c
blob97172f8a15b7a8eccfb0baeb514d08193752b97a
1 /*
2 * drivers/s390/net/qeth_core_main.c
4 * Copyright IBM Corp. 2007, 2009
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
11 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/ip.h>
20 #include <linux/tcp.h>
21 #include <linux/mii.h>
22 #include <linux/kthread.h>
23 #include <linux/slab.h>
24 #include <net/iucv/af_iucv.h>
26 #include <asm/ebcdic.h>
27 #include <asm/io.h>
28 #include <asm/sysinfo.h>
30 #include "qeth_core.h"
32 struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
33 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
34 /* N P A M L V H */
35 [QETH_DBF_SETUP] = {"qeth_setup",
36 8, 1, 8, 5, &debug_hex_ascii_view, NULL},
37 [QETH_DBF_MSG] = {"qeth_msg",
38 8, 1, 128, 3, &debug_sprintf_view, NULL},
39 [QETH_DBF_CTRL] = {"qeth_control",
40 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
42 EXPORT_SYMBOL_GPL(qeth_dbf);
44 struct qeth_card_list_struct qeth_core_card_list;
45 EXPORT_SYMBOL_GPL(qeth_core_card_list);
46 struct kmem_cache *qeth_core_header_cache;
47 EXPORT_SYMBOL_GPL(qeth_core_header_cache);
48 static struct kmem_cache *qeth_qdio_outbuf_cache;
50 static struct device *qeth_core_root_dev;
51 static unsigned int known_devices[][6] = QETH_MODELLIST_ARRAY;
52 static struct lock_class_key qdio_out_skb_queue_key;
54 static void qeth_send_control_data_cb(struct qeth_channel *,
55 struct qeth_cmd_buffer *);
56 static int qeth_issue_next_read(struct qeth_card *);
57 static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *);
58 static void qeth_setup_ccw(struct qeth_channel *, unsigned char *, __u32);
59 static void qeth_free_buffer_pool(struct qeth_card *);
60 static int qeth_qdio_establish(struct qeth_card *);
61 static void qeth_free_qdio_buffers(struct qeth_card *);
62 static void qeth_notify_skbs(struct qeth_qdio_out_q *queue,
63 struct qeth_qdio_out_buffer *buf,
64 enum iucv_tx_notify notification);
65 static void qeth_release_skbs(struct qeth_qdio_out_buffer *buf);
66 static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
67 struct qeth_qdio_out_buffer *buf,
68 enum qeth_qdio_buffer_states newbufstate);
71 static inline const char *qeth_get_cardname(struct qeth_card *card)
73 if (card->info.guestlan) {
74 switch (card->info.type) {
75 case QETH_CARD_TYPE_OSD:
76 return " Guest LAN QDIO";
77 case QETH_CARD_TYPE_IQD:
78 return " Guest LAN Hiper";
79 case QETH_CARD_TYPE_OSM:
80 return " Guest LAN QDIO - OSM";
81 case QETH_CARD_TYPE_OSX:
82 return " Guest LAN QDIO - OSX";
83 default:
84 return " unknown";
86 } else {
87 switch (card->info.type) {
88 case QETH_CARD_TYPE_OSD:
89 return " OSD Express";
90 case QETH_CARD_TYPE_IQD:
91 return " HiperSockets";
92 case QETH_CARD_TYPE_OSN:
93 return " OSN QDIO";
94 case QETH_CARD_TYPE_OSM:
95 return " OSM QDIO";
96 case QETH_CARD_TYPE_OSX:
97 return " OSX QDIO";
98 default:
99 return " unknown";
102 return " n/a";
105 /* max length to be returned: 14 */
106 const char *qeth_get_cardname_short(struct qeth_card *card)
108 if (card->info.guestlan) {
109 switch (card->info.type) {
110 case QETH_CARD_TYPE_OSD:
111 return "GuestLAN QDIO";
112 case QETH_CARD_TYPE_IQD:
113 return "GuestLAN Hiper";
114 case QETH_CARD_TYPE_OSM:
115 return "GuestLAN OSM";
116 case QETH_CARD_TYPE_OSX:
117 return "GuestLAN OSX";
118 default:
119 return "unknown";
121 } else {
122 switch (card->info.type) {
123 case QETH_CARD_TYPE_OSD:
124 switch (card->info.link_type) {
125 case QETH_LINK_TYPE_FAST_ETH:
126 return "OSD_100";
127 case QETH_LINK_TYPE_HSTR:
128 return "HSTR";
129 case QETH_LINK_TYPE_GBIT_ETH:
130 return "OSD_1000";
131 case QETH_LINK_TYPE_10GBIT_ETH:
132 return "OSD_10GIG";
133 case QETH_LINK_TYPE_LANE_ETH100:
134 return "OSD_FE_LANE";
135 case QETH_LINK_TYPE_LANE_TR:
136 return "OSD_TR_LANE";
137 case QETH_LINK_TYPE_LANE_ETH1000:
138 return "OSD_GbE_LANE";
139 case QETH_LINK_TYPE_LANE:
140 return "OSD_ATM_LANE";
141 default:
142 return "OSD_Express";
144 case QETH_CARD_TYPE_IQD:
145 return "HiperSockets";
146 case QETH_CARD_TYPE_OSN:
147 return "OSN";
148 case QETH_CARD_TYPE_OSM:
149 return "OSM_1000";
150 case QETH_CARD_TYPE_OSX:
151 return "OSX_10GIG";
152 default:
153 return "unknown";
156 return "n/a";
159 void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
160 int clear_start_mask)
162 unsigned long flags;
164 spin_lock_irqsave(&card->thread_mask_lock, flags);
165 card->thread_allowed_mask = threads;
166 if (clear_start_mask)
167 card->thread_start_mask &= threads;
168 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
169 wake_up(&card->wait_q);
171 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads);
173 int qeth_threads_running(struct qeth_card *card, unsigned long threads)
175 unsigned long flags;
176 int rc = 0;
178 spin_lock_irqsave(&card->thread_mask_lock, flags);
179 rc = (card->thread_running_mask & threads);
180 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
181 return rc;
183 EXPORT_SYMBOL_GPL(qeth_threads_running);
185 int qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
187 return wait_event_interruptible(card->wait_q,
188 qeth_threads_running(card, threads) == 0);
190 EXPORT_SYMBOL_GPL(qeth_wait_for_threads);
192 void qeth_clear_working_pool_list(struct qeth_card *card)
194 struct qeth_buffer_pool_entry *pool_entry, *tmp;
196 QETH_CARD_TEXT(card, 5, "clwrklst");
197 list_for_each_entry_safe(pool_entry, tmp,
198 &card->qdio.in_buf_pool.entry_list, list){
199 list_del(&pool_entry->list);
202 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list);
204 static int qeth_alloc_buffer_pool(struct qeth_card *card)
206 struct qeth_buffer_pool_entry *pool_entry;
207 void *ptr;
208 int i, j;
210 QETH_CARD_TEXT(card, 5, "alocpool");
211 for (i = 0; i < card->qdio.init_pool.buf_count; ++i) {
212 pool_entry = kzalloc(sizeof(*pool_entry), GFP_KERNEL);
213 if (!pool_entry) {
214 qeth_free_buffer_pool(card);
215 return -ENOMEM;
217 for (j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j) {
218 ptr = (void *) __get_free_page(GFP_KERNEL);
219 if (!ptr) {
220 while (j > 0)
221 free_page((unsigned long)
222 pool_entry->elements[--j]);
223 kfree(pool_entry);
224 qeth_free_buffer_pool(card);
225 return -ENOMEM;
227 pool_entry->elements[j] = ptr;
229 list_add(&pool_entry->init_list,
230 &card->qdio.init_pool.entry_list);
232 return 0;
235 int qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
237 QETH_CARD_TEXT(card, 2, "realcbp");
239 if ((card->state != CARD_STATE_DOWN) &&
240 (card->state != CARD_STATE_RECOVER))
241 return -EPERM;
243 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
244 qeth_clear_working_pool_list(card);
245 qeth_free_buffer_pool(card);
246 card->qdio.in_buf_pool.buf_count = bufcnt;
247 card->qdio.init_pool.buf_count = bufcnt;
248 return qeth_alloc_buffer_pool(card);
250 EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool);
252 static inline int qeth_cq_init(struct qeth_card *card)
254 int rc;
256 if (card->options.cq == QETH_CQ_ENABLED) {
257 QETH_DBF_TEXT(SETUP, 2, "cqinit");
258 memset(card->qdio.c_q->qdio_bufs, 0,
259 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
260 card->qdio.c_q->next_buf_to_init = 127;
261 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT,
262 card->qdio.no_in_queues - 1, 0,
263 127);
264 if (rc) {
265 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
266 goto out;
269 rc = 0;
270 out:
271 return rc;
274 static inline int qeth_alloc_cq(struct qeth_card *card)
276 int rc;
278 if (card->options.cq == QETH_CQ_ENABLED) {
279 int i;
280 struct qdio_outbuf_state *outbuf_states;
282 QETH_DBF_TEXT(SETUP, 2, "cqon");
283 card->qdio.c_q = kzalloc(sizeof(struct qeth_qdio_q),
284 GFP_KERNEL);
285 if (!card->qdio.c_q) {
286 rc = -1;
287 goto kmsg_out;
289 QETH_DBF_HEX(SETUP, 2, &card->qdio.c_q, sizeof(void *));
291 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) {
292 card->qdio.c_q->bufs[i].buffer =
293 &card->qdio.c_q->qdio_bufs[i];
296 card->qdio.no_in_queues = 2;
298 card->qdio.out_bufstates = (struct qdio_outbuf_state *)
299 kzalloc(card->qdio.no_out_queues *
300 QDIO_MAX_BUFFERS_PER_Q *
301 sizeof(struct qdio_outbuf_state), GFP_KERNEL);
302 outbuf_states = card->qdio.out_bufstates;
303 if (outbuf_states == NULL) {
304 rc = -1;
305 goto free_cq_out;
307 for (i = 0; i < card->qdio.no_out_queues; ++i) {
308 card->qdio.out_qs[i]->bufstates = outbuf_states;
309 outbuf_states += QDIO_MAX_BUFFERS_PER_Q;
311 } else {
312 QETH_DBF_TEXT(SETUP, 2, "nocq");
313 card->qdio.c_q = NULL;
314 card->qdio.no_in_queues = 1;
316 QETH_DBF_TEXT_(SETUP, 2, "iqc%d", card->qdio.no_in_queues);
317 rc = 0;
318 out:
319 return rc;
320 free_cq_out:
321 kfree(card->qdio.c_q);
322 card->qdio.c_q = NULL;
323 kmsg_out:
324 dev_err(&card->gdev->dev, "Failed to create completion queue\n");
325 goto out;
328 static inline void qeth_free_cq(struct qeth_card *card)
330 if (card->qdio.c_q) {
331 --card->qdio.no_in_queues;
332 kfree(card->qdio.c_q);
333 card->qdio.c_q = NULL;
335 kfree(card->qdio.out_bufstates);
336 card->qdio.out_bufstates = NULL;
339 static inline enum iucv_tx_notify qeth_compute_cq_notification(int sbalf15,
340 int delayed) {
341 enum iucv_tx_notify n;
343 switch (sbalf15) {
344 case 0:
345 n = delayed ? TX_NOTIFY_DELAYED_OK : TX_NOTIFY_OK;
346 break;
347 case 4:
348 case 16:
349 case 17:
350 case 18:
351 n = delayed ? TX_NOTIFY_DELAYED_UNREACHABLE :
352 TX_NOTIFY_UNREACHABLE;
353 break;
354 default:
355 n = delayed ? TX_NOTIFY_DELAYED_GENERALERROR :
356 TX_NOTIFY_GENERALERROR;
357 break;
360 return n;
363 static inline void qeth_cleanup_handled_pending(struct qeth_qdio_out_q *q,
364 int bidx, int forced_cleanup)
366 if (q->bufs[bidx]->next_pending != NULL) {
367 struct qeth_qdio_out_buffer *head = q->bufs[bidx];
368 struct qeth_qdio_out_buffer *c = q->bufs[bidx]->next_pending;
370 while (c) {
371 if (forced_cleanup ||
372 atomic_read(&c->state) ==
373 QETH_QDIO_BUF_HANDLED_DELAYED) {
374 struct qeth_qdio_out_buffer *f = c;
375 QETH_CARD_TEXT(f->q->card, 5, "fp");
376 QETH_CARD_TEXT_(f->q->card, 5, "%lx", (long) f);
377 /* release here to avoid interleaving between
378 outbound tasklet and inbound tasklet
379 regarding notifications and lifecycle */
380 qeth_release_skbs(c);
382 c = f->next_pending;
383 BUG_ON(head->next_pending != f);
384 head->next_pending = c;
385 kmem_cache_free(qeth_qdio_outbuf_cache, f);
386 } else {
387 head = c;
388 c = c->next_pending;
396 static inline void qeth_qdio_handle_aob(struct qeth_card *card,
397 unsigned long phys_aob_addr) {
398 struct qaob *aob;
399 struct qeth_qdio_out_buffer *buffer;
400 enum iucv_tx_notify notification;
402 aob = (struct qaob *) phys_to_virt(phys_aob_addr);
403 QETH_CARD_TEXT(card, 5, "haob");
404 QETH_CARD_TEXT_(card, 5, "%lx", phys_aob_addr);
405 buffer = (struct qeth_qdio_out_buffer *) aob->user1;
406 QETH_CARD_TEXT_(card, 5, "%lx", aob->user1);
408 BUG_ON(buffer == NULL);
410 if (atomic_cmpxchg(&buffer->state, QETH_QDIO_BUF_PRIMED,
411 QETH_QDIO_BUF_IN_CQ) == QETH_QDIO_BUF_PRIMED) {
412 notification = TX_NOTIFY_OK;
413 } else {
414 BUG_ON(atomic_read(&buffer->state) != QETH_QDIO_BUF_PENDING);
416 atomic_set(&buffer->state, QETH_QDIO_BUF_IN_CQ);
417 notification = TX_NOTIFY_DELAYED_OK;
420 if (aob->aorc != 0) {
421 QETH_CARD_TEXT_(card, 2, "aorc%02X", aob->aorc);
422 notification = qeth_compute_cq_notification(aob->aorc, 1);
424 qeth_notify_skbs(buffer->q, buffer, notification);
426 buffer->aob = NULL;
427 qeth_clear_output_buffer(buffer->q, buffer,
428 QETH_QDIO_BUF_HANDLED_DELAYED);
429 /* from here on: do not touch buffer anymore */
430 qdio_release_aob(aob);
433 static inline int qeth_is_cq(struct qeth_card *card, unsigned int queue)
435 return card->options.cq == QETH_CQ_ENABLED &&
436 card->qdio.c_q != NULL &&
437 queue != 0 &&
438 queue == card->qdio.no_in_queues - 1;
442 static int qeth_issue_next_read(struct qeth_card *card)
444 int rc;
445 struct qeth_cmd_buffer *iob;
447 QETH_CARD_TEXT(card, 5, "issnxrd");
448 if (card->read.state != CH_STATE_UP)
449 return -EIO;
450 iob = qeth_get_buffer(&card->read);
451 if (!iob) {
452 dev_warn(&card->gdev->dev, "The qeth device driver "
453 "failed to recover an error on the device\n");
454 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
455 "available\n", dev_name(&card->gdev->dev));
456 return -ENOMEM;
458 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
459 QETH_CARD_TEXT(card, 6, "noirqpnd");
460 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
461 (addr_t) iob, 0, 0);
462 if (rc) {
463 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
464 "rc=%i\n", dev_name(&card->gdev->dev), rc);
465 atomic_set(&card->read.irq_pending, 0);
466 card->read_or_write_problem = 1;
467 qeth_schedule_recovery(card);
468 wake_up(&card->wait_q);
470 return rc;
473 static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card)
475 struct qeth_reply *reply;
477 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
478 if (reply) {
479 atomic_set(&reply->refcnt, 1);
480 atomic_set(&reply->received, 0);
481 reply->card = card;
483 return reply;
486 static void qeth_get_reply(struct qeth_reply *reply)
488 WARN_ON(atomic_read(&reply->refcnt) <= 0);
489 atomic_inc(&reply->refcnt);
492 static void qeth_put_reply(struct qeth_reply *reply)
494 WARN_ON(atomic_read(&reply->refcnt) <= 0);
495 if (atomic_dec_and_test(&reply->refcnt))
496 kfree(reply);
499 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
500 struct qeth_card *card)
502 char *ipa_name;
503 int com = cmd->hdr.command;
504 ipa_name = qeth_get_ipa_cmd_name(com);
505 if (rc)
506 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s/%s returned "
507 "x%X \"%s\"\n",
508 ipa_name, com, dev_name(&card->gdev->dev),
509 QETH_CARD_IFNAME(card), rc,
510 qeth_get_ipa_msg(rc));
511 else
512 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s/%s succeeded\n",
513 ipa_name, com, dev_name(&card->gdev->dev),
514 QETH_CARD_IFNAME(card));
517 static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
518 struct qeth_cmd_buffer *iob)
520 struct qeth_ipa_cmd *cmd = NULL;
522 QETH_CARD_TEXT(card, 5, "chkipad");
523 if (IS_IPA(iob->data)) {
524 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
525 if (IS_IPA_REPLY(cmd)) {
526 if (cmd->hdr.command != IPA_CMD_SETCCID &&
527 cmd->hdr.command != IPA_CMD_DELCCID &&
528 cmd->hdr.command != IPA_CMD_MODCCID &&
529 cmd->hdr.command != IPA_CMD_SET_DIAG_ASS)
530 qeth_issue_ipa_msg(cmd,
531 cmd->hdr.return_code, card);
532 return cmd;
533 } else {
534 switch (cmd->hdr.command) {
535 case IPA_CMD_STOPLAN:
536 dev_warn(&card->gdev->dev,
537 "The link for interface %s on CHPID"
538 " 0x%X failed\n",
539 QETH_CARD_IFNAME(card),
540 card->info.chpid);
541 card->lan_online = 0;
542 if (card->dev && netif_carrier_ok(card->dev))
543 netif_carrier_off(card->dev);
544 return NULL;
545 case IPA_CMD_STARTLAN:
546 dev_info(&card->gdev->dev,
547 "The link for %s on CHPID 0x%X has"
548 " been restored\n",
549 QETH_CARD_IFNAME(card),
550 card->info.chpid);
551 netif_carrier_on(card->dev);
552 card->lan_online = 1;
553 if (card->info.hwtrap)
554 card->info.hwtrap = 2;
555 qeth_schedule_recovery(card);
556 return NULL;
557 case IPA_CMD_MODCCID:
558 return cmd;
559 case IPA_CMD_REGISTER_LOCAL_ADDR:
560 QETH_CARD_TEXT(card, 3, "irla");
561 break;
562 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
563 QETH_CARD_TEXT(card, 3, "urla");
564 break;
565 default:
566 QETH_DBF_MESSAGE(2, "Received data is IPA "
567 "but not a reply!\n");
568 break;
572 return cmd;
575 void qeth_clear_ipacmd_list(struct qeth_card *card)
577 struct qeth_reply *reply, *r;
578 unsigned long flags;
580 QETH_CARD_TEXT(card, 4, "clipalst");
582 spin_lock_irqsave(&card->lock, flags);
583 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
584 qeth_get_reply(reply);
585 reply->rc = -EIO;
586 atomic_inc(&reply->received);
587 list_del_init(&reply->list);
588 wake_up(&reply->wait_q);
589 qeth_put_reply(reply);
591 spin_unlock_irqrestore(&card->lock, flags);
592 atomic_set(&card->write.irq_pending, 0);
594 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list);
596 static int qeth_check_idx_response(struct qeth_card *card,
597 unsigned char *buffer)
599 if (!buffer)
600 return 0;
602 QETH_DBF_HEX(CTRL, 2, buffer, QETH_DBF_CTRL_LEN);
603 if ((buffer[2] & 0xc0) == 0xc0) {
604 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
605 "with cause code 0x%02x%s\n",
606 buffer[4],
607 ((buffer[4] == 0x22) ?
608 " -- try another portname" : ""));
609 QETH_CARD_TEXT(card, 2, "ckidxres");
610 QETH_CARD_TEXT(card, 2, " idxterm");
611 QETH_CARD_TEXT_(card, 2, " rc%d", -EIO);
612 if (buffer[4] == 0xf6) {
613 dev_err(&card->gdev->dev,
614 "The qeth device is not configured "
615 "for the OSI layer required by z/VM\n");
616 return -EPERM;
618 return -EIO;
620 return 0;
623 static void qeth_setup_ccw(struct qeth_channel *channel, unsigned char *iob,
624 __u32 len)
626 struct qeth_card *card;
628 card = CARD_FROM_CDEV(channel->ccwdev);
629 QETH_CARD_TEXT(card, 4, "setupccw");
630 if (channel == &card->read)
631 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
632 else
633 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
634 channel->ccw.count = len;
635 channel->ccw.cda = (__u32) __pa(iob);
638 static struct qeth_cmd_buffer *__qeth_get_buffer(struct qeth_channel *channel)
640 __u8 index;
642 QETH_CARD_TEXT(CARD_FROM_CDEV(channel->ccwdev), 6, "getbuff");
643 index = channel->io_buf_no;
644 do {
645 if (channel->iob[index].state == BUF_STATE_FREE) {
646 channel->iob[index].state = BUF_STATE_LOCKED;
647 channel->io_buf_no = (channel->io_buf_no + 1) %
648 QETH_CMD_BUFFER_NO;
649 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
650 return channel->iob + index;
652 index = (index + 1) % QETH_CMD_BUFFER_NO;
653 } while (index != channel->io_buf_no);
655 return NULL;
658 void qeth_release_buffer(struct qeth_channel *channel,
659 struct qeth_cmd_buffer *iob)
661 unsigned long flags;
663 QETH_CARD_TEXT(CARD_FROM_CDEV(channel->ccwdev), 6, "relbuff");
664 spin_lock_irqsave(&channel->iob_lock, flags);
665 memset(iob->data, 0, QETH_BUFSIZE);
666 iob->state = BUF_STATE_FREE;
667 iob->callback = qeth_send_control_data_cb;
668 iob->rc = 0;
669 spin_unlock_irqrestore(&channel->iob_lock, flags);
671 EXPORT_SYMBOL_GPL(qeth_release_buffer);
673 static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *channel)
675 struct qeth_cmd_buffer *buffer = NULL;
676 unsigned long flags;
678 spin_lock_irqsave(&channel->iob_lock, flags);
679 buffer = __qeth_get_buffer(channel);
680 spin_unlock_irqrestore(&channel->iob_lock, flags);
681 return buffer;
684 struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *channel)
686 struct qeth_cmd_buffer *buffer;
687 wait_event(channel->wait_q,
688 ((buffer = qeth_get_buffer(channel)) != NULL));
689 return buffer;
691 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer);
693 void qeth_clear_cmd_buffers(struct qeth_channel *channel)
695 int cnt;
697 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
698 qeth_release_buffer(channel, &channel->iob[cnt]);
699 channel->buf_no = 0;
700 channel->io_buf_no = 0;
702 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers);
704 static void qeth_send_control_data_cb(struct qeth_channel *channel,
705 struct qeth_cmd_buffer *iob)
707 struct qeth_card *card;
708 struct qeth_reply *reply, *r;
709 struct qeth_ipa_cmd *cmd;
710 unsigned long flags;
711 int keep_reply;
712 int rc = 0;
714 card = CARD_FROM_CDEV(channel->ccwdev);
715 QETH_CARD_TEXT(card, 4, "sndctlcb");
716 rc = qeth_check_idx_response(card, iob->data);
717 switch (rc) {
718 case 0:
719 break;
720 case -EIO:
721 qeth_clear_ipacmd_list(card);
722 qeth_schedule_recovery(card);
723 /* fall through */
724 default:
725 goto out;
728 cmd = qeth_check_ipa_data(card, iob);
729 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
730 goto out;
731 /*in case of OSN : check if cmd is set */
732 if (card->info.type == QETH_CARD_TYPE_OSN &&
733 cmd &&
734 cmd->hdr.command != IPA_CMD_STARTLAN &&
735 card->osn_info.assist_cb != NULL) {
736 card->osn_info.assist_cb(card->dev, cmd);
737 goto out;
740 spin_lock_irqsave(&card->lock, flags);
741 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
742 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
743 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
744 qeth_get_reply(reply);
745 list_del_init(&reply->list);
746 spin_unlock_irqrestore(&card->lock, flags);
747 keep_reply = 0;
748 if (reply->callback != NULL) {
749 if (cmd) {
750 reply->offset = (__u16)((char *)cmd -
751 (char *)iob->data);
752 keep_reply = reply->callback(card,
753 reply,
754 (unsigned long)cmd);
755 } else
756 keep_reply = reply->callback(card,
757 reply,
758 (unsigned long)iob);
760 if (cmd)
761 reply->rc = (u16) cmd->hdr.return_code;
762 else if (iob->rc)
763 reply->rc = iob->rc;
764 if (keep_reply) {
765 spin_lock_irqsave(&card->lock, flags);
766 list_add_tail(&reply->list,
767 &card->cmd_waiter_list);
768 spin_unlock_irqrestore(&card->lock, flags);
769 } else {
770 atomic_inc(&reply->received);
771 wake_up(&reply->wait_q);
773 qeth_put_reply(reply);
774 goto out;
777 spin_unlock_irqrestore(&card->lock, flags);
778 out:
779 memcpy(&card->seqno.pdu_hdr_ack,
780 QETH_PDU_HEADER_SEQ_NO(iob->data),
781 QETH_SEQ_NO_LENGTH);
782 qeth_release_buffer(channel, iob);
785 static int qeth_setup_channel(struct qeth_channel *channel)
787 int cnt;
789 QETH_DBF_TEXT(SETUP, 2, "setupch");
790 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
791 channel->iob[cnt].data =
792 kzalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
793 if (channel->iob[cnt].data == NULL)
794 break;
795 channel->iob[cnt].state = BUF_STATE_FREE;
796 channel->iob[cnt].channel = channel;
797 channel->iob[cnt].callback = qeth_send_control_data_cb;
798 channel->iob[cnt].rc = 0;
800 if (cnt < QETH_CMD_BUFFER_NO) {
801 while (cnt-- > 0)
802 kfree(channel->iob[cnt].data);
803 return -ENOMEM;
805 channel->buf_no = 0;
806 channel->io_buf_no = 0;
807 atomic_set(&channel->irq_pending, 0);
808 spin_lock_init(&channel->iob_lock);
810 init_waitqueue_head(&channel->wait_q);
811 return 0;
814 static int qeth_set_thread_start_bit(struct qeth_card *card,
815 unsigned long thread)
817 unsigned long flags;
819 spin_lock_irqsave(&card->thread_mask_lock, flags);
820 if (!(card->thread_allowed_mask & thread) ||
821 (card->thread_start_mask & thread)) {
822 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
823 return -EPERM;
825 card->thread_start_mask |= thread;
826 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
827 return 0;
830 void qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
832 unsigned long flags;
834 spin_lock_irqsave(&card->thread_mask_lock, flags);
835 card->thread_start_mask &= ~thread;
836 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
837 wake_up(&card->wait_q);
839 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit);
841 void qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
843 unsigned long flags;
845 spin_lock_irqsave(&card->thread_mask_lock, flags);
846 card->thread_running_mask &= ~thread;
847 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
848 wake_up(&card->wait_q);
850 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit);
852 static int __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
854 unsigned long flags;
855 int rc = 0;
857 spin_lock_irqsave(&card->thread_mask_lock, flags);
858 if (card->thread_start_mask & thread) {
859 if ((card->thread_allowed_mask & thread) &&
860 !(card->thread_running_mask & thread)) {
861 rc = 1;
862 card->thread_start_mask &= ~thread;
863 card->thread_running_mask |= thread;
864 } else
865 rc = -EPERM;
867 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
868 return rc;
871 int qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
873 int rc = 0;
875 wait_event(card->wait_q,
876 (rc = __qeth_do_run_thread(card, thread)) >= 0);
877 return rc;
879 EXPORT_SYMBOL_GPL(qeth_do_run_thread);
881 void qeth_schedule_recovery(struct qeth_card *card)
883 QETH_CARD_TEXT(card, 2, "startrec");
884 WARN_ON(1);
885 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
886 schedule_work(&card->kernel_thread_starter);
888 EXPORT_SYMBOL_GPL(qeth_schedule_recovery);
890 static int qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
892 int dstat, cstat;
893 char *sense;
894 struct qeth_card *card;
896 sense = (char *) irb->ecw;
897 cstat = irb->scsw.cmd.cstat;
898 dstat = irb->scsw.cmd.dstat;
899 card = CARD_FROM_CDEV(cdev);
901 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
902 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
903 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
904 QETH_CARD_TEXT(card, 2, "CGENCHK");
905 dev_warn(&cdev->dev, "The qeth device driver "
906 "failed to recover an error on the device\n");
907 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x\n",
908 dev_name(&cdev->dev), dstat, cstat);
909 print_hex_dump(KERN_WARNING, "qeth: irb ", DUMP_PREFIX_OFFSET,
910 16, 1, irb, 64, 1);
911 return 1;
914 if (dstat & DEV_STAT_UNIT_CHECK) {
915 if (sense[SENSE_RESETTING_EVENT_BYTE] &
916 SENSE_RESETTING_EVENT_FLAG) {
917 QETH_CARD_TEXT(card, 2, "REVIND");
918 return 1;
920 if (sense[SENSE_COMMAND_REJECT_BYTE] &
921 SENSE_COMMAND_REJECT_FLAG) {
922 QETH_CARD_TEXT(card, 2, "CMDREJi");
923 return 1;
925 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
926 QETH_CARD_TEXT(card, 2, "AFFE");
927 return 1;
929 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
930 QETH_CARD_TEXT(card, 2, "ZEROSEN");
931 return 0;
933 QETH_CARD_TEXT(card, 2, "DGENCHK");
934 return 1;
936 return 0;
939 static long __qeth_check_irb_error(struct ccw_device *cdev,
940 unsigned long intparm, struct irb *irb)
942 struct qeth_card *card;
944 card = CARD_FROM_CDEV(cdev);
946 if (!IS_ERR(irb))
947 return 0;
949 switch (PTR_ERR(irb)) {
950 case -EIO:
951 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
952 dev_name(&cdev->dev));
953 QETH_CARD_TEXT(card, 2, "ckirberr");
954 QETH_CARD_TEXT_(card, 2, " rc%d", -EIO);
955 break;
956 case -ETIMEDOUT:
957 dev_warn(&cdev->dev, "A hardware operation timed out"
958 " on the device\n");
959 QETH_CARD_TEXT(card, 2, "ckirberr");
960 QETH_CARD_TEXT_(card, 2, " rc%d", -ETIMEDOUT);
961 if (intparm == QETH_RCD_PARM) {
962 if (card && (card->data.ccwdev == cdev)) {
963 card->data.state = CH_STATE_DOWN;
964 wake_up(&card->wait_q);
967 break;
968 default:
969 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
970 dev_name(&cdev->dev), PTR_ERR(irb));
971 QETH_CARD_TEXT(card, 2, "ckirberr");
972 QETH_CARD_TEXT(card, 2, " rc???");
974 return PTR_ERR(irb);
977 static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
978 struct irb *irb)
980 int rc;
981 int cstat, dstat;
982 struct qeth_cmd_buffer *buffer;
983 struct qeth_channel *channel;
984 struct qeth_card *card;
985 struct qeth_cmd_buffer *iob;
986 __u8 index;
988 if (__qeth_check_irb_error(cdev, intparm, irb))
989 return;
990 cstat = irb->scsw.cmd.cstat;
991 dstat = irb->scsw.cmd.dstat;
993 card = CARD_FROM_CDEV(cdev);
994 if (!card)
995 return;
997 QETH_CARD_TEXT(card, 5, "irq");
999 if (card->read.ccwdev == cdev) {
1000 channel = &card->read;
1001 QETH_CARD_TEXT(card, 5, "read");
1002 } else if (card->write.ccwdev == cdev) {
1003 channel = &card->write;
1004 QETH_CARD_TEXT(card, 5, "write");
1005 } else {
1006 channel = &card->data;
1007 QETH_CARD_TEXT(card, 5, "data");
1009 atomic_set(&channel->irq_pending, 0);
1011 if (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC))
1012 channel->state = CH_STATE_STOPPED;
1014 if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC))
1015 channel->state = CH_STATE_HALTED;
1017 /*let's wake up immediately on data channel*/
1018 if ((channel == &card->data) && (intparm != 0) &&
1019 (intparm != QETH_RCD_PARM))
1020 goto out;
1022 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
1023 QETH_CARD_TEXT(card, 6, "clrchpar");
1024 /* we don't have to handle this further */
1025 intparm = 0;
1027 if (intparm == QETH_HALT_CHANNEL_PARM) {
1028 QETH_CARD_TEXT(card, 6, "hltchpar");
1029 /* we don't have to handle this further */
1030 intparm = 0;
1032 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
1033 (dstat & DEV_STAT_UNIT_CHECK) ||
1034 (cstat)) {
1035 if (irb->esw.esw0.erw.cons) {
1036 dev_warn(&channel->ccwdev->dev,
1037 "The qeth device driver failed to recover "
1038 "an error on the device\n");
1039 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
1040 "0x%X dstat 0x%X\n",
1041 dev_name(&channel->ccwdev->dev), cstat, dstat);
1042 print_hex_dump(KERN_WARNING, "qeth: irb ",
1043 DUMP_PREFIX_OFFSET, 16, 1, irb, 32, 1);
1044 print_hex_dump(KERN_WARNING, "qeth: sense data ",
1045 DUMP_PREFIX_OFFSET, 16, 1, irb->ecw, 32, 1);
1047 if (intparm == QETH_RCD_PARM) {
1048 channel->state = CH_STATE_DOWN;
1049 goto out;
1051 rc = qeth_get_problem(cdev, irb);
1052 if (rc) {
1053 qeth_clear_ipacmd_list(card);
1054 qeth_schedule_recovery(card);
1055 goto out;
1059 if (intparm == QETH_RCD_PARM) {
1060 channel->state = CH_STATE_RCD_DONE;
1061 goto out;
1063 if (intparm) {
1064 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
1065 buffer->state = BUF_STATE_PROCESSED;
1067 if (channel == &card->data)
1068 return;
1069 if (channel == &card->read &&
1070 channel->state == CH_STATE_UP)
1071 qeth_issue_next_read(card);
1073 iob = channel->iob;
1074 index = channel->buf_no;
1075 while (iob[index].state == BUF_STATE_PROCESSED) {
1076 if (iob[index].callback != NULL)
1077 iob[index].callback(channel, iob + index);
1079 index = (index + 1) % QETH_CMD_BUFFER_NO;
1081 channel->buf_no = index;
1082 out:
1083 wake_up(&card->wait_q);
1084 return;
1087 static void qeth_notify_skbs(struct qeth_qdio_out_q *q,
1088 struct qeth_qdio_out_buffer *buf,
1089 enum iucv_tx_notify notification)
1091 struct sk_buff *skb;
1093 if (skb_queue_empty(&buf->skb_list))
1094 goto out;
1095 skb = skb_peek(&buf->skb_list);
1096 while (skb) {
1097 QETH_CARD_TEXT_(q->card, 5, "skbn%d", notification);
1098 QETH_CARD_TEXT_(q->card, 5, "%lx", (long) skb);
1099 if (skb->protocol == ETH_P_AF_IUCV) {
1100 if (skb->sk) {
1101 struct iucv_sock *iucv = iucv_sk(skb->sk);
1102 iucv->sk_txnotify(skb, notification);
1105 if (skb_queue_is_last(&buf->skb_list, skb))
1106 skb = NULL;
1107 else
1108 skb = skb_queue_next(&buf->skb_list, skb);
1110 out:
1111 return;
1114 static void qeth_release_skbs(struct qeth_qdio_out_buffer *buf)
1116 struct sk_buff *skb;
1118 skb = skb_dequeue(&buf->skb_list);
1119 while (skb) {
1120 QETH_CARD_TEXT(buf->q->card, 5, "skbr");
1121 QETH_CARD_TEXT_(buf->q->card, 5, "%lx", (long) skb);
1122 atomic_dec(&skb->users);
1123 dev_kfree_skb_any(skb);
1124 skb = skb_dequeue(&buf->skb_list);
1128 static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
1129 struct qeth_qdio_out_buffer *buf,
1130 enum qeth_qdio_buffer_states newbufstate)
1132 int i;
1134 /* is PCI flag set on buffer? */
1135 if (buf->buffer->element[0].sflags & SBAL_SFLAGS0_PCI_REQ)
1136 atomic_dec(&queue->set_pci_flags_count);
1138 if (newbufstate == QETH_QDIO_BUF_EMPTY) {
1139 qeth_release_skbs(buf);
1141 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i) {
1142 if (buf->buffer->element[i].addr && buf->is_header[i])
1143 kmem_cache_free(qeth_core_header_cache,
1144 buf->buffer->element[i].addr);
1145 buf->is_header[i] = 0;
1146 buf->buffer->element[i].length = 0;
1147 buf->buffer->element[i].addr = NULL;
1148 buf->buffer->element[i].eflags = 0;
1149 buf->buffer->element[i].sflags = 0;
1151 buf->buffer->element[15].eflags = 0;
1152 buf->buffer->element[15].sflags = 0;
1153 buf->next_element_to_fill = 0;
1154 atomic_set(&buf->state, newbufstate);
1157 static void qeth_clear_outq_buffers(struct qeth_qdio_out_q *q, int free)
1159 int j;
1161 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
1162 if (!q->bufs[j])
1163 continue;
1164 qeth_cleanup_handled_pending(q, j, free);
1165 qeth_clear_output_buffer(q, q->bufs[j], QETH_QDIO_BUF_EMPTY);
1166 if (free) {
1167 kmem_cache_free(qeth_qdio_outbuf_cache, q->bufs[j]);
1168 q->bufs[j] = NULL;
1173 void qeth_clear_qdio_buffers(struct qeth_card *card)
1175 int i;
1177 QETH_CARD_TEXT(card, 2, "clearqdbf");
1178 /* clear outbound buffers to free skbs */
1179 for (i = 0; i < card->qdio.no_out_queues; ++i) {
1180 if (card->qdio.out_qs[i]) {
1181 qeth_clear_outq_buffers(card->qdio.out_qs[i], 0);
1185 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers);
1187 static void qeth_free_buffer_pool(struct qeth_card *card)
1189 struct qeth_buffer_pool_entry *pool_entry, *tmp;
1190 int i = 0;
1191 list_for_each_entry_safe(pool_entry, tmp,
1192 &card->qdio.init_pool.entry_list, init_list){
1193 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
1194 free_page((unsigned long)pool_entry->elements[i]);
1195 list_del(&pool_entry->init_list);
1196 kfree(pool_entry);
1200 static void qeth_free_qdio_buffers(struct qeth_card *card)
1202 int i, j;
1204 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
1205 QETH_QDIO_UNINITIALIZED)
1206 return;
1208 qeth_free_cq(card);
1209 cancel_delayed_work_sync(&card->buffer_reclaim_work);
1210 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
1211 kfree_skb(card->qdio.in_q->bufs[j].rx_skb);
1212 kfree(card->qdio.in_q);
1213 card->qdio.in_q = NULL;
1214 /* inbound buffer pool */
1215 qeth_free_buffer_pool(card);
1216 /* free outbound qdio_qs */
1217 if (card->qdio.out_qs) {
1218 for (i = 0; i < card->qdio.no_out_queues; ++i) {
1219 qeth_clear_outq_buffers(card->qdio.out_qs[i], 1);
1220 kfree(card->qdio.out_qs[i]);
1222 kfree(card->qdio.out_qs);
1223 card->qdio.out_qs = NULL;
1227 static void qeth_clean_channel(struct qeth_channel *channel)
1229 int cnt;
1231 QETH_DBF_TEXT(SETUP, 2, "freech");
1232 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1233 kfree(channel->iob[cnt].data);
1236 static void qeth_get_channel_path_desc(struct qeth_card *card)
1238 struct ccw_device *ccwdev;
1239 struct channelPath_dsc {
1240 u8 flags;
1241 u8 lsn;
1242 u8 desc;
1243 u8 chpid;
1244 u8 swla;
1245 u8 zeroes;
1246 u8 chla;
1247 u8 chpp;
1248 } *chp_dsc;
1250 QETH_DBF_TEXT(SETUP, 2, "chp_desc");
1252 ccwdev = card->data.ccwdev;
1253 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1254 if (chp_dsc != NULL) {
1255 if (card->info.type != QETH_CARD_TYPE_IQD) {
1256 /* CHPP field bit 6 == 1 -> single queue */
1257 if ((chp_dsc->chpp & 0x02) == 0x02) {
1258 if ((atomic_read(&card->qdio.state) !=
1259 QETH_QDIO_UNINITIALIZED) &&
1260 (card->qdio.no_out_queues == 4))
1261 /* change from 4 to 1 outbound queues */
1262 qeth_free_qdio_buffers(card);
1263 card->qdio.no_out_queues = 1;
1264 if (card->qdio.default_out_queue != 0)
1265 dev_info(&card->gdev->dev,
1266 "Priority Queueing not supported\n");
1267 card->qdio.default_out_queue = 0;
1268 } else {
1269 if ((atomic_read(&card->qdio.state) !=
1270 QETH_QDIO_UNINITIALIZED) &&
1271 (card->qdio.no_out_queues == 1)) {
1272 /* change from 1 to 4 outbound queues */
1273 qeth_free_qdio_buffers(card);
1274 card->qdio.default_out_queue = 2;
1276 card->qdio.no_out_queues = 4;
1279 card->info.func_level = 0x4100 + chp_dsc->desc;
1280 kfree(chp_dsc);
1282 QETH_DBF_TEXT_(SETUP, 2, "nr:%x", card->qdio.no_out_queues);
1283 QETH_DBF_TEXT_(SETUP, 2, "lvl:%02x", card->info.func_level);
1284 return;
1287 static void qeth_init_qdio_info(struct qeth_card *card)
1289 QETH_DBF_TEXT(SETUP, 4, "intqdinf");
1290 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
1291 /* inbound */
1292 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
1293 if (card->info.type == QETH_CARD_TYPE_IQD)
1294 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_HSDEFAULT;
1295 else
1296 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
1297 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
1298 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
1299 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
1302 static void qeth_set_intial_options(struct qeth_card *card)
1304 card->options.route4.type = NO_ROUTER;
1305 card->options.route6.type = NO_ROUTER;
1306 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1307 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1308 card->options.fake_broadcast = 0;
1309 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1310 card->options.performance_stats = 0;
1311 card->options.rx_sg_cb = QETH_RX_SG_CB;
1312 card->options.isolation = ISOLATION_MODE_NONE;
1313 card->options.cq = QETH_CQ_DISABLED;
1316 static int qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1318 unsigned long flags;
1319 int rc = 0;
1321 spin_lock_irqsave(&card->thread_mask_lock, flags);
1322 QETH_CARD_TEXT_(card, 4, " %02x%02x%02x",
1323 (u8) card->thread_start_mask,
1324 (u8) card->thread_allowed_mask,
1325 (u8) card->thread_running_mask);
1326 rc = (card->thread_start_mask & thread);
1327 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1328 return rc;
1331 static void qeth_start_kernel_thread(struct work_struct *work)
1333 struct qeth_card *card = container_of(work, struct qeth_card,
1334 kernel_thread_starter);
1335 QETH_CARD_TEXT(card , 2, "strthrd");
1337 if (card->read.state != CH_STATE_UP &&
1338 card->write.state != CH_STATE_UP)
1339 return;
1340 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1341 kthread_run(card->discipline.recover, (void *) card,
1342 "qeth_recover");
1345 static int qeth_setup_card(struct qeth_card *card)
1348 QETH_DBF_TEXT(SETUP, 2, "setupcrd");
1349 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1351 card->read.state = CH_STATE_DOWN;
1352 card->write.state = CH_STATE_DOWN;
1353 card->data.state = CH_STATE_DOWN;
1354 card->state = CARD_STATE_DOWN;
1355 card->lan_online = 0;
1356 card->read_or_write_problem = 0;
1357 card->dev = NULL;
1358 spin_lock_init(&card->vlanlock);
1359 spin_lock_init(&card->mclock);
1360 spin_lock_init(&card->lock);
1361 spin_lock_init(&card->ip_lock);
1362 spin_lock_init(&card->thread_mask_lock);
1363 mutex_init(&card->conf_mutex);
1364 mutex_init(&card->discipline_mutex);
1365 card->thread_start_mask = 0;
1366 card->thread_allowed_mask = 0;
1367 card->thread_running_mask = 0;
1368 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
1369 INIT_LIST_HEAD(&card->ip_list);
1370 INIT_LIST_HEAD(card->ip_tbd_list);
1371 INIT_LIST_HEAD(&card->cmd_waiter_list);
1372 init_waitqueue_head(&card->wait_q);
1373 /* initial options */
1374 qeth_set_intial_options(card);
1375 /* IP address takeover */
1376 INIT_LIST_HEAD(&card->ipato.entries);
1377 card->ipato.enabled = 0;
1378 card->ipato.invert4 = 0;
1379 card->ipato.invert6 = 0;
1380 /* init QDIO stuff */
1381 qeth_init_qdio_info(card);
1382 INIT_DELAYED_WORK(&card->buffer_reclaim_work, qeth_buffer_reclaim_work);
1383 return 0;
1386 static void qeth_core_sl_print(struct seq_file *m, struct service_level *slr)
1388 struct qeth_card *card = container_of(slr, struct qeth_card,
1389 qeth_service_level);
1390 if (card->info.mcl_level[0])
1391 seq_printf(m, "qeth: %s firmware level %s\n",
1392 CARD_BUS_ID(card), card->info.mcl_level);
1395 static struct qeth_card *qeth_alloc_card(void)
1397 struct qeth_card *card;
1399 QETH_DBF_TEXT(SETUP, 2, "alloccrd");
1400 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
1401 if (!card)
1402 goto out;
1403 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1404 card->ip_tbd_list = kzalloc(sizeof(struct list_head), GFP_KERNEL);
1405 if (!card->ip_tbd_list) {
1406 QETH_DBF_TEXT(SETUP, 0, "iptbdnom");
1407 goto out_card;
1409 if (qeth_setup_channel(&card->read))
1410 goto out_ip;
1411 if (qeth_setup_channel(&card->write))
1412 goto out_channel;
1413 card->options.layer2 = -1;
1414 card->qeth_service_level.seq_print = qeth_core_sl_print;
1415 register_service_level(&card->qeth_service_level);
1416 return card;
1418 out_channel:
1419 qeth_clean_channel(&card->read);
1420 out_ip:
1421 kfree(card->ip_tbd_list);
1422 out_card:
1423 kfree(card);
1424 out:
1425 return NULL;
1428 static int qeth_determine_card_type(struct qeth_card *card)
1430 int i = 0;
1432 QETH_DBF_TEXT(SETUP, 2, "detcdtyp");
1434 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1435 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1436 while (known_devices[i][QETH_DEV_MODEL_IND]) {
1437 if ((CARD_RDEV(card)->id.dev_type ==
1438 known_devices[i][QETH_DEV_TYPE_IND]) &&
1439 (CARD_RDEV(card)->id.dev_model ==
1440 known_devices[i][QETH_DEV_MODEL_IND])) {
1441 card->info.type = known_devices[i][QETH_DEV_MODEL_IND];
1442 card->qdio.no_out_queues =
1443 known_devices[i][QETH_QUEUE_NO_IND];
1444 card->qdio.no_in_queues = 1;
1445 card->info.is_multicast_different =
1446 known_devices[i][QETH_MULTICAST_IND];
1447 qeth_get_channel_path_desc(card);
1448 return 0;
1450 i++;
1452 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1453 dev_err(&card->gdev->dev, "The adapter hardware is of an "
1454 "unknown type\n");
1455 return -ENOENT;
1458 static int qeth_clear_channel(struct qeth_channel *channel)
1460 unsigned long flags;
1461 struct qeth_card *card;
1462 int rc;
1464 card = CARD_FROM_CDEV(channel->ccwdev);
1465 QETH_CARD_TEXT(card, 3, "clearch");
1466 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1467 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
1468 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1470 if (rc)
1471 return rc;
1472 rc = wait_event_interruptible_timeout(card->wait_q,
1473 channel->state == CH_STATE_STOPPED, QETH_TIMEOUT);
1474 if (rc == -ERESTARTSYS)
1475 return rc;
1476 if (channel->state != CH_STATE_STOPPED)
1477 return -ETIME;
1478 channel->state = CH_STATE_DOWN;
1479 return 0;
1482 static int qeth_halt_channel(struct qeth_channel *channel)
1484 unsigned long flags;
1485 struct qeth_card *card;
1486 int rc;
1488 card = CARD_FROM_CDEV(channel->ccwdev);
1489 QETH_CARD_TEXT(card, 3, "haltch");
1490 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1491 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
1492 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1494 if (rc)
1495 return rc;
1496 rc = wait_event_interruptible_timeout(card->wait_q,
1497 channel->state == CH_STATE_HALTED, QETH_TIMEOUT);
1498 if (rc == -ERESTARTSYS)
1499 return rc;
1500 if (channel->state != CH_STATE_HALTED)
1501 return -ETIME;
1502 return 0;
1505 static int qeth_halt_channels(struct qeth_card *card)
1507 int rc1 = 0, rc2 = 0, rc3 = 0;
1509 QETH_CARD_TEXT(card, 3, "haltchs");
1510 rc1 = qeth_halt_channel(&card->read);
1511 rc2 = qeth_halt_channel(&card->write);
1512 rc3 = qeth_halt_channel(&card->data);
1513 if (rc1)
1514 return rc1;
1515 if (rc2)
1516 return rc2;
1517 return rc3;
1520 static int qeth_clear_channels(struct qeth_card *card)
1522 int rc1 = 0, rc2 = 0, rc3 = 0;
1524 QETH_CARD_TEXT(card, 3, "clearchs");
1525 rc1 = qeth_clear_channel(&card->read);
1526 rc2 = qeth_clear_channel(&card->write);
1527 rc3 = qeth_clear_channel(&card->data);
1528 if (rc1)
1529 return rc1;
1530 if (rc2)
1531 return rc2;
1532 return rc3;
1535 static int qeth_clear_halt_card(struct qeth_card *card, int halt)
1537 int rc = 0;
1539 QETH_CARD_TEXT(card, 3, "clhacrd");
1541 if (halt)
1542 rc = qeth_halt_channels(card);
1543 if (rc)
1544 return rc;
1545 return qeth_clear_channels(card);
1548 int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
1550 int rc = 0;
1552 QETH_CARD_TEXT(card, 3, "qdioclr");
1553 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
1554 QETH_QDIO_CLEANING)) {
1555 case QETH_QDIO_ESTABLISHED:
1556 if (card->info.type == QETH_CARD_TYPE_IQD)
1557 rc = qdio_shutdown(CARD_DDEV(card),
1558 QDIO_FLAG_CLEANUP_USING_HALT);
1559 else
1560 rc = qdio_shutdown(CARD_DDEV(card),
1561 QDIO_FLAG_CLEANUP_USING_CLEAR);
1562 if (rc)
1563 QETH_CARD_TEXT_(card, 3, "1err%d", rc);
1564 qdio_free(CARD_DDEV(card));
1565 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
1566 break;
1567 case QETH_QDIO_CLEANING:
1568 return rc;
1569 default:
1570 break;
1572 rc = qeth_clear_halt_card(card, use_halt);
1573 if (rc)
1574 QETH_CARD_TEXT_(card, 3, "2err%d", rc);
1575 card->state = CARD_STATE_DOWN;
1576 return rc;
1578 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card);
1580 static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
1581 int *length)
1583 struct ciw *ciw;
1584 char *rcd_buf;
1585 int ret;
1586 struct qeth_channel *channel = &card->data;
1587 unsigned long flags;
1590 * scan for RCD command in extended SenseID data
1592 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
1593 if (!ciw || ciw->cmd == 0)
1594 return -EOPNOTSUPP;
1595 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
1596 if (!rcd_buf)
1597 return -ENOMEM;
1599 channel->ccw.cmd_code = ciw->cmd;
1600 channel->ccw.cda = (__u32) __pa(rcd_buf);
1601 channel->ccw.count = ciw->count;
1602 channel->ccw.flags = CCW_FLAG_SLI;
1603 channel->state = CH_STATE_RCD;
1604 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1605 ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1606 QETH_RCD_PARM, LPM_ANYPATH, 0,
1607 QETH_RCD_TIMEOUT);
1608 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1609 if (!ret)
1610 wait_event(card->wait_q,
1611 (channel->state == CH_STATE_RCD_DONE ||
1612 channel->state == CH_STATE_DOWN));
1613 if (channel->state == CH_STATE_DOWN)
1614 ret = -EIO;
1615 else
1616 channel->state = CH_STATE_DOWN;
1617 if (ret) {
1618 kfree(rcd_buf);
1619 *buffer = NULL;
1620 *length = 0;
1621 } else {
1622 *length = ciw->count;
1623 *buffer = rcd_buf;
1625 return ret;
1628 static void qeth_configure_unitaddr(struct qeth_card *card, char *prcd)
1630 QETH_DBF_TEXT(SETUP, 2, "cfgunit");
1631 card->info.chpid = prcd[30];
1632 card->info.unit_addr2 = prcd[31];
1633 card->info.cula = prcd[63];
1634 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1635 (prcd[0x11] == _ascebc['M']));
1638 static void qeth_configure_blkt_default(struct qeth_card *card, char *prcd)
1640 QETH_DBF_TEXT(SETUP, 2, "cfgblkt");
1642 if (prcd[74] == 0xF0 && prcd[75] == 0xF0 && prcd[76] == 0xF5) {
1643 card->info.blkt.time_total = 250;
1644 card->info.blkt.inter_packet = 5;
1645 card->info.blkt.inter_packet_jumbo = 15;
1646 } else {
1647 card->info.blkt.time_total = 0;
1648 card->info.blkt.inter_packet = 0;
1649 card->info.blkt.inter_packet_jumbo = 0;
1653 static void qeth_init_tokens(struct qeth_card *card)
1655 card->token.issuer_rm_w = 0x00010103UL;
1656 card->token.cm_filter_w = 0x00010108UL;
1657 card->token.cm_connection_w = 0x0001010aUL;
1658 card->token.ulp_filter_w = 0x0001010bUL;
1659 card->token.ulp_connection_w = 0x0001010dUL;
1662 static void qeth_init_func_level(struct qeth_card *card)
1664 switch (card->info.type) {
1665 case QETH_CARD_TYPE_IQD:
1666 card->info.func_level = QETH_IDX_FUNC_LEVEL_IQD;
1667 break;
1668 case QETH_CARD_TYPE_OSD:
1669 case QETH_CARD_TYPE_OSN:
1670 card->info.func_level = QETH_IDX_FUNC_LEVEL_OSD;
1671 break;
1672 default:
1673 break;
1677 static int qeth_idx_activate_get_answer(struct qeth_channel *channel,
1678 void (*idx_reply_cb)(struct qeth_channel *,
1679 struct qeth_cmd_buffer *))
1681 struct qeth_cmd_buffer *iob;
1682 unsigned long flags;
1683 int rc;
1684 struct qeth_card *card;
1686 QETH_DBF_TEXT(SETUP, 2, "idxanswr");
1687 card = CARD_FROM_CDEV(channel->ccwdev);
1688 iob = qeth_get_buffer(channel);
1689 iob->callback = idx_reply_cb;
1690 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1691 channel->ccw.count = QETH_BUFSIZE;
1692 channel->ccw.cda = (__u32) __pa(iob->data);
1694 wait_event(card->wait_q,
1695 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1696 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1697 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1698 rc = ccw_device_start(channel->ccwdev,
1699 &channel->ccw, (addr_t) iob, 0, 0);
1700 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1702 if (rc) {
1703 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc);
1704 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
1705 atomic_set(&channel->irq_pending, 0);
1706 wake_up(&card->wait_q);
1707 return rc;
1709 rc = wait_event_interruptible_timeout(card->wait_q,
1710 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1711 if (rc == -ERESTARTSYS)
1712 return rc;
1713 if (channel->state != CH_STATE_UP) {
1714 rc = -ETIME;
1715 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
1716 qeth_clear_cmd_buffers(channel);
1717 } else
1718 rc = 0;
1719 return rc;
1722 static int qeth_idx_activate_channel(struct qeth_channel *channel,
1723 void (*idx_reply_cb)(struct qeth_channel *,
1724 struct qeth_cmd_buffer *))
1726 struct qeth_card *card;
1727 struct qeth_cmd_buffer *iob;
1728 unsigned long flags;
1729 __u16 temp;
1730 __u8 tmp;
1731 int rc;
1732 struct ccw_dev_id temp_devid;
1734 card = CARD_FROM_CDEV(channel->ccwdev);
1736 QETH_DBF_TEXT(SETUP, 2, "idxactch");
1738 iob = qeth_get_buffer(channel);
1739 iob->callback = idx_reply_cb;
1740 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1741 channel->ccw.count = IDX_ACTIVATE_SIZE;
1742 channel->ccw.cda = (__u32) __pa(iob->data);
1743 if (channel == &card->write) {
1744 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1745 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1746 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1747 card->seqno.trans_hdr++;
1748 } else {
1749 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1750 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1751 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1753 tmp = ((__u8)card->info.portno) | 0x80;
1754 memcpy(QETH_IDX_ACT_PNO(iob->data), &tmp, 1);
1755 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1756 &card->token.issuer_rm_w, QETH_MPC_TOKEN_LENGTH);
1757 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1758 &card->info.func_level, sizeof(__u16));
1759 ccw_device_get_id(CARD_DDEV(card), &temp_devid);
1760 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp_devid.devno, 2);
1761 temp = (card->info.cula << 8) + card->info.unit_addr2;
1762 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1764 wait_event(card->wait_q,
1765 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1766 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1767 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1768 rc = ccw_device_start(channel->ccwdev,
1769 &channel->ccw, (addr_t) iob, 0, 0);
1770 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1772 if (rc) {
1773 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1774 rc);
1775 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1776 atomic_set(&channel->irq_pending, 0);
1777 wake_up(&card->wait_q);
1778 return rc;
1780 rc = wait_event_interruptible_timeout(card->wait_q,
1781 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1782 if (rc == -ERESTARTSYS)
1783 return rc;
1784 if (channel->state != CH_STATE_ACTIVATING) {
1785 dev_warn(&channel->ccwdev->dev, "The qeth device driver"
1786 " failed to recover an error on the device\n");
1787 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1788 dev_name(&channel->ccwdev->dev));
1789 QETH_DBF_TEXT_(SETUP, 2, "2err%d", -ETIME);
1790 qeth_clear_cmd_buffers(channel);
1791 return -ETIME;
1793 return qeth_idx_activate_get_answer(channel, idx_reply_cb);
1796 static int qeth_peer_func_level(int level)
1798 if ((level & 0xff) == 8)
1799 return (level & 0xff) + 0x400;
1800 if (((level >> 8) & 3) == 1)
1801 return (level & 0xff) + 0x200;
1802 return level;
1805 static void qeth_idx_write_cb(struct qeth_channel *channel,
1806 struct qeth_cmd_buffer *iob)
1808 struct qeth_card *card;
1809 __u16 temp;
1811 QETH_DBF_TEXT(SETUP , 2, "idxwrcb");
1813 if (channel->state == CH_STATE_DOWN) {
1814 channel->state = CH_STATE_ACTIVATING;
1815 goto out;
1817 card = CARD_FROM_CDEV(channel->ccwdev);
1819 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1820 if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == QETH_IDX_ACT_ERR_EXCL)
1821 dev_err(&card->write.ccwdev->dev,
1822 "The adapter is used exclusively by another "
1823 "host\n");
1824 else
1825 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1826 " negative reply\n",
1827 dev_name(&card->write.ccwdev->dev));
1828 goto out;
1830 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1831 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1832 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
1833 "function level mismatch (sent: 0x%x, received: "
1834 "0x%x)\n", dev_name(&card->write.ccwdev->dev),
1835 card->info.func_level, temp);
1836 goto out;
1838 channel->state = CH_STATE_UP;
1839 out:
1840 qeth_release_buffer(channel, iob);
1843 static void qeth_idx_read_cb(struct qeth_channel *channel,
1844 struct qeth_cmd_buffer *iob)
1846 struct qeth_card *card;
1847 __u16 temp;
1849 QETH_DBF_TEXT(SETUP , 2, "idxrdcb");
1850 if (channel->state == CH_STATE_DOWN) {
1851 channel->state = CH_STATE_ACTIVATING;
1852 goto out;
1855 card = CARD_FROM_CDEV(channel->ccwdev);
1856 if (qeth_check_idx_response(card, iob->data))
1857 goto out;
1859 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1860 switch (QETH_IDX_ACT_CAUSE_CODE(iob->data)) {
1861 case QETH_IDX_ACT_ERR_EXCL:
1862 dev_err(&card->write.ccwdev->dev,
1863 "The adapter is used exclusively by another "
1864 "host\n");
1865 break;
1866 case QETH_IDX_ACT_ERR_AUTH:
1867 case QETH_IDX_ACT_ERR_AUTH_USER:
1868 dev_err(&card->read.ccwdev->dev,
1869 "Setting the device online failed because of "
1870 "insufficient authorization\n");
1871 break;
1872 default:
1873 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
1874 " negative reply\n",
1875 dev_name(&card->read.ccwdev->dev));
1877 QETH_CARD_TEXT_(card, 2, "idxread%c",
1878 QETH_IDX_ACT_CAUSE_CODE(iob->data));
1879 goto out;
1883 * * temporary fix for microcode bug
1884 * * to revert it,replace OR by AND
1885 * */
1886 if ((!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1887 (card->info.type == QETH_CARD_TYPE_OSD))
1888 card->info.portname_required = 1;
1890 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1891 if (temp != qeth_peer_func_level(card->info.func_level)) {
1892 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
1893 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1894 dev_name(&card->read.ccwdev->dev),
1895 card->info.func_level, temp);
1896 goto out;
1898 memcpy(&card->token.issuer_rm_r,
1899 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1900 QETH_MPC_TOKEN_LENGTH);
1901 memcpy(&card->info.mcl_level[0],
1902 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1903 channel->state = CH_STATE_UP;
1904 out:
1905 qeth_release_buffer(channel, iob);
1908 void qeth_prepare_control_data(struct qeth_card *card, int len,
1909 struct qeth_cmd_buffer *iob)
1911 qeth_setup_ccw(&card->write, iob->data, len);
1912 iob->callback = qeth_release_buffer;
1914 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1915 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1916 card->seqno.trans_hdr++;
1917 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1918 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1919 card->seqno.pdu_hdr++;
1920 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1921 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1922 QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
1924 EXPORT_SYMBOL_GPL(qeth_prepare_control_data);
1926 int qeth_send_control_data(struct qeth_card *card, int len,
1927 struct qeth_cmd_buffer *iob,
1928 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1929 unsigned long),
1930 void *reply_param)
1932 int rc;
1933 unsigned long flags;
1934 struct qeth_reply *reply = NULL;
1935 unsigned long timeout, event_timeout;
1936 struct qeth_ipa_cmd *cmd;
1938 QETH_CARD_TEXT(card, 2, "sendctl");
1940 if (card->read_or_write_problem) {
1941 qeth_release_buffer(iob->channel, iob);
1942 return -EIO;
1944 reply = qeth_alloc_reply(card);
1945 if (!reply) {
1946 return -ENOMEM;
1948 reply->callback = reply_cb;
1949 reply->param = reply_param;
1950 if (card->state == CARD_STATE_DOWN)
1951 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1952 else
1953 reply->seqno = card->seqno.ipa++;
1954 init_waitqueue_head(&reply->wait_q);
1955 spin_lock_irqsave(&card->lock, flags);
1956 list_add_tail(&reply->list, &card->cmd_waiter_list);
1957 spin_unlock_irqrestore(&card->lock, flags);
1958 QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
1960 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
1961 qeth_prepare_control_data(card, len, iob);
1963 if (IS_IPA(iob->data))
1964 event_timeout = QETH_IPA_TIMEOUT;
1965 else
1966 event_timeout = QETH_TIMEOUT;
1967 timeout = jiffies + event_timeout;
1969 QETH_CARD_TEXT(card, 6, "noirqpnd");
1970 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1971 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1972 (addr_t) iob, 0, 0);
1973 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1974 if (rc) {
1975 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
1976 "ccw_device_start rc = %i\n",
1977 dev_name(&card->write.ccwdev->dev), rc);
1978 QETH_CARD_TEXT_(card, 2, " err%d", rc);
1979 spin_lock_irqsave(&card->lock, flags);
1980 list_del_init(&reply->list);
1981 qeth_put_reply(reply);
1982 spin_unlock_irqrestore(&card->lock, flags);
1983 qeth_release_buffer(iob->channel, iob);
1984 atomic_set(&card->write.irq_pending, 0);
1985 wake_up(&card->wait_q);
1986 return rc;
1989 /* we have only one long running ipassist, since we can ensure
1990 process context of this command we can sleep */
1991 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1992 if ((cmd->hdr.command == IPA_CMD_SETIP) &&
1993 (cmd->hdr.prot_version == QETH_PROT_IPV4)) {
1994 if (!wait_event_timeout(reply->wait_q,
1995 atomic_read(&reply->received), event_timeout))
1996 goto time_err;
1997 } else {
1998 while (!atomic_read(&reply->received)) {
1999 if (time_after(jiffies, timeout))
2000 goto time_err;
2001 cpu_relax();
2005 if (reply->rc == -EIO)
2006 goto error;
2007 rc = reply->rc;
2008 qeth_put_reply(reply);
2009 return rc;
2011 time_err:
2012 reply->rc = -ETIME;
2013 spin_lock_irqsave(&reply->card->lock, flags);
2014 list_del_init(&reply->list);
2015 spin_unlock_irqrestore(&reply->card->lock, flags);
2016 atomic_inc(&reply->received);
2017 error:
2018 atomic_set(&card->write.irq_pending, 0);
2019 qeth_release_buffer(iob->channel, iob);
2020 card->write.buf_no = (card->write.buf_no + 1) % QETH_CMD_BUFFER_NO;
2021 rc = reply->rc;
2022 qeth_put_reply(reply);
2023 return rc;
2025 EXPORT_SYMBOL_GPL(qeth_send_control_data);
2027 static int qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2028 unsigned long data)
2030 struct qeth_cmd_buffer *iob;
2032 QETH_DBF_TEXT(SETUP, 2, "cmenblcb");
2034 iob = (struct qeth_cmd_buffer *) data;
2035 memcpy(&card->token.cm_filter_r,
2036 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2037 QETH_MPC_TOKEN_LENGTH);
2038 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2039 return 0;
2042 static int qeth_cm_enable(struct qeth_card *card)
2044 int rc;
2045 struct qeth_cmd_buffer *iob;
2047 QETH_DBF_TEXT(SETUP, 2, "cmenable");
2049 iob = qeth_wait_for_buffer(&card->write);
2050 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2051 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2052 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2053 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2054 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2056 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2057 qeth_cm_enable_cb, NULL);
2058 return rc;
2061 static int qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2062 unsigned long data)
2065 struct qeth_cmd_buffer *iob;
2067 QETH_DBF_TEXT(SETUP, 2, "cmsetpcb");
2069 iob = (struct qeth_cmd_buffer *) data;
2070 memcpy(&card->token.cm_connection_r,
2071 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2072 QETH_MPC_TOKEN_LENGTH);
2073 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2074 return 0;
2077 static int qeth_cm_setup(struct qeth_card *card)
2079 int rc;
2080 struct qeth_cmd_buffer *iob;
2082 QETH_DBF_TEXT(SETUP, 2, "cmsetup");
2084 iob = qeth_wait_for_buffer(&card->write);
2085 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2086 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2087 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2088 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2089 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2090 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2091 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2092 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2093 qeth_cm_setup_cb, NULL);
2094 return rc;
2098 static inline int qeth_get_initial_mtu_for_card(struct qeth_card *card)
2100 switch (card->info.type) {
2101 case QETH_CARD_TYPE_UNKNOWN:
2102 return 1500;
2103 case QETH_CARD_TYPE_IQD:
2104 return card->info.max_mtu;
2105 case QETH_CARD_TYPE_OSD:
2106 switch (card->info.link_type) {
2107 case QETH_LINK_TYPE_HSTR:
2108 case QETH_LINK_TYPE_LANE_TR:
2109 return 2000;
2110 default:
2111 return 1492;
2113 case QETH_CARD_TYPE_OSM:
2114 case QETH_CARD_TYPE_OSX:
2115 return 1492;
2116 default:
2117 return 1500;
2121 static inline int qeth_get_mtu_outof_framesize(int framesize)
2123 switch (framesize) {
2124 case 0x4000:
2125 return 8192;
2126 case 0x6000:
2127 return 16384;
2128 case 0xa000:
2129 return 32768;
2130 case 0xffff:
2131 return 57344;
2132 default:
2133 return 0;
2137 static inline int qeth_mtu_is_valid(struct qeth_card *card, int mtu)
2139 switch (card->info.type) {
2140 case QETH_CARD_TYPE_OSD:
2141 case QETH_CARD_TYPE_OSM:
2142 case QETH_CARD_TYPE_OSX:
2143 case QETH_CARD_TYPE_IQD:
2144 return ((mtu >= 576) &&
2145 (mtu <= card->info.max_mtu));
2146 case QETH_CARD_TYPE_OSN:
2147 case QETH_CARD_TYPE_UNKNOWN:
2148 default:
2149 return 1;
2153 static int qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2154 unsigned long data)
2157 __u16 mtu, framesize;
2158 __u16 len;
2159 __u8 link_type;
2160 struct qeth_cmd_buffer *iob;
2162 QETH_DBF_TEXT(SETUP, 2, "ulpenacb");
2164 iob = (struct qeth_cmd_buffer *) data;
2165 memcpy(&card->token.ulp_filter_r,
2166 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2167 QETH_MPC_TOKEN_LENGTH);
2168 if (card->info.type == QETH_CARD_TYPE_IQD) {
2169 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2170 mtu = qeth_get_mtu_outof_framesize(framesize);
2171 if (!mtu) {
2172 iob->rc = -EINVAL;
2173 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2174 return 0;
2176 if (card->info.initial_mtu && (card->info.initial_mtu != mtu)) {
2177 /* frame size has changed */
2178 if (card->dev &&
2179 ((card->dev->mtu == card->info.initial_mtu) ||
2180 (card->dev->mtu > mtu)))
2181 card->dev->mtu = mtu;
2182 qeth_free_qdio_buffers(card);
2184 card->info.initial_mtu = mtu;
2185 card->info.max_mtu = mtu;
2186 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2187 } else {
2188 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2189 card->info.max_mtu = *(__u16 *)QETH_ULP_ENABLE_RESP_MAX_MTU(
2190 iob->data);
2191 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2194 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2195 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2196 memcpy(&link_type,
2197 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2198 card->info.link_type = link_type;
2199 } else
2200 card->info.link_type = 0;
2201 QETH_DBF_TEXT_(SETUP, 2, "link%d", card->info.link_type);
2202 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2203 return 0;
2206 static int qeth_ulp_enable(struct qeth_card *card)
2208 int rc;
2209 char prot_type;
2210 struct qeth_cmd_buffer *iob;
2212 /*FIXME: trace view callbacks*/
2213 QETH_DBF_TEXT(SETUP, 2, "ulpenabl");
2215 iob = qeth_wait_for_buffer(&card->write);
2216 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2218 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2219 (__u8) card->info.portno;
2220 if (card->options.layer2)
2221 if (card->info.type == QETH_CARD_TYPE_OSN)
2222 prot_type = QETH_PROT_OSN2;
2223 else
2224 prot_type = QETH_PROT_LAYER2;
2225 else
2226 prot_type = QETH_PROT_TCPIP;
2228 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data), &prot_type, 1);
2229 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2230 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2231 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2232 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2233 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2234 card->info.portname, 9);
2235 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2236 qeth_ulp_enable_cb, NULL);
2237 return rc;
2241 static int qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2242 unsigned long data)
2244 struct qeth_cmd_buffer *iob;
2245 int rc = 0;
2247 QETH_DBF_TEXT(SETUP, 2, "ulpstpcb");
2249 iob = (struct qeth_cmd_buffer *) data;
2250 memcpy(&card->token.ulp_connection_r,
2251 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2252 QETH_MPC_TOKEN_LENGTH);
2253 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2254 3)) {
2255 QETH_DBF_TEXT(SETUP, 2, "olmlimit");
2256 dev_err(&card->gdev->dev, "A connection could not be "
2257 "established because of an OLM limit\n");
2258 iob->rc = -EMLINK;
2260 QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
2261 return rc;
2264 static int qeth_ulp_setup(struct qeth_card *card)
2266 int rc;
2267 __u16 temp;
2268 struct qeth_cmd_buffer *iob;
2269 struct ccw_dev_id dev_id;
2271 QETH_DBF_TEXT(SETUP, 2, "ulpsetup");
2273 iob = qeth_wait_for_buffer(&card->write);
2274 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2276 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2277 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2278 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2279 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2280 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2281 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2283 ccw_device_get_id(CARD_DDEV(card), &dev_id);
2284 memcpy(QETH_ULP_SETUP_CUA(iob->data), &dev_id.devno, 2);
2285 temp = (card->info.cula << 8) + card->info.unit_addr2;
2286 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2287 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2288 qeth_ulp_setup_cb, NULL);
2289 return rc;
2292 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q *q, int bidx)
2294 int rc;
2295 struct qeth_qdio_out_buffer *newbuf;
2297 rc = 0;
2298 newbuf = kmem_cache_zalloc(qeth_qdio_outbuf_cache, GFP_ATOMIC);
2299 if (!newbuf) {
2300 rc = -ENOMEM;
2301 goto out;
2303 newbuf->buffer = &q->qdio_bufs[bidx];
2304 skb_queue_head_init(&newbuf->skb_list);
2305 lockdep_set_class(&newbuf->skb_list.lock, &qdio_out_skb_queue_key);
2306 newbuf->q = q;
2307 newbuf->aob = NULL;
2308 newbuf->next_pending = q->bufs[bidx];
2309 atomic_set(&newbuf->state, QETH_QDIO_BUF_EMPTY);
2310 q->bufs[bidx] = newbuf;
2311 if (q->bufstates) {
2312 q->bufstates[bidx].user = newbuf;
2313 QETH_CARD_TEXT_(q->card, 2, "nbs%d", bidx);
2314 QETH_CARD_TEXT_(q->card, 2, "%lx", (long) newbuf);
2315 QETH_CARD_TEXT_(q->card, 2, "%lx",
2316 (long) newbuf->next_pending);
2318 out:
2319 return rc;
2323 static int qeth_alloc_qdio_buffers(struct qeth_card *card)
2325 int i, j;
2327 QETH_DBF_TEXT(SETUP, 2, "allcqdbf");
2329 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
2330 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
2331 return 0;
2333 card->qdio.in_q = kzalloc(sizeof(struct qeth_qdio_q),
2334 GFP_KERNEL);
2335 if (!card->qdio.in_q)
2336 goto out_nomem;
2337 QETH_DBF_TEXT(SETUP, 2, "inq");
2338 QETH_DBF_HEX(SETUP, 2, &card->qdio.in_q, sizeof(void *));
2339 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
2340 /* give inbound qeth_qdio_buffers their qdio_buffers */
2341 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) {
2342 card->qdio.in_q->bufs[i].buffer =
2343 &card->qdio.in_q->qdio_bufs[i];
2344 card->qdio.in_q->bufs[i].rx_skb = NULL;
2346 /* inbound buffer pool */
2347 if (qeth_alloc_buffer_pool(card))
2348 goto out_freeinq;
2350 /* outbound */
2351 card->qdio.out_qs =
2352 kzalloc(card->qdio.no_out_queues *
2353 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
2354 if (!card->qdio.out_qs)
2355 goto out_freepool;
2356 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2357 card->qdio.out_qs[i] = kzalloc(sizeof(struct qeth_qdio_out_q),
2358 GFP_KERNEL);
2359 if (!card->qdio.out_qs[i])
2360 goto out_freeoutq;
2361 QETH_DBF_TEXT_(SETUP, 2, "outq %i", i);
2362 QETH_DBF_HEX(SETUP, 2, &card->qdio.out_qs[i], sizeof(void *));
2363 card->qdio.out_qs[i]->queue_no = i;
2364 /* give outbound qeth_qdio_buffers their qdio_buffers */
2365 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2366 BUG_ON(card->qdio.out_qs[i]->bufs[j] != NULL);
2367 if (qeth_init_qdio_out_buf(card->qdio.out_qs[i], j))
2368 goto out_freeoutqbufs;
2372 /* completion */
2373 if (qeth_alloc_cq(card))
2374 goto out_freeoutq;
2376 return 0;
2378 out_freeoutqbufs:
2379 while (j > 0) {
2380 --j;
2381 kmem_cache_free(qeth_qdio_outbuf_cache,
2382 card->qdio.out_qs[i]->bufs[j]);
2383 card->qdio.out_qs[i]->bufs[j] = NULL;
2385 out_freeoutq:
2386 while (i > 0) {
2387 kfree(card->qdio.out_qs[--i]);
2388 qeth_clear_outq_buffers(card->qdio.out_qs[i], 1);
2390 kfree(card->qdio.out_qs);
2391 card->qdio.out_qs = NULL;
2392 out_freepool:
2393 qeth_free_buffer_pool(card);
2394 out_freeinq:
2395 kfree(card->qdio.in_q);
2396 card->qdio.in_q = NULL;
2397 out_nomem:
2398 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
2399 return -ENOMEM;
2402 static void qeth_create_qib_param_field(struct qeth_card *card,
2403 char *param_field)
2406 param_field[0] = _ascebc['P'];
2407 param_field[1] = _ascebc['C'];
2408 param_field[2] = _ascebc['I'];
2409 param_field[3] = _ascebc['T'];
2410 *((unsigned int *) (&param_field[4])) = QETH_PCI_THRESHOLD_A(card);
2411 *((unsigned int *) (&param_field[8])) = QETH_PCI_THRESHOLD_B(card);
2412 *((unsigned int *) (&param_field[12])) = QETH_PCI_TIMER_VALUE(card);
2415 static void qeth_create_qib_param_field_blkt(struct qeth_card *card,
2416 char *param_field)
2418 param_field[16] = _ascebc['B'];
2419 param_field[17] = _ascebc['L'];
2420 param_field[18] = _ascebc['K'];
2421 param_field[19] = _ascebc['T'];
2422 *((unsigned int *) (&param_field[20])) = card->info.blkt.time_total;
2423 *((unsigned int *) (&param_field[24])) = card->info.blkt.inter_packet;
2424 *((unsigned int *) (&param_field[28])) =
2425 card->info.blkt.inter_packet_jumbo;
2428 static int qeth_qdio_activate(struct qeth_card *card)
2430 QETH_DBF_TEXT(SETUP, 3, "qdioact");
2431 return qdio_activate(CARD_DDEV(card));
2434 static int qeth_dm_act(struct qeth_card *card)
2436 int rc;
2437 struct qeth_cmd_buffer *iob;
2439 QETH_DBF_TEXT(SETUP, 2, "dmact");
2441 iob = qeth_wait_for_buffer(&card->write);
2442 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
2444 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
2445 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2446 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
2447 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2448 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
2449 return rc;
2452 static int qeth_mpc_initialize(struct qeth_card *card)
2454 int rc;
2456 QETH_DBF_TEXT(SETUP, 2, "mpcinit");
2458 rc = qeth_issue_next_read(card);
2459 if (rc) {
2460 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2461 return rc;
2463 rc = qeth_cm_enable(card);
2464 if (rc) {
2465 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
2466 goto out_qdio;
2468 rc = qeth_cm_setup(card);
2469 if (rc) {
2470 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
2471 goto out_qdio;
2473 rc = qeth_ulp_enable(card);
2474 if (rc) {
2475 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
2476 goto out_qdio;
2478 rc = qeth_ulp_setup(card);
2479 if (rc) {
2480 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
2481 goto out_qdio;
2483 rc = qeth_alloc_qdio_buffers(card);
2484 if (rc) {
2485 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
2486 goto out_qdio;
2488 rc = qeth_qdio_establish(card);
2489 if (rc) {
2490 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
2491 qeth_free_qdio_buffers(card);
2492 goto out_qdio;
2494 rc = qeth_qdio_activate(card);
2495 if (rc) {
2496 QETH_DBF_TEXT_(SETUP, 2, "7err%d", rc);
2497 goto out_qdio;
2499 rc = qeth_dm_act(card);
2500 if (rc) {
2501 QETH_DBF_TEXT_(SETUP, 2, "8err%d", rc);
2502 goto out_qdio;
2505 return 0;
2506 out_qdio:
2507 qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
2508 return rc;
2511 static void qeth_print_status_with_portname(struct qeth_card *card)
2513 char dbf_text[15];
2514 int i;
2516 sprintf(dbf_text, "%s", card->info.portname + 1);
2517 for (i = 0; i < 8; i++)
2518 dbf_text[i] =
2519 (char) _ebcasc[(__u8) dbf_text[i]];
2520 dbf_text[8] = 0;
2521 dev_info(&card->gdev->dev, "Device is a%s card%s%s%s\n"
2522 "with link type %s (portname: %s)\n",
2523 qeth_get_cardname(card),
2524 (card->info.mcl_level[0]) ? " (level: " : "",
2525 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2526 (card->info.mcl_level[0]) ? ")" : "",
2527 qeth_get_cardname_short(card),
2528 dbf_text);
2532 static void qeth_print_status_no_portname(struct qeth_card *card)
2534 if (card->info.portname[0])
2535 dev_info(&card->gdev->dev, "Device is a%s "
2536 "card%s%s%s\nwith link type %s "
2537 "(no portname needed by interface).\n",
2538 qeth_get_cardname(card),
2539 (card->info.mcl_level[0]) ? " (level: " : "",
2540 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2541 (card->info.mcl_level[0]) ? ")" : "",
2542 qeth_get_cardname_short(card));
2543 else
2544 dev_info(&card->gdev->dev, "Device is a%s "
2545 "card%s%s%s\nwith link type %s.\n",
2546 qeth_get_cardname(card),
2547 (card->info.mcl_level[0]) ? " (level: " : "",
2548 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
2549 (card->info.mcl_level[0]) ? ")" : "",
2550 qeth_get_cardname_short(card));
2553 void qeth_print_status_message(struct qeth_card *card)
2555 switch (card->info.type) {
2556 case QETH_CARD_TYPE_OSD:
2557 case QETH_CARD_TYPE_OSM:
2558 case QETH_CARD_TYPE_OSX:
2559 /* VM will use a non-zero first character
2560 * to indicate a HiperSockets like reporting
2561 * of the level OSA sets the first character to zero
2562 * */
2563 if (!card->info.mcl_level[0]) {
2564 sprintf(card->info.mcl_level, "%02x%02x",
2565 card->info.mcl_level[2],
2566 card->info.mcl_level[3]);
2568 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2569 break;
2571 /* fallthrough */
2572 case QETH_CARD_TYPE_IQD:
2573 if ((card->info.guestlan) ||
2574 (card->info.mcl_level[0] & 0x80)) {
2575 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
2576 card->info.mcl_level[0]];
2577 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
2578 card->info.mcl_level[1]];
2579 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
2580 card->info.mcl_level[2]];
2581 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
2582 card->info.mcl_level[3]];
2583 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
2585 break;
2586 default:
2587 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
2589 if (card->info.portname_required)
2590 qeth_print_status_with_portname(card);
2591 else
2592 qeth_print_status_no_portname(card);
2594 EXPORT_SYMBOL_GPL(qeth_print_status_message);
2596 static void qeth_initialize_working_pool_list(struct qeth_card *card)
2598 struct qeth_buffer_pool_entry *entry;
2600 QETH_CARD_TEXT(card, 5, "inwrklst");
2602 list_for_each_entry(entry,
2603 &card->qdio.init_pool.entry_list, init_list) {
2604 qeth_put_buffer_pool_entry(card, entry);
2608 static inline struct qeth_buffer_pool_entry *qeth_find_free_buffer_pool_entry(
2609 struct qeth_card *card)
2611 struct list_head *plh;
2612 struct qeth_buffer_pool_entry *entry;
2613 int i, free;
2614 struct page *page;
2616 if (list_empty(&card->qdio.in_buf_pool.entry_list))
2617 return NULL;
2619 list_for_each(plh, &card->qdio.in_buf_pool.entry_list) {
2620 entry = list_entry(plh, struct qeth_buffer_pool_entry, list);
2621 free = 1;
2622 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2623 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2624 free = 0;
2625 break;
2628 if (free) {
2629 list_del_init(&entry->list);
2630 return entry;
2634 /* no free buffer in pool so take first one and swap pages */
2635 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2636 struct qeth_buffer_pool_entry, list);
2637 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2638 if (page_count(virt_to_page(entry->elements[i])) > 1) {
2639 page = alloc_page(GFP_ATOMIC);
2640 if (!page) {
2641 return NULL;
2642 } else {
2643 free_page((unsigned long)entry->elements[i]);
2644 entry->elements[i] = page_address(page);
2645 if (card->options.performance_stats)
2646 card->perf_stats.sg_alloc_page_rx++;
2650 list_del_init(&entry->list);
2651 return entry;
2654 static int qeth_init_input_buffer(struct qeth_card *card,
2655 struct qeth_qdio_buffer *buf)
2657 struct qeth_buffer_pool_entry *pool_entry;
2658 int i;
2660 if ((card->options.cq == QETH_CQ_ENABLED) && (!buf->rx_skb)) {
2661 buf->rx_skb = dev_alloc_skb(QETH_RX_PULL_LEN + ETH_HLEN);
2662 if (!buf->rx_skb)
2663 return 1;
2666 pool_entry = qeth_find_free_buffer_pool_entry(card);
2667 if (!pool_entry)
2668 return 1;
2671 * since the buffer is accessed only from the input_tasklet
2672 * there shouldn't be a need to synchronize; also, since we use
2673 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2674 * buffers
2677 buf->pool_entry = pool_entry;
2678 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
2679 buf->buffer->element[i].length = PAGE_SIZE;
2680 buf->buffer->element[i].addr = pool_entry->elements[i];
2681 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2682 buf->buffer->element[i].eflags = SBAL_EFLAGS_LAST_ENTRY;
2683 else
2684 buf->buffer->element[i].eflags = 0;
2685 buf->buffer->element[i].sflags = 0;
2687 return 0;
2690 int qeth_init_qdio_queues(struct qeth_card *card)
2692 int i, j;
2693 int rc;
2695 QETH_DBF_TEXT(SETUP, 2, "initqdqs");
2697 /* inbound queue */
2698 memset(card->qdio.in_q->qdio_bufs, 0,
2699 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
2700 qeth_initialize_working_pool_list(card);
2701 /*give only as many buffers to hardware as we have buffer pool entries*/
2702 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
2703 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
2704 card->qdio.in_q->next_buf_to_init =
2705 card->qdio.in_buf_pool.buf_count - 1;
2706 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
2707 card->qdio.in_buf_pool.buf_count - 1);
2708 if (rc) {
2709 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
2710 return rc;
2713 /* completion */
2714 rc = qeth_cq_init(card);
2715 if (rc) {
2716 return rc;
2719 /* outbound queue */
2720 for (i = 0; i < card->qdio.no_out_queues; ++i) {
2721 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
2722 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
2723 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
2724 qeth_clear_output_buffer(card->qdio.out_qs[i],
2725 card->qdio.out_qs[i]->bufs[j],
2726 QETH_QDIO_BUF_EMPTY);
2728 card->qdio.out_qs[i]->card = card;
2729 card->qdio.out_qs[i]->next_buf_to_fill = 0;
2730 card->qdio.out_qs[i]->do_pack = 0;
2731 atomic_set(&card->qdio.out_qs[i]->used_buffers, 0);
2732 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
2733 atomic_set(&card->qdio.out_qs[i]->state,
2734 QETH_OUT_Q_UNLOCKED);
2736 return 0;
2738 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues);
2740 static inline __u8 qeth_get_ipa_adp_type(enum qeth_link_types link_type)
2742 switch (link_type) {
2743 case QETH_LINK_TYPE_HSTR:
2744 return 2;
2745 default:
2746 return 1;
2750 static void qeth_fill_ipacmd_header(struct qeth_card *card,
2751 struct qeth_ipa_cmd *cmd, __u8 command,
2752 enum qeth_prot_versions prot)
2754 memset(cmd, 0, sizeof(struct qeth_ipa_cmd));
2755 cmd->hdr.command = command;
2756 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
2757 cmd->hdr.seqno = card->seqno.ipa;
2758 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
2759 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
2760 if (card->options.layer2)
2761 cmd->hdr.prim_version_no = 2;
2762 else
2763 cmd->hdr.prim_version_no = 1;
2764 cmd->hdr.param_count = 1;
2765 cmd->hdr.prot_version = prot;
2766 cmd->hdr.ipa_supported = 0;
2767 cmd->hdr.ipa_enabled = 0;
2770 struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *card,
2771 enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
2773 struct qeth_cmd_buffer *iob;
2774 struct qeth_ipa_cmd *cmd;
2776 iob = qeth_wait_for_buffer(&card->write);
2777 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2778 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
2780 return iob;
2782 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer);
2784 void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2785 char prot_type)
2787 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2788 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data), &prot_type, 1);
2789 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2790 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2792 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd);
2794 int qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2795 int (*reply_cb)(struct qeth_card *, struct qeth_reply*,
2796 unsigned long),
2797 void *reply_param)
2799 int rc;
2800 char prot_type;
2802 QETH_CARD_TEXT(card, 4, "sendipa");
2804 if (card->options.layer2)
2805 if (card->info.type == QETH_CARD_TYPE_OSN)
2806 prot_type = QETH_PROT_OSN2;
2807 else
2808 prot_type = QETH_PROT_LAYER2;
2809 else
2810 prot_type = QETH_PROT_TCPIP;
2811 qeth_prepare_ipa_cmd(card, iob, prot_type);
2812 rc = qeth_send_control_data(card, IPA_CMD_LENGTH,
2813 iob, reply_cb, reply_param);
2814 if (rc == -ETIME) {
2815 qeth_clear_ipacmd_list(card);
2816 qeth_schedule_recovery(card);
2818 return rc;
2820 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd);
2822 int qeth_send_startlan(struct qeth_card *card)
2824 int rc;
2825 struct qeth_cmd_buffer *iob;
2827 QETH_DBF_TEXT(SETUP, 2, "strtlan");
2829 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_STARTLAN, 0);
2830 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
2831 return rc;
2833 EXPORT_SYMBOL_GPL(qeth_send_startlan);
2835 int qeth_default_setadapterparms_cb(struct qeth_card *card,
2836 struct qeth_reply *reply, unsigned long data)
2838 struct qeth_ipa_cmd *cmd;
2840 QETH_CARD_TEXT(card, 4, "defadpcb");
2842 cmd = (struct qeth_ipa_cmd *) data;
2843 if (cmd->hdr.return_code == 0)
2844 cmd->hdr.return_code =
2845 cmd->data.setadapterparms.hdr.return_code;
2846 return 0;
2848 EXPORT_SYMBOL_GPL(qeth_default_setadapterparms_cb);
2850 static int qeth_query_setadapterparms_cb(struct qeth_card *card,
2851 struct qeth_reply *reply, unsigned long data)
2853 struct qeth_ipa_cmd *cmd;
2855 QETH_CARD_TEXT(card, 3, "quyadpcb");
2857 cmd = (struct qeth_ipa_cmd *) data;
2858 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f) {
2859 card->info.link_type =
2860 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
2861 QETH_DBF_TEXT_(SETUP, 2, "lnk %d", card->info.link_type);
2863 card->options.adp.supported_funcs =
2864 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
2865 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
2868 struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
2869 __u32 command, __u32 cmdlen)
2871 struct qeth_cmd_buffer *iob;
2872 struct qeth_ipa_cmd *cmd;
2874 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETADAPTERPARMS,
2875 QETH_PROT_IPV4);
2876 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2877 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
2878 cmd->data.setadapterparms.hdr.command_code = command;
2879 cmd->data.setadapterparms.hdr.used_total = 1;
2880 cmd->data.setadapterparms.hdr.seq_no = 1;
2882 return iob;
2884 EXPORT_SYMBOL_GPL(qeth_get_adapter_cmd);
2886 int qeth_query_setadapterparms(struct qeth_card *card)
2888 int rc;
2889 struct qeth_cmd_buffer *iob;
2891 QETH_CARD_TEXT(card, 3, "queryadp");
2892 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
2893 sizeof(struct qeth_ipacmd_setadpparms));
2894 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
2895 return rc;
2897 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms);
2899 static int qeth_query_ipassists_cb(struct qeth_card *card,
2900 struct qeth_reply *reply, unsigned long data)
2902 struct qeth_ipa_cmd *cmd;
2904 QETH_DBF_TEXT(SETUP, 2, "qipasscb");
2906 cmd = (struct qeth_ipa_cmd *) data;
2907 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
2908 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
2909 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
2910 } else {
2911 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
2912 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
2914 QETH_DBF_TEXT(SETUP, 2, "suppenbl");
2915 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported);
2916 QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled);
2917 return 0;
2920 int qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
2922 int rc;
2923 struct qeth_cmd_buffer *iob;
2925 QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot);
2926 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot);
2927 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
2928 return rc;
2930 EXPORT_SYMBOL_GPL(qeth_query_ipassists);
2932 static int qeth_query_setdiagass_cb(struct qeth_card *card,
2933 struct qeth_reply *reply, unsigned long data)
2935 struct qeth_ipa_cmd *cmd;
2936 __u16 rc;
2938 cmd = (struct qeth_ipa_cmd *)data;
2939 rc = cmd->hdr.return_code;
2940 if (rc)
2941 QETH_CARD_TEXT_(card, 2, "diagq:%x", rc);
2942 else
2943 card->info.diagass_support = cmd->data.diagass.ext;
2944 return 0;
2947 static int qeth_query_setdiagass(struct qeth_card *card)
2949 struct qeth_cmd_buffer *iob;
2950 struct qeth_ipa_cmd *cmd;
2952 QETH_DBF_TEXT(SETUP, 2, "qdiagass");
2953 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
2954 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2955 cmd->data.diagass.subcmd_len = 16;
2956 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_QUERY;
2957 return qeth_send_ipa_cmd(card, iob, qeth_query_setdiagass_cb, NULL);
2960 static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
2962 unsigned long info = get_zeroed_page(GFP_KERNEL);
2963 struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
2964 struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
2965 struct ccw_dev_id ccwid;
2966 int level, rc;
2968 tid->chpid = card->info.chpid;
2969 ccw_device_get_id(CARD_RDEV(card), &ccwid);
2970 tid->ssid = ccwid.ssid;
2971 tid->devno = ccwid.devno;
2972 if (!info)
2973 return;
2975 rc = stsi(NULL, 0, 0, 0);
2976 if (rc == -ENOSYS)
2977 level = rc;
2978 else
2979 level = (((unsigned int) rc) >> 28);
2981 if ((level >= 2) && (stsi(info222, 2, 2, 2) != -ENOSYS))
2982 tid->lparnr = info222->lpar_number;
2984 if ((level >= 3) && (stsi(info322, 3, 2, 2) != -ENOSYS)) {
2985 EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
2986 memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
2988 free_page(info);
2989 return;
2992 static int qeth_hw_trap_cb(struct qeth_card *card,
2993 struct qeth_reply *reply, unsigned long data)
2995 struct qeth_ipa_cmd *cmd;
2996 __u16 rc;
2998 cmd = (struct qeth_ipa_cmd *)data;
2999 rc = cmd->hdr.return_code;
3000 if (rc)
3001 QETH_CARD_TEXT_(card, 2, "trapc:%x", rc);
3002 return 0;
3005 int qeth_hw_trap(struct qeth_card *card, enum qeth_diags_trap_action action)
3007 struct qeth_cmd_buffer *iob;
3008 struct qeth_ipa_cmd *cmd;
3010 QETH_DBF_TEXT(SETUP, 2, "diagtrap");
3011 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
3012 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
3013 cmd->data.diagass.subcmd_len = 80;
3014 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRAP;
3015 cmd->data.diagass.type = 1;
3016 cmd->data.diagass.action = action;
3017 switch (action) {
3018 case QETH_DIAGS_TRAP_ARM:
3019 cmd->data.diagass.options = 0x0003;
3020 cmd->data.diagass.ext = 0x00010000 +
3021 sizeof(struct qeth_trap_id);
3022 qeth_get_trap_id(card,
3023 (struct qeth_trap_id *)cmd->data.diagass.cdata);
3024 break;
3025 case QETH_DIAGS_TRAP_DISARM:
3026 cmd->data.diagass.options = 0x0001;
3027 break;
3028 case QETH_DIAGS_TRAP_CAPTURE:
3029 break;
3031 return qeth_send_ipa_cmd(card, iob, qeth_hw_trap_cb, NULL);
3033 EXPORT_SYMBOL_GPL(qeth_hw_trap);
3035 int qeth_check_qdio_errors(struct qeth_card *card, struct qdio_buffer *buf,
3036 unsigned int qdio_error, const char *dbftext)
3038 if (qdio_error) {
3039 QETH_CARD_TEXT(card, 2, dbftext);
3040 QETH_CARD_TEXT_(card, 2, " F15=%02X",
3041 buf->element[15].sflags);
3042 QETH_CARD_TEXT_(card, 2, " F14=%02X",
3043 buf->element[14].sflags);
3044 QETH_CARD_TEXT_(card, 2, " qerr=%X", qdio_error);
3045 if ((buf->element[15].sflags) == 0x12) {
3046 card->stats.rx_dropped++;
3047 return 0;
3048 } else
3049 return 1;
3051 return 0;
3053 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors);
3055 void qeth_buffer_reclaim_work(struct work_struct *work)
3057 struct qeth_card *card = container_of(work, struct qeth_card,
3058 buffer_reclaim_work.work);
3060 QETH_CARD_TEXT_(card, 2, "brw:%x", card->reclaim_index);
3061 qeth_queue_input_buffer(card, card->reclaim_index);
3064 void qeth_queue_input_buffer(struct qeth_card *card, int index)
3066 struct qeth_qdio_q *queue = card->qdio.in_q;
3067 struct list_head *lh;
3068 int count;
3069 int i;
3070 int rc;
3071 int newcount = 0;
3073 count = (index < queue->next_buf_to_init)?
3074 card->qdio.in_buf_pool.buf_count -
3075 (queue->next_buf_to_init - index) :
3076 card->qdio.in_buf_pool.buf_count -
3077 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
3078 /* only requeue at a certain threshold to avoid SIGAs */
3079 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)) {
3080 for (i = queue->next_buf_to_init;
3081 i < queue->next_buf_to_init + count; ++i) {
3082 if (qeth_init_input_buffer(card,
3083 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q])) {
3084 break;
3085 } else {
3086 newcount++;
3090 if (newcount < count) {
3091 /* we are in memory shortage so we switch back to
3092 traditional skb allocation and drop packages */
3093 atomic_set(&card->force_alloc_skb, 3);
3094 count = newcount;
3095 } else {
3096 atomic_add_unless(&card->force_alloc_skb, -1, 0);
3099 if (!count) {
3100 i = 0;
3101 list_for_each(lh, &card->qdio.in_buf_pool.entry_list)
3102 i++;
3103 if (i == card->qdio.in_buf_pool.buf_count) {
3104 QETH_CARD_TEXT(card, 2, "qsarbw");
3105 card->reclaim_index = index;
3106 schedule_delayed_work(
3107 &card->buffer_reclaim_work,
3108 QETH_RECLAIM_WORK_TIME);
3110 return;
3114 * according to old code it should be avoided to requeue all
3115 * 128 buffers in order to benefit from PCI avoidance.
3116 * this function keeps at least one buffer (the buffer at
3117 * 'index') un-requeued -> this buffer is the first buffer that
3118 * will be requeued the next time
3120 if (card->options.performance_stats) {
3121 card->perf_stats.inbound_do_qdio_cnt++;
3122 card->perf_stats.inbound_do_qdio_start_time =
3123 qeth_get_micros();
3125 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0,
3126 queue->next_buf_to_init, count);
3127 if (card->options.performance_stats)
3128 card->perf_stats.inbound_do_qdio_time +=
3129 qeth_get_micros() -
3130 card->perf_stats.inbound_do_qdio_start_time;
3131 if (rc) {
3132 QETH_CARD_TEXT(card, 2, "qinberr");
3134 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
3135 QDIO_MAX_BUFFERS_PER_Q;
3138 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer);
3140 static int qeth_handle_send_error(struct qeth_card *card,
3141 struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err)
3143 int sbalf15 = buffer->buffer->element[15].sflags;
3145 QETH_CARD_TEXT(card, 6, "hdsnderr");
3146 if (card->info.type == QETH_CARD_TYPE_IQD) {
3147 if (sbalf15 == 0) {
3148 qdio_err = 0;
3149 } else {
3150 qdio_err = 1;
3153 qeth_check_qdio_errors(card, buffer->buffer, qdio_err, "qouterr");
3155 if (!qdio_err)
3156 return QETH_SEND_ERROR_NONE;
3158 if ((sbalf15 >= 15) && (sbalf15 <= 31))
3159 return QETH_SEND_ERROR_RETRY;
3161 QETH_CARD_TEXT(card, 1, "lnkfail");
3162 QETH_CARD_TEXT_(card, 1, "%04x %02x",
3163 (u16)qdio_err, (u8)sbalf15);
3164 return QETH_SEND_ERROR_LINK_FAILURE;
3168 * Switched to packing state if the number of used buffers on a queue
3169 * reaches a certain limit.
3171 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
3173 if (!queue->do_pack) {
3174 if (atomic_read(&queue->used_buffers)
3175 >= QETH_HIGH_WATERMARK_PACK){
3176 /* switch non-PACKING -> PACKING */
3177 QETH_CARD_TEXT(queue->card, 6, "np->pack");
3178 if (queue->card->options.performance_stats)
3179 queue->card->perf_stats.sc_dp_p++;
3180 queue->do_pack = 1;
3186 * Switches from packing to non-packing mode. If there is a packing
3187 * buffer on the queue this buffer will be prepared to be flushed.
3188 * In that case 1 is returned to inform the caller. If no buffer
3189 * has to be flushed, zero is returned.
3191 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
3193 struct qeth_qdio_out_buffer *buffer;
3194 int flush_count = 0;
3196 if (queue->do_pack) {
3197 if (atomic_read(&queue->used_buffers)
3198 <= QETH_LOW_WATERMARK_PACK) {
3199 /* switch PACKING -> non-PACKING */
3200 QETH_CARD_TEXT(queue->card, 6, "pack->np");
3201 if (queue->card->options.performance_stats)
3202 queue->card->perf_stats.sc_p_dp++;
3203 queue->do_pack = 0;
3204 /* flush packing buffers */
3205 buffer = queue->bufs[queue->next_buf_to_fill];
3206 if ((atomic_read(&buffer->state) ==
3207 QETH_QDIO_BUF_EMPTY) &&
3208 (buffer->next_element_to_fill > 0)) {
3209 atomic_set(&buffer->state,
3210 QETH_QDIO_BUF_PRIMED);
3211 flush_count++;
3212 queue->next_buf_to_fill =
3213 (queue->next_buf_to_fill + 1) %
3214 QDIO_MAX_BUFFERS_PER_Q;
3218 return flush_count;
3223 * Called to flush a packing buffer if no more pci flags are on the queue.
3224 * Checks if there is a packing buffer and prepares it to be flushed.
3225 * In that case returns 1, otherwise zero.
3227 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
3229 struct qeth_qdio_out_buffer *buffer;
3231 buffer = queue->bufs[queue->next_buf_to_fill];
3232 if ((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
3233 (buffer->next_element_to_fill > 0)) {
3234 /* it's a packing buffer */
3235 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
3236 queue->next_buf_to_fill =
3237 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
3238 return 1;
3240 return 0;
3243 static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
3244 int count)
3246 struct qeth_qdio_out_buffer *buf;
3247 int rc;
3248 int i;
3249 unsigned int qdio_flags;
3251 for (i = index; i < index + count; ++i) {
3252 int bidx = i % QDIO_MAX_BUFFERS_PER_Q;
3253 buf = queue->bufs[bidx];
3254 buf->buffer->element[buf->next_element_to_fill - 1].eflags |=
3255 SBAL_EFLAGS_LAST_ENTRY;
3257 if (queue->bufstates)
3258 queue->bufstates[bidx].user = buf;
3260 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
3261 continue;
3263 if (!queue->do_pack) {
3264 if ((atomic_read(&queue->used_buffers) >=
3265 (QETH_HIGH_WATERMARK_PACK -
3266 QETH_WATERMARK_PACK_FUZZ)) &&
3267 !atomic_read(&queue->set_pci_flags_count)) {
3268 /* it's likely that we'll go to packing
3269 * mode soon */
3270 atomic_inc(&queue->set_pci_flags_count);
3271 buf->buffer->element[0].sflags |= SBAL_SFLAGS0_PCI_REQ;
3273 } else {
3274 if (!atomic_read(&queue->set_pci_flags_count)) {
3276 * there's no outstanding PCI any more, so we
3277 * have to request a PCI to be sure the the PCI
3278 * will wake at some time in the future then we
3279 * can flush packed buffers that might still be
3280 * hanging around, which can happen if no
3281 * further send was requested by the stack
3283 atomic_inc(&queue->set_pci_flags_count);
3284 buf->buffer->element[0].sflags |= SBAL_SFLAGS0_PCI_REQ;
3289 queue->card->dev->trans_start = jiffies;
3290 if (queue->card->options.performance_stats) {
3291 queue->card->perf_stats.outbound_do_qdio_cnt++;
3292 queue->card->perf_stats.outbound_do_qdio_start_time =
3293 qeth_get_micros();
3295 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
3296 if (atomic_read(&queue->set_pci_flags_count))
3297 qdio_flags |= QDIO_FLAG_PCI_OUT;
3298 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
3299 queue->queue_no, index, count);
3300 if (queue->card->options.performance_stats)
3301 queue->card->perf_stats.outbound_do_qdio_time +=
3302 qeth_get_micros() -
3303 queue->card->perf_stats.outbound_do_qdio_start_time;
3304 atomic_add(count, &queue->used_buffers);
3305 if (rc) {
3306 queue->card->stats.tx_errors += count;
3307 /* ignore temporary SIGA errors without busy condition */
3308 if (rc == QDIO_ERROR_SIGA_TARGET)
3309 return;
3310 QETH_CARD_TEXT(queue->card, 2, "flushbuf");
3311 QETH_CARD_TEXT_(queue->card, 2, " q%d", queue->queue_no);
3312 QETH_CARD_TEXT_(queue->card, 2, " idx%d", index);
3313 QETH_CARD_TEXT_(queue->card, 2, " c%d", count);
3314 QETH_CARD_TEXT_(queue->card, 2, " err%d", rc);
3316 /* this must not happen under normal circumstances. if it
3317 * happens something is really wrong -> recover */
3318 qeth_schedule_recovery(queue->card);
3319 return;
3321 if (queue->card->options.performance_stats)
3322 queue->card->perf_stats.bufs_sent += count;
3325 static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
3327 int index;
3328 int flush_cnt = 0;
3329 int q_was_packing = 0;
3332 * check if weed have to switch to non-packing mode or if
3333 * we have to get a pci flag out on the queue
3335 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
3336 !atomic_read(&queue->set_pci_flags_count)) {
3337 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
3338 QETH_OUT_Q_UNLOCKED) {
3340 * If we get in here, there was no action in
3341 * do_send_packet. So, we check if there is a
3342 * packing buffer to be flushed here.
3344 netif_stop_queue(queue->card->dev);
3345 index = queue->next_buf_to_fill;
3346 q_was_packing = queue->do_pack;
3347 /* queue->do_pack may change */
3348 barrier();
3349 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
3350 if (!flush_cnt &&
3351 !atomic_read(&queue->set_pci_flags_count))
3352 flush_cnt +=
3353 qeth_flush_buffers_on_no_pci(queue);
3354 if (queue->card->options.performance_stats &&
3355 q_was_packing)
3356 queue->card->perf_stats.bufs_sent_pack +=
3357 flush_cnt;
3358 if (flush_cnt)
3359 qeth_flush_buffers(queue, index, flush_cnt);
3360 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3365 void qeth_qdio_start_poll(struct ccw_device *ccwdev, int queue,
3366 unsigned long card_ptr)
3368 struct qeth_card *card = (struct qeth_card *)card_ptr;
3370 if (card->dev && (card->dev->flags & IFF_UP))
3371 napi_schedule(&card->napi);
3373 EXPORT_SYMBOL_GPL(qeth_qdio_start_poll);
3375 int qeth_configure_cq(struct qeth_card *card, enum qeth_cq cq)
3377 int rc;
3379 if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
3380 rc = -1;
3381 goto out;
3382 } else {
3383 if (card->options.cq == cq) {
3384 rc = 0;
3385 goto out;
3388 if (card->state != CARD_STATE_DOWN &&
3389 card->state != CARD_STATE_RECOVER) {
3390 rc = -1;
3391 goto out;
3394 qeth_free_qdio_buffers(card);
3395 card->options.cq = cq;
3396 rc = 0;
3398 out:
3399 return rc;
3402 EXPORT_SYMBOL_GPL(qeth_configure_cq);
3405 static void qeth_qdio_cq_handler(struct qeth_card *card,
3406 unsigned int qdio_err,
3407 unsigned int queue, int first_element, int count) {
3408 struct qeth_qdio_q *cq = card->qdio.c_q;
3409 int i;
3410 int rc;
3412 if (!qeth_is_cq(card, queue))
3413 goto out;
3415 QETH_CARD_TEXT_(card, 5, "qcqhe%d", first_element);
3416 QETH_CARD_TEXT_(card, 5, "qcqhc%d", count);
3417 QETH_CARD_TEXT_(card, 5, "qcqherr%d", qdio_err);
3419 if (qdio_err) {
3420 netif_stop_queue(card->dev);
3421 qeth_schedule_recovery(card);
3422 goto out;
3425 if (card->options.performance_stats) {
3426 card->perf_stats.cq_cnt++;
3427 card->perf_stats.cq_start_time = qeth_get_micros();
3430 for (i = first_element; i < first_element + count; ++i) {
3431 int bidx = i % QDIO_MAX_BUFFERS_PER_Q;
3432 struct qdio_buffer *buffer = &cq->qdio_bufs[bidx];
3433 int e;
3435 e = 0;
3436 while (buffer->element[e].addr) {
3437 unsigned long phys_aob_addr;
3439 phys_aob_addr = (unsigned long) buffer->element[e].addr;
3440 qeth_qdio_handle_aob(card, phys_aob_addr);
3441 buffer->element[e].addr = NULL;
3442 buffer->element[e].eflags = 0;
3443 buffer->element[e].sflags = 0;
3444 buffer->element[e].length = 0;
3446 ++e;
3449 buffer->element[15].eflags = 0;
3450 buffer->element[15].sflags = 0;
3452 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, queue,
3453 card->qdio.c_q->next_buf_to_init,
3454 count);
3455 if (rc) {
3456 dev_warn(&card->gdev->dev,
3457 "QDIO reported an error, rc=%i\n", rc);
3458 QETH_CARD_TEXT(card, 2, "qcqherr");
3460 card->qdio.c_q->next_buf_to_init = (card->qdio.c_q->next_buf_to_init
3461 + count) % QDIO_MAX_BUFFERS_PER_Q;
3463 netif_wake_queue(card->dev);
3465 if (card->options.performance_stats) {
3466 int delta_t = qeth_get_micros();
3467 delta_t -= card->perf_stats.cq_start_time;
3468 card->perf_stats.cq_time += delta_t;
3470 out:
3471 return;
3474 void qeth_qdio_input_handler(struct ccw_device *ccwdev, unsigned int qdio_err,
3475 unsigned int queue, int first_elem, int count,
3476 unsigned long card_ptr)
3478 struct qeth_card *card = (struct qeth_card *)card_ptr;
3480 QETH_CARD_TEXT_(card, 2, "qihq%d", queue);
3481 QETH_CARD_TEXT_(card, 2, "qiec%d", qdio_err);
3483 if (qeth_is_cq(card, queue))
3484 qeth_qdio_cq_handler(card, qdio_err, queue, first_elem, count);
3485 else if (qdio_err)
3486 qeth_schedule_recovery(card);
3490 EXPORT_SYMBOL_GPL(qeth_qdio_input_handler);
3492 void qeth_qdio_output_handler(struct ccw_device *ccwdev,
3493 unsigned int qdio_error, int __queue, int first_element,
3494 int count, unsigned long card_ptr)
3496 struct qeth_card *card = (struct qeth_card *) card_ptr;
3497 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3498 struct qeth_qdio_out_buffer *buffer;
3499 int i;
3501 QETH_CARD_TEXT(card, 6, "qdouhdl");
3502 if (qdio_error & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
3503 QETH_CARD_TEXT(card, 2, "achkcond");
3504 netif_stop_queue(card->dev);
3505 qeth_schedule_recovery(card);
3506 return;
3508 if (card->options.performance_stats) {
3509 card->perf_stats.outbound_handler_cnt++;
3510 card->perf_stats.outbound_handler_start_time =
3511 qeth_get_micros();
3513 for (i = first_element; i < (first_element + count); ++i) {
3514 int bidx = i % QDIO_MAX_BUFFERS_PER_Q;
3515 buffer = queue->bufs[bidx];
3516 qeth_handle_send_error(card, buffer, qdio_error);
3518 if (queue->bufstates &&
3519 (queue->bufstates[bidx].flags &
3520 QDIO_OUTBUF_STATE_FLAG_PENDING) != 0) {
3521 BUG_ON(card->options.cq != QETH_CQ_ENABLED);
3523 if (atomic_cmpxchg(&buffer->state,
3524 QETH_QDIO_BUF_PRIMED,
3525 QETH_QDIO_BUF_PENDING) ==
3526 QETH_QDIO_BUF_PRIMED) {
3527 qeth_notify_skbs(queue, buffer,
3528 TX_NOTIFY_PENDING);
3530 buffer->aob = queue->bufstates[bidx].aob;
3531 QETH_CARD_TEXT_(queue->card, 5, "pel%d", bidx);
3532 QETH_CARD_TEXT(queue->card, 5, "aob");
3533 QETH_CARD_TEXT_(queue->card, 5, "%lx",
3534 virt_to_phys(buffer->aob));
3535 BUG_ON(bidx < 0 || bidx >= QDIO_MAX_BUFFERS_PER_Q);
3536 if (qeth_init_qdio_out_buf(queue, bidx)) {
3537 QETH_CARD_TEXT(card, 2, "outofbuf");
3538 qeth_schedule_recovery(card);
3540 } else {
3541 if (card->options.cq == QETH_CQ_ENABLED) {
3542 enum iucv_tx_notify n;
3544 n = qeth_compute_cq_notification(
3545 buffer->buffer->element[15].sflags, 0);
3546 qeth_notify_skbs(queue, buffer, n);
3549 qeth_clear_output_buffer(queue, buffer,
3550 QETH_QDIO_BUF_EMPTY);
3552 qeth_cleanup_handled_pending(queue, bidx, 0);
3554 atomic_sub(count, &queue->used_buffers);
3555 /* check if we need to do something on this outbound queue */
3556 if (card->info.type != QETH_CARD_TYPE_IQD)
3557 qeth_check_outbound_queue(queue);
3559 netif_wake_queue(queue->card->dev);
3560 if (card->options.performance_stats)
3561 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3562 card->perf_stats.outbound_handler_start_time;
3564 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler);
3566 int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3567 int ipv, int cast_type)
3569 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSD ||
3570 card->info.type == QETH_CARD_TYPE_OSX))
3571 return card->qdio.default_out_queue;
3572 switch (card->qdio.no_out_queues) {
3573 case 4:
3574 if (cast_type && card->info.is_multicast_different)
3575 return card->info.is_multicast_different &
3576 (card->qdio.no_out_queues - 1);
3577 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3578 const u8 tos = ip_hdr(skb)->tos;
3580 if (card->qdio.do_prio_queueing ==
3581 QETH_PRIO_Q_ING_TOS) {
3582 if (tos & IP_TOS_NOTIMPORTANT)
3583 return 3;
3584 if (tos & IP_TOS_HIGHRELIABILITY)
3585 return 2;
3586 if (tos & IP_TOS_HIGHTHROUGHPUT)
3587 return 1;
3588 if (tos & IP_TOS_LOWDELAY)
3589 return 0;
3591 if (card->qdio.do_prio_queueing ==
3592 QETH_PRIO_Q_ING_PREC)
3593 return 3 - (tos >> 6);
3594 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3595 /* TODO: IPv6!!! */
3597 return card->qdio.default_out_queue;
3598 case 1: /* fallthrough for single-out-queue 1920-device */
3599 default:
3600 return card->qdio.default_out_queue;
3603 EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
3605 int qeth_get_elements_no(struct qeth_card *card, void *hdr,
3606 struct sk_buff *skb, int elems)
3608 int dlen = skb->len - skb->data_len;
3609 int elements_needed = PFN_UP((unsigned long)skb->data + dlen - 1) -
3610 PFN_DOWN((unsigned long)skb->data);
3612 elements_needed += skb_shinfo(skb)->nr_frags;
3613 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
3614 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3615 "(Number=%d / Length=%d). Discarded.\n",
3616 (elements_needed+elems), skb->len);
3617 return 0;
3619 return elements_needed;
3621 EXPORT_SYMBOL_GPL(qeth_get_elements_no);
3623 int qeth_hdr_chk_and_bounce(struct sk_buff *skb, int len)
3625 int hroom, inpage, rest;
3627 if (((unsigned long)skb->data & PAGE_MASK) !=
3628 (((unsigned long)skb->data + len - 1) & PAGE_MASK)) {
3629 hroom = skb_headroom(skb);
3630 inpage = PAGE_SIZE - ((unsigned long) skb->data % PAGE_SIZE);
3631 rest = len - inpage;
3632 if (rest > hroom)
3633 return 1;
3634 memmove(skb->data - rest, skb->data, skb->len - skb->data_len);
3635 skb->data -= rest;
3636 QETH_DBF_MESSAGE(2, "skb bounce len: %d rest: %d\n", len, rest);
3638 return 0;
3640 EXPORT_SYMBOL_GPL(qeth_hdr_chk_and_bounce);
3642 static inline void __qeth_fill_buffer(struct sk_buff *skb,
3643 struct qdio_buffer *buffer, int is_tso, int *next_element_to_fill,
3644 int offset)
3646 int length = skb->len - skb->data_len;
3647 int length_here;
3648 int element;
3649 char *data;
3650 int first_lap, cnt;
3651 struct skb_frag_struct *frag;
3653 element = *next_element_to_fill;
3654 data = skb->data;
3655 first_lap = (is_tso == 0 ? 1 : 0);
3657 if (offset >= 0) {
3658 data = skb->data + offset;
3659 length -= offset;
3660 first_lap = 0;
3663 while (length > 0) {
3664 /* length_here is the remaining amount of data in this page */
3665 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
3666 if (length < length_here)
3667 length_here = length;
3669 buffer->element[element].addr = data;
3670 buffer->element[element].length = length_here;
3671 length -= length_here;
3672 if (!length) {
3673 if (first_lap)
3674 if (skb_shinfo(skb)->nr_frags)
3675 buffer->element[element].eflags =
3676 SBAL_EFLAGS_FIRST_FRAG;
3677 else
3678 buffer->element[element].eflags = 0;
3679 else
3680 buffer->element[element].eflags =
3681 SBAL_EFLAGS_MIDDLE_FRAG;
3682 } else {
3683 if (first_lap)
3684 buffer->element[element].eflags =
3685 SBAL_EFLAGS_FIRST_FRAG;
3686 else
3687 buffer->element[element].eflags =
3688 SBAL_EFLAGS_MIDDLE_FRAG;
3690 data += length_here;
3691 element++;
3692 first_lap = 0;
3695 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
3696 frag = &skb_shinfo(skb)->frags[cnt];
3697 buffer->element[element].addr = (char *)page_to_phys(frag->page)
3698 + frag->page_offset;
3699 buffer->element[element].length = frag->size;
3700 buffer->element[element].eflags = SBAL_EFLAGS_MIDDLE_FRAG;
3701 element++;
3704 if (buffer->element[element - 1].eflags)
3705 buffer->element[element - 1].eflags = SBAL_EFLAGS_LAST_FRAG;
3706 *next_element_to_fill = element;
3709 static inline int qeth_fill_buffer(struct qeth_qdio_out_q *queue,
3710 struct qeth_qdio_out_buffer *buf, struct sk_buff *skb,
3711 struct qeth_hdr *hdr, int offset, int hd_len)
3713 struct qdio_buffer *buffer;
3714 int flush_cnt = 0, hdr_len, large_send = 0;
3716 buffer = buf->buffer;
3717 atomic_inc(&skb->users);
3718 skb_queue_tail(&buf->skb_list, skb);
3720 /*check first on TSO ....*/
3721 if (hdr->hdr.l3.id == QETH_HEADER_TYPE_TSO) {
3722 int element = buf->next_element_to_fill;
3724 hdr_len = sizeof(struct qeth_hdr_tso) +
3725 ((struct qeth_hdr_tso *)hdr)->ext.dg_hdr_len;
3726 /*fill first buffer entry only with header information */
3727 buffer->element[element].addr = skb->data;
3728 buffer->element[element].length = hdr_len;
3729 buffer->element[element].eflags = SBAL_EFLAGS_FIRST_FRAG;
3730 buf->next_element_to_fill++;
3731 skb->data += hdr_len;
3732 skb->len -= hdr_len;
3733 large_send = 1;
3736 if (offset >= 0) {
3737 int element = buf->next_element_to_fill;
3738 buffer->element[element].addr = hdr;
3739 buffer->element[element].length = sizeof(struct qeth_hdr) +
3740 hd_len;
3741 buffer->element[element].eflags = SBAL_EFLAGS_FIRST_FRAG;
3742 buf->is_header[element] = 1;
3743 buf->next_element_to_fill++;
3746 __qeth_fill_buffer(skb, buffer, large_send,
3747 (int *)&buf->next_element_to_fill, offset);
3749 if (!queue->do_pack) {
3750 QETH_CARD_TEXT(queue->card, 6, "fillbfnp");
3751 /* set state to PRIMED -> will be flushed */
3752 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
3753 flush_cnt = 1;
3754 } else {
3755 QETH_CARD_TEXT(queue->card, 6, "fillbfpa");
3756 if (queue->card->options.performance_stats)
3757 queue->card->perf_stats.skbs_sent_pack++;
3758 if (buf->next_element_to_fill >=
3759 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
3761 * packed buffer if full -> set state PRIMED
3762 * -> will be flushed
3764 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
3765 flush_cnt = 1;
3768 return flush_cnt;
3771 int qeth_do_send_packet_fast(struct qeth_card *card,
3772 struct qeth_qdio_out_q *queue, struct sk_buff *skb,
3773 struct qeth_hdr *hdr, int elements_needed,
3774 int offset, int hd_len)
3776 struct qeth_qdio_out_buffer *buffer;
3777 int index;
3779 /* spin until we get the queue ... */
3780 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3781 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
3782 /* ... now we've got the queue */
3783 index = queue->next_buf_to_fill;
3784 buffer = queue->bufs[queue->next_buf_to_fill];
3786 * check if buffer is empty to make sure that we do not 'overtake'
3787 * ourselves and try to fill a buffer that is already primed
3789 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
3790 goto out;
3791 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
3792 QDIO_MAX_BUFFERS_PER_Q;
3793 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3794 qeth_fill_buffer(queue, buffer, skb, hdr, offset, hd_len);
3795 qeth_flush_buffers(queue, index, 1);
3796 return 0;
3797 out:
3798 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3799 return -EBUSY;
3801 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast);
3803 int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
3804 struct sk_buff *skb, struct qeth_hdr *hdr,
3805 int elements_needed)
3807 struct qeth_qdio_out_buffer *buffer;
3808 int start_index;
3809 int flush_count = 0;
3810 int do_pack = 0;
3811 int tmp;
3812 int rc = 0;
3814 /* spin until we get the queue ... */
3815 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3816 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
3817 start_index = queue->next_buf_to_fill;
3818 buffer = queue->bufs[queue->next_buf_to_fill];
3820 * check if buffer is empty to make sure that we do not 'overtake'
3821 * ourselves and try to fill a buffer that is already primed
3823 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
3824 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3825 return -EBUSY;
3827 /* check if we need to switch packing state of this queue */
3828 qeth_switch_to_packing_if_needed(queue);
3829 if (queue->do_pack) {
3830 do_pack = 1;
3831 /* does packet fit in current buffer? */
3832 if ((QETH_MAX_BUFFER_ELEMENTS(card) -
3833 buffer->next_element_to_fill) < elements_needed) {
3834 /* ... no -> set state PRIMED */
3835 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
3836 flush_count++;
3837 queue->next_buf_to_fill =
3838 (queue->next_buf_to_fill + 1) %
3839 QDIO_MAX_BUFFERS_PER_Q;
3840 buffer = queue->bufs[queue->next_buf_to_fill];
3841 /* we did a step forward, so check buffer state
3842 * again */
3843 if (atomic_read(&buffer->state) !=
3844 QETH_QDIO_BUF_EMPTY) {
3845 qeth_flush_buffers(queue, start_index,
3846 flush_count);
3847 atomic_set(&queue->state,
3848 QETH_OUT_Q_UNLOCKED);
3849 return -EBUSY;
3853 tmp = qeth_fill_buffer(queue, buffer, skb, hdr, -1, 0);
3854 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
3855 QDIO_MAX_BUFFERS_PER_Q;
3856 flush_count += tmp;
3857 if (flush_count)
3858 qeth_flush_buffers(queue, start_index, flush_count);
3859 else if (!atomic_read(&queue->set_pci_flags_count))
3860 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
3862 * queue->state will go from LOCKED -> UNLOCKED or from
3863 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
3864 * (switch packing state or flush buffer to get another pci flag out).
3865 * In that case we will enter this loop
3867 while (atomic_dec_return(&queue->state)) {
3868 flush_count = 0;
3869 start_index = queue->next_buf_to_fill;
3870 /* check if we can go back to non-packing state */
3871 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
3873 * check if we need to flush a packing buffer to get a pci
3874 * flag out on the queue
3876 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
3877 flush_count += qeth_flush_buffers_on_no_pci(queue);
3878 if (flush_count)
3879 qeth_flush_buffers(queue, start_index, flush_count);
3881 /* at this point the queue is UNLOCKED again */
3882 if (queue->card->options.performance_stats && do_pack)
3883 queue->card->perf_stats.bufs_sent_pack += flush_count;
3885 return rc;
3887 EXPORT_SYMBOL_GPL(qeth_do_send_packet);
3889 static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
3890 struct qeth_reply *reply, unsigned long data)
3892 struct qeth_ipa_cmd *cmd;
3893 struct qeth_ipacmd_setadpparms *setparms;
3895 QETH_CARD_TEXT(card, 4, "prmadpcb");
3897 cmd = (struct qeth_ipa_cmd *) data;
3898 setparms = &(cmd->data.setadapterparms);
3900 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
3901 if (cmd->hdr.return_code) {
3902 QETH_CARD_TEXT_(card, 4, "prmrc%2.2x", cmd->hdr.return_code);
3903 setparms->data.mode = SET_PROMISC_MODE_OFF;
3905 card->info.promisc_mode = setparms->data.mode;
3906 return 0;
3909 void qeth_setadp_promisc_mode(struct qeth_card *card)
3911 enum qeth_ipa_promisc_modes mode;
3912 struct net_device *dev = card->dev;
3913 struct qeth_cmd_buffer *iob;
3914 struct qeth_ipa_cmd *cmd;
3916 QETH_CARD_TEXT(card, 4, "setprom");
3918 if (((dev->flags & IFF_PROMISC) &&
3919 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
3920 (!(dev->flags & IFF_PROMISC) &&
3921 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
3922 return;
3923 mode = SET_PROMISC_MODE_OFF;
3924 if (dev->flags & IFF_PROMISC)
3925 mode = SET_PROMISC_MODE_ON;
3926 QETH_CARD_TEXT_(card, 4, "mode:%x", mode);
3928 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
3929 sizeof(struct qeth_ipacmd_setadpparms));
3930 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
3931 cmd->data.setadapterparms.data.mode = mode;
3932 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
3934 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode);
3936 int qeth_change_mtu(struct net_device *dev, int new_mtu)
3938 struct qeth_card *card;
3939 char dbf_text[15];
3941 card = dev->ml_priv;
3943 QETH_CARD_TEXT(card, 4, "chgmtu");
3944 sprintf(dbf_text, "%8x", new_mtu);
3945 QETH_CARD_TEXT(card, 4, dbf_text);
3947 if (new_mtu < 64)
3948 return -EINVAL;
3949 if (new_mtu > 65535)
3950 return -EINVAL;
3951 if ((!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) &&
3952 (!qeth_mtu_is_valid(card, new_mtu)))
3953 return -EINVAL;
3954 dev->mtu = new_mtu;
3955 return 0;
3957 EXPORT_SYMBOL_GPL(qeth_change_mtu);
3959 struct net_device_stats *qeth_get_stats(struct net_device *dev)
3961 struct qeth_card *card;
3963 card = dev->ml_priv;
3965 QETH_CARD_TEXT(card, 5, "getstat");
3967 return &card->stats;
3969 EXPORT_SYMBOL_GPL(qeth_get_stats);
3971 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
3972 struct qeth_reply *reply, unsigned long data)
3974 struct qeth_ipa_cmd *cmd;
3976 QETH_CARD_TEXT(card, 4, "chgmaccb");
3978 cmd = (struct qeth_ipa_cmd *) data;
3979 if (!card->options.layer2 ||
3980 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
3981 memcpy(card->dev->dev_addr,
3982 &cmd->data.setadapterparms.data.change_addr.addr,
3983 OSA_ADDR_LEN);
3984 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
3986 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
3987 return 0;
3990 int qeth_setadpparms_change_macaddr(struct qeth_card *card)
3992 int rc;
3993 struct qeth_cmd_buffer *iob;
3994 struct qeth_ipa_cmd *cmd;
3996 QETH_CARD_TEXT(card, 4, "chgmac");
3998 iob = qeth_get_adapter_cmd(card, IPA_SETADP_ALTER_MAC_ADDRESS,
3999 sizeof(struct qeth_ipacmd_setadpparms));
4000 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4001 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
4002 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
4003 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
4004 card->dev->dev_addr, OSA_ADDR_LEN);
4005 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
4006 NULL);
4007 return rc;
4009 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
4011 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card *card,
4012 struct qeth_reply *reply, unsigned long data)
4014 struct qeth_ipa_cmd *cmd;
4015 struct qeth_set_access_ctrl *access_ctrl_req;
4017 QETH_CARD_TEXT(card, 4, "setaccb");
4019 cmd = (struct qeth_ipa_cmd *) data;
4020 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4021 QETH_DBF_TEXT_(SETUP, 2, "setaccb");
4022 QETH_DBF_TEXT_(SETUP, 2, "%s", card->gdev->dev.kobj.name);
4023 QETH_DBF_TEXT_(SETUP, 2, "rc=%d",
4024 cmd->data.setadapterparms.hdr.return_code);
4025 switch (cmd->data.setadapterparms.hdr.return_code) {
4026 case SET_ACCESS_CTRL_RC_SUCCESS:
4027 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED:
4028 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED:
4030 card->options.isolation = access_ctrl_req->subcmd_code;
4031 if (card->options.isolation == ISOLATION_MODE_NONE) {
4032 dev_info(&card->gdev->dev,
4033 "QDIO data connection isolation is deactivated\n");
4034 } else {
4035 dev_info(&card->gdev->dev,
4036 "QDIO data connection isolation is activated\n");
4038 QETH_DBF_MESSAGE(3, "OK:SET_ACCESS_CTRL(%s, %d)==%d\n",
4039 card->gdev->dev.kobj.name,
4040 access_ctrl_req->subcmd_code,
4041 cmd->data.setadapterparms.hdr.return_code);
4042 break;
4044 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED:
4046 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
4047 card->gdev->dev.kobj.name,
4048 access_ctrl_req->subcmd_code,
4049 cmd->data.setadapterparms.hdr.return_code);
4050 dev_err(&card->gdev->dev, "Adapter does not "
4051 "support QDIO data connection isolation\n");
4053 /* ensure isolation mode is "none" */
4054 card->options.isolation = ISOLATION_MODE_NONE;
4055 break;
4057 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER:
4059 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d\n",
4060 card->gdev->dev.kobj.name,
4061 access_ctrl_req->subcmd_code,
4062 cmd->data.setadapterparms.hdr.return_code);
4063 dev_err(&card->gdev->dev,
4064 "Adapter is dedicated. "
4065 "QDIO data connection isolation not supported\n");
4067 /* ensure isolation mode is "none" */
4068 card->options.isolation = ISOLATION_MODE_NONE;
4069 break;
4071 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF:
4073 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d\n",
4074 card->gdev->dev.kobj.name,
4075 access_ctrl_req->subcmd_code,
4076 cmd->data.setadapterparms.hdr.return_code);
4077 dev_err(&card->gdev->dev,
4078 "TSO does not permit QDIO data connection isolation\n");
4080 /* ensure isolation mode is "none" */
4081 card->options.isolation = ISOLATION_MODE_NONE;
4082 break;
4084 default:
4086 /* this should never happen */
4087 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d"
4088 "==UNKNOWN\n",
4089 card->gdev->dev.kobj.name,
4090 access_ctrl_req->subcmd_code,
4091 cmd->data.setadapterparms.hdr.return_code);
4093 /* ensure isolation mode is "none" */
4094 card->options.isolation = ISOLATION_MODE_NONE;
4095 break;
4098 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
4099 return 0;
4102 static int qeth_setadpparms_set_access_ctrl(struct qeth_card *card,
4103 enum qeth_ipa_isolation_modes isolation)
4105 int rc;
4106 struct qeth_cmd_buffer *iob;
4107 struct qeth_ipa_cmd *cmd;
4108 struct qeth_set_access_ctrl *access_ctrl_req;
4110 QETH_CARD_TEXT(card, 4, "setacctl");
4112 QETH_DBF_TEXT_(SETUP, 2, "setacctl");
4113 QETH_DBF_TEXT_(SETUP, 2, "%s", card->gdev->dev.kobj.name);
4115 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_ACCESS_CONTROL,
4116 sizeof(struct qeth_ipacmd_setadpparms_hdr) +
4117 sizeof(struct qeth_set_access_ctrl));
4118 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4119 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4120 access_ctrl_req->subcmd_code = isolation;
4122 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_set_access_ctrl_cb,
4123 NULL);
4124 QETH_DBF_TEXT_(SETUP, 2, "rc=%d", rc);
4125 return rc;
4128 int qeth_set_access_ctrl_online(struct qeth_card *card)
4130 int rc = 0;
4132 QETH_CARD_TEXT(card, 4, "setactlo");
4134 if ((card->info.type == QETH_CARD_TYPE_OSD ||
4135 card->info.type == QETH_CARD_TYPE_OSX) &&
4136 qeth_adp_supported(card, IPA_SETADP_SET_ACCESS_CONTROL)) {
4137 rc = qeth_setadpparms_set_access_ctrl(card,
4138 card->options.isolation);
4139 if (rc) {
4140 QETH_DBF_MESSAGE(3,
4141 "IPA(SET_ACCESS_CTRL,%s,%d) sent failed\n",
4142 card->gdev->dev.kobj.name,
4143 rc);
4145 } else if (card->options.isolation != ISOLATION_MODE_NONE) {
4146 card->options.isolation = ISOLATION_MODE_NONE;
4148 dev_err(&card->gdev->dev, "Adapter does not "
4149 "support QDIO data connection isolation\n");
4150 rc = -EOPNOTSUPP;
4152 return rc;
4154 EXPORT_SYMBOL_GPL(qeth_set_access_ctrl_online);
4156 void qeth_tx_timeout(struct net_device *dev)
4158 struct qeth_card *card;
4160 card = dev->ml_priv;
4161 QETH_CARD_TEXT(card, 4, "txtimeo");
4162 card->stats.tx_errors++;
4163 qeth_schedule_recovery(card);
4165 EXPORT_SYMBOL_GPL(qeth_tx_timeout);
4167 int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4169 struct qeth_card *card = dev->ml_priv;
4170 int rc = 0;
4172 switch (regnum) {
4173 case MII_BMCR: /* Basic mode control register */
4174 rc = BMCR_FULLDPLX;
4175 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH) &&
4176 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4177 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4178 rc |= BMCR_SPEED100;
4179 break;
4180 case MII_BMSR: /* Basic mode status register */
4181 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4182 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4183 BMSR_100BASE4;
4184 break;
4185 case MII_PHYSID1: /* PHYS ID 1 */
4186 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4187 dev->dev_addr[2];
4188 rc = (rc >> 5) & 0xFFFF;
4189 break;
4190 case MII_PHYSID2: /* PHYS ID 2 */
4191 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4192 break;
4193 case MII_ADVERTISE: /* Advertisement control reg */
4194 rc = ADVERTISE_ALL;
4195 break;
4196 case MII_LPA: /* Link partner ability reg */
4197 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4198 LPA_100BASE4 | LPA_LPACK;
4199 break;
4200 case MII_EXPANSION: /* Expansion register */
4201 break;
4202 case MII_DCOUNTER: /* disconnect counter */
4203 break;
4204 case MII_FCSCOUNTER: /* false carrier counter */
4205 break;
4206 case MII_NWAYTEST: /* N-way auto-neg test register */
4207 break;
4208 case MII_RERRCOUNTER: /* rx error counter */
4209 rc = card->stats.rx_errors;
4210 break;
4211 case MII_SREVISION: /* silicon revision */
4212 break;
4213 case MII_RESV1: /* reserved 1 */
4214 break;
4215 case MII_LBRERROR: /* loopback, rx, bypass error */
4216 break;
4217 case MII_PHYADDR: /* physical address */
4218 break;
4219 case MII_RESV2: /* reserved 2 */
4220 break;
4221 case MII_TPISTATUS: /* TPI status for 10mbps */
4222 break;
4223 case MII_NCONFIG: /* network interface config */
4224 break;
4225 default:
4226 break;
4228 return rc;
4230 EXPORT_SYMBOL_GPL(qeth_mdio_read);
4232 static int qeth_send_ipa_snmp_cmd(struct qeth_card *card,
4233 struct qeth_cmd_buffer *iob, int len,
4234 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
4235 unsigned long),
4236 void *reply_param)
4238 u16 s1, s2;
4240 QETH_CARD_TEXT(card, 4, "sendsnmp");
4242 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4243 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4244 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4245 /* adjust PDU length fields in IPA_PDU_HEADER */
4246 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4247 s2 = (u32) len;
4248 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4249 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4250 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4251 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4252 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4253 reply_cb, reply_param);
4256 static int qeth_snmp_command_cb(struct qeth_card *card,
4257 struct qeth_reply *reply, unsigned long sdata)
4259 struct qeth_ipa_cmd *cmd;
4260 struct qeth_arp_query_info *qinfo;
4261 struct qeth_snmp_cmd *snmp;
4262 unsigned char *data;
4263 __u16 data_len;
4265 QETH_CARD_TEXT(card, 3, "snpcmdcb");
4267 cmd = (struct qeth_ipa_cmd *) sdata;
4268 data = (unsigned char *)((char *)cmd - reply->offset);
4269 qinfo = (struct qeth_arp_query_info *) reply->param;
4270 snmp = &cmd->data.setadapterparms.data.snmp;
4272 if (cmd->hdr.return_code) {
4273 QETH_CARD_TEXT_(card, 4, "scer1%i", cmd->hdr.return_code);
4274 return 0;
4276 if (cmd->data.setadapterparms.hdr.return_code) {
4277 cmd->hdr.return_code =
4278 cmd->data.setadapterparms.hdr.return_code;
4279 QETH_CARD_TEXT_(card, 4, "scer2%i", cmd->hdr.return_code);
4280 return 0;
4282 data_len = *((__u16 *)QETH_IPA_PDU_LEN_PDU1(data));
4283 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4284 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4285 else
4286 data_len -= (__u16)((char *)&snmp->request - (char *)cmd);
4288 /* check if there is enough room in userspace */
4289 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4290 QETH_CARD_TEXT_(card, 4, "scer3%i", -ENOMEM);
4291 cmd->hdr.return_code = -ENOMEM;
4292 return 0;
4294 QETH_CARD_TEXT_(card, 4, "snore%i",
4295 cmd->data.setadapterparms.hdr.used_total);
4296 QETH_CARD_TEXT_(card, 4, "sseqn%i",
4297 cmd->data.setadapterparms.hdr.seq_no);
4298 /*copy entries to user buffer*/
4299 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4300 memcpy(qinfo->udata + qinfo->udata_offset,
4301 (char *)snmp,
4302 data_len + offsetof(struct qeth_snmp_cmd, data));
4303 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4304 } else {
4305 memcpy(qinfo->udata + qinfo->udata_offset,
4306 (char *)&snmp->request, data_len);
4308 qinfo->udata_offset += data_len;
4309 /* check if all replies received ... */
4310 QETH_CARD_TEXT_(card, 4, "srtot%i",
4311 cmd->data.setadapterparms.hdr.used_total);
4312 QETH_CARD_TEXT_(card, 4, "srseq%i",
4313 cmd->data.setadapterparms.hdr.seq_no);
4314 if (cmd->data.setadapterparms.hdr.seq_no <
4315 cmd->data.setadapterparms.hdr.used_total)
4316 return 1;
4317 return 0;
4320 int qeth_snmp_command(struct qeth_card *card, char __user *udata)
4322 struct qeth_cmd_buffer *iob;
4323 struct qeth_ipa_cmd *cmd;
4324 struct qeth_snmp_ureq *ureq;
4325 int req_len;
4326 struct qeth_arp_query_info qinfo = {0, };
4327 int rc = 0;
4329 QETH_CARD_TEXT(card, 3, "snmpcmd");
4331 if (card->info.guestlan)
4332 return -EOPNOTSUPP;
4334 if ((!qeth_adp_supported(card, IPA_SETADP_SET_SNMP_CONTROL)) &&
4335 (!card->options.layer2)) {
4336 return -EOPNOTSUPP;
4338 /* skip 4 bytes (data_len struct member) to get req_len */
4339 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4340 return -EFAULT;
4341 ureq = memdup_user(udata, req_len + sizeof(struct qeth_snmp_ureq_hdr));
4342 if (IS_ERR(ureq)) {
4343 QETH_CARD_TEXT(card, 2, "snmpnome");
4344 return PTR_ERR(ureq);
4346 qinfo.udata_len = ureq->hdr.data_len;
4347 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
4348 if (!qinfo.udata) {
4349 kfree(ureq);
4350 return -ENOMEM;
4352 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4354 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
4355 QETH_SNMP_SETADP_CMDLENGTH + req_len);
4356 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4357 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
4358 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
4359 qeth_snmp_command_cb, (void *)&qinfo);
4360 if (rc)
4361 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
4362 QETH_CARD_IFNAME(card), rc);
4363 else {
4364 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4365 rc = -EFAULT;
4368 kfree(ureq);
4369 kfree(qinfo.udata);
4370 return rc;
4372 EXPORT_SYMBOL_GPL(qeth_snmp_command);
4374 static inline int qeth_get_qdio_q_format(struct qeth_card *card)
4376 switch (card->info.type) {
4377 case QETH_CARD_TYPE_IQD:
4378 return 2;
4379 default:
4380 return 0;
4384 static void qeth_determine_capabilities(struct qeth_card *card)
4386 int rc;
4387 int length;
4388 char *prcd;
4389 struct ccw_device *ddev;
4390 int ddev_offline = 0;
4392 QETH_DBF_TEXT(SETUP, 2, "detcapab");
4393 ddev = CARD_DDEV(card);
4394 if (!ddev->online) {
4395 ddev_offline = 1;
4396 rc = ccw_device_set_online(ddev);
4397 if (rc) {
4398 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
4399 goto out;
4403 rc = qeth_read_conf_data(card, (void **) &prcd, &length);
4404 if (rc) {
4405 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
4406 dev_name(&card->gdev->dev), rc);
4407 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
4408 goto out_offline;
4410 qeth_configure_unitaddr(card, prcd);
4411 qeth_configure_blkt_default(card, prcd);
4412 kfree(prcd);
4414 rc = qdio_get_ssqd_desc(ddev, &card->ssqd);
4415 if (rc)
4416 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
4418 QETH_DBF_TEXT_(SETUP, 2, "qfmt%d", card->ssqd.qfmt);
4419 QETH_DBF_TEXT_(SETUP, 2, "%d", card->ssqd.qdioac1);
4420 QETH_DBF_TEXT_(SETUP, 2, "%d", card->ssqd.qdioac3);
4421 QETH_DBF_TEXT_(SETUP, 2, "icnt%d", card->ssqd.icnt);
4422 if (!((card->ssqd.qfmt != QDIO_IQDIO_QFMT) ||
4423 ((card->ssqd.qdioac1 & CHSC_AC1_INITIATE_INPUTQ) == 0) ||
4424 ((card->ssqd.qdioac3 & CHSC_AC3_FORMAT2_CQ_AVAILABLE) == 0))) {
4425 dev_info(&card->gdev->dev,
4426 "Completion Queueing supported\n");
4427 } else {
4428 card->options.cq = QETH_CQ_NOTAVAILABLE;
4432 out_offline:
4433 if (ddev_offline == 1)
4434 ccw_device_set_offline(ddev);
4435 out:
4436 return;
4439 static inline void qeth_qdio_establish_cq(struct qeth_card *card,
4440 struct qdio_buffer **in_sbal_ptrs,
4441 void (**queue_start_poll) (struct ccw_device *, int, unsigned long)) {
4442 int i;
4444 if (card->options.cq == QETH_CQ_ENABLED) {
4445 int offset = QDIO_MAX_BUFFERS_PER_Q *
4446 (card->qdio.no_in_queues - 1);
4447 i = QDIO_MAX_BUFFERS_PER_Q * (card->qdio.no_in_queues - 1);
4448 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) {
4449 in_sbal_ptrs[offset + i] = (struct qdio_buffer *)
4450 virt_to_phys(card->qdio.c_q->bufs[i].buffer);
4453 queue_start_poll[card->qdio.no_in_queues - 1] = NULL;
4457 static int qeth_qdio_establish(struct qeth_card *card)
4459 struct qdio_initialize init_data;
4460 char *qib_param_field;
4461 struct qdio_buffer **in_sbal_ptrs;
4462 void (**queue_start_poll) (struct ccw_device *, int, unsigned long);
4463 struct qdio_buffer **out_sbal_ptrs;
4464 int i, j, k;
4465 int rc = 0;
4467 QETH_DBF_TEXT(SETUP, 2, "qdioest");
4469 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
4470 GFP_KERNEL);
4471 if (!qib_param_field) {
4472 rc = -ENOMEM;
4473 goto out_free_nothing;
4476 qeth_create_qib_param_field(card, qib_param_field);
4477 qeth_create_qib_param_field_blkt(card, qib_param_field);
4479 in_sbal_ptrs = kzalloc(card->qdio.no_in_queues *
4480 QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
4481 GFP_KERNEL);
4482 if (!in_sbal_ptrs) {
4483 rc = -ENOMEM;
4484 goto out_free_qib_param;
4486 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) {
4487 in_sbal_ptrs[i] = (struct qdio_buffer *)
4488 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
4491 queue_start_poll = kzalloc(sizeof(void *) * card->qdio.no_in_queues,
4492 GFP_KERNEL);
4493 if (!queue_start_poll) {
4494 rc = -ENOMEM;
4495 goto out_free_in_sbals;
4497 for (i = 0; i < card->qdio.no_in_queues; ++i)
4498 queue_start_poll[i] = card->discipline.start_poll;
4500 qeth_qdio_establish_cq(card, in_sbal_ptrs, queue_start_poll);
4502 out_sbal_ptrs =
4503 kzalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
4504 sizeof(void *), GFP_KERNEL);
4505 if (!out_sbal_ptrs) {
4506 rc = -ENOMEM;
4507 goto out_free_queue_start_poll;
4509 for (i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
4510 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k) {
4511 out_sbal_ptrs[k] = (struct qdio_buffer *)virt_to_phys(
4512 card->qdio.out_qs[i]->bufs[j]->buffer);
4515 memset(&init_data, 0, sizeof(struct qdio_initialize));
4516 init_data.cdev = CARD_DDEV(card);
4517 init_data.q_format = qeth_get_qdio_q_format(card);
4518 init_data.qib_param_field_format = 0;
4519 init_data.qib_param_field = qib_param_field;
4520 init_data.no_input_qs = card->qdio.no_in_queues;
4521 init_data.no_output_qs = card->qdio.no_out_queues;
4522 init_data.input_handler = card->discipline.input_handler;
4523 init_data.output_handler = card->discipline.output_handler;
4524 init_data.queue_start_poll = queue_start_poll;
4525 init_data.int_parm = (unsigned long) card;
4526 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
4527 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
4528 init_data.output_sbal_state_array = card->qdio.out_bufstates;
4529 init_data.scan_threshold =
4530 (card->info.type == QETH_CARD_TYPE_IQD) ? 8 : 32;
4532 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
4533 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
4534 rc = qdio_allocate(&init_data);
4535 if (rc) {
4536 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
4537 goto out;
4539 rc = qdio_establish(&init_data);
4540 if (rc) {
4541 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
4542 qdio_free(CARD_DDEV(card));
4546 switch (card->options.cq) {
4547 case QETH_CQ_ENABLED:
4548 dev_info(&card->gdev->dev, "Completion Queue support enabled");
4549 break;
4550 case QETH_CQ_DISABLED:
4551 dev_info(&card->gdev->dev, "Completion Queue support disabled");
4552 break;
4553 default:
4554 break;
4556 out:
4557 kfree(out_sbal_ptrs);
4558 out_free_queue_start_poll:
4559 kfree(queue_start_poll);
4560 out_free_in_sbals:
4561 kfree(in_sbal_ptrs);
4562 out_free_qib_param:
4563 kfree(qib_param_field);
4564 out_free_nothing:
4565 return rc;
4568 static void qeth_core_free_card(struct qeth_card *card)
4571 QETH_DBF_TEXT(SETUP, 2, "freecrd");
4572 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
4573 qeth_clean_channel(&card->read);
4574 qeth_clean_channel(&card->write);
4575 if (card->dev)
4576 free_netdev(card->dev);
4577 kfree(card->ip_tbd_list);
4578 qeth_free_qdio_buffers(card);
4579 unregister_service_level(&card->qeth_service_level);
4580 kfree(card);
4583 static struct ccw_device_id qeth_ids[] = {
4584 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
4585 .driver_info = QETH_CARD_TYPE_OSD},
4586 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
4587 .driver_info = QETH_CARD_TYPE_IQD},
4588 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
4589 .driver_info = QETH_CARD_TYPE_OSN},
4590 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
4591 .driver_info = QETH_CARD_TYPE_OSM},
4592 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
4593 .driver_info = QETH_CARD_TYPE_OSX},
4596 MODULE_DEVICE_TABLE(ccw, qeth_ids);
4598 static struct ccw_driver qeth_ccw_driver = {
4599 .driver = {
4600 .owner = THIS_MODULE,
4601 .name = "qeth",
4603 .ids = qeth_ids,
4604 .probe = ccwgroup_probe_ccwdev,
4605 .remove = ccwgroup_remove_ccwdev,
4608 static int qeth_core_driver_group(const char *buf, struct device *root_dev,
4609 unsigned long driver_id)
4611 return ccwgroup_create_from_string(root_dev, driver_id,
4612 &qeth_ccw_driver, 3, buf);
4615 int qeth_core_hardsetup_card(struct qeth_card *card)
4617 int retries = 0;
4618 int rc;
4620 QETH_DBF_TEXT(SETUP, 2, "hrdsetup");
4621 atomic_set(&card->force_alloc_skb, 0);
4622 qeth_get_channel_path_desc(card);
4623 retry:
4624 if (retries)
4625 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
4626 dev_name(&card->gdev->dev));
4627 ccw_device_set_offline(CARD_DDEV(card));
4628 ccw_device_set_offline(CARD_WDEV(card));
4629 ccw_device_set_offline(CARD_RDEV(card));
4630 rc = ccw_device_set_online(CARD_RDEV(card));
4631 if (rc)
4632 goto retriable;
4633 rc = ccw_device_set_online(CARD_WDEV(card));
4634 if (rc)
4635 goto retriable;
4636 rc = ccw_device_set_online(CARD_DDEV(card));
4637 if (rc)
4638 goto retriable;
4639 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
4640 retriable:
4641 if (rc == -ERESTARTSYS) {
4642 QETH_DBF_TEXT(SETUP, 2, "break1");
4643 return rc;
4644 } else if (rc) {
4645 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
4646 if (++retries > 3)
4647 goto out;
4648 else
4649 goto retry;
4651 qeth_determine_capabilities(card);
4652 qeth_init_tokens(card);
4653 qeth_init_func_level(card);
4654 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
4655 if (rc == -ERESTARTSYS) {
4656 QETH_DBF_TEXT(SETUP, 2, "break2");
4657 return rc;
4658 } else if (rc) {
4659 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
4660 if (--retries < 0)
4661 goto out;
4662 else
4663 goto retry;
4665 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
4666 if (rc == -ERESTARTSYS) {
4667 QETH_DBF_TEXT(SETUP, 2, "break3");
4668 return rc;
4669 } else if (rc) {
4670 QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
4671 if (--retries < 0)
4672 goto out;
4673 else
4674 goto retry;
4676 card->read_or_write_problem = 0;
4677 rc = qeth_mpc_initialize(card);
4678 if (rc) {
4679 QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
4680 goto out;
4683 card->options.ipa4.supported_funcs = 0;
4684 card->options.adp.supported_funcs = 0;
4685 card->info.diagass_support = 0;
4686 qeth_query_ipassists(card, QETH_PROT_IPV4);
4687 if (qeth_is_supported(card, IPA_SETADAPTERPARMS))
4688 qeth_query_setadapterparms(card);
4689 if (qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST))
4690 qeth_query_setdiagass(card);
4691 return 0;
4692 out:
4693 dev_warn(&card->gdev->dev, "The qeth device driver failed to recover "
4694 "an error on the device\n");
4695 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
4696 dev_name(&card->gdev->dev), rc);
4697 return rc;
4699 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card);
4701 static inline int qeth_create_skb_frag(struct qeth_qdio_buffer *qethbuffer,
4702 struct qdio_buffer_element *element,
4703 struct sk_buff **pskb, int offset, int *pfrag, int data_len)
4705 struct page *page = virt_to_page(element->addr);
4706 if (*pskb == NULL) {
4707 if (qethbuffer->rx_skb) {
4708 /* only if qeth_card.options.cq == QETH_CQ_ENABLED */
4709 *pskb = qethbuffer->rx_skb;
4710 qethbuffer->rx_skb = NULL;
4711 } else {
4712 *pskb = dev_alloc_skb(QETH_RX_PULL_LEN + ETH_HLEN);
4713 if (!(*pskb))
4714 return -ENOMEM;
4717 skb_reserve(*pskb, ETH_HLEN);
4718 if (data_len <= QETH_RX_PULL_LEN) {
4719 memcpy(skb_put(*pskb, data_len), element->addr + offset,
4720 data_len);
4721 } else {
4722 get_page(page);
4723 memcpy(skb_put(*pskb, QETH_RX_PULL_LEN),
4724 element->addr + offset, QETH_RX_PULL_LEN);
4725 skb_fill_page_desc(*pskb, *pfrag, page,
4726 offset + QETH_RX_PULL_LEN,
4727 data_len - QETH_RX_PULL_LEN);
4728 (*pskb)->data_len += data_len - QETH_RX_PULL_LEN;
4729 (*pskb)->len += data_len - QETH_RX_PULL_LEN;
4730 (*pskb)->truesize += data_len - QETH_RX_PULL_LEN;
4731 (*pfrag)++;
4733 } else {
4734 get_page(page);
4735 skb_fill_page_desc(*pskb, *pfrag, page, offset, data_len);
4736 (*pskb)->data_len += data_len;
4737 (*pskb)->len += data_len;
4738 (*pskb)->truesize += data_len;
4739 (*pfrag)++;
4743 return 0;
4746 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
4747 struct qeth_qdio_buffer *qethbuffer,
4748 struct qdio_buffer_element **__element, int *__offset,
4749 struct qeth_hdr **hdr)
4751 struct qdio_buffer_element *element = *__element;
4752 struct qdio_buffer *buffer = qethbuffer->buffer;
4753 int offset = *__offset;
4754 struct sk_buff *skb = NULL;
4755 int skb_len = 0;
4756 void *data_ptr;
4757 int data_len;
4758 int headroom = 0;
4759 int use_rx_sg = 0;
4760 int frag = 0;
4762 /* qeth_hdr must not cross element boundaries */
4763 if (element->length < offset + sizeof(struct qeth_hdr)) {
4764 if (qeth_is_last_sbale(element))
4765 return NULL;
4766 element++;
4767 offset = 0;
4768 if (element->length < sizeof(struct qeth_hdr))
4769 return NULL;
4771 *hdr = element->addr + offset;
4773 offset += sizeof(struct qeth_hdr);
4774 switch ((*hdr)->hdr.l2.id) {
4775 case QETH_HEADER_TYPE_LAYER2:
4776 skb_len = (*hdr)->hdr.l2.pkt_length;
4777 break;
4778 case QETH_HEADER_TYPE_LAYER3:
4779 skb_len = (*hdr)->hdr.l3.length;
4780 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
4781 (card->info.link_type == QETH_LINK_TYPE_HSTR))
4782 headroom = TR_HLEN;
4783 else
4784 headroom = ETH_HLEN;
4785 break;
4786 case QETH_HEADER_TYPE_OSN:
4787 skb_len = (*hdr)->hdr.osn.pdu_length;
4788 headroom = sizeof(struct qeth_hdr);
4789 break;
4790 default:
4791 break;
4794 if (!skb_len)
4795 return NULL;
4797 if (((skb_len >= card->options.rx_sg_cb) &&
4798 (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
4799 (!atomic_read(&card->force_alloc_skb))) ||
4800 (card->options.cq == QETH_CQ_ENABLED)) {
4801 use_rx_sg = 1;
4802 } else {
4803 skb = dev_alloc_skb(skb_len + headroom);
4804 if (!skb)
4805 goto no_mem;
4806 if (headroom)
4807 skb_reserve(skb, headroom);
4810 data_ptr = element->addr + offset;
4811 while (skb_len) {
4812 data_len = min(skb_len, (int)(element->length - offset));
4813 if (data_len) {
4814 if (use_rx_sg) {
4815 if (qeth_create_skb_frag(qethbuffer, element,
4816 &skb, offset, &frag, data_len))
4817 goto no_mem;
4818 } else {
4819 memcpy(skb_put(skb, data_len), data_ptr,
4820 data_len);
4823 skb_len -= data_len;
4824 if (skb_len) {
4825 if (qeth_is_last_sbale(element)) {
4826 QETH_CARD_TEXT(card, 4, "unexeob");
4827 QETH_CARD_HEX(card, 2, buffer, sizeof(void *));
4828 dev_kfree_skb_any(skb);
4829 card->stats.rx_errors++;
4830 return NULL;
4832 element++;
4833 offset = 0;
4834 data_ptr = element->addr;
4835 } else {
4836 offset += data_len;
4839 *__element = element;
4840 *__offset = offset;
4841 if (use_rx_sg && card->options.performance_stats) {
4842 card->perf_stats.sg_skbs_rx++;
4843 card->perf_stats.sg_frags_rx += skb_shinfo(skb)->nr_frags;
4845 return skb;
4846 no_mem:
4847 if (net_ratelimit()) {
4848 QETH_CARD_TEXT(card, 2, "noskbmem");
4850 card->stats.rx_dropped++;
4851 return NULL;
4853 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb);
4855 static void qeth_unregister_dbf_views(void)
4857 int x;
4858 for (x = 0; x < QETH_DBF_INFOS; x++) {
4859 debug_unregister(qeth_dbf[x].id);
4860 qeth_dbf[x].id = NULL;
4864 void qeth_dbf_longtext(debug_info_t *id, int level, char *fmt, ...)
4866 char dbf_txt_buf[32];
4867 va_list args;
4869 if (level > id->level)
4870 return;
4871 va_start(args, fmt);
4872 vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
4873 va_end(args);
4874 debug_text_event(id, level, dbf_txt_buf);
4876 EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
4878 static int qeth_register_dbf_views(void)
4880 int ret;
4881 int x;
4883 for (x = 0; x < QETH_DBF_INFOS; x++) {
4884 /* register the areas */
4885 qeth_dbf[x].id = debug_register(qeth_dbf[x].name,
4886 qeth_dbf[x].pages,
4887 qeth_dbf[x].areas,
4888 qeth_dbf[x].len);
4889 if (qeth_dbf[x].id == NULL) {
4890 qeth_unregister_dbf_views();
4891 return -ENOMEM;
4894 /* register a view */
4895 ret = debug_register_view(qeth_dbf[x].id, qeth_dbf[x].view);
4896 if (ret) {
4897 qeth_unregister_dbf_views();
4898 return ret;
4901 /* set a passing level */
4902 debug_set_level(qeth_dbf[x].id, qeth_dbf[x].level);
4905 return 0;
4908 int qeth_core_load_discipline(struct qeth_card *card,
4909 enum qeth_discipline_id discipline)
4911 int rc = 0;
4912 switch (discipline) {
4913 case QETH_DISCIPLINE_LAYER3:
4914 card->discipline.ccwgdriver = try_then_request_module(
4915 symbol_get(qeth_l3_ccwgroup_driver),
4916 "qeth_l3");
4917 break;
4918 case QETH_DISCIPLINE_LAYER2:
4919 card->discipline.ccwgdriver = try_then_request_module(
4920 symbol_get(qeth_l2_ccwgroup_driver),
4921 "qeth_l2");
4922 break;
4924 if (!card->discipline.ccwgdriver) {
4925 dev_err(&card->gdev->dev, "There is no kernel module to "
4926 "support discipline %d\n", discipline);
4927 rc = -EINVAL;
4929 return rc;
4932 void qeth_core_free_discipline(struct qeth_card *card)
4934 if (card->options.layer2)
4935 symbol_put(qeth_l2_ccwgroup_driver);
4936 else
4937 symbol_put(qeth_l3_ccwgroup_driver);
4938 card->discipline.ccwgdriver = NULL;
4941 static int qeth_core_probe_device(struct ccwgroup_device *gdev)
4943 struct qeth_card *card;
4944 struct device *dev;
4945 int rc;
4946 unsigned long flags;
4947 char dbf_name[20];
4949 QETH_DBF_TEXT(SETUP, 2, "probedev");
4951 dev = &gdev->dev;
4952 if (!get_device(dev))
4953 return -ENODEV;
4955 QETH_DBF_TEXT_(SETUP, 2, "%s", dev_name(&gdev->dev));
4957 card = qeth_alloc_card();
4958 if (!card) {
4959 QETH_DBF_TEXT_(SETUP, 2, "1err%d", -ENOMEM);
4960 rc = -ENOMEM;
4961 goto err_dev;
4964 snprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s",
4965 dev_name(&gdev->dev));
4966 card->debug = debug_register(dbf_name, 2, 1, 8);
4967 if (!card->debug) {
4968 QETH_DBF_TEXT_(SETUP, 2, "%s", "qcdbf");
4969 rc = -ENOMEM;
4970 goto err_card;
4972 debug_register_view(card->debug, &debug_hex_ascii_view);
4974 card->read.ccwdev = gdev->cdev[0];
4975 card->write.ccwdev = gdev->cdev[1];
4976 card->data.ccwdev = gdev->cdev[2];
4977 dev_set_drvdata(&gdev->dev, card);
4978 card->gdev = gdev;
4979 gdev->cdev[0]->handler = qeth_irq;
4980 gdev->cdev[1]->handler = qeth_irq;
4981 gdev->cdev[2]->handler = qeth_irq;
4983 rc = qeth_determine_card_type(card);
4984 if (rc) {
4985 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
4986 goto err_dbf;
4988 rc = qeth_setup_card(card);
4989 if (rc) {
4990 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
4991 goto err_dbf;
4994 if (card->info.type == QETH_CARD_TYPE_OSN)
4995 rc = qeth_core_create_osn_attributes(dev);
4996 else
4997 rc = qeth_core_create_device_attributes(dev);
4998 if (rc)
4999 goto err_dbf;
5000 switch (card->info.type) {
5001 case QETH_CARD_TYPE_OSN:
5002 case QETH_CARD_TYPE_OSM:
5003 rc = qeth_core_load_discipline(card, QETH_DISCIPLINE_LAYER2);
5004 if (rc)
5005 goto err_attr;
5006 rc = card->discipline.ccwgdriver->probe(card->gdev);
5007 if (rc)
5008 goto err_disc;
5009 case QETH_CARD_TYPE_OSD:
5010 case QETH_CARD_TYPE_OSX:
5011 default:
5012 break;
5015 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
5016 list_add_tail(&card->list, &qeth_core_card_list.list);
5017 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
5019 qeth_determine_capabilities(card);
5020 return 0;
5022 err_disc:
5023 qeth_core_free_discipline(card);
5024 err_attr:
5025 if (card->info.type == QETH_CARD_TYPE_OSN)
5026 qeth_core_remove_osn_attributes(dev);
5027 else
5028 qeth_core_remove_device_attributes(dev);
5029 err_dbf:
5030 debug_unregister(card->debug);
5031 err_card:
5032 qeth_core_free_card(card);
5033 err_dev:
5034 put_device(dev);
5035 return rc;
5038 static void qeth_core_remove_device(struct ccwgroup_device *gdev)
5040 unsigned long flags;
5041 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5043 QETH_DBF_TEXT(SETUP, 2, "removedv");
5045 if (card->info.type == QETH_CARD_TYPE_OSN) {
5046 qeth_core_remove_osn_attributes(&gdev->dev);
5047 } else {
5048 qeth_core_remove_device_attributes(&gdev->dev);
5051 if (card->discipline.ccwgdriver) {
5052 card->discipline.ccwgdriver->remove(gdev);
5053 qeth_core_free_discipline(card);
5056 debug_unregister(card->debug);
5057 write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
5058 list_del(&card->list);
5059 write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
5060 qeth_core_free_card(card);
5061 dev_set_drvdata(&gdev->dev, NULL);
5062 put_device(&gdev->dev);
5063 return;
5066 static int qeth_core_set_online(struct ccwgroup_device *gdev)
5068 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5069 int rc = 0;
5070 int def_discipline;
5072 if (!card->discipline.ccwgdriver) {
5073 if (card->info.type == QETH_CARD_TYPE_IQD)
5074 def_discipline = QETH_DISCIPLINE_LAYER3;
5075 else
5076 def_discipline = QETH_DISCIPLINE_LAYER2;
5077 rc = qeth_core_load_discipline(card, def_discipline);
5078 if (rc)
5079 goto err;
5080 rc = card->discipline.ccwgdriver->probe(card->gdev);
5081 if (rc)
5082 goto err;
5084 rc = card->discipline.ccwgdriver->set_online(gdev);
5085 err:
5086 return rc;
5089 static int qeth_core_set_offline(struct ccwgroup_device *gdev)
5091 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5092 return card->discipline.ccwgdriver->set_offline(gdev);
5095 static void qeth_core_shutdown(struct ccwgroup_device *gdev)
5097 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5098 if (card->discipline.ccwgdriver &&
5099 card->discipline.ccwgdriver->shutdown)
5100 card->discipline.ccwgdriver->shutdown(gdev);
5103 static int qeth_core_prepare(struct ccwgroup_device *gdev)
5105 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5106 if (card->discipline.ccwgdriver &&
5107 card->discipline.ccwgdriver->prepare)
5108 return card->discipline.ccwgdriver->prepare(gdev);
5109 return 0;
5112 static void qeth_core_complete(struct ccwgroup_device *gdev)
5114 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5115 if (card->discipline.ccwgdriver &&
5116 card->discipline.ccwgdriver->complete)
5117 card->discipline.ccwgdriver->complete(gdev);
5120 static int qeth_core_freeze(struct ccwgroup_device *gdev)
5122 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5123 if (card->discipline.ccwgdriver &&
5124 card->discipline.ccwgdriver->freeze)
5125 return card->discipline.ccwgdriver->freeze(gdev);
5126 return 0;
5129 static int qeth_core_thaw(struct ccwgroup_device *gdev)
5131 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5132 if (card->discipline.ccwgdriver &&
5133 card->discipline.ccwgdriver->thaw)
5134 return card->discipline.ccwgdriver->thaw(gdev);
5135 return 0;
5138 static int qeth_core_restore(struct ccwgroup_device *gdev)
5140 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
5141 if (card->discipline.ccwgdriver &&
5142 card->discipline.ccwgdriver->restore)
5143 return card->discipline.ccwgdriver->restore(gdev);
5144 return 0;
5147 static struct ccwgroup_driver qeth_core_ccwgroup_driver = {
5148 .driver = {
5149 .owner = THIS_MODULE,
5150 .name = "qeth",
5152 .driver_id = 0xD8C5E3C8,
5153 .probe = qeth_core_probe_device,
5154 .remove = qeth_core_remove_device,
5155 .set_online = qeth_core_set_online,
5156 .set_offline = qeth_core_set_offline,
5157 .shutdown = qeth_core_shutdown,
5158 .prepare = qeth_core_prepare,
5159 .complete = qeth_core_complete,
5160 .freeze = qeth_core_freeze,
5161 .thaw = qeth_core_thaw,
5162 .restore = qeth_core_restore,
5165 static ssize_t
5166 qeth_core_driver_group_store(struct device_driver *ddrv, const char *buf,
5167 size_t count)
5169 int err;
5170 err = qeth_core_driver_group(buf, qeth_core_root_dev,
5171 qeth_core_ccwgroup_driver.driver_id);
5172 if (err)
5173 return err;
5174 else
5175 return count;
5178 static DRIVER_ATTR(group, 0200, NULL, qeth_core_driver_group_store);
5180 static struct {
5181 const char str[ETH_GSTRING_LEN];
5182 } qeth_ethtool_stats_keys[] = {
5183 /* 0 */{"rx skbs"},
5184 {"rx buffers"},
5185 {"tx skbs"},
5186 {"tx buffers"},
5187 {"tx skbs no packing"},
5188 {"tx buffers no packing"},
5189 {"tx skbs packing"},
5190 {"tx buffers packing"},
5191 {"tx sg skbs"},
5192 {"tx sg frags"},
5193 /* 10 */{"rx sg skbs"},
5194 {"rx sg frags"},
5195 {"rx sg page allocs"},
5196 {"tx large kbytes"},
5197 {"tx large count"},
5198 {"tx pk state ch n->p"},
5199 {"tx pk state ch p->n"},
5200 {"tx pk watermark low"},
5201 {"tx pk watermark high"},
5202 {"queue 0 buffer usage"},
5203 /* 20 */{"queue 1 buffer usage"},
5204 {"queue 2 buffer usage"},
5205 {"queue 3 buffer usage"},
5206 {"rx poll time"},
5207 {"rx poll count"},
5208 {"rx do_QDIO time"},
5209 {"rx do_QDIO count"},
5210 {"tx handler time"},
5211 {"tx handler count"},
5212 {"tx time"},
5213 /* 30 */{"tx count"},
5214 {"tx do_QDIO time"},
5215 {"tx do_QDIO count"},
5216 {"tx csum"},
5217 {"tx lin"},
5218 {"cq handler count"},
5219 {"cq handler time"}
5222 int qeth_core_get_sset_count(struct net_device *dev, int stringset)
5224 switch (stringset) {
5225 case ETH_SS_STATS:
5226 return (sizeof(qeth_ethtool_stats_keys) / ETH_GSTRING_LEN);
5227 default:
5228 return -EINVAL;
5231 EXPORT_SYMBOL_GPL(qeth_core_get_sset_count);
5233 void qeth_core_get_ethtool_stats(struct net_device *dev,
5234 struct ethtool_stats *stats, u64 *data)
5236 struct qeth_card *card = dev->ml_priv;
5237 data[0] = card->stats.rx_packets -
5238 card->perf_stats.initial_rx_packets;
5239 data[1] = card->perf_stats.bufs_rec;
5240 data[2] = card->stats.tx_packets -
5241 card->perf_stats.initial_tx_packets;
5242 data[3] = card->perf_stats.bufs_sent;
5243 data[4] = card->stats.tx_packets - card->perf_stats.initial_tx_packets
5244 - card->perf_stats.skbs_sent_pack;
5245 data[5] = card->perf_stats.bufs_sent - card->perf_stats.bufs_sent_pack;
5246 data[6] = card->perf_stats.skbs_sent_pack;
5247 data[7] = card->perf_stats.bufs_sent_pack;
5248 data[8] = card->perf_stats.sg_skbs_sent;
5249 data[9] = card->perf_stats.sg_frags_sent;
5250 data[10] = card->perf_stats.sg_skbs_rx;
5251 data[11] = card->perf_stats.sg_frags_rx;
5252 data[12] = card->perf_stats.sg_alloc_page_rx;
5253 data[13] = (card->perf_stats.large_send_bytes >> 10);
5254 data[14] = card->perf_stats.large_send_cnt;
5255 data[15] = card->perf_stats.sc_dp_p;
5256 data[16] = card->perf_stats.sc_p_dp;
5257 data[17] = QETH_LOW_WATERMARK_PACK;
5258 data[18] = QETH_HIGH_WATERMARK_PACK;
5259 data[19] = atomic_read(&card->qdio.out_qs[0]->used_buffers);
5260 data[20] = (card->qdio.no_out_queues > 1) ?
5261 atomic_read(&card->qdio.out_qs[1]->used_buffers) : 0;
5262 data[21] = (card->qdio.no_out_queues > 2) ?
5263 atomic_read(&card->qdio.out_qs[2]->used_buffers) : 0;
5264 data[22] = (card->qdio.no_out_queues > 3) ?
5265 atomic_read(&card->qdio.out_qs[3]->used_buffers) : 0;
5266 data[23] = card->perf_stats.inbound_time;
5267 data[24] = card->perf_stats.inbound_cnt;
5268 data[25] = card->perf_stats.inbound_do_qdio_time;
5269 data[26] = card->perf_stats.inbound_do_qdio_cnt;
5270 data[27] = card->perf_stats.outbound_handler_time;
5271 data[28] = card->perf_stats.outbound_handler_cnt;
5272 data[29] = card->perf_stats.outbound_time;
5273 data[30] = card->perf_stats.outbound_cnt;
5274 data[31] = card->perf_stats.outbound_do_qdio_time;
5275 data[32] = card->perf_stats.outbound_do_qdio_cnt;
5276 data[33] = card->perf_stats.tx_csum;
5277 data[34] = card->perf_stats.tx_lin;
5278 data[35] = card->perf_stats.cq_cnt;
5279 data[36] = card->perf_stats.cq_time;
5281 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats);
5283 void qeth_core_get_strings(struct net_device *dev, u32 stringset, u8 *data)
5285 switch (stringset) {
5286 case ETH_SS_STATS:
5287 memcpy(data, &qeth_ethtool_stats_keys,
5288 sizeof(qeth_ethtool_stats_keys));
5289 break;
5290 default:
5291 WARN_ON(1);
5292 break;
5295 EXPORT_SYMBOL_GPL(qeth_core_get_strings);
5297 void qeth_core_get_drvinfo(struct net_device *dev,
5298 struct ethtool_drvinfo *info)
5300 struct qeth_card *card = dev->ml_priv;
5301 if (card->options.layer2)
5302 strcpy(info->driver, "qeth_l2");
5303 else
5304 strcpy(info->driver, "qeth_l3");
5306 strcpy(info->version, "1.0");
5307 strcpy(info->fw_version, card->info.mcl_level);
5308 sprintf(info->bus_info, "%s/%s/%s",
5309 CARD_RDEV_ID(card),
5310 CARD_WDEV_ID(card),
5311 CARD_DDEV_ID(card));
5313 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo);
5315 int qeth_core_ethtool_get_settings(struct net_device *netdev,
5316 struct ethtool_cmd *ecmd)
5318 struct qeth_card *card = netdev->ml_priv;
5319 enum qeth_link_types link_type;
5321 if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan))
5322 link_type = QETH_LINK_TYPE_10GBIT_ETH;
5323 else
5324 link_type = card->info.link_type;
5326 ecmd->transceiver = XCVR_INTERNAL;
5327 ecmd->supported = SUPPORTED_Autoneg;
5328 ecmd->advertising = ADVERTISED_Autoneg;
5329 ecmd->duplex = DUPLEX_FULL;
5330 ecmd->autoneg = AUTONEG_ENABLE;
5332 switch (link_type) {
5333 case QETH_LINK_TYPE_FAST_ETH:
5334 case QETH_LINK_TYPE_LANE_ETH100:
5335 ecmd->supported |= SUPPORTED_10baseT_Half |
5336 SUPPORTED_10baseT_Full |
5337 SUPPORTED_100baseT_Half |
5338 SUPPORTED_100baseT_Full |
5339 SUPPORTED_TP;
5340 ecmd->advertising |= ADVERTISED_10baseT_Half |
5341 ADVERTISED_10baseT_Full |
5342 ADVERTISED_100baseT_Half |
5343 ADVERTISED_100baseT_Full |
5344 ADVERTISED_TP;
5345 ecmd->speed = SPEED_100;
5346 ecmd->port = PORT_TP;
5347 break;
5349 case QETH_LINK_TYPE_GBIT_ETH:
5350 case QETH_LINK_TYPE_LANE_ETH1000:
5351 ecmd->supported |= SUPPORTED_10baseT_Half |
5352 SUPPORTED_10baseT_Full |
5353 SUPPORTED_100baseT_Half |
5354 SUPPORTED_100baseT_Full |
5355 SUPPORTED_1000baseT_Half |
5356 SUPPORTED_1000baseT_Full |
5357 SUPPORTED_FIBRE;
5358 ecmd->advertising |= ADVERTISED_10baseT_Half |
5359 ADVERTISED_10baseT_Full |
5360 ADVERTISED_100baseT_Half |
5361 ADVERTISED_100baseT_Full |
5362 ADVERTISED_1000baseT_Half |
5363 ADVERTISED_1000baseT_Full |
5364 ADVERTISED_FIBRE;
5365 ecmd->speed = SPEED_1000;
5366 ecmd->port = PORT_FIBRE;
5367 break;
5369 case QETH_LINK_TYPE_10GBIT_ETH:
5370 ecmd->supported |= SUPPORTED_10baseT_Half |
5371 SUPPORTED_10baseT_Full |
5372 SUPPORTED_100baseT_Half |
5373 SUPPORTED_100baseT_Full |
5374 SUPPORTED_1000baseT_Half |
5375 SUPPORTED_1000baseT_Full |
5376 SUPPORTED_10000baseT_Full |
5377 SUPPORTED_FIBRE;
5378 ecmd->advertising |= ADVERTISED_10baseT_Half |
5379 ADVERTISED_10baseT_Full |
5380 ADVERTISED_100baseT_Half |
5381 ADVERTISED_100baseT_Full |
5382 ADVERTISED_1000baseT_Half |
5383 ADVERTISED_1000baseT_Full |
5384 ADVERTISED_10000baseT_Full |
5385 ADVERTISED_FIBRE;
5386 ecmd->speed = SPEED_10000;
5387 ecmd->port = PORT_FIBRE;
5388 break;
5390 default:
5391 ecmd->supported |= SUPPORTED_10baseT_Half |
5392 SUPPORTED_10baseT_Full |
5393 SUPPORTED_TP;
5394 ecmd->advertising |= ADVERTISED_10baseT_Half |
5395 ADVERTISED_10baseT_Full |
5396 ADVERTISED_TP;
5397 ecmd->speed = SPEED_10;
5398 ecmd->port = PORT_TP;
5401 return 0;
5403 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings);
5405 static int __init qeth_core_init(void)
5407 int rc;
5409 pr_info("loading core functions\n");
5410 INIT_LIST_HEAD(&qeth_core_card_list.list);
5411 rwlock_init(&qeth_core_card_list.rwlock);
5413 rc = qeth_register_dbf_views();
5414 if (rc)
5415 goto out_err;
5416 rc = ccw_driver_register(&qeth_ccw_driver);
5417 if (rc)
5418 goto ccw_err;
5419 rc = ccwgroup_driver_register(&qeth_core_ccwgroup_driver);
5420 if (rc)
5421 goto ccwgroup_err;
5422 rc = driver_create_file(&qeth_core_ccwgroup_driver.driver,
5423 &driver_attr_group);
5424 if (rc)
5425 goto driver_err;
5426 qeth_core_root_dev = root_device_register("qeth");
5427 rc = IS_ERR(qeth_core_root_dev) ? PTR_ERR(qeth_core_root_dev) : 0;
5428 if (rc)
5429 goto register_err;
5431 qeth_core_header_cache = kmem_cache_create("qeth_hdr",
5432 sizeof(struct qeth_hdr) + ETH_HLEN, 64, 0, NULL);
5433 if (!qeth_core_header_cache) {
5434 rc = -ENOMEM;
5435 goto slab_err;
5438 qeth_qdio_outbuf_cache = kmem_cache_create("qeth_buf",
5439 sizeof(struct qeth_qdio_out_buffer), 0, 0, NULL);
5440 if (!qeth_qdio_outbuf_cache) {
5441 rc = -ENOMEM;
5442 goto cqslab_err;
5445 return 0;
5446 cqslab_err:
5447 kmem_cache_destroy(qeth_core_header_cache);
5448 slab_err:
5449 root_device_unregister(qeth_core_root_dev);
5450 register_err:
5451 driver_remove_file(&qeth_core_ccwgroup_driver.driver,
5452 &driver_attr_group);
5453 driver_err:
5454 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
5455 ccwgroup_err:
5456 ccw_driver_unregister(&qeth_ccw_driver);
5457 ccw_err:
5458 QETH_DBF_MESSAGE(2, "Initialization failed with code %d\n", rc);
5459 qeth_unregister_dbf_views();
5460 out_err:
5461 pr_err("Initializing the qeth device driver failed\n");
5462 return rc;
5465 static void __exit qeth_core_exit(void)
5467 root_device_unregister(qeth_core_root_dev);
5468 driver_remove_file(&qeth_core_ccwgroup_driver.driver,
5469 &driver_attr_group);
5470 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
5471 ccw_driver_unregister(&qeth_ccw_driver);
5472 kmem_cache_destroy(qeth_qdio_outbuf_cache);
5473 kmem_cache_destroy(qeth_core_header_cache);
5474 qeth_unregister_dbf_views();
5475 pr_info("core functions removed\n");
5478 module_init(qeth_core_init);
5479 module_exit(qeth_core_exit);
5480 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
5481 MODULE_DESCRIPTION("qeth core functions");
5482 MODULE_LICENSE("GPL");