1/*
2 * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5 * Copyright (c) 2009-2011 ZIH, TU Dresden, Federal Republic of Germany. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses.  You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
12 *
13 *     Redistribution and use in source and binary forms, with or
14 *     without modification, are permitted provided that the following
15 *     conditions are met:
16 *
17 *      - Redistributions of source code must retain the above
18 *        copyright notice, this list of conditions and the following
19 *        disclaimer.
20 *
21 *      - Redistributions in binary form must reproduce the above
22 *        copyright notice, this list of conditions and the following
23 *        disclaimer in the documentation and/or other materials
24 *        provided with the distribution.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * SOFTWARE.
34 *
35 */
36
37/*
38 * Abstract:
39 * 	Declaration of osm_opensm_t.
40 *	This object represents the OpenSM super object.
41 *	This object is part of the OpenSM family of objects.
42 */
43
44#ifndef _OSM_OPENSM_H_
45#define _OSM_OPENSM_H_
46
47#include <stdio.h>
48#include <complib/cl_qlist.h>
49#include <complib/cl_dispatcher.h>
50#include <complib/cl_passivelock.h>
51#include <complib/cl_atomic.h>
52#include <complib/cl_nodenamemap.h>
53#include <opensm/osm_console_io.h>
54#include <opensm/osm_stats.h>
55#include <opensm/osm_log.h>
56#include <opensm/osm_sm.h>
57#include <opensm/osm_sa.h>
58#include <opensm/osm_perfmgr.h>
59#include <opensm/osm_event_plugin.h>
60#include <opensm/osm_db.h>
61#include <opensm/osm_subnet.h>
62#include <opensm/osm_mad_pool.h>
63#include <opensm/osm_vl15intf.h>
64#include <opensm/osm_congestion_control.h>
65
66#ifdef __cplusplus
67#  define BEGIN_C_DECLS extern "C" {
68#  define END_C_DECLS   }
69#else				/* !__cplusplus */
70#  define BEGIN_C_DECLS
71#  define END_C_DECLS
72#endif				/* __cplusplus */
73
74BEGIN_C_DECLS
75/****h* OpenSM/OpenSM
76* NAME
77*	OpenSM
78*
79* DESCRIPTION
80*	The OpenSM object encapsulates the information needed by the
81*	OpenSM to govern itself.  The OpenSM is one OpenSM object.
82*
83*	The OpenSM object is thread safe.
84*
85*	This object should be treated as opaque and should
86*	be manipulated only through the provided functions.
87*
88* AUTHOR
89*	Steve King, Intel
90*
91*********/
92/****d* OpenSM: OpenSM/osm_routing_engine_type_t
93* NAME
94*       osm_routing_engine_type_t
95*
96* DESCRIPTION
97*       Enumerates the possible routing engines that
98*       could be used to route a subnet.
99*
100* SYNOPSIS
101*/
102typedef enum _osm_routing_engine_type {
103	OSM_ROUTING_ENGINE_TYPE_NONE = 0,
104	OSM_ROUTING_ENGINE_TYPE_MINHOP,
105	OSM_ROUTING_ENGINE_TYPE_UPDN,
106	OSM_ROUTING_ENGINE_TYPE_DNUP,
107	OSM_ROUTING_ENGINE_TYPE_FILE,
108	OSM_ROUTING_ENGINE_TYPE_FTREE,
109	OSM_ROUTING_ENGINE_TYPE_LASH,
110	OSM_ROUTING_ENGINE_TYPE_DOR,
111	OSM_ROUTING_ENGINE_TYPE_TORUS_2QOS,
112	OSM_ROUTING_ENGINE_TYPE_SSSP,
113	OSM_ROUTING_ENGINE_TYPE_DFSSSP,
114	OSM_ROUTING_ENGINE_TYPE_UNKNOWN
115} osm_routing_engine_type_t;
116/***********/
117
118/****s* OpenSM: OpenSM/osm_routing_engine
119* NAME
120*	struct osm_routing_engine
121*
122* DESCRIPTION
123*	OpenSM routing engine module definition.
124* NOTES
125*	routing engine structure - multicast callbacks may be
126*	added later.
127*/
128struct osm_routing_engine {
129	osm_routing_engine_type_t type;
130	const char *name;
131	void *context;
132	int (*build_lid_matrices) (void *context);
133	int (*ucast_build_fwd_tables) (void *context);
134	void (*ucast_dump_tables) (void *context);
135	void (*update_sl2vl)(void *context, IN osm_physp_t *port,
136			     IN uint8_t in_port_num, IN uint8_t out_port_num,
137			     IN OUT ib_slvl_table_t *t);
138	void (*update_vlarb)(void *context, IN osm_physp_t *port,
139			     IN uint8_t port_num,
140			     IN OUT ib_vl_arb_table_t *block,
141			     unsigned block_length, unsigned block_num);
142	uint8_t (*path_sl)(void *context, IN uint8_t path_sl_hint,
143			   IN const ib_net16_t slid, IN const ib_net16_t dlid);
144	ib_api_status_t (*mcast_build_stree)(void *context,
145					     IN OUT osm_mgrp_box_t *mgb);
146	void (*destroy) (void *context);
147	struct osm_routing_engine *next;
148};
149/*
150* FIELDS
151*	name
152*		The routing engine name (will be used in logs).
153*
154*	context
155*		The routing engine context. Will be passed as parameter
156*		to the callback functions.
157*
158*	build_lid_matrices
159*		The callback for lid matrices generation.
160*
161*	ucast_build_fwd_tables
162*		The callback for unicast forwarding table generation.
163*
164*	ucast_dump_tables
165*		The callback for dumping unicast routing tables.
166*
167*	update_sl2vl(void *context, IN osm_physp_t *port,
168*		     IN uint8_t in_port_num, IN uint8_t out_port_num,
169*		     OUT ib_slvl_table_t *t)
170*		The callback to allow routing engine input for SL2VL maps.
171*		*port is the physical port for which the SL2VL map is to be
172*		updated. For switches, in_port_num/out_port_num identify
173*		which part of the SL2VL map to update.  For router/HCA ports,
174*		in_port_num/out_port_num should be ignored.
175*
176*	update_vlarb(void *context, IN osm_physp_t *port,
177*		     IN uint8_t port_num,
178*		     IN OUT ib_vl_arb_table_t *block,
179*		     unsigned block_length, unsigned block_num)
180*		The callback to allow routing engine input for VLArbitration.
181*		*port is the physical port for which the VLArb table is to be
182*		updated.
183*
184*	path_sl
185*		The callback for computing path SL.
186*
187*	mcast_build_stree
188*		The callback for building the spanning tree for multicast
189*		forwarding, called per MLID.
190*
191*	destroy
192*		The destroy method, may be used for routing engine
193*		internals cleanup.
194*
195*	next
196*		Pointer to next routing engine in the list.
197*/
198
199/****s* OpenSM: OpenSM/osm_opensm_t
200* NAME
201*	osm_opensm_t
202*
203* DESCRIPTION
204*	OpenSM structure.
205*
206*	This object should be treated as opaque and should
207*	be manipulated only through the provided functions.
208*
209* SYNOPSIS
210*/
211typedef struct osm_opensm {
212	const char *osm_version;
213	osm_subn_t subn;
214	osm_sm_t sm;
215	osm_sa_t sa;
216#ifdef ENABLE_OSM_PERF_MGR
217	osm_perfmgr_t perfmgr;
218#endif				/* ENABLE_OSM_PERF_MGR */
219	osm_congestion_control_t cc;
220	cl_qlist_t plugin_list;
221	osm_db_t db;
222	boolean_t mad_pool_constructed;
223	osm_mad_pool_t mad_pool;
224	osm_vendor_t *p_vendor;
225	boolean_t vl15_constructed;
226	osm_vl15_t vl15;
227	osm_log_t log;
228	cl_dispatcher_t disp;
229	cl_dispatcher_t sa_set_disp;
230	boolean_t sa_set_disp_initialized;
231	cl_plock_t lock;
232	struct osm_routing_engine *routing_engine_list;
233	struct osm_routing_engine *routing_engine_used;
234	struct osm_routing_engine *default_routing_engine;
235	boolean_t no_fallback_routing_engine;
236	osm_stats_t stats;
237	osm_console_t console;
238	nn_map_t *node_name_map;
239} osm_opensm_t;
240/*
241* FIELDS
242* 	osm_version
243* 		OpenSM version (as generated in osm_version.h)
244*
245*	subn
246*		Subnet object for this subnet.
247*
248*	sm
249*		The Subnet Manager (SM) object for this subnet.
250*
251*	sa
252*		The Subnet Administration (SA) object for this subnet.
253*
254*	db
255*		Persistant storage of some data required between sessions.
256*
257*	mad_pool
258*		Pool of Management Datagram (MAD) objects.
259*
260*	p_vendor
261*		Pointer to the Vendor specific adapter for various
262*		transport interfaces, such as UMADT, AL, etc.  The
263*		particular interface is set at compile time.
264*
265*	vl15
266*		The VL15 interface.
267*
268*	log
269*		Log facility used by all OpenSM components.
270*
271*	disp
272*		Central dispatcher containing the OpenSM worker threads.
273*
274*	sa_set_disp
275*		Dispatcher for SA Set and Delete requests.
276*
277*	sa_set_disp_initialized.
278*		Indicator that sa_set_disp dispatcher was initialized.
279*
280*	lock
281*		Shared lock guarding most OpenSM structures.
282*
283*	routing_engine_list
284*		List of routing engines that should be tried for use.
285*
286*	routing_engine_used
287*		Indicates which routing engine was used to route a subnet.
288*
289*	no_fallback_routing_engine
290*		Indicates if default routing engine should not be used.
291*
292*	stats
293*		Open SM statistics block
294*
295* SEE ALSO
296*********/
297
298/****f* OpenSM: OpenSM/osm_opensm_construct
299* NAME
300*	osm_opensm_construct
301*
302* DESCRIPTION
303*	This function constructs an OpenSM object.
304*
305* SYNOPSIS
306*/
307void osm_opensm_construct(IN osm_opensm_t * p_osm);
308/*
309* PARAMETERS
310*	p_osm
311*		[in] Pointer to a OpenSM object to construct.
312*
313* RETURN VALUE
314*	This function does not return a value.
315*
316* NOTES
317*	Allows calling osm_opensm_init, osm_opensm_destroy
318*
319*	Calling osm_opensm_construct is a prerequisite to calling any other
320*	method except osm_opensm_init.
321*
322* SEE ALSO
323*	SM object, osm_opensm_init, osm_opensm_destroy
324*********/
325
326/****f* OpenSM: OpenSM/osm_opensm_construct_finish
327* NAME
328*	osm_opensm_construct_finish
329*
330* DESCRIPTION
331*	The osm_opensm_construct_finish function completes
332*	the second phase of constucting an OpenSM object.
333*
334* SYNOPSIS
335*/
336void osm_opensm_construct_finish(IN osm_opensm_t * p_osm);
337/*
338* PARAMETERS
339*	p_osm
340*		[in] Pointer to a OpenSM object to construct.
341*
342* RETURN VALUE
343*	This function does not return a value.
344*
345* NOTES
346*	Calling osm_opensm_construct/osm_construct_finish is a prerequisite
347*	to calling any other method except osm_opensm_init/osm_opensm_init_finish.
348*
349* SEE ALSO
350*	SM object, osm_opensm_init, osm_opensm_construct_finish,
351*	osm_opensm_destroy, osm_opensm_destroy_finish
352*********/
353
354/****f* OpenSM: OpenSM/osm_opensm_destroy
355* NAME
356*	osm_opensm_destroy
357*
358* DESCRIPTION
359*	The osm_opensm_destroy function destroys an SM, releasing
360*	all resources.
361*
362* SYNOPSIS
363*/
364void osm_opensm_destroy(IN osm_opensm_t * p_osm);
365/*
366* PARAMETERS
367*	p_osm
368*		[in] Pointer to a OpenSM object to destroy.
369*
370* RETURN VALUE
371*	This function does not return a value.
372*
373* NOTES
374*	Performs any necessary cleanup of the specified OpenSM object.
375*	Further operations should not be attempted on the destroyed object.
376*	This function should only be called after a call to osm_opensm_construct or
377*	osm_opensm_init.
378*
379* SEE ALSO
380*	SM object, osm_opensm_construct, osm_opensm_init
381*********/
382
383/****f* OpenSM: OpenSM/osm_opensm_destroy_finish
384* NAME
385*	osm_opensm_destroy_finish
386*
387* DESCRIPTION
388*	The osm_opensm_destroy_finish function handles the second phase
389*	of destroying an SM, releasing all resources.
390*
391* SYNOPSIS
392*/
393void osm_opensm_destroy_finish(IN osm_opensm_t * p_osm);
394/*
395* PARAMETERS
396*	p_osm
397*		[in] Pointer to a OpenSM object to destroy.
398*
399* RETURN VALUE
400*	This function does not return a value.
401*
402* NOTES
403*	Performs second phase of any necessary cleanup of the specified OpenSM object.
404*	Further operations should not be attempted on the destroyed object.
405*	This function should only be called after a call to
406*	osm_opensm_construct_finish or osm_opensm_init_finish.
407*
408* SEE ALSO
409*	SM object, osm_opensm_construct, osm_opensm_construct_finish,
410*	osm_opensm_init, osm_opensm_init_finish
411*********/
412
413/****f* OpenSM: OpenSM/osm_opensm_init
414* NAME
415*	osm_opensm_init
416*
417* DESCRIPTION
418*	The osm_opensm_init function initializes a OpenSM object for use.
419*
420* SYNOPSIS
421*/
422ib_api_status_t osm_opensm_init(IN osm_opensm_t * p_osm,
423				IN const osm_subn_opt_t * p_opt);
424/*
425* PARAMETERS
426*	p_osm
427*		[in] Pointer to an osm_opensm_t object to initialize.
428*
429*	p_opt
430*		[in] Pointer to the subnet options structure.
431*
432* RETURN VALUES
433*	IB_SUCCESS if the OpenSM object was initialized successfully.
434*
435* NOTES
436*	Allows calling other OpenSM methods.
437*
438* SEE ALSO
439*	SM object, osm_opensm_construct, osm_opensm_destroy
440*********/
441
442/****f* OpenSM: OpenSM/osm_opensm_init_finish
443* NAME
444*	osm_opensm_init_finish
445*
446* DESCRIPTION
447*	The osm_opensm_init_finish function performs the second phase
448*	of initialization of an OpenSM object.
449*
450* SYNOPSIS
451*/
452ib_api_status_t osm_opensm_init_finish(IN osm_opensm_t * p_osm,
453				       IN const osm_subn_opt_t * p_opt);
454/*
455* PARAMETERS
456*	p_osm
457*		[in] Pointer to an osm_opensm_t object to initialize.
458*
459*	p_opt
460*		[in] Pointer to the subnet options structure.
461*
462* RETURN VALUES
463*	IB_SUCCESS if the OpenSM object was initialized successfully.
464*
465* NOTES
466*	Allows calling other OpenSM methods.
467*
468* SEE ALSO
469*	SM object, osm_opensm_construct, osm_opensm_construct_finish,
470*	osm_opensm_destroy, osm_opensm_destroy_finish
471*********/
472
473/****f* OpenSM: OpenSM/osm_opensm_sweep
474* NAME
475*	osm_opensm_sweep
476*
477* DESCRIPTION
478*	Initiates a subnet sweep.
479*
480* SYNOPSIS
481*/
482static inline void osm_opensm_sweep(IN osm_opensm_t * p_osm)
483{
484	osm_sm_sweep(&p_osm->sm);
485}
486
487/*
488* PARAMETERS
489*	p_osm
490*		[in] Pointer to an osm_opensm_t object on which to
491*		initiate a sweep.
492*
493* RETURN VALUES
494*	None
495*
496* NOTES
497*	If the OpenSM object is not bound to a port, this function
498*	does nothing.
499*
500* SEE ALSO
501*********/
502
503/****f* OpenSM: OpenSM/osm_opensm_set_log_flags
504* NAME
505*	osm_opensm_set_log_flags
506*
507* DESCRIPTION
508*	Sets the log level.
509*
510* SYNOPSIS
511*/
512static inline void osm_opensm_set_log_flags(IN osm_opensm_t * p_osm,
513					    IN osm_log_level_t log_flags)
514{
515	osm_log_set_level(&p_osm->log, log_flags);
516}
517
518/*
519* PARAMETERS
520*	p_osm
521*		[in] Pointer to an osm_opensm_t object.
522*
523*	log_flags
524*		[in] Log level flags to set.
525*
526* RETURN VALUES
527*	None
528*
529* NOTES
530*
531* SEE ALSO
532*********/
533
534/****f* OpenSM: OpenSM/osm_opensm_bind
535* NAME
536*	osm_opensm_bind
537*
538* DESCRIPTION
539*	Binds the opensm object to a port guid.
540*
541* SYNOPSIS
542*/
543ib_api_status_t osm_opensm_bind(IN osm_opensm_t * p_osm, IN ib_net64_t guid);
544/*
545* PARAMETERS
546*	p_osm
547*		[in] Pointer to an osm_opensm_t object to bind.
548*
549*	guid
550*		[in] Local port GUID with which to bind.
551*
552* RETURN VALUES
553*	None
554*
555* NOTES
556*	A given opensm object can only be bound to one port at a time.
557*
558* SEE ALSO
559*********/
560
561/****f* OpenSM: OpenSM/osm_opensm_wait_for_subnet_up
562* NAME
563*	osm_opensm_wait_for_subnet_up
564*
565* DESCRIPTION
566*	Blocks the calling thread until the subnet is up.
567*
568* SYNOPSIS
569*/
570static inline cl_status_t
571osm_opensm_wait_for_subnet_up(IN osm_opensm_t * p_osm, IN uint32_t wait_us,
572			      IN boolean_t interruptible)
573{
574	return osm_sm_wait_for_subnet_up(&p_osm->sm, wait_us, interruptible);
575}
576
577/*
578* PARAMETERS
579*	p_osm
580*		[in] Pointer to an osm_opensm_t object.
581*
582*	wait_us
583*		[in] Number of microseconds to wait.
584*
585*	interruptible
586*		[in] Indicates whether the wait operation can be interrupted
587*		by external signals.
588*
589* RETURN VALUES
590*	CL_SUCCESS if the wait operation succeeded in response to the event
591*	being set.
592*
593*	CL_TIMEOUT if the specified time period elapses.
594*
595*	CL_NOT_DONE if the wait was interrupted by an external signal.
596*
597*	CL_ERROR if the wait operation failed.
598*
599* NOTES
600*
601* SEE ALSO
602*********/
603
604/****f* OpenSM: OpenSM/osm_routing_engine_type_str
605* NAME
606*	osm_routing_engine_type_str
607*
608* DESCRIPTION
609*	Returns a string for the specified routing engine type.
610*
611* SYNOPSIS
612*/
613const char *osm_routing_engine_type_str(IN osm_routing_engine_type_t type);
614/*
615* PARAMETERS
616*	type
617*		[in] routing engine type.
618*
619* RETURN VALUES
620*	Pointer to routing engine name.
621*
622* NOTES
623*
624* SEE ALSO
625*********/
626
627/****f* OpenSM: OpenSM/osm_routing_engine_type
628* NAME
629*	osm_routing_engine_type
630*
631* DESCRIPTION
632*	Returns a routing engine type specified routing engine name string.
633*
634* SYNOPSIS
635*/
636osm_routing_engine_type_t osm_routing_engine_type(IN const char *str);
637/*
638* PARAMETERS
639*	str
640*		[in] routing engine name string.
641*
642* RETURN VALUES
643*	Routing engine type.
644*
645* NOTES
646*
647* SEE ALSO
648*********/
649
650void osm_opensm_report_event(osm_opensm_t *osm, osm_epi_event_id_t event_id,
651			     void *event_data);
652
653/* dump helpers */
654void osm_dump_mcast_routes(osm_opensm_t * osm);
655void osm_dump_all(osm_opensm_t * osm);
656void osm_dump_qmap_to_file(osm_opensm_t * p_osm, const char *file_name,
657			   cl_qmap_t * map,
658			   void (*func) (cl_map_item_t *, FILE *, void *),
659			   void *cxt);
660
661/****v* OpenSM/osm_exit_flag
662*/
663extern volatile unsigned int osm_exit_flag;
664/*
665* DESCRIPTION
666*  Set to one to cause all threads to leave
667*********/
668
669END_C_DECLS
670#endif				/* _OSM_OPENSM_H_ */
671