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_vlarb_rec_rcv_t.
39 * This object represents the VLArbitrationRecord 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_vl_arb_item {
61 cl_list_item_t list_item;
62 ib_vl_arb_table_record_t rec;
65 typedef struct osm_vl_arb_search_ctxt {
66 const ib_vl_arb_table_record_t *p_rcvd_rec;
71 const osm_physp_t *p_req_physp;
72 } osm_vl_arb_search_ctxt_t;
74 /**********************************************************************
75 **********************************************************************/
77 __osm_sa_vl_arb_create(IN osm_sa_t * sa,
78 IN osm_physp_t * const p_physp,
79 IN osm_vl_arb_search_ctxt_t * const p_ctxt,
82 osm_vl_arb_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 2A02: "
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 VLArbitration for: port 0x%016" PRIx64
103 ", lid %u, port %u Block:%u\n",
104 cl_ntoh64(osm_physp_get_port_guid(p_physp)),
105 cl_ntoh16(lid), osm_physp_get_port_num(p_physp), block);
107 memset(p_rec_item, 0, sizeof(*p_rec_item));
109 p_rec_item->rec.lid = lid;
110 p_rec_item->rec.port_num = osm_physp_get_port_num(p_physp);
111 p_rec_item->rec.block_num = block;
112 p_rec_item->rec.vl_arb_tbl = *(osm_physp_get_vla_tbl(p_physp, block));
114 cl_qlist_insert_tail(p_ctxt->p_list, &p_rec_item->list_item);
117 OSM_LOG_EXIT(sa->p_log);
120 /**********************************************************************
121 **********************************************************************/
123 __osm_sa_vl_arb_check_physp(IN osm_sa_t * sa,
124 IN osm_physp_t * const p_physp,
125 osm_vl_arb_search_ctxt_t * const p_ctxt)
127 ib_net64_t comp_mask = p_ctxt->comp_mask;
130 OSM_LOG_ENTER(sa->p_log);
132 /* we got here with the phys port - all that's left is to get the right block */
133 for (block = 1; block <= 4; block++) {
134 if (!(comp_mask & IB_VLA_COMPMASK_BLOCK)
135 || block == p_ctxt->block_num) {
136 __osm_sa_vl_arb_create(sa, p_physp, p_ctxt, block);
140 OSM_LOG_EXIT(sa->p_log);
143 /**********************************************************************
144 **********************************************************************/
146 __osm_sa_vl_arb_by_comp_mask(IN osm_sa_t * sa,
147 IN const osm_port_t * const p_port,
148 osm_vl_arb_search_ctxt_t * const p_ctxt)
150 const ib_vl_arb_table_record_t *p_rcvd_rec;
151 ib_net64_t comp_mask;
152 osm_physp_t *p_physp;
155 const osm_physp_t *p_req_physp;
157 OSM_LOG_ENTER(sa->p_log);
159 p_rcvd_rec = p_ctxt->p_rcvd_rec;
160 comp_mask = p_ctxt->comp_mask;
161 port_num = p_rcvd_rec->port_num;
162 p_req_physp = p_ctxt->p_req_physp;
164 /* if this is a switch port we can search all ports
165 otherwise we must be looking on port 0 */
166 if (p_port->p_node->node_info.node_type != IB_NODE_TYPE_SWITCH) {
167 /* we put it in the comp mask and port num */
168 port_num = p_port->p_physp->port_num;
169 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
170 "Using Physical Default Port Number: 0x%X (for End Node)\n",
172 comp_mask |= IB_VLA_COMPMASK_OUT_PORT;
175 if (comp_mask & IB_VLA_COMPMASK_OUT_PORT) {
176 if (port_num < osm_node_get_num_physp(p_port->p_node)) {
178 osm_node_get_physp_ptr(p_port->p_node, port_num);
179 /* check that the p_physp is valid, and that the requester
180 and the p_physp share a pkey. */
182 osm_physp_share_pkey(sa->p_log, p_req_physp,
184 __osm_sa_vl_arb_check_physp(sa, p_physp,
187 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A03: "
188 "Given Physical Port Number: 0x%X is out of range should be < 0x%X\n",
190 osm_node_get_num_physp(p_port->p_node));
194 num_ports = osm_node_get_num_physp(p_port->p_node);
195 for (port_num = 0; port_num < num_ports; port_num++) {
197 osm_node_get_physp_ptr(p_port->p_node, port_num);
201 /* if the requester and the p_physp don't share a pkey -
203 if (!osm_physp_share_pkey
204 (sa->p_log, p_req_physp, p_physp))
207 __osm_sa_vl_arb_check_physp(sa, p_physp, p_ctxt);
211 OSM_LOG_EXIT(sa->p_log);
214 /**********************************************************************
215 **********************************************************************/
217 __osm_sa_vl_arb_by_comp_mask_cb(IN cl_map_item_t * const p_map_item,
220 const osm_port_t *const p_port = (osm_port_t *) p_map_item;
221 osm_vl_arb_search_ctxt_t *const p_ctxt =
222 (osm_vl_arb_search_ctxt_t *) context;
224 __osm_sa_vl_arb_by_comp_mask(p_ctxt->sa, p_port, p_ctxt);
227 /**********************************************************************
228 **********************************************************************/
229 void osm_vlarb_rec_rcv_process(IN void *ctx, IN void *data)
232 osm_madw_t *p_madw = data;
233 const ib_sa_mad_t *sad_mad;
234 const ib_vl_arb_table_record_t *p_rcvd_rec;
235 const osm_port_t *p_port = NULL;
236 const ib_vl_arb_table_t *p_vl_arb;
238 osm_vl_arb_search_ctxt_t context;
239 ib_api_status_t status = IB_SUCCESS;
240 ib_net64_t comp_mask;
241 osm_physp_t *p_req_physp;
245 OSM_LOG_ENTER(sa->p_log);
249 sad_mad = osm_madw_get_sa_mad_ptr(p_madw);
251 (ib_vl_arb_table_record_t *) ib_sa_mad_get_payload_ptr(sad_mad);
252 comp_mask = sad_mad->comp_mask;
254 CL_ASSERT(sad_mad->attr_id == IB_MAD_ATTR_VLARB_RECORD);
256 /* we only support SubnAdmGet and SubnAdmGetTable methods */
257 if (sad_mad->method != IB_MAD_METHOD_GET &&
258 sad_mad->method != IB_MAD_METHOD_GETTABLE) {
259 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A05: "
260 "Unsupported Method (%s)\n",
261 ib_get_sa_method_str(sad_mad->method));
262 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
266 /* update the requester physical port. */
267 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
268 osm_madw_get_mad_addr_ptr
270 if (p_req_physp == NULL) {
271 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A04: "
272 "Cannot find requester physical port\n");
276 p_vl_arb = (ib_vl_arb_table_t *) ib_sa_mad_get_payload_ptr(sad_mad);
278 cl_qlist_init(&rec_list);
280 context.p_rcvd_rec = p_rcvd_rec;
281 context.p_list = &rec_list;
282 context.comp_mask = sad_mad->comp_mask;
284 context.block_num = p_rcvd_rec->block_num;
285 context.p_req_physp = p_req_physp;
287 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
288 "Got Query Lid:%u(%02X), Port:0x%02X(%02X), Block:0x%02X(%02X)\n",
289 cl_ntoh16(p_rcvd_rec->lid),
290 (comp_mask & IB_VLA_COMPMASK_LID) != 0, p_rcvd_rec->port_num,
291 (comp_mask & IB_VLA_COMPMASK_OUT_PORT) != 0,
292 p_rcvd_rec->block_num,
293 (comp_mask & IB_VLA_COMPMASK_BLOCK) != 0);
295 cl_plock_acquire(sa->p_lock);
298 If the user specified a LID, it obviously narrows our
299 work load, since we don't have to search every port
301 if (comp_mask & IB_VLA_COMPMASK_LID) {
303 osm_get_port_by_base_lid(sa->p_subn, p_rcvd_rec->lid,
305 if ((status != IB_SUCCESS) || (p_port == NULL)) {
306 status = IB_NOT_FOUND;
307 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A09: "
308 "No port found with LID %u\n",
309 cl_ntoh16(p_rcvd_rec->lid));
313 if (status == IB_SUCCESS) {
314 /* if we got a unique port - no need for a port search */
316 /* this does the loop on all the port phys ports */
317 __osm_sa_vl_arb_by_comp_mask(sa, p_port, &context);
319 cl_qmap_apply_func(&sa->p_subn->port_guid_tbl,
320 __osm_sa_vl_arb_by_comp_mask_cb,
324 cl_plock_release(sa->p_lock);
326 osm_sa_respond(sa, p_madw, sizeof(ib_vl_arb_table_record_t), &rec_list);
329 OSM_LOG_EXIT(sa->p_log);