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