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 */
43 #include <infiniband/umad.h>
47 #define DEBUG if (ibdebug) IBWARN
50 #define MAX_AGENTS 256
52 static int class_agent[MAX_CLASS];
53 static int agent_class[MAX_AGENTS];
56 register_agent(int agent, int mclass)
58 static int initialized;
62 memset(class_agent, 0xff, sizeof class_agent);
63 memset(agent_class, 0xff, sizeof agent_class);
66 if (mclass < 0 || mclass >= MAX_CLASS ||
67 agent < 0 || agent >= MAX_AGENTS) {
68 DEBUG("bad mgmt class %d or agent %d", mclass, agent);
72 class_agent[mclass] = agent;
73 agent_class[agent] = mclass;
79 mgmt_class_vers(int mgmt_class)
81 if ((mgmt_class >= IB_VENDOR_RANGE1_START_CLASS &&
82 mgmt_class <= IB_VENDOR_RANGE1_END_CLASS) ||
83 (mgmt_class >= IB_VENDOR_RANGE2_START_CLASS &&
84 mgmt_class <= IB_VENDOR_RANGE2_END_CLASS))
89 case IB_SMI_DIRECT_CLASS:
93 case IB_PERFORMANCE_CLASS:
95 case IB_DEVICE_MGMT_CLASS:
105 mad_class_agent(int mgmt)
107 if (mgmt < 1 || mgmt > MAX_CLASS)
109 return class_agent[mgmt];
113 mad_agent_class(int agent)
115 if (agent < 1 || agent > MAX_AGENTS)
117 return agent_class[agent];
121 mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version)
125 if ((vers = mgmt_class_vers(mgmt)) <= 0) {
126 DEBUG("Unknown class %d mgmt_class", mgmt);
129 if ((agent = umad_register(port_id, mgmt,
130 vers, rmpp_version, 0)) < 0) {
131 DEBUG("Can't register agent for class %d", mgmt);
135 if (mgmt < 0 || mgmt >= MAX_CLASS || agent >= MAX_AGENTS) {
136 DEBUG("bad mgmt class %d or agent %d", mgmt, agent);
144 mad_register_client(int mgmt, uint8_t rmpp_version)
148 agent = mad_register_port_client(madrpc_portid(), mgmt, rmpp_version);
152 return register_agent(agent, mgmt);
156 mad_register_server(int mgmt, uint8_t rmpp_version,
157 long method_mask[], uint32_t class_oui)
159 long class_method_mask[16/sizeof(long)];
161 int agent, vers, mad_portid;
164 memcpy(class_method_mask, method_mask, sizeof class_method_mask);
166 memset(class_method_mask, 0xff, sizeof(class_method_mask));
168 if ((mad_portid = madrpc_portid()) < 0)
171 if (class_agent[mgmt] >= 0) {
172 DEBUG("Class 0x%x already registered", mgmt);
175 if ((vers = mgmt_class_vers(mgmt)) <= 0) {
176 DEBUG("Unknown class 0x%x mgmt_class", mgmt);
179 if (mgmt >= IB_VENDOR_RANGE2_START_CLASS &&
180 mgmt <= IB_VENDOR_RANGE2_END_CLASS) {
181 oui[0] = (class_oui >> 16) & 0xff;
182 oui[1] = (class_oui >> 8) & 0xff;
183 oui[2] = class_oui & 0xff;
184 if ((agent = umad_register_oui(mad_portid, mgmt, rmpp_version,
185 oui, class_method_mask)) < 0) {
186 DEBUG("Can't register agent for class %d", mgmt);
189 } else if ((agent = umad_register(mad_portid, mgmt, vers, rmpp_version,
190 class_method_mask)) < 0) {
191 DEBUG("Can't register agent for class %d", mgmt);
195 if (register_agent(agent, mgmt) < 0)