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_mftr_rcv_t.
39 * This object represents the MulticastForwardingTable 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_mftr_item {
58 cl_list_item_t list_item;
62 typedef struct osm_mftr_search_ctxt {
63 const ib_mft_record_t *p_rcvd_rec;
67 const osm_physp_t *p_req_physp;
68 } osm_mftr_search_ctxt_t;
70 /**********************************************************************
71 **********************************************************************/
72 static ib_api_status_t
73 __osm_mftr_rcv_new_mftr(IN osm_sa_t * sa,
74 IN osm_switch_t * const p_sw,
75 IN cl_qlist_t * const p_list,
76 IN ib_net16_t const lid,
77 IN uint16_t const block, IN uint8_t const position)
79 osm_mftr_item_t *p_rec_item;
80 ib_api_status_t status = IB_SUCCESS;
81 uint16_t position_block_num;
83 OSM_LOG_ENTER(sa->p_log);
85 p_rec_item = malloc(sizeof(*p_rec_item));
86 if (p_rec_item == NULL) {
87 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4A02: "
88 "rec_item alloc failed\n");
89 status = IB_INSUFFICIENT_RESOURCES;
93 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
94 "New MulticastForwardingTable: sw 0x%016" PRIx64
95 "\n\t\t\t\tblock %u position %u lid %u\n",
96 cl_ntoh64(osm_node_get_node_guid(p_sw->p_node)),
97 block, position, cl_ntoh16(lid));
99 position_block_num = ((uint16_t) position << 12) |
100 (block & IB_MCAST_BLOCK_ID_MASK_HO);
102 memset(p_rec_item, 0, sizeof(*p_rec_item));
104 p_rec_item->rec.lid = lid;
105 p_rec_item->rec.position_block_num = cl_hton16(position_block_num);
107 /* copy the mft block */
108 osm_switch_get_mft_block(p_sw, block, position, p_rec_item->rec.mft);
110 cl_qlist_insert_tail(p_list, &p_rec_item->list_item);
113 OSM_LOG_EXIT(sa->p_log);
117 /**********************************************************************
118 **********************************************************************/
120 __osm_mftr_rcv_by_comp_mask(IN cl_map_item_t * const p_map_item,
123 const osm_mftr_search_ctxt_t *const p_ctxt =
124 (osm_mftr_search_ctxt_t *) context;
125 osm_switch_t *const p_sw = (osm_switch_t *) p_map_item;
126 const ib_mft_record_t *const p_rcvd_rec = p_ctxt->p_rcvd_rec;
127 osm_sa_t *sa = p_ctxt->sa;
128 ib_net64_t const comp_mask = p_ctxt->comp_mask;
129 const osm_physp_t *const p_req_physp = p_ctxt->p_req_physp;
131 uint16_t min_lid_ho, max_lid_ho;
132 uint16_t position_block_num_ho;
133 uint16_t min_block, max_block, block;
134 const osm_physp_t *p_physp;
135 uint8_t min_position, max_position, position;
137 /* In switches, the port guid is the node guid. */
139 osm_get_port_by_guid(sa->p_subn, p_sw->p_node->node_info.port_guid);
141 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4A05: "
142 "Failed to find Port by Node Guid:0x%016" PRIx64
143 "\n", cl_ntoh64(p_sw->p_node->node_info.node_guid));
147 /* check that the requester physp and the current physp are under
148 the same partition. */
149 p_physp = p_port->p_physp;
151 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4A06: "
152 "Failed to find default physical Port by Node Guid:0x%016"
154 cl_ntoh64(p_sw->p_node->node_info.node_guid));
157 if (!osm_physp_share_pkey(sa->p_log, p_req_physp, p_physp))
160 /* get the port 0 of the switch */
161 osm_port_get_lid_range_ho(p_port, &min_lid_ho, &max_lid_ho);
163 /* compare the lids - if required */
164 if (comp_mask & IB_MFTR_COMPMASK_LID) {
165 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
166 "Comparing lid:%u to port lid range: %u .. %u\n",
167 cl_ntoh16(p_rcvd_rec->lid), min_lid_ho, max_lid_ho);
168 /* ok we are ready for range check */
169 if (min_lid_ho > cl_ntoh16(p_rcvd_rec->lid) ||
170 max_lid_ho < cl_ntoh16(p_rcvd_rec->lid))
174 if (!osm_switch_supports_mcast(p_sw))
177 /* Are there any blocks in use ? */
178 if (osm_switch_get_mft_max_block_in_use(p_sw) == -1)
181 position_block_num_ho = cl_ntoh16(p_rcvd_rec->position_block_num);
183 /* now we need to decide which blocks to output */
184 if (comp_mask & IB_MFTR_COMPMASK_BLOCK) {
185 max_block = min_block =
186 position_block_num_ho & IB_MCAST_BLOCK_ID_MASK_HO;
187 if (max_block > osm_switch_get_mft_max_block_in_use(p_sw))
190 /* use as many blocks as needed */
192 max_block = osm_switch_get_mft_max_block_in_use(p_sw);
195 /* need to decide which positions to output */
196 if (comp_mask & IB_MFTR_COMPMASK_POSITION) {
197 min_position = max_position =
198 (position_block_num_ho & 0xF000) >> 12;
199 if (max_position > osm_switch_get_mft_max_position(p_sw))
202 /* use as many positions as needed */
204 max_position = osm_switch_get_mft_max_position(p_sw);
207 /* so we can add these one by one ... */
208 for (block = min_block; block <= max_block; block++)
209 for (position = min_position; position <= max_position;
211 __osm_mftr_rcv_new_mftr(sa, p_sw, p_ctxt->p_list,
212 osm_port_get_base_lid(p_port),
216 /**********************************************************************
217 **********************************************************************/
218 void osm_mftr_rcv_process(IN void *ctx, IN void *data)
221 osm_madw_t *p_madw = data;
222 const ib_sa_mad_t *p_rcvd_mad;
223 const ib_mft_record_t *p_rcvd_rec;
225 osm_mftr_search_ctxt_t context;
226 osm_physp_t *p_req_physp;
230 OSM_LOG_ENTER(sa->p_log);
234 p_rcvd_mad = osm_madw_get_sa_mad_ptr(p_madw);
235 p_rcvd_rec = (ib_mft_record_t *) ib_sa_mad_get_payload_ptr(p_rcvd_mad);
237 CL_ASSERT(p_rcvd_mad->attr_id == IB_MAD_ATTR_MFT_RECORD);
239 /* we only support SubnAdmGet and SubnAdmGetTable methods */
240 if (p_rcvd_mad->method != IB_MAD_METHOD_GET &&
241 p_rcvd_mad->method != IB_MAD_METHOD_GETTABLE) {
242 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4A08: "
243 "Unsupported Method (%s)\n",
244 ib_get_sa_method_str(p_rcvd_mad->method));
245 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
249 /* update the requester physical port. */
250 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log,
252 osm_madw_get_mad_addr_ptr
254 if (p_req_physp == NULL) {
255 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4A07: "
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.p_req_physp = p_req_physp;
268 cl_plock_acquire(sa->p_lock);
270 /* Go over all switches */
271 cl_qmap_apply_func(&sa->p_subn->sw_guid_tbl,
272 __osm_mftr_rcv_by_comp_mask, &context);
274 cl_plock_release(sa->p_lock);
276 osm_sa_respond(sa, p_madw, sizeof(ib_mft_record_t), &rec_list);
279 OSM_LOG_EXIT(sa->p_log);