2 * Copyright (c) 2004,2005 Voltaire Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #endif /* HAVE_CONFIG_H */
46 #include <infiniband/umad.h>
50 #define DEBUG if (ibdebug) IBWARN
53 #define MAX_AGENTS 256
55 static int class_agent[MAX_CLASS];
56 static int agent_class[MAX_AGENTS];
59 register_agent(int agent, int mclass)
61 static int initialized;
65 memset(class_agent, 0xff, sizeof class_agent);
66 memset(agent_class, 0xff, sizeof agent_class);
69 if (mclass < 0 || mclass >= MAX_CLASS ||
70 agent < 0 || agent >= MAX_AGENTS) {
71 DEBUG("bad mgmt class %d or agent %d", mclass, agent);
75 class_agent[mclass] = agent;
76 agent_class[agent] = mclass;
82 mgmt_class_vers(int mgmt_class)
84 if ((mgmt_class >= IB_VENDOR_RANGE1_START_CLASS &&
85 mgmt_class <= IB_VENDOR_RANGE1_END_CLASS) ||
86 (mgmt_class >= IB_VENDOR_RANGE2_START_CLASS &&
87 mgmt_class <= IB_VENDOR_RANGE2_END_CLASS))
92 case IB_SMI_DIRECT_CLASS:
96 case IB_PERFORMANCE_CLASS:
98 case IB_DEVICE_MGMT_CLASS:
108 mad_class_agent(int mgmt)
110 if (mgmt < 1 || mgmt > MAX_CLASS)
112 return class_agent[mgmt];
116 mad_agent_class(int agent)
118 if (agent < 1 || agent > MAX_AGENTS)
120 return agent_class[agent];
124 mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version)
128 if ((vers = mgmt_class_vers(mgmt)) <= 0) {
129 DEBUG("Unknown class %d mgmt_class", mgmt);
132 if ((agent = umad_register(port_id, mgmt,
133 vers, rmpp_version, 0)) < 0) {
134 DEBUG("Can't register agent for class %d", mgmt);
138 if (mgmt < 0 || mgmt >= MAX_CLASS || agent >= MAX_AGENTS) {
139 DEBUG("bad mgmt class %d or agent %d", mgmt, agent);
147 mad_register_client(int mgmt, uint8_t rmpp_version)
151 agent = mad_register_port_client(madrpc_portid(), mgmt, rmpp_version);
155 return register_agent(agent, mgmt);
159 mad_register_server(int mgmt, uint8_t rmpp_version,
160 long method_mask[], uint32_t class_oui)
162 long class_method_mask[16/sizeof(long)];
164 int agent, vers, mad_portid;
167 memcpy(class_method_mask, method_mask, sizeof class_method_mask);
169 memset(class_method_mask, 0xff, sizeof(class_method_mask));
171 if ((mad_portid = madrpc_portid()) < 0)
174 if (class_agent[mgmt] >= 0) {
175 DEBUG("Class 0x%x already registered", mgmt);
178 if ((vers = mgmt_class_vers(mgmt)) <= 0) {
179 DEBUG("Unknown class 0x%x mgmt_class", mgmt);
182 if (mgmt >= IB_VENDOR_RANGE2_START_CLASS &&
183 mgmt <= IB_VENDOR_RANGE2_END_CLASS) {
184 oui[0] = (class_oui >> 16) & 0xff;
185 oui[1] = (class_oui >> 8) & 0xff;
186 oui[2] = class_oui & 0xff;
187 if ((agent = umad_register_oui(mad_portid, mgmt, rmpp_version,
188 oui, class_method_mask)) < 0) {
189 DEBUG("Can't register agent for class %d", mgmt);
192 } else if ((agent = umad_register(mad_portid, mgmt, vers, rmpp_version,
193 class_method_mask)) < 0) {
194 DEBUG("Can't register agent for class %d", mgmt);
198 if (register_agent(agent, mgmt) < 0)