18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
38c2ecf20Sopenharmony_ci * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
68c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
78c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
88c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
98c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
128c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
138c2ecf20Sopenharmony_ci *     conditions are met:
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
168c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
178c2ecf20Sopenharmony_ci *        disclaimer.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
208c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
218c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
228c2ecf20Sopenharmony_ci *        provided with the distribution.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
258c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
268c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
278c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
288c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
298c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
308c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
318c2ecf20Sopenharmony_ci * SOFTWARE.
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
358c2ecf20Sopenharmony_ci#include <rdma/ib_smi.h>
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#include "qib.h"
388c2ecf20Sopenharmony_ci#include "qib_mad.h"
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/*
418c2ecf20Sopenharmony_ci * Switch to alternate path.
428c2ecf20Sopenharmony_ci * The QP s_lock should be held and interrupts disabled.
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_civoid qib_migrate_qp(struct rvt_qp *qp)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	struct ib_event ev;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	qp->s_mig_state = IB_MIG_MIGRATED;
498c2ecf20Sopenharmony_ci	qp->remote_ah_attr = qp->alt_ah_attr;
508c2ecf20Sopenharmony_ci	qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr);
518c2ecf20Sopenharmony_ci	qp->s_pkey_index = qp->s_alt_pkey_index;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	ev.device = qp->ibqp.device;
548c2ecf20Sopenharmony_ci	ev.element.qp = &qp->ibqp;
558c2ecf20Sopenharmony_ci	ev.event = IB_EVENT_PATH_MIG;
568c2ecf20Sopenharmony_ci	qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic __be64 get_sguid(struct qib_ibport *ibp, unsigned index)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	if (!index) {
628c2ecf20Sopenharmony_ci		struct qib_pportdata *ppd = ppd_from_ibp(ibp);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci		return ppd->guid;
658c2ecf20Sopenharmony_ci	}
668c2ecf20Sopenharmony_ci	return ibp->guids[index - 1];
678c2ecf20Sopenharmony_ci}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic int gid_ok(union ib_gid *gid, __be64 gid_prefix, __be64 id)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	return (gid->global.interface_id == id &&
728c2ecf20Sopenharmony_ci		(gid->global.subnet_prefix == gid_prefix ||
738c2ecf20Sopenharmony_ci		 gid->global.subnet_prefix == IB_DEFAULT_GID_PREFIX));
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/*
778c2ecf20Sopenharmony_ci *
788c2ecf20Sopenharmony_ci * This should be called with the QP r_lock held.
798c2ecf20Sopenharmony_ci *
808c2ecf20Sopenharmony_ci * The s_lock will be acquired around the qib_migrate_qp() call.
818c2ecf20Sopenharmony_ci */
828c2ecf20Sopenharmony_ciint qib_ruc_check_hdr(struct qib_ibport *ibp, struct ib_header *hdr,
838c2ecf20Sopenharmony_ci		      int has_grh, struct rvt_qp *qp, u32 bth0)
848c2ecf20Sopenharmony_ci{
858c2ecf20Sopenharmony_ci	__be64 guid;
868c2ecf20Sopenharmony_ci	unsigned long flags;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	if (qp->s_mig_state == IB_MIG_ARMED && (bth0 & IB_BTH_MIG_REQ)) {
898c2ecf20Sopenharmony_ci		if (!has_grh) {
908c2ecf20Sopenharmony_ci			if (rdma_ah_get_ah_flags(&qp->alt_ah_attr) &
918c2ecf20Sopenharmony_ci			    IB_AH_GRH)
928c2ecf20Sopenharmony_ci				goto err;
938c2ecf20Sopenharmony_ci		} else {
948c2ecf20Sopenharmony_ci			const struct ib_global_route *grh;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci			if (!(rdma_ah_get_ah_flags(&qp->alt_ah_attr) &
978c2ecf20Sopenharmony_ci			      IB_AH_GRH))
988c2ecf20Sopenharmony_ci				goto err;
998c2ecf20Sopenharmony_ci			grh = rdma_ah_read_grh(&qp->alt_ah_attr);
1008c2ecf20Sopenharmony_ci			guid = get_sguid(ibp, grh->sgid_index);
1018c2ecf20Sopenharmony_ci			if (!gid_ok(&hdr->u.l.grh.dgid,
1028c2ecf20Sopenharmony_ci				    ibp->rvp.gid_prefix, guid))
1038c2ecf20Sopenharmony_ci				goto err;
1048c2ecf20Sopenharmony_ci			if (!gid_ok(&hdr->u.l.grh.sgid,
1058c2ecf20Sopenharmony_ci			    grh->dgid.global.subnet_prefix,
1068c2ecf20Sopenharmony_ci			    grh->dgid.global.interface_id))
1078c2ecf20Sopenharmony_ci				goto err;
1088c2ecf20Sopenharmony_ci		}
1098c2ecf20Sopenharmony_ci		if (!qib_pkey_ok((u16)bth0,
1108c2ecf20Sopenharmony_ci				 qib_get_pkey(ibp, qp->s_alt_pkey_index))) {
1118c2ecf20Sopenharmony_ci			qib_bad_pkey(ibp,
1128c2ecf20Sopenharmony_ci				     (u16)bth0,
1138c2ecf20Sopenharmony_ci				     (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF,
1148c2ecf20Sopenharmony_ci				     0, qp->ibqp.qp_num,
1158c2ecf20Sopenharmony_ci				     hdr->lrh[3], hdr->lrh[1]);
1168c2ecf20Sopenharmony_ci			goto err;
1178c2ecf20Sopenharmony_ci		}
1188c2ecf20Sopenharmony_ci		/* Validate the SLID. See Ch. 9.6.1.5 and 17.2.8 */
1198c2ecf20Sopenharmony_ci		if ((be16_to_cpu(hdr->lrh[3]) !=
1208c2ecf20Sopenharmony_ci		     rdma_ah_get_dlid(&qp->alt_ah_attr)) ||
1218c2ecf20Sopenharmony_ci		    ppd_from_ibp(ibp)->port !=
1228c2ecf20Sopenharmony_ci			    rdma_ah_get_port_num(&qp->alt_ah_attr))
1238c2ecf20Sopenharmony_ci			goto err;
1248c2ecf20Sopenharmony_ci		spin_lock_irqsave(&qp->s_lock, flags);
1258c2ecf20Sopenharmony_ci		qib_migrate_qp(qp);
1268c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&qp->s_lock, flags);
1278c2ecf20Sopenharmony_ci	} else {
1288c2ecf20Sopenharmony_ci		if (!has_grh) {
1298c2ecf20Sopenharmony_ci			if (rdma_ah_get_ah_flags(&qp->remote_ah_attr) &
1308c2ecf20Sopenharmony_ci			    IB_AH_GRH)
1318c2ecf20Sopenharmony_ci				goto err;
1328c2ecf20Sopenharmony_ci		} else {
1338c2ecf20Sopenharmony_ci			const struct ib_global_route *grh;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci			if (!(rdma_ah_get_ah_flags(&qp->remote_ah_attr) &
1368c2ecf20Sopenharmony_ci			      IB_AH_GRH))
1378c2ecf20Sopenharmony_ci				goto err;
1388c2ecf20Sopenharmony_ci			grh = rdma_ah_read_grh(&qp->remote_ah_attr);
1398c2ecf20Sopenharmony_ci			guid = get_sguid(ibp, grh->sgid_index);
1408c2ecf20Sopenharmony_ci			if (!gid_ok(&hdr->u.l.grh.dgid,
1418c2ecf20Sopenharmony_ci				    ibp->rvp.gid_prefix, guid))
1428c2ecf20Sopenharmony_ci				goto err;
1438c2ecf20Sopenharmony_ci			if (!gid_ok(&hdr->u.l.grh.sgid,
1448c2ecf20Sopenharmony_ci			    grh->dgid.global.subnet_prefix,
1458c2ecf20Sopenharmony_ci			    grh->dgid.global.interface_id))
1468c2ecf20Sopenharmony_ci				goto err;
1478c2ecf20Sopenharmony_ci		}
1488c2ecf20Sopenharmony_ci		if (!qib_pkey_ok((u16)bth0,
1498c2ecf20Sopenharmony_ci				 qib_get_pkey(ibp, qp->s_pkey_index))) {
1508c2ecf20Sopenharmony_ci			qib_bad_pkey(ibp,
1518c2ecf20Sopenharmony_ci				     (u16)bth0,
1528c2ecf20Sopenharmony_ci				     (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF,
1538c2ecf20Sopenharmony_ci				     0, qp->ibqp.qp_num,
1548c2ecf20Sopenharmony_ci				     hdr->lrh[3], hdr->lrh[1]);
1558c2ecf20Sopenharmony_ci			goto err;
1568c2ecf20Sopenharmony_ci		}
1578c2ecf20Sopenharmony_ci		/* Validate the SLID. See Ch. 9.6.1.5 */
1588c2ecf20Sopenharmony_ci		if (be16_to_cpu(hdr->lrh[3]) !=
1598c2ecf20Sopenharmony_ci		    rdma_ah_get_dlid(&qp->remote_ah_attr) ||
1608c2ecf20Sopenharmony_ci		    ppd_from_ibp(ibp)->port != qp->port_num)
1618c2ecf20Sopenharmony_ci			goto err;
1628c2ecf20Sopenharmony_ci		if (qp->s_mig_state == IB_MIG_REARM &&
1638c2ecf20Sopenharmony_ci		    !(bth0 & IB_BTH_MIG_REQ))
1648c2ecf20Sopenharmony_ci			qp->s_mig_state = IB_MIG_ARMED;
1658c2ecf20Sopenharmony_ci	}
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	return 0;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cierr:
1708c2ecf20Sopenharmony_ci	return 1;
1718c2ecf20Sopenharmony_ci}
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/**
1748c2ecf20Sopenharmony_ci * qib_make_grh - construct a GRH header
1758c2ecf20Sopenharmony_ci * @ibp: a pointer to the IB port
1768c2ecf20Sopenharmony_ci * @hdr: a pointer to the GRH header being constructed
1778c2ecf20Sopenharmony_ci * @grh: the global route address to send to
1788c2ecf20Sopenharmony_ci * @hwords: the number of 32 bit words of header being sent
1798c2ecf20Sopenharmony_ci * @nwords: the number of 32 bit words of data being sent
1808c2ecf20Sopenharmony_ci *
1818c2ecf20Sopenharmony_ci * Return the size of the header in 32 bit words.
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_ciu32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
1848c2ecf20Sopenharmony_ci		 const struct ib_global_route *grh, u32 hwords, u32 nwords)
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	hdr->version_tclass_flow =
1878c2ecf20Sopenharmony_ci		cpu_to_be32((IB_GRH_VERSION << IB_GRH_VERSION_SHIFT) |
1888c2ecf20Sopenharmony_ci			    (grh->traffic_class << IB_GRH_TCLASS_SHIFT) |
1898c2ecf20Sopenharmony_ci			    (grh->flow_label << IB_GRH_FLOW_SHIFT));
1908c2ecf20Sopenharmony_ci	hdr->paylen = cpu_to_be16((hwords - 2 + nwords + SIZE_OF_CRC) << 2);
1918c2ecf20Sopenharmony_ci	/* next_hdr is defined by C8-7 in ch. 8.4.1 */
1928c2ecf20Sopenharmony_ci	hdr->next_hdr = IB_GRH_NEXT_HDR;
1938c2ecf20Sopenharmony_ci	hdr->hop_limit = grh->hop_limit;
1948c2ecf20Sopenharmony_ci	/* The SGID is 32-bit aligned. */
1958c2ecf20Sopenharmony_ci	hdr->sgid.global.subnet_prefix = ibp->rvp.gid_prefix;
1968c2ecf20Sopenharmony_ci	if (!grh->sgid_index)
1978c2ecf20Sopenharmony_ci		hdr->sgid.global.interface_id = ppd_from_ibp(ibp)->guid;
1988c2ecf20Sopenharmony_ci	else if (grh->sgid_index < QIB_GUIDS_PER_PORT)
1998c2ecf20Sopenharmony_ci		hdr->sgid.global.interface_id = ibp->guids[grh->sgid_index - 1];
2008c2ecf20Sopenharmony_ci	hdr->dgid = grh->dgid;
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	/* GRH header size in 32-bit words. */
2038c2ecf20Sopenharmony_ci	return sizeof(struct ib_grh) / sizeof(u32);
2048c2ecf20Sopenharmony_ci}
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_civoid qib_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
2078c2ecf20Sopenharmony_ci			 u32 bth0, u32 bth2)
2088c2ecf20Sopenharmony_ci{
2098c2ecf20Sopenharmony_ci	struct qib_qp_priv *priv = qp->priv;
2108c2ecf20Sopenharmony_ci	struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
2118c2ecf20Sopenharmony_ci	u16 lrh0;
2128c2ecf20Sopenharmony_ci	u32 nwords;
2138c2ecf20Sopenharmony_ci	u32 extra_bytes;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	/* Construct the header. */
2168c2ecf20Sopenharmony_ci	extra_bytes = -qp->s_cur_size & 3;
2178c2ecf20Sopenharmony_ci	nwords = (qp->s_cur_size + extra_bytes) >> 2;
2188c2ecf20Sopenharmony_ci	lrh0 = QIB_LRH_BTH;
2198c2ecf20Sopenharmony_ci	if (unlikely(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH)) {
2208c2ecf20Sopenharmony_ci		qp->s_hdrwords +=
2218c2ecf20Sopenharmony_ci			qib_make_grh(ibp, &priv->s_hdr->u.l.grh,
2228c2ecf20Sopenharmony_ci				     rdma_ah_read_grh(&qp->remote_ah_attr),
2238c2ecf20Sopenharmony_ci				     qp->s_hdrwords, nwords);
2248c2ecf20Sopenharmony_ci		lrh0 = QIB_LRH_GRH;
2258c2ecf20Sopenharmony_ci	}
2268c2ecf20Sopenharmony_ci	lrh0 |= ibp->sl_to_vl[rdma_ah_get_sl(&qp->remote_ah_attr)] << 12 |
2278c2ecf20Sopenharmony_ci		rdma_ah_get_sl(&qp->remote_ah_attr) << 4;
2288c2ecf20Sopenharmony_ci	priv->s_hdr->lrh[0] = cpu_to_be16(lrh0);
2298c2ecf20Sopenharmony_ci	priv->s_hdr->lrh[1] =
2308c2ecf20Sopenharmony_ci			cpu_to_be16(rdma_ah_get_dlid(&qp->remote_ah_attr));
2318c2ecf20Sopenharmony_ci	priv->s_hdr->lrh[2] =
2328c2ecf20Sopenharmony_ci			cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
2338c2ecf20Sopenharmony_ci	priv->s_hdr->lrh[3] =
2348c2ecf20Sopenharmony_ci		cpu_to_be16(ppd_from_ibp(ibp)->lid |
2358c2ecf20Sopenharmony_ci			    rdma_ah_get_path_bits(&qp->remote_ah_attr));
2368c2ecf20Sopenharmony_ci	bth0 |= qib_get_pkey(ibp, qp->s_pkey_index);
2378c2ecf20Sopenharmony_ci	bth0 |= extra_bytes << 20;
2388c2ecf20Sopenharmony_ci	if (qp->s_mig_state == IB_MIG_MIGRATED)
2398c2ecf20Sopenharmony_ci		bth0 |= IB_BTH_MIG_REQ;
2408c2ecf20Sopenharmony_ci	ohdr->bth[0] = cpu_to_be32(bth0);
2418c2ecf20Sopenharmony_ci	ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
2428c2ecf20Sopenharmony_ci	ohdr->bth[2] = cpu_to_be32(bth2);
2438c2ecf20Sopenharmony_ci	this_cpu_inc(ibp->pmastats->n_unicast_xmit);
2448c2ecf20Sopenharmony_ci}
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_civoid _qib_do_send(struct work_struct *work)
2478c2ecf20Sopenharmony_ci{
2488c2ecf20Sopenharmony_ci	struct qib_qp_priv *priv = container_of(work, struct qib_qp_priv,
2498c2ecf20Sopenharmony_ci						s_work);
2508c2ecf20Sopenharmony_ci	struct rvt_qp *qp = priv->owner;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	qib_do_send(qp);
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci/**
2568c2ecf20Sopenharmony_ci * qib_do_send - perform a send on a QP
2578c2ecf20Sopenharmony_ci * @qp: pointer to the QP
2588c2ecf20Sopenharmony_ci *
2598c2ecf20Sopenharmony_ci * Process entries in the send work queue until credit or queue is
2608c2ecf20Sopenharmony_ci * exhausted.  Only allow one CPU to send a packet per QP (tasklet).
2618c2ecf20Sopenharmony_ci * Otherwise, two threads could send packets out of order.
2628c2ecf20Sopenharmony_ci */
2638c2ecf20Sopenharmony_civoid qib_do_send(struct rvt_qp *qp)
2648c2ecf20Sopenharmony_ci{
2658c2ecf20Sopenharmony_ci	struct qib_qp_priv *priv = qp->priv;
2668c2ecf20Sopenharmony_ci	struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
2678c2ecf20Sopenharmony_ci	struct qib_pportdata *ppd = ppd_from_ibp(ibp);
2688c2ecf20Sopenharmony_ci	int (*make_req)(struct rvt_qp *qp, unsigned long *flags);
2698c2ecf20Sopenharmony_ci	unsigned long flags;
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	if ((qp->ibqp.qp_type == IB_QPT_RC ||
2728c2ecf20Sopenharmony_ci	     qp->ibqp.qp_type == IB_QPT_UC) &&
2738c2ecf20Sopenharmony_ci	    (rdma_ah_get_dlid(&qp->remote_ah_attr) &
2748c2ecf20Sopenharmony_ci	     ~((1 << ppd->lmc) - 1)) == ppd->lid) {
2758c2ecf20Sopenharmony_ci		rvt_ruc_loopback(qp);
2768c2ecf20Sopenharmony_ci		return;
2778c2ecf20Sopenharmony_ci	}
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	if (qp->ibqp.qp_type == IB_QPT_RC)
2808c2ecf20Sopenharmony_ci		make_req = qib_make_rc_req;
2818c2ecf20Sopenharmony_ci	else if (qp->ibqp.qp_type == IB_QPT_UC)
2828c2ecf20Sopenharmony_ci		make_req = qib_make_uc_req;
2838c2ecf20Sopenharmony_ci	else
2848c2ecf20Sopenharmony_ci		make_req = qib_make_ud_req;
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	spin_lock_irqsave(&qp->s_lock, flags);
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	/* Return if we are already busy processing a work request. */
2898c2ecf20Sopenharmony_ci	if (!qib_send_ok(qp)) {
2908c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&qp->s_lock, flags);
2918c2ecf20Sopenharmony_ci		return;
2928c2ecf20Sopenharmony_ci	}
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	qp->s_flags |= RVT_S_BUSY;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	do {
2978c2ecf20Sopenharmony_ci		/* Check for a constructed packet to be sent. */
2988c2ecf20Sopenharmony_ci		if (qp->s_hdrwords != 0) {
2998c2ecf20Sopenharmony_ci			spin_unlock_irqrestore(&qp->s_lock, flags);
3008c2ecf20Sopenharmony_ci			/*
3018c2ecf20Sopenharmony_ci			 * If the packet cannot be sent now, return and
3028c2ecf20Sopenharmony_ci			 * the send tasklet will be woken up later.
3038c2ecf20Sopenharmony_ci			 */
3048c2ecf20Sopenharmony_ci			if (qib_verbs_send(qp, priv->s_hdr, qp->s_hdrwords,
3058c2ecf20Sopenharmony_ci					   qp->s_cur_sge, qp->s_cur_size))
3068c2ecf20Sopenharmony_ci				return;
3078c2ecf20Sopenharmony_ci			/* Record that s_hdr is empty. */
3088c2ecf20Sopenharmony_ci			qp->s_hdrwords = 0;
3098c2ecf20Sopenharmony_ci			spin_lock_irqsave(&qp->s_lock, flags);
3108c2ecf20Sopenharmony_ci		}
3118c2ecf20Sopenharmony_ci	} while (make_req(qp, &flags));
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&qp->s_lock, flags);
3148c2ecf20Sopenharmony_ci}
315