Whamcloud - gitweb
* Landed b_cray_portals_merge.
[fs/lustre-release.git] / lnet / lnet / lib-ni.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * lib/lib-ni.c
5  * Network status registers and distance functions.
6  *
7  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
8  *  Copyright (c) 2001-2002 Sandia National Laboratories
9  *
10  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #define DEBUG_SUBSYSTEM S_PORTALS
27 #include <portals/lib-p30.h>
28 #include <portals/arg-blocks.h>
29
30 #define MAX_DIST 18446744073709551615ULL
31
32 int do_PtlNIStatus(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
33 {
34         /*
35          * Incoming:
36          *      ptl_handle_ni_t interface_in
37          *      ptl_sr_index_t register_in
38          *
39          * Outgoing:
40          *      ptl_sr_value_t          * status_out
41          */
42
43         PtlNIStatus_in *args = v_args;
44         PtlNIStatus_out *ret = v_ret;
45         lib_ni_t *ni = &nal->ni;
46         lib_counters_t *count = &ni->counters;
47
48         if (!args)
49                 return ret->rc = PTL_SEGV;
50
51         ret->rc = PTL_OK;
52         ret->status_out = 0;
53
54         /*
55          * I hate this sort of code....  Hash tables, offset lists?
56          * Treat the counters as an array of ints?
57          */
58         if (args->register_in == PTL_SR_DROP_COUNT)
59                 ret->status_out = count->drop_count;
60
61         else if (args->register_in == PTL_SR_DROP_LENGTH)
62                 ret->status_out = count->drop_length;
63
64         else if (args->register_in == PTL_SR_RECV_COUNT)
65                 ret->status_out = count->recv_count;
66
67         else if (args->register_in == PTL_SR_RECV_LENGTH)
68                 ret->status_out = count->recv_length;
69
70         else if (args->register_in == PTL_SR_SEND_COUNT)
71                 ret->status_out = count->send_count;
72
73         else if (args->register_in == PTL_SR_SEND_LENGTH)
74                 ret->status_out = count->send_length;
75
76         else if (args->register_in == PTL_SR_MSGS_MAX)
77                 ret->status_out = count->msgs_max;
78         else
79                 ret->rc = PTL_SR_INDEX_INVALID;
80
81         return ret->rc;
82 }
83
84
85 int do_PtlNIDist(nal_cb_t * nal, void *private, void *v_args, void *v_ret)
86 {
87         /*
88          * Incoming:
89          *      ptl_handle_ni_t interface_in
90          *      ptl_process_id_t process_in
91
92          *
93          * Outgoing:
94          *      unsigned long   * distance_out
95
96          */
97
98         PtlNIDist_in *args = v_args;
99         PtlNIDist_out *ret = v_ret;
100
101         unsigned long dist;
102         ptl_process_id_t id_in = args->process_in;
103         ptl_nid_t nid;
104         int rc;
105
106         nid = id_in.nid;
107
108         if ((rc = nal->cb_dist(nal, nid, &dist)) != 0) {
109                 ret->distance_out = (unsigned long) MAX_DIST;
110                 return PTL_PROCESS_INVALID;
111         }
112
113         ret->distance_out = dist;
114
115         return ret->rc = PTL_OK;
116 }