Path: blob/master/drivers/infiniband/hw/ipath/ipath_ruc.c
15112 views
/*1* Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.2* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*/3233#include <linux/sched.h>34#include <linux/spinlock.h>3536#include "ipath_verbs.h"37#include "ipath_kernel.h"3839/*40* Convert the AETH RNR timeout code into the number of milliseconds.41*/42const u32 ib_ipath_rnr_table[32] = {43656, /* 0 */441, /* 1 */451, /* 2 */461, /* 3 */471, /* 4 */481, /* 5 */491, /* 6 */501, /* 7 */511, /* 8 */521, /* 9 */531, /* A */541, /* B */551, /* C */561, /* D */572, /* E */582, /* F */593, /* 10 */604, /* 11 */616, /* 12 */628, /* 13 */6311, /* 14 */6416, /* 15 */6521, /* 16 */6631, /* 17 */6741, /* 18 */6862, /* 19 */6982, /* 1A */70123, /* 1B */71164, /* 1C */72246, /* 1D */73328, /* 1E */74492 /* 1F */75};7677/**78* ipath_insert_rnr_queue - put QP on the RNR timeout list for the device79* @qp: the QP80*81* Called with the QP s_lock held and interrupts disabled.82* XXX Use a simple list for now. We might need a priority83* queue if we have lots of QPs waiting for RNR timeouts84* but that should be rare.85*/86void ipath_insert_rnr_queue(struct ipath_qp *qp)87{88struct ipath_ibdev *dev = to_idev(qp->ibqp.device);8990/* We already did a spin_lock_irqsave(), so just use spin_lock */91spin_lock(&dev->pending_lock);92if (list_empty(&dev->rnrwait))93list_add(&qp->timerwait, &dev->rnrwait);94else {95struct list_head *l = &dev->rnrwait;96struct ipath_qp *nqp = list_entry(l->next, struct ipath_qp,97timerwait);9899while (qp->s_rnr_timeout >= nqp->s_rnr_timeout) {100qp->s_rnr_timeout -= nqp->s_rnr_timeout;101l = l->next;102if (l->next == &dev->rnrwait) {103nqp = NULL;104break;105}106nqp = list_entry(l->next, struct ipath_qp,107timerwait);108}109if (nqp)110nqp->s_rnr_timeout -= qp->s_rnr_timeout;111list_add(&qp->timerwait, l);112}113spin_unlock(&dev->pending_lock);114}115116/**117* ipath_init_sge - Validate a RWQE and fill in the SGE state118* @qp: the QP119*120* Return 1 if OK.121*/122int ipath_init_sge(struct ipath_qp *qp, struct ipath_rwqe *wqe,123u32 *lengthp, struct ipath_sge_state *ss)124{125int i, j, ret;126struct ib_wc wc;127128*lengthp = 0;129for (i = j = 0; i < wqe->num_sge; i++) {130if (wqe->sg_list[i].length == 0)131continue;132/* Check LKEY */133if (!ipath_lkey_ok(qp, j ? &ss->sg_list[j - 1] : &ss->sge,134&wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE))135goto bad_lkey;136*lengthp += wqe->sg_list[i].length;137j++;138}139ss->num_sge = j;140ret = 1;141goto bail;142143bad_lkey:144memset(&wc, 0, sizeof(wc));145wc.wr_id = wqe->wr_id;146wc.status = IB_WC_LOC_PROT_ERR;147wc.opcode = IB_WC_RECV;148wc.qp = &qp->ibqp;149/* Signal solicited completion event. */150ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);151ret = 0;152bail:153return ret;154}155156/**157* ipath_get_rwqe - copy the next RWQE into the QP's RWQE158* @qp: the QP159* @wr_id_only: update qp->r_wr_id only, not qp->r_sge160*161* Return 0 if no RWQE is available, otherwise return 1.162*163* Can be called from interrupt level.164*/165int ipath_get_rwqe(struct ipath_qp *qp, int wr_id_only)166{167unsigned long flags;168struct ipath_rq *rq;169struct ipath_rwq *wq;170struct ipath_srq *srq;171struct ipath_rwqe *wqe;172void (*handler)(struct ib_event *, void *);173u32 tail;174int ret;175176if (qp->ibqp.srq) {177srq = to_isrq(qp->ibqp.srq);178handler = srq->ibsrq.event_handler;179rq = &srq->rq;180} else {181srq = NULL;182handler = NULL;183rq = &qp->r_rq;184}185186spin_lock_irqsave(&rq->lock, flags);187if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {188ret = 0;189goto unlock;190}191192wq = rq->wq;193tail = wq->tail;194/* Validate tail before using it since it is user writable. */195if (tail >= rq->size)196tail = 0;197do {198if (unlikely(tail == wq->head)) {199ret = 0;200goto unlock;201}202/* Make sure entry is read after head index is read. */203smp_rmb();204wqe = get_rwqe_ptr(rq, tail);205if (++tail >= rq->size)206tail = 0;207if (wr_id_only)208break;209qp->r_sge.sg_list = qp->r_sg_list;210} while (!ipath_init_sge(qp, wqe, &qp->r_len, &qp->r_sge));211qp->r_wr_id = wqe->wr_id;212wq->tail = tail;213214ret = 1;215set_bit(IPATH_R_WRID_VALID, &qp->r_aflags);216if (handler) {217u32 n;218219/*220* validate head pointer value and compute221* the number of remaining WQEs.222*/223n = wq->head;224if (n >= rq->size)225n = 0;226if (n < tail)227n += rq->size - tail;228else229n -= tail;230if (n < srq->limit) {231struct ib_event ev;232233srq->limit = 0;234spin_unlock_irqrestore(&rq->lock, flags);235ev.device = qp->ibqp.device;236ev.element.srq = qp->ibqp.srq;237ev.event = IB_EVENT_SRQ_LIMIT_REACHED;238handler(&ev, srq->ibsrq.srq_context);239goto bail;240}241}242unlock:243spin_unlock_irqrestore(&rq->lock, flags);244bail:245return ret;246}247248/**249* ipath_ruc_loopback - handle UC and RC lookback requests250* @sqp: the sending QP251*252* This is called from ipath_do_send() to253* forward a WQE addressed to the same HCA.254* Note that although we are single threaded due to the tasklet, we still255* have to protect against post_send(). We don't have to worry about256* receive interrupts since this is a connected protocol and all packets257* will pass through here.258*/259static void ipath_ruc_loopback(struct ipath_qp *sqp)260{261struct ipath_ibdev *dev = to_idev(sqp->ibqp.device);262struct ipath_qp *qp;263struct ipath_swqe *wqe;264struct ipath_sge *sge;265unsigned long flags;266struct ib_wc wc;267u64 sdata;268atomic64_t *maddr;269enum ib_wc_status send_status;270271/*272* Note that we check the responder QP state after273* checking the requester's state.274*/275qp = ipath_lookup_qpn(&dev->qp_table, sqp->remote_qpn);276277spin_lock_irqsave(&sqp->s_lock, flags);278279/* Return if we are already busy processing a work request. */280if ((sqp->s_flags & (IPATH_S_BUSY | IPATH_S_ANY_WAIT)) ||281!(ib_ipath_state_ops[sqp->state] & IPATH_PROCESS_OR_FLUSH_SEND))282goto unlock;283284sqp->s_flags |= IPATH_S_BUSY;285286again:287if (sqp->s_last == sqp->s_head)288goto clr_busy;289wqe = get_swqe_ptr(sqp, sqp->s_last);290291/* Return if it is not OK to start a new work reqeust. */292if (!(ib_ipath_state_ops[sqp->state] & IPATH_PROCESS_NEXT_SEND_OK)) {293if (!(ib_ipath_state_ops[sqp->state] & IPATH_FLUSH_SEND))294goto clr_busy;295/* We are in the error state, flush the work request. */296send_status = IB_WC_WR_FLUSH_ERR;297goto flush_send;298}299300/*301* We can rely on the entry not changing without the s_lock302* being held until we update s_last.303* We increment s_cur to indicate s_last is in progress.304*/305if (sqp->s_last == sqp->s_cur) {306if (++sqp->s_cur >= sqp->s_size)307sqp->s_cur = 0;308}309spin_unlock_irqrestore(&sqp->s_lock, flags);310311if (!qp || !(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {312dev->n_pkt_drops++;313/*314* For RC, the requester would timeout and retry so315* shortcut the timeouts and just signal too many retries.316*/317if (sqp->ibqp.qp_type == IB_QPT_RC)318send_status = IB_WC_RETRY_EXC_ERR;319else320send_status = IB_WC_SUCCESS;321goto serr;322}323324memset(&wc, 0, sizeof wc);325send_status = IB_WC_SUCCESS;326327sqp->s_sge.sge = wqe->sg_list[0];328sqp->s_sge.sg_list = wqe->sg_list + 1;329sqp->s_sge.num_sge = wqe->wr.num_sge;330sqp->s_len = wqe->length;331switch (wqe->wr.opcode) {332case IB_WR_SEND_WITH_IMM:333wc.wc_flags = IB_WC_WITH_IMM;334wc.ex.imm_data = wqe->wr.ex.imm_data;335/* FALLTHROUGH */336case IB_WR_SEND:337if (!ipath_get_rwqe(qp, 0))338goto rnr_nak;339break;340341case IB_WR_RDMA_WRITE_WITH_IMM:342if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))343goto inv_err;344wc.wc_flags = IB_WC_WITH_IMM;345wc.ex.imm_data = wqe->wr.ex.imm_data;346if (!ipath_get_rwqe(qp, 1))347goto rnr_nak;348/* FALLTHROUGH */349case IB_WR_RDMA_WRITE:350if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))351goto inv_err;352if (wqe->length == 0)353break;354if (unlikely(!ipath_rkey_ok(qp, &qp->r_sge, wqe->length,355wqe->wr.wr.rdma.remote_addr,356wqe->wr.wr.rdma.rkey,357IB_ACCESS_REMOTE_WRITE)))358goto acc_err;359break;360361case IB_WR_RDMA_READ:362if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ)))363goto inv_err;364if (unlikely(!ipath_rkey_ok(qp, &sqp->s_sge, wqe->length,365wqe->wr.wr.rdma.remote_addr,366wqe->wr.wr.rdma.rkey,367IB_ACCESS_REMOTE_READ)))368goto acc_err;369qp->r_sge.sge = wqe->sg_list[0];370qp->r_sge.sg_list = wqe->sg_list + 1;371qp->r_sge.num_sge = wqe->wr.num_sge;372break;373374case IB_WR_ATOMIC_CMP_AND_SWP:375case IB_WR_ATOMIC_FETCH_AND_ADD:376if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC)))377goto inv_err;378if (unlikely(!ipath_rkey_ok(qp, &qp->r_sge, sizeof(u64),379wqe->wr.wr.atomic.remote_addr,380wqe->wr.wr.atomic.rkey,381IB_ACCESS_REMOTE_ATOMIC)))382goto acc_err;383/* Perform atomic OP and save result. */384maddr = (atomic64_t *) qp->r_sge.sge.vaddr;385sdata = wqe->wr.wr.atomic.compare_add;386*(u64 *) sqp->s_sge.sge.vaddr =387(wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?388(u64) atomic64_add_return(sdata, maddr) - sdata :389(u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,390sdata, wqe->wr.wr.atomic.swap);391goto send_comp;392393default:394send_status = IB_WC_LOC_QP_OP_ERR;395goto serr;396}397398sge = &sqp->s_sge.sge;399while (sqp->s_len) {400u32 len = sqp->s_len;401402if (len > sge->length)403len = sge->length;404if (len > sge->sge_length)405len = sge->sge_length;406BUG_ON(len == 0);407ipath_copy_sge(&qp->r_sge, sge->vaddr, len);408sge->vaddr += len;409sge->length -= len;410sge->sge_length -= len;411if (sge->sge_length == 0) {412if (--sqp->s_sge.num_sge)413*sge = *sqp->s_sge.sg_list++;414} else if (sge->length == 0 && sge->mr != NULL) {415if (++sge->n >= IPATH_SEGSZ) {416if (++sge->m >= sge->mr->mapsz)417break;418sge->n = 0;419}420sge->vaddr =421sge->mr->map[sge->m]->segs[sge->n].vaddr;422sge->length =423sge->mr->map[sge->m]->segs[sge->n].length;424}425sqp->s_len -= len;426}427428if (!test_and_clear_bit(IPATH_R_WRID_VALID, &qp->r_aflags))429goto send_comp;430431if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM)432wc.opcode = IB_WC_RECV_RDMA_WITH_IMM;433else434wc.opcode = IB_WC_RECV;435wc.wr_id = qp->r_wr_id;436wc.status = IB_WC_SUCCESS;437wc.byte_len = wqe->length;438wc.qp = &qp->ibqp;439wc.src_qp = qp->remote_qpn;440wc.slid = qp->remote_ah_attr.dlid;441wc.sl = qp->remote_ah_attr.sl;442wc.port_num = 1;443/* Signal completion event if the solicited bit is set. */444ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc,445wqe->wr.send_flags & IB_SEND_SOLICITED);446447send_comp:448spin_lock_irqsave(&sqp->s_lock, flags);449flush_send:450sqp->s_rnr_retry = sqp->s_rnr_retry_cnt;451ipath_send_complete(sqp, wqe, send_status);452goto again;453454rnr_nak:455/* Handle RNR NAK */456if (qp->ibqp.qp_type == IB_QPT_UC)457goto send_comp;458/*459* Note: we don't need the s_lock held since the BUSY flag460* makes this single threaded.461*/462if (sqp->s_rnr_retry == 0) {463send_status = IB_WC_RNR_RETRY_EXC_ERR;464goto serr;465}466if (sqp->s_rnr_retry_cnt < 7)467sqp->s_rnr_retry--;468spin_lock_irqsave(&sqp->s_lock, flags);469if (!(ib_ipath_state_ops[sqp->state] & IPATH_PROCESS_RECV_OK))470goto clr_busy;471sqp->s_flags |= IPATH_S_WAITING;472dev->n_rnr_naks++;473sqp->s_rnr_timeout = ib_ipath_rnr_table[qp->r_min_rnr_timer];474ipath_insert_rnr_queue(sqp);475goto clr_busy;476477inv_err:478send_status = IB_WC_REM_INV_REQ_ERR;479wc.status = IB_WC_LOC_QP_OP_ERR;480goto err;481482acc_err:483send_status = IB_WC_REM_ACCESS_ERR;484wc.status = IB_WC_LOC_PROT_ERR;485err:486/* responder goes to error state */487ipath_rc_error(qp, wc.status);488489serr:490spin_lock_irqsave(&sqp->s_lock, flags);491ipath_send_complete(sqp, wqe, send_status);492if (sqp->ibqp.qp_type == IB_QPT_RC) {493int lastwqe = ipath_error_qp(sqp, IB_WC_WR_FLUSH_ERR);494495sqp->s_flags &= ~IPATH_S_BUSY;496spin_unlock_irqrestore(&sqp->s_lock, flags);497if (lastwqe) {498struct ib_event ev;499500ev.device = sqp->ibqp.device;501ev.element.qp = &sqp->ibqp;502ev.event = IB_EVENT_QP_LAST_WQE_REACHED;503sqp->ibqp.event_handler(&ev, sqp->ibqp.qp_context);504}505goto done;506}507clr_busy:508sqp->s_flags &= ~IPATH_S_BUSY;509unlock:510spin_unlock_irqrestore(&sqp->s_lock, flags);511done:512if (qp && atomic_dec_and_test(&qp->refcount))513wake_up(&qp->wait);514}515516static void want_buffer(struct ipath_devdata *dd, struct ipath_qp *qp)517{518if (!(dd->ipath_flags & IPATH_HAS_SEND_DMA) ||519qp->ibqp.qp_type == IB_QPT_SMI) {520unsigned long flags;521522spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);523dd->ipath_sendctrl |= INFINIPATH_S_PIOINTBUFAVAIL;524ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,525dd->ipath_sendctrl);526ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);527spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);528}529}530531/**532* ipath_no_bufs_available - tell the layer driver we need buffers533* @qp: the QP that caused the problem534* @dev: the device we ran out of buffers on535*536* Called when we run out of PIO buffers.537* If we are now in the error state, return zero to flush the538* send work request.539*/540static int ipath_no_bufs_available(struct ipath_qp *qp,541struct ipath_ibdev *dev)542{543unsigned long flags;544int ret = 1;545546/*547* Note that as soon as want_buffer() is called and548* possibly before it returns, ipath_ib_piobufavail()549* could be called. Therefore, put QP on the piowait list before550* enabling the PIO avail interrupt.551*/552spin_lock_irqsave(&qp->s_lock, flags);553if (ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK) {554dev->n_piowait++;555qp->s_flags |= IPATH_S_WAITING;556qp->s_flags &= ~IPATH_S_BUSY;557spin_lock(&dev->pending_lock);558if (list_empty(&qp->piowait))559list_add_tail(&qp->piowait, &dev->piowait);560spin_unlock(&dev->pending_lock);561} else562ret = 0;563spin_unlock_irqrestore(&qp->s_lock, flags);564if (ret)565want_buffer(dev->dd, qp);566return ret;567}568569/**570* ipath_make_grh - construct a GRH header571* @dev: a pointer to the ipath device572* @hdr: a pointer to the GRH header being constructed573* @grh: the global route address to send to574* @hwords: the number of 32 bit words of header being sent575* @nwords: the number of 32 bit words of data being sent576*577* Return the size of the header in 32 bit words.578*/579u32 ipath_make_grh(struct ipath_ibdev *dev, struct ib_grh *hdr,580struct ib_global_route *grh, u32 hwords, u32 nwords)581{582hdr->version_tclass_flow =583cpu_to_be32((6 << 28) |584(grh->traffic_class << 20) |585grh->flow_label);586hdr->paylen = cpu_to_be16((hwords - 2 + nwords + SIZE_OF_CRC) << 2);587/* next_hdr is defined by C8-7 in ch. 8.4.1 */588hdr->next_hdr = 0x1B;589hdr->hop_limit = grh->hop_limit;590/* The SGID is 32-bit aligned. */591hdr->sgid.global.subnet_prefix = dev->gid_prefix;592hdr->sgid.global.interface_id = dev->dd->ipath_guid;593hdr->dgid = grh->dgid;594595/* GRH header size in 32-bit words. */596return sizeof(struct ib_grh) / sizeof(u32);597}598599void ipath_make_ruc_header(struct ipath_ibdev *dev, struct ipath_qp *qp,600struct ipath_other_headers *ohdr,601u32 bth0, u32 bth2)602{603u16 lrh0;604u32 nwords;605u32 extra_bytes;606607/* Construct the header. */608extra_bytes = -qp->s_cur_size & 3;609nwords = (qp->s_cur_size + extra_bytes) >> 2;610lrh0 = IPATH_LRH_BTH;611if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {612qp->s_hdrwords += ipath_make_grh(dev, &qp->s_hdr.u.l.grh,613&qp->remote_ah_attr.grh,614qp->s_hdrwords, nwords);615lrh0 = IPATH_LRH_GRH;616}617lrh0 |= qp->remote_ah_attr.sl << 4;618qp->s_hdr.lrh[0] = cpu_to_be16(lrh0);619qp->s_hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);620qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);621qp->s_hdr.lrh[3] = cpu_to_be16(dev->dd->ipath_lid |622qp->remote_ah_attr.src_path_bits);623bth0 |= ipath_get_pkey(dev->dd, qp->s_pkey_index);624bth0 |= extra_bytes << 20;625ohdr->bth[0] = cpu_to_be32(bth0 | (1 << 22));626ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);627ohdr->bth[2] = cpu_to_be32(bth2);628}629630/**631* ipath_do_send - perform a send on a QP632* @data: contains a pointer to the QP633*634* Process entries in the send work queue until credit or queue is635* exhausted. Only allow one CPU to send a packet per QP (tasklet).636* Otherwise, two threads could send packets out of order.637*/638void ipath_do_send(unsigned long data)639{640struct ipath_qp *qp = (struct ipath_qp *)data;641struct ipath_ibdev *dev = to_idev(qp->ibqp.device);642int (*make_req)(struct ipath_qp *qp);643unsigned long flags;644645if ((qp->ibqp.qp_type == IB_QPT_RC ||646qp->ibqp.qp_type == IB_QPT_UC) &&647qp->remote_ah_attr.dlid == dev->dd->ipath_lid) {648ipath_ruc_loopback(qp);649goto bail;650}651652if (qp->ibqp.qp_type == IB_QPT_RC)653make_req = ipath_make_rc_req;654else if (qp->ibqp.qp_type == IB_QPT_UC)655make_req = ipath_make_uc_req;656else657make_req = ipath_make_ud_req;658659spin_lock_irqsave(&qp->s_lock, flags);660661/* Return if we are already busy processing a work request. */662if ((qp->s_flags & (IPATH_S_BUSY | IPATH_S_ANY_WAIT)) ||663!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_OR_FLUSH_SEND)) {664spin_unlock_irqrestore(&qp->s_lock, flags);665goto bail;666}667668qp->s_flags |= IPATH_S_BUSY;669670spin_unlock_irqrestore(&qp->s_lock, flags);671672again:673/* Check for a constructed packet to be sent. */674if (qp->s_hdrwords != 0) {675/*676* If no PIO bufs are available, return. An interrupt will677* call ipath_ib_piobufavail() when one is available.678*/679if (ipath_verbs_send(qp, &qp->s_hdr, qp->s_hdrwords,680qp->s_cur_sge, qp->s_cur_size)) {681if (ipath_no_bufs_available(qp, dev))682goto bail;683}684dev->n_unicast_xmit++;685/* Record that we sent the packet and s_hdr is empty. */686qp->s_hdrwords = 0;687}688689if (make_req(qp))690goto again;691692bail:;693}694695/*696* This should be called with s_lock held.697*/698void ipath_send_complete(struct ipath_qp *qp, struct ipath_swqe *wqe,699enum ib_wc_status status)700{701u32 old_last, last;702703if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_OR_FLUSH_SEND))704return;705706/* See ch. 11.2.4.1 and 10.7.3.1 */707if (!(qp->s_flags & IPATH_S_SIGNAL_REQ_WR) ||708(wqe->wr.send_flags & IB_SEND_SIGNALED) ||709status != IB_WC_SUCCESS) {710struct ib_wc wc;711712memset(&wc, 0, sizeof wc);713wc.wr_id = wqe->wr.wr_id;714wc.status = status;715wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode];716wc.qp = &qp->ibqp;717if (status == IB_WC_SUCCESS)718wc.byte_len = wqe->length;719ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc,720status != IB_WC_SUCCESS);721}722723old_last = last = qp->s_last;724if (++last >= qp->s_size)725last = 0;726qp->s_last = last;727if (qp->s_cur == old_last)728qp->s_cur = last;729if (qp->s_tail == old_last)730qp->s_tail = last;731if (qp->state == IB_QPS_SQD && last == qp->s_cur)732qp->s_draining = 0;733}734735736