]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
[OPENSM] Reduce stack consumption by using a union of structs. Code borrowed from...
authorStan Smith <stan.smith@intel.com>
Fri, 21 May 2010 19:36:06 +0000 (19:36 +0000)
committerStan Smith <stan.smith@intel.com>
Fri, 21 May 2010 19:36:06 +0000 (19:36 +0000)
Support OSMV_QUERY_MULTIPATH_REC queries.

signed-off-by: stan smith <stan.smith@intel.com>

git-svn-id: svn://openib.tc.cornell.edu/gen1@2806 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

trunk/ulp/opensm/user/libvendor/osm_vendor_mlx_sa.c

index eea0d0e43006e130b6fbd1af7a120ccab546189d..1f468e64cb30b2628a05d72abb27515f5ebb1e93 100644 (file)
@@ -147,9 +147,9 @@ __osmv_sa_mad_rcv_cb(IN osm_madw_t * p_madw,
                                        "__osmv_sa_mad_rcv_cb: Count = 0\n");\r
                        }\r
                        else {\r
-                               query_res.result_cnt = (uintn_t)\r
-                                       ((p_madw->mad_size - IB_SA_MAD_HDR_SIZE) /\r
-                                        ib_get_attr_size(p_sa_mad->attr_offset));\r
+                               query_res.result_cnt =\r
+                                       (p_madw->mad_size - IB_SA_MAD_HDR_SIZE) /\r
+                                       ib_get_attr_size(p_sa_mad->attr_offset);\r
                                osm_log(p_bind->p_log, OSM_LOG_DEBUG,\r
                                        "__osmv_sa_mad_rcv_cb: "\r
                                        "Count = %u = %u / %u (%u)\n",\r
@@ -593,14 +593,23 @@ ib_api_status_t
 osmv_query_sa(IN osm_bind_handle_t h_bind,\r
              IN const osmv_query_req_t * const p_query_req)\r
 {\r
-       osmv_sa_bind_info_t *p_bind = (osmv_sa_bind_info_t *) h_bind;\r
+       union {\r
+               ib_service_record_t svc_rec;\r
+               ib_node_record_t node_rec;\r
+               ib_portinfo_record_t port_info;\r
+               ib_path_rec_t path_rec;\r
+#ifdef DUAL_SIDED_RMPP\r
+               ib_multipath_rec_t multipath_rec;\r
+#endif\r
+               ib_class_port_info_t class_port_info;\r
+       } u;\r
        osmv_sa_mad_data_t sa_mad_data;\r
+       osmv_sa_bind_info_t *p_bind = (osmv_sa_bind_info_t *) h_bind;\r
        osmv_user_query_t *p_user_query;\r
-       ib_service_record_t svc_rec;\r
-       ib_node_record_t node_rec;\r
-       ib_portinfo_record_t port_info;\r
-       ib_path_rec_t path_rec;\r
-       ib_class_port_info_t class_port_info;\r
+#ifdef DUAL_SIDED_RMPP\r
+       osmv_multipath_req_t *p_mpr_req;\r
+       int i, j;\r
+#endif\r
        osm_log_t *p_log = p_bind->p_log;\r
        ib_api_status_t status;\r
 \r
@@ -610,6 +619,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
        sa_mad_data.method = IB_MAD_METHOD_GETTABLE;\r
        sa_mad_data.attr_mod = 0;\r
 \r
+       memset((void*)&u, 0, sizeof(u));\r
+\r
        /* Set the MAD attributes and component mask correctly. */\r
        switch (p_query_req->query_type) {\r
 \r
@@ -634,7 +645,7 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_service_record_t));\r
                sa_mad_data.comp_mask = 0;\r
-               sa_mad_data.p_attr = &svc_rec;\r
+               sa_mad_data.p_attr = &u.svc_rec;\r
                break;\r
 \r
        case OSMV_QUERY_SVC_REC_BY_NAME:\r
@@ -645,8 +656,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
                sa_mad_data.comp_mask = IB_SR_COMPMASK_SNAME;\r
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_service_record_t));\r
-               sa_mad_data.p_attr = &svc_rec;\r
-               memcpy(svc_rec.service_name, p_query_req->p_query_input,\r
+               sa_mad_data.p_attr = &u.svc_rec;\r
+               memcpy(u.svc_rec.service_name, p_query_req->p_query_input,\r
                       sizeof(ib_svc_name_t));\r
                break;\r
 \r
@@ -657,8 +668,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
                sa_mad_data.comp_mask = IB_SR_COMPMASK_SID;\r
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_service_record_t));\r
-               sa_mad_data.p_attr = &svc_rec;\r
-               svc_rec.service_id =\r
+               sa_mad_data.p_attr = &u.svc_rec;\r
+               u.svc_rec.service_id =\r
                    *(ib_net64_t *) (p_query_req->p_query_input);\r
                break;\r
 \r
@@ -670,7 +681,7 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_class_port_info_t));\r
                sa_mad_data.comp_mask = 0;\r
-               sa_mad_data.p_attr = &class_port_info;\r
+               sa_mad_data.p_attr = &u.class_port_info;\r
 \r
                break;\r
 \r
@@ -682,8 +693,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_node_record_t));\r
                sa_mad_data.comp_mask = IB_NR_COMPMASK_NODEGUID;\r
-               sa_mad_data.p_attr = &node_rec;\r
-               node_rec.node_info.node_guid =\r
+               sa_mad_data.p_attr = &u.node_rec;\r
+               u.node_rec.node_info.node_guid =\r
                    *(ib_net64_t *) (p_query_req->p_query_input);\r
 \r
                break;\r
@@ -695,8 +706,8 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_portinfo_record_t));\r
                sa_mad_data.comp_mask = IB_PIR_COMPMASK_LID;\r
-               sa_mad_data.p_attr = &port_info;\r
-               port_info.lid = *(ib_net16_t *) (p_query_req->p_query_input);\r
+               sa_mad_data.p_attr = &u.port_info;\r
+               u.port_info.lid = *(ib_net16_t *) (p_query_req->p_query_input);\r
                break;\r
 \r
        case OSMV_QUERY_PORT_REC_BY_LID_AND_NUM:\r
@@ -746,39 +757,37 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
        case OSMV_QUERY_PATH_REC_BY_PORT_GUIDS:\r
                osm_log(p_log, OSM_LOG_DEBUG,\r
                        "osmv_query_sa DBG:001 %s", "PATH_REC_BY_PORT_GUIDS\n");\r
-               memset(&path_rec, 0, sizeof(ib_path_rec_t));\r
+               memset(&u.path_rec, 0, sizeof(ib_path_rec_t));\r
                sa_mad_data.attr_id = IB_MAD_ATTR_PATH_RECORD;\r
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_path_rec_t));\r
                sa_mad_data.comp_mask =\r
                    (IB_PR_COMPMASK_DGID | IB_PR_COMPMASK_SGID | IB_PR_COMPMASK_NUMBPATH);\r
-               path_rec.num_path = 0x7f;\r
-               sa_mad_data.p_attr = &path_rec;\r
-               ib_gid_set_default(&path_rec.dgid,\r
+               u.path_rec.num_path = 0x7f;\r
+               sa_mad_data.p_attr = &u.path_rec;\r
+               ib_gid_set_default(&u.path_rec.dgid,\r
                                   ((osmv_guid_pair_t *) (p_query_req->\r
-                                                         p_query_input))->\r
-                                  dest_guid);\r
-               ib_gid_set_default(&path_rec.sgid,\r
+                                                         p_query_input))->dest_guid);\r
+               ib_gid_set_default(&u.path_rec.sgid,\r
                                   ((osmv_guid_pair_t *) (p_query_req->\r
-                                                         p_query_input))->\r
-                                  src_guid);\r
+                                                         p_query_input))->src_guid);\r
                break;\r
 \r
        case OSMV_QUERY_PATH_REC_BY_GIDS:\r
                osm_log(p_log, OSM_LOG_DEBUG,\r
                        "osmv_query_sa DBG:001 %s", "PATH_REC_BY_GIDS\n");\r
-               memset(&path_rec, 0, sizeof(ib_path_rec_t));\r
+               memset(&u.path_rec, 0, sizeof(ib_path_rec_t));\r
                sa_mad_data.attr_id = IB_MAD_ATTR_PATH_RECORD;\r
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_path_rec_t));\r
                sa_mad_data.comp_mask =\r
-                   (IB_PR_COMPMASK_DGID | IB_PR_COMPMASK_SGID | IB_PR_COMPMASK_NUMBPATH);\r
-               path_rec.num_path = 0x7f;\r
-               sa_mad_data.p_attr = &path_rec;\r
-               memcpy(&path_rec.dgid,\r
+                 (IB_PR_COMPMASK_DGID | IB_PR_COMPMASK_SGID | IB_PR_COMPMASK_NUMBPATH);\r
+               u.path_rec.num_path = 0x7f;\r
+               sa_mad_data.p_attr = &u.path_rec;\r
+               memcpy(&u.path_rec.dgid,\r
                       &((osmv_gid_pair_t *) (p_query_req->p_query_input))->\r
                       dest_gid, sizeof(ib_gid_t));\r
-               memcpy(&path_rec.sgid,\r
+               memcpy(&u.path_rec.sgid,\r
                       &((osmv_gid_pair_t *) (p_query_req->p_query_input))->\r
                       src_gid, sizeof(ib_gid_t));\r
                break;\r
@@ -786,18 +795,18 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
        case OSMV_QUERY_PATH_REC_BY_LIDS:\r
                osm_log(p_log, OSM_LOG_DEBUG,\r
                        "osmv_query_sa DBG:001 %s", "PATH_REC_BY_LIDS\n");\r
-               memset(&path_rec, 0, sizeof(ib_path_rec_t));\r
+               memset(&u.path_rec, 0, sizeof(ib_path_rec_t));\r
                sa_mad_data.method = IB_MAD_METHOD_GET;\r
                sa_mad_data.attr_id = IB_MAD_ATTR_PATH_RECORD;\r
                sa_mad_data.attr_offset =\r
                    ib_get_attr_offset(sizeof(ib_path_rec_t));\r
                sa_mad_data.comp_mask =\r
                    (IB_PR_COMPMASK_DLID | IB_PR_COMPMASK_SLID);\r
-               sa_mad_data.p_attr = &path_rec;\r
-               path_rec.dlid =\r
+               sa_mad_data.p_attr = &u.path_rec;\r
+               u.path_rec.dlid =\r
                    ((osmv_lid_pair_t *) (p_query_req->p_query_input))->\r
                    dest_lid;\r
-               path_rec.slid =\r
+               u.path_rec.slid =\r
                    ((osmv_lid_pair_t *) (p_query_req->p_query_input))->src_lid;\r
                break;\r
 \r
@@ -827,9 +836,50 @@ osmv_query_sa(IN osm_bind_handle_t h_bind,
                sa_mad_data.p_attr = p_user_query->p_attr;\r
                break;\r
 \r
+#ifdef DUAL_SIDED_RMPP\r
+       case OSMV_QUERY_MULTIPATH_REC:\r
+               OSM_LOG(p_log, OSM_LOG_DEBUG, "DBG:001 MULTIPATH_REC\n");\r
+               /* Validate sgid/dgid counts against SA client limit */\r
+               p_mpr_req = (osmv_multipath_req_t *) p_query_req->p_query_input;\r
+               if (p_mpr_req->sgid_count + p_mpr_req->dgid_count >\r
+                   IB_MULTIPATH_MAX_GIDS) {\r
+                       OSM_LOG(p_log, OSM_LOG_ERROR, "DBG:001 MULTIPATH_REC "\r
+                               "SGID count %d DGID count %d max count %d\n",\r
+                               p_mpr_req->sgid_count, p_mpr_req->dgid_count,\r
+                               IB_MULTIPATH_MAX_GIDS);\r
+                       CL_ASSERT(0);\r
+                       return IB_ERROR;\r
+               }\r
+               memset(&u.multipath_rec, 0, sizeof(ib_multipath_rec_t));\r
+               sa_mad_data.method = IB_MAD_METHOD_GETMULTI;\r
+               sa_mad_data.attr_id = IB_MAD_ATTR_MULTIPATH_RECORD;\r
+               sa_mad_data.attr_offset =\r
+                   ib_get_attr_offset(sizeof(ib_multipath_rec_t));\r
+               sa_mad_data.p_attr = &u.multipath_rec;\r
+               sa_mad_data.comp_mask = p_mpr_req->comp_mask;\r
+               u.multipath_rec.num_path = p_mpr_req->num_path;\r
+               if (p_mpr_req->reversible)\r
+                       u.multipath_rec.num_path |= 0x80;\r
+               else\r
+                       u.multipath_rec.num_path &= ~0x80;\r
+               u.multipath_rec.pkey = p_mpr_req->pkey;\r
+               ib_multipath_rec_set_sl(&u.multipath_rec, p_mpr_req->sl);\r
+               ib_multipath_rec_set_qos_class(&u.multipath_rec, 0);\r
+               u.multipath_rec.independence = p_mpr_req->independence;\r
+               u.multipath_rec.sgid_count = p_mpr_req->sgid_count;\r
+               u.multipath_rec.dgid_count = p_mpr_req->dgid_count;\r
+               j = 0;\r
+               for (i = 0; i < p_mpr_req->sgid_count; i++, j++)\r
+                       u.multipath_rec.gids[j] = p_mpr_req->gids[j];\r
+               for (i = 0; i < p_mpr_req->dgid_count; i++, j++)\r
+                       u.multipath_rec.gids[j] = p_mpr_req->gids[j];\r
+               break;\r
+#endif\r
+\r
        default:\r
                osm_log(p_log, OSM_LOG_ERROR,\r
-                       "osmv_query_sa DBG:001 %s", "UNKNOWN\n");\r
+                       "osmv_query_sa DBG:001 UNKNOWN 0x%x (%d)\n",\r
+                       p_query_req->query_type,p_query_req->query_type);\r
                CL_ASSERT(0);\r
                return IB_ERROR;\r
        }\r