xref: /illumos-gate/usr/src/uts/common/sys/ib/adapters/hermon/hermon_agents.h (revision 9e39c5ba00a55fa05777cc94b148296af305e135)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_IB_ADAPTERS_HERMON_AGENTS_H
28 #define	_SYS_IB_ADAPTERS_HERMON_AGENTS_H
29 
30 /*
31  * hermon_agents.h
32  *    Contains all of the prototypes, #defines, and structures necessary
33  *    for all of the Hermon Infiniband Management Agent (SMA, PMA, BMA)
34  *    routines
35  *    Specifically it contains the various flags, structures used for tracking
36  *    the Hermon agents, and prototypes for initialization and teardown
37  *    functions.
38  */
39 
40 #include <sys/types.h>
41 #include <sys/conf.h>
42 #include <sys/ddi.h>
43 #include <sys/sunddi.h>
44 
45 #include <sys/ib/mgt/ibmf/ibmf.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /*
52  * The following defines specify the default number of (SW-assisted) agents
53  * per port.  It is broken down by QP number.  QP0 will have only the one
54  * agent, the SMA.  QP1 should have two agents, the PMA and BMA, but for now
55  * the Hermon firmware doesn't support a BMA.  So we do not register it with
56  * the IBMF.
57  */
58 #define	HERMON_NUM_QP0_AGENTS_PER_PORT		1
59 #define	HERMON_NUM_QP1_AGENTS_PER_PORT		1
60 
61 /* Number of threads for the agent handling task queue */
62 #define	HERMON_TASKQ_NTHREADS			1
63 
64 /* Maximum number of tasks on task queue */
65 #define	HERMON_TASKQ_MAX_TASKS			4
66 
67 /*
68  * The following defines the name for the task queue.  Note: this string
69  * will later be combined with the Hermon driver instance number to create
70  * a unique name for the task queue
71  */
72 #define	HERMON_TASKQ_NAME			"hermon_taskq"
73 
74 /*
75  * The following macros are used when handling directed route MADs. They tell
76  * the driver whether a given MAD is a directed route MAD, can extract the
77  * "hop pointer" and "hop count" fields, and can even set the "direction" bit
78  * in the MAD and (if necessary) update the "hop pointer".
79  * More details on how these macros are used can be found in the
80  * hermon_agents.c source file.
81  */
82 #define	HERMON_MAD_IS_DR(madhdrp)			\
83 	(((sm_dr_mad_hdr_t *)(madhdrp))->MgmtClass == 0x81)
84 #define	HERMON_DRMAD_GET_HOPCOUNT(madhdrp)		\
85 	(((sm_dr_mad_hdr_t *)(madhdrp))->HopCount)
86 #define	HERMON_DRMAD_GET_HOPPOINTER(madhdrp)		\
87 	(((sm_dr_mad_hdr_t *)(madhdrp))->HopPointer)
88 #define	HERMON_DRMAD_SET_HOPPOINTER(madhdrp, hp)	\
89 	(((sm_dr_mad_hdr_t *)(madhdrp))->HopPointer = (hp))
90 #ifdef	_LITTLE_ENDIAN
91 #define	HERMON_DRMAD_SET_DIRECTION(madhdrp)		\
92 	(((sm_dr_mad_hdr_t *)(madhdrp))->D_Status |= 0x0080)
93 #else
94 #define	HERMON_DRMAD_SET_DIRECTION(madhdrp)		\
95 	(((sm_dr_mad_hdr_t *)(madhdrp))->D_Status |= 0x8000)
96 #endif
97 
98 /*
99  * The following macro is used to determine whether a received MAD is
100  * one of the special "Hermon Trap" MADs.  If it is, then some special
101  * processing (described in hermon_agents.c) is necessary.
102  */
103 #define	HERMON_IS_SPECIAL_TRAP_MAD(msgp)		\
104 	((((msgp)->im_msgbufs_recv.im_bufs_mad_hdr->R_Method &	\
105 	MAD_METHOD_MASK) == MAD_METHOD_TRAP) &&			\
106 	((msgp)->im_local_addr.ia_remote_lid == 0))
107 
108 /*
109  * The following macro is used to determine whether a received MAD is
110  * a "TrapRepress" MAD.  If it is, then no response MAD should be sent
111  * (described in hermon_agents.c).
112  */
113 #define	HERMON_IS_TRAP_REPRESS_MAD(msgp)		\
114 	((((msgp)->im_msgbufs_recv.im_bufs_mad_hdr->R_Method &	\
115 	MAD_METHOD_MASK) == MAD_METHOD_TRAP_REPRESS))
116 
117 /*
118  * The following define specified the offset for the start of "Return Path"
119  * in a directed route MAD.  Note: this is the offset from the start of the
120  * MAD data area (in bytes).
121  */
122 #define	HERMON_DRMAD_RETURN_PATH_OFFSET		0x80
123 
124 /*
125  * The hermon_agent_list_s structure is used in the Hermon IB Management Agent
126  * routines to keep track of the number (and type) of each registered agent.
127  * The primary purpose of tracking this information (port number, management
128  * class, and IBMF handle) is to be able to later deregister all the agents
129  * which are registered at attach() time.  Note: a pointer to this structure
130  * is returned to the driver (by the IBMF) every time the agent callback
131  * routine is called.  This is why the structure contains a backpointer to
132  * the Hermon softstate.
133  */
134 struct hermon_agent_list_s {
135 	hermon_state_t		*agl_state;
136 	uint_t			agl_port;
137 	ibmf_client_type_t	agl_mgmtclass;
138 	ibmf_handle_t		agl_ibmfhdl;
139 };
140 
141 /*
142  * The hermon_agent_handler_arg_t structure is used in the Hermon IB Management
143  * Agent routines to pass request information through the task queue.  Each
144  * time a request is received (by the Hermon agent request callback), one
145  * of these structures is allocated and filled with the relevant information
146  * for the request.  It is then dispatched to the task queue (with a pointer
147  * to the structure passed as an argument).  From there it is later pulled
148  * apart and the individual fields of the structure used to handle the
149  * request.
150  */
151 typedef struct hermon_agent_handler_arg_s {
152 	ibmf_handle_t		ahd_ibmfhdl;
153 	ibmf_msg_t		*ahd_ibmfmsg;
154 	hermon_agent_list_t	*ahd_agentlist;
155 } hermon_agent_handler_arg_t;
156 
157 int hermon_agent_handlers_init(hermon_state_t *state);
158 int hermon_agent_handlers_fini(hermon_state_t *state);
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif	/* _SYS_IB_ADAPTERS_HERMON_AGENTS_H */
165