blob: 9d094f9103602b355f5e21fcec6b502fd8db216e [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001/*
2 * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.
3 * All rights reserved.
4 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include <linux/err.h>
36#include <linux/vmalloc.h>
37
38#include "qib.h"
39
40#define BITS_PER_PAGE (PAGE_SIZE*BITS_PER_BYTE)
41#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1)
42
43static inline unsigned mk_qpn(struct qib_qpn_table *qpt,
44 struct qpn_map *map, unsigned off)
45{
46 return (map - qpt->map) * BITS_PER_PAGE + off;
47}
48
49static inline unsigned find_next_offset(struct qib_qpn_table *qpt,
50 struct qpn_map *map, unsigned off,
Mike Marciniszyn2528ea62011-01-10 17:42:21 -080051 unsigned n)
Ralph Campbellf9315512010-05-23 21:44:54 -070052{
53 if (qpt->mask) {
54 off++;
Mike Marciniszyn2528ea62011-01-10 17:42:21 -080055 if (((off & qpt->mask) >> 1) >= n)
56 off = (off | qpt->mask) + 2;
Ralph Campbellf9315512010-05-23 21:44:54 -070057 } else
58 off = find_next_zero_bit(map->page, BITS_PER_PAGE, off);
59 return off;
60}
61
62/*
63 * Convert the AETH credit code into the number of credits.
64 */
65static u32 credit_table[31] = {
66 0, /* 0 */
67 1, /* 1 */
68 2, /* 2 */
69 3, /* 3 */
70 4, /* 4 */
71 6, /* 5 */
72 8, /* 6 */
73 12, /* 7 */
74 16, /* 8 */
75 24, /* 9 */
76 32, /* A */
77 48, /* B */
78 64, /* C */
79 96, /* D */
80 128, /* E */
81 192, /* F */
82 256, /* 10 */
83 384, /* 11 */
84 512, /* 12 */
85 768, /* 13 */
86 1024, /* 14 */
87 1536, /* 15 */
88 2048, /* 16 */
89 3072, /* 17 */
90 4096, /* 18 */
91 6144, /* 19 */
92 8192, /* 1A */
93 12288, /* 1B */
94 16384, /* 1C */
95 24576, /* 1D */
96 32768 /* 1E */
97};
98
99static void get_map_page(struct qib_qpn_table *qpt, struct qpn_map *map)
100{
101 unsigned long page = get_zeroed_page(GFP_KERNEL);
102
103 /*
104 * Free the page if someone raced with us installing it.
105 */
106
107 spin_lock(&qpt->lock);
108 if (map->page)
109 free_page(page);
110 else
111 map->page = (void *)page;
112 spin_unlock(&qpt->lock);
113}
114
115/*
116 * Allocate the next available QPN or
117 * zero/one for QP type IB_QPT_SMI/IB_QPT_GSI.
118 */
119static int alloc_qpn(struct qib_devdata *dd, struct qib_qpn_table *qpt,
120 enum ib_qp_type type, u8 port)
121{
122 u32 i, offset, max_scan, qpn;
123 struct qpn_map *map;
124 u32 ret;
Ralph Campbellf9315512010-05-23 21:44:54 -0700125
126 if (type == IB_QPT_SMI || type == IB_QPT_GSI) {
127 unsigned n;
128
129 ret = type == IB_QPT_GSI;
130 n = 1 << (ret + 2 * (port - 1));
131 spin_lock(&qpt->lock);
132 if (qpt->flags & n)
133 ret = -EINVAL;
134 else
135 qpt->flags |= n;
136 spin_unlock(&qpt->lock);
137 goto bail;
138 }
139
Mike Marciniszyn7c3edd32011-01-10 17:42:22 -0800140 qpn = qpt->last + 2;
Ralph Campbellf9315512010-05-23 21:44:54 -0700141 if (qpn >= QPN_MAX)
142 qpn = 2;
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800143 if (qpt->mask && ((qpn & qpt->mask) >> 1) >= dd->n_krcv_queues)
144 qpn = (qpn | qpt->mask) + 2;
Ralph Campbellf9315512010-05-23 21:44:54 -0700145 offset = qpn & BITS_PER_PAGE_MASK;
146 map = &qpt->map[qpn / BITS_PER_PAGE];
147 max_scan = qpt->nmaps - !offset;
148 for (i = 0;;) {
149 if (unlikely(!map->page)) {
150 get_map_page(qpt, map);
151 if (unlikely(!map->page))
152 break;
153 }
154 do {
155 if (!test_and_set_bit(offset, map->page)) {
156 qpt->last = qpn;
157 ret = qpn;
158 goto bail;
159 }
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800160 offset = find_next_offset(qpt, map, offset,
161 dd->n_krcv_queues);
Ralph Campbellf9315512010-05-23 21:44:54 -0700162 qpn = mk_qpn(qpt, map, offset);
163 /*
164 * This test differs from alloc_pidmap().
165 * If find_next_offset() does find a zero
166 * bit, we don't need to check for QPN
167 * wrapping around past our starting QPN.
168 * We just need to be sure we don't loop
169 * forever.
170 */
171 } while (offset < BITS_PER_PAGE && qpn < QPN_MAX);
172 /*
173 * In order to keep the number of pages allocated to a
174 * minimum, we scan the all existing pages before increasing
175 * the size of the bitmap table.
176 */
177 if (++i > max_scan) {
178 if (qpt->nmaps == QPNMAP_ENTRIES)
179 break;
180 map = &qpt->map[qpt->nmaps++];
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800181 offset = 0;
Ralph Campbellf9315512010-05-23 21:44:54 -0700182 } else if (map < &qpt->map[qpt->nmaps]) {
183 ++map;
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800184 offset = 0;
Ralph Campbellf9315512010-05-23 21:44:54 -0700185 } else {
186 map = &qpt->map[0];
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800187 offset = 2;
Ralph Campbellf9315512010-05-23 21:44:54 -0700188 }
189 qpn = mk_qpn(qpt, map, offset);
190 }
191
192 ret = -ENOMEM;
193
194bail:
195 return ret;
196}
197
198static void free_qpn(struct qib_qpn_table *qpt, u32 qpn)
199{
200 struct qpn_map *map;
201
202 map = qpt->map + qpn / BITS_PER_PAGE;
203 if (map->page)
204 clear_bit(qpn & BITS_PER_PAGE_MASK, map->page);
205}
206
207/*
208 * Put the QP into the hash table.
209 * The hash table holds a reference to the QP.
210 */
211static void insert_qp(struct qib_ibdev *dev, struct qib_qp *qp)
212{
213 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
214 unsigned n = qp->ibqp.qp_num % dev->qp_table_size;
215 unsigned long flags;
216
217 spin_lock_irqsave(&dev->qpt_lock, flags);
218
219 if (qp->ibqp.qp_num == 0)
220 ibp->qp0 = qp;
221 else if (qp->ibqp.qp_num == 1)
222 ibp->qp1 = qp;
223 else {
224 qp->next = dev->qp_table[n];
225 dev->qp_table[n] = qp;
226 }
227 atomic_inc(&qp->refcount);
228
229 spin_unlock_irqrestore(&dev->qpt_lock, flags);
230}
231
232/*
233 * Remove the QP from the table so it can't be found asynchronously by
234 * the receive interrupt routine.
235 */
236static void remove_qp(struct qib_ibdev *dev, struct qib_qp *qp)
237{
238 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
239 struct qib_qp *q, **qpp;
240 unsigned long flags;
241
242 qpp = &dev->qp_table[qp->ibqp.qp_num % dev->qp_table_size];
243
244 spin_lock_irqsave(&dev->qpt_lock, flags);
245
246 if (ibp->qp0 == qp) {
247 ibp->qp0 = NULL;
248 atomic_dec(&qp->refcount);
249 } else if (ibp->qp1 == qp) {
250 ibp->qp1 = NULL;
251 atomic_dec(&qp->refcount);
252 } else
253 for (; (q = *qpp) != NULL; qpp = &q->next)
254 if (q == qp) {
255 *qpp = qp->next;
256 qp->next = NULL;
257 atomic_dec(&qp->refcount);
258 break;
259 }
260
261 spin_unlock_irqrestore(&dev->qpt_lock, flags);
262}
263
264/**
265 * qib_free_all_qps - check for QPs still in use
266 * @qpt: the QP table to empty
267 *
268 * There should not be any QPs still in use.
269 * Free memory for table.
270 */
271unsigned qib_free_all_qps(struct qib_devdata *dd)
272{
273 struct qib_ibdev *dev = &dd->verbs_dev;
274 unsigned long flags;
275 struct qib_qp *qp;
276 unsigned n, qp_inuse = 0;
277
278 for (n = 0; n < dd->num_pports; n++) {
279 struct qib_ibport *ibp = &dd->pport[n].ibport_data;
280
281 if (!qib_mcast_tree_empty(ibp))
282 qp_inuse++;
283 if (ibp->qp0)
284 qp_inuse++;
285 if (ibp->qp1)
286 qp_inuse++;
287 }
288
289 spin_lock_irqsave(&dev->qpt_lock, flags);
290 for (n = 0; n < dev->qp_table_size; n++) {
291 qp = dev->qp_table[n];
292 dev->qp_table[n] = NULL;
293
294 for (; qp; qp = qp->next)
295 qp_inuse++;
296 }
297 spin_unlock_irqrestore(&dev->qpt_lock, flags);
298
299 return qp_inuse;
300}
301
302/**
303 * qib_lookup_qpn - return the QP with the given QPN
304 * @qpt: the QP table
305 * @qpn: the QP number to look up
306 *
307 * The caller is responsible for decrementing the QP reference count
308 * when done.
309 */
310struct qib_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn)
311{
312 struct qib_ibdev *dev = &ppd_from_ibp(ibp)->dd->verbs_dev;
313 unsigned long flags;
314 struct qib_qp *qp;
315
316 spin_lock_irqsave(&dev->qpt_lock, flags);
317
318 if (qpn == 0)
319 qp = ibp->qp0;
320 else if (qpn == 1)
321 qp = ibp->qp1;
322 else
323 for (qp = dev->qp_table[qpn % dev->qp_table_size]; qp;
324 qp = qp->next)
325 if (qp->ibqp.qp_num == qpn)
326 break;
327 if (qp)
328 atomic_inc(&qp->refcount);
329
330 spin_unlock_irqrestore(&dev->qpt_lock, flags);
331 return qp;
332}
333
334/**
335 * qib_reset_qp - initialize the QP state to the reset state
336 * @qp: the QP to reset
337 * @type: the QP type
338 */
339static void qib_reset_qp(struct qib_qp *qp, enum ib_qp_type type)
340{
341 qp->remote_qpn = 0;
342 qp->qkey = 0;
343 qp->qp_access_flags = 0;
344 atomic_set(&qp->s_dma_busy, 0);
345 qp->s_flags &= QIB_S_SIGNAL_REQ_WR;
346 qp->s_hdrwords = 0;
347 qp->s_wqe = NULL;
348 qp->s_draining = 0;
349 qp->s_next_psn = 0;
350 qp->s_last_psn = 0;
351 qp->s_sending_psn = 0;
352 qp->s_sending_hpsn = 0;
353 qp->s_psn = 0;
354 qp->r_psn = 0;
355 qp->r_msn = 0;
356 if (type == IB_QPT_RC) {
357 qp->s_state = IB_OPCODE_RC_SEND_LAST;
358 qp->r_state = IB_OPCODE_RC_SEND_LAST;
359 } else {
360 qp->s_state = IB_OPCODE_UC_SEND_LAST;
361 qp->r_state = IB_OPCODE_UC_SEND_LAST;
362 }
363 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
364 qp->r_nak_state = 0;
365 qp->r_aflags = 0;
366 qp->r_flags = 0;
367 qp->s_head = 0;
368 qp->s_tail = 0;
369 qp->s_cur = 0;
370 qp->s_acked = 0;
371 qp->s_last = 0;
372 qp->s_ssn = 1;
373 qp->s_lsn = 0;
374 qp->s_mig_state = IB_MIG_MIGRATED;
375 memset(qp->s_ack_queue, 0, sizeof(qp->s_ack_queue));
376 qp->r_head_ack_queue = 0;
377 qp->s_tail_ack_queue = 0;
378 qp->s_num_rd_atomic = 0;
379 if (qp->r_rq.wq) {
380 qp->r_rq.wq->head = 0;
381 qp->r_rq.wq->tail = 0;
382 }
383 qp->r_sge.num_sge = 0;
384}
385
386static void clear_mr_refs(struct qib_qp *qp, int clr_sends)
387{
388 unsigned n;
389
390 if (test_and_clear_bit(QIB_R_REWIND_SGE, &qp->r_aflags))
391 while (qp->s_rdma_read_sge.num_sge) {
392 atomic_dec(&qp->s_rdma_read_sge.sge.mr->refcount);
393 if (--qp->s_rdma_read_sge.num_sge)
394 qp->s_rdma_read_sge.sge =
395 *qp->s_rdma_read_sge.sg_list++;
396 }
397
398 while (qp->r_sge.num_sge) {
399 atomic_dec(&qp->r_sge.sge.mr->refcount);
400 if (--qp->r_sge.num_sge)
401 qp->r_sge.sge = *qp->r_sge.sg_list++;
402 }
403
404 if (clr_sends) {
405 while (qp->s_last != qp->s_head) {
406 struct qib_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
407 unsigned i;
408
409 for (i = 0; i < wqe->wr.num_sge; i++) {
410 struct qib_sge *sge = &wqe->sg_list[i];
411
412 atomic_dec(&sge->mr->refcount);
413 }
414 if (qp->ibqp.qp_type == IB_QPT_UD ||
415 qp->ibqp.qp_type == IB_QPT_SMI ||
416 qp->ibqp.qp_type == IB_QPT_GSI)
417 atomic_dec(&to_iah(wqe->wr.wr.ud.ah)->refcount);
418 if (++qp->s_last >= qp->s_size)
419 qp->s_last = 0;
420 }
421 if (qp->s_rdma_mr) {
422 atomic_dec(&qp->s_rdma_mr->refcount);
423 qp->s_rdma_mr = NULL;
424 }
425 }
426
427 if (qp->ibqp.qp_type != IB_QPT_RC)
428 return;
429
430 for (n = 0; n < ARRAY_SIZE(qp->s_ack_queue); n++) {
431 struct qib_ack_entry *e = &qp->s_ack_queue[n];
432
433 if (e->opcode == IB_OPCODE_RC_RDMA_READ_REQUEST &&
434 e->rdma_sge.mr) {
435 atomic_dec(&e->rdma_sge.mr->refcount);
436 e->rdma_sge.mr = NULL;
437 }
438 }
439}
440
441/**
442 * qib_error_qp - put a QP into the error state
443 * @qp: the QP to put into the error state
444 * @err: the receive completion error to signal if a RWQE is active
445 *
446 * Flushes both send and receive work queues.
447 * Returns true if last WQE event should be generated.
Ralph Campbella5210c12010-08-02 22:39:30 +0000448 * The QP r_lock and s_lock should be held and interrupts disabled.
Ralph Campbellf9315512010-05-23 21:44:54 -0700449 * If we are already in error state, just return.
450 */
451int qib_error_qp(struct qib_qp *qp, enum ib_wc_status err)
452{
453 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
454 struct ib_wc wc;
455 int ret = 0;
456
457 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET)
458 goto bail;
459
460 qp->state = IB_QPS_ERR;
461
462 if (qp->s_flags & (QIB_S_TIMER | QIB_S_WAIT_RNR)) {
463 qp->s_flags &= ~(QIB_S_TIMER | QIB_S_WAIT_RNR);
464 del_timer(&qp->s_timer);
465 }
Mike Marciniszyn16028f22011-01-10 17:42:20 -0800466
467 if (qp->s_flags & QIB_S_ANY_WAIT_SEND)
468 qp->s_flags &= ~QIB_S_ANY_WAIT_SEND;
469
Ralph Campbellf9315512010-05-23 21:44:54 -0700470 spin_lock(&dev->pending_lock);
471 if (!list_empty(&qp->iowait) && !(qp->s_flags & QIB_S_BUSY)) {
472 qp->s_flags &= ~QIB_S_ANY_WAIT_IO;
473 list_del_init(&qp->iowait);
474 }
475 spin_unlock(&dev->pending_lock);
476
477 if (!(qp->s_flags & QIB_S_BUSY)) {
478 qp->s_hdrwords = 0;
479 if (qp->s_rdma_mr) {
480 atomic_dec(&qp->s_rdma_mr->refcount);
481 qp->s_rdma_mr = NULL;
482 }
483 if (qp->s_tx) {
484 qib_put_txreq(qp->s_tx);
485 qp->s_tx = NULL;
486 }
487 }
488
489 /* Schedule the sending tasklet to drain the send work queue. */
490 if (qp->s_last != qp->s_head)
491 qib_schedule_send(qp);
492
493 clear_mr_refs(qp, 0);
494
495 memset(&wc, 0, sizeof(wc));
496 wc.qp = &qp->ibqp;
497 wc.opcode = IB_WC_RECV;
498
499 if (test_and_clear_bit(QIB_R_WRID_VALID, &qp->r_aflags)) {
500 wc.wr_id = qp->r_wr_id;
501 wc.status = err;
502 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
503 }
504 wc.status = IB_WC_WR_FLUSH_ERR;
505
506 if (qp->r_rq.wq) {
507 struct qib_rwq *wq;
508 u32 head;
509 u32 tail;
510
511 spin_lock(&qp->r_rq.lock);
512
513 /* sanity check pointers before trusting them */
514 wq = qp->r_rq.wq;
515 head = wq->head;
516 if (head >= qp->r_rq.size)
517 head = 0;
518 tail = wq->tail;
519 if (tail >= qp->r_rq.size)
520 tail = 0;
521 while (tail != head) {
522 wc.wr_id = get_rwqe_ptr(&qp->r_rq, tail)->wr_id;
523 if (++tail >= qp->r_rq.size)
524 tail = 0;
525 qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
526 }
527 wq->tail = tail;
528
529 spin_unlock(&qp->r_rq.lock);
530 } else if (qp->ibqp.event_handler)
531 ret = 1;
532
533bail:
534 return ret;
535}
536
537/**
538 * qib_modify_qp - modify the attributes of a queue pair
539 * @ibqp: the queue pair who's attributes we're modifying
540 * @attr: the new attributes
541 * @attr_mask: the mask of attributes to modify
542 * @udata: user data for libibverbs.so
543 *
544 * Returns 0 on success, otherwise returns an errno.
545 */
546int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
547 int attr_mask, struct ib_udata *udata)
548{
549 struct qib_ibdev *dev = to_idev(ibqp->device);
550 struct qib_qp *qp = to_iqp(ibqp);
551 enum ib_qp_state cur_state, new_state;
552 struct ib_event ev;
553 int lastwqe = 0;
554 int mig = 0;
555 int ret;
556 u32 pmtu = 0; /* for gcc warning only */
557
558 spin_lock_irq(&qp->r_lock);
559 spin_lock(&qp->s_lock);
560
561 cur_state = attr_mask & IB_QP_CUR_STATE ?
562 attr->cur_qp_state : qp->state;
563 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
564
565 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
566 attr_mask))
567 goto inval;
568
569 if (attr_mask & IB_QP_AV) {
570 if (attr->ah_attr.dlid >= QIB_MULTICAST_LID_BASE)
571 goto inval;
572 if (qib_check_ah(qp->ibqp.device, &attr->ah_attr))
573 goto inval;
574 }
575
576 if (attr_mask & IB_QP_ALT_PATH) {
577 if (attr->alt_ah_attr.dlid >= QIB_MULTICAST_LID_BASE)
578 goto inval;
579 if (qib_check_ah(qp->ibqp.device, &attr->alt_ah_attr))
580 goto inval;
581 if (attr->alt_pkey_index >= qib_get_npkeys(dd_from_dev(dev)))
582 goto inval;
583 }
584
585 if (attr_mask & IB_QP_PKEY_INDEX)
586 if (attr->pkey_index >= qib_get_npkeys(dd_from_dev(dev)))
587 goto inval;
588
589 if (attr_mask & IB_QP_MIN_RNR_TIMER)
590 if (attr->min_rnr_timer > 31)
591 goto inval;
592
593 if (attr_mask & IB_QP_PORT)
594 if (qp->ibqp.qp_type == IB_QPT_SMI ||
595 qp->ibqp.qp_type == IB_QPT_GSI ||
596 attr->port_num == 0 ||
597 attr->port_num > ibqp->device->phys_port_cnt)
598 goto inval;
599
600 if (attr_mask & IB_QP_DEST_QPN)
601 if (attr->dest_qp_num > QIB_QPN_MASK)
602 goto inval;
603
604 if (attr_mask & IB_QP_RETRY_CNT)
605 if (attr->retry_cnt > 7)
606 goto inval;
607
608 if (attr_mask & IB_QP_RNR_RETRY)
609 if (attr->rnr_retry > 7)
610 goto inval;
611
612 /*
613 * Don't allow invalid path_mtu values. OK to set greater
614 * than the active mtu (or even the max_cap, if we have tuned
615 * that to a small mtu. We'll set qp->path_mtu
616 * to the lesser of requested attribute mtu and active,
617 * for packetizing messages.
618 * Note that the QP port has to be set in INIT and MTU in RTR.
619 */
620 if (attr_mask & IB_QP_PATH_MTU) {
621 struct qib_devdata *dd = dd_from_dev(dev);
622 int mtu, pidx = qp->port_num - 1;
623
624 mtu = ib_mtu_enum_to_int(attr->path_mtu);
625 if (mtu == -1)
626 goto inval;
627 if (mtu > dd->pport[pidx].ibmtu) {
628 switch (dd->pport[pidx].ibmtu) {
629 case 4096:
630 pmtu = IB_MTU_4096;
631 break;
632 case 2048:
633 pmtu = IB_MTU_2048;
634 break;
635 case 1024:
636 pmtu = IB_MTU_1024;
637 break;
638 case 512:
639 pmtu = IB_MTU_512;
640 break;
641 case 256:
642 pmtu = IB_MTU_256;
643 break;
644 default:
645 pmtu = IB_MTU_2048;
646 }
647 } else
648 pmtu = attr->path_mtu;
649 }
650
651 if (attr_mask & IB_QP_PATH_MIG_STATE) {
652 if (attr->path_mig_state == IB_MIG_REARM) {
653 if (qp->s_mig_state == IB_MIG_ARMED)
654 goto inval;
655 if (new_state != IB_QPS_RTS)
656 goto inval;
657 } else if (attr->path_mig_state == IB_MIG_MIGRATED) {
658 if (qp->s_mig_state == IB_MIG_REARM)
659 goto inval;
660 if (new_state != IB_QPS_RTS && new_state != IB_QPS_SQD)
661 goto inval;
662 if (qp->s_mig_state == IB_MIG_ARMED)
663 mig = 1;
664 } else
665 goto inval;
666 }
667
668 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
669 if (attr->max_dest_rd_atomic > QIB_MAX_RDMA_ATOMIC)
670 goto inval;
671
672 switch (new_state) {
673 case IB_QPS_RESET:
674 if (qp->state != IB_QPS_RESET) {
675 qp->state = IB_QPS_RESET;
676 spin_lock(&dev->pending_lock);
677 if (!list_empty(&qp->iowait))
678 list_del_init(&qp->iowait);
679 spin_unlock(&dev->pending_lock);
680 qp->s_flags &= ~(QIB_S_TIMER | QIB_S_ANY_WAIT);
681 spin_unlock(&qp->s_lock);
682 spin_unlock_irq(&qp->r_lock);
683 /* Stop the sending work queue and retry timer */
684 cancel_work_sync(&qp->s_work);
685 del_timer_sync(&qp->s_timer);
686 wait_event(qp->wait_dma, !atomic_read(&qp->s_dma_busy));
687 if (qp->s_tx) {
688 qib_put_txreq(qp->s_tx);
689 qp->s_tx = NULL;
690 }
691 remove_qp(dev, qp);
692 wait_event(qp->wait, !atomic_read(&qp->refcount));
693 spin_lock_irq(&qp->r_lock);
694 spin_lock(&qp->s_lock);
695 clear_mr_refs(qp, 1);
696 qib_reset_qp(qp, ibqp->qp_type);
697 }
698 break;
699
700 case IB_QPS_RTR:
701 /* Allow event to retrigger if QP set to RTR more than once */
702 qp->r_flags &= ~QIB_R_COMM_EST;
703 qp->state = new_state;
704 break;
705
706 case IB_QPS_SQD:
707 qp->s_draining = qp->s_last != qp->s_cur;
708 qp->state = new_state;
709 break;
710
711 case IB_QPS_SQE:
712 if (qp->ibqp.qp_type == IB_QPT_RC)
713 goto inval;
714 qp->state = new_state;
715 break;
716
717 case IB_QPS_ERR:
718 lastwqe = qib_error_qp(qp, IB_WC_WR_FLUSH_ERR);
719 break;
720
721 default:
722 qp->state = new_state;
723 break;
724 }
725
726 if (attr_mask & IB_QP_PKEY_INDEX)
727 qp->s_pkey_index = attr->pkey_index;
728
729 if (attr_mask & IB_QP_PORT)
730 qp->port_num = attr->port_num;
731
732 if (attr_mask & IB_QP_DEST_QPN)
733 qp->remote_qpn = attr->dest_qp_num;
734
735 if (attr_mask & IB_QP_SQ_PSN) {
736 qp->s_next_psn = attr->sq_psn & QIB_PSN_MASK;
737 qp->s_psn = qp->s_next_psn;
738 qp->s_sending_psn = qp->s_next_psn;
739 qp->s_last_psn = qp->s_next_psn - 1;
740 qp->s_sending_hpsn = qp->s_last_psn;
741 }
742
743 if (attr_mask & IB_QP_RQ_PSN)
744 qp->r_psn = attr->rq_psn & QIB_PSN_MASK;
745
746 if (attr_mask & IB_QP_ACCESS_FLAGS)
747 qp->qp_access_flags = attr->qp_access_flags;
748
749 if (attr_mask & IB_QP_AV) {
750 qp->remote_ah_attr = attr->ah_attr;
751 qp->s_srate = attr->ah_attr.static_rate;
752 }
753
754 if (attr_mask & IB_QP_ALT_PATH) {
755 qp->alt_ah_attr = attr->alt_ah_attr;
756 qp->s_alt_pkey_index = attr->alt_pkey_index;
757 }
758
759 if (attr_mask & IB_QP_PATH_MIG_STATE) {
760 qp->s_mig_state = attr->path_mig_state;
761 if (mig) {
762 qp->remote_ah_attr = qp->alt_ah_attr;
763 qp->port_num = qp->alt_ah_attr.port_num;
764 qp->s_pkey_index = qp->s_alt_pkey_index;
765 }
766 }
767
Mike Marciniszyncc6ea132011-09-23 13:16:34 -0400768 if (attr_mask & IB_QP_PATH_MTU) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700769 qp->path_mtu = pmtu;
Mike Marciniszyncc6ea132011-09-23 13:16:34 -0400770 qp->pmtu = ib_mtu_enum_to_int(pmtu);
771 }
Ralph Campbellf9315512010-05-23 21:44:54 -0700772
773 if (attr_mask & IB_QP_RETRY_CNT) {
774 qp->s_retry_cnt = attr->retry_cnt;
775 qp->s_retry = attr->retry_cnt;
776 }
777
778 if (attr_mask & IB_QP_RNR_RETRY) {
779 qp->s_rnr_retry_cnt = attr->rnr_retry;
780 qp->s_rnr_retry = attr->rnr_retry;
781 }
782
783 if (attr_mask & IB_QP_MIN_RNR_TIMER)
784 qp->r_min_rnr_timer = attr->min_rnr_timer;
785
786 if (attr_mask & IB_QP_TIMEOUT)
787 qp->timeout = attr->timeout;
788
789 if (attr_mask & IB_QP_QKEY)
790 qp->qkey = attr->qkey;
791
792 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
793 qp->r_max_rd_atomic = attr->max_dest_rd_atomic;
794
795 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
796 qp->s_max_rd_atomic = attr->max_rd_atomic;
797
798 spin_unlock(&qp->s_lock);
799 spin_unlock_irq(&qp->r_lock);
800
801 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT)
802 insert_qp(dev, qp);
803
804 if (lastwqe) {
805 ev.device = qp->ibqp.device;
806 ev.element.qp = &qp->ibqp;
807 ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
808 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
809 }
810 if (mig) {
811 ev.device = qp->ibqp.device;
812 ev.element.qp = &qp->ibqp;
813 ev.event = IB_EVENT_PATH_MIG;
814 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
815 }
816 ret = 0;
817 goto bail;
818
819inval:
820 spin_unlock(&qp->s_lock);
821 spin_unlock_irq(&qp->r_lock);
822 ret = -EINVAL;
823
824bail:
825 return ret;
826}
827
828int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
829 int attr_mask, struct ib_qp_init_attr *init_attr)
830{
831 struct qib_qp *qp = to_iqp(ibqp);
832
833 attr->qp_state = qp->state;
834 attr->cur_qp_state = attr->qp_state;
835 attr->path_mtu = qp->path_mtu;
836 attr->path_mig_state = qp->s_mig_state;
837 attr->qkey = qp->qkey;
838 attr->rq_psn = qp->r_psn & QIB_PSN_MASK;
839 attr->sq_psn = qp->s_next_psn & QIB_PSN_MASK;
840 attr->dest_qp_num = qp->remote_qpn;
841 attr->qp_access_flags = qp->qp_access_flags;
842 attr->cap.max_send_wr = qp->s_size - 1;
843 attr->cap.max_recv_wr = qp->ibqp.srq ? 0 : qp->r_rq.size - 1;
844 attr->cap.max_send_sge = qp->s_max_sge;
845 attr->cap.max_recv_sge = qp->r_rq.max_sge;
846 attr->cap.max_inline_data = 0;
847 attr->ah_attr = qp->remote_ah_attr;
848 attr->alt_ah_attr = qp->alt_ah_attr;
849 attr->pkey_index = qp->s_pkey_index;
850 attr->alt_pkey_index = qp->s_alt_pkey_index;
851 attr->en_sqd_async_notify = 0;
852 attr->sq_draining = qp->s_draining;
853 attr->max_rd_atomic = qp->s_max_rd_atomic;
854 attr->max_dest_rd_atomic = qp->r_max_rd_atomic;
855 attr->min_rnr_timer = qp->r_min_rnr_timer;
856 attr->port_num = qp->port_num;
857 attr->timeout = qp->timeout;
858 attr->retry_cnt = qp->s_retry_cnt;
859 attr->rnr_retry = qp->s_rnr_retry_cnt;
860 attr->alt_port_num = qp->alt_ah_attr.port_num;
861 attr->alt_timeout = qp->alt_timeout;
862
863 init_attr->event_handler = qp->ibqp.event_handler;
864 init_attr->qp_context = qp->ibqp.qp_context;
865 init_attr->send_cq = qp->ibqp.send_cq;
866 init_attr->recv_cq = qp->ibqp.recv_cq;
867 init_attr->srq = qp->ibqp.srq;
868 init_attr->cap = attr->cap;
869 if (qp->s_flags & QIB_S_SIGNAL_REQ_WR)
870 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR;
871 else
872 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR;
873 init_attr->qp_type = qp->ibqp.qp_type;
874 init_attr->port_num = qp->port_num;
875 return 0;
876}
877
878/**
879 * qib_compute_aeth - compute the AETH (syndrome + MSN)
880 * @qp: the queue pair to compute the AETH for
881 *
882 * Returns the AETH.
883 */
884__be32 qib_compute_aeth(struct qib_qp *qp)
885{
886 u32 aeth = qp->r_msn & QIB_MSN_MASK;
887
888 if (qp->ibqp.srq) {
889 /*
890 * Shared receive queues don't generate credits.
891 * Set the credit field to the invalid value.
892 */
893 aeth |= QIB_AETH_CREDIT_INVAL << QIB_AETH_CREDIT_SHIFT;
894 } else {
895 u32 min, max, x;
896 u32 credits;
897 struct qib_rwq *wq = qp->r_rq.wq;
898 u32 head;
899 u32 tail;
900
901 /* sanity check pointers before trusting them */
902 head = wq->head;
903 if (head >= qp->r_rq.size)
904 head = 0;
905 tail = wq->tail;
906 if (tail >= qp->r_rq.size)
907 tail = 0;
908 /*
909 * Compute the number of credits available (RWQEs).
910 * XXX Not holding the r_rq.lock here so there is a small
911 * chance that the pair of reads are not atomic.
912 */
913 credits = head - tail;
914 if ((int)credits < 0)
915 credits += qp->r_rq.size;
916 /*
917 * Binary search the credit table to find the code to
918 * use.
919 */
920 min = 0;
921 max = 31;
922 for (;;) {
923 x = (min + max) / 2;
924 if (credit_table[x] == credits)
925 break;
926 if (credit_table[x] > credits)
927 max = x;
928 else if (min == x)
929 break;
930 else
931 min = x;
932 }
933 aeth |= x << QIB_AETH_CREDIT_SHIFT;
934 }
935 return cpu_to_be32(aeth);
936}
937
938/**
939 * qib_create_qp - create a queue pair for a device
940 * @ibpd: the protection domain who's device we create the queue pair for
941 * @init_attr: the attributes of the queue pair
942 * @udata: user data for libibverbs.so
943 *
944 * Returns the queue pair on success, otherwise returns an errno.
945 *
946 * Called by the ib_create_qp() core verbs function.
947 */
948struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
949 struct ib_qp_init_attr *init_attr,
950 struct ib_udata *udata)
951{
952 struct qib_qp *qp;
953 int err;
954 struct qib_swqe *swq = NULL;
955 struct qib_ibdev *dev;
956 struct qib_devdata *dd;
957 size_t sz;
958 size_t sg_list_sz;
959 struct ib_qp *ret;
960
961 if (init_attr->cap.max_send_sge > ib_qib_max_sges ||
962 init_attr->cap.max_send_wr > ib_qib_max_qp_wrs) {
963 ret = ERR_PTR(-EINVAL);
964 goto bail;
965 }
966
967 /* Check receive queue parameters if no SRQ is specified. */
968 if (!init_attr->srq) {
969 if (init_attr->cap.max_recv_sge > ib_qib_max_sges ||
970 init_attr->cap.max_recv_wr > ib_qib_max_qp_wrs) {
971 ret = ERR_PTR(-EINVAL);
972 goto bail;
973 }
974 if (init_attr->cap.max_send_sge +
975 init_attr->cap.max_send_wr +
976 init_attr->cap.max_recv_sge +
977 init_attr->cap.max_recv_wr == 0) {
978 ret = ERR_PTR(-EINVAL);
979 goto bail;
980 }
981 }
982
983 switch (init_attr->qp_type) {
984 case IB_QPT_SMI:
985 case IB_QPT_GSI:
986 if (init_attr->port_num == 0 ||
987 init_attr->port_num > ibpd->device->phys_port_cnt) {
988 ret = ERR_PTR(-EINVAL);
989 goto bail;
990 }
991 case IB_QPT_UC:
992 case IB_QPT_RC:
993 case IB_QPT_UD:
994 sz = sizeof(struct qib_sge) *
995 init_attr->cap.max_send_sge +
996 sizeof(struct qib_swqe);
997 swq = vmalloc((init_attr->cap.max_send_wr + 1) * sz);
998 if (swq == NULL) {
999 ret = ERR_PTR(-ENOMEM);
1000 goto bail;
1001 }
1002 sz = sizeof(*qp);
1003 sg_list_sz = 0;
1004 if (init_attr->srq) {
1005 struct qib_srq *srq = to_isrq(init_attr->srq);
1006
1007 if (srq->rq.max_sge > 1)
1008 sg_list_sz = sizeof(*qp->r_sg_list) *
1009 (srq->rq.max_sge - 1);
1010 } else if (init_attr->cap.max_recv_sge > 1)
1011 sg_list_sz = sizeof(*qp->r_sg_list) *
1012 (init_attr->cap.max_recv_sge - 1);
1013 qp = kzalloc(sz + sg_list_sz, GFP_KERNEL);
1014 if (!qp) {
1015 ret = ERR_PTR(-ENOMEM);
1016 goto bail_swq;
1017 }
1018 if (init_attr->srq)
1019 sz = 0;
1020 else {
1021 qp->r_rq.size = init_attr->cap.max_recv_wr + 1;
1022 qp->r_rq.max_sge = init_attr->cap.max_recv_sge;
1023 sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) +
1024 sizeof(struct qib_rwqe);
1025 qp->r_rq.wq = vmalloc_user(sizeof(struct qib_rwq) +
1026 qp->r_rq.size * sz);
1027 if (!qp->r_rq.wq) {
1028 ret = ERR_PTR(-ENOMEM);
1029 goto bail_qp;
1030 }
1031 }
1032
1033 /*
1034 * ib_create_qp() will initialize qp->ibqp
1035 * except for qp->ibqp.qp_num.
1036 */
1037 spin_lock_init(&qp->r_lock);
1038 spin_lock_init(&qp->s_lock);
1039 spin_lock_init(&qp->r_rq.lock);
1040 atomic_set(&qp->refcount, 0);
1041 init_waitqueue_head(&qp->wait);
1042 init_waitqueue_head(&qp->wait_dma);
1043 init_timer(&qp->s_timer);
1044 qp->s_timer.data = (unsigned long)qp;
1045 INIT_WORK(&qp->s_work, qib_do_send);
1046 INIT_LIST_HEAD(&qp->iowait);
1047 INIT_LIST_HEAD(&qp->rspwait);
1048 qp->state = IB_QPS_RESET;
1049 qp->s_wq = swq;
1050 qp->s_size = init_attr->cap.max_send_wr + 1;
1051 qp->s_max_sge = init_attr->cap.max_send_sge;
1052 if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR)
1053 qp->s_flags = QIB_S_SIGNAL_REQ_WR;
1054 dev = to_idev(ibpd->device);
1055 dd = dd_from_dev(dev);
1056 err = alloc_qpn(dd, &dev->qpn_table, init_attr->qp_type,
1057 init_attr->port_num);
1058 if (err < 0) {
1059 ret = ERR_PTR(err);
1060 vfree(qp->r_rq.wq);
1061 goto bail_qp;
1062 }
1063 qp->ibqp.qp_num = err;
1064 qp->port_num = init_attr->port_num;
Ralph Campbellf9315512010-05-23 21:44:54 -07001065 qib_reset_qp(qp, init_attr->qp_type);
1066 break;
1067
1068 default:
1069 /* Don't support raw QPs */
1070 ret = ERR_PTR(-ENOSYS);
1071 goto bail;
1072 }
1073
1074 init_attr->cap.max_inline_data = 0;
1075
1076 /*
1077 * Return the address of the RWQ as the offset to mmap.
1078 * See qib_mmap() for details.
1079 */
1080 if (udata && udata->outlen >= sizeof(__u64)) {
1081 if (!qp->r_rq.wq) {
1082 __u64 offset = 0;
1083
1084 err = ib_copy_to_udata(udata, &offset,
1085 sizeof(offset));
1086 if (err) {
1087 ret = ERR_PTR(err);
1088 goto bail_ip;
1089 }
1090 } else {
1091 u32 s = sizeof(struct qib_rwq) + qp->r_rq.size * sz;
1092
1093 qp->ip = qib_create_mmap_info(dev, s,
1094 ibpd->uobject->context,
1095 qp->r_rq.wq);
1096 if (!qp->ip) {
1097 ret = ERR_PTR(-ENOMEM);
1098 goto bail_ip;
1099 }
1100
1101 err = ib_copy_to_udata(udata, &(qp->ip->offset),
1102 sizeof(qp->ip->offset));
1103 if (err) {
1104 ret = ERR_PTR(err);
1105 goto bail_ip;
1106 }
1107 }
1108 }
1109
1110 spin_lock(&dev->n_qps_lock);
1111 if (dev->n_qps_allocated == ib_qib_max_qps) {
1112 spin_unlock(&dev->n_qps_lock);
1113 ret = ERR_PTR(-ENOMEM);
1114 goto bail_ip;
1115 }
1116
1117 dev->n_qps_allocated++;
1118 spin_unlock(&dev->n_qps_lock);
1119
1120 if (qp->ip) {
1121 spin_lock_irq(&dev->pending_lock);
1122 list_add(&qp->ip->pending_mmaps, &dev->pending_mmaps);
1123 spin_unlock_irq(&dev->pending_lock);
1124 }
1125
1126 ret = &qp->ibqp;
1127 goto bail;
1128
1129bail_ip:
1130 if (qp->ip)
1131 kref_put(&qp->ip->ref, qib_release_mmap_info);
1132 else
1133 vfree(qp->r_rq.wq);
1134 free_qpn(&dev->qpn_table, qp->ibqp.qp_num);
1135bail_qp:
1136 kfree(qp);
1137bail_swq:
1138 vfree(swq);
1139bail:
1140 return ret;
1141}
1142
1143/**
1144 * qib_destroy_qp - destroy a queue pair
1145 * @ibqp: the queue pair to destroy
1146 *
1147 * Returns 0 on success.
1148 *
1149 * Note that this can be called while the QP is actively sending or
1150 * receiving!
1151 */
1152int qib_destroy_qp(struct ib_qp *ibqp)
1153{
1154 struct qib_qp *qp = to_iqp(ibqp);
1155 struct qib_ibdev *dev = to_idev(ibqp->device);
1156
1157 /* Make sure HW and driver activity is stopped. */
1158 spin_lock_irq(&qp->s_lock);
1159 if (qp->state != IB_QPS_RESET) {
1160 qp->state = IB_QPS_RESET;
1161 spin_lock(&dev->pending_lock);
1162 if (!list_empty(&qp->iowait))
1163 list_del_init(&qp->iowait);
1164 spin_unlock(&dev->pending_lock);
1165 qp->s_flags &= ~(QIB_S_TIMER | QIB_S_ANY_WAIT);
1166 spin_unlock_irq(&qp->s_lock);
1167 cancel_work_sync(&qp->s_work);
1168 del_timer_sync(&qp->s_timer);
1169 wait_event(qp->wait_dma, !atomic_read(&qp->s_dma_busy));
1170 if (qp->s_tx) {
1171 qib_put_txreq(qp->s_tx);
1172 qp->s_tx = NULL;
1173 }
1174 remove_qp(dev, qp);
1175 wait_event(qp->wait, !atomic_read(&qp->refcount));
1176 clear_mr_refs(qp, 1);
1177 } else
1178 spin_unlock_irq(&qp->s_lock);
1179
1180 /* all user's cleaned up, mark it available */
1181 free_qpn(&dev->qpn_table, qp->ibqp.qp_num);
1182 spin_lock(&dev->n_qps_lock);
1183 dev->n_qps_allocated--;
1184 spin_unlock(&dev->n_qps_lock);
1185
1186 if (qp->ip)
1187 kref_put(&qp->ip->ref, qib_release_mmap_info);
1188 else
1189 vfree(qp->r_rq.wq);
1190 vfree(qp->s_wq);
1191 kfree(qp);
1192 return 0;
1193}
1194
1195/**
1196 * qib_init_qpn_table - initialize the QP number table for a device
1197 * @qpt: the QPN table
1198 */
1199void qib_init_qpn_table(struct qib_devdata *dd, struct qib_qpn_table *qpt)
1200{
1201 spin_lock_init(&qpt->lock);
1202 qpt->last = 1; /* start with QPN 2 */
1203 qpt->nmaps = 1;
1204 qpt->mask = dd->qpn_mask;
1205}
1206
1207/**
1208 * qib_free_qpn_table - free the QP number table for a device
1209 * @qpt: the QPN table
1210 */
1211void qib_free_qpn_table(struct qib_qpn_table *qpt)
1212{
1213 int i;
1214
1215 for (i = 0; i < ARRAY_SIZE(qpt->map); i++)
1216 if (qpt->map[i].page)
1217 free_page((unsigned long) qpt->map[i].page);
1218}
1219
1220/**
1221 * qib_get_credit - flush the send work queue of a QP
1222 * @qp: the qp who's send work queue to flush
1223 * @aeth: the Acknowledge Extended Transport Header
1224 *
1225 * The QP s_lock should be held.
1226 */
1227void qib_get_credit(struct qib_qp *qp, u32 aeth)
1228{
1229 u32 credit = (aeth >> QIB_AETH_CREDIT_SHIFT) & QIB_AETH_CREDIT_MASK;
1230
1231 /*
1232 * If the credit is invalid, we can send
1233 * as many packets as we like. Otherwise, we have to
1234 * honor the credit field.
1235 */
1236 if (credit == QIB_AETH_CREDIT_INVAL) {
1237 if (!(qp->s_flags & QIB_S_UNLIMITED_CREDIT)) {
1238 qp->s_flags |= QIB_S_UNLIMITED_CREDIT;
1239 if (qp->s_flags & QIB_S_WAIT_SSN_CREDIT) {
1240 qp->s_flags &= ~QIB_S_WAIT_SSN_CREDIT;
1241 qib_schedule_send(qp);
1242 }
1243 }
1244 } else if (!(qp->s_flags & QIB_S_UNLIMITED_CREDIT)) {
1245 /* Compute new LSN (i.e., MSN + credit) */
1246 credit = (aeth + credit_table[credit]) & QIB_MSN_MASK;
1247 if (qib_cmp24(credit, qp->s_lsn) > 0) {
1248 qp->s_lsn = credit;
1249 if (qp->s_flags & QIB_S_WAIT_SSN_CREDIT) {
1250 qp->s_flags &= ~QIB_S_WAIT_SSN_CREDIT;
1251 qib_schedule_send(qp);
1252 }
1253 }
1254 }
1255}