xref: /titanic_50/usr/src/uts/common/sys/ib/clients/of/rdma/ib_addr.h (revision c39526b769298791ff5b0b6c5e761f49aabaeb4e)
1 /*
2  * This file contains definitions used in OFED defined user/kernel
3  * interfaces. These are imported from the OFED header ib_addr.h. Oracle
4  * elects to have and use the contents of ib_addr.h under and governed
5  * by the OpenIB.org BSD license (see below for details). However,
6  * the following notice accompanied the original version of this file:
7  */
8 
9 /*
10  * Copyright (c) 2005 Voltaire Inc.  All rights reserved.
11  * Copyright (c) 2005 Intel Corporation.  All rights reserved.
12  *
13  * This Software is licensed under one of the following licenses:
14  *
15  * 1) under the terms of the "Common Public License 1.0" a copy of which is
16  *    available from the Open Source Initiative, see
17  *    http://www.opensource.org/licenses/cpl.php.
18  *
19  * 2) under the terms of the "The BSD License" a copy of which is
20  *    available from the Open Source Initiative, see
21  *    http://www.opensource.org/licenses/bsd-license.php.
22  *
23  * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
24  *    copy of which is available from the Open Source Initiative, see
25  *    http://www.opensource.org/licenses/gpl-license.php.
26  *
27  * Licensee has the right to choose one of the above licenses.
28  *
29  * Redistributions of source code must retain the above copyright
30  * notice and one of the license notices.
31  *
32  * Redistributions in binary form must reproduce both the above copyright
33  * notice, one of the license notices in the documentation
34  * and/or other materials provided with the distribution.
35  *
36  */
37 
38 #ifndef _SYS_IB_CLIENTS_OF_RDMA_IB_ADDR_H
39 #define	_SYS_IB_CLIENTS_OF_RDMA_IB_ADDR_H
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 
46 #include <sys/socket.h>
47 #include <sys/ib/clients/of/rdma/ib_verbs.h>
48 
49 #define	MAX_ADDR_LEN	32	/* Maximim hardware length */
50 
51 struct rdma_dev_addr {
52 	unsigned char src_dev_addr[MAX_ADDR_LEN];
53 	unsigned char dst_dev_addr[MAX_ADDR_LEN];
54 	unsigned char broadcast[MAX_ADDR_LEN];
55 	enum rdma_node_type dev_type;
56 };
57 
ip_addr_size(struct sockaddr * addr)58 static inline int ip_addr_size(struct sockaddr *addr)
59 {
60 	return addr->sa_family == AF_INET6 ?
61 	    sizeof (struct sockaddr_in6) :
62 	    sizeof (struct sockaddr_in);
63 }
64 
ib_addr_get_pkey(struct rdma_dev_addr * dev_addr)65 static inline uint16_t ib_addr_get_pkey(struct rdma_dev_addr *dev_addr)
66 {
67 	return (((uint16_t)dev_addr->broadcast[8] << 8) |
68 	    (uint16_t)dev_addr->broadcast[9]);
69 }
70 
ib_addr_set_pkey(struct rdma_dev_addr * dev_addr,uint16_t pkey)71 static inline void ib_addr_set_pkey(struct rdma_dev_addr *dev_addr,
72     uint16_t pkey)
73 {
74 	dev_addr->broadcast[8] = pkey >> 8;
75 	dev_addr->broadcast[9] = (unsigned char) pkey;
76 }
77 
ib_addr_get_mgid(struct rdma_dev_addr * dev_addr,union ib_gid * gid)78 static inline void ib_addr_get_mgid(struct rdma_dev_addr *dev_addr,
79     union ib_gid *gid)
80 {
81 	(void) memcpy(gid, dev_addr->broadcast + 4, sizeof (*gid));
82 }
83 
ib_addr_get_sgid(struct rdma_dev_addr * dev_addr,union ib_gid * gid)84 static inline void ib_addr_get_sgid(struct rdma_dev_addr *dev_addr,
85     union ib_gid *gid)
86 {
87 	(void) memcpy(gid, dev_addr->src_dev_addr + 4, sizeof (*gid));
88 }
89 
ib_addr_set_sgid(struct rdma_dev_addr * dev_addr,union ib_gid * gid)90 static inline void ib_addr_set_sgid(struct rdma_dev_addr *dev_addr,
91     union ib_gid *gid)
92 {
93 	(void) memcpy(dev_addr->src_dev_addr + 4, gid, sizeof (*gid));
94 }
95 
ib_addr_get_dgid(struct rdma_dev_addr * dev_addr,union ib_gid * gid)96 static inline void ib_addr_get_dgid(struct rdma_dev_addr *dev_addr,
97     union ib_gid *gid)
98 {
99 	(void) memcpy(gid, dev_addr->dst_dev_addr + 4, sizeof (*gid));
100 }
101 
ib_addr_set_dgid(struct rdma_dev_addr * dev_addr,union ib_gid * gid)102 static inline void ib_addr_set_dgid(struct rdma_dev_addr *dev_addr,
103     union ib_gid *gid)
104 {
105 	(void) memcpy(dev_addr->dst_dev_addr + 4, gid, sizeof (*gid));
106 }
107 
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 #endif /* _SYS_IB_CLIENTS_OF_RDMA_IB_ADDR_H */
113