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()
467 if (!rdi->qp_dev) in rvt_qp_exit()
470 kfree(rdi->qp_dev->qp_table); in rvt_qp_exit()
471 free_qpn_table(&rdi->qp_dev->qpn_table); in rvt_qp_exit()
472 kfree(rdi->qp_dev); in rvt_qp_exit()
478 return (map - qpt->map) * RVT_BITS_PER_PAGE + off; in mk_qpn()
482 * alloc_qpn - Allocate the next available qpn or zero/one for QP type
501 if (rdi->driver_f.alloc_qpn) in alloc_qpn()
502 return rdi->driver_f.alloc_qpn(rdi, qpt, type, port_num); in alloc_qpn()
508 n = 1 << (ret + 2 * (port_num - 1)); in alloc_qpn()
509 spin_lock(&qpt->lock); in alloc_qpn()
510 if (qpt->flags & n) in alloc_qpn()
511 ret = -EINVAL; in alloc_qpn()
513 qpt->flags |= n; in alloc_qpn()
514 spin_unlock(&qpt->lock); in alloc_qpn()
518 qpn = qpt->last + qpt->incr; in alloc_qpn()
520 qpn = qpt->incr | ((qpt->last & 1) ^ 1); in alloc_qpn()
523 map = &qpt->map[qpn / RVT_BITS_PER_PAGE]; in alloc_qpn()
524 max_scan = qpt->nmaps - !offset; in alloc_qpn()
526 if (unlikely(!map->page)) { in alloc_qpn()
528 if (unlikely(!map->page)) in alloc_qpn()
532 if (!test_and_set_bit(offset, map->page)) { in alloc_qpn()
533 qpt->last = qpn; in alloc_qpn()
537 offset += qpt->incr; in alloc_qpn()
540 * That is OK. It gets re-assigned below in alloc_qpn()
550 if (qpt->nmaps == RVT_QPNMAP_ENTRIES) in alloc_qpn()
552 map = &qpt->map[qpt->nmaps++]; in alloc_qpn()
554 offset = qpt->incr | (offset & 1); in alloc_qpn()
555 } else if (map < &qpt->map[qpt->nmaps]) { in alloc_qpn()
558 offset = qpt->incr | (offset & 1); in alloc_qpn()
560 map = &qpt->map[0]; in alloc_qpn()
562 offset = qpt->incr | ((offset & 1) ^ 1); in alloc_qpn()
564 /* there can be no set bits in low-order QoS bits */ in alloc_qpn()
565 WARN_ON(rdi->dparms.qos_shift > 1 && in alloc_qpn()
566 offset & ((BIT(rdi->dparms.qos_shift - 1) - 1) << 1)); in alloc_qpn()
570 ret = -ENOMEM; in alloc_qpn()
577 * rvt_clear_mr_refs - Drop help mr refs
584 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_clear_mr_refs()
586 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags)) in rvt_clear_mr_refs()
587 rvt_put_ss(&qp->s_rdma_read_sge); in rvt_clear_mr_refs()
589 rvt_put_ss(&qp->r_sge); in rvt_clear_mr_refs()
592 while (qp->s_last != qp->s_head) { in rvt_clear_mr_refs()
593 struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_last); in rvt_clear_mr_refs()
596 if (++qp->s_last >= qp->s_size) in rvt_clear_mr_refs()
597 qp->s_last = 0; in rvt_clear_mr_refs()
600 if (qp->s_rdma_mr) { in rvt_clear_mr_refs()
601 rvt_put_mr(qp->s_rdma_mr); in rvt_clear_mr_refs()
602 qp->s_rdma_mr = NULL; in rvt_clear_mr_refs()
606 for (n = 0; qp->s_ack_queue && n < rvt_max_atomic(rdi); n++) { in rvt_clear_mr_refs()
607 struct rvt_ack_entry *e = &qp->s_ack_queue[n]; in rvt_clear_mr_refs()
609 if (e->rdma_sge.mr) { in rvt_clear_mr_refs()
610 rvt_put_mr(e->rdma_sge.mr); in rvt_clear_mr_refs()
611 e->rdma_sge.mr = NULL; in rvt_clear_mr_refs()
617 * rvt_swqe_has_lkey - return true if lkey is used by swqe
627 for (i = 0; i < wqe->wr.num_sge; i++) { in rvt_swqe_has_lkey()
628 struct rvt_sge *sge = &wqe->sg_list[i]; in rvt_swqe_has_lkey()
630 if (rvt_mr_has_lkey(sge->mr, lkey)) in rvt_swqe_has_lkey()
637 * rvt_qp_sends_has_lkey - return true is qp sends use lkey
643 u32 s_last = qp->s_last; in rvt_qp_sends_has_lkey()
645 while (s_last != qp->s_head) { in rvt_qp_sends_has_lkey()
651 if (++s_last >= qp->s_size) in rvt_qp_sends_has_lkey()
654 if (qp->s_rdma_mr) in rvt_qp_sends_has_lkey()
655 if (rvt_mr_has_lkey(qp->s_rdma_mr, lkey)) in rvt_qp_sends_has_lkey()
661 * rvt_qp_acks_has_lkey - return true if acks have lkey
668 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_qp_acks_has_lkey()
670 for (i = 0; qp->s_ack_queue && i < rvt_max_atomic(rdi); i++) { in rvt_qp_acks_has_lkey()
671 struct rvt_ack_entry *e = &qp->s_ack_queue[i]; in rvt_qp_acks_has_lkey()
673 if (rvt_mr_has_lkey(e->rdma_sge.mr, lkey)) in rvt_qp_acks_has_lkey()
680 * rvt_qp_mr_clean - clean up remote ops for lkey
682 * @lkey: the lkey that is being de-registered
694 if (qp->ibqp.qp_type == IB_QPT_SMI || in rvt_qp_mr_clean()
695 qp->ibqp.qp_type == IB_QPT_GSI) in rvt_qp_mr_clean()
698 spin_lock_irq(&qp->r_lock); in rvt_qp_mr_clean()
699 spin_lock(&qp->s_hlock); in rvt_qp_mr_clean()
700 spin_lock(&qp->s_lock); in rvt_qp_mr_clean()
702 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET) in rvt_qp_mr_clean()
705 if (rvt_ss_has_lkey(&qp->r_sge, lkey) || in rvt_qp_mr_clean()
710 spin_unlock(&qp->s_lock); in rvt_qp_mr_clean()
711 spin_unlock(&qp->s_hlock); in rvt_qp_mr_clean()
712 spin_unlock_irq(&qp->r_lock); in rvt_qp_mr_clean()
716 ev.device = qp->ibqp.device; in rvt_qp_mr_clean()
717 ev.element.qp = &qp->ibqp; in rvt_qp_mr_clean()
719 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_qp_mr_clean()
724 * rvt_remove_qp - remove qp form table
733 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_remove_qp()
734 u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits); in rvt_remove_qp()
738 spin_lock_irqsave(&rdi->qp_dev->qpt_lock, flags); in rvt_remove_qp()
740 if (rcu_dereference_protected(rvp->qp[0], in rvt_remove_qp()
741 lockdep_is_held(&rdi->qp_dev->qpt_lock)) == qp) { in rvt_remove_qp()
742 RCU_INIT_POINTER(rvp->qp[0], NULL); in rvt_remove_qp()
743 } else if (rcu_dereference_protected(rvp->qp[1], in rvt_remove_qp()
744 lockdep_is_held(&rdi->qp_dev->qpt_lock)) == qp) { in rvt_remove_qp()
745 RCU_INIT_POINTER(rvp->qp[1], NULL); in rvt_remove_qp()
751 qpp = &rdi->qp_dev->qp_table[n]; in rvt_remove_qp()
753 lockdep_is_held(&rdi->qp_dev->qpt_lock))) != NULL; in rvt_remove_qp()
754 qpp = &q->next) { in rvt_remove_qp()
757 rcu_dereference_protected(qp->next, in rvt_remove_qp()
758 lockdep_is_held(&rdi->qp_dev->qpt_lock))); in rvt_remove_qp()
766 spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags); in rvt_remove_qp()
774 * rvt_alloc_rq - allocate memory for user or kernel buffer
780 * Return: If memory allocation failed, return -ENONEM
782 * queues and non-shared receive queues to allocate
783 * memory.
789 rq->wq = vmalloc_user(sizeof(struct rvt_rwq) + size); in rvt_alloc_rq()
790 if (!rq->wq) in rvt_alloc_rq()
792 /* need kwq with no buffers */ in rvt_alloc_rq()
793 rq->kwq = kzalloc_node(sizeof(*rq->kwq), GFP_KERNEL, node); in rvt_alloc_rq()
794 if (!rq->kwq) in rvt_alloc_rq()
796 rq->kwq->curr_wq = rq->wq->wq; in rvt_alloc_rq()
799 rq->kwq = in rvt_alloc_rq()
801 if (!rq->kwq) in rvt_alloc_rq()
803 rq->kwq->curr_wq = rq->kwq->wq; in rvt_alloc_rq()
806 spin_lock_init(&rq->kwq->p_lock); in rvt_alloc_rq()
807 spin_lock_init(&rq->kwq->c_lock); in rvt_alloc_rq()
811 return -ENOMEM; in rvt_alloc_rq()
815 * rvt_init_qp - initialize the QP state to the reset state
828 qp->remote_qpn = 0; in rvt_init_qp()
829 qp->qkey = 0; in rvt_init_qp()
830 qp->qp_access_flags = 0; in rvt_init_qp()
831 qp->s_flags &= RVT_S_SIGNAL_REQ_WR; in rvt_init_qp()
832 qp->s_hdrwords = 0; in rvt_init_qp()
833 qp->s_wqe = NULL; in rvt_init_qp()
834 qp->s_draining = 0; in rvt_init_qp()
835 qp->s_next_psn = 0; in rvt_init_qp()
836 qp->s_last_psn = 0; in rvt_init_qp()
837 qp->s_sending_psn = 0; in rvt_init_qp()
838 qp->s_sending_hpsn = 0; in rvt_init_qp()
839 qp->s_psn = 0; in rvt_init_qp()
840 qp->r_psn = 0; in rvt_init_qp()
841 qp->r_msn = 0; in rvt_init_qp()
843 qp->s_state = IB_OPCODE_RC_SEND_LAST; in rvt_init_qp()
844 qp->r_state = IB_OPCODE_RC_SEND_LAST; in rvt_init_qp()
846 qp->s_state = IB_OPCODE_UC_SEND_LAST; in rvt_init_qp()
847 qp->r_state = IB_OPCODE_UC_SEND_LAST; in rvt_init_qp()
849 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE; in rvt_init_qp()
850 qp->r_nak_state = 0; in rvt_init_qp()
851 qp->r_aflags = 0; in rvt_init_qp()
852 qp->r_flags = 0; in rvt_init_qp()
853 qp->s_head = 0; in rvt_init_qp()
854 qp->s_tail = 0; in rvt_init_qp()
855 qp->s_cur = 0; in rvt_init_qp()
856 qp->s_acked = 0; in rvt_init_qp()
857 qp->s_last = 0; in rvt_init_qp()
858 qp->s_ssn = 1; in rvt_init_qp()
859 qp->s_lsn = 0; in rvt_init_qp()
860 qp->s_mig_state = IB_MIG_MIGRATED; in rvt_init_qp()
861 qp->r_head_ack_queue = 0; in rvt_init_qp()
862 qp->s_tail_ack_queue = 0; in rvt_init_qp()
863 qp->s_acked_ack_queue = 0; in rvt_init_qp()
864 qp->s_num_rd_atomic = 0; in rvt_init_qp()
865 qp->r_sge.num_sge = 0; in rvt_init_qp()
866 atomic_set(&qp->s_reserved_used, 0); in rvt_init_qp()
870 * _rvt_reset_qp - initialize the QP state to the reset state
879 __must_hold(&qp->s_lock) in _rvt_reset_qp()
880 __must_hold(&qp->s_hlock) in _rvt_reset_qp()
881 __must_hold(&qp->r_lock) in _rvt_reset_qp()
883 lockdep_assert_held(&qp->r_lock); in _rvt_reset_qp()
884 lockdep_assert_held(&qp->s_hlock); in _rvt_reset_qp()
885 lockdep_assert_held(&qp->s_lock); in _rvt_reset_qp()
886 if (qp->state != IB_QPS_RESET) { in _rvt_reset_qp()
887 qp->state = IB_QPS_RESET; in _rvt_reset_qp()
890 rdi->driver_f.flush_qp_waiters(qp); in _rvt_reset_qp()
892 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_ANY_WAIT); in _rvt_reset_qp()
893 spin_unlock(&qp->s_lock); in _rvt_reset_qp()
894 spin_unlock(&qp->s_hlock); in _rvt_reset_qp()
895 spin_unlock_irq(&qp->r_lock); in _rvt_reset_qp()
898 rdi->driver_f.stop_send_queue(qp); in _rvt_reset_qp()
901 rdi->driver_f.quiesce_qp(qp); in _rvt_reset_qp()
907 spin_lock_irq(&qp->r_lock); in _rvt_reset_qp()
908 spin_lock(&qp->s_hlock); in _rvt_reset_qp()
909 spin_lock(&qp->s_lock); in _rvt_reset_qp()
913 * Let the driver do any tear down or re-init it needs to for in _rvt_reset_qp()
916 rdi->driver_f.notify_qp_reset(qp); in _rvt_reset_qp()
919 lockdep_assert_held(&qp->r_lock); in _rvt_reset_qp()
920 lockdep_assert_held(&qp->s_hlock); in _rvt_reset_qp()
921 lockdep_assert_held(&qp->s_lock); in _rvt_reset_qp()
925 * rvt_reset_qp - initialize the QP state to the reset state
936 spin_lock_irq(&qp->r_lock); in rvt_reset_qp()
937 spin_lock(&qp->s_hlock); in rvt_reset_qp()
938 spin_lock(&qp->s_lock); in rvt_reset_qp()
940 spin_unlock(&qp->s_lock); in rvt_reset_qp()
941 spin_unlock(&qp->s_hlock); in rvt_reset_qp()
942 spin_unlock_irq(&qp->r_lock); in rvt_reset_qp()
946 * rvt_free_qpn - Free a qpn from the bit map
957 map = qpt->map + (qpn & RVT_QPN_MASK) / RVT_BITS_PER_PAGE; in rvt_free_qpn()
958 if (map->page) in rvt_free_qpn()
959 clear_bit(qpn & RVT_BITS_PER_PAGE_MASK, map->page); in rvt_free_qpn()
963 * get_allowed_ops - Given a QP type return the appropriate allowed OP
973 * free_ud_wq_attr - Clean up AH attribute cache for UD QPs
984 for (i = 0; qp->allowed_ops == IB_OPCODE_UD && i < qp->s_size; i++) { in free_ud_wq_attr()
986 kfree(wqe->ud_wr.attr); in free_ud_wq_attr()
987 wqe->ud_wr.attr = NULL; in free_ud_wq_attr()
992 * alloc_ud_wq_attr - AH attribute cache for UD QPs
1004 for (i = 0; qp->allowed_ops == IB_OPCODE_UD && i < qp->s_size; i++) { in alloc_ud_wq_attr()
1006 wqe->ud_wr.attr = kzalloc_node(sizeof(*wqe->ud_wr.attr), in alloc_ud_wq_attr()
1008 if (!wqe->ud_wr.attr) { in alloc_ud_wq_attr()
1010 return -ENOMEM; in alloc_ud_wq_attr()
1018 * rvt_create_qp - create a queue pair for a device
1035 int ret = -ENOMEM; in rvt_create_qp()
1039 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_create_qp()
1045 return -EINVAL; in rvt_create_qp()
1047 if (init_attr->create_flags & ~IB_QP_CREATE_NETDEV_USE) in rvt_create_qp()
1048 return -EOPNOTSUPP; in rvt_create_qp()
1050 if (init_attr->cap.max_send_sge > rdi->dparms.props.max_send_sge || in rvt_create_qp()
1051 init_attr->cap.max_send_wr > rdi->dparms.props.max_qp_wr) in rvt_create_qp()
1052 return -EINVAL; in rvt_create_qp()
1054 /* Check receive queue parameters if no SRQ is specified. */ in rvt_create_qp()
1055 if (!init_attr->srq) { in rvt_create_qp()
1056 if (init_attr->cap.max_recv_sge > in rvt_create_qp()
1057 rdi->dparms.props.max_recv_sge || in rvt_create_qp()
1058 init_attr->cap.max_recv_wr > rdi->dparms.props.max_qp_wr) in rvt_create_qp()
1059 return -EINVAL; in rvt_create_qp()
1061 if (init_attr->cap.max_send_sge + in rvt_create_qp()
1062 init_attr->cap.max_send_wr + in rvt_create_qp()
1063 init_attr->cap.max_recv_sge + in rvt_create_qp()
1064 init_attr->cap.max_recv_wr == 0) in rvt_create_qp()
1065 return -EINVAL; in rvt_create_qp()
1068 init_attr->cap.max_send_wr + 1 + in rvt_create_qp()
1069 rdi->dparms.reserved_operations; in rvt_create_qp()
1070 switch (init_attr->qp_type) { in rvt_create_qp()
1073 if (init_attr->port_num == 0 || in rvt_create_qp()
1074 init_attr->port_num > ibqp->device->phys_port_cnt) in rvt_create_qp()
1075 return -EINVAL; in rvt_create_qp()
1080 sz = struct_size(swq, sg_list, init_attr->cap.max_send_sge); in rvt_create_qp()
1081 swq = vzalloc_node(array_size(sz, sqsize), rdi->dparms.node); in rvt_create_qp()
1083 return -ENOMEM; in rvt_create_qp()
1085 if (init_attr->srq) { in rvt_create_qp()
1086 struct rvt_srq *srq = ibsrq_to_rvtsrq(init_attr->srq); in rvt_create_qp()
1088 if (srq->rq.max_sge > 1) in rvt_create_qp()
1089 sg_list_sz = sizeof(*qp->r_sg_list) * in rvt_create_qp()
1090 (srq->rq.max_sge - 1); in rvt_create_qp()
1091 } else if (init_attr->cap.max_recv_sge > 1) in rvt_create_qp()
1092 sg_list_sz = sizeof(*qp->r_sg_list) * in rvt_create_qp()
1093 (init_attr->cap.max_recv_sge - 1); in rvt_create_qp()
1094 qp->r_sg_list = in rvt_create_qp()
1095 kzalloc_node(sg_list_sz, GFP_KERNEL, rdi->dparms.node); in rvt_create_qp()
1096 if (!qp->r_sg_list) in rvt_create_qp()
1098 qp->allowed_ops = get_allowed_ops(init_attr->qp_type); in rvt_create_qp()
1100 RCU_INIT_POINTER(qp->next, NULL); in rvt_create_qp()
1101 if (init_attr->qp_type == IB_QPT_RC) { in rvt_create_qp()
1102 qp->s_ack_queue = in rvt_create_qp()
1104 sizeof(*qp->s_ack_queue), in rvt_create_qp()
1106 rdi->dparms.node); in rvt_create_qp()
1107 if (!qp->s_ack_queue) in rvt_create_qp()
1111 timer_setup(&qp->s_timer, rvt_rc_timeout, 0); in rvt_create_qp()
1112 hrtimer_init(&qp->s_rnr_timer, CLOCK_MONOTONIC, in rvt_create_qp()
1114 qp->s_rnr_timer.function = rvt_rc_rnr_retry; in rvt_create_qp()
1120 priv = rdi->driver_f.qp_priv_alloc(rdi, qp); in rvt_create_qp()
1125 qp->priv = priv; in rvt_create_qp()
1126 qp->timeout_jiffies = in rvt_create_qp()
1127 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) / in rvt_create_qp()
1129 if (init_attr->srq) { in rvt_create_qp()
1132 qp->r_rq.size = init_attr->cap.max_recv_wr + 1; in rvt_create_qp()
1133 qp->r_rq.max_sge = init_attr->cap.max_recv_sge; in rvt_create_qp()
1134 sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) + in rvt_create_qp()
1136 ret = rvt_alloc_rq(&qp->r_rq, qp->r_rq.size * sz, in rvt_create_qp()
1137 rdi->dparms.node, udata); in rvt_create_qp()
1143 * ib_create_qp() will initialize qp->ibqp in rvt_create_qp()
1144 * except for qp->ibqp.qp_num. in rvt_create_qp()
1146 spin_lock_init(&qp->r_lock); in rvt_create_qp()
1147 spin_lock_init(&qp->s_hlock); in rvt_create_qp()
1148 spin_lock_init(&qp->s_lock); in rvt_create_qp()
1149 atomic_set(&qp->refcount, 0); in rvt_create_qp()
1150 atomic_set(&qp->local_ops_pending, 0); in rvt_create_qp()
1151 init_waitqueue_head(&qp->wait); in rvt_create_qp()
1152 INIT_LIST_HEAD(&qp->rspwait); in rvt_create_qp()
1153 qp->state = IB_QPS_RESET; in rvt_create_qp()
1154 qp->s_wq = swq; in rvt_create_qp()
1155 qp->s_size = sqsize; in rvt_create_qp()
1156 qp->s_avail = init_attr->cap.max_send_wr; in rvt_create_qp()
1157 qp->s_max_sge = init_attr->cap.max_send_sge; in rvt_create_qp()
1158 if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR) in rvt_create_qp()
1159 qp->s_flags = RVT_S_SIGNAL_REQ_WR; in rvt_create_qp()
1160 ret = alloc_ud_wq_attr(qp, rdi->dparms.node); in rvt_create_qp()
1164 if (init_attr->create_flags & IB_QP_CREATE_NETDEV_USE) in rvt_create_qp()
1167 ret = alloc_qpn(rdi, &rdi->qp_dev->qpn_table, in rvt_create_qp()
1168 init_attr->qp_type, in rvt_create_qp()
1169 init_attr->port_num, in rvt_create_qp()
1174 qp->ibqp.qp_num = ret; in rvt_create_qp()
1175 if (init_attr->create_flags & IB_QP_CREATE_NETDEV_USE) in rvt_create_qp()
1176 qp->ibqp.qp_num |= RVT_AIP_QP_BASE; in rvt_create_qp()
1177 qp->port_num = init_attr->port_num; in rvt_create_qp()
1178 rvt_init_qp(rdi, qp, init_attr->qp_type); in rvt_create_qp()
1179 if (rdi->driver_f.qp_priv_init) { in rvt_create_qp()
1180 ret = rdi->driver_f.qp_priv_init(rdi, qp, init_attr); in rvt_create_qp()
1188 return -EOPNOTSUPP; in rvt_create_qp()
1191 init_attr->cap.max_inline_data = 0; in rvt_create_qp()
1197 if (udata && udata->outlen >= sizeof(__u64)) { in rvt_create_qp()
1198 if (!qp->r_rq.wq) { in rvt_create_qp()
1206 u32 s = sizeof(struct rvt_rwq) + qp->r_rq.size * sz; in rvt_create_qp()
1208 qp->ip = rvt_create_mmap_info(rdi, s, udata, in rvt_create_qp()
1209 qp->r_rq.wq); in rvt_create_qp()
1210 if (IS_ERR(qp->ip)) { in rvt_create_qp()
1211 ret = PTR_ERR(qp->ip); in rvt_create_qp()
1215 ret = ib_copy_to_udata(udata, &qp->ip->offset, in rvt_create_qp()
1216 sizeof(qp->ip->offset)); in rvt_create_qp()
1220 qp->pid = current->pid; in rvt_create_qp()
1223 spin_lock(&rdi->n_qps_lock); in rvt_create_qp()
1224 if (rdi->n_qps_allocated == rdi->dparms.props.max_qp) { in rvt_create_qp()
1225 spin_unlock(&rdi->n_qps_lock); in rvt_create_qp()
1226 ret = -ENOMEM; in rvt_create_qp()
1230 rdi->n_qps_allocated++; in rvt_create_qp()
1240 if (init_attr->qp_type == IB_QPT_RC) { in rvt_create_qp()
1241 rdi->n_rc_qps++; in rvt_create_qp()
1242 rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL; in rvt_create_qp()
1244 spin_unlock(&rdi->n_qps_lock); in rvt_create_qp()
1246 if (qp->ip) { in rvt_create_qp()
1247 spin_lock_irq(&rdi->pending_lock); in rvt_create_qp()
1248 list_add(&qp->ip->pending_mmaps, &rdi->pending_mmaps); in rvt_create_qp()
1249 spin_unlock_irq(&rdi->pending_lock); in rvt_create_qp()
1255 if (qp->ip) in rvt_create_qp()
1256 kref_put(&qp->ip->ref, rvt_release_mmap_info); in rvt_create_qp()
1259 rvt_free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num); in rvt_create_qp()
1265 rvt_free_rq(&qp->r_rq); in rvt_create_qp()
1268 rdi->driver_f.qp_priv_free(rdi, qp); in rvt_create_qp()
1271 kfree(qp->s_ack_queue); in rvt_create_qp()
1272 kfree(qp->r_sg_list); in rvt_create_qp()
1278 * rvt_error_qp - put a QP into the error state
1290 struct ib_wc wc; in rvt_error_qp() local
1292 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_error_qp()
1294 lockdep_assert_held(&qp->r_lock); in rvt_error_qp()
1295 lockdep_assert_held(&qp->s_lock); in rvt_error_qp()
1296 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET) in rvt_error_qp()
1299 qp->state = IB_QPS_ERR; in rvt_error_qp()
1301 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) { in rvt_error_qp()
1302 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR); in rvt_error_qp()
1303 del_timer(&qp->s_timer); in rvt_error_qp()
1306 if (qp->s_flags & RVT_S_ANY_WAIT_SEND) in rvt_error_qp()
1307 qp->s_flags &= ~RVT_S_ANY_WAIT_SEND; in rvt_error_qp()
1309 rdi->driver_f.notify_error_qp(qp); in rvt_error_qp()
1312 if (READ_ONCE(qp->s_last) != qp->s_head) in rvt_error_qp()
1313 rdi->driver_f.schedule_send(qp); in rvt_error_qp()
1317 memset(&wc, 0, sizeof(wc)); in rvt_error_qp()
1318 wc.qp = &qp->ibqp; in rvt_error_qp()
1319 wc.opcode = IB_WC_RECV; in rvt_error_qp()
1321 if (test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) { in rvt_error_qp()
1322 wc.wr_id = qp->r_wr_id; in rvt_error_qp()
1323 wc.status = err; in rvt_error_qp()
1324 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_error_qp()
1326 wc.status = IB_WC_WR_FLUSH_ERR; in rvt_error_qp()
1328 if (qp->r_rq.kwq) { in rvt_error_qp()
1334 spin_lock(&qp->r_rq.kwq->c_lock); in rvt_error_qp()
1335 /* qp->ip used to validate if there is a user buffer mmaped */ in rvt_error_qp()
1336 if (qp->ip) { in rvt_error_qp()
1337 wq = qp->r_rq.wq; in rvt_error_qp()
1338 head = RDMA_READ_UAPI_ATOMIC(wq->head); in rvt_error_qp()
1339 tail = RDMA_READ_UAPI_ATOMIC(wq->tail); in rvt_error_qp()
1341 kwq = qp->r_rq.kwq; in rvt_error_qp()
1342 head = kwq->head; in rvt_error_qp()
1343 tail = kwq->tail; in rvt_error_qp()
1346 if (head >= qp->r_rq.size) in rvt_error_qp()
1348 if (tail >= qp->r_rq.size) in rvt_error_qp()
1351 wc.wr_id = rvt_get_rwqe_ptr(&qp->r_rq, tail)->wr_id; in rvt_error_qp()
1352 if (++tail >= qp->r_rq.size) in rvt_error_qp()
1354 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_error_qp()
1356 if (qp->ip) in rvt_error_qp()
1357 RDMA_WRITE_UAPI_ATOMIC(wq->tail, tail); in rvt_error_qp()
1359 kwq->tail = tail; in rvt_error_qp()
1360 spin_unlock(&qp->r_rq.kwq->c_lock); in rvt_error_qp()
1361 } else if (qp->ibqp.event_handler) { in rvt_error_qp()
1376 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_insert_qp()
1380 spin_lock_irqsave(&rdi->qp_dev->qpt_lock, flags); in rvt_insert_qp()
1382 if (qp->ibqp.qp_num <= 1) { in rvt_insert_qp()
1383 rcu_assign_pointer(rvp->qp[qp->ibqp.qp_num], qp); in rvt_insert_qp()
1385 u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits); in rvt_insert_qp()
1387 qp->next = rdi->qp_dev->qp_table[n]; in rvt_insert_qp()
1388 rcu_assign_pointer(rdi->qp_dev->qp_table[n], qp); in rvt_insert_qp()
1392 spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags); in rvt_insert_qp()
1396 * rvt_modify_qp - modify the attributes of a queue pair
1407 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_modify_qp()
1417 return -EOPNOTSUPP; in rvt_modify_qp()
1419 spin_lock_irq(&qp->r_lock); in rvt_modify_qp()
1420 spin_lock(&qp->s_hlock); in rvt_modify_qp()
1421 spin_lock(&qp->s_lock); in rvt_modify_qp()
1424 attr->cur_qp_state : qp->state; in rvt_modify_qp()
1425 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; in rvt_modify_qp()
1426 opa_ah = rdma_cap_opa_ah(ibqp->device, qp->port_num); in rvt_modify_qp()
1428 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, in rvt_modify_qp()
1432 if (rdi->driver_f.check_modify_qp && in rvt_modify_qp()
1433 rdi->driver_f.check_modify_qp(qp, attr, attr_mask, udata)) in rvt_modify_qp()
1438 if (rdma_ah_get_dlid(&attr->ah_attr) >= in rvt_modify_qp()
1442 if (rdma_ah_get_dlid(&attr->ah_attr) >= in rvt_modify_qp()
1447 if (rvt_check_ah(qp->ibqp.device, &attr->ah_attr)) in rvt_modify_qp()
1453 if (rdma_ah_get_dlid(&attr->alt_ah_attr) >= in rvt_modify_qp()
1457 if (rdma_ah_get_dlid(&attr->alt_ah_attr) >= in rvt_modify_qp()
1462 if (rvt_check_ah(qp->ibqp.device, &attr->alt_ah_attr)) in rvt_modify_qp()
1464 if (attr->alt_pkey_index >= rvt_get_npkeys(rdi)) in rvt_modify_qp()
1469 if (attr->pkey_index >= rvt_get_npkeys(rdi)) in rvt_modify_qp()
1473 if (attr->min_rnr_timer > 31) in rvt_modify_qp()
1477 if (qp->ibqp.qp_type == IB_QPT_SMI || in rvt_modify_qp()
1478 qp->ibqp.qp_type == IB_QPT_GSI || in rvt_modify_qp()
1479 attr->port_num == 0 || in rvt_modify_qp()
1480 attr->port_num > ibqp->device->phys_port_cnt) in rvt_modify_qp()
1484 if (attr->dest_qp_num > RVT_QPN_MASK) in rvt_modify_qp()
1488 if (attr->retry_cnt > 7) in rvt_modify_qp()
1492 if (attr->rnr_retry > 7) in rvt_modify_qp()
1498 * that to a small mtu. We'll set qp->path_mtu in rvt_modify_qp()
1504 pmtu = rdi->driver_f.get_pmtu_from_attr(rdi, qp, attr); in rvt_modify_qp()
1510 if (attr->path_mig_state == IB_MIG_REARM) { in rvt_modify_qp()
1511 if (qp->s_mig_state == IB_MIG_ARMED) in rvt_modify_qp()
1515 } else if (attr->path_mig_state == IB_MIG_MIGRATED) { in rvt_modify_qp()
1516 if (qp->s_mig_state == IB_MIG_REARM) in rvt_modify_qp()
1520 if (qp->s_mig_state == IB_MIG_ARMED) in rvt_modify_qp()
1528 if (attr->max_dest_rd_atomic > rdi->dparms.max_rdma_atomic) in rvt_modify_qp()
1533 if (qp->state != IB_QPS_RESET) in rvt_modify_qp()
1534 _rvt_reset_qp(rdi, qp, ibqp->qp_type); in rvt_modify_qp()
1538 /* Allow event to re-trigger if QP set to RTR more than once */ in rvt_modify_qp()
1539 qp->r_flags &= ~RVT_R_COMM_EST; in rvt_modify_qp()
1540 qp->state = new_state; in rvt_modify_qp()
1544 qp->s_draining = qp->s_last != qp->s_cur; in rvt_modify_qp()
1545 qp->state = new_state; in rvt_modify_qp()
1549 if (qp->ibqp.qp_type == IB_QPT_RC) in rvt_modify_qp()
1551 qp->state = new_state; in rvt_modify_qp()
1559 qp->state = new_state; in rvt_modify_qp()
1564 qp->s_pkey_index = attr->pkey_index; in rvt_modify_qp()
1567 qp->port_num = attr->port_num; in rvt_modify_qp()
1570 qp->remote_qpn = attr->dest_qp_num; in rvt_modify_qp()
1573 qp->s_next_psn = attr->sq_psn & rdi->dparms.psn_modify_mask; in rvt_modify_qp()
1574 qp->s_psn = qp->s_next_psn; in rvt_modify_qp()
1575 qp->s_sending_psn = qp->s_next_psn; in rvt_modify_qp()
1576 qp->s_last_psn = qp->s_next_psn - 1; in rvt_modify_qp()
1577 qp->s_sending_hpsn = qp->s_last_psn; in rvt_modify_qp()
1581 qp->r_psn = attr->rq_psn & rdi->dparms.psn_modify_mask; in rvt_modify_qp()
1584 qp->qp_access_flags = attr->qp_access_flags; in rvt_modify_qp()
1587 rdma_replace_ah_attr(&qp->remote_ah_attr, &attr->ah_attr); in rvt_modify_qp()
1588 qp->s_srate = rdma_ah_get_static_rate(&attr->ah_attr); in rvt_modify_qp()
1589 qp->srate_mbps = ib_rate_to_mbps(qp->s_srate); in rvt_modify_qp()
1593 rdma_replace_ah_attr(&qp->alt_ah_attr, &attr->alt_ah_attr); in rvt_modify_qp()
1594 qp->s_alt_pkey_index = attr->alt_pkey_index; in rvt_modify_qp()
1598 qp->s_mig_state = attr->path_mig_state; in rvt_modify_qp()
1600 qp->remote_ah_attr = qp->alt_ah_attr; in rvt_modify_qp()
1601 qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr); in rvt_modify_qp()
1602 qp->s_pkey_index = qp->s_alt_pkey_index; in rvt_modify_qp()
1607 qp->pmtu = rdi->driver_f.mtu_from_qp(rdi, qp, pmtu); in rvt_modify_qp()
1608 qp->log_pmtu = ilog2(qp->pmtu); in rvt_modify_qp()
1612 qp->s_retry_cnt = attr->retry_cnt; in rvt_modify_qp()
1613 qp->s_retry = attr->retry_cnt; in rvt_modify_qp()
1617 qp->s_rnr_retry_cnt = attr->rnr_retry; in rvt_modify_qp()
1618 qp->s_rnr_retry = attr->rnr_retry; in rvt_modify_qp()
1622 qp->r_min_rnr_timer = attr->min_rnr_timer; in rvt_modify_qp()
1625 qp->timeout = attr->timeout; in rvt_modify_qp()
1626 qp->timeout_jiffies = rvt_timeout_to_jiffies(qp->timeout); in rvt_modify_qp()
1630 qp->qkey = attr->qkey; in rvt_modify_qp()
1633 qp->r_max_rd_atomic = attr->max_dest_rd_atomic; in rvt_modify_qp()
1636 qp->s_max_rd_atomic = attr->max_rd_atomic; in rvt_modify_qp()
1638 if (rdi->driver_f.modify_qp) in rvt_modify_qp()
1639 rdi->driver_f.modify_qp(qp, attr, attr_mask, udata); in rvt_modify_qp()
1641 spin_unlock(&qp->s_lock); in rvt_modify_qp()
1642 spin_unlock(&qp->s_hlock); in rvt_modify_qp()
1643 spin_unlock_irq(&qp->r_lock); in rvt_modify_qp()
1649 ev.device = qp->ibqp.device; in rvt_modify_qp()
1650 ev.element.qp = &qp->ibqp; in rvt_modify_qp()
1652 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_modify_qp()
1655 ev.device = qp->ibqp.device; in rvt_modify_qp()
1656 ev.element.qp = &qp->ibqp; in rvt_modify_qp()
1658 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_modify_qp()
1663 spin_unlock(&qp->s_lock); in rvt_modify_qp()
1664 spin_unlock(&qp->s_hlock); in rvt_modify_qp()
1665 spin_unlock_irq(&qp->r_lock); in rvt_modify_qp()
1666 return -EINVAL; in rvt_modify_qp()
1670 * rvt_destroy_qp - destroy a queue pair
1682 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_destroy_qp()
1684 rvt_reset_qp(rdi, qp, ibqp->qp_type); in rvt_destroy_qp()
1686 wait_event(qp->wait, !atomic_read(&qp->refcount)); in rvt_destroy_qp()
1688 rvt_free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num); in rvt_destroy_qp()
1690 spin_lock(&rdi->n_qps_lock); in rvt_destroy_qp()
1691 rdi->n_qps_allocated--; in rvt_destroy_qp()
1692 if (qp->ibqp.qp_type == IB_QPT_RC) { in rvt_destroy_qp()
1693 rdi->n_rc_qps--; in rvt_destroy_qp()
1694 rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL; in rvt_destroy_qp()
1696 spin_unlock(&rdi->n_qps_lock); in rvt_destroy_qp()
1698 if (qp->ip) in rvt_destroy_qp()
1699 kref_put(&qp->ip->ref, rvt_release_mmap_info); in rvt_destroy_qp()
1700 kvfree(qp->r_rq.kwq); in rvt_destroy_qp()
1701 rdi->driver_f.qp_priv_free(rdi, qp); in rvt_destroy_qp()
1702 kfree(qp->s_ack_queue); in rvt_destroy_qp()
1703 kfree(qp->r_sg_list); in rvt_destroy_qp()
1704 rdma_destroy_ah_attr(&qp->remote_ah_attr); in rvt_destroy_qp()
1705 rdma_destroy_ah_attr(&qp->alt_ah_attr); in rvt_destroy_qp()
1707 vfree(qp->s_wq); in rvt_destroy_qp()
1712 * rvt_query_qp - query an ipbq
1724 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_query_qp()
1726 attr->qp_state = qp->state; in rvt_query_qp()
1727 attr->cur_qp_state = attr->qp_state; in rvt_query_qp()
1728 attr->path_mtu = rdi->driver_f.mtu_to_path_mtu(qp->pmtu); in rvt_query_qp()
1729 attr->path_mig_state = qp->s_mig_state; in rvt_query_qp()
1730 attr->qkey = qp->qkey; in rvt_query_qp()
1731 attr->rq_psn = qp->r_psn & rdi->dparms.psn_mask; in rvt_query_qp()
1732 attr->sq_psn = qp->s_next_psn & rdi->dparms.psn_mask; in rvt_query_qp()
1733 attr->dest_qp_num = qp->remote_qpn; in rvt_query_qp()
1734 attr->qp_access_flags = qp->qp_access_flags; in rvt_query_qp()
1735 attr->cap.max_send_wr = qp->s_size - 1 - in rvt_query_qp()
1736 rdi->dparms.reserved_operations; in rvt_query_qp()
1737 attr->cap.max_recv_wr = qp->ibqp.srq ? 0 : qp->r_rq.size - 1; in rvt_query_qp()
1738 attr->cap.max_send_sge = qp->s_max_sge; in rvt_query_qp()
1739 attr->cap.max_recv_sge = qp->r_rq.max_sge; in rvt_query_qp()
1740 attr->cap.max_inline_data = 0; in rvt_query_qp()
1741 attr->ah_attr = qp->remote_ah_attr; in rvt_query_qp()
1742 attr->alt_ah_attr = qp->alt_ah_attr; in rvt_query_qp()
1743 attr->pkey_index = qp->s_pkey_index; in rvt_query_qp()
1744 attr->alt_pkey_index = qp->s_alt_pkey_index; in rvt_query_qp()
1745 attr->en_sqd_async_notify = 0; in rvt_query_qp()
1746 attr->sq_draining = qp->s_draining; in rvt_query_qp()
1747 attr->max_rd_atomic = qp->s_max_rd_atomic; in rvt_query_qp()
1748 attr->max_dest_rd_atomic = qp->r_max_rd_atomic; in rvt_query_qp()
1749 attr->min_rnr_timer = qp->r_min_rnr_timer; in rvt_query_qp()
1750 attr->port_num = qp->port_num; in rvt_query_qp()
1751 attr->timeout = qp->timeout; in rvt_query_qp()
1752 attr->retry_cnt = qp->s_retry_cnt; in rvt_query_qp()
1753 attr->rnr_retry = qp->s_rnr_retry_cnt; in rvt_query_qp()
1754 attr->alt_port_num = in rvt_query_qp()
1755 rdma_ah_get_port_num(&qp->alt_ah_attr); in rvt_query_qp()
1756 attr->alt_timeout = qp->alt_timeout; in rvt_query_qp()
1758 init_attr->event_handler = qp->ibqp.event_handler; in rvt_query_qp()
1759 init_attr->qp_context = qp->ibqp.qp_context; in rvt_query_qp()
1760 init_attr->send_cq = qp->ibqp.send_cq; in rvt_query_qp()
1761 init_attr->recv_cq = qp->ibqp.recv_cq; in rvt_query_qp()
1762 init_attr->srq = qp->ibqp.srq; in rvt_query_qp()
1763 init_attr->cap = attr->cap; in rvt_query_qp()
1764 if (qp->s_flags & RVT_S_SIGNAL_REQ_WR) in rvt_query_qp()
1765 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR; in rvt_query_qp()
1767 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; in rvt_query_qp()
1768 init_attr->qp_type = qp->ibqp.qp_type; in rvt_query_qp()
1769 init_attr->port_num = qp->port_num; in rvt_query_qp()
1774 * rvt_post_recv - post a receive on a QP
1787 struct rvt_krwq *wq = qp->r_rq.kwq; in rvt_post_recv()
1789 int qp_err_flush = (ib_rvt_state_ops[qp->state] & RVT_FLUSH_RECV) && in rvt_post_recv()
1790 !qp->ibqp.srq; in rvt_post_recv()
1793 if (!(ib_rvt_state_ops[qp->state] & RVT_POST_RECV_OK) || !wq) { in rvt_post_recv()
1795 return -EINVAL; in rvt_post_recv()
1798 for (; wr; wr = wr->next) { in rvt_post_recv()
1803 if ((unsigned)wr->num_sge > qp->r_rq.max_sge) { in rvt_post_recv()
1805 return -EINVAL; in rvt_post_recv()
1808 spin_lock_irqsave(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1809 next = wq->head + 1; in rvt_post_recv()
1810 if (next >= qp->r_rq.size) in rvt_post_recv()
1812 if (next == READ_ONCE(wq->tail)) { in rvt_post_recv()
1813 spin_unlock_irqrestore(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1815 return -ENOMEM; in rvt_post_recv()
1818 struct ib_wc wc; in rvt_post_recv() local
1820 memset(&wc, 0, sizeof(wc)); in rvt_post_recv()
1821 wc.qp = &qp->ibqp; in rvt_post_recv()
1822 wc.opcode = IB_WC_RECV; in rvt_post_recv()
1823 wc.wr_id = wr->wr_id; in rvt_post_recv()
1824 wc.status = IB_WC_WR_FLUSH_ERR; in rvt_post_recv()
1825 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_post_recv()
1827 wqe = rvt_get_rwqe_ptr(&qp->r_rq, wq->head); in rvt_post_recv()
1828 wqe->wr_id = wr->wr_id; in rvt_post_recv()
1829 wqe->num_sge = wr->num_sge; in rvt_post_recv()
1830 for (i = 0; i < wr->num_sge; i++) { in rvt_post_recv()
1831 wqe->sg_list[i].addr = wr->sg_list[i].addr; in rvt_post_recv()
1832 wqe->sg_list[i].length = wr->sg_list[i].length; in rvt_post_recv()
1833 wqe->sg_list[i].lkey = wr->sg_list[i].lkey; in rvt_post_recv()
1839 smp_store_release(&wq->head, next); in rvt_post_recv()
1841 spin_unlock_irqrestore(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1847 * rvt_qp_valid_operation - validate post send wr request
1871 if (wr->opcode >= RVT_OPERATION_MAX || !post_parms[wr->opcode].length) in rvt_qp_valid_operation()
1872 return -EINVAL; in rvt_qp_valid_operation()
1873 if (!(post_parms[wr->opcode].qpt_support & BIT(qp->ibqp.qp_type))) in rvt_qp_valid_operation()
1874 return -EINVAL; in rvt_qp_valid_operation()
1875 if ((post_parms[wr->opcode].flags & RVT_OPERATION_PRIV) && in rvt_qp_valid_operation()
1876 ibpd_to_rvtpd(qp->ibqp.pd)->user) in rvt_qp_valid_operation()
1877 return -EINVAL; in rvt_qp_valid_operation()
1878 if (post_parms[wr->opcode].flags & RVT_OPERATION_ATOMIC_SGE && in rvt_qp_valid_operation()
1879 (wr->num_sge == 0 || in rvt_qp_valid_operation()
1880 wr->sg_list[0].length < sizeof(u64) || in rvt_qp_valid_operation()
1881 wr->sg_list[0].addr & (sizeof(u64) - 1))) in rvt_qp_valid_operation()
1882 return -EINVAL; in rvt_qp_valid_operation()
1883 if (post_parms[wr->opcode].flags & RVT_OPERATION_ATOMIC && in rvt_qp_valid_operation()
1884 !qp->s_max_rd_atomic) in rvt_qp_valid_operation()
1885 return -EINVAL; in rvt_qp_valid_operation()
1886 len = post_parms[wr->opcode].length; in rvt_qp_valid_operation()
1888 if (qp->ibqp.qp_type != IB_QPT_UC && in rvt_qp_valid_operation()
1889 qp->ibqp.qp_type != IB_QPT_RC) { in rvt_qp_valid_operation()
1890 if (qp->ibqp.pd != ud_wr(wr)->ah->pd) in rvt_qp_valid_operation()
1891 return -EINVAL; in rvt_qp_valid_operation()
1898 * rvt_qp_is_avail - determine queue capacity
1906 * For non reserved operations, the qp->s_avail
1909 * The return value is zero or a -ENOMEM.
1924 reserved_used = atomic_read(&qp->s_reserved_used); in rvt_qp_is_avail()
1925 if (reserved_used >= rdi->dparms.reserved_operations) in rvt_qp_is_avail()
1926 return -ENOMEM; in rvt_qp_is_avail()
1929 /* non-reserved operations */ in rvt_qp_is_avail()
1930 if (likely(qp->s_avail)) in rvt_qp_is_avail()
1933 slast = smp_load_acquire(&qp->s_last); in rvt_qp_is_avail()
1934 if (qp->s_head >= slast) in rvt_qp_is_avail()
1935 avail = qp->s_size - (qp->s_head - slast); in rvt_qp_is_avail()
1937 avail = slast - qp->s_head; in rvt_qp_is_avail()
1939 reserved_used = atomic_read(&qp->s_reserved_used); in rvt_qp_is_avail()
1940 avail = avail - 1 - in rvt_qp_is_avail()
1941 (rdi->dparms.reserved_operations - reserved_used); in rvt_qp_is_avail()
1944 return -ENOMEM; in rvt_qp_is_avail()
1945 qp->s_avail = avail; in rvt_qp_is_avail()
1946 if (WARN_ON(qp->s_avail > in rvt_qp_is_avail()
1947 (qp->s_size - 1 - rdi->dparms.reserved_operations))) in rvt_qp_is_avail()
1950 qp->ibqp.qp_num, qp->s_size, qp->s_avail, in rvt_qp_is_avail()
1951 qp->s_head, qp->s_tail, qp->s_cur, in rvt_qp_is_avail()
1952 qp->s_acked, qp->s_last); in rvt_qp_is_avail()
1957 * rvt_post_one_wr - post one RC, UC, or UD send work request
1973 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_post_one_wr()
1983 if (unlikely(wr->num_sge > qp->s_max_sge)) in rvt_post_one_wr()
1984 return -EINVAL; in rvt_post_one_wr()
1986 ret = rvt_qp_valid_operation(qp, rdi->post_parms, wr); in rvt_post_one_wr()
1997 * not required and no previous local invalidate ops are pending. in rvt_post_one_wr()
2002 if ((rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL)) { in rvt_post_one_wr()
2003 switch (wr->opcode) { in rvt_post_one_wr()
2006 reg_wr(wr)->mr, in rvt_post_one_wr()
2007 reg_wr(wr)->key, in rvt_post_one_wr()
2008 reg_wr(wr)->access); in rvt_post_one_wr()
2009 if (ret || !(wr->send_flags & IB_SEND_SIGNALED)) in rvt_post_one_wr()
2013 if ((wr->send_flags & IB_SEND_FENCE) || in rvt_post_one_wr()
2014 atomic_read(&qp->local_ops_pending)) { in rvt_post_one_wr()
2018 qp, wr->ex.invalidate_rkey); in rvt_post_one_wr()
2019 if (ret || !(wr->send_flags & IB_SEND_SIGNALED)) in rvt_post_one_wr()
2024 return -EINVAL; in rvt_post_one_wr()
2028 reserved_op = rdi->post_parms[wr->opcode].flags & in rvt_post_one_wr()
2034 next = qp->s_head + 1; in rvt_post_one_wr()
2035 if (next >= qp->s_size) in rvt_post_one_wr()
2038 rkt = &rdi->lkey_table; in rvt_post_one_wr()
2039 pd = ibpd_to_rvtpd(qp->ibqp.pd); in rvt_post_one_wr()
2040 wqe = rvt_get_swqe_ptr(qp, qp->s_head); in rvt_post_one_wr()
2043 memcpy(&wqe->wr, wr, cplen); in rvt_post_one_wr()
2045 wqe->length = 0; in rvt_post_one_wr()
2047 if (wr->num_sge) { in rvt_post_one_wr()
2050 acc = wr->opcode >= IB_WR_RDMA_READ ? in rvt_post_one_wr()
2052 for (i = 0; i < wr->num_sge; i++) { in rvt_post_one_wr()
2053 u32 length = wr->sg_list[i].length; in rvt_post_one_wr()
2057 ret = rvt_lkey_ok(rkt, pd, &wqe->sg_list[j], last_sge, in rvt_post_one_wr()
2058 &wr->sg_list[i], acc); in rvt_post_one_wr()
2061 wqe->length += length; in rvt_post_one_wr()
2063 last_sge = &wqe->sg_list[j]; in rvt_post_one_wr()
2066 wqe->wr.num_sge = j; in rvt_post_one_wr()
2074 log_pmtu = qp->log_pmtu; in rvt_post_one_wr()
2075 if (qp->allowed_ops == IB_OPCODE_UD) { in rvt_post_one_wr()
2078 log_pmtu = ah->log_pmtu; in rvt_post_one_wr()
2079 rdma_copy_ah_attr(wqe->ud_wr.attr, &ah->attr); in rvt_post_one_wr()
2082 if (rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL) { in rvt_post_one_wr()
2084 atomic_inc(&qp->local_ops_pending); in rvt_post_one_wr()
2086 wqe->wr.send_flags |= RVT_SEND_COMPLETION_ONLY; in rvt_post_one_wr()
2087 wqe->ssn = 0; in rvt_post_one_wr()
2088 wqe->psn = 0; in rvt_post_one_wr()
2089 wqe->lpsn = 0; in rvt_post_one_wr()
2091 wqe->ssn = qp->s_ssn++; in rvt_post_one_wr()
2092 wqe->psn = qp->s_next_psn; in rvt_post_one_wr()
2093 wqe->lpsn = wqe->psn + in rvt_post_one_wr()
2094 (wqe->length ? in rvt_post_one_wr()
2095 ((wqe->length - 1) >> log_pmtu) : in rvt_post_one_wr()
2099 /* general part of wqe valid - allow for driver checks */ in rvt_post_one_wr()
2100 if (rdi->driver_f.setup_wqe) { in rvt_post_one_wr()
2101 ret = rdi->driver_f.setup_wqe(qp, wqe, call_send); in rvt_post_one_wr()
2106 if (!(rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL)) in rvt_post_one_wr()
2107 qp->s_next_psn = wqe->lpsn + 1; in rvt_post_one_wr()
2110 wqe->wr.send_flags |= RVT_SEND_RESERVE_USED; in rvt_post_one_wr()
2113 wqe->wr.send_flags &= ~RVT_SEND_RESERVE_USED; in rvt_post_one_wr()
2114 qp->s_avail--; in rvt_post_one_wr()
2116 trace_rvt_post_one_wr(qp, wqe, wr->num_sge); in rvt_post_one_wr()
2118 qp->s_head = next; in rvt_post_one_wr()
2123 if (qp->allowed_ops == IB_OPCODE_UD) in rvt_post_one_wr()
2124 rdma_destroy_ah_attr(wqe->ud_wr.attr); in rvt_post_one_wr()
2128 struct rvt_sge *sge = &wqe->sg_list[--j]; in rvt_post_one_wr()
2130 rvt_put_mr(sge->mr); in rvt_post_one_wr()
2136 * rvt_post_send - post a send on a QP
2149 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_post_send()
2155 spin_lock_irqsave(&qp->s_hlock, flags); in rvt_post_send()
2159 * there is no need to do this every time we post a send. in rvt_post_send()
2161 if (unlikely(!(ib_rvt_state_ops[qp->state] & RVT_POST_SEND_OK))) { in rvt_post_send()
2162 spin_unlock_irqrestore(&qp->s_hlock, flags); in rvt_post_send()
2163 return -EINVAL; in rvt_post_send()
2171 call_send = qp->s_head == READ_ONCE(qp->s_last) && !wr->next; in rvt_post_send()
2173 for (; wr; wr = wr->next) { in rvt_post_send()
2182 spin_unlock_irqrestore(&qp->s_hlock, flags); in rvt_post_send()
2189 rdi->driver_f.do_send(qp); in rvt_post_send()
2191 rdi->driver_f.schedule_send_no_lock(qp); in rvt_post_send()
2197 * rvt_post_srq_recv - post a receive on a shared receive queue
2213 for (; wr; wr = wr->next) { in rvt_post_srq_recv()
2218 if ((unsigned)wr->num_sge > srq->rq.max_sge) { in rvt_post_srq_recv()
2220 return -EINVAL; in rvt_post_srq_recv()
2223 spin_lock_irqsave(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2224 wq = srq->rq.kwq; in rvt_post_srq_recv()
2225 next = wq->head + 1; in rvt_post_srq_recv()
2226 if (next >= srq->rq.size) in rvt_post_srq_recv()
2228 if (next == READ_ONCE(wq->tail)) { in rvt_post_srq_recv()
2229 spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2231 return -ENOMEM; in rvt_post_srq_recv()
2234 wqe = rvt_get_rwqe_ptr(&srq->rq, wq->head); in rvt_post_srq_recv()
2235 wqe->wr_id = wr->wr_id; in rvt_post_srq_recv()
2236 wqe->num_sge = wr->num_sge; in rvt_post_srq_recv()
2237 for (i = 0; i < wr->num_sge; i++) { in rvt_post_srq_recv()
2238 wqe->sg_list[i].addr = wr->sg_list[i].addr; in rvt_post_srq_recv()
2239 wqe->sg_list[i].length = wr->sg_list[i].length; in rvt_post_srq_recv()
2240 wqe->sg_list[i].lkey = wr->sg_list[i].lkey; in rvt_post_srq_recv()
2243 smp_store_release(&wq->head, next); in rvt_post_srq_recv()
2244 spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2272 struct ib_wc wc; in init_sge() local
2276 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in init_sge()
2278 rkt = &rdi->lkey_table; in init_sge()
2279 pd = ibpd_to_rvtpd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd); in init_sge()
2280 ss = &qp->r_sge; in init_sge()
2281 ss->sg_list = qp->r_sg_list; in init_sge()
2282 qp->r_len = 0; in init_sge()
2283 for (i = j = 0; i < wqe->num_sge; i++) { in init_sge()
2284 if (wqe->sg_list[i].length == 0) in init_sge()
2287 ret = rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge, in init_sge()
2288 NULL, rvt_cast_sge(&wqe->sg_list[i]), in init_sge()
2292 qp->r_len += wqe->sg_list[i].length; in init_sge()
2295 ss->num_sge = j; in init_sge()
2296 ss->total_len = qp->r_len; in init_sge()
2301 struct rvt_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge; in init_sge()
2303 rvt_put_mr(sge->mr); in init_sge()
2305 ss->num_sge = 0; in init_sge()
2306 memset(&wc, 0, sizeof(wc)); in init_sge()
2307 wc.wr_id = wqe->wr_id; in init_sge()
2308 wc.status = IB_WC_LOC_PROT_ERR; in init_sge()
2309 wc.opcode = IB_WC_RECV; in init_sge()
2310 wc.qp = &qp->ibqp; in init_sge()
2312 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in init_sge()
2317 * get_rvt_head - get head indices of the circular buffer
2321 * Return - head index value
2328 head = RDMA_READ_UAPI_ATOMIC(rq->wq->head); in get_rvt_head()
2330 head = rq->kwq->head; in get_rvt_head()
2336 * rvt_get_rwqe - copy the next RWQE into the QP's RWQE
2338 * @wr_id_only: update qp->r_wr_id only, not qp->r_sge
2340 * Return -1 if there is a local error, 0 if no RWQE is available,
2359 if (qp->ibqp.srq) { in rvt_get_rwqe()
2360 srq = ibsrq_to_rvtsrq(qp->ibqp.srq); in rvt_get_rwqe()
2361 handler = srq->ibsrq.event_handler; in rvt_get_rwqe()
2362 rq = &srq->rq; in rvt_get_rwqe()
2363 ip = srq->ip; in rvt_get_rwqe()
2367 rq = &qp->r_rq; in rvt_get_rwqe()
2368 ip = qp->ip; in rvt_get_rwqe()
2371 spin_lock_irqsave(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2372 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) { in rvt_get_rwqe()
2376 kwq = rq->kwq; in rvt_get_rwqe()
2378 wq = rq->wq; in rvt_get_rwqe()
2379 tail = RDMA_READ_UAPI_ATOMIC(wq->tail); in rvt_get_rwqe()
2381 tail = kwq->tail; in rvt_get_rwqe()
2385 if (tail >= rq->size) in rvt_get_rwqe()
2388 if (kwq->count < RVT_RWQ_COUNT_THRESHOLD) { in rvt_get_rwqe()
2390 kwq->count = rvt_get_rq_count(rq, head, tail); in rvt_get_rwqe()
2392 if (unlikely(kwq->count == 0)) { in rvt_get_rwqe()
2400 * Even though we update the tail index in memory, the verbs in rvt_get_rwqe()
2404 if (++tail >= rq->size) in rvt_get_rwqe()
2407 RDMA_WRITE_UAPI_ATOMIC(wq->tail, tail); in rvt_get_rwqe()
2409 kwq->tail = tail; in rvt_get_rwqe()
2411 ret = -1; in rvt_get_rwqe()
2414 qp->r_wr_id = wqe->wr_id; in rvt_get_rwqe()
2416 kwq->count--; in rvt_get_rwqe()
2418 set_bit(RVT_R_WRID_VALID, &qp->r_aflags); in rvt_get_rwqe()
2424 if (kwq->count < srq->limit) { in rvt_get_rwqe()
2425 kwq->count = in rvt_get_rwqe()
2428 if (kwq->count < srq->limit) { in rvt_get_rwqe()
2431 srq->limit = 0; in rvt_get_rwqe()
2432 spin_unlock_irqrestore(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2433 ev.device = qp->ibqp.device; in rvt_get_rwqe()
2434 ev.element.srq = qp->ibqp.srq; in rvt_get_rwqe()
2436 handler(&ev, srq->ibsrq.srq_context); in rvt_get_rwqe()
2442 spin_unlock_irqrestore(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2449 * rvt_comm_est - handle trap with QP established
2454 qp->r_flags |= RVT_R_COMM_EST; in rvt_comm_est()
2455 if (qp->ibqp.event_handler) { in rvt_comm_est()
2458 ev.device = qp->ibqp.device; in rvt_comm_est()
2459 ev.element.qp = &qp->ibqp; in rvt_comm_est()
2461 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_comm_est()
2471 spin_lock_irqsave(&qp->s_lock, flags); in rvt_rc_error()
2473 spin_unlock_irqrestore(&qp->s_lock, flags); in rvt_rc_error()
2478 ev.device = qp->ibqp.device; in rvt_rc_error()
2479 ev.element.qp = &qp->ibqp; in rvt_rc_error()
2481 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_rc_error()
2487 * rvt_rnr_tbl_to_usec - return index into ib_rvt_rnr_table
2488 * @index - the index
2504 * rvt_add_retry_timer_ext - add/start a retry timer
2505 * @qp - the QP
2506 * @shift - timeout shift to wait for multiple packets
2511 struct ib_qp *ibqp = &qp->ibqp; in rvt_add_retry_timer_ext()
2512 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_add_retry_timer_ext()
2514 lockdep_assert_held(&qp->s_lock); in rvt_add_retry_timer_ext()
2515 qp->s_flags |= RVT_S_TIMER; in rvt_add_retry_timer_ext()
2516 /* 4.096 usec. * (1 << qp->timeout) */ in rvt_add_retry_timer_ext()
2517 qp->s_timer.expires = jiffies + rdi->busy_jiffies + in rvt_add_retry_timer_ext()
2518 (qp->timeout_jiffies << shift); in rvt_add_retry_timer_ext()
2519 add_timer(&qp->s_timer); in rvt_add_retry_timer_ext()
2524 * rvt_add_rnr_timer - add/start an rnr timer on the QP
2532 lockdep_assert_held(&qp->s_lock); in rvt_add_rnr_timer()
2533 qp->s_flags |= RVT_S_WAIT_RNR; in rvt_add_rnr_timer()
2536 hrtimer_start(&qp->s_rnr_timer, in rvt_add_rnr_timer()
2542 * rvt_stop_rc_timers - stop all timers
2548 lockdep_assert_held(&qp->s_lock); in rvt_stop_rc_timers()
2550 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) { in rvt_stop_rc_timers()
2551 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR); in rvt_stop_rc_timers()
2552 del_timer(&qp->s_timer); in rvt_stop_rc_timers()
2553 hrtimer_try_to_cancel(&qp->s_rnr_timer); in rvt_stop_rc_timers()
2559 * rvt_stop_rnr_timer - stop an rnr timer
2567 lockdep_assert_held(&qp->s_lock); in rvt_stop_rnr_timer()
2569 if (qp->s_flags & RVT_S_WAIT_RNR) { in rvt_stop_rnr_timer()
2570 qp->s_flags &= ~RVT_S_WAIT_RNR; in rvt_stop_rnr_timer()
2576 * rvt_del_timers_sync - wait for any timeout routines to exit
2581 del_timer_sync(&qp->s_timer); in rvt_del_timers_sync()
2582 hrtimer_cancel(&qp->s_rnr_timer); in rvt_del_timers_sync()
2592 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_rc_timeout()
2595 spin_lock_irqsave(&qp->r_lock, flags); in rvt_rc_timeout()
2596 spin_lock(&qp->s_lock); in rvt_rc_timeout()
2597 if (qp->s_flags & RVT_S_TIMER) { in rvt_rc_timeout()
2598 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_rc_timeout()
2600 qp->s_flags &= ~RVT_S_TIMER; in rvt_rc_timeout()
2601 rvp->n_rc_timeouts++; in rvt_rc_timeout()
2602 del_timer(&qp->s_timer); in rvt_rc_timeout()
2603 trace_rvt_rc_timeout(qp, qp->s_last_psn + 1); in rvt_rc_timeout()
2604 if (rdi->driver_f.notify_restart_rc) in rvt_rc_timeout()
2605 rdi->driver_f.notify_restart_rc(qp, in rvt_rc_timeout()
2606 qp->s_last_psn + 1, in rvt_rc_timeout()
2608 rdi->driver_f.schedule_send(qp); in rvt_rc_timeout()
2610 spin_unlock(&qp->s_lock); in rvt_rc_timeout()
2611 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_rc_timeout()
2620 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_rc_rnr_retry()
2623 spin_lock_irqsave(&qp->s_lock, flags); in rvt_rc_rnr_retry()
2626 rdi->driver_f.schedule_send(qp); in rvt_rc_rnr_retry()
2627 spin_unlock_irqrestore(&qp->s_lock, flags); in rvt_rc_rnr_retry()
2633 * rvt_qp_iter_init - initial for QP iteration
2636 * @cb: user-defined callback
2641 * The @cb is a user-defined callback and @v is a 64-bit
2646 * Use cases that require memory allocation to succeed
2661 i->rdi = rdi; in rvt_qp_iter_init()
2663 i->specials = rdi->ibdev.phys_port_cnt * 2; in rvt_qp_iter_init()
2664 i->v = v; in rvt_qp_iter_init()
2665 i->cb = cb; in rvt_qp_iter_init()
2672 * rvt_qp_iter_next - return the next QP in iter
2678 * Updates iter->qp with the current QP when the return
2681 * Return: 0 - iter->qp is valid 1 - no more QPs
2686 int n = iter->n; in rvt_qp_iter_next()
2688 struct rvt_qp *pqp = iter->qp; in rvt_qp_iter_next()
2690 struct rvt_dev_info *rdi = iter->rdi; in rvt_qp_iter_next()
2696 * the qp->next hash link to NULL, this works just fine. in rvt_qp_iter_next()
2698 * iter->specials is 2 * # ports in rvt_qp_iter_next()
2700 * n = 0..iter->specials is the special qp indices in rvt_qp_iter_next()
2702 * n = iter->specials..rdi->qp_dev->qp_table_size+iter->specials are in rvt_qp_iter_next()
2706 for (; n < rdi->qp_dev->qp_table_size + iter->specials; n++) { in rvt_qp_iter_next()
2708 qp = rcu_dereference(pqp->next); in rvt_qp_iter_next()
2710 if (n < iter->specials) { in rvt_qp_iter_next()
2714 pidx = n % rdi->ibdev.phys_port_cnt; in rvt_qp_iter_next()
2715 rvp = rdi->ports[pidx]; in rvt_qp_iter_next()
2716 qp = rcu_dereference(rvp->qp[n & 1]); in rvt_qp_iter_next()
2719 rdi->qp_dev->qp_table[ in rvt_qp_iter_next()
2720 (n - iter->specials)]); in rvt_qp_iter_next()
2725 iter->qp = qp; in rvt_qp_iter_next()
2726 iter->n = n; in rvt_qp_iter_next()
2735 * rvt_qp_iter - iterate all QPs
2737 * @v: a 64-bit value
2742 * The @cb is a user-defined callback and @v is a 64-bit
2757 .specials = rdi->ibdev.phys_port_cnt * 2, in rvt_qp_iter()
2786 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND)) in rvt_send_complete()
2788 rdi = ib_to_rvt(qp->ibqp.device); in rvt_send_complete()
2790 old_last = qp->s_last; in rvt_send_complete()
2792 last = rvt_qp_complete_swqe(qp, wqe, rdi->wc_opcode[wqe->wr.opcode], in rvt_send_complete()
2794 if (qp->s_acked == old_last) in rvt_send_complete()
2795 qp->s_acked = last; in rvt_send_complete()
2796 if (qp->s_cur == old_last) in rvt_send_complete()
2797 qp->s_cur = last; in rvt_send_complete()
2798 if (qp->s_tail == old_last) in rvt_send_complete()
2799 qp->s_tail = last; in rvt_send_complete()
2800 if (qp->state == IB_QPS_SQD && last == qp->s_cur) in rvt_send_complete()
2801 qp->s_draining = 0; in rvt_send_complete()
2806 * rvt_copy_sge - copy data to SGE memory
2818 struct rvt_sge *sge = &ss->sge; in rvt_copy_sge()
2822 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_copy_sge()
2823 struct rvt_wss *wss = rdi->wss; in rvt_copy_sge()
2824 unsigned int sge_copy_mode = rdi->dparms.sge_copy_mode; in rvt_copy_sge()
2835 wss_insert(wss, sge->vaddr); in rvt_copy_sge()
2837 wss_insert(wss, (sge->vaddr + PAGE_SIZE)); in rvt_copy_sge()
2847 length -= 8; in rvt_copy_sge()
2862 ((u8 *)sge->vaddr)[i] = ((u8 *)data)[i]; in rvt_copy_sge()
2864 cacheless_memcpy(sge->vaddr, data, len); in rvt_copy_sge()
2866 memcpy(sge->vaddr, data, len); in rvt_copy_sge()
2870 length -= len; in rvt_copy_sge()
2885 rvp->n_pkt_drops++; in loopback_qp_drop()
2890 return sqp->ibqp.qp_type == IB_QPT_RC ? in loopback_qp_drop()
2895 * rvt_ruc_loopback - handle UC and RC loopback requests
2907 struct rvt_dev_info *rdi = ib_to_rvt(sqp->ibqp.device); in rvt_ruc_loopback()
2912 struct ib_wc wc; in rvt_ruc_loopback() local
2922 rvp = rdi->ports[sqp->port_num - 1]; in rvt_ruc_loopback()
2929 qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), rvp, in rvt_ruc_loopback()
2930 sqp->remote_qpn); in rvt_ruc_loopback()
2932 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
2935 if ((sqp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT)) || in rvt_ruc_loopback()
2936 !(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_OR_FLUSH_SEND)) in rvt_ruc_loopback()
2939 sqp->s_flags |= RVT_S_BUSY; in rvt_ruc_loopback()
2942 if (sqp->s_last == READ_ONCE(sqp->s_head)) in rvt_ruc_loopback()
2944 wqe = rvt_get_swqe_ptr(sqp, sqp->s_last); in rvt_ruc_loopback()
2947 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_NEXT_SEND_OK)) { in rvt_ruc_loopback()
2948 if (!(ib_rvt_state_ops[sqp->state] & RVT_FLUSH_SEND)) in rvt_ruc_loopback()
2960 if (sqp->s_last == sqp->s_cur) { in rvt_ruc_loopback()
2961 if (++sqp->s_cur >= sqp->s_size) in rvt_ruc_loopback()
2962 sqp->s_cur = 0; in rvt_ruc_loopback()
2964 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()
2970 spin_lock_irqsave(&qp->r_lock, flags); in rvt_ruc_loopback()
2971 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) || in rvt_ruc_loopback()
2972 qp->ibqp.qp_type != sqp->ibqp.qp_type) { in rvt_ruc_loopback()
2977 memset(&wc, 0, sizeof(wc)); in rvt_ruc_loopback()
2981 sqp->s_sge.sge = wqe->sg_list[0]; in rvt_ruc_loopback()
2982 sqp->s_sge.sg_list = wqe->sg_list + 1; in rvt_ruc_loopback()
2983 sqp->s_sge.num_sge = wqe->wr.num_sge; in rvt_ruc_loopback()
2984 sqp->s_len = wqe->length; in rvt_ruc_loopback()
2985 switch (wqe->wr.opcode) { in rvt_ruc_loopback()
2990 if (!(wqe->wr.send_flags & RVT_SEND_COMPLETION_ONLY)) { in rvt_ruc_loopback()
2992 wqe->wr.ex.invalidate_rkey)) in rvt_ruc_loopback()
3006 if (wqe->length > qp->r_len) in rvt_ruc_loopback()
3008 switch (wqe->wr.opcode) { in rvt_ruc_loopback()
3011 wqe->wr.ex.invalidate_rkey)) { in rvt_ruc_loopback()
3012 wc.wc_flags = IB_WC_WITH_INVALIDATE; in rvt_ruc_loopback()
3013 wc.ex.invalidate_rkey = in rvt_ruc_loopback()
3014 wqe->wr.ex.invalidate_rkey; in rvt_ruc_loopback()
3018 wc.wc_flags = IB_WC_WITH_IMM; in rvt_ruc_loopback()
3019 wc.ex.imm_data = wqe->wr.ex.imm_data; in rvt_ruc_loopback()
3027 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) in rvt_ruc_loopback()
3029 wc.wc_flags = IB_WC_WITH_IMM; in rvt_ruc_loopback()
3030 wc.ex.imm_data = wqe->wr.ex.imm_data; in rvt_ruc_loopback()
3040 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) in rvt_ruc_loopback()
3043 if (wqe->length == 0) in rvt_ruc_loopback()
3045 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, wqe->length, in rvt_ruc_loopback()
3046 wqe->rdma_wr.remote_addr, in rvt_ruc_loopback()
3047 wqe->rdma_wr.rkey, in rvt_ruc_loopback()
3050 qp->r_sge.sg_list = NULL; in rvt_ruc_loopback()
3051 qp->r_sge.num_sge = 1; in rvt_ruc_loopback()
3052 qp->r_sge.total_len = wqe->length; in rvt_ruc_loopback()
3056 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ))) in rvt_ruc_loopback()
3058 if (unlikely(!rvt_rkey_ok(qp, &sqp->s_sge.sge, wqe->length, in rvt_ruc_loopback()
3059 wqe->rdma_wr.remote_addr, in rvt_ruc_loopback()
3060 wqe->rdma_wr.rkey, in rvt_ruc_loopback()
3064 sqp->s_sge.sg_list = NULL; in rvt_ruc_loopback()
3065 sqp->s_sge.num_sge = 1; in rvt_ruc_loopback()
3066 qp->r_sge.sge = wqe->sg_list[0]; in rvt_ruc_loopback()
3067 qp->r_sge.sg_list = wqe->sg_list + 1; in rvt_ruc_loopback()
3068 qp->r_sge.num_sge = wqe->wr.num_sge; in rvt_ruc_loopback()
3069 qp->r_sge.total_len = wqe->length; in rvt_ruc_loopback()
3074 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC))) 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()
3137 atomic_dec(&sqp->local_ops_pending); in rvt_ruc_loopback()
3144 if (qp->ibqp.qp_type == IB_QPT_UC) in rvt_ruc_loopback()
3146 rvp->n_rnr_naks++; in rvt_ruc_loopback()
3151 if (sqp->s_rnr_retry == 0) { in rvt_ruc_loopback()
3155 if (sqp->s_rnr_retry_cnt < 7) in rvt_ruc_loopback()
3156 sqp->s_rnr_retry--; in rvt_ruc_loopback()
3157 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_ruc_loopback()
3158 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
3159 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_RECV_OK)) in rvt_ruc_loopback()
3161 rvt_add_rnr_timer(sqp, qp->r_min_rnr_timer << in rvt_ruc_loopback()
3167 wc.status = IB_WC_LOC_QP_OP_ERR; in rvt_ruc_loopback()
3172 sqp->ibqp.qp_type == IB_QPT_RC ? in rvt_ruc_loopback()
3175 wc.status = IB_WC_LOC_QP_OP_ERR; in rvt_ruc_loopback()
3180 wc.status = IB_WC_LOC_PROT_ERR; in rvt_ruc_loopback()
3183 rvt_rc_error(qp, wc.status); in rvt_ruc_loopback()
3186 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_ruc_loopback()
3188 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
3190 if (sqp->ibqp.qp_type == IB_QPT_RC) { in rvt_ruc_loopback()
3193 sqp->s_flags &= ~RVT_S_BUSY; in rvt_ruc_loopback()
3194 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()
3198 ev.device = sqp->ibqp.device; in rvt_ruc_loopback()
3199 ev.element.qp = &sqp->ibqp; in rvt_ruc_loopback()
3201 sqp->ibqp.event_handler(&ev, sqp->ibqp.qp_context); in rvt_ruc_loopback()
3206 sqp->s_flags &= ~RVT_S_BUSY; in rvt_ruc_loopback()
3208 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()