2 * Copyright (c) 2004-2009 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.
5 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
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:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
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.
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
39 * Implementation of osm_slvl_rec_rcv_t.
40 * This object represents the SLtoVL Mapping Query Receiver object.
41 * This object is part of the opensm family of objects.
46 #endif /* HAVE_CONFIG_H */
49 #include <iba/ib_types.h>
50 #include <complib/cl_qmap.h>
51 #include <complib/cl_passivelock.h>
52 #include <complib/cl_debug.h>
53 #include <complib/cl_qlist.h>
54 #include <opensm/osm_file_ids.h>
55 #define FILE_ID OSM_FILE_SA_SLVL_RECORD_C
56 #include <vendor/osm_vendor_api.h>
57 #include <opensm/osm_port.h>
58 #include <opensm/osm_node.h>
59 #include <opensm/osm_helper.h>
60 #include <opensm/osm_pkey.h>
61 #include <opensm/osm_sa.h>
63 #define SA_SLVL_RESP_SIZE SA_ITEM_RESP_SIZE(slvl_rec)
65 typedef struct osm_slvl_search_ctxt {
66 const ib_slvl_table_record_t *p_rcvd_rec;
71 const osm_physp_t *p_req_physp;
72 } osm_slvl_search_ctxt_t;
74 static void sa_slvl_create(IN osm_sa_t * sa, IN const osm_physp_t * p_physp,
75 IN osm_slvl_search_ctxt_t * p_ctxt,
76 IN uint8_t in_port_idx)
78 osm_sa_item_t *p_rec_item;
81 OSM_LOG_ENTER(sa->p_log);
83 p_rec_item = malloc(SA_SLVL_RESP_SIZE);
84 if (p_rec_item == NULL) {
85 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2602: "
86 "rec_item alloc failed\n");
90 if (p_physp->p_node->node_info.node_type != IB_NODE_TYPE_SWITCH)
91 lid = p_physp->port_info.base_lid;
93 lid = osm_node_get_base_lid(p_physp->p_node, 0);
95 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
96 "New SLtoVL Map for: OUT port 0x%016" PRIx64
97 ", lid 0x%X, port %u to In Port:%u\n",
98 cl_ntoh64(osm_physp_get_port_guid(p_physp)),
99 cl_ntoh16(lid), osm_physp_get_port_num(p_physp), in_port_idx);
101 memset(p_rec_item, 0, SA_SLVL_RESP_SIZE);
103 p_rec_item->resp.slvl_rec.lid = lid;
104 if (p_physp->p_node->node_info.node_type == IB_NODE_TYPE_SWITCH) {
105 p_rec_item->resp.slvl_rec.out_port_num = osm_physp_get_port_num(p_physp);
106 p_rec_item->resp.slvl_rec.in_port_num = in_port_idx;
108 p_rec_item->resp.slvl_rec.slvl_tbl =
109 *(osm_physp_get_slvl_tbl(p_physp, in_port_idx));
111 cl_qlist_insert_tail(p_ctxt->p_list, &p_rec_item->list_item);
114 OSM_LOG_EXIT(sa->p_log);
117 static void sa_slvl_by_comp_mask(IN osm_sa_t * sa, IN const osm_port_t * p_port,
118 osm_slvl_search_ctxt_t * p_ctxt)
120 const ib_slvl_table_record_t *p_rcvd_rec;
121 ib_net64_t comp_mask;
122 const osm_physp_t *p_out_physp, *p_in_physp;
123 uint8_t in_port_num, out_port_num;
125 uint8_t in_port_start, in_port_end;
126 uint8_t out_port_start, out_port_end;
127 const osm_physp_t *p_req_physp;
129 OSM_LOG_ENTER(sa->p_log);
131 p_rcvd_rec = p_ctxt->p_rcvd_rec;
132 comp_mask = p_ctxt->comp_mask;
133 num_ports = osm_node_get_num_physp(p_port->p_node);
135 in_port_end = num_ports - 1;
137 out_port_end = num_ports - 1;
138 p_req_physp = p_ctxt->p_req_physp;
140 if (p_port->p_node->node_info.node_type != IB_NODE_TYPE_SWITCH) {
141 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
142 "Using Physical Default Port Number: 0x%X (for End Node)\n",
143 p_port->p_physp->port_num);
144 p_out_physp = p_port->p_physp;
145 /* check that the p_out_physp and the p_req_physp share a pkey */
146 if (osm_physp_share_pkey(sa->p_log, p_req_physp, p_out_physp,
147 sa->p_subn->opt.allow_both_pkeys))
148 sa_slvl_create(sa, p_out_physp, p_ctxt, 0);
150 if (comp_mask & IB_SLVL_COMPMASK_OUT_PORT)
151 out_port_start = out_port_end =
152 p_rcvd_rec->out_port_num;
153 if (comp_mask & IB_SLVL_COMPMASK_IN_PORT)
154 in_port_start = in_port_end = p_rcvd_rec->in_port_num;
156 for (out_port_num = out_port_start;
157 out_port_num <= out_port_end; out_port_num++) {
159 osm_node_get_physp_ptr(p_port->p_node,
164 for (in_port_num = in_port_start;
165 in_port_num <= in_port_end; in_port_num++) {
167 if (out_port_num && out_port_num == in_port_num)
172 osm_node_get_physp_ptr(p_port->p_node,
177 /* if the requester and the p_out_physp don't share a pkey -
179 if (!osm_physp_share_pkey(sa->p_log, p_req_physp, p_out_physp,
180 sa->p_subn->opt.allow_both_pkeys))
183 sa_slvl_create(sa, p_out_physp, p_ctxt,
188 OSM_LOG_EXIT(sa->p_log);
191 static void sa_slvl_by_comp_mask_cb(IN cl_map_item_t * p_map_item, IN void *cxt)
193 const osm_port_t *p_port = (osm_port_t *) p_map_item;
194 osm_slvl_search_ctxt_t *p_ctxt = cxt;
196 sa_slvl_by_comp_mask(p_ctxt->sa, p_port, p_ctxt);
199 void osm_slvl_rec_rcv_process(IN void *ctx, IN void *data)
202 osm_madw_t *p_madw = data;
203 const ib_sa_mad_t *p_rcvd_mad;
204 const ib_slvl_table_record_t *p_rcvd_rec;
205 const osm_port_t *p_port = NULL;
207 osm_slvl_search_ctxt_t context;
208 ib_api_status_t status = IB_SUCCESS;
209 ib_net64_t comp_mask;
210 osm_physp_t *p_req_physp;
214 OSM_LOG_ENTER(sa->p_log);
218 p_rcvd_mad = osm_madw_get_sa_mad_ptr(p_madw);
220 (ib_slvl_table_record_t *) ib_sa_mad_get_payload_ptr(p_rcvd_mad);
221 comp_mask = p_rcvd_mad->comp_mask;
223 CL_ASSERT(p_rcvd_mad->attr_id == IB_MAD_ATTR_SLVL_RECORD);
225 /* we only support SubnAdmGet and SubnAdmGetTable methods */
226 if (p_rcvd_mad->method != IB_MAD_METHOD_GET &&
227 p_rcvd_mad->method != IB_MAD_METHOD_GETTABLE) {
228 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2604: "
229 "Unsupported Method (%s) for SL2VLRecord request\n",
230 ib_get_sa_method_str(p_rcvd_mad->method));
231 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
235 cl_plock_acquire(sa->p_lock);
237 /* update the requester physical port */
238 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
239 osm_madw_get_mad_addr_ptr
241 if (p_req_physp == NULL) {
242 cl_plock_release(sa->p_lock);
243 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2603: "
244 "Cannot find requester physical port\n");
247 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
248 "Requester port GUID 0x%" PRIx64 "\n",
249 cl_ntoh64(osm_physp_get_port_guid(p_req_physp)));
251 cl_qlist_init(&rec_list);
253 context.p_rcvd_rec = p_rcvd_rec;
254 context.p_list = &rec_list;
255 context.comp_mask = p_rcvd_mad->comp_mask;
257 context.in_port_num = p_rcvd_rec->in_port_num;
258 context.p_req_physp = p_req_physp;
260 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
261 "Got Query Lid:%u(%02X), In-Port:0x%02X(%02X), Out-Port:0x%02X(%02X)\n",
262 cl_ntoh16(p_rcvd_rec->lid),
263 (comp_mask & IB_SLVL_COMPMASK_LID) != 0,
264 p_rcvd_rec->in_port_num,
265 (comp_mask & IB_SLVL_COMPMASK_IN_PORT) != 0,
266 p_rcvd_rec->out_port_num,
267 (comp_mask & IB_SLVL_COMPMASK_OUT_PORT) != 0);
270 If the user specified a LID, it obviously narrows our
271 work load, since we don't have to search every port
273 if (comp_mask & IB_SLVL_COMPMASK_LID) {
274 p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid);
276 status = IB_NOT_FOUND;
277 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2608: "
278 "No port found with LID %u\n",
279 cl_ntoh16(p_rcvd_rec->lid));
283 if (status == IB_SUCCESS) {
284 /* if we have a unique port - no need for a port search */
286 /* this does the loop on all the port phys ports */
287 sa_slvl_by_comp_mask(sa, p_port, &context);
289 cl_qmap_apply_func(&sa->p_subn->port_guid_tbl,
290 sa_slvl_by_comp_mask_cb, &context);
293 cl_plock_release(sa->p_lock);
295 osm_sa_respond(sa, p_madw, sizeof(ib_slvl_table_record_t), &rec_list);
298 OSM_LOG_EXIT(sa->p_log);