Whamcloud - gitweb
LU-6068 misc: update Intel copyright messages 2014
[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 libcfs_ipif_query */
28 #include <libcfs/libcfs.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 /* plug in our functions for use on the simulator */
57 #if !defined(GNILND_USE_RCA)
58
59 extern kgn_data_t kgnilnd_data;
60
61 #define kgnilnd_hw_hb()              do {} while(0)
62
63 #ifdef CONFIG_CRAY_XT
64
65 /* Aries Sim doesn't have hardcoded tables, so we'll hijack the nic_pe
66  * and decode our address and nic addr from that - the rest are just offsets */
67
68 static inline int
69 kgnilnd_nid_to_nicaddrs(__u32 nid, int numnic, __u32 *nicaddr)
70 {
71         if (numnic > 1) {
72                 CERROR("manual nid2nic translation doesn't support"
73                        "multiple nic addrs (you asked for %d)\n",
74                         numnic);
75                 return -EINVAL;
76         }
77         if (nid < kgnilnd_data.kgn_nid_trans_private) {
78                 CERROR("Request for invalid nid translation %u,"
79                        "minimum "LPU64"\n",
80                        nid, kgnilnd_data.kgn_nid_trans_private);
81                 return -ESRCH;
82         }
83
84         *nicaddr = nid - kgnilnd_data.kgn_nid_trans_private;
85
86         CDEBUG(D_NETTRACE, "Sim nid %d -> nic 0x%x\n", nid, *nicaddr);
87
88         return 1;
89 }
90
91 static inline int
92 kgnilnd_nicaddr_to_nid(__u32 nicaddr, __u32 *nid)
93 {
94         *nid = kgnilnd_data.kgn_nid_trans_private + nicaddr;
95         return 1;
96 }
97
98 /* XXX Nic: This does not support multiple device!!!! */
99 static inline int
100 kgnilnd_setup_nic_translation(__u32 device_id)
101 {
102         char              *if_name = "ipogif0";
103         __u32              ipaddr, netmask, my_nid;
104         int                up, rc;
105
106         LCONSOLE_INFO("using Aries SIM IP info for RCA translation\n");
107
108         rc = libcfs_ipif_query(if_name, &up, &ipaddr, &netmask);
109         if (rc != 0) {
110                 CERROR ("can't get IP interface for %s: %d\n", if_name, rc);
111                 return rc;
112         }
113         if (!up) {
114                 CERROR ("IP interface %s is down\n", if_name);
115                 return -ENODEV;
116         }
117
118         my_nid = ((ipaddr >> 8) & 0xFF) + (ipaddr & 0xFF);
119         kgnilnd_data.kgn_nid_trans_private = my_nid - device_id;
120
121         return 0;
122 }
123
124 #else /* CONFIG_CRAY_XT */
125 #include <net/inet_common.h>
126 #include <linux/if_arp.h>
127
128 static inline int
129 kgnilnd_nid_to_nicaddrs(__u32 nid, int numnic, __u32 *nicaddrs)
130 {
131         int rc;
132
133 #define NID_MASK ((1ULL << 18) - 1)
134         mm_segment_t fs;
135         struct arpreq req = {
136                 .arp_dev = "ipogif0",
137         };
138
139         req.arp_pa.sa_family = AF_INET;
140         ((struct sockaddr_in *)&req.arp_pa)->sin_addr.s_addr = htonl(nid);
141
142         fs = get_fs();
143         set_fs(get_ds());
144
145         rc = inet_ioctl(kgnilnd_data.kgn_sock, SIOCGARP, (unsigned long)&req);
146         set_fs(fs);
147
148         if (rc < 0) {
149                 CDEBUG(D_NETERROR, "inet_ioctl returned %d\n", rc);
150                 return 0;
151         }
152
153         /* use the lower 18 bits of the mac address to use as a nid value */
154         *nicaddrs = *(__u32 *)&req.arp_ha.sa_data[2];
155         *nicaddrs = ntohl(*nicaddrs) & NID_MASK;
156
157         CDEBUG(D_NETTRACE, "nid %s -> nic 0x%x\n", libcfs_nid2str(nid),
158                 nicaddrs[0]);
159
160         return 1;
161 }
162
163 static inline int
164 kgnilnd_nicaddr_to_nid(__u32 nicaddr, __u32 *nid)
165 {
166         int rc;
167         mm_segment_t fs;
168         struct ifreq ifr = {
169                 .ifr_name = "ipogif0",
170         };
171
172         struct sockaddr_in* ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
173
174         fs = get_fs();
175         set_fs(get_ds());
176         rc = inet_ioctl(kgnilnd_data.kgn_sock, SIOCGIFADDR, (unsigned long)&ifr);
177         set_fs(fs);
178
179         if (rc < 0) {
180                 CDEBUG(D_NETERROR, "inet_ioctl returned %d\n", rc);
181                 return 1;
182         }
183
184         CDEBUG(D_NETTRACE, "ipaddr %08x\n", htonl(ipaddr->sin_addr.s_addr));
185
186         *nid = htonl(ipaddr->sin_addr.s_addr);
187         CDEBUG(D_NETTRACE, "nic 0x%x -> nid %s\n", nicaddr,
188                 libcfs_nid2str(*nid));
189         return 0;
190 }
191
192 static inline int
193 kgnilnd_setup_nic_translation(__u32 device_id)
194 {
195         return 0;
196 }
197
198 #endif /* CONFIG_CRAY_XT */
199
200 #endif /* GNILND_USE_RCA */
201
202 #endif /* _GNILND_ARIES_H */