2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/err.h>
34 #include <linux/vmalloc.h>
36 #include "ipath_verbs.h"
37 #include "ips_common.h"
39 #define BITS_PER_PAGE (PAGE_SIZE*BITS_PER_BYTE)
40 #define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1)
41 #define mk_qpn(qpt, map, off) (((map) - (qpt)->map) * BITS_PER_PAGE + \
43 #define find_next_offset(map, off) find_next_zero_bit((map)->page, \
46 #define TRANS_INVALID 0
47 #define TRANS_ANY2RST 1
48 #define TRANS_RST2INIT 2
49 #define TRANS_INIT2INIT 3
50 #define TRANS_INIT2RTR 4
51 #define TRANS_RTR2RTS 5
52 #define TRANS_RTS2RTS 6
53 #define TRANS_SQERR2RTS 7
54 #define TRANS_ANY2ERR 8
55 #define TRANS_RTS2SQD 9 /* XXX Wait for expected ACKs & signal event */
56 #define TRANS_SQD2SQD 10 /* error if not drained & parameter change */
57 #define TRANS_SQD2RTS 11 /* error if not drained */
60 * Convert the AETH credit code into the number of credits.
62 static u32 credit_table[31] = {
96 static u32 alloc_qpn(struct ipath_qp_table *qpt)
98 u32 i, offset, max_scan, qpn;
105 offset = qpn & BITS_PER_PAGE_MASK;
106 map = &qpt->map[qpn / BITS_PER_PAGE];
107 max_scan = qpt->nmaps - !offset;
109 if (unlikely(!map->page)) {
110 unsigned long page = get_zeroed_page(GFP_KERNEL);
114 * Free the page if someone raced with us
117 spin_lock_irqsave(&qpt->lock, flags);
121 map->page = (void *)page;
122 spin_unlock_irqrestore(&qpt->lock, flags);
123 if (unlikely(!map->page))
126 if (likely(atomic_read(&map->n_free))) {
128 if (!test_and_set_bit(offset, map->page)) {
129 atomic_dec(&map->n_free);
134 offset = find_next_offset(map, offset);
135 qpn = mk_qpn(qpt, map, offset);
137 * This test differs from alloc_pidmap().
138 * If find_next_offset() does find a zero
139 * bit, we don't need to check for QPN
140 * wrapping around past our starting QPN.
141 * We just need to be sure we don't loop
144 } while (offset < BITS_PER_PAGE && qpn < QPN_MAX);
147 * In order to keep the number of pages allocated to a
148 * minimum, we scan the all existing pages before increasing
149 * the size of the bitmap table.
151 if (++i > max_scan) {
152 if (qpt->nmaps == QPNMAP_ENTRIES)
154 map = &qpt->map[qpt->nmaps++];
156 } else if (map < &qpt->map[qpt->nmaps]) {
163 qpn = mk_qpn(qpt, map, offset);
172 static void free_qpn(struct ipath_qp_table *qpt, u32 qpn)
176 map = qpt->map + qpn / BITS_PER_PAGE;
178 clear_bit(qpn & BITS_PER_PAGE_MASK, map->page);
179 atomic_inc(&map->n_free);
183 * ipath_alloc_qpn - allocate a QP number
186 * @type: the QP type (IB_QPT_SMI and IB_QPT_GSI are special)
188 * Allocate the next available QPN and put the QP into the hash table.
189 * The hash table holds a reference to the QP.
191 int ipath_alloc_qpn(struct ipath_qp_table *qpt, struct ipath_qp *qp,
192 enum ib_qp_type type)
198 if (type == IB_QPT_SMI)
200 else if (type == IB_QPT_GSI)
203 /* Allocate the next available QPN */
204 qpn = alloc_qpn(qpt);
210 qp->ibqp.qp_num = qpn;
212 /* Add the QP to the hash table. */
213 spin_lock_irqsave(&qpt->lock, flags);
216 qp->next = qpt->table[qpn];
217 qpt->table[qpn] = qp;
218 atomic_inc(&qp->refcount);
220 spin_unlock_irqrestore(&qpt->lock, flags);
228 * ipath_free_qp - remove a QP from the QP table
230 * @qp: the QP to remove
232 * Remove the QP from the table so it can't be found asynchronously by
233 * the receive interrupt routine.
235 void ipath_free_qp(struct ipath_qp_table *qpt, struct ipath_qp *qp)
237 struct ipath_qp *q, **qpp;
241 spin_lock_irqsave(&qpt->lock, flags);
243 /* Remove QP from the hash table. */
244 qpp = &qpt->table[qp->ibqp.qp_num % qpt->max];
245 for (; (q = *qpp) != NULL; qpp = &q->next) {
249 atomic_dec(&qp->refcount);
255 spin_unlock_irqrestore(&qpt->lock, flags);
260 /* If QPN is not reserved, mark QPN free in the bitmap. */
261 if (qp->ibqp.qp_num > 1)
262 free_qpn(qpt, qp->ibqp.qp_num);
264 wait_event(qp->wait, !atomic_read(&qp->refcount));
268 * ipath_free_all_qps - remove all QPs from the table
269 * @qpt: the QP table to empty
271 void ipath_free_all_qps(struct ipath_qp_table *qpt)
274 struct ipath_qp *qp, *nqp;
277 for (n = 0; n < qpt->max; n++) {
278 spin_lock_irqsave(&qpt->lock, flags);
280 qpt->table[n] = NULL;
281 spin_unlock_irqrestore(&qpt->lock, flags);
285 if (qp->ibqp.qp_num > 1)
286 free_qpn(qpt, qp->ibqp.qp_num);
287 if (!atomic_dec_and_test(&qp->refcount) ||
288 !ipath_destroy_qp(&qp->ibqp))
289 _VERBS_INFO("QP memory leak!\n");
294 for (n = 0; n < ARRAY_SIZE(qpt->map); n++) {
295 if (qpt->map[n].page)
296 free_page((unsigned long)qpt->map[n].page);
301 * ipath_lookup_qpn - return the QP with the given QPN
303 * @qpn: the QP number to look up
305 * The caller is responsible for decrementing the QP reference count
308 struct ipath_qp *ipath_lookup_qpn(struct ipath_qp_table *qpt, u32 qpn)
313 spin_lock_irqsave(&qpt->lock, flags);
315 for (qp = qpt->table[qpn % qpt->max]; qp; qp = qp->next) {
316 if (qp->ibqp.qp_num == qpn) {
317 atomic_inc(&qp->refcount);
322 spin_unlock_irqrestore(&qpt->lock, flags);
327 * ipath_reset_qp - initialize the QP state to the reset state
328 * @qp: the QP to reset
330 static void ipath_reset_qp(struct ipath_qp *qp)
334 qp->qp_access_flags = 0;
338 atomic_set(&qp->msn, 0);
339 if (qp->ibqp.qp_type == IB_QPT_RC) {
340 qp->s_state = IB_OPCODE_RC_SEND_LAST;
341 qp->r_state = IB_OPCODE_RC_SEND_LAST;
343 qp->s_state = IB_OPCODE_UC_SEND_LAST;
344 qp->r_state = IB_OPCODE_UC_SEND_LAST;
346 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
348 qp->s_rnr_timeout = 0;
361 * ipath_modify_qp - modify the attributes of a queue pair
362 * @ibqp: the queue pair who's attributes we're modifying
363 * @attr: the new attributes
364 * @attr_mask: the mask of attributes to modify
366 * Returns 0 on success, otherwise returns an errno.
368 int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
371 struct ipath_qp *qp = to_iqp(ibqp);
372 enum ib_qp_state cur_state, new_state;
376 spin_lock_irqsave(&qp->r_rq.lock, flags);
377 spin_lock(&qp->s_lock);
379 cur_state = attr_mask & IB_QP_CUR_STATE ?
380 attr->cur_qp_state : qp->state;
381 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
383 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
401 if (attr_mask & IB_QP_PKEY_INDEX) {
402 struct ipath_ibdev *dev = to_idev(ibqp->device);
404 if (attr->pkey_index >= ipath_layer_get_npkeys(dev->dd))
406 qp->s_pkey_index = attr->pkey_index;
409 if (attr_mask & IB_QP_DEST_QPN)
410 qp->remote_qpn = attr->dest_qp_num;
412 if (attr_mask & IB_QP_SQ_PSN) {
413 qp->s_next_psn = attr->sq_psn;
414 qp->s_last_psn = qp->s_next_psn - 1;
417 if (attr_mask & IB_QP_RQ_PSN)
418 qp->r_psn = attr->rq_psn;
420 if (attr_mask & IB_QP_ACCESS_FLAGS)
421 qp->qp_access_flags = attr->qp_access_flags;
423 if (attr_mask & IB_QP_AV) {
424 if (attr->ah_attr.dlid == 0 ||
425 attr->ah_attr.dlid >= IPS_MULTICAST_LID_BASE)
427 qp->remote_ah_attr = attr->ah_attr;
430 if (attr_mask & IB_QP_PATH_MTU)
431 qp->path_mtu = attr->path_mtu;
433 if (attr_mask & IB_QP_RETRY_CNT)
434 qp->s_retry = qp->s_retry_cnt = attr->retry_cnt;
436 if (attr_mask & IB_QP_RNR_RETRY) {
437 qp->s_rnr_retry = attr->rnr_retry;
438 if (qp->s_rnr_retry > 7)
440 qp->s_rnr_retry_cnt = qp->s_rnr_retry;
443 if (attr_mask & IB_QP_MIN_RNR_TIMER) {
444 if (attr->min_rnr_timer > 31)
446 qp->s_min_rnr_timer = attr->min_rnr_timer;
449 if (attr_mask & IB_QP_QKEY)
450 qp->qkey = attr->qkey;
452 if (attr_mask & IB_QP_PKEY_INDEX)
453 qp->s_pkey_index = attr->pkey_index;
455 qp->state = new_state;
456 spin_unlock(&qp->s_lock);
457 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
460 * If QP1 changed to the RTS state, try to move to the link to INIT
461 * even if it was ACTIVE so the SM will reinitialize the SMA's
464 if (qp->ibqp.qp_num == 1 && new_state == IB_QPS_RTS) {
465 struct ipath_ibdev *dev = to_idev(ibqp->device);
467 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
473 spin_unlock(&qp->s_lock);
474 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
481 int ipath_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
482 int attr_mask, struct ib_qp_init_attr *init_attr)
484 struct ipath_qp *qp = to_iqp(ibqp);
486 attr->qp_state = qp->state;
487 attr->cur_qp_state = attr->qp_state;
488 attr->path_mtu = qp->path_mtu;
489 attr->path_mig_state = 0;
490 attr->qkey = qp->qkey;
491 attr->rq_psn = qp->r_psn;
492 attr->sq_psn = qp->s_next_psn;
493 attr->dest_qp_num = qp->remote_qpn;
494 attr->qp_access_flags = qp->qp_access_flags;
495 attr->cap.max_send_wr = qp->s_size - 1;
496 attr->cap.max_recv_wr = qp->r_rq.size - 1;
497 attr->cap.max_send_sge = qp->s_max_sge;
498 attr->cap.max_recv_sge = qp->r_rq.max_sge;
499 attr->cap.max_inline_data = 0;
500 attr->ah_attr = qp->remote_ah_attr;
501 memset(&attr->alt_ah_attr, 0, sizeof(attr->alt_ah_attr));
502 attr->pkey_index = qp->s_pkey_index;
503 attr->alt_pkey_index = 0;
504 attr->en_sqd_async_notify = 0;
505 attr->sq_draining = 0;
506 attr->max_rd_atomic = 1;
507 attr->max_dest_rd_atomic = 1;
508 attr->min_rnr_timer = qp->s_min_rnr_timer;
511 attr->retry_cnt = qp->s_retry_cnt;
512 attr->rnr_retry = qp->s_rnr_retry;
513 attr->alt_port_num = 0;
514 attr->alt_timeout = 0;
516 init_attr->event_handler = qp->ibqp.event_handler;
517 init_attr->qp_context = qp->ibqp.qp_context;
518 init_attr->send_cq = qp->ibqp.send_cq;
519 init_attr->recv_cq = qp->ibqp.recv_cq;
520 init_attr->srq = qp->ibqp.srq;
521 init_attr->cap = attr->cap;
522 init_attr->sq_sig_type =
523 (qp->s_flags & (1 << IPATH_S_SIGNAL_REQ_WR))
524 ? IB_SIGNAL_REQ_WR : 0;
525 init_attr->qp_type = qp->ibqp.qp_type;
526 init_attr->port_num = 1;
531 * ipath_compute_aeth - compute the AETH (syndrome + MSN)
532 * @qp: the queue pair to compute the AETH for
536 * The QP s_lock should be held.
538 __be32 ipath_compute_aeth(struct ipath_qp *qp)
540 u32 aeth = atomic_read(&qp->msn) & IPS_MSN_MASK;
542 if (qp->s_nak_state) {
543 aeth |= qp->s_nak_state << IPS_AETH_CREDIT_SHIFT;
544 } else if (qp->ibqp.srq) {
546 * Shared receive queues don't generate credits.
547 * Set the credit field to the invalid value.
549 aeth |= IPS_AETH_CREDIT_INVAL << IPS_AETH_CREDIT_SHIFT;
555 * Compute the number of credits available (RWQEs).
556 * XXX Not holding the r_rq.lock here so there is a small
557 * chance that the pair of reads are not atomic.
559 credits = qp->r_rq.head - qp->r_rq.tail;
560 if ((int)credits < 0)
561 credits += qp->r_rq.size;
563 * Binary search the credit table to find the code to
570 if (credit_table[x] == credits)
572 if (credit_table[x] > credits)
579 aeth |= x << IPS_AETH_CREDIT_SHIFT;
581 return cpu_to_be32(aeth);
585 * ipath_create_qp - create a queue pair for a device
586 * @ibpd: the protection domain who's device we create the queue pair for
587 * @init_attr: the attributes of the queue pair
588 * @udata: unused by InfiniPath
590 * Returns the queue pair on success, otherwise returns an errno.
592 * Called by the ib_create_qp() core verbs function.
594 struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
595 struct ib_qp_init_attr *init_attr,
596 struct ib_udata *udata)
600 struct ipath_swqe *swq = NULL;
601 struct ipath_ibdev *dev;
605 if (init_attr->cap.max_send_sge > 255 ||
606 init_attr->cap.max_recv_sge > 255) {
607 ret = ERR_PTR(-ENOMEM);
611 switch (init_attr->qp_type) {
614 sz = sizeof(struct ipath_sge) *
615 init_attr->cap.max_send_sge +
616 sizeof(struct ipath_swqe);
617 swq = vmalloc((init_attr->cap.max_send_wr + 1) * sz);
619 ret = ERR_PTR(-ENOMEM);
626 qp = kmalloc(sizeof(*qp), GFP_KERNEL);
628 ret = ERR_PTR(-ENOMEM);
631 qp->r_rq.size = init_attr->cap.max_recv_wr + 1;
632 sz = sizeof(struct ipath_sge) *
633 init_attr->cap.max_recv_sge +
634 sizeof(struct ipath_rwqe);
635 qp->r_rq.wq = vmalloc(qp->r_rq.size * sz);
638 ret = ERR_PTR(-ENOMEM);
643 * ib_create_qp() will initialize qp->ibqp
644 * except for qp->ibqp.qp_num.
646 spin_lock_init(&qp->s_lock);
647 spin_lock_init(&qp->r_rq.lock);
648 atomic_set(&qp->refcount, 0);
649 init_waitqueue_head(&qp->wait);
650 tasklet_init(&qp->s_task,
651 init_attr->qp_type == IB_QPT_RC ?
652 ipath_do_rc_send : ipath_do_uc_send,
654 qp->piowait.next = LIST_POISON1;
655 qp->piowait.prev = LIST_POISON2;
656 qp->timerwait.next = LIST_POISON1;
657 qp->timerwait.prev = LIST_POISON2;
658 qp->state = IB_QPS_RESET;
660 qp->s_size = init_attr->cap.max_send_wr + 1;
661 qp->s_max_sge = init_attr->cap.max_send_sge;
662 qp->r_rq.max_sge = init_attr->cap.max_recv_sge;
663 qp->s_flags = init_attr->sq_sig_type == IB_SIGNAL_REQ_WR ?
664 1 << IPATH_S_SIGNAL_REQ_WR : 0;
665 dev = to_idev(ibpd->device);
666 err = ipath_alloc_qpn(&dev->qp_table, qp,
677 /* Tell the core driver that the kernel SMA is present. */
678 if (qp->ibqp.qp_type == IB_QPT_SMI)
679 ipath_layer_set_verbs_flags(dev->dd,
680 IPATH_VERBS_KERNEL_SMA);
684 /* Don't support raw QPs */
685 ret = ERR_PTR(-ENOSYS);
689 init_attr->cap.max_inline_data = 0;
698 * ipath_destroy_qp - destroy a queue pair
699 * @ibqp: the queue pair to destroy
701 * Returns 0 on success.
703 * Note that this can be called while the QP is actively sending or
706 int ipath_destroy_qp(struct ib_qp *ibqp)
708 struct ipath_qp *qp = to_iqp(ibqp);
709 struct ipath_ibdev *dev = to_idev(ibqp->device);
712 /* Tell the core driver that the kernel SMA is gone. */
713 if (qp->ibqp.qp_type == IB_QPT_SMI)
714 ipath_layer_set_verbs_flags(dev->dd, 0);
716 spin_lock_irqsave(&qp->r_rq.lock, flags);
717 spin_lock(&qp->s_lock);
718 qp->state = IB_QPS_ERR;
719 spin_unlock(&qp->s_lock);
720 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
722 /* Stop the sending tasklet. */
723 tasklet_kill(&qp->s_task);
725 /* Make sure the QP isn't on the timeout list. */
726 spin_lock_irqsave(&dev->pending_lock, flags);
727 if (qp->timerwait.next != LIST_POISON1)
728 list_del(&qp->timerwait);
729 if (qp->piowait.next != LIST_POISON1)
730 list_del(&qp->piowait);
731 spin_unlock_irqrestore(&dev->pending_lock, flags);
734 * Make sure that the QP is not in the QPN table so receive
735 * interrupts will discard packets for this QP. XXX Also remove QP
736 * from multicast table.
738 if (atomic_read(&qp->refcount) != 0)
739 ipath_free_qp(&dev->qp_table, qp);
748 * ipath_init_qp_table - initialize the QP table for a device
749 * @idev: the device who's QP table we're initializing
750 * @size: the size of the QP table
752 * Returns 0 on success, otherwise returns an errno.
754 int ipath_init_qp_table(struct ipath_ibdev *idev, int size)
759 idev->qp_table.last = 1; /* QPN 0 and 1 are special. */
760 idev->qp_table.max = size;
761 idev->qp_table.nmaps = 1;
762 idev->qp_table.table = kzalloc(size * sizeof(*idev->qp_table.table),
764 if (idev->qp_table.table == NULL) {
769 for (i = 0; i < ARRAY_SIZE(idev->qp_table.map); i++) {
770 atomic_set(&idev->qp_table.map[i].n_free, BITS_PER_PAGE);
771 idev->qp_table.map[i].page = NULL;
781 * ipath_sqerror_qp - put a QP's send queue into an error state
782 * @qp: QP who's send queue will be put into an error state
783 * @wc: the WC responsible for putting the QP in this state
785 * Flushes the send work queue.
786 * The QP s_lock should be held.
789 void ipath_sqerror_qp(struct ipath_qp *qp, struct ib_wc *wc)
791 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
792 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
794 _VERBS_INFO("Send queue error on QP%d/%d: err: %d\n",
795 qp->ibqp.qp_num, qp->remote_qpn, wc->status);
797 spin_lock(&dev->pending_lock);
798 /* XXX What if its already removed by the timeout code? */
799 if (qp->timerwait.next != LIST_POISON1)
800 list_del(&qp->timerwait);
801 if (qp->piowait.next != LIST_POISON1)
802 list_del(&qp->piowait);
803 spin_unlock(&dev->pending_lock);
805 ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 1);
806 if (++qp->s_last >= qp->s_size)
809 wc->status = IB_WC_WR_FLUSH_ERR;
811 while (qp->s_last != qp->s_head) {
812 wc->wr_id = wqe->wr.wr_id;
813 wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
814 ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 1);
815 if (++qp->s_last >= qp->s_size)
817 wqe = get_swqe_ptr(qp, qp->s_last);
819 qp->s_cur = qp->s_tail = qp->s_head;
820 qp->state = IB_QPS_SQE;
824 * ipath_error_qp - put a QP into an error state
825 * @qp: the QP to put into an error state
827 * Flushes both send and receive work queues.
828 * QP r_rq.lock and s_lock should be held.
831 void ipath_error_qp(struct ipath_qp *qp)
833 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
836 _VERBS_INFO("QP%d/%d in error state\n",
837 qp->ibqp.qp_num, qp->remote_qpn);
839 spin_lock(&dev->pending_lock);
840 /* XXX What if its already removed by the timeout code? */
841 if (qp->timerwait.next != LIST_POISON1)
842 list_del(&qp->timerwait);
843 if (qp->piowait.next != LIST_POISON1)
844 list_del(&qp->piowait);
845 spin_unlock(&dev->pending_lock);
847 wc.status = IB_WC_WR_FLUSH_ERR;
851 wc.qp_num = qp->ibqp.qp_num;
857 wc.dlid_path_bits = 0;
860 while (qp->s_last != qp->s_head) {
861 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
863 wc.wr_id = wqe->wr.wr_id;
864 wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
865 if (++qp->s_last >= qp->s_size)
867 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 1);
869 qp->s_cur = qp->s_tail = qp->s_head;
871 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
873 wc.opcode = IB_WC_RECV;
874 while (qp->r_rq.tail != qp->r_rq.head) {
875 wc.wr_id = get_rwqe_ptr(&qp->r_rq, qp->r_rq.tail)->wr_id;
876 if (++qp->r_rq.tail >= qp->r_rq.size)
878 ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
883 * ipath_get_credit - flush the send work queue of a QP
884 * @qp: the qp who's send work queue to flush
885 * @aeth: the Acknowledge Extended Transport Header
887 * The QP s_lock should be held.
889 void ipath_get_credit(struct ipath_qp *qp, u32 aeth)
891 u32 credit = (aeth >> IPS_AETH_CREDIT_SHIFT) & IPS_AETH_CREDIT_MASK;
894 * If the credit is invalid, we can send
895 * as many packets as we like. Otherwise, we have to
896 * honor the credit field.
898 if (credit == IPS_AETH_CREDIT_INVAL) {
899 qp->s_lsn = (u32) -1;
900 } else if (qp->s_lsn != (u32) -1) {
901 /* Compute new LSN (i.e., MSN + credit) */
902 credit = (aeth + credit_table[credit]) & IPS_MSN_MASK;
903 if (ipath_cmp24(credit, qp->s_lsn) > 0)
907 /* Restart sending if it was blocked due to lack of credits. */
908 if (qp->s_cur != qp->s_head &&
909 (qp->s_lsn == (u32) -1 ||
910 ipath_cmp24(get_swqe_ptr(qp, qp->s_cur)->ssn,
911 qp->s_lsn + 1) <= 0))
912 tasklet_hi_schedule(&qp->s_task);