Lines Matching +full:no +full:- +full:memory +full:- +full:wc
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright(c) 2016 - 2020 Intel Corporation.
66 * completions as per IB 1.2 C10-96.
97 * there are no security issues. The extra fault recovery machinery in cacheless_memcpy()
105 struct rvt_wss *wss = rdi->wss; in rvt_wss_exit()
111 kfree(wss->entries); in rvt_wss_exit()
112 wss->entries = NULL; in rvt_wss_exit()
113 kfree(rdi->wss); in rvt_wss_exit()
114 rdi->wss = NULL; in rvt_wss_exit()
118 * rvt_wss_init - Init wss data structures
124 unsigned int sge_copy_mode = rdi->dparms.sge_copy_mode; in rvt_wss_init()
125 unsigned int wss_threshold = rdi->dparms.wss_threshold; in rvt_wss_init()
126 unsigned int wss_clean_period = rdi->dparms.wss_clean_period; in rvt_wss_init()
132 int node = rdi->dparms.node; in rvt_wss_init()
135 rdi->wss = NULL; in rvt_wss_init()
139 rdi->wss = kzalloc_node(sizeof(*rdi->wss), GFP_KERNEL, node); in rvt_wss_init()
140 if (!rdi->wss) in rvt_wss_init()
141 return -ENOMEM; in rvt_wss_init()
142 wss = rdi->wss; in rvt_wss_init()
144 /* check for a valid percent range - default to 80 if none or invalid */ in rvt_wss_init()
157 * Calculate the table size - the next power of 2 larger than the in rvt_wss_init()
166 wss->pages_mask = table_bits - 1; in rvt_wss_init()
167 wss->num_entries = table_bits / BITS_PER_LONG; in rvt_wss_init()
169 wss->threshold = (llc_bits * wss_threshold) / 100; in rvt_wss_init()
170 if (wss->threshold == 0) in rvt_wss_init()
171 wss->threshold = 1; in rvt_wss_init()
173 wss->clean_period = wss_clean_period; in rvt_wss_init()
174 atomic_set(&wss->clean_counter, wss_clean_period); in rvt_wss_init()
176 wss->entries = kcalloc_node(wss->num_entries, sizeof(*wss->entries), in rvt_wss_init()
178 if (!wss->entries) { in rvt_wss_init()
180 return -ENOMEM; in rvt_wss_init()
195 * race - the next possible racer will not start until the next clean
208 if (atomic_dec_and_test(&wss->clean_counter)) { in wss_advance_clean_counter()
222 atomic_set(&wss->clean_counter, wss->clean_period); in wss_advance_clean_counter()
228 * is always a power-of-2. in wss_advance_clean_counter()
230 entry = (atomic_inc_return(&wss->clean_entry) - 1) in wss_advance_clean_counter()
231 & (wss->num_entries - 1); in wss_advance_clean_counter()
234 bits = xchg(&wss->entries[entry], 0); in wss_advance_clean_counter()
238 atomic_sub(weight, &wss->total_count); in wss_advance_clean_counter()
247 u32 page = ((unsigned long)address >> PAGE_SHIFT) & wss->pages_mask; in wss_insert()
249 u32 nr = page & (BITS_PER_LONG - 1); in wss_insert()
251 if (!test_and_set_bit(nr, &wss->entries[entry])) in wss_insert()
252 atomic_inc(&wss->total_count); in wss_insert()
262 return atomic_read(&wss->total_count) >= wss->threshold; in wss_exceeds_threshold()
274 spin_lock(&qpt->lock); in get_map_page()
275 if (map->page) in get_map_page()
278 map->page = (void *)page; in get_map_page()
279 spin_unlock(&qpt->lock); in get_map_page()
283 * init_qpn_table - initialize the QP number table for a device
293 if (!(rdi->dparms.qpn_res_end >= rdi->dparms.qpn_res_start)) in init_qpn_table()
294 return -EINVAL; in init_qpn_table()
296 spin_lock_init(&qpt->lock); in init_qpn_table()
298 qpt->last = rdi->dparms.qpn_start; in init_qpn_table()
299 qpt->incr = rdi->dparms.qpn_inc << rdi->dparms.qos_shift; in init_qpn_table()
303 * our qpn table. No need for two. Lets go ahead and mark the bitmaps in init_qpn_table()
309 qpt->nmaps = rdi->dparms.qpn_res_start / RVT_BITS_PER_PAGE; in init_qpn_table()
312 offset = rdi->dparms.qpn_res_start & RVT_BITS_PER_PAGE_MASK; in init_qpn_table()
315 map = &qpt->map[qpt->nmaps]; in init_qpn_table()
317 rvt_pr_info(rdi, "Reserving QPNs from 0x%x to 0x%x for non-verbs use\n", in init_qpn_table()
318 rdi->dparms.qpn_res_start, rdi->dparms.qpn_res_end); in init_qpn_table()
319 for (i = rdi->dparms.qpn_res_start; i <= rdi->dparms.qpn_res_end; i++) { in init_qpn_table()
320 if (!map->page) { in init_qpn_table()
322 if (!map->page) { in init_qpn_table()
323 ret = -ENOMEM; in init_qpn_table()
327 set_bit(offset, map->page); in init_qpn_table()
331 qpt->nmaps++; in init_qpn_table()
340 * free_qpn_table - free the QP number table for a device
347 for (i = 0; i < ARRAY_SIZE(qpt->map); i++) in free_qpn_table()
348 free_page((unsigned long)qpt->map[i].page); in free_qpn_table()
352 * rvt_driver_qp_init - Init driver qp resources
360 int ret = -ENOMEM; in rvt_driver_qp_init()
362 if (!rdi->dparms.qp_table_size) in rvt_driver_qp_init()
363 return -EINVAL; in rvt_driver_qp_init()
369 if (!rdi->driver_f.free_all_qps || in rvt_driver_qp_init()
370 !rdi->driver_f.qp_priv_alloc || in rvt_driver_qp_init()
371 !rdi->driver_f.qp_priv_free || in rvt_driver_qp_init()
372 !rdi->driver_f.notify_qp_reset || in rvt_driver_qp_init()
373 !rdi->driver_f.notify_restart_rc) in rvt_driver_qp_init()
374 return -EINVAL; in rvt_driver_qp_init()
377 rdi->qp_dev = kzalloc_node(sizeof(*rdi->qp_dev), GFP_KERNEL, in rvt_driver_qp_init()
378 rdi->dparms.node); in rvt_driver_qp_init()
379 if (!rdi->qp_dev) in rvt_driver_qp_init()
380 return -ENOMEM; in rvt_driver_qp_init()
383 rdi->qp_dev->qp_table_size = rdi->dparms.qp_table_size; in rvt_driver_qp_init()
384 rdi->qp_dev->qp_table_bits = ilog2(rdi->dparms.qp_table_size); in rvt_driver_qp_init()
385 rdi->qp_dev->qp_table = in rvt_driver_qp_init()
386 kmalloc_array_node(rdi->qp_dev->qp_table_size, in rvt_driver_qp_init()
387 sizeof(*rdi->qp_dev->qp_table), in rvt_driver_qp_init()
388 GFP_KERNEL, rdi->dparms.node); in rvt_driver_qp_init()
389 if (!rdi->qp_dev->qp_table) in rvt_driver_qp_init()
392 for (i = 0; i < rdi->qp_dev->qp_table_size; i++) in rvt_driver_qp_init()
393 RCU_INIT_POINTER(rdi->qp_dev->qp_table[i], NULL); in rvt_driver_qp_init()
395 spin_lock_init(&rdi->qp_dev->qpt_lock); in rvt_driver_qp_init()
398 if (init_qpn_table(rdi, &rdi->qp_dev->qpn_table)) in rvt_driver_qp_init()
401 spin_lock_init(&rdi->n_qps_lock); in rvt_driver_qp_init()
406 kfree(rdi->qp_dev->qp_table); in rvt_driver_qp_init()
407 free_qpn_table(&rdi->qp_dev->qpn_table); in rvt_driver_qp_init()
410 kfree(rdi->qp_dev); in rvt_driver_qp_init()
416 * rvt_free_qp_cb - callback function to reset a qp
418 * @v: a 64-bit value
426 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_free_qp_cb()
429 rvt_reset_qp(rdi, qp, qp->ibqp.qp_type); in rvt_free_qp_cb()
436 * rvt_free_all_qps - check for QPs still in use
440 * Free memory for table.
455 * rvt_qp_exit - clean up qps on device exit
465 rvt_pr_err(rdi, "QP memory leak! %u still in use\n", in rvt_qp_exit()
468 kfree(rdi->qp_dev->qp_table); in rvt_qp_exit()
469 free_qpn_table(&rdi->qp_dev->qpn_table); in rvt_qp_exit()
470 kfree(rdi->qp_dev); in rvt_qp_exit()
476 return (map - qpt->map) * RVT_BITS_PER_PAGE + off; in mk_qpn()
480 * alloc_qpn - Allocate the next available qpn or zero/one for QP type
499 if (rdi->driver_f.alloc_qpn) in alloc_qpn()
500 return rdi->driver_f.alloc_qpn(rdi, qpt, type, port_num); in alloc_qpn()
506 n = 1 << (ret + 2 * (port_num - 1)); in alloc_qpn()
507 spin_lock(&qpt->lock); in alloc_qpn()
508 if (qpt->flags & n) in alloc_qpn()
509 ret = -EINVAL; in alloc_qpn()
511 qpt->flags |= n; in alloc_qpn()
512 spin_unlock(&qpt->lock); in alloc_qpn()
516 qpn = qpt->last + qpt->incr; in alloc_qpn()
518 qpn = qpt->incr | ((qpt->last & 1) ^ 1); in alloc_qpn()
521 map = &qpt->map[qpn / RVT_BITS_PER_PAGE]; in alloc_qpn()
522 max_scan = qpt->nmaps - !offset; in alloc_qpn()
524 if (unlikely(!map->page)) { in alloc_qpn()
526 if (unlikely(!map->page)) in alloc_qpn()
530 if (!test_and_set_bit(offset, map->page)) { in alloc_qpn()
531 qpt->last = qpn; in alloc_qpn()
535 offset += qpt->incr; in alloc_qpn()
538 * That is OK. It gets re-assigned below in alloc_qpn()
548 if (qpt->nmaps == RVT_QPNMAP_ENTRIES) in alloc_qpn()
550 map = &qpt->map[qpt->nmaps++]; in alloc_qpn()
552 offset = qpt->incr | (offset & 1); in alloc_qpn()
553 } else if (map < &qpt->map[qpt->nmaps]) { in alloc_qpn()
556 offset = qpt->incr | (offset & 1); in alloc_qpn()
558 map = &qpt->map[0]; in alloc_qpn()
560 offset = qpt->incr | ((offset & 1) ^ 1); in alloc_qpn()
562 /* there can be no set bits in low-order QoS bits */ in alloc_qpn()
563 WARN_ON(rdi->dparms.qos_shift > 1 && in alloc_qpn()
564 offset & ((BIT(rdi->dparms.qos_shift - 1) - 1) << 1)); in alloc_qpn()
568 ret = -ENOMEM; in alloc_qpn()
575 * rvt_clear_mr_refs - Drop help mr refs
582 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_clear_mr_refs()
584 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags)) in rvt_clear_mr_refs()
585 rvt_put_ss(&qp->s_rdma_read_sge); in rvt_clear_mr_refs()
587 rvt_put_ss(&qp->r_sge); in rvt_clear_mr_refs()
590 while (qp->s_last != qp->s_head) { in rvt_clear_mr_refs()
591 struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_last); in rvt_clear_mr_refs()
594 if (++qp->s_last >= qp->s_size) in rvt_clear_mr_refs()
595 qp->s_last = 0; in rvt_clear_mr_refs()
598 if (qp->s_rdma_mr) { in rvt_clear_mr_refs()
599 rvt_put_mr(qp->s_rdma_mr); in rvt_clear_mr_refs()
600 qp->s_rdma_mr = NULL; in rvt_clear_mr_refs()
604 for (n = 0; qp->s_ack_queue && n < rvt_max_atomic(rdi); n++) { in rvt_clear_mr_refs()
605 struct rvt_ack_entry *e = &qp->s_ack_queue[n]; in rvt_clear_mr_refs()
607 if (e->rdma_sge.mr) { in rvt_clear_mr_refs()
608 rvt_put_mr(e->rdma_sge.mr); in rvt_clear_mr_refs()
609 e->rdma_sge.mr = NULL; in rvt_clear_mr_refs()
615 * rvt_swqe_has_lkey - return true if lkey is used by swqe
625 for (i = 0; i < wqe->wr.num_sge; i++) { in rvt_swqe_has_lkey()
626 struct rvt_sge *sge = &wqe->sg_list[i]; in rvt_swqe_has_lkey()
628 if (rvt_mr_has_lkey(sge->mr, lkey)) in rvt_swqe_has_lkey()
635 * rvt_qp_sends_has_lkey - return true is qp sends use lkey
641 u32 s_last = qp->s_last; in rvt_qp_sends_has_lkey()
643 while (s_last != qp->s_head) { in rvt_qp_sends_has_lkey()
649 if (++s_last >= qp->s_size) in rvt_qp_sends_has_lkey()
652 if (qp->s_rdma_mr) in rvt_qp_sends_has_lkey()
653 if (rvt_mr_has_lkey(qp->s_rdma_mr, lkey)) in rvt_qp_sends_has_lkey()
659 * rvt_qp_acks_has_lkey - return true if acks have lkey
666 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_qp_acks_has_lkey()
668 for (i = 0; qp->s_ack_queue && i < rvt_max_atomic(rdi); i++) { in rvt_qp_acks_has_lkey()
669 struct rvt_ack_entry *e = &qp->s_ack_queue[i]; in rvt_qp_acks_has_lkey()
671 if (rvt_mr_has_lkey(e->rdma_sge.mr, lkey)) in rvt_qp_acks_has_lkey()
678 * rvt_qp_mr_clean - clean up remote ops for lkey
680 * @lkey: the lkey that is being de-registered
692 if (qp->ibqp.qp_type == IB_QPT_SMI || in rvt_qp_mr_clean()
693 qp->ibqp.qp_type == IB_QPT_GSI) in rvt_qp_mr_clean()
696 spin_lock_irq(&qp->r_lock); in rvt_qp_mr_clean()
697 spin_lock(&qp->s_hlock); in rvt_qp_mr_clean()
698 spin_lock(&qp->s_lock); in rvt_qp_mr_clean()
700 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET) in rvt_qp_mr_clean()
703 if (rvt_ss_has_lkey(&qp->r_sge, lkey) || in rvt_qp_mr_clean()
708 spin_unlock(&qp->s_lock); in rvt_qp_mr_clean()
709 spin_unlock(&qp->s_hlock); in rvt_qp_mr_clean()
710 spin_unlock_irq(&qp->r_lock); in rvt_qp_mr_clean()
714 ev.device = qp->ibqp.device; in rvt_qp_mr_clean()
715 ev.element.qp = &qp->ibqp; in rvt_qp_mr_clean()
717 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_qp_mr_clean()
722 * rvt_remove_qp - remove qp form table
731 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_remove_qp()
732 u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits); in rvt_remove_qp()
736 spin_lock_irqsave(&rdi->qp_dev->qpt_lock, flags); in rvt_remove_qp()
738 if (rcu_dereference_protected(rvp->qp[0], in rvt_remove_qp()
739 lockdep_is_held(&rdi->qp_dev->qpt_lock)) == qp) { in rvt_remove_qp()
740 RCU_INIT_POINTER(rvp->qp[0], NULL); in rvt_remove_qp()
741 } else if (rcu_dereference_protected(rvp->qp[1], in rvt_remove_qp()
742 lockdep_is_held(&rdi->qp_dev->qpt_lock)) == qp) { in rvt_remove_qp()
743 RCU_INIT_POINTER(rvp->qp[1], NULL); in rvt_remove_qp()
749 qpp = &rdi->qp_dev->qp_table[n]; in rvt_remove_qp()
751 lockdep_is_held(&rdi->qp_dev->qpt_lock))) != NULL; in rvt_remove_qp()
752 qpp = &q->next) { in rvt_remove_qp()
755 rcu_dereference_protected(qp->next, in rvt_remove_qp()
756 lockdep_is_held(&rdi->qp_dev->qpt_lock))); in rvt_remove_qp()
764 spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags); in rvt_remove_qp()
772 * rvt_alloc_rq - allocate memory for user or kernel buffer
778 * Return: If memory allocation failed, return -ENONEM
780 * queues and non-shared receive queues to allocate
781 * memory.
787 rq->wq = vmalloc_user(sizeof(struct rvt_rwq) + size); in rvt_alloc_rq()
788 if (!rq->wq) in rvt_alloc_rq()
790 /* need kwq with no buffers */ in rvt_alloc_rq()
791 rq->kwq = kzalloc_node(sizeof(*rq->kwq), GFP_KERNEL, node); in rvt_alloc_rq()
792 if (!rq->kwq) in rvt_alloc_rq()
794 rq->kwq->curr_wq = rq->wq->wq; in rvt_alloc_rq()
797 rq->kwq = in rvt_alloc_rq()
799 if (!rq->kwq) in rvt_alloc_rq()
801 rq->kwq->curr_wq = rq->kwq->wq; in rvt_alloc_rq()
804 spin_lock_init(&rq->kwq->p_lock); in rvt_alloc_rq()
805 spin_lock_init(&rq->kwq->c_lock); in rvt_alloc_rq()
809 return -ENOMEM; in rvt_alloc_rq()
813 * rvt_init_qp - initialize the QP state to the reset state
826 qp->remote_qpn = 0; in rvt_init_qp()
827 qp->qkey = 0; in rvt_init_qp()
828 qp->qp_access_flags = 0; in rvt_init_qp()
829 qp->s_flags &= RVT_S_SIGNAL_REQ_WR; in rvt_init_qp()
830 qp->s_hdrwords = 0; in rvt_init_qp()
831 qp->s_wqe = NULL; in rvt_init_qp()
832 qp->s_draining = 0; in rvt_init_qp()
833 qp->s_next_psn = 0; in rvt_init_qp()
834 qp->s_last_psn = 0; in rvt_init_qp()
835 qp->s_sending_psn = 0; in rvt_init_qp()
836 qp->s_sending_hpsn = 0; in rvt_init_qp()
837 qp->s_psn = 0; in rvt_init_qp()
838 qp->r_psn = 0; in rvt_init_qp()
839 qp->r_msn = 0; in rvt_init_qp()
841 qp->s_state = IB_OPCODE_RC_SEND_LAST; in rvt_init_qp()
842 qp->r_state = IB_OPCODE_RC_SEND_LAST; in rvt_init_qp()
844 qp->s_state = IB_OPCODE_UC_SEND_LAST; in rvt_init_qp()
845 qp->r_state = IB_OPCODE_UC_SEND_LAST; in rvt_init_qp()
847 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE; in rvt_init_qp()
848 qp->r_nak_state = 0; in rvt_init_qp()
849 qp->r_aflags = 0; in rvt_init_qp()
850 qp->r_flags = 0; in rvt_init_qp()
851 qp->s_head = 0; in rvt_init_qp()
852 qp->s_tail = 0; in rvt_init_qp()
853 qp->s_cur = 0; in rvt_init_qp()
854 qp->s_acked = 0; in rvt_init_qp()
855 qp->s_last = 0; in rvt_init_qp()
856 qp->s_ssn = 1; in rvt_init_qp()
857 qp->s_lsn = 0; in rvt_init_qp()
858 qp->s_mig_state = IB_MIG_MIGRATED; in rvt_init_qp()
859 qp->r_head_ack_queue = 0; in rvt_init_qp()
860 qp->s_tail_ack_queue = 0; in rvt_init_qp()
861 qp->s_acked_ack_queue = 0; in rvt_init_qp()
862 qp->s_num_rd_atomic = 0; in rvt_init_qp()
863 qp->r_sge.num_sge = 0; in rvt_init_qp()
864 atomic_set(&qp->s_reserved_used, 0); in rvt_init_qp()
868 * _rvt_reset_qp - initialize the QP state to the reset state
877 __must_hold(&qp->s_lock) in _rvt_reset_qp()
878 __must_hold(&qp->s_hlock) in _rvt_reset_qp()
879 __must_hold(&qp->r_lock) in _rvt_reset_qp()
881 lockdep_assert_held(&qp->r_lock); in _rvt_reset_qp()
882 lockdep_assert_held(&qp->s_hlock); in _rvt_reset_qp()
883 lockdep_assert_held(&qp->s_lock); in _rvt_reset_qp()
884 if (qp->state != IB_QPS_RESET) { in _rvt_reset_qp()
885 qp->state = IB_QPS_RESET; in _rvt_reset_qp()
888 rdi->driver_f.flush_qp_waiters(qp); in _rvt_reset_qp()
890 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_ANY_WAIT); in _rvt_reset_qp()
891 spin_unlock(&qp->s_lock); in _rvt_reset_qp()
892 spin_unlock(&qp->s_hlock); in _rvt_reset_qp()
893 spin_unlock_irq(&qp->r_lock); in _rvt_reset_qp()
896 rdi->driver_f.stop_send_queue(qp); in _rvt_reset_qp()
899 rdi->driver_f.quiesce_qp(qp); in _rvt_reset_qp()
905 spin_lock_irq(&qp->r_lock); in _rvt_reset_qp()
906 spin_lock(&qp->s_hlock); in _rvt_reset_qp()
907 spin_lock(&qp->s_lock); in _rvt_reset_qp()
911 * Let the driver do any tear down or re-init it needs to for in _rvt_reset_qp()
914 rdi->driver_f.notify_qp_reset(qp); in _rvt_reset_qp()
917 lockdep_assert_held(&qp->r_lock); in _rvt_reset_qp()
918 lockdep_assert_held(&qp->s_hlock); in _rvt_reset_qp()
919 lockdep_assert_held(&qp->s_lock); in _rvt_reset_qp()
923 * rvt_reset_qp - initialize the QP state to the reset state
934 spin_lock_irq(&qp->r_lock); in rvt_reset_qp()
935 spin_lock(&qp->s_hlock); in rvt_reset_qp()
936 spin_lock(&qp->s_lock); in rvt_reset_qp()
938 spin_unlock(&qp->s_lock); in rvt_reset_qp()
939 spin_unlock(&qp->s_hlock); in rvt_reset_qp()
940 spin_unlock_irq(&qp->r_lock); in rvt_reset_qp()
944 * rvt_free_qpn - Free a qpn from the bit map
955 map = qpt->map + (qpn & RVT_QPN_MASK) / RVT_BITS_PER_PAGE; in rvt_free_qpn()
956 if (map->page) in rvt_free_qpn()
957 clear_bit(qpn & RVT_BITS_PER_PAGE_MASK, map->page); in rvt_free_qpn()
961 * get_allowed_ops - Given a QP type return the appropriate allowed OP
971 * free_ud_wq_attr - Clean up AH attribute cache for UD QPs
982 for (i = 0; qp->allowed_ops == IB_OPCODE_UD && i < qp->s_size; i++) { in free_ud_wq_attr()
984 kfree(wqe->ud_wr.attr); in free_ud_wq_attr()
985 wqe->ud_wr.attr = NULL; in free_ud_wq_attr()
990 * alloc_ud_wq_attr - AH attribute cache for UD QPs
1002 for (i = 0; qp->allowed_ops == IB_OPCODE_UD && i < qp->s_size; i++) { in alloc_ud_wq_attr()
1004 wqe->ud_wr.attr = kzalloc_node(sizeof(*wqe->ud_wr.attr), in alloc_ud_wq_attr()
1006 if (!wqe->ud_wr.attr) { in alloc_ud_wq_attr()
1008 return -ENOMEM; in alloc_ud_wq_attr()
1016 * rvt_create_qp - create a queue pair for a device
1033 int ret = -ENOMEM; in rvt_create_qp()
1037 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_create_qp()
1043 return -EINVAL; in rvt_create_qp()
1045 if (init_attr->create_flags & ~IB_QP_CREATE_NETDEV_USE) in rvt_create_qp()
1046 return -EOPNOTSUPP; in rvt_create_qp()
1048 if (init_attr->cap.max_send_sge > rdi->dparms.props.max_send_sge || in rvt_create_qp()
1049 init_attr->cap.max_send_wr > rdi->dparms.props.max_qp_wr) in rvt_create_qp()
1050 return -EINVAL; in rvt_create_qp()
1052 /* Check receive queue parameters if no SRQ is specified. */ in rvt_create_qp()
1053 if (!init_attr->srq) { in rvt_create_qp()
1054 if (init_attr->cap.max_recv_sge > in rvt_create_qp()
1055 rdi->dparms.props.max_recv_sge || in rvt_create_qp()
1056 init_attr->cap.max_recv_wr > rdi->dparms.props.max_qp_wr) in rvt_create_qp()
1057 return -EINVAL; in rvt_create_qp()
1059 if (init_attr->cap.max_send_sge + in rvt_create_qp()
1060 init_attr->cap.max_send_wr + in rvt_create_qp()
1061 init_attr->cap.max_recv_sge + in rvt_create_qp()
1062 init_attr->cap.max_recv_wr == 0) in rvt_create_qp()
1063 return -EINVAL; in rvt_create_qp()
1066 init_attr->cap.max_send_wr + 1 + in rvt_create_qp()
1067 rdi->dparms.reserved_operations; in rvt_create_qp()
1068 switch (init_attr->qp_type) { in rvt_create_qp()
1071 if (init_attr->port_num == 0 || in rvt_create_qp()
1072 init_attr->port_num > ibqp->device->phys_port_cnt) in rvt_create_qp()
1073 return -EINVAL; in rvt_create_qp()
1078 sz = struct_size(swq, sg_list, init_attr->cap.max_send_sge); in rvt_create_qp()
1079 swq = vzalloc_node(array_size(sz, sqsize), rdi->dparms.node); in rvt_create_qp()
1081 return -ENOMEM; in rvt_create_qp()
1083 if (init_attr->srq) { in rvt_create_qp()
1084 struct rvt_srq *srq = ibsrq_to_rvtsrq(init_attr->srq); in rvt_create_qp()
1086 if (srq->rq.max_sge > 1) in rvt_create_qp()
1087 sg_list_sz = sizeof(*qp->r_sg_list) * in rvt_create_qp()
1088 (srq->rq.max_sge - 1); in rvt_create_qp()
1089 } else if (init_attr->cap.max_recv_sge > 1) in rvt_create_qp()
1090 sg_list_sz = sizeof(*qp->r_sg_list) * in rvt_create_qp()
1091 (init_attr->cap.max_recv_sge - 1); in rvt_create_qp()
1092 qp->r_sg_list = in rvt_create_qp()
1093 kzalloc_node(sg_list_sz, GFP_KERNEL, rdi->dparms.node); in rvt_create_qp()
1094 if (!qp->r_sg_list) in rvt_create_qp()
1096 qp->allowed_ops = get_allowed_ops(init_attr->qp_type); in rvt_create_qp()
1098 RCU_INIT_POINTER(qp->next, NULL); in rvt_create_qp()
1099 if (init_attr->qp_type == IB_QPT_RC) { in rvt_create_qp()
1100 qp->s_ack_queue = in rvt_create_qp()
1102 sizeof(*qp->s_ack_queue), in rvt_create_qp()
1104 rdi->dparms.node); in rvt_create_qp()
1105 if (!qp->s_ack_queue) in rvt_create_qp()
1109 timer_setup(&qp->s_timer, rvt_rc_timeout, 0); in rvt_create_qp()
1110 hrtimer_init(&qp->s_rnr_timer, CLOCK_MONOTONIC, in rvt_create_qp()
1112 qp->s_rnr_timer.function = rvt_rc_rnr_retry; in rvt_create_qp()
1118 priv = rdi->driver_f.qp_priv_alloc(rdi, qp); in rvt_create_qp()
1123 qp->priv = priv; in rvt_create_qp()
1124 qp->timeout_jiffies = in rvt_create_qp()
1125 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) / in rvt_create_qp()
1127 if (init_attr->srq) { in rvt_create_qp()
1130 qp->r_rq.size = init_attr->cap.max_recv_wr + 1; in rvt_create_qp()
1131 qp->r_rq.max_sge = init_attr->cap.max_recv_sge; in rvt_create_qp()
1132 sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) + in rvt_create_qp()
1134 ret = rvt_alloc_rq(&qp->r_rq, qp->r_rq.size * sz, in rvt_create_qp()
1135 rdi->dparms.node, udata); in rvt_create_qp()
1141 * ib_create_qp() will initialize qp->ibqp in rvt_create_qp()
1142 * except for qp->ibqp.qp_num. in rvt_create_qp()
1144 spin_lock_init(&qp->r_lock); in rvt_create_qp()
1145 spin_lock_init(&qp->s_hlock); in rvt_create_qp()
1146 spin_lock_init(&qp->s_lock); in rvt_create_qp()
1147 atomic_set(&qp->refcount, 0); in rvt_create_qp()
1148 atomic_set(&qp->local_ops_pending, 0); in rvt_create_qp()
1149 init_waitqueue_head(&qp->wait); in rvt_create_qp()
1150 INIT_LIST_HEAD(&qp->rspwait); in rvt_create_qp()
1151 qp->state = IB_QPS_RESET; in rvt_create_qp()
1152 qp->s_wq = swq; in rvt_create_qp()
1153 qp->s_size = sqsize; in rvt_create_qp()
1154 qp->s_avail = init_attr->cap.max_send_wr; in rvt_create_qp()
1155 qp->s_max_sge = init_attr->cap.max_send_sge; in rvt_create_qp()
1156 if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR) in rvt_create_qp()
1157 qp->s_flags = RVT_S_SIGNAL_REQ_WR; in rvt_create_qp()
1158 ret = alloc_ud_wq_attr(qp, rdi->dparms.node); in rvt_create_qp()
1162 if (init_attr->create_flags & IB_QP_CREATE_NETDEV_USE) in rvt_create_qp()
1165 ret = alloc_qpn(rdi, &rdi->qp_dev->qpn_table, in rvt_create_qp()
1166 init_attr->qp_type, in rvt_create_qp()
1167 init_attr->port_num, in rvt_create_qp()
1172 qp->ibqp.qp_num = ret; in rvt_create_qp()
1173 if (init_attr->create_flags & IB_QP_CREATE_NETDEV_USE) in rvt_create_qp()
1174 qp->ibqp.qp_num |= RVT_AIP_QP_BASE; in rvt_create_qp()
1175 qp->port_num = init_attr->port_num; in rvt_create_qp()
1176 rvt_init_qp(rdi, qp, init_attr->qp_type); in rvt_create_qp()
1177 if (rdi->driver_f.qp_priv_init) { in rvt_create_qp()
1178 ret = rdi->driver_f.qp_priv_init(rdi, qp, init_attr); in rvt_create_qp()
1186 return -EOPNOTSUPP; in rvt_create_qp()
1189 init_attr->cap.max_inline_data = 0; in rvt_create_qp()
1195 if (udata && udata->outlen >= sizeof(__u64)) { in rvt_create_qp()
1196 if (!qp->r_rq.wq) { in rvt_create_qp()
1204 u32 s = sizeof(struct rvt_rwq) + qp->r_rq.size * sz; in rvt_create_qp()
1206 qp->ip = rvt_create_mmap_info(rdi, s, udata, in rvt_create_qp()
1207 qp->r_rq.wq); in rvt_create_qp()
1208 if (IS_ERR(qp->ip)) { in rvt_create_qp()
1209 ret = PTR_ERR(qp->ip); in rvt_create_qp()
1213 ret = ib_copy_to_udata(udata, &qp->ip->offset, in rvt_create_qp()
1214 sizeof(qp->ip->offset)); in rvt_create_qp()
1218 qp->pid = current->pid; in rvt_create_qp()
1221 spin_lock(&rdi->n_qps_lock); in rvt_create_qp()
1222 if (rdi->n_qps_allocated == rdi->dparms.props.max_qp) { in rvt_create_qp()
1223 spin_unlock(&rdi->n_qps_lock); in rvt_create_qp()
1224 ret = -ENOMEM; in rvt_create_qp()
1228 rdi->n_qps_allocated++; in rvt_create_qp()
1238 if (init_attr->qp_type == IB_QPT_RC) { in rvt_create_qp()
1239 rdi->n_rc_qps++; in rvt_create_qp()
1240 rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL; in rvt_create_qp()
1242 spin_unlock(&rdi->n_qps_lock); in rvt_create_qp()
1244 if (qp->ip) { in rvt_create_qp()
1245 spin_lock_irq(&rdi->pending_lock); in rvt_create_qp()
1246 list_add(&qp->ip->pending_mmaps, &rdi->pending_mmaps); in rvt_create_qp()
1247 spin_unlock_irq(&rdi->pending_lock); in rvt_create_qp()
1253 if (qp->ip) in rvt_create_qp()
1254 kref_put(&qp->ip->ref, rvt_release_mmap_info); in rvt_create_qp()
1257 rvt_free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num); in rvt_create_qp()
1263 rvt_free_rq(&qp->r_rq); in rvt_create_qp()
1266 rdi->driver_f.qp_priv_free(rdi, qp); in rvt_create_qp()
1269 kfree(qp->s_ack_queue); in rvt_create_qp()
1270 kfree(qp->r_sg_list); in rvt_create_qp()
1276 * rvt_error_qp - put a QP into the error state
1288 struct ib_wc wc; in rvt_error_qp() local
1290 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_error_qp()
1292 lockdep_assert_held(&qp->r_lock); in rvt_error_qp()
1293 lockdep_assert_held(&qp->s_lock); in rvt_error_qp()
1294 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET) in rvt_error_qp()
1297 qp->state = IB_QPS_ERR; in rvt_error_qp()
1299 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) { in rvt_error_qp()
1300 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR); in rvt_error_qp()
1301 del_timer(&qp->s_timer); in rvt_error_qp()
1304 if (qp->s_flags & RVT_S_ANY_WAIT_SEND) in rvt_error_qp()
1305 qp->s_flags &= ~RVT_S_ANY_WAIT_SEND; in rvt_error_qp()
1307 rdi->driver_f.notify_error_qp(qp); in rvt_error_qp()
1310 if (READ_ONCE(qp->s_last) != qp->s_head) in rvt_error_qp()
1311 rdi->driver_f.schedule_send(qp); in rvt_error_qp()
1315 memset(&wc, 0, sizeof(wc)); in rvt_error_qp()
1316 wc.qp = &qp->ibqp; in rvt_error_qp()
1317 wc.opcode = IB_WC_RECV; in rvt_error_qp()
1319 if (test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) { in rvt_error_qp()
1320 wc.wr_id = qp->r_wr_id; in rvt_error_qp()
1321 wc.status = err; in rvt_error_qp()
1322 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_error_qp()
1324 wc.status = IB_WC_WR_FLUSH_ERR; in rvt_error_qp()
1326 if (qp->r_rq.kwq) { in rvt_error_qp()
1332 spin_lock(&qp->r_rq.kwq->c_lock); in rvt_error_qp()
1333 /* qp->ip used to validate if there is a user buffer mmaped */ in rvt_error_qp()
1334 if (qp->ip) { in rvt_error_qp()
1335 wq = qp->r_rq.wq; in rvt_error_qp()
1336 head = RDMA_READ_UAPI_ATOMIC(wq->head); in rvt_error_qp()
1337 tail = RDMA_READ_UAPI_ATOMIC(wq->tail); in rvt_error_qp()
1339 kwq = qp->r_rq.kwq; in rvt_error_qp()
1340 head = kwq->head; in rvt_error_qp()
1341 tail = kwq->tail; in rvt_error_qp()
1344 if (head >= qp->r_rq.size) in rvt_error_qp()
1346 if (tail >= qp->r_rq.size) in rvt_error_qp()
1349 wc.wr_id = rvt_get_rwqe_ptr(&qp->r_rq, tail)->wr_id; in rvt_error_qp()
1350 if (++tail >= qp->r_rq.size) in rvt_error_qp()
1352 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_error_qp()
1354 if (qp->ip) in rvt_error_qp()
1355 RDMA_WRITE_UAPI_ATOMIC(wq->tail, tail); in rvt_error_qp()
1357 kwq->tail = tail; in rvt_error_qp()
1358 spin_unlock(&qp->r_rq.kwq->c_lock); in rvt_error_qp()
1359 } else if (qp->ibqp.event_handler) { in rvt_error_qp()
1374 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_insert_qp()
1378 spin_lock_irqsave(&rdi->qp_dev->qpt_lock, flags); in rvt_insert_qp()
1380 if (qp->ibqp.qp_num <= 1) { in rvt_insert_qp()
1381 rcu_assign_pointer(rvp->qp[qp->ibqp.qp_num], qp); in rvt_insert_qp()
1383 u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits); in rvt_insert_qp()
1385 qp->next = rdi->qp_dev->qp_table[n]; in rvt_insert_qp()
1386 rcu_assign_pointer(rdi->qp_dev->qp_table[n], qp); in rvt_insert_qp()
1390 spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags); in rvt_insert_qp()
1394 * rvt_modify_qp - modify the attributes of a queue pair
1405 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_modify_qp()
1415 return -EOPNOTSUPP; in rvt_modify_qp()
1417 spin_lock_irq(&qp->r_lock); in rvt_modify_qp()
1418 spin_lock(&qp->s_hlock); in rvt_modify_qp()
1419 spin_lock(&qp->s_lock); in rvt_modify_qp()
1422 attr->cur_qp_state : qp->state; in rvt_modify_qp()
1423 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; in rvt_modify_qp()
1424 opa_ah = rdma_cap_opa_ah(ibqp->device, qp->port_num); in rvt_modify_qp()
1426 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, in rvt_modify_qp()
1430 if (rdi->driver_f.check_modify_qp && in rvt_modify_qp()
1431 rdi->driver_f.check_modify_qp(qp, attr, attr_mask, udata)) in rvt_modify_qp()
1436 if (rdma_ah_get_dlid(&attr->ah_attr) >= in rvt_modify_qp()
1440 if (rdma_ah_get_dlid(&attr->ah_attr) >= in rvt_modify_qp()
1445 if (rvt_check_ah(qp->ibqp.device, &attr->ah_attr)) in rvt_modify_qp()
1451 if (rdma_ah_get_dlid(&attr->alt_ah_attr) >= in rvt_modify_qp()
1455 if (rdma_ah_get_dlid(&attr->alt_ah_attr) >= in rvt_modify_qp()
1460 if (rvt_check_ah(qp->ibqp.device, &attr->alt_ah_attr)) in rvt_modify_qp()
1462 if (attr->alt_pkey_index >= rvt_get_npkeys(rdi)) in rvt_modify_qp()
1467 if (attr->pkey_index >= rvt_get_npkeys(rdi)) in rvt_modify_qp()
1471 if (attr->min_rnr_timer > 31) in rvt_modify_qp()
1475 if (qp->ibqp.qp_type == IB_QPT_SMI || in rvt_modify_qp()
1476 qp->ibqp.qp_type == IB_QPT_GSI || in rvt_modify_qp()
1477 attr->port_num == 0 || in rvt_modify_qp()
1478 attr->port_num > ibqp->device->phys_port_cnt) in rvt_modify_qp()
1482 if (attr->dest_qp_num > RVT_QPN_MASK) in rvt_modify_qp()
1486 if (attr->retry_cnt > 7) in rvt_modify_qp()
1490 if (attr->rnr_retry > 7) in rvt_modify_qp()
1496 * that to a small mtu. We'll set qp->path_mtu in rvt_modify_qp()
1502 pmtu = rdi->driver_f.get_pmtu_from_attr(rdi, qp, attr); in rvt_modify_qp()
1508 if (attr->path_mig_state == IB_MIG_REARM) { in rvt_modify_qp()
1509 if (qp->s_mig_state == IB_MIG_ARMED) in rvt_modify_qp()
1513 } else if (attr->path_mig_state == IB_MIG_MIGRATED) { in rvt_modify_qp()
1514 if (qp->s_mig_state == IB_MIG_REARM) in rvt_modify_qp()
1518 if (qp->s_mig_state == IB_MIG_ARMED) in rvt_modify_qp()
1526 if (attr->max_dest_rd_atomic > rdi->dparms.max_rdma_atomic) in rvt_modify_qp()
1531 if (qp->state != IB_QPS_RESET) in rvt_modify_qp()
1532 _rvt_reset_qp(rdi, qp, ibqp->qp_type); in rvt_modify_qp()
1536 /* Allow event to re-trigger if QP set to RTR more than once */ in rvt_modify_qp()
1537 qp->r_flags &= ~RVT_R_COMM_EST; in rvt_modify_qp()
1538 qp->state = new_state; in rvt_modify_qp()
1542 qp->s_draining = qp->s_last != qp->s_cur; in rvt_modify_qp()
1543 qp->state = new_state; in rvt_modify_qp()
1547 if (qp->ibqp.qp_type == IB_QPT_RC) in rvt_modify_qp()
1549 qp->state = new_state; in rvt_modify_qp()
1557 qp->state = new_state; in rvt_modify_qp()
1562 qp->s_pkey_index = attr->pkey_index; in rvt_modify_qp()
1565 qp->port_num = attr->port_num; in rvt_modify_qp()
1568 qp->remote_qpn = attr->dest_qp_num; in rvt_modify_qp()
1571 qp->s_next_psn = attr->sq_psn & rdi->dparms.psn_modify_mask; in rvt_modify_qp()
1572 qp->s_psn = qp->s_next_psn; in rvt_modify_qp()
1573 qp->s_sending_psn = qp->s_next_psn; in rvt_modify_qp()
1574 qp->s_last_psn = qp->s_next_psn - 1; in rvt_modify_qp()
1575 qp->s_sending_hpsn = qp->s_last_psn; in rvt_modify_qp()
1579 qp->r_psn = attr->rq_psn & rdi->dparms.psn_modify_mask; in rvt_modify_qp()
1582 qp->qp_access_flags = attr->qp_access_flags; in rvt_modify_qp()
1585 rdma_replace_ah_attr(&qp->remote_ah_attr, &attr->ah_attr); in rvt_modify_qp()
1586 qp->s_srate = rdma_ah_get_static_rate(&attr->ah_attr); in rvt_modify_qp()
1587 qp->srate_mbps = ib_rate_to_mbps(qp->s_srate); in rvt_modify_qp()
1591 rdma_replace_ah_attr(&qp->alt_ah_attr, &attr->alt_ah_attr); in rvt_modify_qp()
1592 qp->s_alt_pkey_index = attr->alt_pkey_index; in rvt_modify_qp()
1596 qp->s_mig_state = attr->path_mig_state; in rvt_modify_qp()
1598 qp->remote_ah_attr = qp->alt_ah_attr; in rvt_modify_qp()
1599 qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr); in rvt_modify_qp()
1600 qp->s_pkey_index = qp->s_alt_pkey_index; in rvt_modify_qp()
1605 qp->pmtu = rdi->driver_f.mtu_from_qp(rdi, qp, pmtu); in rvt_modify_qp()
1606 qp->log_pmtu = ilog2(qp->pmtu); in rvt_modify_qp()
1610 qp->s_retry_cnt = attr->retry_cnt; in rvt_modify_qp()
1611 qp->s_retry = attr->retry_cnt; in rvt_modify_qp()
1615 qp->s_rnr_retry_cnt = attr->rnr_retry; in rvt_modify_qp()
1616 qp->s_rnr_retry = attr->rnr_retry; in rvt_modify_qp()
1620 qp->r_min_rnr_timer = attr->min_rnr_timer; in rvt_modify_qp()
1623 qp->timeout = attr->timeout; in rvt_modify_qp()
1624 qp->timeout_jiffies = rvt_timeout_to_jiffies(qp->timeout); in rvt_modify_qp()
1628 qp->qkey = attr->qkey; in rvt_modify_qp()
1631 qp->r_max_rd_atomic = attr->max_dest_rd_atomic; in rvt_modify_qp()
1634 qp->s_max_rd_atomic = attr->max_rd_atomic; in rvt_modify_qp()
1636 if (rdi->driver_f.modify_qp) in rvt_modify_qp()
1637 rdi->driver_f.modify_qp(qp, attr, attr_mask, udata); in rvt_modify_qp()
1639 spin_unlock(&qp->s_lock); in rvt_modify_qp()
1640 spin_unlock(&qp->s_hlock); in rvt_modify_qp()
1641 spin_unlock_irq(&qp->r_lock); in rvt_modify_qp()
1647 ev.device = qp->ibqp.device; in rvt_modify_qp()
1648 ev.element.qp = &qp->ibqp; in rvt_modify_qp()
1650 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_modify_qp()
1653 ev.device = qp->ibqp.device; in rvt_modify_qp()
1654 ev.element.qp = &qp->ibqp; in rvt_modify_qp()
1656 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_modify_qp()
1661 spin_unlock(&qp->s_lock); in rvt_modify_qp()
1662 spin_unlock(&qp->s_hlock); in rvt_modify_qp()
1663 spin_unlock_irq(&qp->r_lock); in rvt_modify_qp()
1664 return -EINVAL; in rvt_modify_qp()
1668 * rvt_destroy_qp - destroy a queue pair
1680 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_destroy_qp()
1682 rvt_reset_qp(rdi, qp, ibqp->qp_type); in rvt_destroy_qp()
1684 wait_event(qp->wait, !atomic_read(&qp->refcount)); in rvt_destroy_qp()
1686 rvt_free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num); in rvt_destroy_qp()
1688 spin_lock(&rdi->n_qps_lock); in rvt_destroy_qp()
1689 rdi->n_qps_allocated--; in rvt_destroy_qp()
1690 if (qp->ibqp.qp_type == IB_QPT_RC) { in rvt_destroy_qp()
1691 rdi->n_rc_qps--; in rvt_destroy_qp()
1692 rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL; in rvt_destroy_qp()
1694 spin_unlock(&rdi->n_qps_lock); in rvt_destroy_qp()
1696 if (qp->ip) in rvt_destroy_qp()
1697 kref_put(&qp->ip->ref, rvt_release_mmap_info); in rvt_destroy_qp()
1698 kvfree(qp->r_rq.kwq); in rvt_destroy_qp()
1699 rdi->driver_f.qp_priv_free(rdi, qp); in rvt_destroy_qp()
1700 kfree(qp->s_ack_queue); in rvt_destroy_qp()
1701 kfree(qp->r_sg_list); in rvt_destroy_qp()
1702 rdma_destroy_ah_attr(&qp->remote_ah_attr); in rvt_destroy_qp()
1703 rdma_destroy_ah_attr(&qp->alt_ah_attr); in rvt_destroy_qp()
1705 vfree(qp->s_wq); in rvt_destroy_qp()
1710 * rvt_query_qp - query an ipbq
1722 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_query_qp()
1724 attr->qp_state = qp->state; in rvt_query_qp()
1725 attr->cur_qp_state = attr->qp_state; in rvt_query_qp()
1726 attr->path_mtu = rdi->driver_f.mtu_to_path_mtu(qp->pmtu); in rvt_query_qp()
1727 attr->path_mig_state = qp->s_mig_state; in rvt_query_qp()
1728 attr->qkey = qp->qkey; in rvt_query_qp()
1729 attr->rq_psn = qp->r_psn & rdi->dparms.psn_mask; in rvt_query_qp()
1730 attr->sq_psn = qp->s_next_psn & rdi->dparms.psn_mask; in rvt_query_qp()
1731 attr->dest_qp_num = qp->remote_qpn; in rvt_query_qp()
1732 attr->qp_access_flags = qp->qp_access_flags; in rvt_query_qp()
1733 attr->cap.max_send_wr = qp->s_size - 1 - in rvt_query_qp()
1734 rdi->dparms.reserved_operations; in rvt_query_qp()
1735 attr->cap.max_recv_wr = qp->ibqp.srq ? 0 : qp->r_rq.size - 1; in rvt_query_qp()
1736 attr->cap.max_send_sge = qp->s_max_sge; in rvt_query_qp()
1737 attr->cap.max_recv_sge = qp->r_rq.max_sge; in rvt_query_qp()
1738 attr->cap.max_inline_data = 0; in rvt_query_qp()
1739 attr->ah_attr = qp->remote_ah_attr; in rvt_query_qp()
1740 attr->alt_ah_attr = qp->alt_ah_attr; in rvt_query_qp()
1741 attr->pkey_index = qp->s_pkey_index; in rvt_query_qp()
1742 attr->alt_pkey_index = qp->s_alt_pkey_index; in rvt_query_qp()
1743 attr->en_sqd_async_notify = 0; in rvt_query_qp()
1744 attr->sq_draining = qp->s_draining; in rvt_query_qp()
1745 attr->max_rd_atomic = qp->s_max_rd_atomic; in rvt_query_qp()
1746 attr->max_dest_rd_atomic = qp->r_max_rd_atomic; in rvt_query_qp()
1747 attr->min_rnr_timer = qp->r_min_rnr_timer; in rvt_query_qp()
1748 attr->port_num = qp->port_num; in rvt_query_qp()
1749 attr->timeout = qp->timeout; in rvt_query_qp()
1750 attr->retry_cnt = qp->s_retry_cnt; in rvt_query_qp()
1751 attr->rnr_retry = qp->s_rnr_retry_cnt; in rvt_query_qp()
1752 attr->alt_port_num = in rvt_query_qp()
1753 rdma_ah_get_port_num(&qp->alt_ah_attr); in rvt_query_qp()
1754 attr->alt_timeout = qp->alt_timeout; in rvt_query_qp()
1756 init_attr->event_handler = qp->ibqp.event_handler; in rvt_query_qp()
1757 init_attr->qp_context = qp->ibqp.qp_context; in rvt_query_qp()
1758 init_attr->send_cq = qp->ibqp.send_cq; in rvt_query_qp()
1759 init_attr->recv_cq = qp->ibqp.recv_cq; in rvt_query_qp()
1760 init_attr->srq = qp->ibqp.srq; in rvt_query_qp()
1761 init_attr->cap = attr->cap; in rvt_query_qp()
1762 if (qp->s_flags & RVT_S_SIGNAL_REQ_WR) in rvt_query_qp()
1763 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR; in rvt_query_qp()
1765 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; in rvt_query_qp()
1766 init_attr->qp_type = qp->ibqp.qp_type; in rvt_query_qp()
1767 init_attr->port_num = qp->port_num; in rvt_query_qp()
1772 * rvt_post_recv - post a receive on a QP
1785 struct rvt_krwq *wq = qp->r_rq.kwq; in rvt_post_recv()
1787 int qp_err_flush = (ib_rvt_state_ops[qp->state] & RVT_FLUSH_RECV) && in rvt_post_recv()
1788 !qp->ibqp.srq; in rvt_post_recv()
1791 if (!(ib_rvt_state_ops[qp->state] & RVT_POST_RECV_OK) || !wq) { in rvt_post_recv()
1793 return -EINVAL; in rvt_post_recv()
1796 for (; wr; wr = wr->next) { in rvt_post_recv()
1801 if ((unsigned)wr->num_sge > qp->r_rq.max_sge) { in rvt_post_recv()
1803 return -EINVAL; in rvt_post_recv()
1806 spin_lock_irqsave(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1807 next = wq->head + 1; in rvt_post_recv()
1808 if (next >= qp->r_rq.size) in rvt_post_recv()
1810 if (next == READ_ONCE(wq->tail)) { in rvt_post_recv()
1811 spin_unlock_irqrestore(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1813 return -ENOMEM; in rvt_post_recv()
1816 struct ib_wc wc; in rvt_post_recv() local
1818 memset(&wc, 0, sizeof(wc)); in rvt_post_recv()
1819 wc.qp = &qp->ibqp; in rvt_post_recv()
1820 wc.opcode = IB_WC_RECV; in rvt_post_recv()
1821 wc.wr_id = wr->wr_id; in rvt_post_recv()
1822 wc.status = IB_WC_WR_FLUSH_ERR; in rvt_post_recv()
1823 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_post_recv()
1825 wqe = rvt_get_rwqe_ptr(&qp->r_rq, wq->head); in rvt_post_recv()
1826 wqe->wr_id = wr->wr_id; in rvt_post_recv()
1827 wqe->num_sge = wr->num_sge; in rvt_post_recv()
1828 for (i = 0; i < wr->num_sge; i++) { in rvt_post_recv()
1829 wqe->sg_list[i].addr = wr->sg_list[i].addr; in rvt_post_recv()
1830 wqe->sg_list[i].length = wr->sg_list[i].length; in rvt_post_recv()
1831 wqe->sg_list[i].lkey = wr->sg_list[i].lkey; in rvt_post_recv()
1837 smp_store_release(&wq->head, next); in rvt_post_recv()
1839 spin_unlock_irqrestore(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1845 * rvt_qp_valid_operation - validate post send wr request
1869 if (wr->opcode >= RVT_OPERATION_MAX || !post_parms[wr->opcode].length) in rvt_qp_valid_operation()
1870 return -EINVAL; in rvt_qp_valid_operation()
1871 if (!(post_parms[wr->opcode].qpt_support & BIT(qp->ibqp.qp_type))) in rvt_qp_valid_operation()
1872 return -EINVAL; in rvt_qp_valid_operation()
1873 if ((post_parms[wr->opcode].flags & RVT_OPERATION_PRIV) && in rvt_qp_valid_operation()
1874 ibpd_to_rvtpd(qp->ibqp.pd)->user) in rvt_qp_valid_operation()
1875 return -EINVAL; in rvt_qp_valid_operation()
1876 if (post_parms[wr->opcode].flags & RVT_OPERATION_ATOMIC_SGE && in rvt_qp_valid_operation()
1877 (wr->num_sge == 0 || in rvt_qp_valid_operation()
1878 wr->sg_list[0].length < sizeof(u64) || in rvt_qp_valid_operation()
1879 wr->sg_list[0].addr & (sizeof(u64) - 1))) in rvt_qp_valid_operation()
1880 return -EINVAL; in rvt_qp_valid_operation()
1881 if (post_parms[wr->opcode].flags & RVT_OPERATION_ATOMIC && in rvt_qp_valid_operation()
1882 !qp->s_max_rd_atomic) in rvt_qp_valid_operation()
1883 return -EINVAL; in rvt_qp_valid_operation()
1884 len = post_parms[wr->opcode].length; in rvt_qp_valid_operation()
1886 if (qp->ibqp.qp_type != IB_QPT_UC && in rvt_qp_valid_operation()
1887 qp->ibqp.qp_type != IB_QPT_RC) { in rvt_qp_valid_operation()
1888 if (qp->ibqp.pd != ud_wr(wr)->ah->pd) in rvt_qp_valid_operation()
1889 return -EINVAL; in rvt_qp_valid_operation()
1896 * rvt_qp_is_avail - determine queue capacity
1904 * For non reserved operations, the qp->s_avail
1907 * The return value is zero or a -ENOMEM.
1922 reserved_used = atomic_read(&qp->s_reserved_used); in rvt_qp_is_avail()
1923 if (reserved_used >= rdi->dparms.reserved_operations) in rvt_qp_is_avail()
1924 return -ENOMEM; in rvt_qp_is_avail()
1927 /* non-reserved operations */ in rvt_qp_is_avail()
1928 if (likely(qp->s_avail)) in rvt_qp_is_avail()
1931 slast = smp_load_acquire(&qp->s_last); in rvt_qp_is_avail()
1932 if (qp->s_head >= slast) in rvt_qp_is_avail()
1933 avail = qp->s_size - (qp->s_head - slast); in rvt_qp_is_avail()
1935 avail = slast - qp->s_head; in rvt_qp_is_avail()
1937 reserved_used = atomic_read(&qp->s_reserved_used); in rvt_qp_is_avail()
1938 avail = avail - 1 - in rvt_qp_is_avail()
1939 (rdi->dparms.reserved_operations - reserved_used); in rvt_qp_is_avail()
1942 return -ENOMEM; in rvt_qp_is_avail()
1943 qp->s_avail = avail; in rvt_qp_is_avail()
1944 if (WARN_ON(qp->s_avail > in rvt_qp_is_avail()
1945 (qp->s_size - 1 - rdi->dparms.reserved_operations))) in rvt_qp_is_avail()
1948 qp->ibqp.qp_num, qp->s_size, qp->s_avail, in rvt_qp_is_avail()
1949 qp->s_head, qp->s_tail, qp->s_cur, in rvt_qp_is_avail()
1950 qp->s_acked, qp->s_last); in rvt_qp_is_avail()
1955 * rvt_post_one_wr - post one RC, UC, or UD send work request
1971 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_post_one_wr()
1981 if (unlikely(wr->num_sge > qp->s_max_sge)) in rvt_post_one_wr()
1982 return -EINVAL; in rvt_post_one_wr()
1984 ret = rvt_qp_valid_operation(qp, rdi->post_parms, wr); in rvt_post_one_wr()
1995 * not required and no previous local invalidate ops are pending. in rvt_post_one_wr()
2000 if ((rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL)) { in rvt_post_one_wr()
2001 switch (wr->opcode) { in rvt_post_one_wr()
2004 reg_wr(wr)->mr, in rvt_post_one_wr()
2005 reg_wr(wr)->key, in rvt_post_one_wr()
2006 reg_wr(wr)->access); in rvt_post_one_wr()
2007 if (ret || !(wr->send_flags & IB_SEND_SIGNALED)) in rvt_post_one_wr()
2011 if ((wr->send_flags & IB_SEND_FENCE) || in rvt_post_one_wr()
2012 atomic_read(&qp->local_ops_pending)) { in rvt_post_one_wr()
2016 qp, wr->ex.invalidate_rkey); in rvt_post_one_wr()
2017 if (ret || !(wr->send_flags & IB_SEND_SIGNALED)) in rvt_post_one_wr()
2022 return -EINVAL; in rvt_post_one_wr()
2026 reserved_op = rdi->post_parms[wr->opcode].flags & in rvt_post_one_wr()
2032 next = qp->s_head + 1; in rvt_post_one_wr()
2033 if (next >= qp->s_size) in rvt_post_one_wr()
2036 rkt = &rdi->lkey_table; in rvt_post_one_wr()
2037 pd = ibpd_to_rvtpd(qp->ibqp.pd); in rvt_post_one_wr()
2038 wqe = rvt_get_swqe_ptr(qp, qp->s_head); in rvt_post_one_wr()
2041 memcpy(&wqe->ud_wr, wr, cplen); in rvt_post_one_wr()
2043 wqe->length = 0; in rvt_post_one_wr()
2045 if (wr->num_sge) { in rvt_post_one_wr()
2048 acc = wr->opcode >= IB_WR_RDMA_READ ? in rvt_post_one_wr()
2050 for (i = 0; i < wr->num_sge; i++) { in rvt_post_one_wr()
2051 u32 length = wr->sg_list[i].length; in rvt_post_one_wr()
2055 ret = rvt_lkey_ok(rkt, pd, &wqe->sg_list[j], last_sge, in rvt_post_one_wr()
2056 &wr->sg_list[i], acc); in rvt_post_one_wr()
2059 wqe->length += length; in rvt_post_one_wr()
2061 last_sge = &wqe->sg_list[j]; in rvt_post_one_wr()
2064 wqe->wr.num_sge = j; in rvt_post_one_wr()
2072 log_pmtu = qp->log_pmtu; in rvt_post_one_wr()
2073 if (qp->allowed_ops == IB_OPCODE_UD) { in rvt_post_one_wr()
2076 log_pmtu = ah->log_pmtu; in rvt_post_one_wr()
2077 rdma_copy_ah_attr(wqe->ud_wr.attr, &ah->attr); in rvt_post_one_wr()
2080 if (rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL) { in rvt_post_one_wr()
2082 atomic_inc(&qp->local_ops_pending); in rvt_post_one_wr()
2084 wqe->wr.send_flags |= RVT_SEND_COMPLETION_ONLY; in rvt_post_one_wr()
2085 wqe->ssn = 0; in rvt_post_one_wr()
2086 wqe->psn = 0; in rvt_post_one_wr()
2087 wqe->lpsn = 0; in rvt_post_one_wr()
2089 wqe->ssn = qp->s_ssn++; in rvt_post_one_wr()
2090 wqe->psn = qp->s_next_psn; in rvt_post_one_wr()
2091 wqe->lpsn = wqe->psn + in rvt_post_one_wr()
2092 (wqe->length ? in rvt_post_one_wr()
2093 ((wqe->length - 1) >> log_pmtu) : in rvt_post_one_wr()
2097 /* general part of wqe valid - allow for driver checks */ in rvt_post_one_wr()
2098 if (rdi->driver_f.setup_wqe) { in rvt_post_one_wr()
2099 ret = rdi->driver_f.setup_wqe(qp, wqe, call_send); in rvt_post_one_wr()
2104 if (!(rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL)) in rvt_post_one_wr()
2105 qp->s_next_psn = wqe->lpsn + 1; in rvt_post_one_wr()
2108 wqe->wr.send_flags |= RVT_SEND_RESERVE_USED; in rvt_post_one_wr()
2111 wqe->wr.send_flags &= ~RVT_SEND_RESERVE_USED; in rvt_post_one_wr()
2112 qp->s_avail--; in rvt_post_one_wr()
2114 trace_rvt_post_one_wr(qp, wqe, wr->num_sge); in rvt_post_one_wr()
2116 qp->s_head = next; in rvt_post_one_wr()
2121 if (qp->allowed_ops == IB_OPCODE_UD) in rvt_post_one_wr()
2122 rdma_destroy_ah_attr(wqe->ud_wr.attr); in rvt_post_one_wr()
2126 struct rvt_sge *sge = &wqe->sg_list[--j]; in rvt_post_one_wr()
2128 rvt_put_mr(sge->mr); in rvt_post_one_wr()
2134 * rvt_post_send - post a send on a QP
2147 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_post_send()
2153 spin_lock_irqsave(&qp->s_hlock, flags); in rvt_post_send()
2157 * there is no need to do this every time we post a send. in rvt_post_send()
2159 if (unlikely(!(ib_rvt_state_ops[qp->state] & RVT_POST_SEND_OK))) { in rvt_post_send()
2160 spin_unlock_irqrestore(&qp->s_hlock, flags); in rvt_post_send()
2161 return -EINVAL; in rvt_post_send()
2169 call_send = qp->s_head == READ_ONCE(qp->s_last) && !wr->next; in rvt_post_send()
2171 for (; wr; wr = wr->next) { in rvt_post_send()
2180 spin_unlock_irqrestore(&qp->s_hlock, flags); in rvt_post_send()
2187 rdi->driver_f.do_send(qp); in rvt_post_send()
2189 rdi->driver_f.schedule_send_no_lock(qp); in rvt_post_send()
2195 * rvt_post_srq_recv - post a receive on a shared receive queue
2211 for (; wr; wr = wr->next) { in rvt_post_srq_recv()
2216 if ((unsigned)wr->num_sge > srq->rq.max_sge) { in rvt_post_srq_recv()
2218 return -EINVAL; in rvt_post_srq_recv()
2221 spin_lock_irqsave(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2222 wq = srq->rq.kwq; in rvt_post_srq_recv()
2223 next = wq->head + 1; in rvt_post_srq_recv()
2224 if (next >= srq->rq.size) in rvt_post_srq_recv()
2226 if (next == READ_ONCE(wq->tail)) { in rvt_post_srq_recv()
2227 spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2229 return -ENOMEM; in rvt_post_srq_recv()
2232 wqe = rvt_get_rwqe_ptr(&srq->rq, wq->head); in rvt_post_srq_recv()
2233 wqe->wr_id = wr->wr_id; in rvt_post_srq_recv()
2234 wqe->num_sge = wr->num_sge; in rvt_post_srq_recv()
2235 for (i = 0; i < wr->num_sge; i++) { in rvt_post_srq_recv()
2236 wqe->sg_list[i].addr = wr->sg_list[i].addr; in rvt_post_srq_recv()
2237 wqe->sg_list[i].length = wr->sg_list[i].length; in rvt_post_srq_recv()
2238 wqe->sg_list[i].lkey = wr->sg_list[i].lkey; in rvt_post_srq_recv()
2241 smp_store_release(&wq->head, next); in rvt_post_srq_recv()
2242 spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2270 struct ib_wc wc; in init_sge() local
2274 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in init_sge()
2276 rkt = &rdi->lkey_table; in init_sge()
2277 pd = ibpd_to_rvtpd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd); in init_sge()
2278 ss = &qp->r_sge; in init_sge()
2279 ss->sg_list = qp->r_sg_list; in init_sge()
2280 qp->r_len = 0; in init_sge()
2281 for (i = j = 0; i < wqe->num_sge; i++) { in init_sge()
2282 if (wqe->sg_list[i].length == 0) in init_sge()
2285 ret = rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge, in init_sge()
2286 NULL, rvt_cast_sge(&wqe->sg_list[i]), in init_sge()
2290 qp->r_len += wqe->sg_list[i].length; in init_sge()
2293 ss->num_sge = j; in init_sge()
2294 ss->total_len = qp->r_len; in init_sge()
2299 struct rvt_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge; in init_sge()
2301 rvt_put_mr(sge->mr); in init_sge()
2303 ss->num_sge = 0; in init_sge()
2304 memset(&wc, 0, sizeof(wc)); in init_sge()
2305 wc.wr_id = wqe->wr_id; in init_sge()
2306 wc.status = IB_WC_LOC_PROT_ERR; in init_sge()
2307 wc.opcode = IB_WC_RECV; in init_sge()
2308 wc.qp = &qp->ibqp; in init_sge()
2310 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in init_sge()
2315 * get_rvt_head - get head indices of the circular buffer
2319 * Return - head index value
2326 head = RDMA_READ_UAPI_ATOMIC(rq->wq->head); in get_rvt_head()
2328 head = rq->kwq->head; in get_rvt_head()
2334 * rvt_get_rwqe - copy the next RWQE into the QP's RWQE
2336 * @wr_id_only: update qp->r_wr_id only, not qp->r_sge
2338 * Return -1 if there is a local error, 0 if no RWQE is available,
2357 if (qp->ibqp.srq) { in rvt_get_rwqe()
2358 srq = ibsrq_to_rvtsrq(qp->ibqp.srq); in rvt_get_rwqe()
2359 handler = srq->ibsrq.event_handler; in rvt_get_rwqe()
2360 rq = &srq->rq; in rvt_get_rwqe()
2361 ip = srq->ip; in rvt_get_rwqe()
2365 rq = &qp->r_rq; in rvt_get_rwqe()
2366 ip = qp->ip; in rvt_get_rwqe()
2369 spin_lock_irqsave(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2370 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) { in rvt_get_rwqe()
2374 kwq = rq->kwq; in rvt_get_rwqe()
2376 wq = rq->wq; in rvt_get_rwqe()
2377 tail = RDMA_READ_UAPI_ATOMIC(wq->tail); in rvt_get_rwqe()
2379 tail = kwq->tail; in rvt_get_rwqe()
2383 if (tail >= rq->size) in rvt_get_rwqe()
2386 if (kwq->count < RVT_RWQ_COUNT_THRESHOLD) { in rvt_get_rwqe()
2388 kwq->count = rvt_get_rq_count(rq, head, tail); in rvt_get_rwqe()
2390 if (unlikely(kwq->count == 0)) { in rvt_get_rwqe()
2398 * Even though we update the tail index in memory, the verbs in rvt_get_rwqe()
2402 if (++tail >= rq->size) in rvt_get_rwqe()
2405 RDMA_WRITE_UAPI_ATOMIC(wq->tail, tail); in rvt_get_rwqe()
2407 kwq->tail = tail; in rvt_get_rwqe()
2409 ret = -1; in rvt_get_rwqe()
2412 qp->r_wr_id = wqe->wr_id; in rvt_get_rwqe()
2414 kwq->count--; in rvt_get_rwqe()
2416 set_bit(RVT_R_WRID_VALID, &qp->r_aflags); in rvt_get_rwqe()
2422 if (kwq->count < srq->limit) { in rvt_get_rwqe()
2423 kwq->count = in rvt_get_rwqe()
2426 if (kwq->count < srq->limit) { in rvt_get_rwqe()
2429 srq->limit = 0; in rvt_get_rwqe()
2430 spin_unlock_irqrestore(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2431 ev.device = qp->ibqp.device; in rvt_get_rwqe()
2432 ev.element.srq = qp->ibqp.srq; in rvt_get_rwqe()
2434 handler(&ev, srq->ibsrq.srq_context); in rvt_get_rwqe()
2440 spin_unlock_irqrestore(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2447 * rvt_comm_est - handle trap with QP established
2452 qp->r_flags |= RVT_R_COMM_EST; in rvt_comm_est()
2453 if (qp->ibqp.event_handler) { in rvt_comm_est()
2456 ev.device = qp->ibqp.device; in rvt_comm_est()
2457 ev.element.qp = &qp->ibqp; in rvt_comm_est()
2459 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_comm_est()
2469 spin_lock_irqsave(&qp->s_lock, flags); in rvt_rc_error()
2471 spin_unlock_irqrestore(&qp->s_lock, flags); in rvt_rc_error()
2476 ev.device = qp->ibqp.device; in rvt_rc_error()
2477 ev.element.qp = &qp->ibqp; in rvt_rc_error()
2479 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_rc_error()
2485 * rvt_rnr_tbl_to_usec - return index into ib_rvt_rnr_table
2486 * @index - the index
2502 * rvt_add_retry_timer_ext - add/start a retry timer
2503 * @qp - the QP
2504 * @shift - timeout shift to wait for multiple packets
2509 struct ib_qp *ibqp = &qp->ibqp; in rvt_add_retry_timer_ext()
2510 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_add_retry_timer_ext()
2512 lockdep_assert_held(&qp->s_lock); in rvt_add_retry_timer_ext()
2513 qp->s_flags |= RVT_S_TIMER; in rvt_add_retry_timer_ext()
2514 /* 4.096 usec. * (1 << qp->timeout) */ in rvt_add_retry_timer_ext()
2515 qp->s_timer.expires = jiffies + rdi->busy_jiffies + in rvt_add_retry_timer_ext()
2516 (qp->timeout_jiffies << shift); in rvt_add_retry_timer_ext()
2517 add_timer(&qp->s_timer); in rvt_add_retry_timer_ext()
2522 * rvt_add_rnr_timer - add/start an rnr timer on the QP
2530 lockdep_assert_held(&qp->s_lock); in rvt_add_rnr_timer()
2531 qp->s_flags |= RVT_S_WAIT_RNR; in rvt_add_rnr_timer()
2534 hrtimer_start(&qp->s_rnr_timer, in rvt_add_rnr_timer()
2540 * rvt_stop_rc_timers - stop all timers
2546 lockdep_assert_held(&qp->s_lock); in rvt_stop_rc_timers()
2548 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) { in rvt_stop_rc_timers()
2549 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR); in rvt_stop_rc_timers()
2550 del_timer(&qp->s_timer); in rvt_stop_rc_timers()
2551 hrtimer_try_to_cancel(&qp->s_rnr_timer); in rvt_stop_rc_timers()
2557 * rvt_stop_rnr_timer - stop an rnr timer
2565 lockdep_assert_held(&qp->s_lock); in rvt_stop_rnr_timer()
2567 if (qp->s_flags & RVT_S_WAIT_RNR) { in rvt_stop_rnr_timer()
2568 qp->s_flags &= ~RVT_S_WAIT_RNR; in rvt_stop_rnr_timer()
2574 * rvt_del_timers_sync - wait for any timeout routines to exit
2579 del_timer_sync(&qp->s_timer); in rvt_del_timers_sync()
2580 hrtimer_cancel(&qp->s_rnr_timer); in rvt_del_timers_sync()
2590 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_rc_timeout()
2593 spin_lock_irqsave(&qp->r_lock, flags); in rvt_rc_timeout()
2594 spin_lock(&qp->s_lock); in rvt_rc_timeout()
2595 if (qp->s_flags & RVT_S_TIMER) { in rvt_rc_timeout()
2596 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_rc_timeout()
2598 qp->s_flags &= ~RVT_S_TIMER; in rvt_rc_timeout()
2599 rvp->n_rc_timeouts++; in rvt_rc_timeout()
2600 del_timer(&qp->s_timer); in rvt_rc_timeout()
2601 trace_rvt_rc_timeout(qp, qp->s_last_psn + 1); in rvt_rc_timeout()
2602 if (rdi->driver_f.notify_restart_rc) in rvt_rc_timeout()
2603 rdi->driver_f.notify_restart_rc(qp, in rvt_rc_timeout()
2604 qp->s_last_psn + 1, in rvt_rc_timeout()
2606 rdi->driver_f.schedule_send(qp); in rvt_rc_timeout()
2608 spin_unlock(&qp->s_lock); in rvt_rc_timeout()
2609 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_rc_timeout()
2618 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_rc_rnr_retry()
2621 spin_lock_irqsave(&qp->s_lock, flags); in rvt_rc_rnr_retry()
2624 rdi->driver_f.schedule_send(qp); in rvt_rc_rnr_retry()
2625 spin_unlock_irqrestore(&qp->s_lock, flags); in rvt_rc_rnr_retry()
2631 * rvt_qp_iter_init - initial for QP iteration
2634 * @cb: user-defined callback
2639 * The @cb is a user-defined callback and @v is a 64-bit
2644 * Use cases that require memory allocation to succeed
2659 i->rdi = rdi; in rvt_qp_iter_init()
2661 i->specials = rdi->ibdev.phys_port_cnt * 2; in rvt_qp_iter_init()
2662 i->v = v; in rvt_qp_iter_init()
2663 i->cb = cb; in rvt_qp_iter_init()
2670 * rvt_qp_iter_next - return the next QP in iter
2676 * Updates iter->qp with the current QP when the return
2679 * Return: 0 - iter->qp is valid 1 - no more QPs
2684 int n = iter->n; in rvt_qp_iter_next()
2686 struct rvt_qp *pqp = iter->qp; in rvt_qp_iter_next()
2688 struct rvt_dev_info *rdi = iter->rdi; in rvt_qp_iter_next()
2694 * the qp->next hash link to NULL, this works just fine. in rvt_qp_iter_next()
2696 * iter->specials is 2 * # ports in rvt_qp_iter_next()
2698 * n = 0..iter->specials is the special qp indices in rvt_qp_iter_next()
2700 * n = iter->specials..rdi->qp_dev->qp_table_size+iter->specials are in rvt_qp_iter_next()
2704 for (; n < rdi->qp_dev->qp_table_size + iter->specials; n++) { in rvt_qp_iter_next()
2706 qp = rcu_dereference(pqp->next); in rvt_qp_iter_next()
2708 if (n < iter->specials) { in rvt_qp_iter_next()
2712 pidx = n % rdi->ibdev.phys_port_cnt; in rvt_qp_iter_next()
2713 rvp = rdi->ports[pidx]; in rvt_qp_iter_next()
2714 qp = rcu_dereference(rvp->qp[n & 1]); in rvt_qp_iter_next()
2717 rdi->qp_dev->qp_table[ in rvt_qp_iter_next()
2718 (n - iter->specials)]); in rvt_qp_iter_next()
2723 iter->qp = qp; in rvt_qp_iter_next()
2724 iter->n = n; in rvt_qp_iter_next()
2733 * rvt_qp_iter - iterate all QPs
2735 * @v: a 64-bit value
2740 * The @cb is a user-defined callback and @v is a 64-bit
2755 .specials = rdi->ibdev.phys_port_cnt * 2, in rvt_qp_iter()
2784 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND)) in rvt_send_complete()
2786 rdi = ib_to_rvt(qp->ibqp.device); in rvt_send_complete()
2788 old_last = qp->s_last; in rvt_send_complete()
2790 last = rvt_qp_complete_swqe(qp, wqe, rdi->wc_opcode[wqe->wr.opcode], in rvt_send_complete()
2792 if (qp->s_acked == old_last) in rvt_send_complete()
2793 qp->s_acked = last; in rvt_send_complete()
2794 if (qp->s_cur == old_last) in rvt_send_complete()
2795 qp->s_cur = last; in rvt_send_complete()
2796 if (qp->s_tail == old_last) in rvt_send_complete()
2797 qp->s_tail = last; in rvt_send_complete()
2798 if (qp->state == IB_QPS_SQD && last == qp->s_cur) in rvt_send_complete()
2799 qp->s_draining = 0; in rvt_send_complete()
2804 * rvt_copy_sge - copy data to SGE memory
2816 struct rvt_sge *sge = &ss->sge; in rvt_copy_sge()
2820 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_copy_sge()
2821 struct rvt_wss *wss = rdi->wss; in rvt_copy_sge()
2822 unsigned int sge_copy_mode = rdi->dparms.sge_copy_mode; in rvt_copy_sge()
2833 wss_insert(wss, sge->vaddr); in rvt_copy_sge()
2835 wss_insert(wss, (sge->vaddr + PAGE_SIZE)); in rvt_copy_sge()
2845 length -= 8; in rvt_copy_sge()
2860 ((u8 *)sge->vaddr)[i] = ((u8 *)data)[i]; in rvt_copy_sge()
2862 cacheless_memcpy(sge->vaddr, data, len); in rvt_copy_sge()
2864 memcpy(sge->vaddr, data, len); in rvt_copy_sge()
2868 length -= len; in rvt_copy_sge()
2883 rvp->n_pkt_drops++; in loopback_qp_drop()
2888 return sqp->ibqp.qp_type == IB_QPT_RC ? in loopback_qp_drop()
2893 * rvt_ruc_loopback - handle UC and RC loopback requests
2905 struct rvt_dev_info *rdi = ib_to_rvt(sqp->ibqp.device); in rvt_ruc_loopback()
2910 struct ib_wc wc; in rvt_ruc_loopback() local
2920 rvp = rdi->ports[sqp->port_num - 1]; in rvt_ruc_loopback()
2927 qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), rvp, in rvt_ruc_loopback()
2928 sqp->remote_qpn); in rvt_ruc_loopback()
2930 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
2933 if ((sqp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT)) || in rvt_ruc_loopback()
2934 !(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_OR_FLUSH_SEND)) in rvt_ruc_loopback()
2937 sqp->s_flags |= RVT_S_BUSY; in rvt_ruc_loopback()
2940 if (sqp->s_last == READ_ONCE(sqp->s_head)) in rvt_ruc_loopback()
2942 wqe = rvt_get_swqe_ptr(sqp, sqp->s_last); in rvt_ruc_loopback()
2945 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_NEXT_SEND_OK)) { in rvt_ruc_loopback()
2946 if (!(ib_rvt_state_ops[sqp->state] & RVT_FLUSH_SEND)) in rvt_ruc_loopback()
2958 if (sqp->s_last == sqp->s_cur) { in rvt_ruc_loopback()
2959 if (++sqp->s_cur >= sqp->s_size) in rvt_ruc_loopback()
2960 sqp->s_cur = 0; in rvt_ruc_loopback()
2962 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()
2968 spin_lock_irqsave(&qp->r_lock, flags); in rvt_ruc_loopback()
2969 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) || in rvt_ruc_loopback()
2970 qp->ibqp.qp_type != sqp->ibqp.qp_type) { in rvt_ruc_loopback()
2975 memset(&wc, 0, sizeof(wc)); in rvt_ruc_loopback()
2979 sqp->s_sge.sge = wqe->sg_list[0]; in rvt_ruc_loopback()
2980 sqp->s_sge.sg_list = wqe->sg_list + 1; in rvt_ruc_loopback()
2981 sqp->s_sge.num_sge = wqe->wr.num_sge; in rvt_ruc_loopback()
2982 sqp->s_len = wqe->length; in rvt_ruc_loopback()
2983 switch (wqe->wr.opcode) { in rvt_ruc_loopback()
2988 if (!(wqe->wr.send_flags & RVT_SEND_COMPLETION_ONLY)) { in rvt_ruc_loopback()
2990 wqe->wr.ex.invalidate_rkey)) in rvt_ruc_loopback()
3004 if (wqe->length > qp->r_len) in rvt_ruc_loopback()
3006 switch (wqe->wr.opcode) { in rvt_ruc_loopback()
3009 wqe->wr.ex.invalidate_rkey)) { in rvt_ruc_loopback()
3010 wc.wc_flags = IB_WC_WITH_INVALIDATE; in rvt_ruc_loopback()
3011 wc.ex.invalidate_rkey = in rvt_ruc_loopback()
3012 wqe->wr.ex.invalidate_rkey; in rvt_ruc_loopback()
3016 wc.wc_flags = IB_WC_WITH_IMM; in rvt_ruc_loopback()
3017 wc.ex.imm_data = wqe->wr.ex.imm_data; in rvt_ruc_loopback()
3025 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) in rvt_ruc_loopback()
3027 wc.wc_flags = IB_WC_WITH_IMM; in rvt_ruc_loopback()
3028 wc.ex.imm_data = wqe->wr.ex.imm_data; in rvt_ruc_loopback()
3038 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) in rvt_ruc_loopback()
3041 if (wqe->length == 0) in rvt_ruc_loopback()
3043 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, wqe->length, in rvt_ruc_loopback()
3044 wqe->rdma_wr.remote_addr, in rvt_ruc_loopback()
3045 wqe->rdma_wr.rkey, in rvt_ruc_loopback()
3048 qp->r_sge.sg_list = NULL; in rvt_ruc_loopback()
3049 qp->r_sge.num_sge = 1; in rvt_ruc_loopback()
3050 qp->r_sge.total_len = wqe->length; in rvt_ruc_loopback()
3054 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ))) in rvt_ruc_loopback()
3056 if (unlikely(!rvt_rkey_ok(qp, &sqp->s_sge.sge, wqe->length, in rvt_ruc_loopback()
3057 wqe->rdma_wr.remote_addr, in rvt_ruc_loopback()
3058 wqe->rdma_wr.rkey, in rvt_ruc_loopback()
3062 sqp->s_sge.sg_list = NULL; in rvt_ruc_loopback()
3063 sqp->s_sge.num_sge = 1; in rvt_ruc_loopback()
3064 qp->r_sge.sge = wqe->sg_list[0]; in rvt_ruc_loopback()
3065 qp->r_sge.sg_list = wqe->sg_list + 1; in rvt_ruc_loopback()
3066 qp->r_sge.num_sge = wqe->wr.num_sge; in rvt_ruc_loopback()
3067 qp->r_sge.total_len = wqe->length; in rvt_ruc_loopback()
3072 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC))) in rvt_ruc_loopback()
3074 if (unlikely(wqe->atomic_wr.remote_addr & (sizeof(u64) - 1))) in rvt_ruc_loopback()
3076 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64), in rvt_ruc_loopback()
3077 wqe->atomic_wr.remote_addr, in rvt_ruc_loopback()
3078 wqe->atomic_wr.rkey, in rvt_ruc_loopback()
3082 maddr = (atomic64_t *)qp->r_sge.sge.vaddr; in rvt_ruc_loopback()
3083 sdata = wqe->atomic_wr.compare_add; in rvt_ruc_loopback()
3084 *(u64 *)sqp->s_sge.sge.vaddr = in rvt_ruc_loopback()
3085 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ? in rvt_ruc_loopback()
3086 (u64)atomic64_add_return(sdata, maddr) - sdata : in rvt_ruc_loopback()
3087 (u64)cmpxchg((u64 *)qp->r_sge.sge.vaddr, in rvt_ruc_loopback()
3088 sdata, wqe->atomic_wr.swap); in rvt_ruc_loopback()
3089 rvt_put_mr(qp->r_sge.sge.mr); in rvt_ruc_loopback()
3090 qp->r_sge.num_sge = 0; in rvt_ruc_loopback()
3098 sge = &sqp->s_sge.sge; in rvt_ruc_loopback()
3099 while (sqp->s_len) { in rvt_ruc_loopback()
3100 u32 len = rvt_get_sge_length(sge, sqp->s_len); in rvt_ruc_loopback()
3103 rvt_copy_sge(qp, &qp->r_sge, sge->vaddr, in rvt_ruc_loopback()
3105 rvt_update_sge(&sqp->s_sge, len, !release); in rvt_ruc_loopback()
3106 sqp->s_len -= len; in rvt_ruc_loopback()
3109 rvt_put_ss(&qp->r_sge); in rvt_ruc_loopback()
3111 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) in rvt_ruc_loopback()
3114 if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM) in rvt_ruc_loopback()
3115 wc.opcode = IB_WC_RECV_RDMA_WITH_IMM; in rvt_ruc_loopback()
3117 wc.opcode = IB_WC_RECV; in rvt_ruc_loopback()
3118 wc.wr_id = qp->r_wr_id; in rvt_ruc_loopback()
3119 wc.status = IB_WC_SUCCESS; in rvt_ruc_loopback()
3120 wc.byte_len = wqe->length; in rvt_ruc_loopback()
3121 wc.qp = &qp->ibqp; in rvt_ruc_loopback()
3122 wc.src_qp = qp->remote_qpn; in rvt_ruc_loopback()
3123 wc.slid = rdma_ah_get_dlid(&qp->remote_ah_attr) & U16_MAX; in rvt_ruc_loopback()
3124 wc.sl = rdma_ah_get_sl(&qp->remote_ah_attr); in rvt_ruc_loopback()
3125 wc.port_num = 1; in rvt_ruc_loopback()
3127 rvt_recv_cq(qp, &wc, wqe->wr.send_flags & IB_SEND_SOLICITED); in rvt_ruc_loopback()
3130 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_ruc_loopback()
3131 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
3132 rvp->n_loop_pkts++; in rvt_ruc_loopback()
3134 sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; in rvt_ruc_loopback()
3135 spin_lock(&sqp->r_lock); in rvt_ruc_loopback()
3137 spin_unlock(&sqp->r_lock); in rvt_ruc_loopback()
3139 atomic_dec(&sqp->local_ops_pending); in rvt_ruc_loopback()
3146 if (qp->ibqp.qp_type == IB_QPT_UC) in rvt_ruc_loopback()
3148 rvp->n_rnr_naks++; in rvt_ruc_loopback()
3153 if (sqp->s_rnr_retry == 0) { in rvt_ruc_loopback()
3157 if (sqp->s_rnr_retry_cnt < 7) in rvt_ruc_loopback()
3158 sqp->s_rnr_retry--; in rvt_ruc_loopback()
3159 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_ruc_loopback()
3160 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
3161 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_RECV_OK)) in rvt_ruc_loopback()
3163 rvt_add_rnr_timer(sqp, qp->r_min_rnr_timer << in rvt_ruc_loopback()
3169 wc.status = IB_WC_LOC_QP_OP_ERR; in rvt_ruc_loopback()
3174 sqp->ibqp.qp_type == IB_QPT_RC ? in rvt_ruc_loopback()
3177 wc.status = IB_WC_LOC_QP_OP_ERR; in rvt_ruc_loopback()
3182 wc.status = IB_WC_LOC_PROT_ERR; in rvt_ruc_loopback()
3185 rvt_rc_error(qp, wc.status); in rvt_ruc_loopback()
3188 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_ruc_loopback()
3190 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
3191 spin_lock(&sqp->r_lock); in rvt_ruc_loopback()
3193 spin_unlock(&sqp->r_lock); in rvt_ruc_loopback()
3194 if (sqp->ibqp.qp_type == IB_QPT_RC) { in rvt_ruc_loopback()
3197 spin_lock(&sqp->r_lock); in rvt_ruc_loopback()
3199 spin_unlock(&sqp->r_lock); in rvt_ruc_loopback()
3201 sqp->s_flags &= ~RVT_S_BUSY; in rvt_ruc_loopback()
3202 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()
3206 ev.device = sqp->ibqp.device; in rvt_ruc_loopback()
3207 ev.element.qp = &sqp->ibqp; in rvt_ruc_loopback()
3209 sqp->ibqp.event_handler(&ev, sqp->ibqp.qp_context); in rvt_ruc_loopback()
3214 sqp->s_flags &= ~RVT_S_BUSY; in rvt_ruc_loopback()
3216 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()