/* * Note that it is OK to post send work requests in the SQE and ERR * states; rvt_do_send() will process them and generate error * completions as per IB 1.2 C10-96.
*/ constint ib_rvt_state_ops[IB_QPS_ERR + 1] = {
[IB_QPS_RESET] = 0,
[IB_QPS_INIT] = RVT_POST_RECV_OK,
[IB_QPS_RTR] = RVT_POST_RECV_OK | RVT_PROCESS_RECV_OK,
[IB_QPS_RTS] = RVT_POST_RECV_OK | RVT_PROCESS_RECV_OK |
RVT_POST_SEND_OK | RVT_PROCESS_SEND_OK |
RVT_PROCESS_NEXT_SEND_OK,
[IB_QPS_SQD] = RVT_POST_RECV_OK | RVT_PROCESS_RECV_OK |
RVT_POST_SEND_OK | RVT_PROCESS_SEND_OK,
[IB_QPS_SQE] = RVT_POST_RECV_OK | RVT_PROCESS_RECV_OK |
RVT_POST_SEND_OK | RVT_FLUSH_SEND,
[IB_QPS_ERR] = RVT_POST_RECV_OK | RVT_FLUSH_RECV |
RVT_POST_SEND_OK | RVT_FLUSH_SEND,
};
EXPORT_SYMBOL(ib_rvt_state_ops);
/* platform specific: return the last level cache (llc) size, in KiB */ staticint rvt_wss_llc_size(void)
{ /* assume that the boot CPU value is universal for all CPUs */ return boot_cpu_data.x86_cache_size;
}
/* platform specific: cacheless copy */ staticvoid cacheless_memcpy(void *dst, void *src, size_t n)
{ /* * Use the only available X64 cacheless copy. Add a __user cast * to quiet sparse. The src agument is already in the kernel so * there are no security issues. The extra fault recovery machinery * is not invoked.
*/
__copy_user_nocache(dst, (void __user *)src, n);
}
/* check for a valid percent range - default to 80 if none or invalid */ if (wss_threshold < 1 || wss_threshold > 100)
wss_threshold = 80;
/* reject a wildly large period */ if (wss_clean_period > 1000000)
wss_clean_period = 256;
/* reject a zero period */ if (wss_clean_period == 0)
wss_clean_period = 1;
/* * Calculate the table size - the next power of 2 larger than the * LLC size. LLC size is in KiB.
*/
llc_size = rvt_wss_llc_size() * 1024;
table_size = roundup_pow_of_two(llc_size);
/* one bit per page in rounded up table */
llc_bits = llc_size / PAGE_SIZE;
table_bits = table_size / PAGE_SIZE;
wss->pages_mask = table_bits - 1;
wss->num_entries = table_bits / BITS_PER_LONG;
/* * Advance the clean counter. When the clean period has expired, * clean an entry. * * This is implemented in atomics to avoid locking. Because multiple * variables are involved, it can be racy which can lead to slightly * inaccurate information. Since this is only a heuristic, this is * OK. Any innaccuracies will clean themselves out as the counter * advances. That said, it is unlikely the entry clean operation will * race - the next possible racer will not start until the next clean * period. * * The clean counter is implemented as a decrement to zero. When zero * is reached an entry is cleaned.
*/ staticvoid wss_advance_clean_counter(struct rvt_wss *wss)
{ int entry; int weight; unsignedlong bits;
/* become the cleaner if we decrement the counter to zero */ if (atomic_dec_and_test(&wss->clean_counter)) { /* * Set, not add, the clean period. This avoids an issue * where the counter could decrement below the clean period. * Doing a set can result in lost decrements, slowing the * clean advance. Since this a heuristic, this possible * slowdown is OK. * * An alternative is to loop, advancing the counter by a * clean period until the result is > 0. However, this could * lead to several threads keeping another in the clean loop. * This could be mitigated by limiting the number of times * we stay in the loop.
*/
atomic_set(&wss->clean_counter, wss->clean_period);
/* * Uniquely grab the entry to clean and move to next. * The current entry is always the lower bits of * wss.clean_entry. The table size, wss.num_entries, * is always a power-of-2.
*/
entry = (atomic_inc_return(&wss->clean_entry) - 1)
& (wss->num_entries - 1);
/* clear the entry and count the bits */
bits = xchg(&wss->entries[entry], 0);
weight = hweight64((u64)bits); /* only adjust the contended total count if needed */ if (weight)
atomic_sub(weight, &wss->total_count);
}
}
/* * Insert the given address into the working set array.
*/ staticvoid wss_insert(struct rvt_wss *wss, void *address)
{
u32 page = ((unsignedlong)address >> PAGE_SHIFT) & wss->pages_mask;
u32 entry = page / BITS_PER_LONG; /* assumes this ends up a shift */
u32 nr = page & (BITS_PER_LONG - 1);
if (!test_and_set_bit(nr, &wss->entries[entry]))
atomic_inc(&wss->total_count);
wss_advance_clean_counter(wss);
}
/* * Is the working set larger than the threshold?
*/ staticinlinebool wss_exceeds_threshold(struct rvt_wss *wss)
{ return atomic_read(&wss->total_count) >= wss->threshold;
}
/* * Drivers may want some QPs beyond what we need for verbs let them use * our qpn table. No need for two. Lets go ahead and mark the bitmaps * for those. The reserved range must be *after* the range which verbs * will pick from.
*/
/* Figure out number of bit maps needed before reserved range */
qpt->nmaps = rdi->dparms.qpn_res_start / RVT_BITS_PER_PAGE;
/* This should always be zero */
offset = rdi->dparms.qpn_res_start & RVT_BITS_PER_PAGE_MASK;
/* Starting with the first reserved bit map */
map = &qpt->map[qpt->nmaps];
rvt_pr_info(rdi, "Reserving QPNs from 0x%x to 0x%x for non-verbs use\n",
rdi->dparms.qpn_res_start, rdi->dparms.qpn_res_end); for (i = rdi->dparms.qpn_res_start; i <= rdi->dparms.qpn_res_end; i++) { if (!map->page) {
get_map_page(qpt, map); if (!map->page) {
ret = -ENOMEM; break;
}
}
set_bit(offset, map->page);
offset++; if (offset == RVT_BITS_PER_PAGE) { /* next page */
qpt->nmaps++;
map++;
offset = 0;
}
} return ret;
}
/** * free_qpn_table - free the QP number table for a device * @qpt: the QPN table
*/ staticvoid free_qpn_table(struct rvt_qpn_table *qpt)
{ int i;
for (i = 0; i < ARRAY_SIZE(qpt->map); i++)
free_page((unsignedlong)qpt->map[i].page);
}
/** * rvt_driver_qp_init - Init driver qp resources * @rdi: rvt dev strucutre * * Return: 0 on success
*/ int rvt_driver_qp_init(struct rvt_dev_info *rdi)
{ int i; int ret = -ENOMEM;
if (!rdi->dparms.qp_table_size) return -EINVAL;
/* * If driver is not doing any QP allocation then make sure it is * providing the necessary QP functions.
*/ if (!rdi->driver_f.free_all_qps ||
!rdi->driver_f.qp_priv_alloc ||
!rdi->driver_f.qp_priv_free ||
!rdi->driver_f.notify_qp_reset ||
!rdi->driver_f.notify_restart_rc) return -EINVAL;
/** * rvt_free_qp_cb - callback function to reset a qp * @qp: the qp to reset * @v: a 64-bit value * * This function resets the qp and removes it from the * qp hash table.
*/ staticvoid rvt_free_qp_cb(struct rvt_qp *qp, u64 v)
{ unsignedint *qp_inuse = (unsignedint *)v; struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device);
/* Reset the qp and remove it from the qp hash list */
rvt_reset_qp(rdi, qp, qp->ibqp.qp_type);
/* Increment the qp_inuse count */
(*qp_inuse)++;
}
/** * rvt_free_all_qps - check for QPs still in use * @rdi: rvt device info structure * * There should not be any QPs still in use. * Free memory for table. * Return the number of QPs still in use.
*/ staticunsigned rvt_free_all_qps(struct rvt_dev_info *rdi)
{ unsignedint qp_inuse = 0;
qp_inuse += rvt_mcast_tree_empty(rdi);
rvt_qp_iter(rdi, (u64)&qp_inuse, rvt_free_qp_cb);
return qp_inuse;
}
/** * rvt_qp_exit - clean up qps on device exit * @rdi: rvt dev structure * * Check for qp leaks and free resources.
*/ void rvt_qp_exit(struct rvt_dev_info *rdi)
{
u32 qps_inuse = rvt_free_all_qps(rdi);
if (qps_inuse)
rvt_pr_err(rdi, "QP memory leak! %u still in use\n",
qps_inuse);
/** * alloc_qpn - Allocate the next available qpn or zero/one for QP type * IB_QPT_SMI/IB_QPT_GSI * @rdi: rvt device info structure * @qpt: queue pair number table pointer * @type: the QP type * @port_num: IB port number, 1 based, comes from core * @exclude_prefix: prefix of special queue pair number being allocated * * Return: The queue pair number
*/ staticint alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt, enum ib_qp_type type, u8 port_num, u8 exclude_prefix)
{
u32 i, offset, max_scan, qpn; struct rvt_qpn_map *map;
u32 ret;
u32 max_qpn = exclude_prefix == RVT_AIP_QP_PREFIX ?
RVT_AIP_QPN_MAX : RVT_QPN_MAX;
if (rdi->driver_f.alloc_qpn) return rdi->driver_f.alloc_qpn(rdi, qpt, type, port_num);
if (type == IB_QPT_SMI || type == IB_QPT_GSI) { unsigned n;
ret = type == IB_QPT_GSI;
n = 1 << (ret + 2 * (port_num - 1));
spin_lock(&qpt->lock); if (qpt->flags & n)
ret = -EINVAL; else
qpt->flags |= n;
spin_unlock(&qpt->lock); goto bail;
}
qpn = qpt->last + qpt->incr; if (qpn >= max_qpn)
qpn = qpt->incr | ((qpt->last & 1) ^ 1); /* offset carries bit 0 */
offset = qpn & RVT_BITS_PER_PAGE_MASK;
map = &qpt->map[qpn / RVT_BITS_PER_PAGE];
max_scan = qpt->nmaps - !offset; for (i = 0;;) { if (unlikely(!map->page)) {
get_map_page(qpt, map); if (unlikely(!map->page)) break;
} do { if (!test_and_set_bit(offset, map->page)) {
qpt->last = qpn;
ret = qpn; goto bail;
}
offset += qpt->incr; /* * This qpn might be bogus if offset >= BITS_PER_PAGE. * That is OK. It gets re-assigned below
*/
qpn = mk_qpn(qpt, map, offset);
} while (offset < RVT_BITS_PER_PAGE && qpn < RVT_QPN_MAX); /* * In order to keep the number of pages allocated to a * minimum, we scan the all existing pages before increasing * the size of the bitmap table.
*/ if (++i > max_scan) { if (qpt->nmaps == RVT_QPNMAP_ENTRIES) break;
map = &qpt->map[qpt->nmaps++]; /* start at incr with current bit 0 */
offset = qpt->incr | (offset & 1);
} elseif (map < &qpt->map[qpt->nmaps]) {
++map; /* start at incr with current bit 0 */
offset = qpt->incr | (offset & 1);
} else {
map = &qpt->map[0]; /* wrap to first map page, invert bit 0 */
offset = qpt->incr | ((offset & 1) ^ 1);
} /* there can be no set bits in low-order QoS bits */
WARN_ON(rdi->dparms.qos_shift > 1 &&
offset & ((BIT(rdi->dparms.qos_shift - 1) - 1) << 1));
qpn = mk_qpn(qpt, map, offset);
}
ret = -ENOMEM;
bail: return ret;
}
/** * rvt_clear_mr_refs - Drop help mr refs * @qp: rvt qp data structure * @clr_sends: If shoudl clear send side or not
*/ staticvoid rvt_clear_mr_refs(struct rvt_qp *qp, int clr_sends)
{ unsigned n; struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device);
if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags))
rvt_put_ss(&qp->s_rdma_read_sge);
rvt_put_ss(&qp->r_sge);
if (clr_sends) { while (qp->s_last != qp->s_head) { struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_last);
rvt_put_qp_swqe(qp, wqe); if (++qp->s_last >= qp->s_size)
qp->s_last = 0;
smp_wmb(); /* see qp_set_savail */
} if (qp->s_rdma_mr) {
rvt_put_mr(qp->s_rdma_mr);
qp->s_rdma_mr = NULL;
}
}
for (n = 0; qp->s_ack_queue && n < rvt_max_atomic(rdi); n++) { struct rvt_ack_entry *e = &qp->s_ack_queue[n];
if (e->rdma_sge.mr) {
rvt_put_mr(e->rdma_sge.mr);
e->rdma_sge.mr = NULL;
}
}
}
/** * rvt_swqe_has_lkey - return true if lkey is used by swqe * @wqe: the send wqe * @lkey: the lkey * * Test the swqe for using lkey
*/ staticbool rvt_swqe_has_lkey(struct rvt_swqe *wqe, u32 lkey)
{ int i;
for (i = 0; i < wqe->wr.num_sge; i++) { struct rvt_sge *sge = &wqe->sg_list[i];
if (rvt_mr_has_lkey(sge->mr, lkey)) returntrue;
} returnfalse;
}
/** * rvt_qp_sends_has_lkey - return true is qp sends use lkey * @qp: the rvt_qp * @lkey: the lkey
*/ staticbool rvt_qp_sends_has_lkey(struct rvt_qp *qp, u32 lkey)
{
u32 s_last = qp->s_last;
if (++s_last >= qp->s_size)
s_last = 0;
} if (qp->s_rdma_mr) if (rvt_mr_has_lkey(qp->s_rdma_mr, lkey)) returntrue; returnfalse;
}
/** * rvt_qp_acks_has_lkey - return true if acks have lkey * @qp: the qp * @lkey: the lkey
*/ staticbool rvt_qp_acks_has_lkey(struct rvt_qp *qp, u32 lkey)
{ int i; struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device);
for (i = 0; qp->s_ack_queue && i < rvt_max_atomic(rdi); i++) { struct rvt_ack_entry *e = &qp->s_ack_queue[i];
if (rvt_mr_has_lkey(e->rdma_sge.mr, lkey)) returntrue;
} returnfalse;
}
/** * rvt_qp_mr_clean - clean up remote ops for lkey * @qp: the qp * @lkey: the lkey that is being de-registered * * This routine checks if the lkey is being used by * the qp. * * If so, the qp is put into an error state to elminate * any references from the qp.
*/ void rvt_qp_mr_clean(struct rvt_qp *qp, u32 lkey)
{ bool lastwqe = false;
if (qp->ibqp.qp_type == IB_QPT_SMI ||
qp->ibqp.qp_type == IB_QPT_GSI) /* avoid special QPs */ return;
spin_lock_irq(&qp->r_lock);
spin_lock(&qp->s_hlock);
spin_lock(&qp->s_lock);
if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET) goto check_lwqe;
/** * rvt_remove_qp - remove qp form table * @rdi: rvt dev struct * @qp: qp to remove * * Remove the QP from the table so it can't be found asynchronously by * the receive routine.
*/ staticvoid rvt_remove_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp)
{ struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1];
u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits); unsignedlong flags; int removed = 1;
spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags); if (removed) {
synchronize_rcu();
rvt_put_qp(qp);
}
}
/** * rvt_alloc_rq - allocate memory for user or kernel buffer * @rq: receive queue data structure * @size: number of request queue entries * @node: The NUMA node * @udata: True if user data is available or not false * * Return: If memory allocation failed, return -ENONEM * This function is used by both shared receive * queues and non-shared receive queues to allocate * memory.
*/ int rvt_alloc_rq(struct rvt_rq *rq, u32 size, int node, struct ib_udata *udata)
{ if (udata) {
rq->wq = vmalloc_user(sizeof(struct rvt_rwq) + size); if (!rq->wq) goto bail; /* need kwq with no buffers */
rq->kwq = kzalloc_node(sizeof(*rq->kwq), GFP_KERNEL, node); if (!rq->kwq) goto bail;
rq->kwq->curr_wq = rq->wq->wq;
} else { /* need kwq with buffers */
rq->kwq =
vzalloc_node(sizeof(struct rvt_krwq) + size, node); if (!rq->kwq) goto bail;
rq->kwq->curr_wq = rq->kwq->wq;
}
/** * rvt_init_qp - initialize the QP state to the reset state * @rdi: rvt dev struct * @qp: the QP to init or reinit * @type: the QP type * * This function is called from both rvt_create_qp() and * rvt_reset_qp(). The difference is that the reset * patch the necessary locks to protect against concurent * access.
*/ staticvoid rvt_init_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, enum ib_qp_type type)
{
qp->remote_qpn = 0;
qp->qkey = 0;
qp->qp_access_flags = 0;
qp->s_flags &= RVT_S_SIGNAL_REQ_WR;
qp->s_hdrwords = 0;
qp->s_wqe = NULL;
qp->s_draining = 0;
qp->s_next_psn = 0;
qp->s_last_psn = 0;
qp->s_sending_psn = 0;
qp->s_sending_hpsn = 0;
qp->s_psn = 0;
qp->r_psn = 0;
qp->r_msn = 0; if (type == IB_QPT_RC) {
qp->s_state = IB_OPCODE_RC_SEND_LAST;
qp->r_state = IB_OPCODE_RC_SEND_LAST;
} else {
qp->s_state = IB_OPCODE_UC_SEND_LAST;
qp->r_state = IB_OPCODE_UC_SEND_LAST;
}
qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
qp->r_nak_state = 0;
qp->r_aflags = 0;
qp->r_flags = 0;
qp->s_head = 0;
qp->s_tail = 0;
qp->s_cur = 0;
qp->s_acked = 0;
qp->s_last = 0;
qp->s_ssn = 1;
qp->s_lsn = 0;
qp->s_mig_state = IB_MIG_MIGRATED;
qp->r_head_ack_queue = 0;
qp->s_tail_ack_queue = 0;
qp->s_acked_ack_queue = 0;
qp->s_num_rd_atomic = 0;
qp->r_sge.num_sge = 0;
atomic_set(&qp->s_reserved_used, 0);
}
/** * _rvt_reset_qp - initialize the QP state to the reset state * @rdi: rvt dev struct * @qp: the QP to reset * @type: the QP type * * r_lock, s_hlock, and s_lock are required to be held by the caller
*/ staticvoid _rvt_reset_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, enum ib_qp_type type)
__must_hold(&qp->s_lock)
__must_hold(&qp->s_hlock)
__must_hold(&qp->r_lock)
{
lockdep_assert_held(&qp->r_lock);
lockdep_assert_held(&qp->s_hlock);
lockdep_assert_held(&qp->s_lock); if (qp->state != IB_QPS_RESET) {
qp->state = IB_QPS_RESET;
/* Let drivers flush their waitlist */
rdi->driver_f.flush_qp_waiters(qp);
rvt_stop_rc_timers(qp);
qp->s_flags &= ~(RVT_S_TIMER | RVT_S_ANY_WAIT);
spin_unlock(&qp->s_lock);
spin_unlock(&qp->s_hlock);
spin_unlock_irq(&qp->r_lock);
/* Stop the send queue and the retry timer */
rdi->driver_f.stop_send_queue(qp);
rvt_del_timers_sync(qp); /* Wait for things to stop */
rdi->driver_f.quiesce_qp(qp);
/* take qp out the hash and wait for it to be unused */
rvt_remove_qp(rdi, qp);
/* grab the lock b/c it was locked at call time */
spin_lock_irq(&qp->r_lock);
spin_lock(&qp->s_hlock);
spin_lock(&qp->s_lock);
rvt_clear_mr_refs(qp, 1); /* * Let the driver do any tear down or re-init it needs to for * a qp that has been reset
*/
rdi->driver_f.notify_qp_reset(qp);
}
rvt_init_qp(rdi, qp, type);
lockdep_assert_held(&qp->r_lock);
lockdep_assert_held(&qp->s_hlock);
lockdep_assert_held(&qp->s_lock);
}
/** * rvt_reset_qp - initialize the QP state to the reset state * @rdi: the device info * @qp: the QP to reset * @type: the QP type * * This is the wrapper function to acquire the r_lock, s_hlock, and s_lock * before calling _rvt_reset_qp().
*/ staticvoid rvt_reset_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, enum ib_qp_type type)
{
spin_lock_irq(&qp->r_lock);
spin_lock(&qp->s_hlock);
spin_lock(&qp->s_lock);
_rvt_reset_qp(rdi, qp, type);
spin_unlock(&qp->s_lock);
spin_unlock(&qp->s_hlock);
spin_unlock_irq(&qp->r_lock);
}
/** * rvt_free_qpn - Free a qpn from the bit map * @qpt: QP table * @qpn: queue pair number to free
*/ staticvoid rvt_free_qpn(struct rvt_qpn_table *qpt, u32 qpn)
{ struct rvt_qpn_map *map;
if ((qpn & RVT_AIP_QP_PREFIX_MASK) == RVT_AIP_QP_BASE)
qpn &= RVT_AIP_QP_SUFFIX;
/** * get_allowed_ops - Given a QP type return the appropriate allowed OP * @type: valid, supported, QP type
*/ static u8 get_allowed_ops(enum ib_qp_type type)
{ return type == IB_QPT_RC ? IB_OPCODE_RC : type == IB_QPT_UC ?
IB_OPCODE_UC : IB_OPCODE_UD;
}
/** * free_ud_wq_attr - Clean up AH attribute cache for UD QPs * @qp: Valid QP with allowed_ops set * * The rvt_swqe data structure being used is a union, so this is * only valid for UD QPs.
*/ staticvoid free_ud_wq_attr(struct rvt_qp *qp)
{ struct rvt_swqe *wqe; int i;
for (i = 0; qp->allowed_ops == IB_OPCODE_UD && i < qp->s_size; i++) {
wqe = rvt_get_swqe_ptr(qp, i);
kfree(wqe->ud_wr.attr);
wqe->ud_wr.attr = NULL;
}
}
/** * alloc_ud_wq_attr - AH attribute cache for UD QPs * @qp: Valid QP with allowed_ops set * @node: Numa node for allocation * * The rvt_swqe data structure being used is a union, so this is * only valid for UD QPs.
*/ staticint alloc_ud_wq_attr(struct rvt_qp *qp, int node)
{ struct rvt_swqe *wqe; int i;
for (i = 0; qp->allowed_ops == IB_OPCODE_UD && i < qp->s_size; i++) {
wqe = rvt_get_swqe_ptr(qp, i);
wqe->ud_wr.attr = kzalloc_node(sizeof(*wqe->ud_wr.attr),
GFP_KERNEL, node); if (!wqe->ud_wr.attr) {
free_ud_wq_attr(qp); return -ENOMEM;
}
}
return 0;
}
/** * rvt_create_qp - create a queue pair for a device * @ibqp: the queue pair * @init_attr: the attributes of the queue pair * @udata: user data for libibverbs.so * * Queue pair creation is mostly an rvt issue. However, drivers have their own * unique idea of what queue pair numbers mean. For instance there is a reserved * range for PSM. * * Return: 0 on success, otherwise returns an errno. * * Called by the ib_create_qp() core verbs function.
*/ int rvt_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init_attr, struct ib_udata *udata)
{ struct rvt_qp *qp = ibqp_to_rvtqp(ibqp); int ret = -ENOMEM; struct rvt_swqe *swq = NULL;
size_t sz;
size_t sg_list_sz = 0; struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); void *priv = NULL;
size_t sqsize;
u8 exclude_prefix = 0;
if (!rdi) return -EINVAL;
if (init_attr->create_flags & ~IB_QP_CREATE_NETDEV_USE) return -EOPNOTSUPP;
if (init_attr->cap.max_send_sge > rdi->dparms.props.max_send_sge ||
init_attr->cap.max_send_wr > rdi->dparms.props.max_qp_wr) return -EINVAL;
/* Check receive queue parameters if no SRQ is specified. */ if (!init_attr->srq) { if (init_attr->cap.max_recv_sge >
rdi->dparms.props.max_recv_sge ||
init_attr->cap.max_recv_wr > rdi->dparms.props.max_qp_wr) return -EINVAL;
if (init_attr->cap.max_send_sge +
init_attr->cap.max_send_wr +
init_attr->cap.max_recv_sge +
init_attr->cap.max_recv_wr == 0) return -EINVAL;
}
sqsize =
init_attr->cap.max_send_wr + 1 +
rdi->dparms.reserved_operations; switch (init_attr->qp_type) { case IB_QPT_SMI: case IB_QPT_GSI: if (init_attr->port_num == 0 ||
init_attr->port_num > ibqp->device->phys_port_cnt) return -EINVAL;
fallthrough; case IB_QPT_UC: case IB_QPT_RC: case IB_QPT_UD:
sz = struct_size(swq, sg_list, init_attr->cap.max_send_sge);
swq = vzalloc_node(array_size(sz, sqsize), rdi->dparms.node); if (!swq) return -ENOMEM;
if (init_attr->srq) { struct rvt_srq *srq = ibsrq_to_rvtsrq(init_attr->srq);
/* * Driver needs to set up it's private QP structure and do any * initialization that is needed.
*/
priv = rdi->driver_f.qp_priv_alloc(rdi, qp); if (IS_ERR(priv)) {
ret = PTR_ERR(priv); goto bail_qp;
}
qp->priv = priv;
qp->timeout_jiffies =
usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
1000UL); if (init_attr->srq) {
sz = 0;
} else {
qp->r_rq.size = init_attr->cap.max_recv_wr + 1;
qp->r_rq.max_sge = init_attr->cap.max_recv_sge;
sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) + sizeof(struct rvt_rwqe);
ret = rvt_alloc_rq(&qp->r_rq, qp->r_rq.size * sz,
rdi->dparms.node, udata); if (ret) goto bail_driver_priv;
}
/* * ib_create_qp() will initialize qp->ibqp * except for qp->ibqp.qp_num.
*/
spin_lock_init(&qp->r_lock);
spin_lock_init(&qp->s_hlock);
spin_lock_init(&qp->s_lock);
atomic_set(&qp->refcount, 0);
atomic_set(&qp->local_ops_pending, 0);
init_waitqueue_head(&qp->wait);
INIT_LIST_HEAD(&qp->rspwait);
qp->state = IB_QPS_RESET;
qp->s_wq = swq;
qp->s_size = sqsize;
qp->s_avail = init_attr->cap.max_send_wr;
qp->s_max_sge = init_attr->cap.max_send_sge; if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR)
qp->s_flags = RVT_S_SIGNAL_REQ_WR;
ret = alloc_ud_wq_attr(qp, rdi->dparms.node); if (ret) goto bail_rq_rvt;
if (init_attr->create_flags & IB_QP_CREATE_NETDEV_USE)
exclude_prefix = RVT_AIP_QP_PREFIX;
ret = alloc_qpn(rdi, &rdi->qp_dev->qpn_table,
init_attr->qp_type,
init_attr->port_num,
exclude_prefix); if (ret < 0) goto bail_rq_wq;
qp->ibqp.qp_num = ret; if (init_attr->create_flags & IB_QP_CREATE_NETDEV_USE)
qp->ibqp.qp_num |= RVT_AIP_QP_BASE;
qp->port_num = init_attr->port_num;
rvt_init_qp(rdi, qp, init_attr->qp_type); if (rdi->driver_f.qp_priv_init) {
ret = rdi->driver_f.qp_priv_init(rdi, qp, init_attr); if (ret) goto bail_rq_wq;
} break;
default: /* Don't support raw QPs */ return -EOPNOTSUPP;
}
init_attr->cap.max_inline_data = 0;
/* * Return the address of the RWQ as the offset to mmap. * See rvt_mmap() for details.
*/ if (udata && udata->outlen >= sizeof(__u64)) { if (!qp->r_rq.wq) {
__u64 offset = 0;
ret = ib_copy_to_udata(udata, &offset, sizeof(offset)); if (ret) goto bail_qpn;
} else {
u32 s = sizeof(struct rvt_rwq) + qp->r_rq.size * sz;
qp->ip = rvt_create_mmap_info(rdi, s, udata,
qp->r_rq.wq); if (IS_ERR(qp->ip)) {
ret = PTR_ERR(qp->ip); goto bail_qpn;
}
ret = ib_copy_to_udata(udata, &qp->ip->offset, sizeof(qp->ip->offset)); if (ret) goto bail_ip;
}
qp->pid = current->pid;
}
spin_lock(&rdi->n_qps_lock); if (rdi->n_qps_allocated == rdi->dparms.props.max_qp) {
spin_unlock(&rdi->n_qps_lock);
ret = -ENOMEM; goto bail_ip;
}
rdi->n_qps_allocated++; /* * Maintain a busy_jiffies variable that will be added to the timeout * period in mod_retry_timer and add_retry_timer. This busy jiffies * is scaled by the number of rc qps created for the device to reduce * the number of timeouts occurring when there is a large number of * qps. busy_jiffies is incremented every rc qp scaling interval. * The scaling interval is selected based on extensive performance * evaluation of targeted workloads.
*/ if (init_attr->qp_type == IB_QPT_RC) {
rdi->n_rc_qps++;
rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL;
}
spin_unlock(&rdi->n_qps_lock);
if (qp->ip) {
spin_lock_irq(&rdi->pending_lock);
list_add(&qp->ip->pending_mmaps, &rdi->pending_mmaps);
spin_unlock_irq(&rdi->pending_lock);
}
return 0;
bail_ip: if (qp->ip)
kref_put(&qp->ip->ref, rvt_release_mmap_info);
/** * rvt_error_qp - put a QP into the error state * @qp: the QP to put into the error state * @err: the receive completion error to signal if a RWQE is active * * Flushes both send and receive work queues. * * Return: true if last WQE event should be generated. * The QP r_lock and s_lock should be held and interrupts disabled. * If we are already in error state, just return.
*/ int rvt_error_qp(struct rvt_qp *qp, enum ib_wc_status err)
{ struct ib_wc wc; int ret = 0; struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device);
spin_lock(&qp->r_rq.kwq->c_lock); /* qp->ip used to validate if there is a user buffer mmaped */ if (qp->ip) {
wq = qp->r_rq.wq;
head = RDMA_READ_UAPI_ATOMIC(wq->head);
tail = RDMA_READ_UAPI_ATOMIC(wq->tail);
} else {
kwq = qp->r_rq.kwq;
head = kwq->head;
tail = kwq->tail;
} /* sanity check pointers before trusting them */ if (head >= qp->r_rq.size)
head = 0; if (tail >= qp->r_rq.size)
tail = 0; while (tail != head) {
wc.wr_id = rvt_get_rwqe_ptr(&qp->r_rq, tail)->wr_id; if (++tail >= qp->r_rq.size)
tail = 0;
rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
} if (qp->ip)
RDMA_WRITE_UAPI_ATOMIC(wq->tail, tail); else
kwq->tail = tail;
spin_unlock(&qp->r_rq.kwq->c_lock);
} elseif (qp->ibqp.event_handler) {
ret = 1;
}
bail: return ret;
}
EXPORT_SYMBOL(rvt_error_qp);
/* * Put the QP into the hash table. * The hash table holds a reference to the QP.
*/ staticvoid rvt_insert_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp)
{ struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; unsignedlong flags;
/** * rvt_modify_qp - modify the attributes of a queue pair * @ibqp: the queue pair who's attributes we're modifying * @attr: the new attributes * @attr_mask: the mask of attributes to modify * @udata: user data for libibverbs.so * * Return: 0 on success, otherwise returns an errno.
*/ int rvt_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask, struct ib_udata *udata)
{ struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); struct rvt_qp *qp = ibqp_to_rvtqp(ibqp); enum ib_qp_state cur_state, new_state; struct ib_event ev; int lastwqe = 0; int mig = 0; int pmtu = 0; /* for gcc warning only */ int opa_ah;
if (attr_mask & ~IB_QP_ATTR_STANDARD_BITS) return -EOPNOTSUPP;
if (attr_mask & IB_QP_DEST_QPN) if (attr->dest_qp_num > RVT_QPN_MASK) goto inval;
if (attr_mask & IB_QP_RETRY_CNT) if (attr->retry_cnt > 7) goto inval;
if (attr_mask & IB_QP_RNR_RETRY) if (attr->rnr_retry > 7) goto inval;
/* * Don't allow invalid path_mtu values. OK to set greater * than the active mtu (or even the max_cap, if we have tuned * that to a small mtu. We'll set qp->path_mtu * to the lesser of requested attribute mtu and active, * for packetizing messages. * Note that the QP port has to be set in INIT and MTU in RTR.
*/ if (attr_mask & IB_QP_PATH_MTU) {
pmtu = rdi->driver_f.get_pmtu_from_attr(rdi, qp, attr); if (pmtu < 0) goto inval;
}
if (attr_mask & IB_QP_PATH_MIG_STATE) { if (attr->path_mig_state == IB_MIG_REARM) { if (qp->s_mig_state == IB_MIG_ARMED) goto inval; if (new_state != IB_QPS_RTS) goto inval;
} elseif (attr->path_mig_state == IB_MIG_MIGRATED) { if (qp->s_mig_state == IB_MIG_REARM) goto inval; if (new_state != IB_QPS_RTS && new_state != IB_QPS_SQD) goto inval; if (qp->s_mig_state == IB_MIG_ARMED)
mig = 1;
} else { goto inval;
}
}
if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) if (attr->max_dest_rd_atomic > rdi->dparms.max_rdma_atomic) goto inval;
switch (new_state) { case IB_QPS_RESET: if (qp->state != IB_QPS_RESET)
_rvt_reset_qp(rdi, qp, ibqp->qp_type); break;
case IB_QPS_RTR: /* Allow event to re-trigger if QP set to RTR more than once */
qp->r_flags &= ~RVT_R_COMM_EST;
qp->state = new_state; break;
/** * rvt_destroy_qp - destroy a queue pair * @ibqp: the queue pair to destroy * @udata: unused by the driver * * Note that this can be called while the QP is actively sending or * receiving! * * Return: 0 on success.
*/ int rvt_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
{ struct rvt_qp *qp = ibqp_to_rvtqp(ibqp); struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device);
rvt_reset_qp(rdi, qp, ibqp->qp_type);
wait_event(qp->wait, !atomic_read(&qp->refcount)); /* qpn is now available for use again */
rvt_free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num);
/** * rvt_post_recv - post a receive on a QP * @ibqp: the QP to post the receive on * @wr: the WR to post * @bad_wr: the first bad WR is put here * * This may be called from interrupt context. * * Return: 0 on success otherwise errno
*/ int rvt_post_recv(struct ib_qp *ibqp, conststruct ib_recv_wr *wr, conststruct ib_recv_wr **bad_wr)
{ struct rvt_qp *qp = ibqp_to_rvtqp(ibqp); struct rvt_krwq *wq = qp->r_rq.kwq; unsignedlong flags; int qp_err_flush = (ib_rvt_state_ops[qp->state] & RVT_FLUSH_RECV) &&
!qp->ibqp.srq;
/* Check that state is OK to post receive. */ if (!(ib_rvt_state_ops[qp->state] & RVT_POST_RECV_OK) || !wq) {
*bad_wr = wr; return -EINVAL;
}
for (; wr; wr = wr->next) { struct rvt_rwqe *wqe;
u32 next; int i;
spin_lock_irqsave(&qp->r_rq.kwq->p_lock, flags);
next = wq->head + 1; if (next >= qp->r_rq.size)
next = 0; if (next == READ_ONCE(wq->tail)) {
spin_unlock_irqrestore(&qp->r_rq.kwq->p_lock, flags);
*bad_wr = wr; return -ENOMEM;
} if (unlikely(qp_err_flush)) { struct ib_wc wc;
memset(&wc, 0, sizeof(wc));
wc.qp = &qp->ibqp;
wc.opcode = IB_WC_RECV;
wc.wr_id = wr->wr_id;
wc.status = IB_WC_WR_FLUSH_ERR;
rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
} else {
wqe = rvt_get_rwqe_ptr(&qp->r_rq, wq->head);
wqe->wr_id = wr->wr_id;
wqe->num_sge = wr->num_sge; for (i = 0; i < wr->num_sge; i++) {
wqe->sg_list[i].addr = wr->sg_list[i].addr;
wqe->sg_list[i].length = wr->sg_list[i].length;
wqe->sg_list[i].lkey = wr->sg_list[i].lkey;
} /* * Make sure queue entry is written * before the head index.
*/
smp_store_release(&wq->head, next);
}
spin_unlock_irqrestore(&qp->r_rq.kwq->p_lock, flags);
} return 0;
}
/** * rvt_qp_valid_operation - validate post send wr request * @qp: the qp * @post_parms: the post send table for the driver * @wr: the work request * * The routine validates the operation based on the * validation table an returns the length of the operation * which can extend beyond the ib_send_bw. Operation * dependent flags key atomic operation validation. * * There is an exception for UD qps that validates the pd and * overrides the length to include the additional UD specific * length. * * Returns a negative error or the length of the work request * for building the swqe.
*/ staticinlineint rvt_qp_valid_operation( struct rvt_qp *qp, conststruct rvt_operation_params *post_parms, conststruct ib_send_wr *wr)
{ int len;
if (wr->opcode >= RVT_OPERATION_MAX || !post_parms[wr->opcode].length) return -EINVAL; if (!(post_parms[wr->opcode].qpt_support & BIT(qp->ibqp.qp_type))) return -EINVAL; if ((post_parms[wr->opcode].flags & RVT_OPERATION_PRIV) &&
ibpd_to_rvtpd(qp->ibqp.pd)->user) return -EINVAL; if (post_parms[wr->opcode].flags & RVT_OPERATION_ATOMIC_SGE &&
(wr->num_sge == 0 ||
wr->sg_list[0].length < sizeof(u64) ||
wr->sg_list[0].addr & (sizeof(u64) - 1))) return -EINVAL; if (post_parms[wr->opcode].flags & RVT_OPERATION_ATOMIC &&
!qp->s_max_rd_atomic) return -EINVAL;
len = post_parms[wr->opcode].length; /* UD specific */ if (qp->ibqp.qp_type != IB_QPT_UC &&
qp->ibqp.qp_type != IB_QPT_RC) { if (qp->ibqp.pd != ud_wr(wr)->ah->pd) return -EINVAL;
len = sizeof(struct ib_ud_wr);
} return len;
}
/** * rvt_qp_is_avail - determine queue capacity * @qp: the qp * @rdi: the rdmavt device * @reserved_op: is reserved operation * * This assumes the s_hlock is held but the s_last * qp variable is uncontrolled. * * For non reserved operations, the qp->s_avail * may be changed. * * The return value is zero or a -ENOMEM.
*/ staticinlineint rvt_qp_is_avail( struct rvt_qp *qp, struct rvt_dev_info *rdi, bool reserved_op)
{
u32 slast;
u32 avail;
u32 reserved_used;
/* see rvt_qp_wqe_unreserve() */
smp_mb__before_atomic(); if (unlikely(reserved_op)) { /* see rvt_qp_wqe_unreserve() */
reserved_used = atomic_read(&qp->s_reserved_used); if (reserved_used >= rdi->dparms.reserved_operations) return -ENOMEM; return 0;
} /* non-reserved operations */ if (likely(qp->s_avail)) return 0; /* See rvt_qp_complete_swqe() */
slast = smp_load_acquire(&qp->s_last); if (qp->s_head >= slast)
avail = qp->s_size - (qp->s_head - slast); else
avail = slast - qp->s_head;
/** * rvt_post_one_wr - post one RC, UC, or UD send work request * @qp: the QP to post on * @wr: the work request to send * @call_send: kick the send engine into gear
*/ staticint rvt_post_one_wr(struct rvt_qp *qp, conststruct ib_send_wr *wr, bool *call_send)
{ struct rvt_swqe *wqe;
u32 next; int i; int j; int acc; struct rvt_lkey_table *rkt; struct rvt_pd *pd; struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device);
u8 log_pmtu; int ret;
size_t cplen; bool reserved_op; int local_ops_delayed = 0;
/* IB spec says that num_sge == 0 is OK. */ if (unlikely(wr->num_sge > qp->s_max_sge)) return -EINVAL;
ret = rvt_qp_valid_operation(qp, rdi->post_parms, wr); if (ret < 0) return ret;
cplen = ret;
/* * Local operations include fast register and local invalidate. * Fast register needs to be processed immediately because the * registered lkey may be used by following work requests and the * lkey needs to be valid at the time those requests are posted. * Local invalidate can be processed immediately if fencing is * not required and no previous local invalidate ops are pending. * Signaled local operations that have been processed immediately * need to have requests with "completion only" flags set posted * to the send queue in order to generate completions.
*/ if ((rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL)) { switch (wr->opcode) { case IB_WR_REG_MR:
ret = rvt_fast_reg_mr(qp,
reg_wr(wr)->mr,
reg_wr(wr)->key,
reg_wr(wr)->access); if (ret || !(wr->send_flags & IB_SEND_SIGNALED)) return ret; break; case IB_WR_LOCAL_INV: if ((wr->send_flags & IB_SEND_FENCE) ||
atomic_read(&qp->local_ops_pending)) {
local_ops_delayed = 1;
} else {
ret = rvt_invalidate_rkey(
qp, wr->ex.invalidate_rkey); if (ret || !(wr->send_flags & IB_SEND_SIGNALED)) return ret;
} break; default: return -EINVAL;
}
}
reserved_op = rdi->post_parms[wr->opcode].flags &
RVT_OPERATION_USE_RESERVE; /* check for avail */
ret = rvt_qp_is_avail(qp, rdi, reserved_op); if (ret) return ret;
next = qp->s_head + 1; if (next >= qp->s_size)
next = 0;
acc = wr->opcode >= IB_WR_RDMA_READ ?
IB_ACCESS_LOCAL_WRITE : 0; for (i = 0; i < wr->num_sge; i++) {
u32 length = wr->sg_list[i].length;
if (length == 0) continue;
ret = rvt_lkey_ok(rkt, pd, &wqe->sg_list[j], last_sge,
&wr->sg_list[i], acc); if (unlikely(ret < 0)) goto bail_inval_free;
wqe->length += length; if (ret)
last_sge = &wqe->sg_list[j];
j += ret;
}
wqe->wr.num_sge = j;
}
/* * Calculate and set SWQE PSN values prior to handing it off * to the driver's check routine. This give the driver the * opportunity to adjust PSN values based on internal checks.
*/
log_pmtu = qp->log_pmtu; if (qp->allowed_ops == IB_OPCODE_UD) { struct rvt_ah *ah = rvt_get_swqe_ah(wqe);
/* general part of wqe valid - allow for driver checks */ if (rdi->driver_f.setup_wqe) {
ret = rdi->driver_f.setup_wqe(qp, wqe, call_send); if (ret < 0) goto bail_inval_free_ref;
}
if (!(rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL))
qp->s_next_psn = wqe->lpsn + 1;
bail_inval_free_ref: if (qp->allowed_ops == IB_OPCODE_UD)
rdma_destroy_ah_attr(wqe->ud_wr.attr);
bail_inval_free: /* release mr holds */ while (j) { struct rvt_sge *sge = &wqe->sg_list[--j];
rvt_put_mr(sge->mr);
} return ret;
}
/** * rvt_post_send - post a send on a QP * @ibqp: the QP to post the send on * @wr: the list of work requests to post * @bad_wr: the first bad WR is put here * * This may be called from interrupt context. * * Return: 0 on success else errno
*/ int rvt_post_send(struct ib_qp *ibqp, conststruct ib_send_wr *wr, conststruct ib_send_wr **bad_wr)
{ struct rvt_qp *qp = ibqp_to_rvtqp(ibqp); struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); unsignedlong flags = 0; bool call_send; unsigned nreq = 0; int err = 0;
spin_lock_irqsave(&qp->s_hlock, flags);
/* * Ensure QP state is such that we can send. If not bail out early, * there is no need to do this every time we post a send.
*/ if (unlikely(!(ib_rvt_state_ops[qp->state] & RVT_POST_SEND_OK))) {
spin_unlock_irqrestore(&qp->s_hlock, flags); return -EINVAL;
}
/* * If the send queue is empty, and we only have a single WR then just go * ahead and kick the send engine into gear. Otherwise we will always * just schedule the send to happen later.
*/
call_send = qp->s_head == READ_ONCE(qp->s_last) && !wr->next;
for (; wr; wr = wr->next) {
err = rvt_post_one_wr(qp, wr, &call_send); if (unlikely(err)) {
*bad_wr = wr; goto bail;
}
nreq++;
}
bail:
spin_unlock_irqrestore(&qp->s_hlock, flags); if (nreq) { /* * Only call do_send if there is exactly one packet, and the * driver said it was ok.
*/ if (nreq == 1 && call_send)
rdi->driver_f.do_send(qp); else
rdi->driver_f.schedule_send_no_lock(qp);
} return err;
}
/** * rvt_post_srq_recv - post a receive on a shared receive queue * @ibsrq: the SRQ to post the receive on * @wr: the list of work requests to post * @bad_wr: A pointer to the first WR to cause a problem is put here * * This may be called from interrupt context. * * Return: 0 on success else errno
*/ int rvt_post_srq_recv(struct ib_srq *ibsrq, conststruct ib_recv_wr *wr, conststruct ib_recv_wr **bad_wr)
{ struct rvt_srq *srq = ibsrq_to_rvtsrq(ibsrq); struct rvt_krwq *wq; unsignedlong flags;
for (; wr; wr = wr->next) { struct rvt_rwqe *wqe;
u32 next; int i;
spin_lock_irqsave(&srq->rq.kwq->p_lock, flags);
wq = srq->rq.kwq;
next = wq->head + 1; if (next >= srq->rq.size)
next = 0; if (next == READ_ONCE(wq->tail)) {
spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags);
*bad_wr = wr; return -ENOMEM;
}
wqe = rvt_get_rwqe_ptr(&srq->rq, wq->head);
wqe->wr_id = wr->wr_id;
wqe->num_sge = wr->num_sge; for (i = 0; i < wr->num_sge; i++) {
wqe->sg_list[i].addr = wr->sg_list[i].addr;
wqe->sg_list[i].length = wr->sg_list[i].length;
wqe->sg_list[i].lkey = wr->sg_list[i].lkey;
} /* Make sure queue entry is written before the head index. */
smp_store_release(&wq->head, next);
spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags);
} return 0;
}
/* * rvt used the internal kernel struct as part of its ABI, for now make sure * the kernel struct does not change layout. FIXME: rvt should never cast the * user struct to a kernel struct.
*/ staticstruct ib_sge *rvt_cast_sge(struct rvt_wqe_sge *sge)
{
BUILD_BUG_ON(offsetof(struct ib_sge, addr) !=
offsetof(struct rvt_wqe_sge, addr));
BUILD_BUG_ON(offsetof(struct ib_sge, length) !=
offsetof(struct rvt_wqe_sge, length));
BUILD_BUG_ON(offsetof(struct ib_sge, lkey) !=
offsetof(struct rvt_wqe_sge, lkey)); return (struct ib_sge *)sge;
}
/* * Validate a RWQE and fill in the SGE state. * Return 1 if OK.
*/ staticint init_sge(struct rvt_qp *qp, struct rvt_rwqe *wqe)
{ int i, j, ret; struct ib_wc wc; struct rvt_lkey_table *rkt; struct rvt_pd *pd; struct rvt_sge_state *ss; struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device);
/** * get_rvt_head - get head indices of the circular buffer * @rq: data structure for request queue entry * @ip: the QP * * Return - head index value
*/ staticinline u32 get_rvt_head(struct rvt_rq *rq, void *ip)
{
u32 head;
if (ip)
head = RDMA_READ_UAPI_ATOMIC(rq->wq->head); else
head = rq->kwq->head;
return head;
}
/** * rvt_get_rwqe - copy the next RWQE into the QP's RWQE * @qp: the QP * @wr_id_only: update qp->r_wr_id only, not qp->r_sge * * Return -1 if there is a local error, 0 if no RWQE is available, * otherwise return 1. * * Can be called from interrupt level.
*/ int rvt_get_rwqe(struct rvt_qp *qp, bool wr_id_only)
{ unsignedlong flags; struct rvt_rq *rq; struct rvt_krwq *kwq = NULL; struct rvt_rwq *wq; struct rvt_srq *srq; struct rvt_rwqe *wqe; void (*handler)(struct ib_event *, void *);
u32 tail;
u32 head; int ret; void *ip = NULL;
/* Validate tail before using it since it is user writable. */ if (tail >= rq->size)
tail = 0;
if (kwq->count < RVT_RWQ_COUNT_THRESHOLD) {
head = get_rvt_head(rq, ip);
kwq->count = rvt_get_rq_count(rq, head, tail);
} if (unlikely(kwq->count == 0)) {
ret = 0; goto unlock;
} /* Make sure entry is read after the count is read. */
smp_rmb();
wqe = rvt_get_rwqe_ptr(rq, tail); /* * Even though we update the tail index in memory, the verbs * consumer is not supposed to post more entries until a * completion is generated.
*/ if (++tail >= rq->size)
tail = 0; if (ip)
RDMA_WRITE_UAPI_ATOMIC(wq->tail, tail); else
kwq->tail = tail; if (!wr_id_only && !init_sge(qp, wqe)) {
ret = -1; goto unlock;
}
qp->r_wr_id = wqe->wr_id;
kwq->count--;
ret = 1;
set_bit(RVT_R_WRID_VALID, &qp->r_aflags); if (handler) { /* * Validate head pointer value and compute * the number of remaining WQEs.
*/ if (kwq->count < srq->limit) {
kwq->count =
rvt_get_rq_count(rq,
get_rvt_head(rq, ip), tail); if (kwq->count < srq->limit) { struct ib_event ev;
/* * rvt_rnr_tbl_to_usec - return index into ib_rvt_rnr_table * @index - the index * return usec from an index into ib_rvt_rnr_table
*/ unsignedlong rvt_rnr_tbl_to_usec(u32 index)
{ return ib_rvt_rnr_table[(index & IB_AETH_CREDIT_MASK)];
}
EXPORT_SYMBOL(rvt_rnr_tbl_to_usec);
/** * rvt_add_rnr_timer - add/start an rnr timer on the QP * @qp: the QP * @aeth: aeth of RNR timeout, simulated aeth for loopback
*/ void rvt_add_rnr_timer(struct rvt_qp *qp, u32 aeth)
{
u32 to;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.