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/*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26#ifndef _SYS_IB_CLIENTS_OF_SOL_UVERBS_SOL_UVERBS_HCA_H
27#define	_SYS_IB_CLIENTS_OF_SOL_UVERBS_SOL_UVERBS_HCA_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*
34 *
35 * NAME: sol_uverbs_hca.h
36 *
37 * DESC: Solaris OFED hca management utility.
38 *
39 *	This file implements a very thin layer that provides the OFA user kernel
40 *	agents the ability to operate in the same IBT/HCA domain.  That is all
41 *	of the OFA user space kernel agents share the same IBT client handle,
42 *	opened by the sol_uverbs driver.
43 *
44 */
45
46#include <sys/ib/ibtl/ibvti.h>
47
48/*
49 * Definitions
50 */
51
52/*
53 * Structures
54 */
55
56/*
57 * HCA Info.
58 *
59 * Each IBT HCA the sol_uverbs driver knows about is maintained in a
60 * a list that points to IBT handles and the client event handler
61 * callbacks.
62 */
63typedef struct sol_uverbs_hca {
64	llist_head_t		list;
65	llist_head_t		event_handler_list;
66	kmutex_t		event_handler_lock;
67	llist_head_t		client_data_list;
68	kmutex_t		client_data_lock;
69	ibt_clnt_hdl_t		clnt_hdl;
70	ib_guid_t		guid;
71	ibt_hca_hdl_t		hdl;
72	ibt_hca_attr_t		attr;
73	uint32_t		nports;
74	ibt_hca_portinfo_t	*ports;
75	size_t			pinfosz;
76} sol_uverbs_hca_t;
77
78/*
79 * Client structure passed to Solaris User Verbs to provide addtion and
80 * removal callbacks.  The "add" function will be invoked for each
81 * IBT hca in the system when it is available, the "remove" will be
82 * invoked when an IBT hca is no longer available.
83 */
84typedef struct sol_uverbs_ib_client {
85	llist_head_t	list;
86	char		*name;
87	void		(*add)(sol_uverbs_hca_t *);
88	void		(*remove)(sol_uverbs_hca_t *);
89} sol_uverbs_ib_client_t;
90
91/*
92 * Event handler structure passed to Solaris User Verbs hca management
93 * to register an asynchronous event handler for an IBT hca.
94 */
95typedef struct sol_uverbs_ib_event_handler {
96	llist_head_t		list;
97	sol_uverbs_hca_t	*hca;
98	void			(*handler)(struct sol_uverbs_ib_event_handler *,
99				ibt_hca_hdl_t hca,
100				ibt_async_code_t code,
101				ibt_async_event_t *event);
102} sol_uverbs_ib_event_handler_t;
103
104#define	SOL_UVERBS_INIT_IB_EVENT_HANDLER(_struct_ptr,  _hca_ptr, _func_ptr) \
105	do {							\
106		(_struct_ptr)->hca	= _hca_ptr;		\
107		(_struct_ptr)->handler	= _func_ptr;		\
108		llist_head_init(&(_struct_ptr)->list, 0);	\
109	} while (0)
110
111/*
112 * Control structures for managmenet of common HCA list.
113 */
114extern kmutex_t		sol_uverbs_hca_lock;
115extern llist_head_t	sol_uverbs_hca_list;
116extern llist_head_t	sol_uverbs_client_list;
117
118/*
119 * Functions
120 */
121/*
122 * sol_uverbs HCA list management and helper sol_uverbs nternal functions.
123 */
124int  sol_uverbs_common_hca_init();
125void sol_uverbs_common_hca_fini();
126sol_uverbs_hca_t *sol_uverbs_ibt_hdl_to_hca(ibt_hca_hdl_t hdl);
127
128/*
129 * COMMON HCA CLIENT API - See sol_uverbs_hca.c for complete
130 * function description.
131 */
132
133/*
134 * Register for client notifications.  The "add" function pointer
135 * in the client structure will be invoked for each hca in the system, the
136 * "remove" function pointer will be invoked as hca's are no longer
137 * available.
138 */
139int  sol_uverbs_ib_register_client(sol_uverbs_ib_client_t *client);
140
141/*
142 * Unregister for client notifications.
143 */
144void sol_uverbs_ib_unregister_client(sol_uverbs_ib_client_t *client);
145
146/*
147 * Mechanism for client to associate private data with each IBT hca.
148 */
149void *sol_uverbs_ib_get_client_data(sol_uverbs_hca_t *hca,
150					sol_uverbs_ib_client_t *client);
151
152void sol_uverbs_ib_set_client_data(sol_uverbs_hca_t *hca,
153	sol_uverbs_ib_client_t *client, void *data);
154
155/*
156 * Mechanism for client to register/unregister for asynchronous event callbacks.
157 */
158int
159sol_uverbs_ib_register_event_handler(sol_uverbs_ib_event_handler_t *handler);
160
161int
162sol_uverbs_ib_unregister_event_handler(sol_uverbs_ib_event_handler_t *handler);
163
164/*
165 * HELPER API provided by sol_uverbs, see sol_uverbs_qp.c for complete
166 * descriptions.
167 */
168
169/*
170 * Map a user QP id to an IBT QP Handle.
171 */
172ibt_qp_hdl_t sol_uverbs_uqpid_to_ibt_handle(uint32_t u_qpid);
173
174/*
175 * Inform sol_uverbs to igonore requested modify QP calls for the
176 * specific QP.
177 */
178int sol_uverbs_disable_user_qp_modify(uint32_t u_qpid);
179int sol_uverbs_enable_user_qp_modify(uint32_t u_qpid);
180
181#ifdef __cplusplus
182}
183#endif
184#endif /* _SYS_IB_CLIENTS_OF_SOL_UVERBS_SOL_UVERBS_HCA_H */
185