OSDN Git Service

net/smc: wait for departure of an IB message
authorKarsten Graul <kgraul@linux.ibm.com>
Mon, 4 May 2020 12:18:41 +0000 (14:18 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 4 May 2020 17:54:39 +0000 (10:54 -0700)
Introduce smc_wr_tx_send_wait() to send an IB message and wait for the
tx completion event of the message. This makes sure that the message is
no longer in-flight when the function returns.

Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
Reviewed-by: Ursula Braun <ubraun@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/smc/smc_core.h
net/smc/smc_wr.c
net/smc/smc_wr.h

index 584f112..86eebba 100644 (file)
@@ -85,6 +85,7 @@ struct smc_link {
        struct smc_rdma_sges    *wr_tx_rdma_sges;/*RDMA WRITE gather meta data*/
        struct smc_rdma_wr      *wr_tx_rdmas;   /* WR RDMA WRITE */
        struct smc_wr_tx_pend   *wr_tx_pends;   /* WR send waiting for CQE */
+       struct completion       *wr_tx_compl;   /* WR send CQE completion */
        /* above four vectors have wr_tx_cnt elements and use the same index */
        dma_addr_t              wr_tx_dma_addr; /* DMA address of wr_tx_bufs */
        atomic_long_t           wr_tx_id;       /* seq # of last sent WR */
index 3fd27be..7239ba9 100644 (file)
@@ -44,6 +44,7 @@ struct smc_wr_tx_pend {       /* control data for a pending send request */
        struct smc_link         *link;
        u32                     idx;
        struct smc_wr_tx_pend_priv priv;
+       u8                      compl_requested;
 };
 
 /******************************** send queue *********************************/
@@ -103,6 +104,8 @@ static inline void smc_wr_tx_process_cqe(struct ib_wc *wc)
        if (pnd_snd_idx == link->wr_tx_cnt)
                return;
        link->wr_tx_pends[pnd_snd_idx].wc_status = wc->status;
+       if (link->wr_tx_pends[pnd_snd_idx].compl_requested)
+               complete(&link->wr_tx_compl[pnd_snd_idx]);
        memcpy(&pnd_snd, &link->wr_tx_pends[pnd_snd_idx], sizeof(pnd_snd));
        /* clear the full struct smc_wr_tx_pend including .priv */
        memset(&link->wr_tx_pends[pnd_snd_idx], 0,
@@ -275,6 +278,33 @@ int smc_wr_tx_send(struct smc_link *link, struct smc_wr_tx_pend_priv *priv)
        return rc;
 }
 
+/* Send prepared WR slot via ib_post_send and wait for send completion
+ * notification.
+ * @priv: pointer to smc_wr_tx_pend_priv identifying prepared message buffer
+ */
+int smc_wr_tx_send_wait(struct smc_link *link, struct smc_wr_tx_pend_priv *priv,
+                       unsigned long timeout)
+{
+       struct smc_wr_tx_pend *pend;
+       int rc;
+
+       pend = container_of(priv, struct smc_wr_tx_pend, priv);
+       pend->compl_requested = 1;
+       init_completion(&link->wr_tx_compl[pend->idx]);
+
+       rc = smc_wr_tx_send(link, priv);
+       if (rc)
+               return rc;
+       /* wait for completion by smc_wr_tx_process_cqe() */
+       rc = wait_for_completion_interruptible_timeout(
+                                       &link->wr_tx_compl[pend->idx], timeout);
+       if (rc <= 0)
+               rc = -ENODATA;
+       if (rc > 0)
+               rc = 0;
+       return rc;
+}
+
 /* Register a memory region and wait for result. */
 int smc_wr_reg_send(struct smc_link *link, struct ib_mr *mr)
 {
@@ -555,6 +585,8 @@ void smc_wr_free_link(struct smc_link *lnk)
 
 void smc_wr_free_link_mem(struct smc_link *lnk)
 {
+       kfree(lnk->wr_tx_compl);
+       lnk->wr_tx_compl = NULL;
        kfree(lnk->wr_tx_pends);
        lnk->wr_tx_pends = NULL;
        kfree(lnk->wr_tx_mask);
@@ -625,8 +657,15 @@ int smc_wr_alloc_link_mem(struct smc_link *link)
                                    GFP_KERNEL);
        if (!link->wr_tx_pends)
                goto no_mem_wr_tx_mask;
+       link->wr_tx_compl = kcalloc(SMC_WR_BUF_CNT,
+                                   sizeof(link->wr_tx_compl[0]),
+                                   GFP_KERNEL);
+       if (!link->wr_tx_compl)
+               goto no_mem_wr_tx_pends;
        return 0;
 
+no_mem_wr_tx_pends:
+       kfree(link->wr_tx_pends);
 no_mem_wr_tx_mask:
        kfree(link->wr_tx_mask);
 no_mem_wr_rx_sges:
index f7eaeb3..423b870 100644 (file)
@@ -101,6 +101,8 @@ int smc_wr_tx_put_slot(struct smc_link *link,
                       struct smc_wr_tx_pend_priv *wr_pend_priv);
 int smc_wr_tx_send(struct smc_link *link,
                   struct smc_wr_tx_pend_priv *wr_pend_priv);
+int smc_wr_tx_send_wait(struct smc_link *link, struct smc_wr_tx_pend_priv *priv,
+                       unsigned long timeout);
 void smc_wr_tx_cq_handler(struct ib_cq *ib_cq, void *cq_context);
 void smc_wr_tx_dismiss_slots(struct smc_link *lnk, u8 wr_rx_hdr_type,
                             smc_wr_tx_filter filter,