Lines Matching refs:link

44 	struct smc_link		*link;  member
55 static inline bool smc_wr_is_tx_pend(struct smc_link *link) in smc_wr_is_tx_pend() argument
57 return !bitmap_empty(link->wr_tx_mask, link->wr_tx_cnt); in smc_wr_is_tx_pend()
61 void smc_wr_tx_wait_no_pending_sends(struct smc_link *link) in smc_wr_tx_wait_no_pending_sends() argument
63 wait_event(link->wr_tx_wait, !smc_wr_is_tx_pend(link)); in smc_wr_tx_wait_no_pending_sends()
66 static inline int smc_wr_tx_find_pending_index(struct smc_link *link, u64 wr_id) in smc_wr_tx_find_pending_index() argument
70 for (i = 0; i < link->wr_tx_cnt; i++) { in smc_wr_tx_find_pending_index()
71 if (link->wr_tx_pends[i].wr_id == wr_id) in smc_wr_tx_find_pending_index()
74 return link->wr_tx_cnt; in smc_wr_tx_find_pending_index()
80 struct smc_link *link; in smc_wr_tx_process_cqe() local
83 link = wc->qp->qp_context; in smc_wr_tx_process_cqe()
87 link->wr_reg_state = FAILED; in smc_wr_tx_process_cqe()
89 link->wr_reg_state = CONFIRMED; in smc_wr_tx_process_cqe()
90 smc_wr_wakeup_reg_wait(link); in smc_wr_tx_process_cqe()
94 pnd_snd_idx = smc_wr_tx_find_pending_index(link, wc->wr_id); in smc_wr_tx_process_cqe()
95 if (pnd_snd_idx == link->wr_tx_cnt) { in smc_wr_tx_process_cqe()
96 if (link->lgr->smc_version != SMC_V2 || in smc_wr_tx_process_cqe()
97 link->wr_tx_v2_pend->wr_id != wc->wr_id) in smc_wr_tx_process_cqe()
99 link->wr_tx_v2_pend->wc_status = wc->status; in smc_wr_tx_process_cqe()
100 memcpy(&pnd_snd, link->wr_tx_v2_pend, sizeof(pnd_snd)); in smc_wr_tx_process_cqe()
102 memset(link->wr_tx_v2_pend, 0, in smc_wr_tx_process_cqe()
103 sizeof(*link->wr_tx_v2_pend)); in smc_wr_tx_process_cqe()
104 memset(link->lgr->wr_tx_buf_v2, 0, in smc_wr_tx_process_cqe()
105 sizeof(*link->lgr->wr_tx_buf_v2)); in smc_wr_tx_process_cqe()
107 link->wr_tx_pends[pnd_snd_idx].wc_status = wc->status; in smc_wr_tx_process_cqe()
108 if (link->wr_tx_pends[pnd_snd_idx].compl_requested) in smc_wr_tx_process_cqe()
109 complete(&link->wr_tx_compl[pnd_snd_idx]); in smc_wr_tx_process_cqe()
110 memcpy(&pnd_snd, &link->wr_tx_pends[pnd_snd_idx], in smc_wr_tx_process_cqe()
113 memset(&link->wr_tx_pends[pnd_snd_idx], 0, in smc_wr_tx_process_cqe()
114 sizeof(link->wr_tx_pends[pnd_snd_idx])); in smc_wr_tx_process_cqe()
115 memset(&link->wr_tx_bufs[pnd_snd_idx], 0, in smc_wr_tx_process_cqe()
116 sizeof(link->wr_tx_bufs[pnd_snd_idx])); in smc_wr_tx_process_cqe()
117 if (!test_and_clear_bit(pnd_snd_idx, link->wr_tx_mask)) in smc_wr_tx_process_cqe()
122 if (link->lgr->smc_version == SMC_V2) { in smc_wr_tx_process_cqe()
123 memset(link->wr_tx_v2_pend, 0, in smc_wr_tx_process_cqe()
124 sizeof(*link->wr_tx_v2_pend)); in smc_wr_tx_process_cqe()
125 memset(link->lgr->wr_tx_buf_v2, 0, in smc_wr_tx_process_cqe()
126 sizeof(*link->lgr->wr_tx_buf_v2)); in smc_wr_tx_process_cqe()
129 smcr_link_down_cond_sched(link); in smc_wr_tx_process_cqe()
132 pnd_snd.handler(&pnd_snd.priv, link, wc->status); in smc_wr_tx_process_cqe()
133 wake_up(&link->wr_tx_wait); in smc_wr_tx_process_cqe()
171 static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32 *idx) in smc_wr_tx_get_free_slot_index() argument
173 *idx = link->wr_tx_cnt; in smc_wr_tx_get_free_slot_index()
174 if (!smc_link_sendable(link)) in smc_wr_tx_get_free_slot_index()
176 for_each_clear_bit(*idx, link->wr_tx_mask, link->wr_tx_cnt) { in smc_wr_tx_get_free_slot_index()
177 if (!test_and_set_bit(*idx, link->wr_tx_mask)) in smc_wr_tx_get_free_slot_index()
180 *idx = link->wr_tx_cnt; in smc_wr_tx_get_free_slot_index()
195 int smc_wr_tx_get_free_slot(struct smc_link *link, in smc_wr_tx_get_free_slot() argument
201 struct smc_link_group *lgr = smc_get_lgr(link); in smc_wr_tx_get_free_slot()
203 u32 idx = link->wr_tx_cnt; in smc_wr_tx_get_free_slot()
211 rc = smc_wr_tx_get_free_slot_index(link, &idx); in smc_wr_tx_get_free_slot()
216 link->wr_tx_wait, in smc_wr_tx_get_free_slot()
217 !smc_link_sendable(link) || in smc_wr_tx_get_free_slot()
219 (smc_wr_tx_get_free_slot_index(link, &idx) != -EBUSY), in smc_wr_tx_get_free_slot()
223 smcr_link_down_cond_sched(link); in smc_wr_tx_get_free_slot()
226 if (idx == link->wr_tx_cnt) in smc_wr_tx_get_free_slot()
229 wr_id = smc_wr_tx_get_next_wr_id(link); in smc_wr_tx_get_free_slot()
230 wr_pend = &link->wr_tx_pends[idx]; in smc_wr_tx_get_free_slot()
233 wr_pend->link = link; in smc_wr_tx_get_free_slot()
235 wr_ib = &link->wr_tx_ibs[idx]; in smc_wr_tx_get_free_slot()
237 *wr_buf = &link->wr_tx_bufs[idx]; in smc_wr_tx_get_free_slot()
239 *wr_rdma_buf = &link->wr_tx_rdmas[idx]; in smc_wr_tx_get_free_slot()
244 int smc_wr_tx_get_v2_slot(struct smc_link *link, in smc_wr_tx_get_v2_slot() argument
253 if (link->wr_tx_v2_pend->idx == link->wr_tx_cnt) in smc_wr_tx_get_v2_slot()
258 wr_id = smc_wr_tx_get_next_wr_id(link); in smc_wr_tx_get_v2_slot()
259 wr_pend = link->wr_tx_v2_pend; in smc_wr_tx_get_v2_slot()
262 wr_pend->link = link; in smc_wr_tx_get_v2_slot()
263 wr_pend->idx = link->wr_tx_cnt; in smc_wr_tx_get_v2_slot()
264 wr_ib = link->wr_tx_v2_ib; in smc_wr_tx_get_v2_slot()
266 *wr_buf = link->lgr->wr_tx_buf_v2; in smc_wr_tx_get_v2_slot()
271 int smc_wr_tx_put_slot(struct smc_link *link, in smc_wr_tx_put_slot() argument
277 if (pend->idx < link->wr_tx_cnt) { in smc_wr_tx_put_slot()
281 memset(&link->wr_tx_pends[idx], 0, in smc_wr_tx_put_slot()
282 sizeof(link->wr_tx_pends[idx])); in smc_wr_tx_put_slot()
283 memset(&link->wr_tx_bufs[idx], 0, in smc_wr_tx_put_slot()
284 sizeof(link->wr_tx_bufs[idx])); in smc_wr_tx_put_slot()
285 test_and_clear_bit(idx, link->wr_tx_mask); in smc_wr_tx_put_slot()
286 wake_up(&link->wr_tx_wait); in smc_wr_tx_put_slot()
288 } else if (link->lgr->smc_version == SMC_V2 && in smc_wr_tx_put_slot()
289 pend->idx == link->wr_tx_cnt) { in smc_wr_tx_put_slot()
291 memset(&link->wr_tx_v2_pend, 0, in smc_wr_tx_put_slot()
292 sizeof(link->wr_tx_v2_pend)); in smc_wr_tx_put_slot()
293 memset(&link->lgr->wr_tx_buf_v2, 0, in smc_wr_tx_put_slot()
294 sizeof(link->lgr->wr_tx_buf_v2)); in smc_wr_tx_put_slot()
304 int smc_wr_tx_send(struct smc_link *link, struct smc_wr_tx_pend_priv *priv) in smc_wr_tx_send() argument
309 ib_req_notify_cq(link->smcibdev->roce_cq_send, in smc_wr_tx_send()
312 rc = ib_post_send(link->roce_qp, &link->wr_tx_ibs[pend->idx], NULL); in smc_wr_tx_send()
314 smc_wr_tx_put_slot(link, priv); in smc_wr_tx_send()
315 smcr_link_down_cond_sched(link); in smc_wr_tx_send()
320 int smc_wr_tx_v2_send(struct smc_link *link, struct smc_wr_tx_pend_priv *priv, in smc_wr_tx_v2_send() argument
325 link->wr_tx_v2_ib->sg_list[0].length = len; in smc_wr_tx_v2_send()
326 ib_req_notify_cq(link->smcibdev->roce_cq_send, in smc_wr_tx_v2_send()
328 rc = ib_post_send(link->roce_qp, link->wr_tx_v2_ib, NULL); in smc_wr_tx_v2_send()
330 smc_wr_tx_put_slot(link, priv); in smc_wr_tx_v2_send()
331 smcr_link_down_cond_sched(link); in smc_wr_tx_v2_send()
340 int smc_wr_tx_send_wait(struct smc_link *link, struct smc_wr_tx_pend_priv *priv, in smc_wr_tx_send_wait() argument
350 init_completion(&link->wr_tx_compl[pnd_idx]); in smc_wr_tx_send_wait()
352 rc = smc_wr_tx_send(link, priv); in smc_wr_tx_send_wait()
357 &link->wr_tx_compl[pnd_idx], timeout); in smc_wr_tx_send_wait()
366 int smc_wr_reg_send(struct smc_link *link, struct ib_mr *mr) in smc_wr_reg_send() argument
370 ib_req_notify_cq(link->smcibdev->roce_cq_send, in smc_wr_reg_send()
372 link->wr_reg_state = POSTED; in smc_wr_reg_send()
373 link->wr_reg.wr.wr_id = (u64)(uintptr_t)mr; in smc_wr_reg_send()
374 link->wr_reg.mr = mr; in smc_wr_reg_send()
375 link->wr_reg.key = mr->rkey; in smc_wr_reg_send()
376 rc = ib_post_send(link->roce_qp, &link->wr_reg.wr, NULL); in smc_wr_reg_send()
380 percpu_ref_get(&link->wr_reg_refs); in smc_wr_reg_send()
381 rc = wait_event_interruptible_timeout(link->wr_reg_wait, in smc_wr_reg_send()
382 (link->wr_reg_state != POSTED), in smc_wr_reg_send()
384 percpu_ref_put(&link->wr_reg_refs); in smc_wr_reg_send()
387 smcr_link_down_cond_sched(link); in smc_wr_reg_send()
392 switch (link->wr_reg_state) { in smc_wr_reg_send()
432 struct smc_link *link = (struct smc_link *)wc->qp->qp_context; in smc_wr_rx_demultiplex() local
441 index = do_div(temp_wr_id, link->wr_rx_cnt); in smc_wr_rx_demultiplex()
442 wr_rx = (struct smc_wr_rx_hdr *)&link->wr_rx_bufs[index]; in smc_wr_rx_demultiplex()
451 struct smc_link *link; in smc_wr_rx_process_cqes() local
455 link = wc[i].qp->qp_context; in smc_wr_rx_process_cqes()
456 link->wr_rx_id_compl = wc[i].wr_id; in smc_wr_rx_process_cqes()
458 link->wr_rx_tstamp = jiffies; in smc_wr_rx_process_cqes()
460 smc_wr_rx_post(link); /* refill WR RX */ in smc_wr_rx_process_cqes()
467 smcr_link_down_cond_sched(link); in smc_wr_rx_process_cqes()
468 if (link->wr_rx_id_compl == link->wr_rx_id) in smc_wr_rx_process_cqes()
469 wake_up(&link->wr_rx_empty_wait); in smc_wr_rx_process_cqes()
472 smc_wr_rx_post(link); /* refill WR RX */ in smc_wr_rx_process_cqes()
511 int smc_wr_rx_post_init(struct smc_link *link) in smc_wr_rx_post_init() argument
516 for (i = 0; i < link->wr_rx_cnt; i++) in smc_wr_rx_post_init()
517 rc = smc_wr_rx_post(link); in smc_wr_rx_post_init()
741 int smc_wr_alloc_link_mem(struct smc_link *link) in smc_wr_alloc_link_mem() argument
743 int sges_per_buf = link->lgr->smc_version == SMC_V2 ? 2 : 1; in smc_wr_alloc_link_mem()
746 link->wr_tx_bufs = kcalloc(SMC_WR_BUF_CNT, SMC_WR_BUF_SIZE, GFP_KERNEL); in smc_wr_alloc_link_mem()
747 if (!link->wr_tx_bufs) in smc_wr_alloc_link_mem()
749 link->wr_rx_bufs = kcalloc(SMC_WR_BUF_CNT * 3, SMC_WR_BUF_SIZE, in smc_wr_alloc_link_mem()
751 if (!link->wr_rx_bufs) in smc_wr_alloc_link_mem()
753 link->wr_tx_ibs = kcalloc(SMC_WR_BUF_CNT, sizeof(link->wr_tx_ibs[0]), in smc_wr_alloc_link_mem()
755 if (!link->wr_tx_ibs) in smc_wr_alloc_link_mem()
757 link->wr_rx_ibs = kcalloc(SMC_WR_BUF_CNT * 3, in smc_wr_alloc_link_mem()
758 sizeof(link->wr_rx_ibs[0]), in smc_wr_alloc_link_mem()
760 if (!link->wr_rx_ibs) in smc_wr_alloc_link_mem()
762 link->wr_tx_rdmas = kcalloc(SMC_WR_BUF_CNT, in smc_wr_alloc_link_mem()
763 sizeof(link->wr_tx_rdmas[0]), in smc_wr_alloc_link_mem()
765 if (!link->wr_tx_rdmas) in smc_wr_alloc_link_mem()
767 link->wr_tx_rdma_sges = kcalloc(SMC_WR_BUF_CNT, in smc_wr_alloc_link_mem()
768 sizeof(link->wr_tx_rdma_sges[0]), in smc_wr_alloc_link_mem()
770 if (!link->wr_tx_rdma_sges) in smc_wr_alloc_link_mem()
772 link->wr_tx_sges = kcalloc(SMC_WR_BUF_CNT, sizeof(link->wr_tx_sges[0]), in smc_wr_alloc_link_mem()
774 if (!link->wr_tx_sges) in smc_wr_alloc_link_mem()
776 link->wr_rx_sges = kcalloc(SMC_WR_BUF_CNT * 3, in smc_wr_alloc_link_mem()
777 sizeof(link->wr_rx_sges[0]) * sges_per_buf, in smc_wr_alloc_link_mem()
779 if (!link->wr_rx_sges) in smc_wr_alloc_link_mem()
781 link->wr_tx_mask = bitmap_zalloc(SMC_WR_BUF_CNT, GFP_KERNEL); in smc_wr_alloc_link_mem()
782 if (!link->wr_tx_mask) in smc_wr_alloc_link_mem()
784 link->wr_tx_pends = kcalloc(SMC_WR_BUF_CNT, in smc_wr_alloc_link_mem()
785 sizeof(link->wr_tx_pends[0]), in smc_wr_alloc_link_mem()
787 if (!link->wr_tx_pends) in smc_wr_alloc_link_mem()
789 link->wr_tx_compl = kcalloc(SMC_WR_BUF_CNT, in smc_wr_alloc_link_mem()
790 sizeof(link->wr_tx_compl[0]), in smc_wr_alloc_link_mem()
792 if (!link->wr_tx_compl) in smc_wr_alloc_link_mem()
795 if (link->lgr->smc_version == SMC_V2) { in smc_wr_alloc_link_mem()
796 link->wr_tx_v2_ib = kzalloc(sizeof(*link->wr_tx_v2_ib), in smc_wr_alloc_link_mem()
798 if (!link->wr_tx_v2_ib) in smc_wr_alloc_link_mem()
800 link->wr_tx_v2_sge = kzalloc(sizeof(*link->wr_tx_v2_sge), in smc_wr_alloc_link_mem()
802 if (!link->wr_tx_v2_sge) in smc_wr_alloc_link_mem()
804 link->wr_tx_v2_pend = kzalloc(sizeof(*link->wr_tx_v2_pend), in smc_wr_alloc_link_mem()
806 if (!link->wr_tx_v2_pend) in smc_wr_alloc_link_mem()
812 kfree(link->wr_tx_v2_sge); in smc_wr_alloc_link_mem()
814 kfree(link->wr_tx_v2_ib); in smc_wr_alloc_link_mem()
816 kfree(link->wr_tx_compl); in smc_wr_alloc_link_mem()
818 kfree(link->wr_tx_pends); in smc_wr_alloc_link_mem()
820 kfree(link->wr_tx_mask); in smc_wr_alloc_link_mem()
822 kfree(link->wr_rx_sges); in smc_wr_alloc_link_mem()
824 kfree(link->wr_tx_sges); in smc_wr_alloc_link_mem()
826 kfree(link->wr_tx_rdma_sges); in smc_wr_alloc_link_mem()
828 kfree(link->wr_tx_rdmas); in smc_wr_alloc_link_mem()
830 kfree(link->wr_rx_ibs); in smc_wr_alloc_link_mem()
832 kfree(link->wr_tx_ibs); in smc_wr_alloc_link_mem()
834 kfree(link->wr_rx_bufs); in smc_wr_alloc_link_mem()
836 kfree(link->wr_tx_bufs); in smc_wr_alloc_link_mem()