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_vlarb_rec_rcv_t.
40 * This object represents the VLArbitrationRecord 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_VLARB_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_VLA_RESP_SIZE SA_ITEM_RESP_SIZE(vlarb_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 static void sa_vl_arb_create(IN osm_sa_t * sa, IN osm_physp_t * p_physp,
75 IN osm_vl_arb_search_ctxt_t * p_ctxt,
78 osm_sa_item_t *p_rec_item;
81 OSM_LOG_ENTER(sa->p_log);
83 p_rec_item = malloc(SA_VLA_RESP_SIZE);
84 if (p_rec_item == NULL) {
85 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A02: "
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 VLArbitration for: port 0x%016" PRIx64
97 ", lid %u, port %u Block:%u\n",
98 cl_ntoh64(osm_physp_get_port_guid(p_physp)),
99 cl_ntoh16(lid), osm_physp_get_port_num(p_physp), block);
101 memset(p_rec_item, 0, SA_VLA_RESP_SIZE);
103 p_rec_item->resp.vlarb_rec.lid = lid;
104 p_rec_item->resp.vlarb_rec.port_num = osm_physp_get_port_num(p_physp);
105 p_rec_item->resp.vlarb_rec.block_num = block;
106 p_rec_item->resp.vlarb_rec.vl_arb_tbl = *(osm_physp_get_vla_tbl(p_physp, block));
108 cl_qlist_insert_tail(p_ctxt->p_list, &p_rec_item->list_item);
111 OSM_LOG_EXIT(sa->p_log);
114 static void sa_vl_arb_check_physp(IN osm_sa_t * sa, IN osm_physp_t * p_physp,
115 osm_vl_arb_search_ctxt_t * p_ctxt)
117 ib_net64_t comp_mask = p_ctxt->comp_mask;
120 OSM_LOG_ENTER(sa->p_log);
122 /* we got here with the phys port - all that's left is to get the right block */
123 for (block = 1; block <= 4; block++) {
124 if (!(comp_mask & IB_VLA_COMPMASK_BLOCK)
125 || block == p_ctxt->block_num)
126 sa_vl_arb_create(sa, p_physp, p_ctxt, block);
129 OSM_LOG_EXIT(sa->p_log);
132 static void sa_vl_arb_by_comp_mask(osm_sa_t * sa, IN const osm_port_t * p_port,
133 osm_vl_arb_search_ctxt_t * p_ctxt)
135 const ib_vl_arb_table_record_t *p_rcvd_rec;
136 ib_net64_t comp_mask;
137 osm_physp_t *p_physp;
140 const osm_physp_t *p_req_physp;
142 OSM_LOG_ENTER(sa->p_log);
144 p_rcvd_rec = p_ctxt->p_rcvd_rec;
145 comp_mask = p_ctxt->comp_mask;
146 port_num = p_rcvd_rec->port_num;
147 p_req_physp = p_ctxt->p_req_physp;
149 /* if this is a switch port we can search all ports
150 otherwise we must be looking on port 0 */
151 if (p_port->p_node->node_info.node_type != IB_NODE_TYPE_SWITCH) {
152 /* we put it in the comp mask and port num */
153 port_num = p_port->p_physp->port_num;
154 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
155 "Using Physical Default Port Number: 0x%X (for End Node)\n",
157 comp_mask |= IB_VLA_COMPMASK_OUT_PORT;
160 if (comp_mask & IB_VLA_COMPMASK_OUT_PORT) {
161 if (port_num < osm_node_get_num_physp(p_port->p_node)) {
163 osm_node_get_physp_ptr(p_port->p_node, port_num);
164 /* check that the p_physp is valid, and that the requester
165 and the p_physp share a pkey. */
167 osm_physp_share_pkey(sa->p_log, p_req_physp, p_physp,
168 sa->p_subn->opt.allow_both_pkeys))
169 sa_vl_arb_check_physp(sa, p_physp, p_ctxt);
171 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A03: "
172 "Given Physical Port Number: 0x%X is out of range should be < 0x%X\n",
174 osm_node_get_num_physp(p_port->p_node));
178 num_ports = osm_node_get_num_physp(p_port->p_node);
179 for (port_num = 0; port_num < num_ports; port_num++) {
181 osm_node_get_physp_ptr(p_port->p_node, port_num);
185 /* if the requester and the p_physp don't share a pkey -
187 if (!osm_physp_share_pkey(sa->p_log, p_req_physp, p_physp,
188 sa->p_subn->opt.allow_both_pkeys))
191 sa_vl_arb_check_physp(sa, p_physp, p_ctxt);
195 OSM_LOG_EXIT(sa->p_log);
198 static void sa_vl_arb_by_comp_mask_cb(IN cl_map_item_t * p_map_item, void *cxt)
200 const osm_port_t *p_port = (osm_port_t *) p_map_item;
201 osm_vl_arb_search_ctxt_t *p_ctxt = cxt;
203 sa_vl_arb_by_comp_mask(p_ctxt->sa, p_port, p_ctxt);
206 void osm_vlarb_rec_rcv_process(IN void *ctx, IN void *data)
209 osm_madw_t *p_madw = data;
210 const ib_sa_mad_t *sad_mad;
211 const ib_vl_arb_table_record_t *p_rcvd_rec;
212 const osm_port_t *p_port = NULL;
214 osm_vl_arb_search_ctxt_t context;
215 ib_api_status_t status = IB_SUCCESS;
216 ib_net64_t comp_mask;
217 osm_physp_t *p_req_physp;
221 OSM_LOG_ENTER(sa->p_log);
225 sad_mad = osm_madw_get_sa_mad_ptr(p_madw);
227 (ib_vl_arb_table_record_t *) ib_sa_mad_get_payload_ptr(sad_mad);
228 comp_mask = sad_mad->comp_mask;
230 CL_ASSERT(sad_mad->attr_id == IB_MAD_ATTR_VLARB_RECORD);
232 /* we only support SubnAdmGet and SubnAdmGetTable methods */
233 if (sad_mad->method != IB_MAD_METHOD_GET &&
234 sad_mad->method != IB_MAD_METHOD_GETTABLE) {
235 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A05: "
236 "Unsupported Method (%s) for a VLArbRecord request\n",
237 ib_get_sa_method_str(sad_mad->method));
238 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
242 cl_plock_acquire(sa->p_lock);
244 /* update the requester physical port */
245 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
246 osm_madw_get_mad_addr_ptr
248 if (p_req_physp == NULL) {
249 cl_plock_release(sa->p_lock);
250 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A04: "
251 "Cannot find requester physical port\n");
254 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
255 "Requester port GUID 0x%" PRIx64 "\n",
256 cl_ntoh64(osm_physp_get_port_guid(p_req_physp)));
258 cl_qlist_init(&rec_list);
260 context.p_rcvd_rec = p_rcvd_rec;
261 context.p_list = &rec_list;
262 context.comp_mask = sad_mad->comp_mask;
264 context.block_num = p_rcvd_rec->block_num;
265 context.p_req_physp = p_req_physp;
267 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
268 "Got Query Lid:%u(%02X), Port:0x%02X(%02X), Block:0x%02X(%02X)\n",
269 cl_ntoh16(p_rcvd_rec->lid),
270 (comp_mask & IB_VLA_COMPMASK_LID) != 0, p_rcvd_rec->port_num,
271 (comp_mask & IB_VLA_COMPMASK_OUT_PORT) != 0,
272 p_rcvd_rec->block_num,
273 (comp_mask & IB_VLA_COMPMASK_BLOCK) != 0);
276 If the user specified a LID, it obviously narrows our
277 work load, since we don't have to search every port
279 if (comp_mask & IB_VLA_COMPMASK_LID) {
280 p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid);
282 status = IB_NOT_FOUND;
283 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A09: "
284 "No port found with LID %u\n",
285 cl_ntoh16(p_rcvd_rec->lid));
289 if (status == IB_SUCCESS) {
290 /* if we got a unique port - no need for a port search */
292 /* this does the loop on all the port phys ports */
293 sa_vl_arb_by_comp_mask(sa, p_port, &context);
295 cl_qmap_apply_func(&sa->p_subn->port_guid_tbl,
296 sa_vl_arb_by_comp_mask_cb, &context);
299 cl_plock_release(sa->p_lock);
301 osm_sa_respond(sa, p_madw, sizeof(ib_vl_arb_table_record_t), &rec_list);
304 OSM_LOG_EXIT(sa->p_log);