-#define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
-#define LNET_VERSION_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
-#define LNET_PHASH_IDX_BITS 9
-#define LNET_PHASH_NUM_BITS (LNET_LOFFT_BITS - 1 -\
- LNET_VERSION_BITS - LNET_PHASH_IDX_BITS)
-#define LNET_PHASH_BITS (LNET_PHASH_IDX_BITS + LNET_PHASH_NUM_BITS)
-
-#define LNET_VERSION_BITMASK ((1ULL << LNET_VERSION_BITS) - 1)
-#define LNET_PHASH_IDX_BITMASK ((1ULL << LNET_PHASH_IDX_BITS) - 1)
-#define LNET_PHASH_NUM_BITMASK ((1ULL << LNET_PHASH_NUM_BITS) - 1)
-
-#define LNET_VERSION_MASK (LNET_VERSION_BITMASK << LNET_PHASH_BITS)
-#define LNET_PHASH_IDX_MASK (LNET_PHASH_IDX_BITMASK << LNET_PHASH_NUM_BITS)
-#define LNET_PHASH_NUM_MASK (LNET_PHASH_NUM_BITMASK)
-
-#define LNET_VERSION_GET(pos) (int)(((pos) & LNET_VERSION_MASK) >> \
- LNET_PHASH_BITS)
-#define LNET_PHASH_IDX_GET(pos) (int)(((pos) & LNET_PHASH_IDX_MASK) >> \
- LNET_PHASH_NUM_BITS)
-#define LNET_PHASH_NUM_GET(pos) (int)((pos) & LNET_PHASH_NUM_MASK)
-#define LNET_VERSION_VALID_MASK(ver) \
- (unsigned int)((ver) & \
- LNET_VERSION_BITMASK)
-#define LNET_PHASH_POS_MAKE(ver, idx, num) \
- (((((loff_t)(ver)) & LNET_VERSION_BITMASK) << \
- LNET_PHASH_BITS) | \
- ((((loff_t)(idx)) & LNET_PHASH_IDX_BITMASK) <<\
- LNET_PHASH_NUM_BITS) | \
- ((num) & LNET_PHASH_NUM_BITMASK))
-
-static int __proc_lnet_stats(void *data, int write,
- loff_t pos, void *buffer, int nob)
-{
- int rc;
- lnet_counters_t *ctrs;
- int len;
- char *tmpstr;
- const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
-
- if (write) {
- LNET_LOCK();
- memset(&the_lnet.ln_counters, 0, sizeof(the_lnet.ln_counters));
- LNET_UNLOCK();
- return 0;
- }
-
- /* read */
-
- LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
- if (ctrs == NULL)
- return -ENOMEM;
-
- LIBCFS_ALLOC(tmpstr, tmpsiz);
- if (tmpstr == NULL) {
- LIBCFS_FREE(ctrs, sizeof(*ctrs));
- return -ENOMEM;
- }
-
- LNET_LOCK();
- *ctrs = the_lnet.ln_counters;
- LNET_UNLOCK();
-
- len = snprintf(tmpstr, tmpsiz,
- "%u %u %u %u %u %u %u "LPU64" "LPU64" "
- LPU64" "LPU64,
- ctrs->msgs_alloc, ctrs->msgs_max,
- ctrs->errors,
- ctrs->send_count, ctrs->recv_count,
- ctrs->route_count, ctrs->drop_count,
- ctrs->send_length, ctrs->recv_length,
- ctrs->route_length, ctrs->drop_length);
-
- if (pos >= min_t(int, len, strlen(tmpstr)))
- rc = 0;
- else
- rc = cfs_trace_copyout_string(buffer, nob,
- tmpstr + pos, "\n");
-
- LIBCFS_FREE(tmpstr, tmpsiz);
- LIBCFS_FREE(ctrs, sizeof(*ctrs));
- return rc;
-}
-
-DECLARE_PROC_HANDLER(proc_lnet_stats);
-
-int LL_PROC_PROTO(proc_lnet_routes)
-{
- int rc = 0;
- char *tmpstr;
- char *s;
- const int tmpsiz = 256;
- int len;
- int ver;
- int num;
-
- DECLARE_LL_PROC_PPOS_DECL;
-
- num = LNET_PHASH_NUM_GET(*ppos);
- ver = LNET_VERSION_GET(*ppos);
-
- LASSERT (!write);
-
- if (*lenp == 0)
- return 0;
-
- LIBCFS_ALLOC(tmpstr, tmpsiz);
- if (tmpstr == NULL)
- return -ENOMEM;
-
- s = tmpstr; /* points to current position in tmpstr[] */
-
- if (*ppos == 0) {
- s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
- the_lnet.ln_routing ? "enabled" : "disabled");
- LASSERT (tmpstr + tmpsiz - s > 0);
-
- s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %7s %s\n",
- "net", "hops", "state", "router");
- LASSERT (tmpstr + tmpsiz - s > 0);
-
- LNET_LOCK();
- ver = (unsigned int)the_lnet.ln_remote_nets_version;
- LNET_UNLOCK();
- *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
- } else {
- cfs_list_t *n;
- cfs_list_t *r;
- lnet_route_t *route = NULL;
- lnet_remotenet_t *rnet = NULL;
- int skip = num - 1;
-
- LNET_LOCK();
-
- if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_remote_nets_version)) {
- LNET_UNLOCK();
- LIBCFS_FREE(tmpstr, tmpsiz);
- return -ESTALE;
- }
-
- n = the_lnet.ln_remote_nets.next;
-
- while (n != &the_lnet.ln_remote_nets && route == NULL) {
- rnet = cfs_list_entry(n, lnet_remotenet_t, lrn_list);