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