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_lftr_rcv_t.
39 * This object represents the LinearForwardingTable 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_debug.h>
50 #include <complib/cl_qlist.h>
51 #include <vendor/osm_vendor_api.h>
52 #include <opensm/osm_switch.h>
53 #include <opensm/osm_helper.h>
54 #include <opensm/osm_pkey.h>
55 #include <opensm/osm_sa.h>
57 typedef struct osm_lftr_item {
58 cl_list_item_t list_item;
62 typedef struct osm_lftr_search_ctxt {
63 const ib_lft_record_t *p_rcvd_rec;
67 const osm_physp_t *p_req_physp;
68 } osm_lftr_search_ctxt_t;
70 /**********************************************************************
71 **********************************************************************/
72 static ib_api_status_t
73 __osm_lftr_rcv_new_lftr(IN osm_sa_t * sa,
74 IN const osm_switch_t * const p_sw,
75 IN cl_qlist_t * const p_list,
76 IN ib_net16_t const lid, IN uint16_t const block)
78 osm_lftr_item_t *p_rec_item;
79 ib_api_status_t status = IB_SUCCESS;
81 OSM_LOG_ENTER(sa->p_log);
83 p_rec_item = malloc(sizeof(*p_rec_item));
84 if (p_rec_item == NULL) {
85 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4402: "
86 "rec_item alloc failed\n");
87 status = IB_INSUFFICIENT_RESOURCES;
91 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
92 "New LinearForwardingTable: sw 0x%016" PRIx64
93 "\n\t\t\t\tblock 0x%02X lid %u\n",
94 cl_ntoh64(osm_node_get_node_guid(p_sw->p_node)),
95 block, cl_ntoh16(lid));
97 memset(p_rec_item, 0, sizeof(*p_rec_item));
99 p_rec_item->rec.lid = lid;
100 p_rec_item->rec.block_num = cl_hton16(block);
102 /* copy the lft block */
103 osm_switch_get_lft_block(p_sw, block, p_rec_item->rec.lft);
105 cl_qlist_insert_tail(p_list, &p_rec_item->list_item);
108 OSM_LOG_EXIT(sa->p_log);
112 /**********************************************************************
113 **********************************************************************/
115 __osm_lftr_rcv_by_comp_mask(IN cl_map_item_t * const p_map_item,
118 const osm_lftr_search_ctxt_t *const p_ctxt =
119 (osm_lftr_search_ctxt_t *) context;
120 const osm_switch_t *const p_sw = (osm_switch_t *) p_map_item;
121 const ib_lft_record_t *const p_rcvd_rec = p_ctxt->p_rcvd_rec;
122 osm_sa_t *sa = p_ctxt->sa;
123 ib_net64_t const comp_mask = p_ctxt->comp_mask;
124 const osm_physp_t *const p_req_physp = p_ctxt->p_req_physp;
126 uint16_t min_lid_ho, max_lid_ho;
127 uint16_t min_block, max_block, block;
128 const osm_physp_t *p_physp;
130 /* In switches, the port guid is the node guid. */
131 p_port = osm_get_port_by_guid(sa->p_subn,
132 p_sw->p_node->node_info.port_guid);
134 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4405: "
135 "Failed to find Port by Node Guid:0x%016" PRIx64
136 "\n", cl_ntoh64(p_sw->p_node->node_info.node_guid));
140 /* check that the requester physp and the current physp are under
141 the same partition. */
142 p_physp = p_port->p_physp;
144 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4406: "
145 "Failed to find default physical Port by Node Guid:0x%016"
147 cl_ntoh64(p_sw->p_node->node_info.node_guid));
150 if (!osm_physp_share_pkey(sa->p_log, p_req_physp, p_physp))
153 /* get the port 0 of the switch */
154 osm_port_get_lid_range_ho(p_port, &min_lid_ho, &max_lid_ho);
156 /* compare the lids - if required */
157 if (comp_mask & IB_LFTR_COMPMASK_LID) {
158 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
159 "Comparing lid:%u to port lid range: %u .. %u\n",
160 cl_ntoh16(p_rcvd_rec->lid), min_lid_ho, max_lid_ho);
161 /* ok we are ready for range check */
162 if (min_lid_ho > cl_ntoh16(p_rcvd_rec->lid) ||
163 max_lid_ho < cl_ntoh16(p_rcvd_rec->lid))
167 /* now we need to decide which blocks to output */
168 max_block = osm_switch_get_max_block_id_in_use(p_sw);
169 if (comp_mask & IB_LFTR_COMPMASK_BLOCK) {
170 min_block = cl_ntoh16(p_rcvd_rec->block_num);
171 if (min_block > max_block)
173 max_block = min_block;
174 } else /* use as many blocks as "in use" */
177 /* so we can add these blocks one by one ... */
178 for (block = min_block; block <= max_block; block++)
179 __osm_lftr_rcv_new_lftr(sa, p_sw, p_ctxt->p_list,
180 osm_port_get_base_lid(p_port), block);
183 /**********************************************************************
184 **********************************************************************/
185 void osm_lftr_rcv_process(IN void *ctx, IN void *data)
188 osm_madw_t *p_madw = data;
189 const ib_sa_mad_t *p_rcvd_mad;
190 const ib_lft_record_t *p_rcvd_rec;
192 osm_lftr_search_ctxt_t context;
193 osm_physp_t *p_req_physp;
197 OSM_LOG_ENTER(sa->p_log);
201 p_rcvd_mad = osm_madw_get_sa_mad_ptr(p_madw);
202 p_rcvd_rec = (ib_lft_record_t *) ib_sa_mad_get_payload_ptr(p_rcvd_mad);
204 CL_ASSERT(p_rcvd_mad->attr_id == IB_MAD_ATTR_LFT_RECORD);
206 /* we only support SubnAdmGet and SubnAdmGetTable methods */
207 if (p_rcvd_mad->method != IB_MAD_METHOD_GET &&
208 p_rcvd_mad->method != IB_MAD_METHOD_GETTABLE) {
209 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4408: "
210 "Unsupported Method (%s)\n",
211 ib_get_sa_method_str(p_rcvd_mad->method));
212 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
216 /* update the requester physical port. */
217 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
218 osm_madw_get_mad_addr_ptr
220 if (p_req_physp == NULL) {
221 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4407: "
222 "Cannot find requester physical port\n");
226 cl_qlist_init(&rec_list);
228 context.p_rcvd_rec = p_rcvd_rec;
229 context.p_list = &rec_list;
230 context.comp_mask = p_rcvd_mad->comp_mask;
232 context.p_req_physp = p_req_physp;
234 cl_plock_acquire(sa->p_lock);
236 /* Go over all switches */
237 cl_qmap_apply_func(&sa->p_subn->sw_guid_tbl,
238 __osm_lftr_rcv_by_comp_mask, &context);
240 cl_plock_release(sa->p_lock);
242 osm_sa_respond(sa, p_madw, sizeof(ib_lft_record_t), &rec_list);
245 OSM_LOG_EXIT(sa->p_log);