From 8ba2f3170cc4472a55807128163e3a49fa325df9 Mon Sep 17 00:00:00 2001 From: Stan Smith Date: Fri, 21 May 2010 19:36:06 +0000 Subject: [PATCH] [OPENSM] Reduce stack consumption by using a union of structs. Code borrowed from osm_vendor_umad_sa.c Support OSMV_QUERY_MULTIPATH_REC queries. signed-off-by: stan smith git-svn-id: svn://openib.tc.cornell.edu/gen1@2806 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- .../opensm/user/libvendor/osm_vendor_mlx_sa.c | 128 ++++++++++++------ 1 file changed, 89 insertions(+), 39 deletions(-) diff --git a/trunk/ulp/opensm/user/libvendor/osm_vendor_mlx_sa.c b/trunk/ulp/opensm/user/libvendor/osm_vendor_mlx_sa.c index eea0d0e4..1f468e64 100644 --- a/trunk/ulp/opensm/user/libvendor/osm_vendor_mlx_sa.c +++ b/trunk/ulp/opensm/user/libvendor/osm_vendor_mlx_sa.c @@ -147,9 +147,9 @@ __osmv_sa_mad_rcv_cb(IN osm_madw_t * p_madw, "__osmv_sa_mad_rcv_cb: Count = 0\n"); } else { - query_res.result_cnt = (uintn_t) - ((p_madw->mad_size - IB_SA_MAD_HDR_SIZE) / - ib_get_attr_size(p_sa_mad->attr_offset)); + query_res.result_cnt = + (p_madw->mad_size - IB_SA_MAD_HDR_SIZE) / + ib_get_attr_size(p_sa_mad->attr_offset); osm_log(p_bind->p_log, OSM_LOG_DEBUG, "__osmv_sa_mad_rcv_cb: " "Count = %u = %u / %u (%u)\n", @@ -593,14 +593,23 @@ ib_api_status_t osmv_query_sa(IN osm_bind_handle_t h_bind, IN const osmv_query_req_t * const p_query_req) { - osmv_sa_bind_info_t *p_bind = (osmv_sa_bind_info_t *) h_bind; + union { + ib_service_record_t svc_rec; + ib_node_record_t node_rec; + ib_portinfo_record_t port_info; + ib_path_rec_t path_rec; +#ifdef DUAL_SIDED_RMPP + ib_multipath_rec_t multipath_rec; +#endif + ib_class_port_info_t class_port_info; + } u; osmv_sa_mad_data_t sa_mad_data; + osmv_sa_bind_info_t *p_bind = (osmv_sa_bind_info_t *) h_bind; osmv_user_query_t *p_user_query; - ib_service_record_t svc_rec; - ib_node_record_t node_rec; - ib_portinfo_record_t port_info; - ib_path_rec_t path_rec; - ib_class_port_info_t class_port_info; +#ifdef DUAL_SIDED_RMPP + osmv_multipath_req_t *p_mpr_req; + int i, j; +#endif osm_log_t *p_log = p_bind->p_log; ib_api_status_t status; @@ -610,6 +619,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, sa_mad_data.method = IB_MAD_METHOD_GETTABLE; sa_mad_data.attr_mod = 0; + memset((void*)&u, 0, sizeof(u)); + /* Set the MAD attributes and component mask correctly. */ switch (p_query_req->query_type) { @@ -634,7 +645,7 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); sa_mad_data.comp_mask = 0; - sa_mad_data.p_attr = &svc_rec; + sa_mad_data.p_attr = &u.svc_rec; break; case OSMV_QUERY_SVC_REC_BY_NAME: @@ -645,8 +656,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, sa_mad_data.comp_mask = IB_SR_COMPMASK_SNAME; sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); - sa_mad_data.p_attr = &svc_rec; - memcpy(svc_rec.service_name, p_query_req->p_query_input, + sa_mad_data.p_attr = &u.svc_rec; + memcpy(u.svc_rec.service_name, p_query_req->p_query_input, sizeof(ib_svc_name_t)); break; @@ -657,8 +668,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, sa_mad_data.comp_mask = IB_SR_COMPMASK_SID; sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); - sa_mad_data.p_attr = &svc_rec; - svc_rec.service_id = + sa_mad_data.p_attr = &u.svc_rec; + u.svc_rec.service_id = *(ib_net64_t *) (p_query_req->p_query_input); break; @@ -670,7 +681,7 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_class_port_info_t)); sa_mad_data.comp_mask = 0; - sa_mad_data.p_attr = &class_port_info; + sa_mad_data.p_attr = &u.class_port_info; break; @@ -682,8 +693,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_node_record_t)); sa_mad_data.comp_mask = IB_NR_COMPMASK_NODEGUID; - sa_mad_data.p_attr = &node_rec; - node_rec.node_info.node_guid = + sa_mad_data.p_attr = &u.node_rec; + u.node_rec.node_info.node_guid = *(ib_net64_t *) (p_query_req->p_query_input); break; @@ -695,8 +706,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_portinfo_record_t)); sa_mad_data.comp_mask = IB_PIR_COMPMASK_LID; - sa_mad_data.p_attr = &port_info; - port_info.lid = *(ib_net16_t *) (p_query_req->p_query_input); + sa_mad_data.p_attr = &u.port_info; + u.port_info.lid = *(ib_net16_t *) (p_query_req->p_query_input); break; case OSMV_QUERY_PORT_REC_BY_LID_AND_NUM: @@ -746,39 +757,37 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, case OSMV_QUERY_PATH_REC_BY_PORT_GUIDS: osm_log(p_log, OSM_LOG_DEBUG, "osmv_query_sa DBG:001 %s", "PATH_REC_BY_PORT_GUIDS\n"); - memset(&path_rec, 0, sizeof(ib_path_rec_t)); + memset(&u.path_rec, 0, sizeof(ib_path_rec_t)); sa_mad_data.attr_id = IB_MAD_ATTR_PATH_RECORD; sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_path_rec_t)); sa_mad_data.comp_mask = (IB_PR_COMPMASK_DGID | IB_PR_COMPMASK_SGID | IB_PR_COMPMASK_NUMBPATH); - path_rec.num_path = 0x7f; - sa_mad_data.p_attr = &path_rec; - ib_gid_set_default(&path_rec.dgid, + u.path_rec.num_path = 0x7f; + sa_mad_data.p_attr = &u.path_rec; + ib_gid_set_default(&u.path_rec.dgid, ((osmv_guid_pair_t *) (p_query_req-> - p_query_input))-> - dest_guid); - ib_gid_set_default(&path_rec.sgid, + p_query_input))->dest_guid); + ib_gid_set_default(&u.path_rec.sgid, ((osmv_guid_pair_t *) (p_query_req-> - p_query_input))-> - src_guid); + p_query_input))->src_guid); break; case OSMV_QUERY_PATH_REC_BY_GIDS: osm_log(p_log, OSM_LOG_DEBUG, "osmv_query_sa DBG:001 %s", "PATH_REC_BY_GIDS\n"); - memset(&path_rec, 0, sizeof(ib_path_rec_t)); + memset(&u.path_rec, 0, sizeof(ib_path_rec_t)); sa_mad_data.attr_id = IB_MAD_ATTR_PATH_RECORD; sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_path_rec_t)); sa_mad_data.comp_mask = - (IB_PR_COMPMASK_DGID | IB_PR_COMPMASK_SGID | IB_PR_COMPMASK_NUMBPATH); - path_rec.num_path = 0x7f; - sa_mad_data.p_attr = &path_rec; - memcpy(&path_rec.dgid, + (IB_PR_COMPMASK_DGID | IB_PR_COMPMASK_SGID | IB_PR_COMPMASK_NUMBPATH); + u.path_rec.num_path = 0x7f; + sa_mad_data.p_attr = &u.path_rec; + memcpy(&u.path_rec.dgid, &((osmv_gid_pair_t *) (p_query_req->p_query_input))-> dest_gid, sizeof(ib_gid_t)); - memcpy(&path_rec.sgid, + memcpy(&u.path_rec.sgid, &((osmv_gid_pair_t *) (p_query_req->p_query_input))-> src_gid, sizeof(ib_gid_t)); break; @@ -786,18 +795,18 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, case OSMV_QUERY_PATH_REC_BY_LIDS: osm_log(p_log, OSM_LOG_DEBUG, "osmv_query_sa DBG:001 %s", "PATH_REC_BY_LIDS\n"); - memset(&path_rec, 0, sizeof(ib_path_rec_t)); + memset(&u.path_rec, 0, sizeof(ib_path_rec_t)); sa_mad_data.method = IB_MAD_METHOD_GET; sa_mad_data.attr_id = IB_MAD_ATTR_PATH_RECORD; sa_mad_data.attr_offset = ib_get_attr_offset(sizeof(ib_path_rec_t)); sa_mad_data.comp_mask = (IB_PR_COMPMASK_DLID | IB_PR_COMPMASK_SLID); - sa_mad_data.p_attr = &path_rec; - path_rec.dlid = + sa_mad_data.p_attr = &u.path_rec; + u.path_rec.dlid = ((osmv_lid_pair_t *) (p_query_req->p_query_input))-> dest_lid; - path_rec.slid = + u.path_rec.slid = ((osmv_lid_pair_t *) (p_query_req->p_query_input))->src_lid; break; @@ -827,9 +836,50 @@ osmv_query_sa(IN osm_bind_handle_t h_bind, sa_mad_data.p_attr = p_user_query->p_attr; break; +#ifdef DUAL_SIDED_RMPP + case OSMV_QUERY_MULTIPATH_REC: + OSM_LOG(p_log, OSM_LOG_DEBUG, "DBG:001 MULTIPATH_REC\n"); + /* Validate sgid/dgid counts against SA client limit */ + p_mpr_req = (osmv_multipath_req_t *) p_query_req->p_query_input; + if (p_mpr_req->sgid_count + p_mpr_req->dgid_count > + IB_MULTIPATH_MAX_GIDS) { + OSM_LOG(p_log, OSM_LOG_ERROR, "DBG:001 MULTIPATH_REC " + "SGID count %d DGID count %d max count %d\n", + p_mpr_req->sgid_count, p_mpr_req->dgid_count, + IB_MULTIPATH_MAX_GIDS); + CL_ASSERT(0); + return IB_ERROR; + } + memset(&u.multipath_rec, 0, sizeof(ib_multipath_rec_t)); + sa_mad_data.method = IB_MAD_METHOD_GETMULTI; + sa_mad_data.attr_id = IB_MAD_ATTR_MULTIPATH_RECORD; + sa_mad_data.attr_offset = + ib_get_attr_offset(sizeof(ib_multipath_rec_t)); + sa_mad_data.p_attr = &u.multipath_rec; + sa_mad_data.comp_mask = p_mpr_req->comp_mask; + u.multipath_rec.num_path = p_mpr_req->num_path; + if (p_mpr_req->reversible) + u.multipath_rec.num_path |= 0x80; + else + u.multipath_rec.num_path &= ~0x80; + u.multipath_rec.pkey = p_mpr_req->pkey; + ib_multipath_rec_set_sl(&u.multipath_rec, p_mpr_req->sl); + ib_multipath_rec_set_qos_class(&u.multipath_rec, 0); + u.multipath_rec.independence = p_mpr_req->independence; + u.multipath_rec.sgid_count = p_mpr_req->sgid_count; + u.multipath_rec.dgid_count = p_mpr_req->dgid_count; + j = 0; + for (i = 0; i < p_mpr_req->sgid_count; i++, j++) + u.multipath_rec.gids[j] = p_mpr_req->gids[j]; + for (i = 0; i < p_mpr_req->dgid_count; i++, j++) + u.multipath_rec.gids[j] = p_mpr_req->gids[j]; + break; +#endif + default: osm_log(p_log, OSM_LOG_ERROR, - "osmv_query_sa DBG:001 %s", "UNKNOWN\n"); + "osmv_query_sa DBG:001 UNKNOWN 0x%x (%d)\n", + p_query_req->query_type,p_query_req->query_type); CL_ASSERT(0); return IB_ERROR; } -- 2.41.0