1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/*
37219820Sjeff * Abstract:
38219820Sjeff * 	Declaration of osm_sa_t.
39219820Sjeff *	This object represents an IBA subnet.
40219820Sjeff *	This object is part of the OpenSM family of objects.
41219820Sjeff */
42219820Sjeff
43219820Sjeff#ifndef _OSM_SA_H_
44219820Sjeff#define _OSM_SA_H_
45219820Sjeff
46219820Sjeff#include <iba/ib_types.h>
47219820Sjeff#include <complib/cl_passivelock.h>
48219820Sjeff#include <complib/cl_event.h>
49219820Sjeff#include <complib/cl_thread.h>
50219820Sjeff#include <complib/cl_timer.h>
51219820Sjeff#include <complib/cl_dispatcher.h>
52219820Sjeff#include <opensm/osm_stats.h>
53219820Sjeff#include <opensm/osm_subnet.h>
54219820Sjeff#include <vendor/osm_vendor_api.h>
55219820Sjeff#include <opensm/osm_mad_pool.h>
56219820Sjeff#include <opensm/osm_log.h>
57219820Sjeff#include <opensm/osm_sa_mad_ctrl.h>
58219820Sjeff#include <opensm/osm_sm.h>
59219820Sjeff#include <opensm/osm_multicast.h>
60219820Sjeff
61219820Sjeff#ifdef __cplusplus
62219820Sjeff#  define BEGIN_C_DECLS extern "C" {
63219820Sjeff#  define END_C_DECLS   }
64219820Sjeff#else				/* !__cplusplus */
65219820Sjeff#  define BEGIN_C_DECLS
66219820Sjeff#  define END_C_DECLS
67219820Sjeff#endif				/* __cplusplus */
68219820Sjeff
69219820SjeffBEGIN_C_DECLS
70219820Sjeff/****h* OpenSM/SA
71219820Sjeff* NAME
72219820Sjeff*	SA
73219820Sjeff*
74219820Sjeff* DESCRIPTION
75219820Sjeff*	The SA object encapsulates the information needed by the
76219820Sjeff*	OpenSM to instantiate a subnet administrator.  The OpenSM allocates
77219820Sjeff*	one SA object per subnet manager.
78219820Sjeff*
79219820Sjeff*	The SA object is thread safe.
80219820Sjeff*
81219820Sjeff*	This object should be treated as opaque and should
82219820Sjeff*	be manipulated only through the provided functions.
83219820Sjeff*
84219820Sjeff* AUTHOR
85219820Sjeff*	Ranjit Pandit, Intel
86219820Sjeff*	Anil Keshavamurthy, Intel
87219820Sjeff*
88219820Sjeff*********/
89219820Sjeff/****d* OpenSM: SA/osm_sa_state_t
90219820Sjeff* NAME
91219820Sjeff*	osm_sa_state_t
92219820Sjeff*
93219820Sjeff* DESCRIPTION
94219820Sjeff*	Enumerates the possible states of SA object.
95219820Sjeff*
96219820Sjeff* SYNOPSIS
97219820Sjeff*/
98219820Sjefftypedef enum _osm_sa_state {
99219820Sjeff	OSM_SA_STATE_INIT = 0,
100219820Sjeff	OSM_SA_STATE_READY
101219820Sjeff} osm_sa_state_t;
102219820Sjeff/***********/
103219820Sjeff
104219820Sjeff/****s* OpenSM: SM/osm_sa_t
105219820Sjeff* NAME
106219820Sjeff*	osm_sa_t
107219820Sjeff*
108219820Sjeff* DESCRIPTION
109219820Sjeff*	Subnet Administration structure.
110219820Sjeff*
111219820Sjeff*	This object should be treated as opaque and should
112219820Sjeff*	be manipulated only through the provided functions.
113219820Sjeff*
114219820Sjeff* SYNOPSIS
115219820Sjeff*/
116219820Sjefftypedef struct osm_sa {
117219820Sjeff	osm_sa_state_t state;
118219820Sjeff	osm_sm_t *sm;
119219820Sjeff	osm_subn_t *p_subn;
120219820Sjeff	osm_vendor_t *p_vendor;
121219820Sjeff	osm_log_t *p_log;
122219820Sjeff	osm_mad_pool_t *p_mad_pool;
123219820Sjeff	cl_dispatcher_t *p_disp;
124219820Sjeff	cl_plock_t *p_lock;
125219820Sjeff	atomic32_t sa_trans_id;
126219820Sjeff	osm_sa_mad_ctrl_t mad_ctrl;
127219820Sjeff	cl_timer_t sr_timer;
128219820Sjeff	cl_disp_reg_handle_t cpi_disp_h;
129219820Sjeff	cl_disp_reg_handle_t nr_disp_h;
130219820Sjeff	cl_disp_reg_handle_t pir_disp_h;
131219820Sjeff	cl_disp_reg_handle_t gir_disp_h;
132219820Sjeff	cl_disp_reg_handle_t lr_disp_h;
133219820Sjeff	cl_disp_reg_handle_t pr_disp_h;
134219820Sjeff	cl_disp_reg_handle_t smir_disp_h;
135219820Sjeff	cl_disp_reg_handle_t mcmr_disp_h;
136219820Sjeff	cl_disp_reg_handle_t sr_disp_h;
137219820Sjeff#if defined (VENDOR_RMPP_SUPPORT) && defined (DUAL_SIDED_RMPP)
138219820Sjeff	cl_disp_reg_handle_t mpr_disp_h;
139219820Sjeff#endif
140219820Sjeff	cl_disp_reg_handle_t infr_disp_h;
141219820Sjeff	cl_disp_reg_handle_t infir_disp_h;
142219820Sjeff	cl_disp_reg_handle_t vlarb_disp_h;
143219820Sjeff	cl_disp_reg_handle_t slvl_disp_h;
144219820Sjeff	cl_disp_reg_handle_t pkey_disp_h;
145219820Sjeff	cl_disp_reg_handle_t lft_disp_h;
146219820Sjeff	cl_disp_reg_handle_t sir_disp_h;
147219820Sjeff	cl_disp_reg_handle_t mft_disp_h;
148219820Sjeff} osm_sa_t;
149219820Sjeff/*
150219820Sjeff* FIELDS
151219820Sjeff*	state
152219820Sjeff*		State of this SA object
153219820Sjeff*
154219820Sjeff*	sm
155219820Sjeff*		Pointer to the Subnet Manager object.
156219820Sjeff*
157219820Sjeff*	p_subn
158219820Sjeff*		Pointer to the Subnet object for this subnet.
159219820Sjeff*
160219820Sjeff*	p_vendor
161219820Sjeff*		Pointer to the vendor specific interfaces object.
162219820Sjeff*
163219820Sjeff*	p_log
164219820Sjeff*		Pointer to the log object.
165219820Sjeff*
166219820Sjeff*	p_mad_pool
167219820Sjeff*		Pointer to the MAD pool.
168219820Sjeff*
169219820Sjeff*	p_disp
170219820Sjeff*		Pointer to dispatcher
171219820Sjeff*
172219820Sjeff*	p_lock
173219820Sjeff*		Pointer to Lock for serialization
174219820Sjeff*
175219820Sjeff*	sa_trans_id
176219820Sjeff*		Transaction ID
177219820Sjeff*
178219820Sjeff*	mad_ctrl
179219820Sjeff*		Mad Controller
180219820Sjeff*
181219820Sjeff* SEE ALSO
182219820Sjeff*	SM object
183219820Sjeff*********/
184219820Sjeff
185219820Sjeff/****f* OpenSM: SA/osm_sa_construct
186219820Sjeff* NAME
187219820Sjeff*	osm_sa_construct
188219820Sjeff*
189219820Sjeff* DESCRIPTION
190219820Sjeff*	This function constructs an SA object.
191219820Sjeff*
192219820Sjeff* SYNOPSIS
193219820Sjeff*/
194219820Sjeffvoid osm_sa_construct(IN osm_sa_t * const p_sa);
195219820Sjeff/*
196219820Sjeff* PARAMETERS
197219820Sjeff*	p_sa
198219820Sjeff*		[in] Pointer to a SA object to construct.
199219820Sjeff*
200219820Sjeff* RETURN VALUE
201219820Sjeff*	This function does not return a value.
202219820Sjeff*
203219820Sjeff* NOTES
204219820Sjeff*	Allows calling osm_sa_destroy.
205219820Sjeff*
206219820Sjeff*	Calling osm_sa_construct is a prerequisite to calling any other
207219820Sjeff*	method except osm_sa_init.
208219820Sjeff*
209219820Sjeff* SEE ALSO
210219820Sjeff*	SA object, osm_sa_init, osm_sa_destroy
211219820Sjeff*********/
212219820Sjeff
213219820Sjeff/****f* OpenSM: SA/osm_sa_shutdown
214219820Sjeff* NAME
215219820Sjeff*	osm_sa_shutdown
216219820Sjeff*
217219820Sjeff* DESCRIPTION
218219820Sjeff*	The osm_sa_shutdown function shutdowns an SA, unregistering from all
219219820Sjeff*  dispatcher messages and unbinding the QP1 mad service
220219820Sjeff*
221219820Sjeff* SYNOPSIS
222219820Sjeff*/
223219820Sjeffvoid osm_sa_shutdown(IN osm_sa_t * const p_sa);
224219820Sjeff/*
225219820Sjeff* PARAMETERS
226219820Sjeff*	p_sa
227219820Sjeff*		[in] Pointer to a SA object to shutdown.
228219820Sjeff*
229219820Sjeff* RETURN VALUE
230219820Sjeff*	This function does not return a value.
231219820Sjeff*
232219820Sjeff* SEE ALSO
233219820Sjeff*	SA object, osm_sa_construct, osm_sa_init
234219820Sjeff*********/
235219820Sjeff
236219820Sjeff/****f* OpenSM: SA/osm_sa_destroy
237219820Sjeff* NAME
238219820Sjeff*	osm_sa_destroy
239219820Sjeff*
240219820Sjeff* DESCRIPTION
241219820Sjeff*	The osm_sa_destroy function destroys an SA, releasing
242219820Sjeff*	all resources.
243219820Sjeff*
244219820Sjeff* SYNOPSIS
245219820Sjeff*/
246219820Sjeffvoid osm_sa_destroy(IN osm_sa_t * const p_sa);
247219820Sjeff/*
248219820Sjeff* PARAMETERS
249219820Sjeff*	p_sa
250219820Sjeff*		[in] Pointer to a SA object to destroy.
251219820Sjeff*
252219820Sjeff* RETURN VALUE
253219820Sjeff*	This function does not return a value.
254219820Sjeff*
255219820Sjeff* NOTES
256219820Sjeff*	Performs any necessary cleanup of the specified SA object.
257219820Sjeff*	Further operations should not be attempted on the destroyed object.
258219820Sjeff*	This function should only be called after a call to osm_sa_construct or
259219820Sjeff*	osm_sa_init.
260219820Sjeff*
261219820Sjeff* SEE ALSO
262219820Sjeff*	SA object, osm_sa_construct, osm_sa_init
263219820Sjeff*********/
264219820Sjeff
265219820Sjeff/****f* OpenSM: SA/osm_sa_init
266219820Sjeff* NAME
267219820Sjeff*	osm_sa_init
268219820Sjeff*
269219820Sjeff* DESCRIPTION
270219820Sjeff*	The osm_sa_init function initializes a SA object for use.
271219820Sjeff*
272219820Sjeff* SYNOPSIS
273219820Sjeff*/
274219820Sjeffib_api_status_t osm_sa_init(IN osm_sm_t * const p_sm,
275219820Sjeff			    IN osm_sa_t * const p_sa,
276219820Sjeff			    IN osm_subn_t * const p_subn,
277219820Sjeff			    IN osm_vendor_t * const p_vendor,
278219820Sjeff			    IN osm_mad_pool_t * const p_mad_pool,
279219820Sjeff			    IN osm_log_t * const p_log,
280219820Sjeff			    IN osm_stats_t * const p_stats,
281219820Sjeff			    IN cl_dispatcher_t * const p_disp,
282219820Sjeff			    IN cl_plock_t * const p_lock);
283219820Sjeff/*
284219820Sjeff* PARAMETERS
285219820Sjeff*	p_sa
286219820Sjeff*		[in] Pointer to an osm_sa_t object to initialize.
287219820Sjeff*
288219820Sjeff*	p_subn
289219820Sjeff*		[in] Pointer to the Subnet object for this subnet.
290219820Sjeff*
291219820Sjeff*	p_vendor
292219820Sjeff*		[in] Pointer to the vendor specific interfaces object.
293219820Sjeff*
294219820Sjeff*	p_mad_pool
295219820Sjeff*		[in] Pointer to the MAD pool.
296219820Sjeff*
297219820Sjeff*	p_log
298219820Sjeff*		[in] Pointer to the log object.
299219820Sjeff*
300219820Sjeff*	p_stats
301219820Sjeff*		[in] Pointer to the statistics object.
302219820Sjeff*
303219820Sjeff*	p_disp
304219820Sjeff*		[in] Pointer to the OpenSM central Dispatcher.
305219820Sjeff*
306219820Sjeff*	p_lock
307219820Sjeff*		[in] Pointer to the OpenSM serializing lock.
308219820Sjeff*
309219820Sjeff* RETURN VALUES
310219820Sjeff*	CL_SUCCESS if the SA object was initialized successfully.
311219820Sjeff*
312219820Sjeff* NOTES
313219820Sjeff*	Allows calling other SA methods.
314219820Sjeff*
315219820Sjeff* SEE ALSO
316219820Sjeff*	SA object, osm_sa_construct, osm_sa_destroy
317219820Sjeff*********/
318219820Sjeff
319219820Sjeff/****f* OpenSM: SA/osm_sa_bind
320219820Sjeff* NAME
321219820Sjeff*	osm_sa_bind
322219820Sjeff*
323219820Sjeff* DESCRIPTION
324219820Sjeff*	Binds the SA object to a port guid.
325219820Sjeff*
326219820Sjeff* SYNOPSIS
327219820Sjeff*/
328219820Sjeffib_api_status_t
329219820Sjeffosm_sa_bind(IN osm_sa_t * const p_sa, IN const ib_net64_t port_guid);
330219820Sjeff/*
331219820Sjeff* PARAMETERS
332219820Sjeff*	p_sa
333219820Sjeff*		[in] Pointer to an osm_sa_t object to bind.
334219820Sjeff*
335219820Sjeff*	port_guid
336219820Sjeff*		[in] Local port GUID with which to bind.
337219820Sjeff*
338219820Sjeff*
339219820Sjeff* RETURN VALUES
340219820Sjeff*	None
341219820Sjeff*
342219820Sjeff* NOTES
343219820Sjeff*	A given SA object can only be bound to one port at a time.
344219820Sjeff*
345219820Sjeff* SEE ALSO
346219820Sjeff*********/
347219820Sjeff
348219820Sjeff/****f* OpenSM: SA/osm_sa_send
349219820Sjeff* NAME
350219820Sjeff*	osm_sa_send
351219820Sjeff*
352219820Sjeff* DESCRIPTION
353219820Sjeff*	Sends SA MAD via osm_vendor_send and maintains the QP1 sent statistic
354219820Sjeff*
355219820Sjeff* SYNOPSIS
356219820Sjeff*/
357219820Sjeffib_api_status_t osm_sa_send(osm_sa_t *sa, IN osm_madw_t * const p_madw,
358219820Sjeff			    IN boolean_t const resp_expected);
359219820Sjeff
360219820Sjeff/****f* IBA Base: Types/osm_sa_send_error
361219820Sjeff* NAME
362219820Sjeff*	osm_sa_send_error
363219820Sjeff*
364219820Sjeff* DESCRIPTION
365219820Sjeff*	Sends a generic SA response with the specified error status.
366219820Sjeff*	The payload is simply replicated from the request MAD.
367219820Sjeff*
368219820Sjeff* SYNOPSIS
369219820Sjeff*/
370219820Sjeffvoid osm_sa_send_error(IN osm_sa_t * sa, IN const osm_madw_t * const p_madw,
371219820Sjeff		       IN const ib_net16_t sa_status);
372219820Sjeff/*
373219820Sjeff* PARAMETERS
374219820Sjeff*	sa
375219820Sjeff*		[in] Pointer to an osm_sa_t object.
376219820Sjeff*
377219820Sjeff*	p_madw
378219820Sjeff*		[in] Original MAD to which the response must be sent.
379219820Sjeff*
380219820Sjeff*	sa_status
381219820Sjeff*		[in] Status to send in the response.
382219820Sjeff*
383219820Sjeff* RETURN VALUES
384219820Sjeff*	None.
385219820Sjeff*
386219820Sjeff* SEE ALSO
387219820Sjeff*	SA object
388219820Sjeff*********/
389219820Sjeff
390219820Sjeff/****f* OpenSM: SA/osm_sa_respond
391219820Sjeff* NAME
392219820Sjeff*	osm_sa_respond
393219820Sjeff*
394219820Sjeff* DESCRIPTION
395219820Sjeff*	Sends SA MAD response
396219820Sjeff*/
397219820Sjeffvoid osm_sa_respond(osm_sa_t *sa, osm_madw_t *madw, size_t attr_size,
398219820Sjeff		    cl_qlist_t *list);
399219820Sjeff/*
400219820Sjeff* PARAMETERS
401219820Sjeff*	sa
402219820Sjeff*		[in] Pointer to an osm_sa_t object.
403219820Sjeff*
404219820Sjeff*	p_madw
405219820Sjeff*		[in] Original MAD to which the response must be sent.
406219820Sjeff*
407219820Sjeff*	attr_size
408219820Sjeff*		[in] Size of this SA attribute.
409219820Sjeff*
410219820Sjeff*	list
411219820Sjeff*		[in] List of attribute to respond - it will be freed after
412219820Sjeff*		sending.
413219820Sjeff*
414219820Sjeff* RETURN VALUES
415219820Sjeff*	None.
416219820Sjeff*
417219820Sjeff* SEE ALSO
418219820Sjeff*	SA object
419219820Sjeff*********/
420219820Sjeff
421219820Sjeffstruct osm_opensm;
422219820Sjeff/****f* OpenSM: SA/osm_sa_db_file_dump
423219820Sjeff* NAME
424219820Sjeff*	osm_sa_db_file_dump
425219820Sjeff*
426219820Sjeff* DESCRIPTION
427219820Sjeff*	Dumps the SA DB to the dump file.
428219820Sjeff*
429219820Sjeff* SYNOPSIS
430219820Sjeff*/
431219820Sjeffint osm_sa_db_file_dump(struct osm_opensm *p_osm);
432219820Sjeff/*
433219820Sjeff* PARAMETERS
434219820Sjeff*	p_osm
435219820Sjeff*		[in] Pointer to an osm_opensm_t object.
436219820Sjeff*
437219820Sjeff* RETURN VALUES
438219820Sjeff*	None
439219820Sjeff*
440219820Sjeff*********/
441219820Sjeff
442219820Sjeff/****f* OpenSM: SA/osm_sa_db_file_load
443219820Sjeff* NAME
444219820Sjeff*	osm_sa_db_file_load
445219820Sjeff*
446219820Sjeff* DESCRIPTION
447219820Sjeff*	Loads SA DB from the file.
448219820Sjeff*
449219820Sjeff* SYNOPSIS
450219820Sjeff*/
451219820Sjeffint osm_sa_db_file_load(struct osm_opensm *p_osm);
452219820Sjeff/*
453219820Sjeff* PARAMETERS
454219820Sjeff*	p_osm
455219820Sjeff*		[in] Pointer to an osm_opensm_t object.
456219820Sjeff*
457219820Sjeff* RETURN VALUES
458219820Sjeff*	0 on success, other value on failure.
459219820Sjeff*
460219820Sjeff*********/
461219820Sjeff
462219820Sjeff/****f* OpenSM: MC Member Record Receiver/osm_mcmr_rcv_find_or_create_new_mgrp
463219820Sjeff* NAME
464219820Sjeff*	osm_mcmr_rcv_find_or_create_new_mgrp
465219820Sjeff*
466219820Sjeff* DESCRIPTION
467219820Sjeff*	Create new Multicast group
468219820Sjeff*
469219820Sjeff* SYNOPSIS
470219820Sjeff*/
471219820Sjeff
472219820Sjeffib_api_status_t
473219820Sjeffosm_mcmr_rcv_find_or_create_new_mgrp(IN osm_sa_t * sa,
474219820Sjeff				     IN uint64_t comp_mask,
475219820Sjeff				     IN ib_member_rec_t *
476219820Sjeff				     const p_recvd_mcmember_rec,
477219820Sjeff				     OUT osm_mgrp_t ** pp_mgrp);
478219820Sjeff/*
479219820Sjeff* PARAMETERS
480219820Sjeff*	p_sa
481219820Sjeff*		[in] Pointer to an osm_sa_t object.
482219820Sjeff*	p_recvd_mcmember_rec
483219820Sjeff*		[in] Received Multicast member record
484219820Sjeff*
485219820Sjeff*	pp_mgrp
486219820Sjeff*		[out] pointer the osm_mgrp_t object
487219820Sjeff*
488219820Sjeff* RETURN VALUES
489219820Sjeff*	IB_SUCCESS, IB_ERROR
490219820Sjeff*
491219820Sjeff*********/
492219820Sjeff
493219820Sjeffosm_mgrp_t *osm_get_mgrp_by_mgid(IN osm_sa_t * sa, IN ib_gid_t * p_mgid);
494219820Sjeff
495219820SjeffEND_C_DECLS
496219820Sjeff#endif				/* _OSM_SA_H_ */
497