Lines Matching +full:no +full:- +full:memory +full:- +full:wc

2  * Copyright(c) 2016 - 2020 Intel Corporation.
24 * - Redistributions of source code must retain the above copyright
26 * - Redistributions in binary form must reproduce the above copyright
30 * - Neither the name of Intel Corporation nor the names of its
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
108 * completions as per IB 1.2 C10-96.
139 * there are no security issues. The extra fault recovery machinery in cacheless_memcpy()
147 struct rvt_wss *wss = rdi->wss; in rvt_wss_exit()
153 kfree(wss->entries); in rvt_wss_exit()
154 wss->entries = NULL; in rvt_wss_exit()
155 kfree(rdi->wss); in rvt_wss_exit()
156 rdi->wss = NULL; in rvt_wss_exit()
160 * rvt_wss_init - Init wss data structures
166 unsigned int sge_copy_mode = rdi->dparms.sge_copy_mode; in rvt_wss_init()
167 unsigned int wss_threshold = rdi->dparms.wss_threshold; in rvt_wss_init()
168 unsigned int wss_clean_period = rdi->dparms.wss_clean_period; in rvt_wss_init()
174 int node = rdi->dparms.node; in rvt_wss_init()
177 rdi->wss = NULL; in rvt_wss_init()
181 rdi->wss = kzalloc_node(sizeof(*rdi->wss), GFP_KERNEL, node); in rvt_wss_init()
182 if (!rdi->wss) in rvt_wss_init()
183 return -ENOMEM; in rvt_wss_init()
184 wss = rdi->wss; in rvt_wss_init()
186 /* check for a valid percent range - default to 80 if none or invalid */ in rvt_wss_init()
199 * Calculate the table size - the next power of 2 larger than the in rvt_wss_init()
208 wss->pages_mask = table_bits - 1; in rvt_wss_init()
209 wss->num_entries = table_bits / BITS_PER_LONG; in rvt_wss_init()
211 wss->threshold = (llc_bits * wss_threshold) / 100; in rvt_wss_init()
212 if (wss->threshold == 0) in rvt_wss_init()
213 wss->threshold = 1; in rvt_wss_init()
215 wss->clean_period = wss_clean_period; in rvt_wss_init()
216 atomic_set(&wss->clean_counter, wss_clean_period); in rvt_wss_init()
218 wss->entries = kcalloc_node(wss->num_entries, sizeof(*wss->entries), in rvt_wss_init()
220 if (!wss->entries) { in rvt_wss_init()
222 return -ENOMEM; in rvt_wss_init()
237 * race - the next possible racer will not start until the next clean
250 if (atomic_dec_and_test(&wss->clean_counter)) { in wss_advance_clean_counter()
264 atomic_set(&wss->clean_counter, wss->clean_period); in wss_advance_clean_counter()
270 * is always a power-of-2. in wss_advance_clean_counter()
272 entry = (atomic_inc_return(&wss->clean_entry) - 1) in wss_advance_clean_counter()
273 & (wss->num_entries - 1); in wss_advance_clean_counter()
276 bits = xchg(&wss->entries[entry], 0); in wss_advance_clean_counter()
280 atomic_sub(weight, &wss->total_count); in wss_advance_clean_counter()
289 u32 page = ((unsigned long)address >> PAGE_SHIFT) & wss->pages_mask; in wss_insert()
291 u32 nr = page & (BITS_PER_LONG - 1); in wss_insert()
293 if (!test_and_set_bit(nr, &wss->entries[entry])) in wss_insert()
294 atomic_inc(&wss->total_count); in wss_insert()
304 return atomic_read(&wss->total_count) >= wss->threshold; in wss_exceeds_threshold()
316 spin_lock(&qpt->lock); in get_map_page()
317 if (map->page) in get_map_page()
320 map->page = (void *)page; in get_map_page()
321 spin_unlock(&qpt->lock); in get_map_page()
325 * init_qpn_table - initialize the QP number table for a device
334 if (!(rdi->dparms.qpn_res_end >= rdi->dparms.qpn_res_start)) in init_qpn_table()
335 return -EINVAL; in init_qpn_table()
337 spin_lock_init(&qpt->lock); in init_qpn_table()
339 qpt->last = rdi->dparms.qpn_start; in init_qpn_table()
340 qpt->incr = rdi->dparms.qpn_inc << rdi->dparms.qos_shift; in init_qpn_table()
344 * our qpn table. No need for two. Lets go ahead and mark the bitmaps in init_qpn_table()
350 qpt->nmaps = rdi->dparms.qpn_res_start / RVT_BITS_PER_PAGE; in init_qpn_table()
353 offset = rdi->dparms.qpn_res_start & RVT_BITS_PER_PAGE_MASK; in init_qpn_table()
356 map = &qpt->map[qpt->nmaps]; in init_qpn_table()
358 rvt_pr_info(rdi, "Reserving QPNs from 0x%x to 0x%x for non-verbs use\n", in init_qpn_table()
359 rdi->dparms.qpn_res_start, rdi->dparms.qpn_res_end); in init_qpn_table()
360 for (i = rdi->dparms.qpn_res_start; i <= rdi->dparms.qpn_res_end; i++) { in init_qpn_table()
361 if (!map->page) { in init_qpn_table()
363 if (!map->page) { in init_qpn_table()
364 ret = -ENOMEM; in init_qpn_table()
368 set_bit(offset, map->page); in init_qpn_table()
372 qpt->nmaps++; in init_qpn_table()
381 * free_qpn_table - free the QP number table for a device
388 for (i = 0; i < ARRAY_SIZE(qpt->map); i++) in free_qpn_table()
389 free_page((unsigned long)qpt->map[i].page); in free_qpn_table()
393 * rvt_driver_qp_init - Init driver qp resources
401 int ret = -ENOMEM; in rvt_driver_qp_init()
403 if (!rdi->dparms.qp_table_size) in rvt_driver_qp_init()
404 return -EINVAL; in rvt_driver_qp_init()
410 if (!rdi->driver_f.free_all_qps || in rvt_driver_qp_init()
411 !rdi->driver_f.qp_priv_alloc || in rvt_driver_qp_init()
412 !rdi->driver_f.qp_priv_free || in rvt_driver_qp_init()
413 !rdi->driver_f.notify_qp_reset || in rvt_driver_qp_init()
414 !rdi->driver_f.notify_restart_rc) in rvt_driver_qp_init()
415 return -EINVAL; in rvt_driver_qp_init()
418 rdi->qp_dev = kzalloc_node(sizeof(*rdi->qp_dev), GFP_KERNEL, in rvt_driver_qp_init()
419 rdi->dparms.node); in rvt_driver_qp_init()
420 if (!rdi->qp_dev) in rvt_driver_qp_init()
421 return -ENOMEM; in rvt_driver_qp_init()
424 rdi->qp_dev->qp_table_size = rdi->dparms.qp_table_size; in rvt_driver_qp_init()
425 rdi->qp_dev->qp_table_bits = ilog2(rdi->dparms.qp_table_size); in rvt_driver_qp_init()
426 rdi->qp_dev->qp_table = in rvt_driver_qp_init()
427 kmalloc_array_node(rdi->qp_dev->qp_table_size, in rvt_driver_qp_init()
428 sizeof(*rdi->qp_dev->qp_table), in rvt_driver_qp_init()
429 GFP_KERNEL, rdi->dparms.node); in rvt_driver_qp_init()
430 if (!rdi->qp_dev->qp_table) in rvt_driver_qp_init()
433 for (i = 0; i < rdi->qp_dev->qp_table_size; i++) in rvt_driver_qp_init()
434 RCU_INIT_POINTER(rdi->qp_dev->qp_table[i], NULL); in rvt_driver_qp_init()
436 spin_lock_init(&rdi->qp_dev->qpt_lock); in rvt_driver_qp_init()
439 if (init_qpn_table(rdi, &rdi->qp_dev->qpn_table)) in rvt_driver_qp_init()
442 spin_lock_init(&rdi->n_qps_lock); in rvt_driver_qp_init()
447 kfree(rdi->qp_dev->qp_table); in rvt_driver_qp_init()
448 free_qpn_table(&rdi->qp_dev->qpn_table); in rvt_driver_qp_init()
451 kfree(rdi->qp_dev); in rvt_driver_qp_init()
457 * rvt_free_qp_cb - callback function to reset a qp
459 * @v: a 64-bit value
467 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_free_qp_cb()
470 rvt_reset_qp(rdi, qp, qp->ibqp.qp_type); in rvt_free_qp_cb()
477 * rvt_free_all_qps - check for QPs still in use
481 * Free memory for table.
496 * rvt_qp_exit - clean up qps on device exit
506 rvt_pr_err(rdi, "QP memory leak! %u still in use\n", in rvt_qp_exit()
508 if (!rdi->qp_dev) in rvt_qp_exit()
511 kfree(rdi->qp_dev->qp_table); in rvt_qp_exit()
512 free_qpn_table(&rdi->qp_dev->qpn_table); in rvt_qp_exit()
513 kfree(rdi->qp_dev); in rvt_qp_exit()
519 return (map - qpt->map) * RVT_BITS_PER_PAGE + off; in mk_qpn()
523 * alloc_qpn - Allocate the next available qpn or zero/one for QP type
541 if (rdi->driver_f.alloc_qpn) in alloc_qpn()
542 return rdi->driver_f.alloc_qpn(rdi, qpt, type, port_num); in alloc_qpn()
548 n = 1 << (ret + 2 * (port_num - 1)); in alloc_qpn()
549 spin_lock(&qpt->lock); in alloc_qpn()
550 if (qpt->flags & n) in alloc_qpn()
551 ret = -EINVAL; in alloc_qpn()
553 qpt->flags |= n; in alloc_qpn()
554 spin_unlock(&qpt->lock); in alloc_qpn()
558 qpn = qpt->last + qpt->incr; in alloc_qpn()
560 qpn = qpt->incr | ((qpt->last & 1) ^ 1); in alloc_qpn()
563 map = &qpt->map[qpn / RVT_BITS_PER_PAGE]; in alloc_qpn()
564 max_scan = qpt->nmaps - !offset; in alloc_qpn()
566 if (unlikely(!map->page)) { in alloc_qpn()
568 if (unlikely(!map->page)) in alloc_qpn()
572 if (!test_and_set_bit(offset, map->page)) { in alloc_qpn()
573 qpt->last = qpn; in alloc_qpn()
577 offset += qpt->incr; in alloc_qpn()
580 * That is OK. It gets re-assigned below in alloc_qpn()
590 if (qpt->nmaps == RVT_QPNMAP_ENTRIES) in alloc_qpn()
592 map = &qpt->map[qpt->nmaps++]; in alloc_qpn()
594 offset = qpt->incr | (offset & 1); in alloc_qpn()
595 } else if (map < &qpt->map[qpt->nmaps]) { in alloc_qpn()
598 offset = qpt->incr | (offset & 1); in alloc_qpn()
600 map = &qpt->map[0]; in alloc_qpn()
602 offset = qpt->incr | ((offset & 1) ^ 1); in alloc_qpn()
604 /* there can be no set bits in low-order QoS bits */ in alloc_qpn()
605 WARN_ON(rdi->dparms.qos_shift > 1 && in alloc_qpn()
606 offset & ((BIT(rdi->dparms.qos_shift - 1) - 1) << 1)); in alloc_qpn()
610 ret = -ENOMEM; in alloc_qpn()
617 * rvt_clear_mr_refs - Drop help mr refs
624 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_clear_mr_refs()
626 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags)) in rvt_clear_mr_refs()
627 rvt_put_ss(&qp->s_rdma_read_sge); in rvt_clear_mr_refs()
629 rvt_put_ss(&qp->r_sge); in rvt_clear_mr_refs()
632 while (qp->s_last != qp->s_head) { in rvt_clear_mr_refs()
633 struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_last); in rvt_clear_mr_refs()
636 if (++qp->s_last >= qp->s_size) in rvt_clear_mr_refs()
637 qp->s_last = 0; in rvt_clear_mr_refs()
640 if (qp->s_rdma_mr) { in rvt_clear_mr_refs()
641 rvt_put_mr(qp->s_rdma_mr); in rvt_clear_mr_refs()
642 qp->s_rdma_mr = NULL; in rvt_clear_mr_refs()
646 for (n = 0; qp->s_ack_queue && n < rvt_max_atomic(rdi); n++) { in rvt_clear_mr_refs()
647 struct rvt_ack_entry *e = &qp->s_ack_queue[n]; in rvt_clear_mr_refs()
649 if (e->rdma_sge.mr) { in rvt_clear_mr_refs()
650 rvt_put_mr(e->rdma_sge.mr); in rvt_clear_mr_refs()
651 e->rdma_sge.mr = NULL; in rvt_clear_mr_refs()
657 * rvt_swqe_has_lkey - return true if lkey is used by swqe
658 * @wqe - the send wqe
659 * @lkey - the lkey
667 for (i = 0; i < wqe->wr.num_sge; i++) { in rvt_swqe_has_lkey()
668 struct rvt_sge *sge = &wqe->sg_list[i]; in rvt_swqe_has_lkey()
670 if (rvt_mr_has_lkey(sge->mr, lkey)) in rvt_swqe_has_lkey()
677 * rvt_qp_sends_has_lkey - return true is qp sends use lkey
678 * @qp - the rvt_qp
679 * @lkey - the lkey
683 u32 s_last = qp->s_last; in rvt_qp_sends_has_lkey()
685 while (s_last != qp->s_head) { in rvt_qp_sends_has_lkey()
691 if (++s_last >= qp->s_size) in rvt_qp_sends_has_lkey()
694 if (qp->s_rdma_mr) in rvt_qp_sends_has_lkey()
695 if (rvt_mr_has_lkey(qp->s_rdma_mr, lkey)) in rvt_qp_sends_has_lkey()
701 * rvt_qp_acks_has_lkey - return true if acks have lkey
702 * @qp - the qp
703 * @lkey - the lkey
708 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_qp_acks_has_lkey()
710 for (i = 0; qp->s_ack_queue && i < rvt_max_atomic(rdi); i++) { in rvt_qp_acks_has_lkey()
711 struct rvt_ack_entry *e = &qp->s_ack_queue[i]; in rvt_qp_acks_has_lkey()
713 if (rvt_mr_has_lkey(e->rdma_sge.mr, lkey)) in rvt_qp_acks_has_lkey()
720 * rvt_qp_mr_clean - clean up remote ops for lkey
721 * @qp - the qp
722 * @lkey - the lkey that is being de-registered
734 if (qp->ibqp.qp_type == IB_QPT_SMI || in rvt_qp_mr_clean()
735 qp->ibqp.qp_type == IB_QPT_GSI) in rvt_qp_mr_clean()
738 spin_lock_irq(&qp->r_lock); in rvt_qp_mr_clean()
739 spin_lock(&qp->s_hlock); in rvt_qp_mr_clean()
740 spin_lock(&qp->s_lock); in rvt_qp_mr_clean()
742 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET) in rvt_qp_mr_clean()
745 if (rvt_ss_has_lkey(&qp->r_sge, lkey) || in rvt_qp_mr_clean()
750 spin_unlock(&qp->s_lock); in rvt_qp_mr_clean()
751 spin_unlock(&qp->s_hlock); in rvt_qp_mr_clean()
752 spin_unlock_irq(&qp->r_lock); in rvt_qp_mr_clean()
756 ev.device = qp->ibqp.device; in rvt_qp_mr_clean()
757 ev.element.qp = &qp->ibqp; in rvt_qp_mr_clean()
759 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_qp_mr_clean()
764 * rvt_remove_qp - remove qp form table
773 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_remove_qp()
774 u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits); in rvt_remove_qp()
778 spin_lock_irqsave(&rdi->qp_dev->qpt_lock, flags); in rvt_remove_qp()
780 if (rcu_dereference_protected(rvp->qp[0], in rvt_remove_qp()
781 lockdep_is_held(&rdi->qp_dev->qpt_lock)) == qp) { in rvt_remove_qp()
782 RCU_INIT_POINTER(rvp->qp[0], NULL); in rvt_remove_qp()
783 } else if (rcu_dereference_protected(rvp->qp[1], in rvt_remove_qp()
784 lockdep_is_held(&rdi->qp_dev->qpt_lock)) == qp) { in rvt_remove_qp()
785 RCU_INIT_POINTER(rvp->qp[1], NULL); in rvt_remove_qp()
791 qpp = &rdi->qp_dev->qp_table[n]; in rvt_remove_qp()
793 lockdep_is_held(&rdi->qp_dev->qpt_lock))) != NULL; in rvt_remove_qp()
794 qpp = &q->next) { in rvt_remove_qp()
797 rcu_dereference_protected(qp->next, in rvt_remove_qp()
798 lockdep_is_held(&rdi->qp_dev->qpt_lock))); in rvt_remove_qp()
806 spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags); in rvt_remove_qp()
814 * rvt_alloc_rq - allocate memory for user or kernel buffer
820 * Return: If memory allocation failed, return -ENONEM
822 * queues and non-shared receive queues to allocate
823 * memory.
829 rq->wq = vmalloc_user(sizeof(struct rvt_rwq) + size); in rvt_alloc_rq()
830 if (!rq->wq) in rvt_alloc_rq()
832 /* need kwq with no buffers */ in rvt_alloc_rq()
833 rq->kwq = kzalloc_node(sizeof(*rq->kwq), GFP_KERNEL, node); in rvt_alloc_rq()
834 if (!rq->kwq) in rvt_alloc_rq()
836 rq->kwq->curr_wq = rq->wq->wq; in rvt_alloc_rq()
839 rq->kwq = in rvt_alloc_rq()
841 if (!rq->kwq) in rvt_alloc_rq()
843 rq->kwq->curr_wq = rq->kwq->wq; in rvt_alloc_rq()
846 spin_lock_init(&rq->kwq->p_lock); in rvt_alloc_rq()
847 spin_lock_init(&rq->kwq->c_lock); in rvt_alloc_rq()
851 return -ENOMEM; in rvt_alloc_rq()
855 * rvt_init_qp - initialize the QP state to the reset state
867 qp->remote_qpn = 0; in rvt_init_qp()
868 qp->qkey = 0; in rvt_init_qp()
869 qp->qp_access_flags = 0; in rvt_init_qp()
870 qp->s_flags &= RVT_S_SIGNAL_REQ_WR; in rvt_init_qp()
871 qp->s_hdrwords = 0; in rvt_init_qp()
872 qp->s_wqe = NULL; in rvt_init_qp()
873 qp->s_draining = 0; in rvt_init_qp()
874 qp->s_next_psn = 0; in rvt_init_qp()
875 qp->s_last_psn = 0; in rvt_init_qp()
876 qp->s_sending_psn = 0; in rvt_init_qp()
877 qp->s_sending_hpsn = 0; in rvt_init_qp()
878 qp->s_psn = 0; in rvt_init_qp()
879 qp->r_psn = 0; in rvt_init_qp()
880 qp->r_msn = 0; in rvt_init_qp()
882 qp->s_state = IB_OPCODE_RC_SEND_LAST; in rvt_init_qp()
883 qp->r_state = IB_OPCODE_RC_SEND_LAST; in rvt_init_qp()
885 qp->s_state = IB_OPCODE_UC_SEND_LAST; in rvt_init_qp()
886 qp->r_state = IB_OPCODE_UC_SEND_LAST; in rvt_init_qp()
888 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE; in rvt_init_qp()
889 qp->r_nak_state = 0; in rvt_init_qp()
890 qp->r_aflags = 0; in rvt_init_qp()
891 qp->r_flags = 0; in rvt_init_qp()
892 qp->s_head = 0; in rvt_init_qp()
893 qp->s_tail = 0; in rvt_init_qp()
894 qp->s_cur = 0; in rvt_init_qp()
895 qp->s_acked = 0; in rvt_init_qp()
896 qp->s_last = 0; in rvt_init_qp()
897 qp->s_ssn = 1; in rvt_init_qp()
898 qp->s_lsn = 0; in rvt_init_qp()
899 qp->s_mig_state = IB_MIG_MIGRATED; in rvt_init_qp()
900 qp->r_head_ack_queue = 0; in rvt_init_qp()
901 qp->s_tail_ack_queue = 0; in rvt_init_qp()
902 qp->s_acked_ack_queue = 0; in rvt_init_qp()
903 qp->s_num_rd_atomic = 0; in rvt_init_qp()
904 qp->r_sge.num_sge = 0; in rvt_init_qp()
905 atomic_set(&qp->s_reserved_used, 0); in rvt_init_qp()
909 * _rvt_reset_qp - initialize the QP state to the reset state
917 __must_hold(&qp->s_lock) in _rvt_reset_qp()
918 __must_hold(&qp->s_hlock) in _rvt_reset_qp()
919 __must_hold(&qp->r_lock) in _rvt_reset_qp()
921 lockdep_assert_held(&qp->r_lock); in _rvt_reset_qp()
922 lockdep_assert_held(&qp->s_hlock); in _rvt_reset_qp()
923 lockdep_assert_held(&qp->s_lock); in _rvt_reset_qp()
924 if (qp->state != IB_QPS_RESET) { in _rvt_reset_qp()
925 qp->state = IB_QPS_RESET; in _rvt_reset_qp()
928 rdi->driver_f.flush_qp_waiters(qp); in _rvt_reset_qp()
930 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_ANY_WAIT); in _rvt_reset_qp()
931 spin_unlock(&qp->s_lock); in _rvt_reset_qp()
932 spin_unlock(&qp->s_hlock); in _rvt_reset_qp()
933 spin_unlock_irq(&qp->r_lock); in _rvt_reset_qp()
936 rdi->driver_f.stop_send_queue(qp); in _rvt_reset_qp()
939 rdi->driver_f.quiesce_qp(qp); in _rvt_reset_qp()
945 spin_lock_irq(&qp->r_lock); in _rvt_reset_qp()
946 spin_lock(&qp->s_hlock); in _rvt_reset_qp()
947 spin_lock(&qp->s_lock); in _rvt_reset_qp()
951 * Let the driver do any tear down or re-init it needs to for in _rvt_reset_qp()
954 rdi->driver_f.notify_qp_reset(qp); in _rvt_reset_qp()
957 lockdep_assert_held(&qp->r_lock); in _rvt_reset_qp()
958 lockdep_assert_held(&qp->s_hlock); in _rvt_reset_qp()
959 lockdep_assert_held(&qp->s_lock); in _rvt_reset_qp()
963 * rvt_reset_qp - initialize the QP state to the reset state
974 spin_lock_irq(&qp->r_lock); in rvt_reset_qp()
975 spin_lock(&qp->s_hlock); in rvt_reset_qp()
976 spin_lock(&qp->s_lock); in rvt_reset_qp()
978 spin_unlock(&qp->s_lock); in rvt_reset_qp()
979 spin_unlock(&qp->s_hlock); in rvt_reset_qp()
980 spin_unlock_irq(&qp->r_lock); in rvt_reset_qp()
983 /** rvt_free_qpn - Free a qpn from the bit map
994 map = qpt->map + (qpn & RVT_QPN_MASK) / RVT_BITS_PER_PAGE; in rvt_free_qpn()
995 if (map->page) in rvt_free_qpn()
996 clear_bit(qpn & RVT_BITS_PER_PAGE_MASK, map->page); in rvt_free_qpn()
1000 * get_allowed_ops - Given a QP type return the appropriate allowed OP
1010 * free_ud_wq_attr - Clean up AH attribute cache for UD QPs
1021 for (i = 0; qp->allowed_ops == IB_OPCODE_UD && i < qp->s_size; i++) { in free_ud_wq_attr()
1023 kfree(wqe->ud_wr.attr); in free_ud_wq_attr()
1024 wqe->ud_wr.attr = NULL; in free_ud_wq_attr()
1029 * alloc_ud_wq_attr - AH attribute cache for UD QPs
1041 for (i = 0; qp->allowed_ops == IB_OPCODE_UD && i < qp->s_size; i++) { in alloc_ud_wq_attr()
1043 wqe->ud_wr.attr = kzalloc_node(sizeof(*wqe->ud_wr.attr), in alloc_ud_wq_attr()
1045 if (!wqe->ud_wr.attr) { in alloc_ud_wq_attr()
1047 return -ENOMEM; in alloc_ud_wq_attr()
1055 * rvt_create_qp - create a queue pair for a device
1077 struct ib_qp *ret = ERR_PTR(-ENOMEM); in rvt_create_qp()
1078 struct rvt_dev_info *rdi = ib_to_rvt(ibpd->device); in rvt_create_qp()
1084 return ERR_PTR(-EINVAL); in rvt_create_qp()
1086 if (init_attr->cap.max_send_sge > rdi->dparms.props.max_send_sge || in rvt_create_qp()
1087 init_attr->cap.max_send_wr > rdi->dparms.props.max_qp_wr || in rvt_create_qp()
1088 (init_attr->create_flags && in rvt_create_qp()
1089 init_attr->create_flags != IB_QP_CREATE_NETDEV_USE)) in rvt_create_qp()
1090 return ERR_PTR(-EINVAL); in rvt_create_qp()
1092 /* Check receive queue parameters if no SRQ is specified. */ in rvt_create_qp()
1093 if (!init_attr->srq) { in rvt_create_qp()
1094 if (init_attr->cap.max_recv_sge > in rvt_create_qp()
1095 rdi->dparms.props.max_recv_sge || in rvt_create_qp()
1096 init_attr->cap.max_recv_wr > rdi->dparms.props.max_qp_wr) in rvt_create_qp()
1097 return ERR_PTR(-EINVAL); in rvt_create_qp()
1099 if (init_attr->cap.max_send_sge + in rvt_create_qp()
1100 init_attr->cap.max_send_wr + in rvt_create_qp()
1101 init_attr->cap.max_recv_sge + in rvt_create_qp()
1102 init_attr->cap.max_recv_wr == 0) in rvt_create_qp()
1103 return ERR_PTR(-EINVAL); in rvt_create_qp()
1106 init_attr->cap.max_send_wr + 1 + in rvt_create_qp()
1107 rdi->dparms.reserved_operations; in rvt_create_qp()
1108 switch (init_attr->qp_type) { in rvt_create_qp()
1111 if (init_attr->port_num == 0 || in rvt_create_qp()
1112 init_attr->port_num > ibpd->device->phys_port_cnt) in rvt_create_qp()
1113 return ERR_PTR(-EINVAL); in rvt_create_qp()
1118 sz = struct_size(swq, sg_list, init_attr->cap.max_send_sge); in rvt_create_qp()
1119 swq = vzalloc_node(array_size(sz, sqsize), rdi->dparms.node); in rvt_create_qp()
1121 return ERR_PTR(-ENOMEM); in rvt_create_qp()
1125 if (init_attr->srq) { in rvt_create_qp()
1126 struct rvt_srq *srq = ibsrq_to_rvtsrq(init_attr->srq); in rvt_create_qp()
1128 if (srq->rq.max_sge > 1) in rvt_create_qp()
1129 sg_list_sz = sizeof(*qp->r_sg_list) * in rvt_create_qp()
1130 (srq->rq.max_sge - 1); in rvt_create_qp()
1131 } else if (init_attr->cap.max_recv_sge > 1) in rvt_create_qp()
1132 sg_list_sz = sizeof(*qp->r_sg_list) * in rvt_create_qp()
1133 (init_attr->cap.max_recv_sge - 1); in rvt_create_qp()
1135 rdi->dparms.node); in rvt_create_qp()
1138 qp->allowed_ops = get_allowed_ops(init_attr->qp_type); in rvt_create_qp()
1140 RCU_INIT_POINTER(qp->next, NULL); in rvt_create_qp()
1141 if (init_attr->qp_type == IB_QPT_RC) { in rvt_create_qp()
1142 qp->s_ack_queue = in rvt_create_qp()
1144 sizeof(*qp->s_ack_queue), in rvt_create_qp()
1146 rdi->dparms.node); in rvt_create_qp()
1147 if (!qp->s_ack_queue) in rvt_create_qp()
1151 timer_setup(&qp->s_timer, rvt_rc_timeout, 0); in rvt_create_qp()
1152 hrtimer_init(&qp->s_rnr_timer, CLOCK_MONOTONIC, in rvt_create_qp()
1154 qp->s_rnr_timer.function = rvt_rc_rnr_retry; in rvt_create_qp()
1160 priv = rdi->driver_f.qp_priv_alloc(rdi, qp); in rvt_create_qp()
1165 qp->priv = priv; in rvt_create_qp()
1166 qp->timeout_jiffies = in rvt_create_qp()
1167 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) / in rvt_create_qp()
1169 if (init_attr->srq) { in rvt_create_qp()
1172 qp->r_rq.size = init_attr->cap.max_recv_wr + 1; in rvt_create_qp()
1173 qp->r_rq.max_sge = init_attr->cap.max_recv_sge; in rvt_create_qp()
1174 sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) + in rvt_create_qp()
1176 err = rvt_alloc_rq(&qp->r_rq, qp->r_rq.size * sz, in rvt_create_qp()
1177 rdi->dparms.node, udata); in rvt_create_qp()
1185 * ib_create_qp() will initialize qp->ibqp in rvt_create_qp()
1186 * except for qp->ibqp.qp_num. in rvt_create_qp()
1188 spin_lock_init(&qp->r_lock); in rvt_create_qp()
1189 spin_lock_init(&qp->s_hlock); in rvt_create_qp()
1190 spin_lock_init(&qp->s_lock); in rvt_create_qp()
1191 atomic_set(&qp->refcount, 0); in rvt_create_qp()
1192 atomic_set(&qp->local_ops_pending, 0); in rvt_create_qp()
1193 init_waitqueue_head(&qp->wait); in rvt_create_qp()
1194 INIT_LIST_HEAD(&qp->rspwait); in rvt_create_qp()
1195 qp->state = IB_QPS_RESET; in rvt_create_qp()
1196 qp->s_wq = swq; in rvt_create_qp()
1197 qp->s_size = sqsize; in rvt_create_qp()
1198 qp->s_avail = init_attr->cap.max_send_wr; in rvt_create_qp()
1199 qp->s_max_sge = init_attr->cap.max_send_sge; in rvt_create_qp()
1200 if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR) in rvt_create_qp()
1201 qp->s_flags = RVT_S_SIGNAL_REQ_WR; in rvt_create_qp()
1202 err = alloc_ud_wq_attr(qp, rdi->dparms.node); in rvt_create_qp()
1208 if (init_attr->create_flags & IB_QP_CREATE_NETDEV_USE) in rvt_create_qp()
1211 err = alloc_qpn(rdi, &rdi->qp_dev->qpn_table, in rvt_create_qp()
1212 init_attr->qp_type, in rvt_create_qp()
1213 init_attr->port_num, in rvt_create_qp()
1219 qp->ibqp.qp_num = err; in rvt_create_qp()
1220 if (init_attr->create_flags & IB_QP_CREATE_NETDEV_USE) in rvt_create_qp()
1221 qp->ibqp.qp_num |= RVT_AIP_QP_BASE; in rvt_create_qp()
1222 qp->port_num = init_attr->port_num; in rvt_create_qp()
1223 rvt_init_qp(rdi, qp, init_attr->qp_type); in rvt_create_qp()
1224 if (rdi->driver_f.qp_priv_init) { in rvt_create_qp()
1225 err = rdi->driver_f.qp_priv_init(rdi, qp, init_attr); in rvt_create_qp()
1235 return ERR_PTR(-EOPNOTSUPP); in rvt_create_qp()
1238 init_attr->cap.max_inline_data = 0; in rvt_create_qp()
1244 if (udata && udata->outlen >= sizeof(__u64)) { in rvt_create_qp()
1245 if (!qp->r_rq.wq) { in rvt_create_qp()
1255 u32 s = sizeof(struct rvt_rwq) + qp->r_rq.size * sz; in rvt_create_qp()
1257 qp->ip = rvt_create_mmap_info(rdi, s, udata, in rvt_create_qp()
1258 qp->r_rq.wq); in rvt_create_qp()
1259 if (IS_ERR(qp->ip)) { in rvt_create_qp()
1260 ret = ERR_CAST(qp->ip); in rvt_create_qp()
1264 err = ib_copy_to_udata(udata, &qp->ip->offset, in rvt_create_qp()
1265 sizeof(qp->ip->offset)); in rvt_create_qp()
1271 qp->pid = current->pid; in rvt_create_qp()
1274 spin_lock(&rdi->n_qps_lock); in rvt_create_qp()
1275 if (rdi->n_qps_allocated == rdi->dparms.props.max_qp) { in rvt_create_qp()
1276 spin_unlock(&rdi->n_qps_lock); in rvt_create_qp()
1277 ret = ERR_PTR(-ENOMEM); in rvt_create_qp()
1281 rdi->n_qps_allocated++; in rvt_create_qp()
1291 if (init_attr->qp_type == IB_QPT_RC) { in rvt_create_qp()
1292 rdi->n_rc_qps++; in rvt_create_qp()
1293 rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL; in rvt_create_qp()
1295 spin_unlock(&rdi->n_qps_lock); in rvt_create_qp()
1297 if (qp->ip) { in rvt_create_qp()
1298 spin_lock_irq(&rdi->pending_lock); in rvt_create_qp()
1299 list_add(&qp->ip->pending_mmaps, &rdi->pending_mmaps); in rvt_create_qp()
1300 spin_unlock_irq(&rdi->pending_lock); in rvt_create_qp()
1303 ret = &qp->ibqp; in rvt_create_qp()
1308 if (qp->ip) in rvt_create_qp()
1309 kref_put(&qp->ip->ref, rvt_release_mmap_info); in rvt_create_qp()
1312 rvt_free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num); in rvt_create_qp()
1318 rvt_free_rq(&qp->r_rq); in rvt_create_qp()
1321 rdi->driver_f.qp_priv_free(rdi, qp); in rvt_create_qp()
1324 kfree(qp->s_ack_queue); in rvt_create_qp()
1334 * rvt_error_qp - put a QP into the error state
1346 struct ib_wc wc; in rvt_error_qp() local
1348 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_error_qp()
1350 lockdep_assert_held(&qp->r_lock); in rvt_error_qp()
1351 lockdep_assert_held(&qp->s_lock); in rvt_error_qp()
1352 if (qp->state == IB_QPS_ERR || qp->state == IB_QPS_RESET) in rvt_error_qp()
1355 qp->state = IB_QPS_ERR; in rvt_error_qp()
1357 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) { in rvt_error_qp()
1358 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR); in rvt_error_qp()
1359 del_timer(&qp->s_timer); in rvt_error_qp()
1362 if (qp->s_flags & RVT_S_ANY_WAIT_SEND) in rvt_error_qp()
1363 qp->s_flags &= ~RVT_S_ANY_WAIT_SEND; in rvt_error_qp()
1365 rdi->driver_f.notify_error_qp(qp); in rvt_error_qp()
1368 if (READ_ONCE(qp->s_last) != qp->s_head) in rvt_error_qp()
1369 rdi->driver_f.schedule_send(qp); in rvt_error_qp()
1373 memset(&wc, 0, sizeof(wc)); in rvt_error_qp()
1374 wc.qp = &qp->ibqp; in rvt_error_qp()
1375 wc.opcode = IB_WC_RECV; in rvt_error_qp()
1377 if (test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) { in rvt_error_qp()
1378 wc.wr_id = qp->r_wr_id; in rvt_error_qp()
1379 wc.status = err; in rvt_error_qp()
1380 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_error_qp()
1382 wc.status = IB_WC_WR_FLUSH_ERR; in rvt_error_qp()
1384 if (qp->r_rq.kwq) { in rvt_error_qp()
1390 spin_lock(&qp->r_rq.kwq->c_lock); in rvt_error_qp()
1391 /* qp->ip used to validate if there is a user buffer mmaped */ in rvt_error_qp()
1392 if (qp->ip) { in rvt_error_qp()
1393 wq = qp->r_rq.wq; in rvt_error_qp()
1394 head = RDMA_READ_UAPI_ATOMIC(wq->head); in rvt_error_qp()
1395 tail = RDMA_READ_UAPI_ATOMIC(wq->tail); in rvt_error_qp()
1397 kwq = qp->r_rq.kwq; in rvt_error_qp()
1398 head = kwq->head; in rvt_error_qp()
1399 tail = kwq->tail; in rvt_error_qp()
1402 if (head >= qp->r_rq.size) in rvt_error_qp()
1404 if (tail >= qp->r_rq.size) in rvt_error_qp()
1407 wc.wr_id = rvt_get_rwqe_ptr(&qp->r_rq, tail)->wr_id; in rvt_error_qp()
1408 if (++tail >= qp->r_rq.size) in rvt_error_qp()
1410 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_error_qp()
1412 if (qp->ip) in rvt_error_qp()
1413 RDMA_WRITE_UAPI_ATOMIC(wq->tail, tail); in rvt_error_qp()
1415 kwq->tail = tail; in rvt_error_qp()
1416 spin_unlock(&qp->r_rq.kwq->c_lock); in rvt_error_qp()
1417 } else if (qp->ibqp.event_handler) { in rvt_error_qp()
1432 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_insert_qp()
1436 spin_lock_irqsave(&rdi->qp_dev->qpt_lock, flags); in rvt_insert_qp()
1438 if (qp->ibqp.qp_num <= 1) { in rvt_insert_qp()
1439 rcu_assign_pointer(rvp->qp[qp->ibqp.qp_num], qp); in rvt_insert_qp()
1441 u32 n = hash_32(qp->ibqp.qp_num, rdi->qp_dev->qp_table_bits); in rvt_insert_qp()
1443 qp->next = rdi->qp_dev->qp_table[n]; in rvt_insert_qp()
1444 rcu_assign_pointer(rdi->qp_dev->qp_table[n], qp); in rvt_insert_qp()
1448 spin_unlock_irqrestore(&rdi->qp_dev->qpt_lock, flags); in rvt_insert_qp()
1452 * rvt_modify_qp - modify the attributes of a queue pair
1463 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_modify_qp()
1472 spin_lock_irq(&qp->r_lock); in rvt_modify_qp()
1473 spin_lock(&qp->s_hlock); in rvt_modify_qp()
1474 spin_lock(&qp->s_lock); in rvt_modify_qp()
1477 attr->cur_qp_state : qp->state; in rvt_modify_qp()
1478 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; in rvt_modify_qp()
1479 opa_ah = rdma_cap_opa_ah(ibqp->device, qp->port_num); in rvt_modify_qp()
1481 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, in rvt_modify_qp()
1485 if (rdi->driver_f.check_modify_qp && in rvt_modify_qp()
1486 rdi->driver_f.check_modify_qp(qp, attr, attr_mask, udata)) in rvt_modify_qp()
1491 if (rdma_ah_get_dlid(&attr->ah_attr) >= in rvt_modify_qp()
1495 if (rdma_ah_get_dlid(&attr->ah_attr) >= in rvt_modify_qp()
1500 if (rvt_check_ah(qp->ibqp.device, &attr->ah_attr)) in rvt_modify_qp()
1506 if (rdma_ah_get_dlid(&attr->alt_ah_attr) >= in rvt_modify_qp()
1510 if (rdma_ah_get_dlid(&attr->alt_ah_attr) >= in rvt_modify_qp()
1515 if (rvt_check_ah(qp->ibqp.device, &attr->alt_ah_attr)) in rvt_modify_qp()
1517 if (attr->alt_pkey_index >= rvt_get_npkeys(rdi)) in rvt_modify_qp()
1522 if (attr->pkey_index >= rvt_get_npkeys(rdi)) in rvt_modify_qp()
1526 if (attr->min_rnr_timer > 31) in rvt_modify_qp()
1530 if (qp->ibqp.qp_type == IB_QPT_SMI || in rvt_modify_qp()
1531 qp->ibqp.qp_type == IB_QPT_GSI || in rvt_modify_qp()
1532 attr->port_num == 0 || in rvt_modify_qp()
1533 attr->port_num > ibqp->device->phys_port_cnt) in rvt_modify_qp()
1537 if (attr->dest_qp_num > RVT_QPN_MASK) in rvt_modify_qp()
1541 if (attr->retry_cnt > 7) in rvt_modify_qp()
1545 if (attr->rnr_retry > 7) in rvt_modify_qp()
1551 * that to a small mtu. We'll set qp->path_mtu in rvt_modify_qp()
1557 pmtu = rdi->driver_f.get_pmtu_from_attr(rdi, qp, attr); in rvt_modify_qp()
1563 if (attr->path_mig_state == IB_MIG_REARM) { in rvt_modify_qp()
1564 if (qp->s_mig_state == IB_MIG_ARMED) in rvt_modify_qp()
1568 } else if (attr->path_mig_state == IB_MIG_MIGRATED) { in rvt_modify_qp()
1569 if (qp->s_mig_state == IB_MIG_REARM) in rvt_modify_qp()
1573 if (qp->s_mig_state == IB_MIG_ARMED) in rvt_modify_qp()
1581 if (attr->max_dest_rd_atomic > rdi->dparms.max_rdma_atomic) in rvt_modify_qp()
1586 if (qp->state != IB_QPS_RESET) in rvt_modify_qp()
1587 _rvt_reset_qp(rdi, qp, ibqp->qp_type); in rvt_modify_qp()
1591 /* Allow event to re-trigger if QP set to RTR more than once */ in rvt_modify_qp()
1592 qp->r_flags &= ~RVT_R_COMM_EST; in rvt_modify_qp()
1593 qp->state = new_state; in rvt_modify_qp()
1597 qp->s_draining = qp->s_last != qp->s_cur; in rvt_modify_qp()
1598 qp->state = new_state; in rvt_modify_qp()
1602 if (qp->ibqp.qp_type == IB_QPT_RC) in rvt_modify_qp()
1604 qp->state = new_state; in rvt_modify_qp()
1612 qp->state = new_state; in rvt_modify_qp()
1617 qp->s_pkey_index = attr->pkey_index; in rvt_modify_qp()
1620 qp->port_num = attr->port_num; in rvt_modify_qp()
1623 qp->remote_qpn = attr->dest_qp_num; in rvt_modify_qp()
1626 qp->s_next_psn = attr->sq_psn & rdi->dparms.psn_modify_mask; in rvt_modify_qp()
1627 qp->s_psn = qp->s_next_psn; in rvt_modify_qp()
1628 qp->s_sending_psn = qp->s_next_psn; in rvt_modify_qp()
1629 qp->s_last_psn = qp->s_next_psn - 1; in rvt_modify_qp()
1630 qp->s_sending_hpsn = qp->s_last_psn; in rvt_modify_qp()
1634 qp->r_psn = attr->rq_psn & rdi->dparms.psn_modify_mask; in rvt_modify_qp()
1637 qp->qp_access_flags = attr->qp_access_flags; in rvt_modify_qp()
1640 rdma_replace_ah_attr(&qp->remote_ah_attr, &attr->ah_attr); in rvt_modify_qp()
1641 qp->s_srate = rdma_ah_get_static_rate(&attr->ah_attr); in rvt_modify_qp()
1642 qp->srate_mbps = ib_rate_to_mbps(qp->s_srate); in rvt_modify_qp()
1646 rdma_replace_ah_attr(&qp->alt_ah_attr, &attr->alt_ah_attr); in rvt_modify_qp()
1647 qp->s_alt_pkey_index = attr->alt_pkey_index; in rvt_modify_qp()
1651 qp->s_mig_state = attr->path_mig_state; in rvt_modify_qp()
1653 qp->remote_ah_attr = qp->alt_ah_attr; in rvt_modify_qp()
1654 qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr); in rvt_modify_qp()
1655 qp->s_pkey_index = qp->s_alt_pkey_index; in rvt_modify_qp()
1660 qp->pmtu = rdi->driver_f.mtu_from_qp(rdi, qp, pmtu); in rvt_modify_qp()
1661 qp->log_pmtu = ilog2(qp->pmtu); in rvt_modify_qp()
1665 qp->s_retry_cnt = attr->retry_cnt; in rvt_modify_qp()
1666 qp->s_retry = attr->retry_cnt; in rvt_modify_qp()
1670 qp->s_rnr_retry_cnt = attr->rnr_retry; in rvt_modify_qp()
1671 qp->s_rnr_retry = attr->rnr_retry; in rvt_modify_qp()
1675 qp->r_min_rnr_timer = attr->min_rnr_timer; in rvt_modify_qp()
1678 qp->timeout = attr->timeout; in rvt_modify_qp()
1679 qp->timeout_jiffies = rvt_timeout_to_jiffies(qp->timeout); in rvt_modify_qp()
1683 qp->qkey = attr->qkey; in rvt_modify_qp()
1686 qp->r_max_rd_atomic = attr->max_dest_rd_atomic; in rvt_modify_qp()
1689 qp->s_max_rd_atomic = attr->max_rd_atomic; in rvt_modify_qp()
1691 if (rdi->driver_f.modify_qp) in rvt_modify_qp()
1692 rdi->driver_f.modify_qp(qp, attr, attr_mask, udata); in rvt_modify_qp()
1694 spin_unlock(&qp->s_lock); in rvt_modify_qp()
1695 spin_unlock(&qp->s_hlock); in rvt_modify_qp()
1696 spin_unlock_irq(&qp->r_lock); in rvt_modify_qp()
1702 ev.device = qp->ibqp.device; in rvt_modify_qp()
1703 ev.element.qp = &qp->ibqp; in rvt_modify_qp()
1705 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_modify_qp()
1708 ev.device = qp->ibqp.device; in rvt_modify_qp()
1709 ev.element.qp = &qp->ibqp; in rvt_modify_qp()
1711 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_modify_qp()
1716 spin_unlock(&qp->s_lock); in rvt_modify_qp()
1717 spin_unlock(&qp->s_hlock); in rvt_modify_qp()
1718 spin_unlock_irq(&qp->r_lock); in rvt_modify_qp()
1719 return -EINVAL; in rvt_modify_qp()
1723 * rvt_destroy_qp - destroy a queue pair
1734 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_destroy_qp()
1736 rvt_reset_qp(rdi, qp, ibqp->qp_type); in rvt_destroy_qp()
1738 wait_event(qp->wait, !atomic_read(&qp->refcount)); in rvt_destroy_qp()
1740 rvt_free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num); in rvt_destroy_qp()
1742 spin_lock(&rdi->n_qps_lock); in rvt_destroy_qp()
1743 rdi->n_qps_allocated--; in rvt_destroy_qp()
1744 if (qp->ibqp.qp_type == IB_QPT_RC) { in rvt_destroy_qp()
1745 rdi->n_rc_qps--; in rvt_destroy_qp()
1746 rdi->busy_jiffies = rdi->n_rc_qps / RC_QP_SCALING_INTERVAL; in rvt_destroy_qp()
1748 spin_unlock(&rdi->n_qps_lock); in rvt_destroy_qp()
1750 if (qp->ip) in rvt_destroy_qp()
1751 kref_put(&qp->ip->ref, rvt_release_mmap_info); in rvt_destroy_qp()
1752 kvfree(qp->r_rq.kwq); in rvt_destroy_qp()
1753 rdi->driver_f.qp_priv_free(rdi, qp); in rvt_destroy_qp()
1754 kfree(qp->s_ack_queue); in rvt_destroy_qp()
1755 rdma_destroy_ah_attr(&qp->remote_ah_attr); in rvt_destroy_qp()
1756 rdma_destroy_ah_attr(&qp->alt_ah_attr); in rvt_destroy_qp()
1758 vfree(qp->s_wq); in rvt_destroy_qp()
1764 * rvt_query_qp - query an ipbq
1776 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_query_qp()
1778 attr->qp_state = qp->state; in rvt_query_qp()
1779 attr->cur_qp_state = attr->qp_state; in rvt_query_qp()
1780 attr->path_mtu = rdi->driver_f.mtu_to_path_mtu(qp->pmtu); in rvt_query_qp()
1781 attr->path_mig_state = qp->s_mig_state; in rvt_query_qp()
1782 attr->qkey = qp->qkey; in rvt_query_qp()
1783 attr->rq_psn = qp->r_psn & rdi->dparms.psn_mask; in rvt_query_qp()
1784 attr->sq_psn = qp->s_next_psn & rdi->dparms.psn_mask; in rvt_query_qp()
1785 attr->dest_qp_num = qp->remote_qpn; in rvt_query_qp()
1786 attr->qp_access_flags = qp->qp_access_flags; in rvt_query_qp()
1787 attr->cap.max_send_wr = qp->s_size - 1 - in rvt_query_qp()
1788 rdi->dparms.reserved_operations; in rvt_query_qp()
1789 attr->cap.max_recv_wr = qp->ibqp.srq ? 0 : qp->r_rq.size - 1; in rvt_query_qp()
1790 attr->cap.max_send_sge = qp->s_max_sge; in rvt_query_qp()
1791 attr->cap.max_recv_sge = qp->r_rq.max_sge; in rvt_query_qp()
1792 attr->cap.max_inline_data = 0; in rvt_query_qp()
1793 attr->ah_attr = qp->remote_ah_attr; in rvt_query_qp()
1794 attr->alt_ah_attr = qp->alt_ah_attr; in rvt_query_qp()
1795 attr->pkey_index = qp->s_pkey_index; in rvt_query_qp()
1796 attr->alt_pkey_index = qp->s_alt_pkey_index; in rvt_query_qp()
1797 attr->en_sqd_async_notify = 0; in rvt_query_qp()
1798 attr->sq_draining = qp->s_draining; in rvt_query_qp()
1799 attr->max_rd_atomic = qp->s_max_rd_atomic; in rvt_query_qp()
1800 attr->max_dest_rd_atomic = qp->r_max_rd_atomic; in rvt_query_qp()
1801 attr->min_rnr_timer = qp->r_min_rnr_timer; in rvt_query_qp()
1802 attr->port_num = qp->port_num; in rvt_query_qp()
1803 attr->timeout = qp->timeout; in rvt_query_qp()
1804 attr->retry_cnt = qp->s_retry_cnt; in rvt_query_qp()
1805 attr->rnr_retry = qp->s_rnr_retry_cnt; in rvt_query_qp()
1806 attr->alt_port_num = in rvt_query_qp()
1807 rdma_ah_get_port_num(&qp->alt_ah_attr); in rvt_query_qp()
1808 attr->alt_timeout = qp->alt_timeout; in rvt_query_qp()
1810 init_attr->event_handler = qp->ibqp.event_handler; in rvt_query_qp()
1811 init_attr->qp_context = qp->ibqp.qp_context; in rvt_query_qp()
1812 init_attr->send_cq = qp->ibqp.send_cq; in rvt_query_qp()
1813 init_attr->recv_cq = qp->ibqp.recv_cq; in rvt_query_qp()
1814 init_attr->srq = qp->ibqp.srq; in rvt_query_qp()
1815 init_attr->cap = attr->cap; in rvt_query_qp()
1816 if (qp->s_flags & RVT_S_SIGNAL_REQ_WR) in rvt_query_qp()
1817 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR; in rvt_query_qp()
1819 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; in rvt_query_qp()
1820 init_attr->qp_type = qp->ibqp.qp_type; in rvt_query_qp()
1821 init_attr->port_num = qp->port_num; in rvt_query_qp()
1826 * rvt_post_receive - post a receive on a QP
1839 struct rvt_krwq *wq = qp->r_rq.kwq; in rvt_post_recv()
1841 int qp_err_flush = (ib_rvt_state_ops[qp->state] & RVT_FLUSH_RECV) && in rvt_post_recv()
1842 !qp->ibqp.srq; in rvt_post_recv()
1845 if (!(ib_rvt_state_ops[qp->state] & RVT_POST_RECV_OK) || !wq) { in rvt_post_recv()
1847 return -EINVAL; in rvt_post_recv()
1850 for (; wr; wr = wr->next) { in rvt_post_recv()
1855 if ((unsigned)wr->num_sge > qp->r_rq.max_sge) { in rvt_post_recv()
1857 return -EINVAL; in rvt_post_recv()
1860 spin_lock_irqsave(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1861 next = wq->head + 1; in rvt_post_recv()
1862 if (next >= qp->r_rq.size) in rvt_post_recv()
1864 if (next == READ_ONCE(wq->tail)) { in rvt_post_recv()
1865 spin_unlock_irqrestore(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1867 return -ENOMEM; in rvt_post_recv()
1870 struct ib_wc wc; in rvt_post_recv() local
1872 memset(&wc, 0, sizeof(wc)); in rvt_post_recv()
1873 wc.qp = &qp->ibqp; in rvt_post_recv()
1874 wc.opcode = IB_WC_RECV; in rvt_post_recv()
1875 wc.wr_id = wr->wr_id; in rvt_post_recv()
1876 wc.status = IB_WC_WR_FLUSH_ERR; in rvt_post_recv()
1877 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in rvt_post_recv()
1879 wqe = rvt_get_rwqe_ptr(&qp->r_rq, wq->head); in rvt_post_recv()
1880 wqe->wr_id = wr->wr_id; in rvt_post_recv()
1881 wqe->num_sge = wr->num_sge; in rvt_post_recv()
1882 for (i = 0; i < wr->num_sge; i++) { in rvt_post_recv()
1883 wqe->sg_list[i].addr = wr->sg_list[i].addr; in rvt_post_recv()
1884 wqe->sg_list[i].length = wr->sg_list[i].length; in rvt_post_recv()
1885 wqe->sg_list[i].lkey = wr->sg_list[i].lkey; in rvt_post_recv()
1891 smp_store_release(&wq->head, next); in rvt_post_recv()
1893 spin_unlock_irqrestore(&qp->r_rq.kwq->p_lock, flags); in rvt_post_recv()
1899 * rvt_qp_valid_operation - validate post send wr request
1900 * @qp - the qp
1901 * @post-parms - the post send table for the driver
1902 * @wr - the work request
1923 if (wr->opcode >= RVT_OPERATION_MAX || !post_parms[wr->opcode].length) in rvt_qp_valid_operation()
1924 return -EINVAL; in rvt_qp_valid_operation()
1925 if (!(post_parms[wr->opcode].qpt_support & BIT(qp->ibqp.qp_type))) in rvt_qp_valid_operation()
1926 return -EINVAL; in rvt_qp_valid_operation()
1927 if ((post_parms[wr->opcode].flags & RVT_OPERATION_PRIV) && in rvt_qp_valid_operation()
1928 ibpd_to_rvtpd(qp->ibqp.pd)->user) in rvt_qp_valid_operation()
1929 return -EINVAL; in rvt_qp_valid_operation()
1930 if (post_parms[wr->opcode].flags & RVT_OPERATION_ATOMIC_SGE && in rvt_qp_valid_operation()
1931 (wr->num_sge == 0 || in rvt_qp_valid_operation()
1932 wr->sg_list[0].length < sizeof(u64) || in rvt_qp_valid_operation()
1933 wr->sg_list[0].addr & (sizeof(u64) - 1))) in rvt_qp_valid_operation()
1934 return -EINVAL; in rvt_qp_valid_operation()
1935 if (post_parms[wr->opcode].flags & RVT_OPERATION_ATOMIC && in rvt_qp_valid_operation()
1936 !qp->s_max_rd_atomic) in rvt_qp_valid_operation()
1937 return -EINVAL; in rvt_qp_valid_operation()
1938 len = post_parms[wr->opcode].length; in rvt_qp_valid_operation()
1940 if (qp->ibqp.qp_type != IB_QPT_UC && in rvt_qp_valid_operation()
1941 qp->ibqp.qp_type != IB_QPT_RC) { in rvt_qp_valid_operation()
1942 if (qp->ibqp.pd != ud_wr(wr)->ah->pd) in rvt_qp_valid_operation()
1943 return -EINVAL; in rvt_qp_valid_operation()
1950 * rvt_qp_is_avail - determine queue capacity
1958 * For non reserved operations, the qp->s_avail
1961 * The return value is zero or a -ENOMEM.
1976 reserved_used = atomic_read(&qp->s_reserved_used); in rvt_qp_is_avail()
1977 if (reserved_used >= rdi->dparms.reserved_operations) in rvt_qp_is_avail()
1978 return -ENOMEM; in rvt_qp_is_avail()
1981 /* non-reserved operations */ in rvt_qp_is_avail()
1982 if (likely(qp->s_avail)) in rvt_qp_is_avail()
1985 slast = smp_load_acquire(&qp->s_last); in rvt_qp_is_avail()
1986 if (qp->s_head >= slast) in rvt_qp_is_avail()
1987 avail = qp->s_size - (qp->s_head - slast); in rvt_qp_is_avail()
1989 avail = slast - qp->s_head; in rvt_qp_is_avail()
1991 reserved_used = atomic_read(&qp->s_reserved_used); in rvt_qp_is_avail()
1992 avail = avail - 1 - in rvt_qp_is_avail()
1993 (rdi->dparms.reserved_operations - reserved_used); in rvt_qp_is_avail()
1996 return -ENOMEM; in rvt_qp_is_avail()
1997 qp->s_avail = avail; in rvt_qp_is_avail()
1998 if (WARN_ON(qp->s_avail > in rvt_qp_is_avail()
1999 (qp->s_size - 1 - rdi->dparms.reserved_operations))) in rvt_qp_is_avail()
2002 qp->ibqp.qp_num, qp->s_size, qp->s_avail, in rvt_qp_is_avail()
2003 qp->s_head, qp->s_tail, qp->s_cur, in rvt_qp_is_avail()
2004 qp->s_acked, qp->s_last); in rvt_qp_is_avail()
2009 * rvt_post_one_wr - post one RC, UC, or UD send work request
2024 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_post_one_wr()
2034 if (unlikely(wr->num_sge > qp->s_max_sge)) in rvt_post_one_wr()
2035 return -EINVAL; in rvt_post_one_wr()
2037 ret = rvt_qp_valid_operation(qp, rdi->post_parms, wr); in rvt_post_one_wr()
2048 * not required and no previous local invalidate ops are pending. in rvt_post_one_wr()
2053 if ((rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL)) { in rvt_post_one_wr()
2054 switch (wr->opcode) { in rvt_post_one_wr()
2057 reg_wr(wr)->mr, in rvt_post_one_wr()
2058 reg_wr(wr)->key, in rvt_post_one_wr()
2059 reg_wr(wr)->access); in rvt_post_one_wr()
2060 if (ret || !(wr->send_flags & IB_SEND_SIGNALED)) in rvt_post_one_wr()
2064 if ((wr->send_flags & IB_SEND_FENCE) || in rvt_post_one_wr()
2065 atomic_read(&qp->local_ops_pending)) { in rvt_post_one_wr()
2069 qp, wr->ex.invalidate_rkey); in rvt_post_one_wr()
2070 if (ret || !(wr->send_flags & IB_SEND_SIGNALED)) in rvt_post_one_wr()
2075 return -EINVAL; in rvt_post_one_wr()
2079 reserved_op = rdi->post_parms[wr->opcode].flags & in rvt_post_one_wr()
2085 next = qp->s_head + 1; in rvt_post_one_wr()
2086 if (next >= qp->s_size) in rvt_post_one_wr()
2089 rkt = &rdi->lkey_table; in rvt_post_one_wr()
2090 pd = ibpd_to_rvtpd(qp->ibqp.pd); in rvt_post_one_wr()
2091 wqe = rvt_get_swqe_ptr(qp, qp->s_head); in rvt_post_one_wr()
2094 memcpy(&wqe->wr, wr, cplen); in rvt_post_one_wr()
2096 wqe->length = 0; in rvt_post_one_wr()
2098 if (wr->num_sge) { in rvt_post_one_wr()
2101 acc = wr->opcode >= IB_WR_RDMA_READ ? in rvt_post_one_wr()
2103 for (i = 0; i < wr->num_sge; i++) { in rvt_post_one_wr()
2104 u32 length = wr->sg_list[i].length; in rvt_post_one_wr()
2108 ret = rvt_lkey_ok(rkt, pd, &wqe->sg_list[j], last_sge, in rvt_post_one_wr()
2109 &wr->sg_list[i], acc); in rvt_post_one_wr()
2112 wqe->length += length; in rvt_post_one_wr()
2114 last_sge = &wqe->sg_list[j]; in rvt_post_one_wr()
2117 wqe->wr.num_sge = j; in rvt_post_one_wr()
2125 log_pmtu = qp->log_pmtu; in rvt_post_one_wr()
2126 if (qp->allowed_ops == IB_OPCODE_UD) { in rvt_post_one_wr()
2129 log_pmtu = ah->log_pmtu; in rvt_post_one_wr()
2130 rdma_copy_ah_attr(wqe->ud_wr.attr, &ah->attr); in rvt_post_one_wr()
2133 if (rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL) { in rvt_post_one_wr()
2135 atomic_inc(&qp->local_ops_pending); in rvt_post_one_wr()
2137 wqe->wr.send_flags |= RVT_SEND_COMPLETION_ONLY; in rvt_post_one_wr()
2138 wqe->ssn = 0; in rvt_post_one_wr()
2139 wqe->psn = 0; in rvt_post_one_wr()
2140 wqe->lpsn = 0; in rvt_post_one_wr()
2142 wqe->ssn = qp->s_ssn++; in rvt_post_one_wr()
2143 wqe->psn = qp->s_next_psn; in rvt_post_one_wr()
2144 wqe->lpsn = wqe->psn + in rvt_post_one_wr()
2145 (wqe->length ? in rvt_post_one_wr()
2146 ((wqe->length - 1) >> log_pmtu) : in rvt_post_one_wr()
2150 /* general part of wqe valid - allow for driver checks */ in rvt_post_one_wr()
2151 if (rdi->driver_f.setup_wqe) { in rvt_post_one_wr()
2152 ret = rdi->driver_f.setup_wqe(qp, wqe, call_send); in rvt_post_one_wr()
2157 if (!(rdi->post_parms[wr->opcode].flags & RVT_OPERATION_LOCAL)) in rvt_post_one_wr()
2158 qp->s_next_psn = wqe->lpsn + 1; in rvt_post_one_wr()
2161 wqe->wr.send_flags |= RVT_SEND_RESERVE_USED; in rvt_post_one_wr()
2164 wqe->wr.send_flags &= ~RVT_SEND_RESERVE_USED; in rvt_post_one_wr()
2165 qp->s_avail--; in rvt_post_one_wr()
2167 trace_rvt_post_one_wr(qp, wqe, wr->num_sge); in rvt_post_one_wr()
2169 qp->s_head = next; in rvt_post_one_wr()
2174 if (qp->allowed_ops == IB_OPCODE_UD) in rvt_post_one_wr()
2175 rdma_destroy_ah_attr(wqe->ud_wr.attr); in rvt_post_one_wr()
2179 struct rvt_sge *sge = &wqe->sg_list[--j]; in rvt_post_one_wr()
2181 rvt_put_mr(sge->mr); in rvt_post_one_wr()
2187 * rvt_post_send - post a send on a QP
2200 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_post_send()
2206 spin_lock_irqsave(&qp->s_hlock, flags); in rvt_post_send()
2210 * there is no need to do this every time we post a send. in rvt_post_send()
2212 if (unlikely(!(ib_rvt_state_ops[qp->state] & RVT_POST_SEND_OK))) { in rvt_post_send()
2213 spin_unlock_irqrestore(&qp->s_hlock, flags); in rvt_post_send()
2214 return -EINVAL; in rvt_post_send()
2222 call_send = qp->s_head == READ_ONCE(qp->s_last) && !wr->next; in rvt_post_send()
2224 for (; wr; wr = wr->next) { in rvt_post_send()
2233 spin_unlock_irqrestore(&qp->s_hlock, flags); in rvt_post_send()
2240 rdi->driver_f.do_send(qp); in rvt_post_send()
2242 rdi->driver_f.schedule_send_no_lock(qp); in rvt_post_send()
2248 * rvt_post_srq_receive - post a receive on a shared receive queue
2264 for (; wr; wr = wr->next) { in rvt_post_srq_recv()
2269 if ((unsigned)wr->num_sge > srq->rq.max_sge) { in rvt_post_srq_recv()
2271 return -EINVAL; in rvt_post_srq_recv()
2274 spin_lock_irqsave(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2275 wq = srq->rq.kwq; in rvt_post_srq_recv()
2276 next = wq->head + 1; in rvt_post_srq_recv()
2277 if (next >= srq->rq.size) in rvt_post_srq_recv()
2279 if (next == READ_ONCE(wq->tail)) { in rvt_post_srq_recv()
2280 spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2282 return -ENOMEM; in rvt_post_srq_recv()
2285 wqe = rvt_get_rwqe_ptr(&srq->rq, wq->head); in rvt_post_srq_recv()
2286 wqe->wr_id = wr->wr_id; in rvt_post_srq_recv()
2287 wqe->num_sge = wr->num_sge; in rvt_post_srq_recv()
2288 for (i = 0; i < wr->num_sge; i++) { in rvt_post_srq_recv()
2289 wqe->sg_list[i].addr = wr->sg_list[i].addr; in rvt_post_srq_recv()
2290 wqe->sg_list[i].length = wr->sg_list[i].length; in rvt_post_srq_recv()
2291 wqe->sg_list[i].lkey = wr->sg_list[i].lkey; in rvt_post_srq_recv()
2294 smp_store_release(&wq->head, next); in rvt_post_srq_recv()
2295 spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags); in rvt_post_srq_recv()
2323 struct ib_wc wc; in init_sge() local
2327 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in init_sge()
2329 rkt = &rdi->lkey_table; in init_sge()
2330 pd = ibpd_to_rvtpd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd); in init_sge()
2331 ss = &qp->r_sge; in init_sge()
2332 ss->sg_list = qp->r_sg_list; in init_sge()
2333 qp->r_len = 0; in init_sge()
2334 for (i = j = 0; i < wqe->num_sge; i++) { in init_sge()
2335 if (wqe->sg_list[i].length == 0) in init_sge()
2338 ret = rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge, in init_sge()
2339 NULL, rvt_cast_sge(&wqe->sg_list[i]), in init_sge()
2343 qp->r_len += wqe->sg_list[i].length; in init_sge()
2346 ss->num_sge = j; in init_sge()
2347 ss->total_len = qp->r_len; in init_sge()
2352 struct rvt_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge; in init_sge()
2354 rvt_put_mr(sge->mr); in init_sge()
2356 ss->num_sge = 0; in init_sge()
2357 memset(&wc, 0, sizeof(wc)); in init_sge()
2358 wc.wr_id = wqe->wr_id; in init_sge()
2359 wc.status = IB_WC_LOC_PROT_ERR; in init_sge()
2360 wc.opcode = IB_WC_RECV; in init_sge()
2361 wc.qp = &qp->ibqp; in init_sge()
2363 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); in init_sge()
2368 * get_rvt_head - get head indices of the circular buffer
2372 * Return - head index value
2379 head = RDMA_READ_UAPI_ATOMIC(rq->wq->head); in get_rvt_head()
2381 head = rq->kwq->head; in get_rvt_head()
2387 * rvt_get_rwqe - copy the next RWQE into the QP's RWQE
2389 * @wr_id_only: update qp->r_wr_id only, not qp->r_sge
2391 * Return -1 if there is a local error, 0 if no RWQE is available,
2410 if (qp->ibqp.srq) { in rvt_get_rwqe()
2411 srq = ibsrq_to_rvtsrq(qp->ibqp.srq); in rvt_get_rwqe()
2412 handler = srq->ibsrq.event_handler; in rvt_get_rwqe()
2413 rq = &srq->rq; in rvt_get_rwqe()
2414 ip = srq->ip; in rvt_get_rwqe()
2418 rq = &qp->r_rq; in rvt_get_rwqe()
2419 ip = qp->ip; in rvt_get_rwqe()
2422 spin_lock_irqsave(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2423 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) { in rvt_get_rwqe()
2427 kwq = rq->kwq; in rvt_get_rwqe()
2429 wq = rq->wq; in rvt_get_rwqe()
2430 tail = RDMA_READ_UAPI_ATOMIC(wq->tail); in rvt_get_rwqe()
2432 tail = kwq->tail; in rvt_get_rwqe()
2436 if (tail >= rq->size) in rvt_get_rwqe()
2439 if (kwq->count < RVT_RWQ_COUNT_THRESHOLD) { in rvt_get_rwqe()
2441 kwq->count = rvt_get_rq_count(rq, head, tail); in rvt_get_rwqe()
2443 if (unlikely(kwq->count == 0)) { in rvt_get_rwqe()
2451 * Even though we update the tail index in memory, the verbs in rvt_get_rwqe()
2455 if (++tail >= rq->size) in rvt_get_rwqe()
2458 RDMA_WRITE_UAPI_ATOMIC(wq->tail, tail); in rvt_get_rwqe()
2460 kwq->tail = tail; in rvt_get_rwqe()
2462 ret = -1; in rvt_get_rwqe()
2465 qp->r_wr_id = wqe->wr_id; in rvt_get_rwqe()
2467 kwq->count--; in rvt_get_rwqe()
2469 set_bit(RVT_R_WRID_VALID, &qp->r_aflags); in rvt_get_rwqe()
2475 if (kwq->count < srq->limit) { in rvt_get_rwqe()
2476 kwq->count = in rvt_get_rwqe()
2479 if (kwq->count < srq->limit) { in rvt_get_rwqe()
2482 srq->limit = 0; in rvt_get_rwqe()
2483 spin_unlock_irqrestore(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2484 ev.device = qp->ibqp.device; in rvt_get_rwqe()
2485 ev.element.srq = qp->ibqp.srq; in rvt_get_rwqe()
2487 handler(&ev, srq->ibsrq.srq_context); in rvt_get_rwqe()
2493 spin_unlock_irqrestore(&rq->kwq->c_lock, flags); in rvt_get_rwqe()
2500 * qp_comm_est - handle trap with QP established
2505 qp->r_flags |= RVT_R_COMM_EST; in rvt_comm_est()
2506 if (qp->ibqp.event_handler) { in rvt_comm_est()
2509 ev.device = qp->ibqp.device; in rvt_comm_est()
2510 ev.element.qp = &qp->ibqp; in rvt_comm_est()
2512 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_comm_est()
2522 spin_lock_irqsave(&qp->s_lock, flags); in rvt_rc_error()
2524 spin_unlock_irqrestore(&qp->s_lock, flags); in rvt_rc_error()
2529 ev.device = qp->ibqp.device; in rvt_rc_error()
2530 ev.element.qp = &qp->ibqp; in rvt_rc_error()
2532 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); in rvt_rc_error()
2538 * rvt_rnr_tbl_to_usec - return index into ib_rvt_rnr_table
2539 * @index - the index
2555 * rvt_add_retry_timer_ext - add/start a retry timer
2556 * @qp - the QP
2557 * @shift - timeout shift to wait for multiple packets
2562 struct ib_qp *ibqp = &qp->ibqp; in rvt_add_retry_timer_ext()
2563 struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); in rvt_add_retry_timer_ext()
2565 lockdep_assert_held(&qp->s_lock); in rvt_add_retry_timer_ext()
2566 qp->s_flags |= RVT_S_TIMER; in rvt_add_retry_timer_ext()
2567 /* 4.096 usec. * (1 << qp->timeout) */ in rvt_add_retry_timer_ext()
2568 qp->s_timer.expires = jiffies + rdi->busy_jiffies + in rvt_add_retry_timer_ext()
2569 (qp->timeout_jiffies << shift); in rvt_add_retry_timer_ext()
2570 add_timer(&qp->s_timer); in rvt_add_retry_timer_ext()
2575 * rvt_add_rnr_timer - add/start an rnr timer on the QP
2583 lockdep_assert_held(&qp->s_lock); in rvt_add_rnr_timer()
2584 qp->s_flags |= RVT_S_WAIT_RNR; in rvt_add_rnr_timer()
2587 hrtimer_start(&qp->s_rnr_timer, in rvt_add_rnr_timer()
2593 * rvt_stop_rc_timers - stop all timers
2599 lockdep_assert_held(&qp->s_lock); in rvt_stop_rc_timers()
2601 if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) { in rvt_stop_rc_timers()
2602 qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR); in rvt_stop_rc_timers()
2603 del_timer(&qp->s_timer); in rvt_stop_rc_timers()
2604 hrtimer_try_to_cancel(&qp->s_rnr_timer); in rvt_stop_rc_timers()
2610 * rvt_stop_rnr_timer - stop an rnr timer
2611 * @qp - the QP
2618 lockdep_assert_held(&qp->s_lock); in rvt_stop_rnr_timer()
2620 if (qp->s_flags & RVT_S_WAIT_RNR) { in rvt_stop_rnr_timer()
2621 qp->s_flags &= ~RVT_S_WAIT_RNR; in rvt_stop_rnr_timer()
2627 * rvt_del_timers_sync - wait for any timeout routines to exit
2632 del_timer_sync(&qp->s_timer); in rvt_del_timers_sync()
2633 hrtimer_cancel(&qp->s_rnr_timer); in rvt_del_timers_sync()
2643 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_rc_timeout()
2646 spin_lock_irqsave(&qp->r_lock, flags); in rvt_rc_timeout()
2647 spin_lock(&qp->s_lock); in rvt_rc_timeout()
2648 if (qp->s_flags & RVT_S_TIMER) { in rvt_rc_timeout()
2649 struct rvt_ibport *rvp = rdi->ports[qp->port_num - 1]; in rvt_rc_timeout()
2651 qp->s_flags &= ~RVT_S_TIMER; in rvt_rc_timeout()
2652 rvp->n_rc_timeouts++; in rvt_rc_timeout()
2653 del_timer(&qp->s_timer); in rvt_rc_timeout()
2654 trace_rvt_rc_timeout(qp, qp->s_last_psn + 1); in rvt_rc_timeout()
2655 if (rdi->driver_f.notify_restart_rc) in rvt_rc_timeout()
2656 rdi->driver_f.notify_restart_rc(qp, in rvt_rc_timeout()
2657 qp->s_last_psn + 1, in rvt_rc_timeout()
2659 rdi->driver_f.schedule_send(qp); in rvt_rc_timeout()
2661 spin_unlock(&qp->s_lock); in rvt_rc_timeout()
2662 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_rc_timeout()
2671 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_rc_rnr_retry()
2674 spin_lock_irqsave(&qp->s_lock, flags); in rvt_rc_rnr_retry()
2677 rdi->driver_f.schedule_send(qp); in rvt_rc_rnr_retry()
2678 spin_unlock_irqrestore(&qp->s_lock, flags); in rvt_rc_rnr_retry()
2684 * rvt_qp_iter_init - initial for QP iteration
2687 * @cb: user-defined callback
2692 * The @cb is a user-defined callback and @v is a 64-bit
2697 * Use cases that require memory allocation to succeed
2712 i->rdi = rdi; in rvt_qp_iter_init()
2714 i->specials = rdi->ibdev.phys_port_cnt * 2; in rvt_qp_iter_init()
2715 i->v = v; in rvt_qp_iter_init()
2716 i->cb = cb; in rvt_qp_iter_init()
2723 * rvt_qp_iter_next - return the next QP in iter
2729 * Updates iter->qp with the current QP when the return
2732 * Return: 0 - iter->qp is valid 1 - no more QPs
2737 int n = iter->n; in rvt_qp_iter_next()
2739 struct rvt_qp *pqp = iter->qp; in rvt_qp_iter_next()
2741 struct rvt_dev_info *rdi = iter->rdi; in rvt_qp_iter_next()
2747 * the qp->next hash link to NULL, this works just fine. in rvt_qp_iter_next()
2749 * iter->specials is 2 * # ports in rvt_qp_iter_next()
2751 * n = 0..iter->specials is the special qp indices in rvt_qp_iter_next()
2753 * n = iter->specials..rdi->qp_dev->qp_table_size+iter->specials are in rvt_qp_iter_next()
2757 for (; n < rdi->qp_dev->qp_table_size + iter->specials; n++) { in rvt_qp_iter_next()
2759 qp = rcu_dereference(pqp->next); in rvt_qp_iter_next()
2761 if (n < iter->specials) { in rvt_qp_iter_next()
2765 pidx = n % rdi->ibdev.phys_port_cnt; in rvt_qp_iter_next()
2766 rvp = rdi->ports[pidx]; in rvt_qp_iter_next()
2767 qp = rcu_dereference(rvp->qp[n & 1]); in rvt_qp_iter_next()
2770 rdi->qp_dev->qp_table[ in rvt_qp_iter_next()
2771 (n - iter->specials)]); in rvt_qp_iter_next()
2776 iter->qp = qp; in rvt_qp_iter_next()
2777 iter->n = n; in rvt_qp_iter_next()
2786 * rvt_qp_iter - iterate all QPs
2788 * @v: a 64-bit value
2793 * The @cb is a user-defined callback and @v is a 64-bit
2808 .specials = rdi->ibdev.phys_port_cnt * 2, in rvt_qp_iter()
2837 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND)) in rvt_send_complete()
2839 rdi = ib_to_rvt(qp->ibqp.device); in rvt_send_complete()
2841 old_last = qp->s_last; in rvt_send_complete()
2843 last = rvt_qp_complete_swqe(qp, wqe, rdi->wc_opcode[wqe->wr.opcode], in rvt_send_complete()
2845 if (qp->s_acked == old_last) in rvt_send_complete()
2846 qp->s_acked = last; in rvt_send_complete()
2847 if (qp->s_cur == old_last) in rvt_send_complete()
2848 qp->s_cur = last; in rvt_send_complete()
2849 if (qp->s_tail == old_last) in rvt_send_complete()
2850 qp->s_tail = last; in rvt_send_complete()
2851 if (qp->state == IB_QPS_SQD && last == qp->s_cur) in rvt_send_complete()
2852 qp->s_draining = 0; in rvt_send_complete()
2857 * rvt_copy_sge - copy data to SGE memory
2869 struct rvt_sge *sge = &ss->sge; in rvt_copy_sge()
2873 struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); in rvt_copy_sge()
2874 struct rvt_wss *wss = rdi->wss; in rvt_copy_sge()
2875 unsigned int sge_copy_mode = rdi->dparms.sge_copy_mode; in rvt_copy_sge()
2886 wss_insert(wss, sge->vaddr); in rvt_copy_sge()
2888 wss_insert(wss, (sge->vaddr + PAGE_SIZE)); in rvt_copy_sge()
2898 length -= 8; in rvt_copy_sge()
2913 ((u8 *)sge->vaddr)[i] = ((u8 *)data)[i]; in rvt_copy_sge()
2915 cacheless_memcpy(sge->vaddr, data, len); in rvt_copy_sge()
2917 memcpy(sge->vaddr, data, len); in rvt_copy_sge()
2921 length -= len; in rvt_copy_sge()
2936 rvp->n_pkt_drops++; in loopback_qp_drop()
2941 return sqp->ibqp.qp_type == IB_QPT_RC ? in loopback_qp_drop()
2946 * ruc_loopback - handle UC and RC loopback requests
2958 struct rvt_dev_info *rdi = ib_to_rvt(sqp->ibqp.device); in rvt_ruc_loopback()
2963 struct ib_wc wc; in rvt_ruc_loopback() local
2973 rvp = rdi->ports[sqp->port_num - 1]; in rvt_ruc_loopback()
2980 qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), rvp, in rvt_ruc_loopback()
2981 sqp->remote_qpn); in rvt_ruc_loopback()
2983 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
2986 if ((sqp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT)) || in rvt_ruc_loopback()
2987 !(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_OR_FLUSH_SEND)) in rvt_ruc_loopback()
2990 sqp->s_flags |= RVT_S_BUSY; in rvt_ruc_loopback()
2993 if (sqp->s_last == READ_ONCE(sqp->s_head)) in rvt_ruc_loopback()
2995 wqe = rvt_get_swqe_ptr(sqp, sqp->s_last); in rvt_ruc_loopback()
2998 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_NEXT_SEND_OK)) { in rvt_ruc_loopback()
2999 if (!(ib_rvt_state_ops[sqp->state] & RVT_FLUSH_SEND)) in rvt_ruc_loopback()
3011 if (sqp->s_last == sqp->s_cur) { in rvt_ruc_loopback()
3012 if (++sqp->s_cur >= sqp->s_size) in rvt_ruc_loopback()
3013 sqp->s_cur = 0; in rvt_ruc_loopback()
3015 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()
3021 spin_lock_irqsave(&qp->r_lock, flags); in rvt_ruc_loopback()
3022 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) || in rvt_ruc_loopback()
3023 qp->ibqp.qp_type != sqp->ibqp.qp_type) { in rvt_ruc_loopback()
3028 memset(&wc, 0, sizeof(wc)); in rvt_ruc_loopback()
3032 sqp->s_sge.sge = wqe->sg_list[0]; in rvt_ruc_loopback()
3033 sqp->s_sge.sg_list = wqe->sg_list + 1; in rvt_ruc_loopback()
3034 sqp->s_sge.num_sge = wqe->wr.num_sge; in rvt_ruc_loopback()
3035 sqp->s_len = wqe->length; in rvt_ruc_loopback()
3036 switch (wqe->wr.opcode) { in rvt_ruc_loopback()
3041 if (!(wqe->wr.send_flags & RVT_SEND_COMPLETION_ONLY)) { in rvt_ruc_loopback()
3043 wqe->wr.ex.invalidate_rkey)) in rvt_ruc_loopback()
3057 if (wqe->length > qp->r_len) in rvt_ruc_loopback()
3059 switch (wqe->wr.opcode) { in rvt_ruc_loopback()
3062 wqe->wr.ex.invalidate_rkey)) { in rvt_ruc_loopback()
3063 wc.wc_flags = IB_WC_WITH_INVALIDATE; in rvt_ruc_loopback()
3064 wc.ex.invalidate_rkey = in rvt_ruc_loopback()
3065 wqe->wr.ex.invalidate_rkey; in rvt_ruc_loopback()
3069 wc.wc_flags = IB_WC_WITH_IMM; in rvt_ruc_loopback()
3070 wc.ex.imm_data = wqe->wr.ex.imm_data; in rvt_ruc_loopback()
3078 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) in rvt_ruc_loopback()
3080 wc.wc_flags = IB_WC_WITH_IMM; in rvt_ruc_loopback()
3081 wc.ex.imm_data = wqe->wr.ex.imm_data; in rvt_ruc_loopback()
3091 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) in rvt_ruc_loopback()
3094 if (wqe->length == 0) in rvt_ruc_loopback()
3096 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, wqe->length, in rvt_ruc_loopback()
3097 wqe->rdma_wr.remote_addr, in rvt_ruc_loopback()
3098 wqe->rdma_wr.rkey, in rvt_ruc_loopback()
3101 qp->r_sge.sg_list = NULL; in rvt_ruc_loopback()
3102 qp->r_sge.num_sge = 1; in rvt_ruc_loopback()
3103 qp->r_sge.total_len = wqe->length; in rvt_ruc_loopback()
3107 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ))) in rvt_ruc_loopback()
3109 if (unlikely(!rvt_rkey_ok(qp, &sqp->s_sge.sge, wqe->length, in rvt_ruc_loopback()
3110 wqe->rdma_wr.remote_addr, in rvt_ruc_loopback()
3111 wqe->rdma_wr.rkey, in rvt_ruc_loopback()
3115 sqp->s_sge.sg_list = NULL; in rvt_ruc_loopback()
3116 sqp->s_sge.num_sge = 1; in rvt_ruc_loopback()
3117 qp->r_sge.sge = wqe->sg_list[0]; in rvt_ruc_loopback()
3118 qp->r_sge.sg_list = wqe->sg_list + 1; in rvt_ruc_loopback()
3119 qp->r_sge.num_sge = wqe->wr.num_sge; in rvt_ruc_loopback()
3120 qp->r_sge.total_len = wqe->length; in rvt_ruc_loopback()
3125 if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC))) in rvt_ruc_loopback()
3127 if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64), in rvt_ruc_loopback()
3128 wqe->atomic_wr.remote_addr, in rvt_ruc_loopback()
3129 wqe->atomic_wr.rkey, in rvt_ruc_loopback()
3133 maddr = (atomic64_t *)qp->r_sge.sge.vaddr; in rvt_ruc_loopback()
3134 sdata = wqe->atomic_wr.compare_add; in rvt_ruc_loopback()
3135 *(u64 *)sqp->s_sge.sge.vaddr = in rvt_ruc_loopback()
3136 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ? in rvt_ruc_loopback()
3137 (u64)atomic64_add_return(sdata, maddr) - sdata : in rvt_ruc_loopback()
3138 (u64)cmpxchg((u64 *)qp->r_sge.sge.vaddr, in rvt_ruc_loopback()
3139 sdata, wqe->atomic_wr.swap); in rvt_ruc_loopback()
3140 rvt_put_mr(qp->r_sge.sge.mr); in rvt_ruc_loopback()
3141 qp->r_sge.num_sge = 0; in rvt_ruc_loopback()
3149 sge = &sqp->s_sge.sge; in rvt_ruc_loopback()
3150 while (sqp->s_len) { in rvt_ruc_loopback()
3151 u32 len = rvt_get_sge_length(sge, sqp->s_len); in rvt_ruc_loopback()
3154 rvt_copy_sge(qp, &qp->r_sge, sge->vaddr, in rvt_ruc_loopback()
3156 rvt_update_sge(&sqp->s_sge, len, !release); in rvt_ruc_loopback()
3157 sqp->s_len -= len; in rvt_ruc_loopback()
3160 rvt_put_ss(&qp->r_sge); in rvt_ruc_loopback()
3162 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) in rvt_ruc_loopback()
3165 if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM) in rvt_ruc_loopback()
3166 wc.opcode = IB_WC_RECV_RDMA_WITH_IMM; in rvt_ruc_loopback()
3168 wc.opcode = IB_WC_RECV; in rvt_ruc_loopback()
3169 wc.wr_id = qp->r_wr_id; in rvt_ruc_loopback()
3170 wc.status = IB_WC_SUCCESS; in rvt_ruc_loopback()
3171 wc.byte_len = wqe->length; in rvt_ruc_loopback()
3172 wc.qp = &qp->ibqp; in rvt_ruc_loopback()
3173 wc.src_qp = qp->remote_qpn; in rvt_ruc_loopback()
3174 wc.slid = rdma_ah_get_dlid(&qp->remote_ah_attr) & U16_MAX; in rvt_ruc_loopback()
3175 wc.sl = rdma_ah_get_sl(&qp->remote_ah_attr); in rvt_ruc_loopback()
3176 wc.port_num = 1; in rvt_ruc_loopback()
3178 rvt_recv_cq(qp, &wc, wqe->wr.send_flags & IB_SEND_SOLICITED); in rvt_ruc_loopback()
3181 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_ruc_loopback()
3182 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
3183 rvp->n_loop_pkts++; in rvt_ruc_loopback()
3185 sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; in rvt_ruc_loopback()
3188 atomic_dec(&sqp->local_ops_pending); in rvt_ruc_loopback()
3195 if (qp->ibqp.qp_type == IB_QPT_UC) in rvt_ruc_loopback()
3197 rvp->n_rnr_naks++; in rvt_ruc_loopback()
3202 if (sqp->s_rnr_retry == 0) { in rvt_ruc_loopback()
3206 if (sqp->s_rnr_retry_cnt < 7) in rvt_ruc_loopback()
3207 sqp->s_rnr_retry--; in rvt_ruc_loopback()
3208 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_ruc_loopback()
3209 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
3210 if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_RECV_OK)) in rvt_ruc_loopback()
3212 rvt_add_rnr_timer(sqp, qp->r_min_rnr_timer << in rvt_ruc_loopback()
3218 wc.status = IB_WC_LOC_QP_OP_ERR; in rvt_ruc_loopback()
3223 sqp->ibqp.qp_type == IB_QPT_RC ? in rvt_ruc_loopback()
3226 wc.status = IB_WC_LOC_QP_OP_ERR; in rvt_ruc_loopback()
3231 wc.status = IB_WC_LOC_PROT_ERR; in rvt_ruc_loopback()
3234 rvt_rc_error(qp, wc.status); in rvt_ruc_loopback()
3237 spin_unlock_irqrestore(&qp->r_lock, flags); in rvt_ruc_loopback()
3239 spin_lock_irqsave(&sqp->s_lock, flags); in rvt_ruc_loopback()
3241 if (sqp->ibqp.qp_type == IB_QPT_RC) { in rvt_ruc_loopback()
3244 sqp->s_flags &= ~RVT_S_BUSY; in rvt_ruc_loopback()
3245 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()
3249 ev.device = sqp->ibqp.device; in rvt_ruc_loopback()
3250 ev.element.qp = &sqp->ibqp; in rvt_ruc_loopback()
3252 sqp->ibqp.event_handler(&ev, sqp->ibqp.qp_context); in rvt_ruc_loopback()
3257 sqp->s_flags &= ~RVT_S_BUSY; in rvt_ruc_loopback()
3259 spin_unlock_irqrestore(&sqp->s_lock, flags); in rvt_ruc_loopback()