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 static 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 static 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_error_qp - put a QP into an error state
362 * @qp: the QP to put into an error state
364 * Flushes both send and receive work queues.
365 * QP r_rq.lock and s_lock should be held.
368 static void ipath_error_qp(struct ipath_qp *qp)
370 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
373 _VERBS_INFO("QP%d/%d in error state\n",
374 qp->ibqp.qp_num, qp->remote_qpn);
376 spin_lock(&dev->pending_lock);
377 /* XXX What if its already removed by the timeout code? */
378 if (qp->timerwait.next != LIST_POISON1)
379 list_del(&qp->timerwait);
380 if (qp->piowait.next != LIST_POISON1)
381 list_del(&qp->piowait);
382 spin_unlock(&dev->pending_lock);
384 wc.status = IB_WC_WR_FLUSH_ERR;
388 wc.qp_num = qp->ibqp.qp_num;
394 wc.dlid_path_bits = 0;
397 while (qp->s_last != qp->s_head) {
398 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
400 wc.wr_id = wqe->wr.wr_id;
401 wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
402 if (++qp->s_last >= qp->s_size)
404 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 1);
406 qp->s_cur = qp->s_tail = qp->s_head;
408 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
410 wc.opcode = IB_WC_RECV;
411 while (qp->r_rq.tail != qp->r_rq.head) {
412 wc.wr_id = get_rwqe_ptr(&qp->r_rq, qp->r_rq.tail)->wr_id;
413 if (++qp->r_rq.tail >= qp->r_rq.size)
415 ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
420 * ipath_modify_qp - modify the attributes of a queue pair
421 * @ibqp: the queue pair who's attributes we're modifying
422 * @attr: the new attributes
423 * @attr_mask: the mask of attributes to modify
425 * Returns 0 on success, otherwise returns an errno.
427 int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
430 struct ipath_qp *qp = to_iqp(ibqp);
431 enum ib_qp_state cur_state, new_state;
435 spin_lock_irqsave(&qp->r_rq.lock, flags);
436 spin_lock(&qp->s_lock);
438 cur_state = attr_mask & IB_QP_CUR_STATE ?
439 attr->cur_qp_state : qp->state;
440 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
442 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
460 if (attr_mask & IB_QP_PKEY_INDEX) {
461 struct ipath_ibdev *dev = to_idev(ibqp->device);
463 if (attr->pkey_index >= ipath_layer_get_npkeys(dev->dd))
465 qp->s_pkey_index = attr->pkey_index;
468 if (attr_mask & IB_QP_DEST_QPN)
469 qp->remote_qpn = attr->dest_qp_num;
471 if (attr_mask & IB_QP_SQ_PSN) {
472 qp->s_next_psn = attr->sq_psn;
473 qp->s_last_psn = qp->s_next_psn - 1;
476 if (attr_mask & IB_QP_RQ_PSN)
477 qp->r_psn = attr->rq_psn;
479 if (attr_mask & IB_QP_ACCESS_FLAGS)
480 qp->qp_access_flags = attr->qp_access_flags;
482 if (attr_mask & IB_QP_AV) {
483 if (attr->ah_attr.dlid == 0 ||
484 attr->ah_attr.dlid >= IPS_MULTICAST_LID_BASE)
486 qp->remote_ah_attr = attr->ah_attr;
489 if (attr_mask & IB_QP_PATH_MTU)
490 qp->path_mtu = attr->path_mtu;
492 if (attr_mask & IB_QP_RETRY_CNT)
493 qp->s_retry = qp->s_retry_cnt = attr->retry_cnt;
495 if (attr_mask & IB_QP_RNR_RETRY) {
496 qp->s_rnr_retry = attr->rnr_retry;
497 if (qp->s_rnr_retry > 7)
499 qp->s_rnr_retry_cnt = qp->s_rnr_retry;
502 if (attr_mask & IB_QP_MIN_RNR_TIMER) {
503 if (attr->min_rnr_timer > 31)
505 qp->s_min_rnr_timer = attr->min_rnr_timer;
508 if (attr_mask & IB_QP_QKEY)
509 qp->qkey = attr->qkey;
511 if (attr_mask & IB_QP_PKEY_INDEX)
512 qp->s_pkey_index = attr->pkey_index;
514 qp->state = new_state;
515 spin_unlock(&qp->s_lock);
516 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
519 * If QP1 changed to the RTS state, try to move to the link to INIT
520 * even if it was ACTIVE so the SM will reinitialize the SMA's
523 if (qp->ibqp.qp_num == 1 && new_state == IB_QPS_RTS) {
524 struct ipath_ibdev *dev = to_idev(ibqp->device);
526 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
532 spin_unlock(&qp->s_lock);
533 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
540 int ipath_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
541 int attr_mask, struct ib_qp_init_attr *init_attr)
543 struct ipath_qp *qp = to_iqp(ibqp);
545 attr->qp_state = qp->state;
546 attr->cur_qp_state = attr->qp_state;
547 attr->path_mtu = qp->path_mtu;
548 attr->path_mig_state = 0;
549 attr->qkey = qp->qkey;
550 attr->rq_psn = qp->r_psn;
551 attr->sq_psn = qp->s_next_psn;
552 attr->dest_qp_num = qp->remote_qpn;
553 attr->qp_access_flags = qp->qp_access_flags;
554 attr->cap.max_send_wr = qp->s_size - 1;
555 attr->cap.max_recv_wr = qp->r_rq.size - 1;
556 attr->cap.max_send_sge = qp->s_max_sge;
557 attr->cap.max_recv_sge = qp->r_rq.max_sge;
558 attr->cap.max_inline_data = 0;
559 attr->ah_attr = qp->remote_ah_attr;
560 memset(&attr->alt_ah_attr, 0, sizeof(attr->alt_ah_attr));
561 attr->pkey_index = qp->s_pkey_index;
562 attr->alt_pkey_index = 0;
563 attr->en_sqd_async_notify = 0;
564 attr->sq_draining = 0;
565 attr->max_rd_atomic = 1;
566 attr->max_dest_rd_atomic = 1;
567 attr->min_rnr_timer = qp->s_min_rnr_timer;
570 attr->retry_cnt = qp->s_retry_cnt;
571 attr->rnr_retry = qp->s_rnr_retry;
572 attr->alt_port_num = 0;
573 attr->alt_timeout = 0;
575 init_attr->event_handler = qp->ibqp.event_handler;
576 init_attr->qp_context = qp->ibqp.qp_context;
577 init_attr->send_cq = qp->ibqp.send_cq;
578 init_attr->recv_cq = qp->ibqp.recv_cq;
579 init_attr->srq = qp->ibqp.srq;
580 init_attr->cap = attr->cap;
581 init_attr->sq_sig_type =
582 (qp->s_flags & (1 << IPATH_S_SIGNAL_REQ_WR))
583 ? IB_SIGNAL_REQ_WR : 0;
584 init_attr->qp_type = qp->ibqp.qp_type;
585 init_attr->port_num = 1;
590 * ipath_compute_aeth - compute the AETH (syndrome + MSN)
591 * @qp: the queue pair to compute the AETH for
595 * The QP s_lock should be held.
597 __be32 ipath_compute_aeth(struct ipath_qp *qp)
599 u32 aeth = atomic_read(&qp->msn) & IPS_MSN_MASK;
601 if (qp->s_nak_state) {
602 aeth |= qp->s_nak_state << IPS_AETH_CREDIT_SHIFT;
603 } else if (qp->ibqp.srq) {
605 * Shared receive queues don't generate credits.
606 * Set the credit field to the invalid value.
608 aeth |= IPS_AETH_CREDIT_INVAL << IPS_AETH_CREDIT_SHIFT;
614 * Compute the number of credits available (RWQEs).
615 * XXX Not holding the r_rq.lock here so there is a small
616 * chance that the pair of reads are not atomic.
618 credits = qp->r_rq.head - qp->r_rq.tail;
619 if ((int)credits < 0)
620 credits += qp->r_rq.size;
622 * Binary search the credit table to find the code to
629 if (credit_table[x] == credits)
631 if (credit_table[x] > credits)
638 aeth |= x << IPS_AETH_CREDIT_SHIFT;
640 return cpu_to_be32(aeth);
644 * ipath_create_qp - create a queue pair for a device
645 * @ibpd: the protection domain who's device we create the queue pair for
646 * @init_attr: the attributes of the queue pair
647 * @udata: unused by InfiniPath
649 * Returns the queue pair on success, otherwise returns an errno.
651 * Called by the ib_create_qp() core verbs function.
653 struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
654 struct ib_qp_init_attr *init_attr,
655 struct ib_udata *udata)
659 struct ipath_swqe *swq = NULL;
660 struct ipath_ibdev *dev;
664 if (init_attr->cap.max_send_sge > 255 ||
665 init_attr->cap.max_recv_sge > 255) {
666 ret = ERR_PTR(-ENOMEM);
670 switch (init_attr->qp_type) {
673 sz = sizeof(struct ipath_sge) *
674 init_attr->cap.max_send_sge +
675 sizeof(struct ipath_swqe);
676 swq = vmalloc((init_attr->cap.max_send_wr + 1) * sz);
678 ret = ERR_PTR(-ENOMEM);
685 qp = kmalloc(sizeof(*qp), GFP_KERNEL);
687 ret = ERR_PTR(-ENOMEM);
690 qp->r_rq.size = init_attr->cap.max_recv_wr + 1;
691 sz = sizeof(struct ipath_sge) *
692 init_attr->cap.max_recv_sge +
693 sizeof(struct ipath_rwqe);
694 qp->r_rq.wq = vmalloc(qp->r_rq.size * sz);
697 ret = ERR_PTR(-ENOMEM);
702 * ib_create_qp() will initialize qp->ibqp
703 * except for qp->ibqp.qp_num.
705 spin_lock_init(&qp->s_lock);
706 spin_lock_init(&qp->r_rq.lock);
707 atomic_set(&qp->refcount, 0);
708 init_waitqueue_head(&qp->wait);
709 tasklet_init(&qp->s_task,
710 init_attr->qp_type == IB_QPT_RC ?
711 ipath_do_rc_send : ipath_do_uc_send,
713 qp->piowait.next = LIST_POISON1;
714 qp->piowait.prev = LIST_POISON2;
715 qp->timerwait.next = LIST_POISON1;
716 qp->timerwait.prev = LIST_POISON2;
717 qp->state = IB_QPS_RESET;
719 qp->s_size = init_attr->cap.max_send_wr + 1;
720 qp->s_max_sge = init_attr->cap.max_send_sge;
721 qp->r_rq.max_sge = init_attr->cap.max_recv_sge;
722 qp->s_flags = init_attr->sq_sig_type == IB_SIGNAL_REQ_WR ?
723 1 << IPATH_S_SIGNAL_REQ_WR : 0;
724 dev = to_idev(ibpd->device);
725 err = ipath_alloc_qpn(&dev->qp_table, qp,
736 /* Tell the core driver that the kernel SMA is present. */
737 if (qp->ibqp.qp_type == IB_QPT_SMI)
738 ipath_layer_set_verbs_flags(dev->dd,
739 IPATH_VERBS_KERNEL_SMA);
743 /* Don't support raw QPs */
744 ret = ERR_PTR(-ENOSYS);
748 init_attr->cap.max_inline_data = 0;
757 * ipath_destroy_qp - destroy a queue pair
758 * @ibqp: the queue pair to destroy
760 * Returns 0 on success.
762 * Note that this can be called while the QP is actively sending or
765 int ipath_destroy_qp(struct ib_qp *ibqp)
767 struct ipath_qp *qp = to_iqp(ibqp);
768 struct ipath_ibdev *dev = to_idev(ibqp->device);
771 /* Tell the core driver that the kernel SMA is gone. */
772 if (qp->ibqp.qp_type == IB_QPT_SMI)
773 ipath_layer_set_verbs_flags(dev->dd, 0);
775 spin_lock_irqsave(&qp->r_rq.lock, flags);
776 spin_lock(&qp->s_lock);
777 qp->state = IB_QPS_ERR;
778 spin_unlock(&qp->s_lock);
779 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
781 /* Stop the sending tasklet. */
782 tasklet_kill(&qp->s_task);
784 /* Make sure the QP isn't on the timeout list. */
785 spin_lock_irqsave(&dev->pending_lock, flags);
786 if (qp->timerwait.next != LIST_POISON1)
787 list_del(&qp->timerwait);
788 if (qp->piowait.next != LIST_POISON1)
789 list_del(&qp->piowait);
790 spin_unlock_irqrestore(&dev->pending_lock, flags);
793 * Make sure that the QP is not in the QPN table so receive
794 * interrupts will discard packets for this QP. XXX Also remove QP
795 * from multicast table.
797 if (atomic_read(&qp->refcount) != 0)
798 ipath_free_qp(&dev->qp_table, qp);
807 * ipath_init_qp_table - initialize the QP table for a device
808 * @idev: the device who's QP table we're initializing
809 * @size: the size of the QP table
811 * Returns 0 on success, otherwise returns an errno.
813 int ipath_init_qp_table(struct ipath_ibdev *idev, int size)
818 idev->qp_table.last = 1; /* QPN 0 and 1 are special. */
819 idev->qp_table.max = size;
820 idev->qp_table.nmaps = 1;
821 idev->qp_table.table = kzalloc(size * sizeof(*idev->qp_table.table),
823 if (idev->qp_table.table == NULL) {
828 for (i = 0; i < ARRAY_SIZE(idev->qp_table.map); i++) {
829 atomic_set(&idev->qp_table.map[i].n_free, BITS_PER_PAGE);
830 idev->qp_table.map[i].page = NULL;
840 * ipath_sqerror_qp - put a QP's send queue into an error state
841 * @qp: QP who's send queue will be put into an error state
842 * @wc: the WC responsible for putting the QP in this state
844 * Flushes the send work queue.
845 * The QP s_lock should be held.
848 void ipath_sqerror_qp(struct ipath_qp *qp, struct ib_wc *wc)
850 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
851 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
853 _VERBS_INFO("Send queue error on QP%d/%d: err: %d\n",
854 qp->ibqp.qp_num, qp->remote_qpn, wc->status);
856 spin_lock(&dev->pending_lock);
857 /* XXX What if its already removed by the timeout code? */
858 if (qp->timerwait.next != LIST_POISON1)
859 list_del(&qp->timerwait);
860 if (qp->piowait.next != LIST_POISON1)
861 list_del(&qp->piowait);
862 spin_unlock(&dev->pending_lock);
864 ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 1);
865 if (++qp->s_last >= qp->s_size)
868 wc->status = IB_WC_WR_FLUSH_ERR;
870 while (qp->s_last != qp->s_head) {
871 wc->wr_id = wqe->wr.wr_id;
872 wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
873 ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 1);
874 if (++qp->s_last >= qp->s_size)
876 wqe = get_swqe_ptr(qp, qp->s_last);
878 qp->s_cur = qp->s_tail = qp->s_head;
879 qp->state = IB_QPS_SQE;
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);