Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Shared Memory Communications over RDMA (SMC-R) and RoCE
0004  *
0005  * Work Requests exploiting Infiniband API
0006  *
0007  * Copyright IBM Corp. 2016
0008  *
0009  * Author(s):  Steffen Maier <maier@linux.vnet.ibm.com>
0010  */
0011 
0012 #ifndef SMC_WR_H
0013 #define SMC_WR_H
0014 
0015 #include <linux/atomic.h>
0016 #include <rdma/ib_verbs.h>
0017 #include <asm/div64.h>
0018 
0019 #include "smc.h"
0020 #include "smc_core.h"
0021 
0022 #define SMC_WR_BUF_CNT 16   /* # of ctrl buffers per link */
0023 
0024 #define SMC_WR_TX_WAIT_FREE_SLOT_TIME   (10 * HZ)
0025 
0026 #define SMC_WR_TX_SIZE 44 /* actual size of wr_send data (<=SMC_WR_BUF_SIZE) */
0027 
0028 #define SMC_WR_TX_PEND_PRIV_SIZE 32
0029 
0030 struct smc_wr_tx_pend_priv {
0031     u8          priv[SMC_WR_TX_PEND_PRIV_SIZE];
0032 };
0033 
0034 typedef void (*smc_wr_tx_handler)(struct smc_wr_tx_pend_priv *,
0035                   struct smc_link *,
0036                   enum ib_wc_status);
0037 
0038 typedef bool (*smc_wr_tx_filter)(struct smc_wr_tx_pend_priv *,
0039                  unsigned long);
0040 
0041 typedef void (*smc_wr_tx_dismisser)(struct smc_wr_tx_pend_priv *);
0042 
0043 struct smc_wr_rx_handler {
0044     struct hlist_node   list;   /* hash table collision resolution */
0045     void            (*handler)(struct ib_wc *, void *);
0046     u8          type;
0047 };
0048 
0049 /* Only used by RDMA write WRs.
0050  * All other WRs (CDC/LLC) use smc_wr_tx_send handling WR_ID implicitly
0051  */
0052 static inline long smc_wr_tx_get_next_wr_id(struct smc_link *link)
0053 {
0054     return atomic_long_inc_return(&link->wr_tx_id);
0055 }
0056 
0057 static inline void smc_wr_tx_set_wr_id(atomic_long_t *wr_tx_id, long val)
0058 {
0059     atomic_long_set(wr_tx_id, val);
0060 }
0061 
0062 static inline bool smc_wr_tx_link_hold(struct smc_link *link)
0063 {
0064     if (!smc_link_sendable(link))
0065         return false;
0066     atomic_inc(&link->wr_tx_refcnt);
0067     return true;
0068 }
0069 
0070 static inline void smc_wr_tx_link_put(struct smc_link *link)
0071 {
0072     if (atomic_dec_and_test(&link->wr_tx_refcnt))
0073         wake_up_all(&link->wr_tx_wait);
0074 }
0075 
0076 static inline void smc_wr_drain_cq(struct smc_link *lnk)
0077 {
0078     wait_event(lnk->wr_rx_empty_wait, lnk->wr_rx_id_compl == lnk->wr_rx_id);
0079 }
0080 
0081 static inline void smc_wr_wakeup_tx_wait(struct smc_link *lnk)
0082 {
0083     wake_up_all(&lnk->wr_tx_wait);
0084 }
0085 
0086 static inline void smc_wr_wakeup_reg_wait(struct smc_link *lnk)
0087 {
0088     wake_up(&lnk->wr_reg_wait);
0089 }
0090 
0091 /* post a new receive work request to fill a completed old work request entry */
0092 static inline int smc_wr_rx_post(struct smc_link *link)
0093 {
0094     int rc;
0095     u64 wr_id, temp_wr_id;
0096     u32 index;
0097 
0098     wr_id = ++link->wr_rx_id; /* tasklet context, thus not atomic */
0099     temp_wr_id = wr_id;
0100     index = do_div(temp_wr_id, link->wr_rx_cnt);
0101     link->wr_rx_ibs[index].wr_id = wr_id;
0102     rc = ib_post_recv(link->roce_qp, &link->wr_rx_ibs[index], NULL);
0103     return rc;
0104 }
0105 
0106 int smc_wr_create_link(struct smc_link *lnk);
0107 int smc_wr_alloc_link_mem(struct smc_link *lnk);
0108 int smc_wr_alloc_lgr_mem(struct smc_link_group *lgr);
0109 void smc_wr_free_link(struct smc_link *lnk);
0110 void smc_wr_free_link_mem(struct smc_link *lnk);
0111 void smc_wr_free_lgr_mem(struct smc_link_group *lgr);
0112 void smc_wr_remember_qp_attr(struct smc_link *lnk);
0113 void smc_wr_remove_dev(struct smc_ib_device *smcibdev);
0114 void smc_wr_add_dev(struct smc_ib_device *smcibdev);
0115 
0116 int smc_wr_tx_get_free_slot(struct smc_link *link, smc_wr_tx_handler handler,
0117                 struct smc_wr_buf **wr_buf,
0118                 struct smc_rdma_wr **wrs,
0119                 struct smc_wr_tx_pend_priv **wr_pend_priv);
0120 int smc_wr_tx_get_v2_slot(struct smc_link *link,
0121               smc_wr_tx_handler handler,
0122               struct smc_wr_v2_buf **wr_buf,
0123               struct smc_wr_tx_pend_priv **wr_pend_priv);
0124 int smc_wr_tx_put_slot(struct smc_link *link,
0125                struct smc_wr_tx_pend_priv *wr_pend_priv);
0126 int smc_wr_tx_send(struct smc_link *link,
0127            struct smc_wr_tx_pend_priv *wr_pend_priv);
0128 int smc_wr_tx_v2_send(struct smc_link *link,
0129               struct smc_wr_tx_pend_priv *priv, int len);
0130 int smc_wr_tx_send_wait(struct smc_link *link, struct smc_wr_tx_pend_priv *priv,
0131             unsigned long timeout);
0132 void smc_wr_tx_cq_handler(struct ib_cq *ib_cq, void *cq_context);
0133 void smc_wr_tx_wait_no_pending_sends(struct smc_link *link);
0134 
0135 int smc_wr_rx_register_handler(struct smc_wr_rx_handler *handler);
0136 int smc_wr_rx_post_init(struct smc_link *link);
0137 void smc_wr_rx_cq_handler(struct ib_cq *ib_cq, void *cq_context);
0138 int smc_wr_reg_send(struct smc_link *link, struct ib_mr *mr);
0139 
0140 #endif /* SMC_WR_H */