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 * Convert the AETH RNR timeout code into the number of microseconds.
43 const u32 ib_qib_rnr_table
[32] = {
44 655360, /* 00: 655.36 */
64 10240, /* 14: 10.24 */
65 15360, /* 15: 15.36 */
66 20480, /* 16: 20.48 */
67 30720, /* 17: 30.72 */
68 40960, /* 18: 40.96 */
69 61440, /* 19: 61.44 */
70 81920, /* 1A: 81.92 */
71 122880, /* 1B: 122.88 */
72 163840, /* 1C: 163.84 */
73 245760, /* 1D: 245.76 */
74 327680, /* 1E: 327.68 */
75 491520 /* 1F: 491.52 */
79 * Validate a RWQE and fill in the SGE state.
82 static int qib_init_sge(struct rvt_qp
*qp
, struct rvt_rwqe
*wqe
)
86 struct rvt_lkey_table
*rkt
;
88 struct rvt_sge_state
*ss
;
90 rkt
= &to_idev(qp
->ibqp
.device
)->rdi
.lkey_table
;
91 pd
= ibpd_to_rvtpd(qp
->ibqp
.srq
? qp
->ibqp
.srq
->pd
: qp
->ibqp
.pd
);
93 ss
->sg_list
= qp
->r_sg_list
;
95 for (i
= j
= 0; i
< wqe
->num_sge
; i
++) {
96 if (wqe
->sg_list
[i
].length
== 0)
99 if (!rvt_lkey_ok(rkt
, pd
, j
? &ss
->sg_list
[j
- 1] : &ss
->sge
,
100 &wqe
->sg_list
[i
], IB_ACCESS_LOCAL_WRITE
))
102 qp
->r_len
+= wqe
->sg_list
[i
].length
;
106 ss
->total_len
= qp
->r_len
;
112 struct rvt_sge
*sge
= --j
? &ss
->sg_list
[j
- 1] : &ss
->sge
;
117 memset(&wc
, 0, sizeof(wc
));
118 wc
.wr_id
= wqe
->wr_id
;
119 wc
.status
= IB_WC_LOC_PROT_ERR
;
120 wc
.opcode
= IB_WC_RECV
;
122 /* Signal solicited completion event. */
123 rvt_cq_enter(ibcq_to_rvtcq(qp
->ibqp
.recv_cq
), &wc
, 1);
130 * qib_get_rwqe - copy the next RWQE into the QP's RWQE
132 * @wr_id_only: update qp->r_wr_id only, not qp->r_sge
134 * Return -1 if there is a local error, 0 if no RWQE is available,
135 * otherwise return 1.
137 * Can be called from interrupt level.
139 int qib_get_rwqe(struct rvt_qp
*qp
, int wr_id_only
)
145 struct rvt_rwqe
*wqe
;
146 void (*handler
)(struct ib_event
*, void *);
151 srq
= ibsrq_to_rvtsrq(qp
->ibqp
.srq
);
152 handler
= srq
->ibsrq
.event_handler
;
160 spin_lock_irqsave(&rq
->lock
, flags
);
161 if (!(ib_rvt_state_ops
[qp
->state
] & RVT_PROCESS_RECV_OK
)) {
168 /* Validate tail before using it since it is user writable. */
169 if (tail
>= rq
->size
)
171 if (unlikely(tail
== wq
->head
)) {
175 /* Make sure entry is read after head index is read. */
177 wqe
= rvt_get_rwqe_ptr(rq
, tail
);
179 * Even though we update the tail index in memory, the verbs
180 * consumer is not supposed to post more entries until a
181 * completion is generated.
183 if (++tail
>= rq
->size
)
186 if (!wr_id_only
&& !qib_init_sge(qp
, wqe
)) {
190 qp
->r_wr_id
= wqe
->wr_id
;
193 set_bit(RVT_R_WRID_VALID
, &qp
->r_aflags
);
198 * Validate head pointer value and compute
199 * the number of remaining WQEs.
205 n
+= rq
->size
- tail
;
208 if (n
< srq
->limit
) {
212 spin_unlock_irqrestore(&rq
->lock
, flags
);
213 ev
.device
= qp
->ibqp
.device
;
214 ev
.element
.srq
= qp
->ibqp
.srq
;
215 ev
.event
= IB_EVENT_SRQ_LIMIT_REACHED
;
216 handler(&ev
, srq
->ibsrq
.srq_context
);
221 spin_unlock_irqrestore(&rq
->lock
, flags
);
227 * Switch to alternate path.
228 * The QP s_lock should be held and interrupts disabled.
230 void qib_migrate_qp(struct rvt_qp
*qp
)
234 qp
->s_mig_state
= IB_MIG_MIGRATED
;
235 qp
->remote_ah_attr
= qp
->alt_ah_attr
;
236 qp
->port_num
= qp
->alt_ah_attr
.port_num
;
237 qp
->s_pkey_index
= qp
->s_alt_pkey_index
;
239 ev
.device
= qp
->ibqp
.device
;
240 ev
.element
.qp
= &qp
->ibqp
;
241 ev
.event
= IB_EVENT_PATH_MIG
;
242 qp
->ibqp
.event_handler(&ev
, qp
->ibqp
.qp_context
);
245 static __be64
get_sguid(struct qib_ibport
*ibp
, unsigned index
)
248 struct qib_pportdata
*ppd
= ppd_from_ibp(ibp
);
252 return ibp
->guids
[index
- 1];
255 static int gid_ok(union ib_gid
*gid
, __be64 gid_prefix
, __be64 id
)
257 return (gid
->global
.interface_id
== id
&&
258 (gid
->global
.subnet_prefix
== gid_prefix
||
259 gid
->global
.subnet_prefix
== IB_DEFAULT_GID_PREFIX
));
264 * This should be called with the QP r_lock held.
266 * The s_lock will be acquired around the qib_migrate_qp() call.
268 int qib_ruc_check_hdr(struct qib_ibport
*ibp
, struct qib_ib_header
*hdr
,
269 int has_grh
, struct rvt_qp
*qp
, u32 bth0
)
274 if (qp
->s_mig_state
== IB_MIG_ARMED
&& (bth0
& IB_BTH_MIG_REQ
)) {
276 if (qp
->alt_ah_attr
.ah_flags
& IB_AH_GRH
)
279 if (!(qp
->alt_ah_attr
.ah_flags
& IB_AH_GRH
))
281 guid
= get_sguid(ibp
, qp
->alt_ah_attr
.grh
.sgid_index
);
282 if (!gid_ok(&hdr
->u
.l
.grh
.dgid
,
283 ibp
->rvp
.gid_prefix
, guid
))
285 if (!gid_ok(&hdr
->u
.l
.grh
.sgid
,
286 qp
->alt_ah_attr
.grh
.dgid
.global
.subnet_prefix
,
287 qp
->alt_ah_attr
.grh
.dgid
.global
.interface_id
))
290 if (!qib_pkey_ok((u16
)bth0
,
291 qib_get_pkey(ibp
, qp
->s_alt_pkey_index
))) {
292 qib_bad_pqkey(ibp
, IB_NOTICE_TRAP_BAD_PKEY
,
294 (be16_to_cpu(hdr
->lrh
[0]) >> 4) & 0xF,
296 hdr
->lrh
[3], hdr
->lrh
[1]);
299 /* Validate the SLID. See Ch. 9.6.1.5 and 17.2.8 */
300 if (be16_to_cpu(hdr
->lrh
[3]) != qp
->alt_ah_attr
.dlid
||
301 ppd_from_ibp(ibp
)->port
!= qp
->alt_ah_attr
.port_num
)
303 spin_lock_irqsave(&qp
->s_lock
, flags
);
305 spin_unlock_irqrestore(&qp
->s_lock
, flags
);
308 if (qp
->remote_ah_attr
.ah_flags
& IB_AH_GRH
)
311 if (!(qp
->remote_ah_attr
.ah_flags
& IB_AH_GRH
))
313 guid
= get_sguid(ibp
,
314 qp
->remote_ah_attr
.grh
.sgid_index
);
315 if (!gid_ok(&hdr
->u
.l
.grh
.dgid
,
316 ibp
->rvp
.gid_prefix
, guid
))
318 if (!gid_ok(&hdr
->u
.l
.grh
.sgid
,
319 qp
->remote_ah_attr
.grh
.dgid
.global
.subnet_prefix
,
320 qp
->remote_ah_attr
.grh
.dgid
.global
.interface_id
))
323 if (!qib_pkey_ok((u16
)bth0
,
324 qib_get_pkey(ibp
, qp
->s_pkey_index
))) {
325 qib_bad_pqkey(ibp
, IB_NOTICE_TRAP_BAD_PKEY
,
327 (be16_to_cpu(hdr
->lrh
[0]) >> 4) & 0xF,
329 hdr
->lrh
[3], hdr
->lrh
[1]);
332 /* Validate the SLID. See Ch. 9.6.1.5 */
333 if (be16_to_cpu(hdr
->lrh
[3]) != qp
->remote_ah_attr
.dlid
||
334 ppd_from_ibp(ibp
)->port
!= qp
->port_num
)
336 if (qp
->s_mig_state
== IB_MIG_REARM
&&
337 !(bth0
& IB_BTH_MIG_REQ
))
338 qp
->s_mig_state
= IB_MIG_ARMED
;
348 * qib_ruc_loopback - handle UC and RC lookback requests
349 * @sqp: the sending QP
351 * This is called from qib_do_send() to
352 * forward a WQE addressed to the same HCA.
353 * Note that although we are single threaded due to the tasklet, we still
354 * have to protect against post_send(). We don't have to worry about
355 * receive interrupts since this is a connected protocol and all packets
356 * will pass through here.
358 static void qib_ruc_loopback(struct rvt_qp
*sqp
)
360 struct qib_ibport
*ibp
= to_iport(sqp
->ibqp
.device
, sqp
->port_num
);
361 struct qib_pportdata
*ppd
= ppd_from_ibp(ibp
);
362 struct qib_devdata
*dd
= ppd
->dd
;
363 struct rvt_dev_info
*rdi
= &dd
->verbs_dev
.rdi
;
365 struct rvt_swqe
*wqe
;
371 enum ib_wc_status send_status
;
377 * Note that we check the responder QP state after
378 * checking the requester's state.
380 qp
= rvt_lookup_qpn(rdi
, &ibp
->rvp
, sqp
->remote_qpn
);
384 spin_lock_irqsave(&sqp
->s_lock
, flags
);
386 /* Return if we are already busy processing a work request. */
387 if ((sqp
->s_flags
& (RVT_S_BUSY
| RVT_S_ANY_WAIT
)) ||
388 !(ib_rvt_state_ops
[sqp
->state
] & RVT_PROCESS_OR_FLUSH_SEND
))
391 sqp
->s_flags
|= RVT_S_BUSY
;
394 smp_read_barrier_depends(); /* see post_one_send() */
395 if (sqp
->s_last
== ACCESS_ONCE(sqp
->s_head
))
397 wqe
= rvt_get_swqe_ptr(sqp
, sqp
->s_last
);
399 /* Return if it is not OK to start a new work reqeust. */
400 if (!(ib_rvt_state_ops
[sqp
->state
] & RVT_PROCESS_NEXT_SEND_OK
)) {
401 if (!(ib_rvt_state_ops
[sqp
->state
] & RVT_FLUSH_SEND
))
403 /* We are in the error state, flush the work request. */
404 send_status
= IB_WC_WR_FLUSH_ERR
;
409 * We can rely on the entry not changing without the s_lock
410 * being held until we update s_last.
411 * We increment s_cur to indicate s_last is in progress.
413 if (sqp
->s_last
== sqp
->s_cur
) {
414 if (++sqp
->s_cur
>= sqp
->s_size
)
417 spin_unlock_irqrestore(&sqp
->s_lock
, flags
);
419 if (!qp
|| !(ib_rvt_state_ops
[qp
->state
] & RVT_PROCESS_RECV_OK
) ||
420 qp
->ibqp
.qp_type
!= sqp
->ibqp
.qp_type
) {
421 ibp
->rvp
.n_pkt_drops
++;
423 * For RC, the requester would timeout and retry so
424 * shortcut the timeouts and just signal too many retries.
426 if (sqp
->ibqp
.qp_type
== IB_QPT_RC
)
427 send_status
= IB_WC_RETRY_EXC_ERR
;
429 send_status
= IB_WC_SUCCESS
;
433 memset(&wc
, 0, sizeof(wc
));
434 send_status
= IB_WC_SUCCESS
;
437 sqp
->s_sge
.sge
= wqe
->sg_list
[0];
438 sqp
->s_sge
.sg_list
= wqe
->sg_list
+ 1;
439 sqp
->s_sge
.num_sge
= wqe
->wr
.num_sge
;
440 sqp
->s_len
= wqe
->length
;
441 switch (wqe
->wr
.opcode
) {
442 case IB_WR_SEND_WITH_IMM
:
443 wc
.wc_flags
= IB_WC_WITH_IMM
;
444 wc
.ex
.imm_data
= wqe
->wr
.ex
.imm_data
;
447 ret
= qib_get_rwqe(qp
, 0);
454 case IB_WR_RDMA_WRITE_WITH_IMM
:
455 if (unlikely(!(qp
->qp_access_flags
& IB_ACCESS_REMOTE_WRITE
)))
457 wc
.wc_flags
= IB_WC_WITH_IMM
;
458 wc
.ex
.imm_data
= wqe
->wr
.ex
.imm_data
;
459 ret
= qib_get_rwqe(qp
, 1);
465 case IB_WR_RDMA_WRITE
:
466 if (unlikely(!(qp
->qp_access_flags
& IB_ACCESS_REMOTE_WRITE
)))
468 if (wqe
->length
== 0)
470 if (unlikely(!rvt_rkey_ok(qp
, &qp
->r_sge
.sge
, wqe
->length
,
471 wqe
->rdma_wr
.remote_addr
,
473 IB_ACCESS_REMOTE_WRITE
)))
475 qp
->r_sge
.sg_list
= NULL
;
476 qp
->r_sge
.num_sge
= 1;
477 qp
->r_sge
.total_len
= wqe
->length
;
480 case IB_WR_RDMA_READ
:
481 if (unlikely(!(qp
->qp_access_flags
& IB_ACCESS_REMOTE_READ
)))
483 if (unlikely(!rvt_rkey_ok(qp
, &sqp
->s_sge
.sge
, wqe
->length
,
484 wqe
->rdma_wr
.remote_addr
,
486 IB_ACCESS_REMOTE_READ
)))
489 sqp
->s_sge
.sg_list
= NULL
;
490 sqp
->s_sge
.num_sge
= 1;
491 qp
->r_sge
.sge
= wqe
->sg_list
[0];
492 qp
->r_sge
.sg_list
= wqe
->sg_list
+ 1;
493 qp
->r_sge
.num_sge
= wqe
->wr
.num_sge
;
494 qp
->r_sge
.total_len
= wqe
->length
;
497 case IB_WR_ATOMIC_CMP_AND_SWP
:
498 case IB_WR_ATOMIC_FETCH_AND_ADD
:
499 if (unlikely(!(qp
->qp_access_flags
& IB_ACCESS_REMOTE_ATOMIC
)))
501 if (unlikely(!rvt_rkey_ok(qp
, &qp
->r_sge
.sge
, sizeof(u64
),
502 wqe
->atomic_wr
.remote_addr
,
504 IB_ACCESS_REMOTE_ATOMIC
)))
506 /* Perform atomic OP and save result. */
507 maddr
= (atomic64_t
*) qp
->r_sge
.sge
.vaddr
;
508 sdata
= wqe
->atomic_wr
.compare_add
;
509 *(u64
*) sqp
->s_sge
.sge
.vaddr
=
510 (wqe
->atomic_wr
.wr
.opcode
== IB_WR_ATOMIC_FETCH_AND_ADD
) ?
511 (u64
) atomic64_add_return(sdata
, maddr
) - sdata
:
512 (u64
) cmpxchg((u64
*) qp
->r_sge
.sge
.vaddr
,
513 sdata
, wqe
->atomic_wr
.swap
);
514 rvt_put_mr(qp
->r_sge
.sge
.mr
);
515 qp
->r_sge
.num_sge
= 0;
519 send_status
= IB_WC_LOC_QP_OP_ERR
;
523 sge
= &sqp
->s_sge
.sge
;
525 u32 len
= sqp
->s_len
;
527 if (len
> sge
->length
)
529 if (len
> sge
->sge_length
)
530 len
= sge
->sge_length
;
532 qib_copy_sge(&qp
->r_sge
, sge
->vaddr
, len
, release
);
535 sge
->sge_length
-= len
;
536 if (sge
->sge_length
== 0) {
539 if (--sqp
->s_sge
.num_sge
)
540 *sge
= *sqp
->s_sge
.sg_list
++;
541 } else if (sge
->length
== 0 && sge
->mr
->lkey
) {
542 if (++sge
->n
>= RVT_SEGSZ
) {
543 if (++sge
->m
>= sge
->mr
->mapsz
)
548 sge
->mr
->map
[sge
->m
]->segs
[sge
->n
].vaddr
;
550 sge
->mr
->map
[sge
->m
]->segs
[sge
->n
].length
;
555 rvt_put_ss(&qp
->r_sge
);
557 if (!test_and_clear_bit(RVT_R_WRID_VALID
, &qp
->r_aflags
))
560 if (wqe
->wr
.opcode
== IB_WR_RDMA_WRITE_WITH_IMM
)
561 wc
.opcode
= IB_WC_RECV_RDMA_WITH_IMM
;
563 wc
.opcode
= IB_WC_RECV
;
564 wc
.wr_id
= qp
->r_wr_id
;
565 wc
.status
= IB_WC_SUCCESS
;
566 wc
.byte_len
= wqe
->length
;
568 wc
.src_qp
= qp
->remote_qpn
;
569 wc
.slid
= qp
->remote_ah_attr
.dlid
;
570 wc
.sl
= qp
->remote_ah_attr
.sl
;
572 /* Signal completion event if the solicited bit is set. */
573 rvt_cq_enter(ibcq_to_rvtcq(qp
->ibqp
.recv_cq
), &wc
,
574 wqe
->wr
.send_flags
& IB_SEND_SOLICITED
);
577 spin_lock_irqsave(&sqp
->s_lock
, flags
);
578 ibp
->rvp
.n_loop_pkts
++;
580 sqp
->s_rnr_retry
= sqp
->s_rnr_retry_cnt
;
581 qib_send_complete(sqp
, wqe
, send_status
);
586 if (qp
->ibqp
.qp_type
== IB_QPT_UC
)
588 ibp
->rvp
.n_rnr_naks
++;
590 * Note: we don't need the s_lock held since the BUSY flag
591 * makes this single threaded.
593 if (sqp
->s_rnr_retry
== 0) {
594 send_status
= IB_WC_RNR_RETRY_EXC_ERR
;
597 if (sqp
->s_rnr_retry_cnt
< 7)
599 spin_lock_irqsave(&sqp
->s_lock
, flags
);
600 if (!(ib_rvt_state_ops
[sqp
->state
] & RVT_PROCESS_RECV_OK
))
602 sqp
->s_flags
|= RVT_S_WAIT_RNR
;
603 sqp
->s_timer
.function
= qib_rc_rnr_retry
;
604 sqp
->s_timer
.expires
= jiffies
+
605 usecs_to_jiffies(ib_qib_rnr_table
[qp
->r_min_rnr_timer
]);
606 add_timer(&sqp
->s_timer
);
610 send_status
= IB_WC_REM_OP_ERR
;
611 wc
.status
= IB_WC_LOC_QP_OP_ERR
;
615 send_status
= IB_WC_REM_INV_REQ_ERR
;
616 wc
.status
= IB_WC_LOC_QP_OP_ERR
;
620 send_status
= IB_WC_REM_ACCESS_ERR
;
621 wc
.status
= IB_WC_LOC_PROT_ERR
;
623 /* responder goes to error state */
624 qib_rc_error(qp
, wc
.status
);
627 spin_lock_irqsave(&sqp
->s_lock
, flags
);
628 qib_send_complete(sqp
, wqe
, send_status
);
629 if (sqp
->ibqp
.qp_type
== IB_QPT_RC
) {
630 int lastwqe
= rvt_error_qp(sqp
, IB_WC_WR_FLUSH_ERR
);
632 sqp
->s_flags
&= ~RVT_S_BUSY
;
633 spin_unlock_irqrestore(&sqp
->s_lock
, flags
);
637 ev
.device
= sqp
->ibqp
.device
;
638 ev
.element
.qp
= &sqp
->ibqp
;
639 ev
.event
= IB_EVENT_QP_LAST_WQE_REACHED
;
640 sqp
->ibqp
.event_handler(&ev
, sqp
->ibqp
.qp_context
);
645 sqp
->s_flags
&= ~RVT_S_BUSY
;
647 spin_unlock_irqrestore(&sqp
->s_lock
, flags
);
653 * qib_make_grh - construct a GRH header
654 * @ibp: a pointer to the IB port
655 * @hdr: a pointer to the GRH header being constructed
656 * @grh: the global route address to send to
657 * @hwords: the number of 32 bit words of header being sent
658 * @nwords: the number of 32 bit words of data being sent
660 * Return the size of the header in 32 bit words.
662 u32
qib_make_grh(struct qib_ibport
*ibp
, struct ib_grh
*hdr
,
663 struct ib_global_route
*grh
, u32 hwords
, u32 nwords
)
665 hdr
->version_tclass_flow
=
666 cpu_to_be32((IB_GRH_VERSION
<< IB_GRH_VERSION_SHIFT
) |
667 (grh
->traffic_class
<< IB_GRH_TCLASS_SHIFT
) |
668 (grh
->flow_label
<< IB_GRH_FLOW_SHIFT
));
669 hdr
->paylen
= cpu_to_be16((hwords
- 2 + nwords
+ SIZE_OF_CRC
) << 2);
670 /* next_hdr is defined by C8-7 in ch. 8.4.1 */
671 hdr
->next_hdr
= IB_GRH_NEXT_HDR
;
672 hdr
->hop_limit
= grh
->hop_limit
;
673 /* The SGID is 32-bit aligned. */
674 hdr
->sgid
.global
.subnet_prefix
= ibp
->rvp
.gid_prefix
;
675 hdr
->sgid
.global
.interface_id
= grh
->sgid_index
?
676 ibp
->guids
[grh
->sgid_index
- 1] : ppd_from_ibp(ibp
)->guid
;
677 hdr
->dgid
= grh
->dgid
;
679 /* GRH header size in 32-bit words. */
680 return sizeof(struct ib_grh
) / sizeof(u32
);
683 void qib_make_ruc_header(struct rvt_qp
*qp
, struct qib_other_headers
*ohdr
,
686 struct qib_qp_priv
*priv
= qp
->priv
;
687 struct qib_ibport
*ibp
= to_iport(qp
->ibqp
.device
, qp
->port_num
);
692 /* Construct the header. */
693 extra_bytes
= -qp
->s_cur_size
& 3;
694 nwords
= (qp
->s_cur_size
+ extra_bytes
) >> 2;
696 if (unlikely(qp
->remote_ah_attr
.ah_flags
& IB_AH_GRH
)) {
697 qp
->s_hdrwords
+= qib_make_grh(ibp
, &priv
->s_hdr
->u
.l
.grh
,
698 &qp
->remote_ah_attr
.grh
,
699 qp
->s_hdrwords
, nwords
);
702 lrh0
|= ibp
->sl_to_vl
[qp
->remote_ah_attr
.sl
] << 12 |
703 qp
->remote_ah_attr
.sl
<< 4;
704 priv
->s_hdr
->lrh
[0] = cpu_to_be16(lrh0
);
705 priv
->s_hdr
->lrh
[1] = cpu_to_be16(qp
->remote_ah_attr
.dlid
);
706 priv
->s_hdr
->lrh
[2] =
707 cpu_to_be16(qp
->s_hdrwords
+ nwords
+ SIZE_OF_CRC
);
708 priv
->s_hdr
->lrh
[3] = cpu_to_be16(ppd_from_ibp(ibp
)->lid
|
709 qp
->remote_ah_attr
.src_path_bits
);
710 bth0
|= qib_get_pkey(ibp
, qp
->s_pkey_index
);
711 bth0
|= extra_bytes
<< 20;
712 if (qp
->s_mig_state
== IB_MIG_MIGRATED
)
713 bth0
|= IB_BTH_MIG_REQ
;
714 ohdr
->bth
[0] = cpu_to_be32(bth0
);
715 ohdr
->bth
[1] = cpu_to_be32(qp
->remote_qpn
);
716 ohdr
->bth
[2] = cpu_to_be32(bth2
);
717 this_cpu_inc(ibp
->pmastats
->n_unicast_xmit
);
720 void _qib_do_send(struct work_struct
*work
)
722 struct qib_qp_priv
*priv
= container_of(work
, struct qib_qp_priv
,
724 struct rvt_qp
*qp
= priv
->owner
;
730 * qib_do_send - perform a send on a QP
731 * @qp: pointer to the QP
733 * Process entries in the send work queue until credit or queue is
734 * exhausted. Only allow one CPU to send a packet per QP (tasklet).
735 * Otherwise, two threads could send packets out of order.
737 void qib_do_send(struct rvt_qp
*qp
)
739 struct qib_qp_priv
*priv
= qp
->priv
;
740 struct qib_ibport
*ibp
= to_iport(qp
->ibqp
.device
, qp
->port_num
);
741 struct qib_pportdata
*ppd
= ppd_from_ibp(ibp
);
742 int (*make_req
)(struct rvt_qp
*qp
);
745 if ((qp
->ibqp
.qp_type
== IB_QPT_RC
||
746 qp
->ibqp
.qp_type
== IB_QPT_UC
) &&
747 (qp
->remote_ah_attr
.dlid
& ~((1 << ppd
->lmc
) - 1)) == ppd
->lid
) {
748 qib_ruc_loopback(qp
);
752 if (qp
->ibqp
.qp_type
== IB_QPT_RC
)
753 make_req
= qib_make_rc_req
;
754 else if (qp
->ibqp
.qp_type
== IB_QPT_UC
)
755 make_req
= qib_make_uc_req
;
757 make_req
= qib_make_ud_req
;
759 spin_lock_irqsave(&qp
->s_lock
, flags
);
761 /* Return if we are already busy processing a work request. */
762 if (!qib_send_ok(qp
)) {
763 spin_unlock_irqrestore(&qp
->s_lock
, flags
);
767 qp
->s_flags
|= RVT_S_BUSY
;
770 /* Check for a constructed packet to be sent. */
771 if (qp
->s_hdrwords
!= 0) {
772 spin_unlock_irqrestore(&qp
->s_lock
, flags
);
774 * If the packet cannot be sent now, return and
775 * the send tasklet will be woken up later.
777 if (qib_verbs_send(qp
, priv
->s_hdr
, qp
->s_hdrwords
,
778 qp
->s_cur_sge
, qp
->s_cur_size
))
780 /* Record that s_hdr is empty. */
782 spin_lock_irqsave(&qp
->s_lock
, flags
);
784 } while (make_req(qp
));
786 spin_unlock_irqrestore(&qp
->s_lock
, flags
);
790 * This should be called with s_lock held.
792 void qib_send_complete(struct rvt_qp
*qp
, struct rvt_swqe
*wqe
,
793 enum ib_wc_status status
)
798 if (!(ib_rvt_state_ops
[qp
->state
] & RVT_PROCESS_OR_FLUSH_SEND
))
803 if (++last
>= qp
->s_size
)
806 /* See post_send() */
808 for (i
= 0; i
< wqe
->wr
.num_sge
; i
++) {
809 struct rvt_sge
*sge
= &wqe
->sg_list
[i
];
813 if (qp
->ibqp
.qp_type
== IB_QPT_UD
||
814 qp
->ibqp
.qp_type
== IB_QPT_SMI
||
815 qp
->ibqp
.qp_type
== IB_QPT_GSI
)
816 atomic_dec(&ibah_to_rvtah(wqe
->ud_wr
.ah
)->refcount
);
818 /* See ch. 11.2.4.1 and 10.7.3.1 */
819 if (!(qp
->s_flags
& RVT_S_SIGNAL_REQ_WR
) ||
820 (wqe
->wr
.send_flags
& IB_SEND_SIGNALED
) ||
821 status
!= IB_WC_SUCCESS
) {
824 memset(&wc
, 0, sizeof(wc
));
825 wc
.wr_id
= wqe
->wr
.wr_id
;
827 wc
.opcode
= ib_qib_wc_opcode
[wqe
->wr
.opcode
];
829 if (status
== IB_WC_SUCCESS
)
830 wc
.byte_len
= wqe
->length
;
831 rvt_cq_enter(ibcq_to_rvtcq(qp
->ibqp
.send_cq
), &wc
,
832 status
!= IB_WC_SUCCESS
);
835 if (qp
->s_acked
== old_last
)
837 if (qp
->s_cur
== old_last
)
839 if (qp
->s_tail
== old_last
)
841 if (qp
->state
== IB_QPS_SQD
&& last
== qp
->s_cur
)