Whamcloud - gitweb
LU-12400 lnet: Infiniband sg_dma changes for linux 5.1
[fs/lustre-release.git] / lnet / klnds / o2iblnd / o2iblnd.h
index 5c7746e..fd6f97c 100644 (file)
@@ -43,7 +43,6 @@
 
 #endif
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/kthread.h>
@@ -65,9 +64,6 @@
 #include <linux/kmod.h>
 #include <linux/sysctl.h>
 #include <linux/pci.h>
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)
-#include <linux/pci-dma.h>
-#endif
 
 #include <net/sock.h>
 #include <linux/in.h>
 #define IBLND_N_SCHED                  2
 #define IBLND_N_SCHED_HIGH             4
 
-#define IBLND_DEV_CAPS_FASTREG_ENABLED         0x1
-#define IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT    0x2
-#define IBLND_DEV_CAPS_FMR_ENABLED             0x4
-
 struct kib_tunables {
        int              *kib_dev_failover;     /* HCA failover */
        unsigned int     *kib_service;          /* IB service number */
@@ -166,8 +158,7 @@ extern struct kib_tunables  kiblnd_tunables;
 #define IBLND_RECV_WRS(c)            IBLND_RX_MSGS(c)
 
 /* 2 = LNet msg + Transfer chain */
-#define IBLND_CQ_ENTRIES(c)    \
-       (IBLND_RECV_WRS(c) + 2 * c->ibc_queue_depth)
+#define IBLND_CQ_ENTRIES(c) (IBLND_RECV_WRS(c) + kiblnd_send_wrs(c))
 
 struct kib_hca_dev;
 
@@ -178,6 +169,12 @@ struct kib_hca_dev;
 #define KIB_IFNAME_SIZE              256
 #endif
 
+enum kib_dev_caps {
+       IBLND_DEV_CAPS_FASTREG_ENABLED          = BIT(0),
+       IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT     = BIT(1),
+       IBLND_DEV_CAPS_FMR_ENABLED              = BIT(2),
+};
+
 struct kib_dev {
        struct list_head        ibd_list;       /* chain on kib_devs */
        struct list_head        ibd_fail_list;  /* chain on kib_failed_devs */
@@ -195,7 +192,7 @@ struct kib_dev {
        unsigned int            ibd_can_failover;
        struct list_head        ibd_nets;
        struct kib_hca_dev      *ibd_hdev;
-       __u32                   ibd_dev_caps;
+       enum kib_dev_caps       ibd_dev_caps;
 };
 
 struct kib_hca_dev {
@@ -563,7 +560,7 @@ struct kib_rx {                                     /* receive message */
        /* message buffer (I/O addr) */
        __u64                   rx_msgaddr;
        /* for dma_unmap_single() */
-       DECLARE_PCI_UNMAP_ADDR(rx_msgunmap);
+       DEFINE_DMA_UNMAP_ADDR(rx_msgunmap);
        /* receive work item... */
        struct ib_recv_wr       rx_wrq;
        /* ...and its memory */
@@ -590,6 +587,8 @@ struct kib_tx {                                     /* transmit message */
        short                   tx_waiting;
        /* LNET completion status */
        int                     tx_status;
+       /* health status of the transmit */
+       enum lnet_msg_hstatus   tx_hstatus;
        /* completion deadline */
        ktime_t                 tx_deadline;
        /* completion cookie */
@@ -601,7 +600,7 @@ struct kib_tx {                                     /* transmit message */
        /* message buffer (I/O addr) */
        __u64                   tx_msgaddr;
        /* for dma_unmap_single() */
-       DECLARE_PCI_UNMAP_ADDR(tx_msgunmap);
+       DEFINE_DMA_UNMAP_ADDR(tx_msgunmap);
        /** sge for tx_msgaddr */
        struct ib_sge           tx_msgsge;
        /* # send work items */
@@ -692,6 +691,8 @@ struct kib_conn {
        struct list_head        ibc_tx_queue_rsrvd;
        /* active tx awaiting completion */
        struct list_head        ibc_active_txs;
+       /* zombie tx awaiting done */
+       struct list_head        ibc_zombie_txs;
        /* serialise */
        spinlock_t              ibc_lock;
        /* the rx descs */
@@ -773,6 +774,26 @@ extern void kiblnd_hdev_destroy(struct kib_hca_dev *hdev);
 
 int kiblnd_msg_queue_size(int version, struct lnet_ni *ni);
 
+static inline int
+kiblnd_concurrent_sends(int version, struct lnet_ni *ni)
+{
+       struct lnet_ioctl_config_o2iblnd_tunables *tunables;
+       int concurrent_sends;
+
+       tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
+       concurrent_sends = tunables->lnd_concurrent_sends;
+
+       if (version == IBLND_MSG_VERSION_1) {
+               if (concurrent_sends > IBLND_MSG_QUEUE_SIZE_V1 * 2)
+                       return IBLND_MSG_QUEUE_SIZE_V1 * 2;
+
+               if (concurrent_sends < IBLND_MSG_QUEUE_SIZE_V1 / 2)
+                       return IBLND_MSG_QUEUE_SIZE_V1 / 2;
+       }
+
+       return concurrent_sends;
+}
+
 static inline void
 kiblnd_hdev_addref_locked(struct kib_hca_dev *hdev)
 {
@@ -1101,6 +1122,12 @@ static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
         ib_dma_unmap_sg(dev, sg, nents, direction);
 }
 
+#ifndef HAVE_IB_SG_DMA_ADDRESS
+#include <linux/scatterlist.h>
+#define ib_sg_dma_address(dev, sg)     sg_dma_address((dev), (sg))
+#define ib_sg_dma_len(dev, sg)         sg_dma_len((dev), (sg))
+#endif
+
 static inline __u64 kiblnd_sg_dma_address(struct ib_device *dev,
                                           struct scatterlist *sg)
 {
@@ -1120,6 +1147,7 @@ static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
 #define KIBLND_CONN_PARAM(e)            ((e)->param.conn.private_data)
 #define KIBLND_CONN_PARAM_LEN(e)        ((e)->param.conn.private_data_len)
 
+void kiblnd_abort_txs(struct kib_conn *conn, struct list_head *txs);
 void kiblnd_map_rx_descs(struct kib_conn *conn);
 void kiblnd_unmap_rx_descs(struct kib_conn *conn);
 void kiblnd_pool_free_node(struct kib_pool *pool, struct list_head *node);
@@ -1164,7 +1192,8 @@ void kiblnd_close_conn(struct kib_conn *conn, int error);
 void kiblnd_close_conn_locked(struct kib_conn *conn, int error);
 
 void kiblnd_launch_tx(struct lnet_ni *ni, struct kib_tx *tx, lnet_nid_t nid);
-void kiblnd_txlist_done(struct list_head *txlist, int status);
+void kiblnd_txlist_done(struct list_head *txlist, int status,
+                       enum lnet_msg_hstatus hstatus);
 
 void kiblnd_qp_event(struct ib_event *event, void *arg);
 void kiblnd_cq_event(struct ib_event *event, void *arg);