1 /* 2 * Copyright (c) 2008 Oracle. All rights reserved. 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 18 * - Redistributions in binary form must reproduce the above 19 * copyright notice, this list of conditions and the following 20 * disclaimer in the documentation and/or other materials 21 * provided with the distribution. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 * 32 */ 33 34 #ifndef _LINUX_RDS_H 35 #define _LINUX_RDS_H 36 37 #include <linux/types.h> 38 #include <linux/socket.h> /* For __kernel_sockaddr_storage. */ 39 40 #define RDS_IB_ABI_VERSION 0x301 41 42 #define SOL_RDS 276 43 44 /* 45 * setsockopt/getsockopt for SOL_RDS 46 */ 47 #define RDS_CANCEL_SENT_TO 1 48 #define RDS_GET_MR 2 49 #define RDS_FREE_MR 3 50 /* deprecated: RDS_BARRIER 4 */ 51 #define RDS_RECVERR 5 52 #define RDS_CONG_MONITOR 6 53 #define RDS_GET_MR_FOR_DEST 7 54 #define SO_RDS_TRANSPORT 8 55 56 /* supported values for SO_RDS_TRANSPORT */ 57 #define RDS_TRANS_IB 0 58 #define RDS_TRANS_IWARP 1 59 #define RDS_TRANS_TCP 2 60 #define RDS_TRANS_COUNT 3 61 #define RDS_TRANS_NONE (~0) 62 63 /* 64 * Control message types for SOL_RDS. 65 * 66 * CMSG_RDMA_ARGS (sendmsg) 67 * Request a RDMA transfer to/from the specified 68 * memory ranges. 69 * The cmsg_data is a struct rds_rdma_args. 70 * RDS_CMSG_RDMA_DEST (recvmsg, sendmsg) 71 * Kernel informs application about intended 72 * source/destination of a RDMA transfer 73 * RDS_CMSG_RDMA_MAP (sendmsg) 74 * Application asks kernel to map the given 75 * memory range into a IB MR, and send the 76 * R_Key along in an RDS extension header. 77 * The cmsg_data is a struct rds_get_mr_args, 78 * the same as for the GET_MR setsockopt. 79 * RDS_CMSG_RDMA_STATUS (recvmsg) 80 * Returns the status of a completed RDMA operation. 81 */ 82 #define RDS_CMSG_RDMA_ARGS 1 83 #define RDS_CMSG_RDMA_DEST 2 84 #define RDS_CMSG_RDMA_MAP 3 85 #define RDS_CMSG_RDMA_STATUS 4 86 #define RDS_CMSG_CONG_UPDATE 5 87 #define RDS_CMSG_ATOMIC_FADD 6 88 #define RDS_CMSG_ATOMIC_CSWP 7 89 #define RDS_CMSG_MASKED_ATOMIC_FADD 8 90 #define RDS_CMSG_MASKED_ATOMIC_CSWP 9 91 92 #define RDS_INFO_FIRST 10000 93 #define RDS_INFO_COUNTERS 10000 94 #define RDS_INFO_CONNECTIONS 10001 95 /* 10002 aka RDS_INFO_FLOWS is deprecated */ 96 #define RDS_INFO_SEND_MESSAGES 10003 97 #define RDS_INFO_RETRANS_MESSAGES 10004 98 #define RDS_INFO_RECV_MESSAGES 10005 99 #define RDS_INFO_SOCKETS 10006 100 #define RDS_INFO_TCP_SOCKETS 10007 101 #define RDS_INFO_IB_CONNECTIONS 10008 102 #define RDS_INFO_CONNECTION_STATS 10009 103 #define RDS_INFO_IWARP_CONNECTIONS 10010 104 #define RDS_INFO_LAST 10010 105 106 struct rds_info_counter { 107 __u8 name[32]; 108 __u64 value; 109 } __attribute__((packed)); 110 111 #define RDS_INFO_CONNECTION_FLAG_SENDING 0x01 112 #define RDS_INFO_CONNECTION_FLAG_CONNECTING 0x02 113 #define RDS_INFO_CONNECTION_FLAG_CONNECTED 0x04 114 115 #define TRANSNAMSIZ 16 116 117 struct rds_info_connection { 118 __u64 next_tx_seq; 119 __u64 next_rx_seq; 120 __be32 laddr; 121 __be32 faddr; 122 __u8 transport[TRANSNAMSIZ]; /* null term ascii */ 123 __u8 flags; 124 } __attribute__((packed)); 125 126 #define RDS_INFO_MESSAGE_FLAG_ACK 0x01 127 #define RDS_INFO_MESSAGE_FLAG_FAST_ACK 0x02 128 129 struct rds_info_message { 130 __u64 seq; 131 __u32 len; 132 __be32 laddr; 133 __be32 faddr; 134 __be16 lport; 135 __be16 fport; 136 __u8 flags; 137 } __attribute__((packed)); 138 139 struct rds_info_socket { 140 __u32 sndbuf; 141 __be32 bound_addr; 142 __be32 connected_addr; 143 __be16 bound_port; 144 __be16 connected_port; 145 __u32 rcvbuf; 146 __u64 inum; 147 } __attribute__((packed)); 148 149 struct rds_info_tcp_socket { 150 __be32 local_addr; 151 __be16 local_port; 152 __be32 peer_addr; 153 __be16 peer_port; 154 __u64 hdr_rem; 155 __u64 data_rem; 156 __u32 last_sent_nxt; 157 __u32 last_expected_una; 158 __u32 last_seen_una; 159 } __attribute__((packed)); 160 161 #define RDS_IB_GID_LEN 16 162 struct rds_info_rdma_connection { 163 __be32 src_addr; 164 __be32 dst_addr; 165 __u8 src_gid[RDS_IB_GID_LEN]; 166 __u8 dst_gid[RDS_IB_GID_LEN]; 167 168 __u32 max_send_wr; 169 __u32 max_recv_wr; 170 __u32 max_send_sge; 171 __u32 rdma_mr_max; 172 __u32 rdma_mr_size; 173 }; 174 175 /* 176 * Congestion monitoring. 177 * Congestion control in RDS happens at the host connection 178 * level by exchanging a bitmap marking congested ports. 179 * By default, a process sleeping in poll() is always woken 180 * up when the congestion map is updated. 181 * With explicit monitoring, an application can have more 182 * fine-grained control. 183 * The application installs a 64bit mask value in the socket, 184 * where each bit corresponds to a group of ports. 185 * When a congestion update arrives, RDS checks the set of 186 * ports that are now uncongested against the list bit mask 187 * installed in the socket, and if they overlap, we queue a 188 * cong_notification on the socket. 189 * 190 * To install the congestion monitor bitmask, use RDS_CONG_MONITOR 191 * with the 64bit mask. 192 * Congestion updates are received via RDS_CMSG_CONG_UPDATE 193 * control messages. 194 * 195 * The correspondence between bits and ports is 196 * 1 << (portnum % 64) 197 */ 198 #define RDS_CONG_MONITOR_SIZE 64 199 #define RDS_CONG_MONITOR_BIT(port) (((unsigned int) port) % RDS_CONG_MONITOR_SIZE) 200 #define RDS_CONG_MONITOR_MASK(port) (1ULL << RDS_CONG_MONITOR_BIT(port)) 201 202 /* 203 * RDMA related types 204 */ 205 206 /* 207 * This encapsulates a remote memory location. 208 * In the current implementation, it contains the R_Key 209 * of the remote memory region, and the offset into it 210 * (so that the application does not have to worry about 211 * alignment). 212 */ 213 typedef __u64 rds_rdma_cookie_t; 214 215 struct rds_iovec { 216 __u64 addr; 217 __u64 bytes; 218 }; 219 220 struct rds_get_mr_args { 221 struct rds_iovec vec; 222 __u64 cookie_addr; 223 __u64 flags; 224 }; 225 226 struct rds_get_mr_for_dest_args { 227 struct __kernel_sockaddr_storage dest_addr; 228 struct rds_iovec vec; 229 __u64 cookie_addr; 230 __u64 flags; 231 }; 232 233 struct rds_free_mr_args { 234 rds_rdma_cookie_t cookie; 235 __u64 flags; 236 }; 237 238 struct rds_rdma_args { 239 rds_rdma_cookie_t cookie; 240 struct rds_iovec remote_vec; 241 __u64 local_vec_addr; 242 __u64 nr_local; 243 __u64 flags; 244 __u64 user_token; 245 }; 246 247 struct rds_atomic_args { 248 rds_rdma_cookie_t cookie; 249 __u64 local_addr; 250 __u64 remote_addr; 251 union { 252 struct { 253 __u64 compare; 254 __u64 swap; 255 } cswp; 256 struct { 257 __u64 add; 258 } fadd; 259 struct { 260 __u64 compare; 261 __u64 swap; 262 __u64 compare_mask; 263 __u64 swap_mask; 264 } m_cswp; 265 struct { 266 __u64 add; 267 __u64 nocarry_mask; 268 } m_fadd; 269 }; 270 __u64 flags; 271 __u64 user_token; 272 }; 273 274 struct rds_rdma_notify { 275 __u64 user_token; 276 __s32 status; 277 }; 278 279 #define RDS_RDMA_SUCCESS 0 280 #define RDS_RDMA_REMOTE_ERROR 1 281 #define RDS_RDMA_CANCELED 2 282 #define RDS_RDMA_DROPPED 3 283 #define RDS_RDMA_OTHER_ERROR 4 284 285 /* 286 * Common set of flags for all RDMA related structs 287 */ 288 #define RDS_RDMA_READWRITE 0x0001 289 #define RDS_RDMA_FENCE 0x0002 /* use FENCE for immediate send */ 290 #define RDS_RDMA_INVALIDATE 0x0004 /* invalidate R_Key after freeing MR */ 291 #define RDS_RDMA_USE_ONCE 0x0008 /* free MR after use */ 292 #define RDS_RDMA_DONTWAIT 0x0010 /* Don't wait in SET_BARRIER */ 293 #define RDS_RDMA_NOTIFY_ME 0x0020 /* Notify when operation completes */ 294 #define RDS_RDMA_SILENT 0x0040 /* Do not interrupt remote */ 295 296 #endif /* IB_RDS_H */ 297