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_slvl_rec_rcv_t.
39 * This object represents the SLtoVL Mapping Query 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_port.h>
55 #include <opensm/osm_node.h>
56 #include <opensm/osm_helper.h>
57 #include <opensm/osm_pkey.h>
58 #include <opensm/osm_sa.h>
60 typedef struct osm_slvl_item {
61 cl_list_item_t list_item;
62 ib_slvl_table_record_t 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 /**********************************************************************
75 **********************************************************************/
77 __osm_sa_slvl_create(IN osm_sa_t * sa,
78 IN const osm_physp_t * const p_physp,
79 IN osm_slvl_search_ctxt_t * const p_ctxt,
80 IN uint8_t in_port_idx)
82 osm_slvl_item_t *p_rec_item;
84 ib_api_status_t status = IB_SUCCESS;
86 OSM_LOG_ENTER(sa->p_log);
88 p_rec_item = malloc(sizeof(*p_rec_item));
89 if (p_rec_item == NULL) {
90 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2602: "
91 "rec_item alloc failed\n");
92 status = IB_INSUFFICIENT_RESOURCES;
96 if (p_physp->p_node->node_info.node_type != IB_NODE_TYPE_SWITCH)
97 lid = p_physp->port_info.base_lid;
99 lid = osm_node_get_base_lid(p_physp->p_node, 0);
101 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
102 "New SLtoVL Map for: OUT port 0x%016" PRIx64
103 ", lid 0x%X, port %u to In Port:%u\n",
104 cl_ntoh64(osm_physp_get_port_guid(p_physp)),
105 cl_ntoh16(lid), osm_physp_get_port_num(p_physp), in_port_idx);
107 memset(p_rec_item, 0, sizeof(*p_rec_item));
109 p_rec_item->rec.lid = lid;
110 p_rec_item->rec.out_port_num = osm_physp_get_port_num(p_physp);
111 p_rec_item->rec.in_port_num = in_port_idx;
112 p_rec_item->rec.slvl_tbl =
113 *(osm_physp_get_slvl_tbl(p_physp, in_port_idx));
115 cl_qlist_insert_tail(p_ctxt->p_list, &p_rec_item->list_item);
118 OSM_LOG_EXIT(sa->p_log);
121 /**********************************************************************
122 **********************************************************************/
124 __osm_sa_slvl_by_comp_mask(IN osm_sa_t * sa,
125 IN const osm_port_t * const p_port,
126 osm_slvl_search_ctxt_t * const p_ctxt)
128 const ib_slvl_table_record_t *p_rcvd_rec;
129 ib_net64_t comp_mask;
130 const osm_physp_t *p_out_physp, *p_in_physp;
131 uint8_t in_port_num, out_port_num;
133 uint8_t in_port_start, in_port_end;
134 uint8_t out_port_start, out_port_end;
135 const osm_physp_t *p_req_physp;
137 OSM_LOG_ENTER(sa->p_log);
139 p_rcvd_rec = p_ctxt->p_rcvd_rec;
140 comp_mask = p_ctxt->comp_mask;
141 num_ports = osm_node_get_num_physp(p_port->p_node);
143 in_port_end = num_ports - 1;
145 out_port_end = num_ports - 1;
146 p_req_physp = p_ctxt->p_req_physp;
148 if (p_port->p_node->node_info.node_type != IB_NODE_TYPE_SWITCH) {
149 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
150 "Using Physical Default Port Number: 0x%X (for End Node)\n",
151 p_port->p_physp->port_num);
152 p_out_physp = p_port->p_physp;
153 /* check that the p_out_physp and the p_req_physp share a pkey */
154 if (osm_physp_share_pkey
155 (sa->p_log, p_req_physp, p_out_physp))
156 __osm_sa_slvl_create(sa, p_out_physp, p_ctxt, 0);
158 if (comp_mask & IB_SLVL_COMPMASK_OUT_PORT)
159 out_port_start = out_port_end =
160 p_rcvd_rec->out_port_num;
161 if (comp_mask & IB_SLVL_COMPMASK_IN_PORT)
162 in_port_start = in_port_end = p_rcvd_rec->in_port_num;
164 for (out_port_num = out_port_start;
165 out_port_num <= out_port_end; out_port_num++) {
167 osm_node_get_physp_ptr(p_port->p_node,
172 for (in_port_num = in_port_start;
173 in_port_num <= in_port_end; in_port_num++) {
175 if (out_port_num && out_port_num == in_port_num)
180 osm_node_get_physp_ptr(p_port->p_node,
185 /* if the requester and the p_out_physp don't share a pkey -
187 if (!osm_physp_share_pkey
188 (sa->p_log, p_req_physp, p_out_physp))
191 __osm_sa_slvl_create(sa, p_out_physp, p_ctxt,
196 OSM_LOG_EXIT(sa->p_log);
199 /**********************************************************************
200 **********************************************************************/
202 __osm_sa_slvl_by_comp_mask_cb(IN cl_map_item_t * const p_map_item,
205 const osm_port_t *const p_port = (osm_port_t *) p_map_item;
206 osm_slvl_search_ctxt_t *const p_ctxt =
207 (osm_slvl_search_ctxt_t *) context;
209 __osm_sa_slvl_by_comp_mask(p_ctxt->sa, p_port, p_ctxt);
212 /**********************************************************************
213 **********************************************************************/
214 void osm_slvl_rec_rcv_process(IN void *ctx, IN void *data)
217 osm_madw_t *p_madw = data;
218 const ib_sa_mad_t *p_rcvd_mad;
219 const ib_slvl_table_record_t *p_rcvd_rec;
220 const osm_port_t *p_port = NULL;
222 osm_slvl_search_ctxt_t context;
223 ib_api_status_t status = IB_SUCCESS;
224 ib_net64_t comp_mask;
225 osm_physp_t *p_req_physp;
229 OSM_LOG_ENTER(sa->p_log);
233 p_rcvd_mad = osm_madw_get_sa_mad_ptr(p_madw);
235 (ib_slvl_table_record_t *) ib_sa_mad_get_payload_ptr(p_rcvd_mad);
236 comp_mask = p_rcvd_mad->comp_mask;
238 CL_ASSERT(p_rcvd_mad->attr_id == IB_MAD_ATTR_SLVL_RECORD);
240 /* we only support SubnAdmGet and SubnAdmGetTable methods */
241 if (p_rcvd_mad->method != IB_MAD_METHOD_GET &&
242 p_rcvd_mad->method != IB_MAD_METHOD_GETTABLE) {
243 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2604: "
244 "Unsupported Method (%s)\n",
245 ib_get_sa_method_str(p_rcvd_mad->method));
246 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
250 /* update the requester physical port. */
251 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
252 osm_madw_get_mad_addr_ptr
254 if (p_req_physp == NULL) {
255 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2603: "
256 "Cannot find requester physical port\n");
260 cl_qlist_init(&rec_list);
262 context.p_rcvd_rec = p_rcvd_rec;
263 context.p_list = &rec_list;
264 context.comp_mask = p_rcvd_mad->comp_mask;
266 context.in_port_num = p_rcvd_rec->in_port_num;
267 context.p_req_physp = p_req_physp;
269 cl_plock_acquire(sa->p_lock);
271 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
272 "Got Query Lid:%u(%02X), In-Port:0x%02X(%02X), Out-Port:0x%02X(%02X)\n",
273 cl_ntoh16(p_rcvd_rec->lid),
274 (comp_mask & IB_SLVL_COMPMASK_LID) != 0,
275 p_rcvd_rec->in_port_num,
276 (comp_mask & IB_SLVL_COMPMASK_IN_PORT) != 0,
277 p_rcvd_rec->out_port_num,
278 (comp_mask & IB_SLVL_COMPMASK_OUT_PORT) != 0);
281 If the user specified a LID, it obviously narrows our
282 work load, since we don't have to search every port
284 if (comp_mask & IB_SLVL_COMPMASK_LID) {
286 osm_get_port_by_base_lid(sa->p_subn, p_rcvd_rec->lid,
288 if ((status != IB_SUCCESS) || (p_port == NULL)) {
289 status = IB_NOT_FOUND;
290 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2608: "
291 "No port found with LID %u\n",
292 cl_ntoh16(p_rcvd_rec->lid));
296 if (status == IB_SUCCESS) {
297 /* if we have a unique port - no need for a port search */
299 /* this does the loop on all the port phys ports */
300 __osm_sa_slvl_by_comp_mask(sa, p_port, &context);
302 cl_qmap_apply_func(&sa->p_subn->port_guid_tbl,
303 __osm_sa_slvl_by_comp_mask_cb,
307 cl_plock_release(sa->p_lock);
309 osm_sa_respond(sa, p_madw, sizeof(ib_slvl_table_record_t), &rec_list);
312 OSM_LOG_EXIT(sa->p_log);