xref: /illumos-gate/usr/src/uts/common/sys/ib/mgt/ibcm/ibcm_arp.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_IB_MGT_IBCM_IBCM_ARP_H
27 #define	_SYS_IB_MGT_IBCM_IBCM_ARP_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/ib/mgt/ibcm/ibcm_impl.h>
34 #include <sys/modhash.h>
35 #include <sys/ib/clients/ibd/ibd.h>
36 #include <sys/strsun.h>
37 #include <sys/socket.h>
38 #include <sys/stat.h>	/* for S_IFCHR */
39 #include <inet/ip2mac.h>
40 #include <inet/ip6.h>
41 
42 /*
43  * IPoIB addr lookup completion function
44  */
45 typedef int (*ibcm_arp_pr_comp_func_t) (void *usr_arg, int status);
46 
47 #define	IBCM_ARP_MAX_IFNAME_LEN		24
48 #define	IBCM_ARP_XMIT_COUNT		6
49 #define	IBCM_ARP_XMIT_INTERVAL		1000	/* timeout in milliseconds */
50 #define	IBCM_ARP_TIMEOUT \
51 		((IBCM_ARP_XMIT_COUNT + 1) * IBCM_ARP_XMIT_INTERVAL)
52 
53 #define	IBCM_H2N_GID(gid) \
54 { \
55 	uint32_t	*ptr; \
56 	ptr = (uint32_t *)&gid.gid_prefix; \
57 	gid.gid_prefix = (uint64_t)(((uint64_t)ntohl(ptr[0]) << 32) | \
58 			(ntohl(ptr[1]))); \
59 	ptr = (uint32_t *)&gid.gid_guid; \
60 	gid.gid_guid = (uint64_t)(((uint64_t)ntohl(ptr[0]) << 32) | \
61 			(ntohl(ptr[1]))); \
62 }
63 
64 #define	IBCM_ARP_PR_RT_PENDING		0x01
65 #define	IBCM_ARP_PR_RESOLVE_PENDING	0x02
66 
67 /*
68  * Path record wait queue node definition
69  */
70 typedef struct ibcm_arp_prwqn {
71 	ibcm_arp_pr_comp_func_t	func;	/* user callback function */
72 	void			*arg;	/* callback function arg */
73 	timeout_id_t		timeout_id;
74 	uint8_t			flags;
75 	ibt_ip_addr_t		usrc_addr;	/* user supplied src address */
76 	ibt_ip_addr_t		dst_addr;	/* user supplied dest address */
77 	ibt_ip_addr_t		src_addr;	/* rts's view of src address */
78 	ibt_ip_addr_t		gateway;	/* rts returned gateway addr */
79 	ibt_ip_addr_t		netmask;	/* rts returned netmask */
80 	char			ifname[IBCM_ARP_MAX_IFNAME_LEN];
81 	uint16_t		ifproto;
82 	ipoib_mac_t		src_mac;
83 	ipoib_mac_t		dst_mac;
84 	ib_gid_t		sgid;
85 	ib_gid_t		dgid;
86 	ip2mac_id_t		ip2mac_id;
87 } ibcm_arp_prwqn_t;
88 
89 typedef struct ibcm_arp_streams_s {
90 	kmutex_t		lock;
91 	kcondvar_t		cv;
92 	queue_t			*arpqueue;
93 	vnode_t			*arp_vp;
94 	int			status;
95 	boolean_t		done;
96 	ibcm_arp_prwqn_t	*wqnp;
97 } ibcm_arp_streams_t;
98 
99 /* GID to IP-Addr and Ip-Addr to GID look-up functions. */
100 
101 #define	IBCM_ARP_IBD_INSTANCES		4
102 
103 typedef struct ibcm_arp_ip_s {
104 	uint8_t		ip_inst;
105 	ib_pkey_t	ip_pkey;
106 	ib_guid_t	ip_hca_guid;
107 	ib_gid_t	ip_port_gid;
108 	sa_family_t	ip_inet_family;
109 	union {
110 		struct sockaddr_in	ip_sockaddr;
111 		struct sockaddr_in6	ip_sockaddr6;
112 	} ip_sin;
113 #define	ip_cm_sin		ip_sin.ip_sockaddr
114 #define	ip_cm_sin6		ip_sin.ip_sockaddr6
115 } ibcm_arp_ip_t;
116 
117 typedef struct ibcm_arp_ibd_insts_s {
118 	uint8_t		ibcm_arp_ibd_alloc;
119 	uint8_t		ibcm_arp_ibd_cnt;
120 	ibcm_arp_ip_t	*ibcm_arp_ip;
121 } ibcm_arp_ibd_insts_t;
122 
123 ibt_status_t ibcm_arp_get_ibaddr(ibt_ip_addr_t srcip, ibt_ip_addr_t destip,
124     ib_gid_t *sgid, ib_gid_t *dgid);
125 ibt_status_t ibcm_arp_get_srcip_plist(ibt_ip_path_attr_t *attr,
126     ibt_path_flags_t flags, ibtl_cm_port_list_t **list_p);
127 ibt_status_t ibcm_arp_get_ibds(ibcm_arp_ibd_insts_t *ibdp, sa_family_t fam);
128 
129 #ifdef	__cplusplus
130 }
131 #endif
132 
133 #endif /* _SYS_IB_MGT_IBCM_IBCM_ARP_H */
134