Whamcloud - gitweb
LU-4423 lnet: don't use iovec instead of kvec
[fs/lustre-release.git] / lnet / klnds / gnilnd / gnilnd.h
index a878522..9f6b36b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2009-2012 Cray, Inc.
  *
- * Copyright (c) 2013, 2014, Intel Corporation.
+ * Copyright (c) 2014, Intel Corporation.
  *
  *   Derived from work by: Eric Barton <eric@bartonsoftware.com>
  *   Author: Nic Henke <nic@cray.com>
 
 /* Max number of connections to keep in purgatory per peer */
 #define GNILND_PURGATORY_MAX     5
+/* Closing, don't put in purgatory */
+#define GNILND_NOPURG             222
 
 /* payload size to add to the base mailbox size
  * This is subtracting 2 from the concurrent_sends as 4 messages are included in the size
@@ -484,8 +486,9 @@ typedef struct kgn_tunables {
        int     *kgn_efault_lbug;      /* LBUG on receiving an EFAULT */
        int     *kgn_max_purgatory;    /* # conns/peer to keep in purgatory */
        int     *kgn_thread_affinity;  /* bind scheduler threads to cpus */
+       int     *kgn_thread_safe;      /* use thread safe kgni API */
 #if CONFIG_SYSCTL && !CFS_SYSFS_MODULE_PARM
-       cfs_sysctl_table_header_t *kgn_sysctl;  /* sysctl interface */
+       struct ctl_table_header *kgn_sysctl;  /* sysctl interface */
 #endif
 } kgn_tunables_t;
 
@@ -588,6 +591,8 @@ typedef struct kgn_device {
        atomic_t                gnd_n_schedule;
        atomic_t                gnd_canceled_dgrams; /* # of outstanding cancels */
        struct rw_semaphore     gnd_conn_sem;       /* serialize connection changes/data movement */
+       void                   *gnd_smdd_hold_buf;  /* buffer to keep smdd */
+       gni_mem_handle_t        gnd_smdd_hold_hndl; /* buffer mem handle */
 } kgn_device_t;
 
 typedef struct kgn_net {
@@ -893,14 +898,6 @@ kgnilnd_thread_fini(void)
        atomic_dec(&kgnilnd_data.kgn_nthreads);
 }
 
-static inline int kgnilnd_gl_mutex_trylock(struct mutex *lock)
-{
-       if (kgnilnd_data.kgn_enable_gl_mutex)
-               return mutex_trylock(lock);
-       else
-               return 1;
-}
-
 static inline void kgnilnd_gl_mutex_lock(struct mutex *lock)
 {
        if (kgnilnd_data.kgn_enable_gl_mutex)
@@ -938,14 +935,11 @@ static inline void kgnilnd_conn_mutex_unlock(struct mutex *lock)
  * This function must not be used in interrupt context. The
  * mutex must be released by the same task that acquired it.
  */
-static inline int kgnilnd_mutex_trylock(struct mutex *lock)
+static inline int __kgnilnd_mutex_trylock(struct mutex *lock)
 {
        int             ret;
        unsigned long   timeout;
 
-       if (!kgnilnd_data.kgn_enable_gl_mutex)
-               return 1;
-
        LASSERT(!in_interrupt());
 
        for (timeout = jiffies + 1; time_before(jiffies, timeout);) {
@@ -957,6 +951,31 @@ static inline int kgnilnd_mutex_trylock(struct mutex *lock)
        return 0;
 }
 
+static inline int kgnilnd_mutex_trylock(struct mutex *lock)
+{
+       if (!kgnilnd_data.kgn_enable_gl_mutex)
+               return 1;
+
+       return __kgnilnd_mutex_trylock(lock);
+}
+
+static inline int kgnilnd_trylock(struct mutex *cq_lock,
+                                 struct mutex *c_lock)
+{
+       if (kgnilnd_data.kgn_enable_gl_mutex)
+               return __kgnilnd_mutex_trylock(cq_lock);
+       else
+               return __kgnilnd_mutex_trylock(c_lock);
+}
+
+static inline void *kgnilnd_vzalloc(int size)
+{
+       void *ret = __vmalloc(size, __GFP_HIGHMEM | GFP_NOFS | __GFP_ZERO,
+                             PAGE_KERNEL);
+       LIBCFS_ALLOC_POST(ret, size);
+       return ret;
+}
+
 /* Copied from DEBUG_REQ in Lustre - the dance is needed to save stack space */
 
 extern void
@@ -1722,7 +1741,7 @@ int kgnilnd_eager_recv(lnet_ni_t *ni, void *private,
                        lnet_msg_t *lntmsg, void **new_private);
 int kgnilnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg,
                int delayed, unsigned int niov,
-               struct iovec *iov, lnet_kiov_t *kiov,
+               struct kvec *iov, lnet_kiov_t *kiov,
                unsigned int offset, unsigned int mlen, unsigned int rlen);
 
 __u16 kgnilnd_cksum_kiov(unsigned int nkiov, lnet_kiov_t *kiov, unsigned int offset, unsigned int nob, int dump_blob);
@@ -1967,6 +1986,8 @@ kgnilnd_conn_dgram_type2str(kgn_dgram_type_t type)
 /* pulls in tunables per platform and adds in nid/nic conversion
  * if RCA wasn't available at build time */
 #include "gnilnd_hss_ops.h"
+/* API wrapper functions - include late to pick up all of the other defines */
+#include "gnilnd_api_wrap.h"
 
 #if defined(CONFIG_CRAY_GEMINI)
  #include "gnilnd_gemini.h"
@@ -1976,7 +1997,38 @@ kgnilnd_conn_dgram_type2str(kgn_dgram_type_t type)
  #error "Undefined Network Hardware Type"
 #endif
 
-/* API wrapper functions - include late to pick up all of the other defines */
-#include "gnilnd_api_wrap.h"
+extern uint32_t kgni_driver_version;
+
+static inline void
+kgnilnd_check_kgni_version(void)
+{
+       uint32_t *kdv;
+
+       kgnilnd_data.kgn_enable_gl_mutex = 1;
+       kdv = symbol_get(kgni_driver_version);
+       if (!kdv) {
+               LCONSOLE_INFO("Not using thread safe locking -"
+                       " no symbol kgni_driver_version\n");
+               return;
+       }
+
+       /* Thread-safe kgni implemented in minor ver 0x44/45, code rev 0xb9 */
+       if (*kdv < GNI_VERSION_CHECK(0, GNILND_KGNI_TS_MINOR_VER, 0xb9)) {
+               symbol_put(kgni_driver_version);
+               LCONSOLE_INFO("Not using thread safe locking, gni version 0x%x,"
+                       " need >= 0x%x\n", *kdv,
+                       GNI_VERSION_CHECK(0, GNILND_KGNI_TS_MINOR_VER, 0xb9));
+               return;
+       }
+
+       symbol_put(kgni_driver_version);
+
+       if (!*kgnilnd_tunables.kgn_thread_safe) {
+               return;
+       }
+
+       /* Use thread-safe locking */
+       kgnilnd_data.kgn_enable_gl_mutex = 0;
+}
 
 #endif /* _GNILND_GNILND_H_ */