2 * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/spinlock.h>
35 #include <rdma/ib_smi.h>
41 * Validate a RWQE and fill in the SGE state.
44 static int qib_init_sge(struct rvt_qp *qp, struct rvt_rwqe *wqe)
48 struct rvt_lkey_table *rkt;
50 struct rvt_sge_state *ss;
52 rkt = &to_idev(qp->ibqp.device)->rdi.lkey_table;
53 pd = ibpd_to_rvtpd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd);
55 ss->sg_list = qp->r_sg_list;
57 for (i = j = 0; i < wqe->num_sge; i++) {
58 if (wqe->sg_list[i].length == 0)
61 ret = rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge,
62 NULL, &wqe->sg_list[i],
63 IB_ACCESS_LOCAL_WRITE);
64 if (unlikely(ret <= 0))
66 qp->r_len += wqe->sg_list[i].length;
70 ss->total_len = qp->r_len;
76 struct rvt_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge;
81 memset(&wc, 0, sizeof(wc));
82 wc.wr_id = wqe->wr_id;
83 wc.status = IB_WC_LOC_PROT_ERR;
84 wc.opcode = IB_WC_RECV;
86 /* Signal solicited completion event. */
87 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
94 * qib_get_rwqe - copy the next RWQE into the QP's RWQE
96 * @wr_id_only: update qp->r_wr_id only, not qp->r_sge
98 * Return -1 if there is a local error, 0 if no RWQE is available,
101 * Can be called from interrupt level.
103 int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only)
109 struct rvt_rwqe *wqe;
110 void (*handler)(struct ib_event *, void *);
115 srq = ibsrq_to_rvtsrq(qp->ibqp.srq);
116 handler = srq->ibsrq.event_handler;
124 spin_lock_irqsave(&rq->lock, flags);
125 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
132 /* Validate tail before using it since it is user writable. */
133 if (tail >= rq->size)
135 if (unlikely(tail == wq->head)) {
139 /* Make sure entry is read after head index is read. */
141 wqe = rvt_get_rwqe_ptr(rq, tail);
143 * Even though we update the tail index in memory, the verbs
144 * consumer is not supposed to post more entries until a
145 * completion is generated.
147 if (++tail >= rq->size)
150 if (!wr_id_only && !qib_init_sge(qp, wqe)) {
154 qp->r_wr_id = wqe->wr_id;
157 set_bit(RVT_R_WRID_VALID, &qp->r_aflags);
162 * Validate head pointer value and compute
163 * the number of remaining WQEs.
169 n += rq->size - tail;
172 if (n < srq->limit) {
176 spin_unlock_irqrestore(&rq->lock, flags);
177 ev.device = qp->ibqp.device;
178 ev.element.srq = qp->ibqp.srq;
179 ev.event = IB_EVENT_SRQ_LIMIT_REACHED;
180 handler(&ev, srq->ibsrq.srq_context);
185 spin_unlock_irqrestore(&rq->lock, flags);
191 * Switch to alternate path.
192 * The QP s_lock should be held and interrupts disabled.
194 void qib_migrate_qp(struct rvt_qp *qp)
198 qp->s_mig_state = IB_MIG_MIGRATED;
199 qp->remote_ah_attr = qp->alt_ah_attr;
200 qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr);
201 qp->s_pkey_index = qp->s_alt_pkey_index;
203 ev.device = qp->ibqp.device;
204 ev.element.qp = &qp->ibqp;
205 ev.event = IB_EVENT_PATH_MIG;
206 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
209 static __be64 get_sguid(struct qib_ibport *ibp, unsigned index)
212 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
216 return ibp->guids[index - 1];
219 static int gid_ok(union ib_gid *gid, __be64 gid_prefix, __be64 id)
221 return (gid->global.interface_id == id &&
222 (gid->global.subnet_prefix == gid_prefix ||
223 gid->global.subnet_prefix == IB_DEFAULT_GID_PREFIX));
228 * This should be called with the QP r_lock held.
230 * The s_lock will be acquired around the qib_migrate_qp() call.
232 int qib_ruc_check_hdr(struct qib_ibport *ibp, struct ib_header *hdr,
233 int has_grh, struct rvt_qp *qp, u32 bth0)
238 if (qp->s_mig_state == IB_MIG_ARMED && (bth0 & IB_BTH_MIG_REQ)) {
240 if (rdma_ah_get_ah_flags(&qp->alt_ah_attr) &
244 const struct ib_global_route *grh;
246 if (!(rdma_ah_get_ah_flags(&qp->alt_ah_attr) &
249 grh = rdma_ah_read_grh(&qp->alt_ah_attr);
250 guid = get_sguid(ibp, grh->sgid_index);
251 if (!gid_ok(&hdr->u.l.grh.dgid,
252 ibp->rvp.gid_prefix, guid))
254 if (!gid_ok(&hdr->u.l.grh.sgid,
255 grh->dgid.global.subnet_prefix,
256 grh->dgid.global.interface_id))
259 if (!qib_pkey_ok((u16)bth0,
260 qib_get_pkey(ibp, qp->s_alt_pkey_index))) {
263 (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF,
265 hdr->lrh[3], hdr->lrh[1]);
268 /* Validate the SLID. See Ch. 9.6.1.5 and 17.2.8 */
269 if ((be16_to_cpu(hdr->lrh[3]) !=
270 rdma_ah_get_dlid(&qp->alt_ah_attr)) ||
271 ppd_from_ibp(ibp)->port !=
272 rdma_ah_get_port_num(&qp->alt_ah_attr))
274 spin_lock_irqsave(&qp->s_lock, flags);
276 spin_unlock_irqrestore(&qp->s_lock, flags);
279 if (rdma_ah_get_ah_flags(&qp->remote_ah_attr) &
283 const struct ib_global_route *grh;
285 if (!(rdma_ah_get_ah_flags(&qp->remote_ah_attr) &
288 grh = rdma_ah_read_grh(&qp->remote_ah_attr);
289 guid = get_sguid(ibp, grh->sgid_index);
290 if (!gid_ok(&hdr->u.l.grh.dgid,
291 ibp->rvp.gid_prefix, guid))
293 if (!gid_ok(&hdr->u.l.grh.sgid,
294 grh->dgid.global.subnet_prefix,
295 grh->dgid.global.interface_id))
298 if (!qib_pkey_ok((u16)bth0,
299 qib_get_pkey(ibp, qp->s_pkey_index))) {
302 (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF,
304 hdr->lrh[3], hdr->lrh[1]);
307 /* Validate the SLID. See Ch. 9.6.1.5 */
308 if (be16_to_cpu(hdr->lrh[3]) !=
309 rdma_ah_get_dlid(&qp->remote_ah_attr) ||
310 ppd_from_ibp(ibp)->port != qp->port_num)
312 if (qp->s_mig_state == IB_MIG_REARM &&
313 !(bth0 & IB_BTH_MIG_REQ))
314 qp->s_mig_state = IB_MIG_ARMED;
324 * qib_ruc_loopback - handle UC and RC lookback requests
325 * @sqp: the sending QP
327 * This is called from qib_do_send() to
328 * forward a WQE addressed to the same HCA.
329 * Note that although we are single threaded due to the tasklet, we still
330 * have to protect against post_send(). We don't have to worry about
331 * receive interrupts since this is a connected protocol and all packets
332 * will pass through here.
334 static void qib_ruc_loopback(struct rvt_qp *sqp)
336 struct qib_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
337 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
338 struct qib_devdata *dd = ppd->dd;
339 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
341 struct rvt_swqe *wqe;
347 enum ib_wc_status send_status;
353 * Note that we check the responder QP state after
354 * checking the requester's state.
356 qp = rvt_lookup_qpn(rdi, &ibp->rvp, sqp->remote_qpn);
360 spin_lock_irqsave(&sqp->s_lock, flags);
362 /* Return if we are already busy processing a work request. */
363 if ((sqp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT)) ||
364 !(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_OR_FLUSH_SEND))
367 sqp->s_flags |= RVT_S_BUSY;
370 smp_read_barrier_depends(); /* see post_one_send() */
371 if (sqp->s_last == READ_ONCE(sqp->s_head))
373 wqe = rvt_get_swqe_ptr(sqp, sqp->s_last);
375 /* Return if it is not OK to start a new work reqeust. */
376 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
377 if (!(ib_rvt_state_ops[sqp->state] & RVT_FLUSH_SEND))
379 /* We are in the error state, flush the work request. */
380 send_status = IB_WC_WR_FLUSH_ERR;
385 * We can rely on the entry not changing without the s_lock
386 * being held until we update s_last.
387 * We increment s_cur to indicate s_last is in progress.
389 if (sqp->s_last == sqp->s_cur) {
390 if (++sqp->s_cur >= sqp->s_size)
393 spin_unlock_irqrestore(&sqp->s_lock, flags);
395 if (!qp || !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) ||
396 qp->ibqp.qp_type != sqp->ibqp.qp_type) {
397 ibp->rvp.n_pkt_drops++;
399 * For RC, the requester would timeout and retry so
400 * shortcut the timeouts and just signal too many retries.
402 if (sqp->ibqp.qp_type == IB_QPT_RC)
403 send_status = IB_WC_RETRY_EXC_ERR;
405 send_status = IB_WC_SUCCESS;
409 memset(&wc, 0, sizeof(wc));
410 send_status = IB_WC_SUCCESS;
413 sqp->s_sge.sge = wqe->sg_list[0];
414 sqp->s_sge.sg_list = wqe->sg_list + 1;
415 sqp->s_sge.num_sge = wqe->wr.num_sge;
416 sqp->s_len = wqe->length;
417 switch (wqe->wr.opcode) {
418 case IB_WR_SEND_WITH_IMM:
419 wc.wc_flags = IB_WC_WITH_IMM;
420 wc.ex.imm_data = wqe->wr.ex.imm_data;
423 ret = qib_get_rwqe(qp, 0);
430 case IB_WR_RDMA_WRITE_WITH_IMM:
431 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
433 wc.wc_flags = IB_WC_WITH_IMM;
434 wc.ex.imm_data = wqe->wr.ex.imm_data;
435 ret = qib_get_rwqe(qp, 1);
441 case IB_WR_RDMA_WRITE:
442 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
444 if (wqe->length == 0)
446 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, wqe->length,
447 wqe->rdma_wr.remote_addr,
449 IB_ACCESS_REMOTE_WRITE)))
451 qp->r_sge.sg_list = NULL;
452 qp->r_sge.num_sge = 1;
453 qp->r_sge.total_len = wqe->length;
456 case IB_WR_RDMA_READ:
457 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ)))
459 if (unlikely(!rvt_rkey_ok(qp, &sqp->s_sge.sge, wqe->length,
460 wqe->rdma_wr.remote_addr,
462 IB_ACCESS_REMOTE_READ)))
465 sqp->s_sge.sg_list = NULL;
466 sqp->s_sge.num_sge = 1;
467 qp->r_sge.sge = wqe->sg_list[0];
468 qp->r_sge.sg_list = wqe->sg_list + 1;
469 qp->r_sge.num_sge = wqe->wr.num_sge;
470 qp->r_sge.total_len = wqe->length;
473 case IB_WR_ATOMIC_CMP_AND_SWP:
474 case IB_WR_ATOMIC_FETCH_AND_ADD:
475 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC)))
477 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
478 wqe->atomic_wr.remote_addr,
480 IB_ACCESS_REMOTE_ATOMIC)))
482 /* Perform atomic OP and save result. */
483 maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
484 sdata = wqe->atomic_wr.compare_add;
485 *(u64 *) sqp->s_sge.sge.vaddr =
486 (wqe->atomic_wr.wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
487 (u64) atomic64_add_return(sdata, maddr) - sdata :
488 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
489 sdata, wqe->atomic_wr.swap);
490 rvt_put_mr(qp->r_sge.sge.mr);
491 qp->r_sge.num_sge = 0;
495 send_status = IB_WC_LOC_QP_OP_ERR;
499 sge = &sqp->s_sge.sge;
501 u32 len = sqp->s_len;
503 if (len > sge->length)
505 if (len > sge->sge_length)
506 len = sge->sge_length;
508 qib_copy_sge(&qp->r_sge, sge->vaddr, len, release);
511 sge->sge_length -= len;
512 if (sge->sge_length == 0) {
515 if (--sqp->s_sge.num_sge)
516 *sge = *sqp->s_sge.sg_list++;
517 } else if (sge->length == 0 && sge->mr->lkey) {
518 if (++sge->n >= RVT_SEGSZ) {
519 if (++sge->m >= sge->mr->mapsz)
524 sge->mr->map[sge->m]->segs[sge->n].vaddr;
526 sge->mr->map[sge->m]->segs[sge->n].length;
531 rvt_put_ss(&qp->r_sge);
533 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
536 if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM)
537 wc.opcode = IB_WC_RECV_RDMA_WITH_IMM;
539 wc.opcode = IB_WC_RECV;
540 wc.wr_id = qp->r_wr_id;
541 wc.status = IB_WC_SUCCESS;
542 wc.byte_len = wqe->length;
544 wc.src_qp = qp->remote_qpn;
545 wc.slid = rdma_ah_get_dlid(&qp->remote_ah_attr);
546 wc.sl = rdma_ah_get_sl(&qp->remote_ah_attr);
548 /* Signal completion event if the solicited bit is set. */
549 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
550 wqe->wr.send_flags & IB_SEND_SOLICITED);
553 spin_lock_irqsave(&sqp->s_lock, flags);
554 ibp->rvp.n_loop_pkts++;
556 sqp->s_rnr_retry = sqp->s_rnr_retry_cnt;
557 qib_send_complete(sqp, wqe, send_status);
562 if (qp->ibqp.qp_type == IB_QPT_UC)
564 ibp->rvp.n_rnr_naks++;
566 * Note: we don't need the s_lock held since the BUSY flag
567 * makes this single threaded.
569 if (sqp->s_rnr_retry == 0) {
570 send_status = IB_WC_RNR_RETRY_EXC_ERR;
573 if (sqp->s_rnr_retry_cnt < 7)
575 spin_lock_irqsave(&sqp->s_lock, flags);
576 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_RECV_OK))
578 rvt_add_rnr_timer(sqp, qp->r_min_rnr_timer <<
579 IB_AETH_CREDIT_SHIFT);
583 send_status = IB_WC_REM_OP_ERR;
584 wc.status = IB_WC_LOC_QP_OP_ERR;
588 send_status = IB_WC_REM_INV_REQ_ERR;
589 wc.status = IB_WC_LOC_QP_OP_ERR;
593 send_status = IB_WC_REM_ACCESS_ERR;
594 wc.status = IB_WC_LOC_PROT_ERR;
596 /* responder goes to error state */
597 rvt_rc_error(qp, wc.status);
600 spin_lock_irqsave(&sqp->s_lock, flags);
601 qib_send_complete(sqp, wqe, send_status);
602 if (sqp->ibqp.qp_type == IB_QPT_RC) {
603 int lastwqe = rvt_error_qp(sqp, IB_WC_WR_FLUSH_ERR);
605 sqp->s_flags &= ~RVT_S_BUSY;
606 spin_unlock_irqrestore(&sqp->s_lock, flags);
610 ev.device = sqp->ibqp.device;
611 ev.element.qp = &sqp->ibqp;
612 ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
613 sqp->ibqp.event_handler(&ev, sqp->ibqp.qp_context);
618 sqp->s_flags &= ~RVT_S_BUSY;
620 spin_unlock_irqrestore(&sqp->s_lock, flags);
626 * qib_make_grh - construct a GRH header
627 * @ibp: a pointer to the IB port
628 * @hdr: a pointer to the GRH header being constructed
629 * @grh: the global route address to send to
630 * @hwords: the number of 32 bit words of header being sent
631 * @nwords: the number of 32 bit words of data being sent
633 * Return the size of the header in 32 bit words.
635 u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
636 const struct ib_global_route *grh, u32 hwords, u32 nwords)
638 hdr->version_tclass_flow =
639 cpu_to_be32((IB_GRH_VERSION << IB_GRH_VERSION_SHIFT) |
640 (grh->traffic_class << IB_GRH_TCLASS_SHIFT) |
641 (grh->flow_label << IB_GRH_FLOW_SHIFT));
642 hdr->paylen = cpu_to_be16((hwords - 2 + nwords + SIZE_OF_CRC) << 2);
643 /* next_hdr is defined by C8-7 in ch. 8.4.1 */
644 hdr->next_hdr = IB_GRH_NEXT_HDR;
645 hdr->hop_limit = grh->hop_limit;
646 /* The SGID is 32-bit aligned. */
647 hdr->sgid.global.subnet_prefix = ibp->rvp.gid_prefix;
648 if (!grh->sgid_index)
649 hdr->sgid.global.interface_id = ppd_from_ibp(ibp)->guid;
650 else if (grh->sgid_index < QIB_GUIDS_PER_PORT)
651 hdr->sgid.global.interface_id = ibp->guids[grh->sgid_index - 1];
652 hdr->dgid = grh->dgid;
654 /* GRH header size in 32-bit words. */
655 return sizeof(struct ib_grh) / sizeof(u32);
658 void qib_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
661 struct qib_qp_priv *priv = qp->priv;
662 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
667 /* Construct the header. */
668 extra_bytes = -qp->s_cur_size & 3;
669 nwords = (qp->s_cur_size + extra_bytes) >> 2;
671 if (unlikely(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH)) {
673 qib_make_grh(ibp, &priv->s_hdr->u.l.grh,
674 rdma_ah_read_grh(&qp->remote_ah_attr),
675 qp->s_hdrwords, nwords);
678 lrh0 |= ibp->sl_to_vl[rdma_ah_get_sl(&qp->remote_ah_attr)] << 12 |
679 rdma_ah_get_sl(&qp->remote_ah_attr) << 4;
680 priv->s_hdr->lrh[0] = cpu_to_be16(lrh0);
681 priv->s_hdr->lrh[1] =
682 cpu_to_be16(rdma_ah_get_dlid(&qp->remote_ah_attr));
683 priv->s_hdr->lrh[2] =
684 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
685 priv->s_hdr->lrh[3] =
686 cpu_to_be16(ppd_from_ibp(ibp)->lid |
687 rdma_ah_get_path_bits(&qp->remote_ah_attr));
688 bth0 |= qib_get_pkey(ibp, qp->s_pkey_index);
689 bth0 |= extra_bytes << 20;
690 if (qp->s_mig_state == IB_MIG_MIGRATED)
691 bth0 |= IB_BTH_MIG_REQ;
692 ohdr->bth[0] = cpu_to_be32(bth0);
693 ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
694 ohdr->bth[2] = cpu_to_be32(bth2);
695 this_cpu_inc(ibp->pmastats->n_unicast_xmit);
698 void _qib_do_send(struct work_struct *work)
700 struct qib_qp_priv *priv = container_of(work, struct qib_qp_priv,
702 struct rvt_qp *qp = priv->owner;
708 * qib_do_send - perform a send on a QP
709 * @qp: pointer to the QP
711 * Process entries in the send work queue until credit or queue is
712 * exhausted. Only allow one CPU to send a packet per QP (tasklet).
713 * Otherwise, two threads could send packets out of order.
715 void qib_do_send(struct rvt_qp *qp)
717 struct qib_qp_priv *priv = qp->priv;
718 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
719 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
720 int (*make_req)(struct rvt_qp *qp, unsigned long *flags);
723 if ((qp->ibqp.qp_type == IB_QPT_RC ||
724 qp->ibqp.qp_type == IB_QPT_UC) &&
725 (rdma_ah_get_dlid(&qp->remote_ah_attr) &
726 ~((1 << ppd->lmc) - 1)) == ppd->lid) {
727 qib_ruc_loopback(qp);
731 if (qp->ibqp.qp_type == IB_QPT_RC)
732 make_req = qib_make_rc_req;
733 else if (qp->ibqp.qp_type == IB_QPT_UC)
734 make_req = qib_make_uc_req;
736 make_req = qib_make_ud_req;
738 spin_lock_irqsave(&qp->s_lock, flags);
740 /* Return if we are already busy processing a work request. */
741 if (!qib_send_ok(qp)) {
742 spin_unlock_irqrestore(&qp->s_lock, flags);
746 qp->s_flags |= RVT_S_BUSY;
749 /* Check for a constructed packet to be sent. */
750 if (qp->s_hdrwords != 0) {
751 spin_unlock_irqrestore(&qp->s_lock, flags);
753 * If the packet cannot be sent now, return and
754 * the send tasklet will be woken up later.
756 if (qib_verbs_send(qp, priv->s_hdr, qp->s_hdrwords,
757 qp->s_cur_sge, qp->s_cur_size))
759 /* Record that s_hdr is empty. */
761 spin_lock_irqsave(&qp->s_lock, flags);
763 } while (make_req(qp, &flags));
765 spin_unlock_irqrestore(&qp->s_lock, flags);
769 * This should be called with s_lock held.
771 void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
772 enum ib_wc_status status)
776 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND))
781 if (++last >= qp->s_size)
784 /* See post_send() */
787 if (qp->ibqp.qp_type == IB_QPT_UD ||
788 qp->ibqp.qp_type == IB_QPT_SMI ||
789 qp->ibqp.qp_type == IB_QPT_GSI)
790 atomic_dec(&ibah_to_rvtah(wqe->ud_wr.ah)->refcount);
792 rvt_qp_swqe_complete(qp,
794 ib_qib_wc_opcode[wqe->wr.opcode],
797 if (qp->s_acked == old_last)
799 if (qp->s_cur == old_last)
801 if (qp->s_tail == old_last)
803 if (qp->state == IB_QPS_SQD && last == qp->s_cur)