Whamcloud - gitweb
LU-6261 gnilnd: Thread-safe optimizations.
[fs/lustre-release.git] / lnet / klnds / gnilnd / gnilnd_aries.h
1 /*
2  * Copyright (C) 2009-2012 Cray, Inc.
3  *
4  * Copyright (c) 2014, Intel Corporation.
5  *
6  *   Author: Nic Henke <nic@cray.com>, James Shimek <jshimek@cray.com>
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  */
24 #ifndef _GNILND_ARIES_H
25 #define _GNILND_ARIES_H
26
27 /* for lnet_ipif_query */
28 #include <lnet/lib-lnet.h>
29
30 #ifndef _GNILND_HSS_OPS_H
31 # error "must include gnilnd_hss_ops.h first"
32 #endif
33
34 /* Set HW related values */
35 #ifdef CONFIG_CRAY_XT
36 #include <aries/aries_timeouts_gpl.h>
37 #else
38 /* from aries_timeouts_gpl.h when building for generic kernel */
39 #define TIMEOUT_SECS(x)         ((uint64_t)(((x) / 1000.0) + 0.5))
40 #ifndef TO_GNILND_timeout
41 #define TO_GNILND_timeout               (60000.000000)
42 #endif /* TO_GNILND_timeout */
43 #endif /* CONFIG_CRAY_XT */
44
45 #define GNILND_BASE_TIMEOUT        TIMEOUT_SECS(TO_GNILND_timeout)
46 #define GNILND_CHECKSUM_DEFAULT    0            /* all off for Aries */
47
48 #if defined(CONFIG_CRAY_COMPUTE)
49 #define GNILND_REVERSE_RDMA        GNILND_REVERSE_PUT
50 #define GNILND_RDMA_DLVR_OPTION    GNI_DLVMODE_PERFORMANCE
51 #else
52 #define GNILND_REVERSE_RDMA        GNILND_REVERSE_GET
53 #define GNILND_RDMA_DLVR_OPTION    GNI_DLVMODE_PERFORMANCE
54 #endif
55
56 /* Thread-safe kgni implemented in minor ver 45, code rev 0xb9 */
57 #define GNILND_KGNI_TS_MINOR_VER 0x45
58
59 /* plug in our functions for use on the simulator */
60 #if !defined(GNILND_USE_RCA)
61
62 extern kgn_data_t kgnilnd_data;
63
64 #define kgnilnd_hw_hb()              do {} while(0)
65
66 #ifdef CONFIG_CRAY_XT
67
68 /* Aries Sim doesn't have hardcoded tables, so we'll hijack the nic_pe
69  * and decode our address and nic addr from that - the rest are just offsets */
70
71 static inline int
72 kgnilnd_nid_to_nicaddrs(__u32 nid, int numnic, __u32 *nicaddr)
73 {
74         if (numnic > 1) {
75                 CERROR("manual nid2nic translation doesn't support"
76                        "multiple nic addrs (you asked for %d)\n",
77                         numnic);
78                 return -EINVAL;
79         }
80         if (nid < kgnilnd_data.kgn_nid_trans_private) {
81                 CERROR("Request for invalid nid translation %u,"
82                        "minimum "LPU64"\n",
83                        nid, kgnilnd_data.kgn_nid_trans_private);
84                 return -ESRCH;
85         }
86
87         *nicaddr = nid - kgnilnd_data.kgn_nid_trans_private;
88
89         CDEBUG(D_NETTRACE, "Sim nid %d -> nic 0x%x\n", nid, *nicaddr);
90
91         return 1;
92 }
93
94 static inline int
95 kgnilnd_nicaddr_to_nid(__u32 nicaddr, __u32 *nid)
96 {
97         *nid = kgnilnd_data.kgn_nid_trans_private + nicaddr;
98         return 1;
99 }
100
101 /* XXX Nic: This does not support multiple device!!!! */
102 static inline int
103 kgnilnd_setup_nic_translation(__u32 device_id)
104 {
105         char              *if_name = "ipogif0";
106         __u32              ipaddr, netmask, my_nid;
107         int                up, rc;
108
109         LCONSOLE_INFO("using Aries SIM IP info for RCA translation\n");
110
111         rc = lnet_ipif_query(if_name, &up, &ipaddr, &netmask);
112         if (rc != 0) {
113                 CERROR ("can't get IP interface for %s: %d\n", if_name, rc);
114                 return rc;
115         }
116         if (!up) {
117                 CERROR ("IP interface %s is down\n", if_name);
118                 return -ENODEV;
119         }
120
121         my_nid = ((ipaddr >> 8) & 0xFF) + (ipaddr & 0xFF);
122         kgnilnd_data.kgn_nid_trans_private = my_nid - device_id;
123
124         return 0;
125 }
126
127 #else /* CONFIG_CRAY_XT */
128 #include <net/inet_common.h>
129 #include <linux/if_arp.h>
130
131 static inline int
132 kgnilnd_nid_to_nicaddrs(__u32 nid, int numnic, __u32 *nicaddrs)
133 {
134         int rc;
135
136 #define NID_MASK ((1ULL << 18) - 1)
137         mm_segment_t fs;
138         struct arpreq req = {
139                 .arp_dev = "ipogif0",
140         };
141
142         req.arp_pa.sa_family = AF_INET;
143         ((struct sockaddr_in *)&req.arp_pa)->sin_addr.s_addr = htonl(nid);
144
145         fs = get_fs();
146         set_fs(get_ds());
147
148         rc = inet_ioctl(kgnilnd_data.kgn_sock, SIOCGARP, (unsigned long)&req);
149         set_fs(fs);
150
151         if (rc < 0) {
152                 CDEBUG(D_NETERROR, "inet_ioctl returned %d\n", rc);
153                 return 0;
154         }
155
156         /* use the lower 18 bits of the mac address to use as a nid value */
157         *nicaddrs = *(__u32 *)&req.arp_ha.sa_data[2];
158         *nicaddrs = ntohl(*nicaddrs) & NID_MASK;
159
160         CDEBUG(D_NETTRACE, "nid %s -> nic 0x%x\n", libcfs_nid2str(nid),
161                 nicaddrs[0]);
162
163         return 1;
164 }
165
166 static inline int
167 kgnilnd_nicaddr_to_nid(__u32 nicaddr, __u32 *nid)
168 {
169         int rc;
170         mm_segment_t fs;
171         struct ifreq ifr = {
172                 .ifr_name = "ipogif0",
173         };
174
175         struct sockaddr_in* ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
176
177         fs = get_fs();
178         set_fs(get_ds());
179         rc = inet_ioctl(kgnilnd_data.kgn_sock, SIOCGIFADDR, (unsigned long)&ifr);
180         set_fs(fs);
181
182         if (rc < 0) {
183                 CDEBUG(D_NETERROR, "inet_ioctl returned %d\n", rc);
184                 return 1;
185         }
186
187         CDEBUG(D_NETTRACE, "ipaddr %08x\n", htonl(ipaddr->sin_addr.s_addr));
188
189         *nid = htonl(ipaddr->sin_addr.s_addr);
190         CDEBUG(D_NETTRACE, "nic 0x%x -> nid %s\n", nicaddr,
191                 libcfs_nid2str(*nid));
192         return 0;
193 }
194
195 static inline int
196 kgnilnd_setup_nic_translation(__u32 device_id)
197 {
198         return 0;
199 }
200
201 #endif /* CONFIG_CRAY_XT */
202
203 #endif /* GNILND_USE_RCA */
204
205 #endif /* _GNILND_ARIES_H */