Whamcloud - gitweb
LU-4431 lnet: 1/3/2014 update for Cray interconnects
[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, minimum %Lu\n",
78                        nid, kgnilnd_data.kgn_nid_trans_private);
79                 return -ESRCH;
80         }
81
82         *nicaddr = nid - kgnilnd_data.kgn_nid_trans_private;
83
84         CDEBUG(D_NETTRACE, "Sim nid %d -> nic 0x%x\n", nid, *nicaddr);
85
86         return 1;
87 }
88
89 static inline int
90 kgnilnd_nicaddr_to_nid(__u32 nicaddr, __u32 *nid)
91 {
92         *nid = kgnilnd_data.kgn_nid_trans_private + nicaddr;
93         return 1;
94 }
95
96 /* XXX Nic: This does not support multiple device!!!! */
97 static inline int
98 kgnilnd_setup_nic_translation(__u32 device_id)
99 {
100         char              *if_name = "ipogif0";
101         __u32              ipaddr, netmask, my_nid;
102         int                up, rc;
103
104         LCONSOLE_INFO("using Aries SIM IP info for RCA translation\n");
105
106         rc = libcfs_ipif_query(if_name, &up, &ipaddr, &netmask);
107         if (rc != 0) {
108                 CERROR ("can't get IP interface for %s: %d\n", if_name, rc);
109                 return rc;
110         }
111         if (!up) {
112                 CERROR ("IP interface %s is down\n", if_name);
113                 return -ENODEV;
114         }
115
116         my_nid = ((ipaddr >> 8) & 0xFF) + (ipaddr & 0xFF);
117         kgnilnd_data.kgn_nid_trans_private = my_nid - device_id;
118
119         return 0;
120 }
121
122 #else /* CONFIG_CRAY_XT */
123 #include <net/inet_common.h>
124 #include <linux/if_arp.h>
125
126 static inline int
127 kgnilnd_nid_to_nicaddrs(__u32 nid, int numnic, __u32 *nicaddrs)
128 {
129         int rc;
130
131 #define NID_MASK ((1ULL << 18) - 1)
132         mm_segment_t fs;
133         struct arpreq req = {
134                 .arp_dev = "ipogif0",
135         };
136
137         req.arp_pa.sa_family = AF_INET;
138         ((struct sockaddr_in *)&req.arp_pa)->sin_addr.s_addr = htonl(nid);
139
140         fs = get_fs();
141         set_fs(get_ds());
142
143         rc = inet_ioctl(kgnilnd_data.kgn_sock, SIOCGARP, (unsigned long)&req);
144         set_fs(fs);
145
146         if (rc < 0) {
147                 CDEBUG(D_NETERROR, "inet_ioctl returned %d\n", rc);
148                 return 0;
149         }
150
151         /* use the lower 18 bits of the mac address to use as a nid value */
152         *nicaddrs = *(__u32 *)&req.arp_ha.sa_data[2];
153         *nicaddrs = ntohl(*nicaddrs) & NID_MASK;
154
155         CDEBUG(D_NETTRACE, "nid %s -> nic 0x%x\n", libcfs_nid2str(nid),
156                 nicaddrs[0]);
157
158         return 1;
159 }
160
161 static inline int
162 kgnilnd_nicaddr_to_nid(__u32 nicaddr, __u32 *nid)
163 {
164         int rc;
165         mm_segment_t fs;
166         struct ifreq ifr = {
167                 .ifr_name = "ipogif0",
168         };
169
170         struct sockaddr_in* ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
171
172         fs = get_fs();
173         set_fs(get_ds());
174         rc = inet_ioctl(kgnilnd_data.kgn_sock, SIOCGIFADDR, (unsigned long)&ifr);
175         set_fs(fs);
176
177         if (rc < 0) {
178                 CDEBUG(D_NETERROR, "inet_ioctl returned %d\n", rc);
179                 return 1;
180         }
181
182         CDEBUG(D_NETTRACE, "ipaddr %08x\n", htonl(ipaddr->sin_addr.s_addr));
183
184         *nid = htonl(ipaddr->sin_addr.s_addr);
185         CDEBUG(D_NETTRACE, "nic 0x%x -> nid %s\n", nicaddr,
186                 libcfs_nid2str(*nid));
187         return 0;
188 }
189
190 static inline int
191 kgnilnd_setup_nic_translation(__u32 device_id)
192 {
193         return 0;
194 }
195
196 #endif /* CONFIG_CRAY_XT */
197
198 #endif /* GNILND_USE_RCA */
199
200 #endif /* _GNILND_ARIES_H */