root/opal/mca/btl/usnic/btl_usnic_util.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. usnic_fls
  2. usnic_convertor_pack_simple
  3. usnic_netmask_to_cidrlen
  4. usnic_cidrlen_to_netmask

   1 /*
   2  * Copyright (c) 2013-2019 Cisco Systems, Inc.  All rights reserved
   3  * $COPYRIGHT$
   4  *
   5  * Additional copyrights may follow
   6  *
   7  * $HEADER$
   8  */
   9 
  10 #ifndef BTL_USNIC_UTIL_H
  11 #define BTL_USNIC_UTIL_H
  12 
  13 #include "opal/datatype/opal_convertor.h"
  14 
  15 #include "btl_usnic.h"
  16 
  17 #ifndef MIN
  18 #  define MIN(a,b)                ((a) < (b) ? (a) : (b))
  19 #endif
  20 
  21 /*
  22  * Safely (but abnornmally) exit this process without abort()'ing (and
  23  * leaving a corefile).
  24  */
  25 struct opal_btl_usnic_module_t;
  26 void opal_btl_usnic_exit(struct opal_btl_usnic_module_t *module);
  27 
  28 /*
  29  * Print a show_help message and then call opal_btl_usnic_exit().
  30  */
  31 void opal_btl_usnic_util_abort(const char *msg, const char *file, int line);
  32 
  33 /*
  34  * Long enough to hold "xxx.xxx.xxx.xxx/xx"
  35  */
  36 #define IPV4STRADDRLEN 20
  37 
  38 /*
  39  * If netmask==0, it is not included in the output string.  addr is
  40  * expected to be in network byte order.
  41  */
  42 void opal_btl_usnic_snprintf_ipv4_addr(char *out, size_t maxlen,
  43                                        uint32_t addr_be, uint32_t netmask_be);
  44 
  45 void opal_btl_usnic_snprintf_bool_array(char *s, size_t slen, bool a[], size_t alen);
  46 
  47 void opal_btl_usnic_dump_hex(int verbose_level, int output_id,
  48                              void *vaddr, int len);
  49 
  50 size_t opal_btl_usnic_convertor_pack_peek(const opal_convertor_t *conv,
  51                                           size_t max_len);
  52 
  53 /* avoid "defined but not used" warnings */
  54 static inline int __opal_attribute_always_inline__ usnic_fls(int x)
  55     __opal_attribute_unused__;
  56 
  57 static inline int __opal_attribute_always_inline__ usnic_fls(int x)
  58 {
  59     int r = 32;
  60 
  61     if (!x) {
  62         return 0;
  63     }
  64     if (!(x & 0xffff0000u)) {
  65         x <<= 16;
  66         r -= 16;
  67     }
  68     if (!(x & 0xff000000u)) {
  69         x <<= 8;
  70         r -= 8;
  71     }
  72     if (!(x & 0xf0000000u)) {
  73         x <<= 4;
  74         r -= 4;
  75     }
  76     if (!(x & 0xc0000000u)) {
  77         x <<= 2;
  78         r -= 2;
  79     }
  80     if (!(x & 0x80000000u)) {
  81         r -= 1;
  82     }
  83     return r;
  84 }
  85 
  86 /* a helper function that just declutters convertor packing */
  87 static inline void
  88 usnic_convertor_pack_simple(
  89     opal_convertor_t *convertor,
  90     void *dest,
  91     size_t max_bytes_to_pack,
  92     size_t *bytes_packed)
  93 {
  94     int rc;
  95     struct iovec iov;
  96     uint32_t iov_count;
  97 
  98     iov.iov_base = (IOVBASE_TYPE*)dest;
  99     iov.iov_len = max_bytes_to_pack;
 100     iov_count = 1;
 101     *bytes_packed = max_bytes_to_pack;
 102     rc = opal_convertor_pack(convertor, &iov, &iov_count, bytes_packed);
 103     if (OPAL_UNLIKELY(rc < 0)) {
 104         opal_btl_usnic_util_abort("opal_convertor_pack error", __FILE__, __LINE__);
 105     }
 106 }
 107 
 108 static inline int
 109 usnic_netmask_to_cidrlen(
 110     uint32_t netmask_be)
 111 {
 112     return 33 - ffs(ntohl(netmask_be));
 113 }
 114 
 115 static inline uint32_t
 116 usnic_cidrlen_to_netmask(
 117     int cidrlen)
 118 {
 119     uint32_t mask;
 120 
 121     mask = ~0 << (32 - cidrlen);
 122     return htonl(mask);
 123 }
 124 
 125 #endif /* BTL_USNIC_UTIL_H */

/* [<][>][^][v][top][bottom][index][help] */