2 * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 * Implementation of osm_cpi_rcv_t.
39 * This object represents the ClassPortInfo Receiver object.
40 * This object is part of the opensm family of objects.
45 #endif /* HAVE_CONFIG_H */
48 #include <iba/ib_types.h>
49 #include <complib/cl_qmap.h>
50 #include <complib/cl_passivelock.h>
51 #include <complib/cl_debug.h>
52 #include <complib/cl_qlist.h>
53 #include <vendor/osm_vendor_api.h>
54 #include <opensm/osm_helper.h>
55 #include <opensm/osm_sa.h>
57 #define MAX_MSECS_TO_RTV 24
58 /* Precalculated table in msec (index is related to encoded value) */
59 /* 4.096 usec * 2 ** n (where n = 8 - 31) */
60 const static uint32_t __msecs_to_rtv_table[MAX_MSECS_TO_RTV] = {
64 4294, 8589, 17179, 34359,
65 68719, 137438, 274877, 549755,
66 1099511, 2199023, 4398046, 8796093
69 /**********************************************************************
70 **********************************************************************/
72 __osm_cpi_rcv_respond(IN osm_sa_t * sa,
73 IN const osm_madw_t * const p_madw)
75 osm_madw_t *p_resp_madw;
76 const ib_sa_mad_t *p_sa_mad;
77 ib_sa_mad_t *p_resp_sa_mad;
78 ib_class_port_info_t *p_resp_cpi;
82 OSM_LOG_ENTER(sa->p_log);
84 memset(&zero_gid, 0, sizeof(ib_gid_t));
87 Get a MAD to reply. Address of Mad is in the received mad_wrapper
89 p_resp_madw = osm_mad_pool_get(sa->p_mad_pool, p_madw->h_bind,
90 MAD_BLOCK_SIZE, &p_madw->mad_addr);
92 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1408: "
93 "Unable to allocate MAD\n");
97 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
98 p_resp_sa_mad = osm_madw_get_sa_mad_ptr(p_resp_madw);
100 memcpy(p_resp_sa_mad, p_sa_mad, IB_SA_MAD_HDR_SIZE);
101 p_resp_sa_mad->method |= IB_MAD_METHOD_RESP_MASK;
102 /* C15-0.1.5 - always return SM_Key = 0 (table 185 p 884) */
103 p_resp_sa_mad->sm_key = 0;
106 (ib_class_port_info_t *) ib_sa_mad_get_payload_ptr(p_resp_sa_mad);
108 /* finally do it (the job) man ! */
109 p_resp_cpi->base_ver = 1;
110 p_resp_cpi->class_ver = 2;
111 /* Calculate encoded response time value */
112 /* transaction timeout is in msec */
113 if (sa->p_subn->opt.transaction_timeout >
114 __msecs_to_rtv_table[MAX_MSECS_TO_RTV - 1])
115 rtv = MAX_MSECS_TO_RTV - 1;
117 for (rtv = 0; rtv < MAX_MSECS_TO_RTV; rtv++) {
118 if (sa->p_subn->opt.transaction_timeout <=
119 __msecs_to_rtv_table[rtv])
124 ib_class_set_resp_time_val(p_resp_cpi, rtv);
125 p_resp_cpi->redir_gid = zero_gid;
126 p_resp_cpi->redir_tc_sl_fl = 0;
127 p_resp_cpi->redir_lid = 0;
128 p_resp_cpi->redir_pkey = 0;
129 p_resp_cpi->redir_qp = CL_NTOH32(1);
130 p_resp_cpi->redir_qkey = IB_QP1_WELL_KNOWN_Q_KEY;
131 p_resp_cpi->trap_gid = zero_gid;
132 p_resp_cpi->trap_tc_sl_fl = 0;
133 p_resp_cpi->trap_lid = 0;
134 p_resp_cpi->trap_pkey = 0;
135 p_resp_cpi->trap_hop_qp = 0;
136 p_resp_cpi->trap_qkey = IB_QP1_WELL_KNOWN_Q_KEY;
138 /* set specific capability mask bits */
139 /* we do not support the following options/optional records:
140 OSM_CAP_IS_SUBN_OPT_RECS_SUP :
141 RandomForwardingTableRecord,
142 ServiceAssociationRecord
143 other optional records supported "under the table"
145 OSM_CAP_IS_MULTIPATH_SUP:
148 OSM_CAP_IS_REINIT_SUP:
149 For reinitialization functionality.
151 So not sending traps, but supporting Get(Notice) and Set(Notice).
154 /* Note host notation replaced later */
155 #if defined (VENDOR_RMPP_SUPPORT) && defined (DUAL_SIDED_RMPP)
156 p_resp_cpi->cap_mask = OSM_CAP_IS_SUBN_GET_SET_NOTICE_SUP |
157 OSM_CAP_IS_PORT_INFO_CAPMASK_MATCH_SUPPORTED |
158 OSM_CAP_IS_MULTIPATH_SUP;
160 p_resp_cpi->cap_mask = OSM_CAP_IS_SUBN_GET_SET_NOTICE_SUP |
161 OSM_CAP_IS_PORT_INFO_CAPMASK_MATCH_SUPPORTED;
163 if (sa->p_subn->opt.qos)
164 ib_class_set_cap_mask2(p_resp_cpi, OSM_CAP2_IS_QOS_SUPPORTED);
166 if (!sa->p_subn->opt.disable_multicast)
167 p_resp_cpi->cap_mask |= OSM_CAP_IS_UD_MCAST_SUP;
168 p_resp_cpi->cap_mask = cl_hton16(p_resp_cpi->cap_mask);
170 if (osm_log_is_active(sa->p_log, OSM_LOG_FRAMES))
171 osm_dump_sa_mad(sa->p_log, p_resp_sa_mad, OSM_LOG_FRAMES);
173 osm_sa_send(sa, p_resp_madw, FALSE);
176 OSM_LOG_EXIT(sa->p_log);
179 /**********************************************************************
180 * This code actually handles the call
181 **********************************************************************/
182 void osm_cpi_rcv_process(IN void *context, IN void *data)
184 osm_sa_t *sa = context;
185 osm_madw_t *p_madw = data;
186 const ib_sa_mad_t *p_sa_mad;
188 OSM_LOG_ENTER(sa->p_log);
192 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
194 /* we only support GET */
195 if (p_sa_mad->method != IB_MAD_METHOD_GET) {
196 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1403: "
197 "Unsupported Method (%s)\n",
198 ib_get_sa_method_str(p_sa_mad->method));
199 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_REQ_INVALID);
203 CL_ASSERT(p_sa_mad->attr_id == IB_MAD_ATTR_CLASS_PORT_INFO);
206 CLASS PORT INFO does not really look on the SMDB - no lock required.
209 __osm_cpi_rcv_respond(sa, p_madw);
212 OSM_LOG_EXIT(sa->p_log);