/* if hca_name == NULL choose first HCA */ static int psib_open_hca(IN char *hca_name, OUT VAPI_hca_hndl_t *hca_hndl) { VAPI_hca_id_t hca_id; VAPI_ret_t rc; assert(hca_hndl != NULL); if (psib_get_hca_name(&hca_id, hca_name)) goto err_hca_name; /* try to get a handle to the given hca_id */ rc = EVAPI_get_hca_hndl(hca_id, hca_hndl); if (rc != VAPI_SUCCESS) goto err_EVAPI_get_hca_hndl; if (psib_debug > 1) { VAPI_hca_vendor_t hca_vendor; /* ?? */ VAPI_hca_cap_t hca_cap; /* HCA capabilities */ rc = VAPI_query_hca_cap(*hca_hndl, &hca_vendor, &hca_cap); if (rc != VAPI_SUCCESS) goto err_VAPI_query_hca_cap; print_hca_cap(&hca_vendor, &hca_cap); } return 0; /* --- */ err_VAPI_query_hca_cap: EVAPI_release_hca_hndl(*hca_hndl); psib_err_rc("VAPI_query_hca_cap() failed", rc); return -1; /* --- */ err_EVAPI_get_hca_hndl: psib_err_rc("EVAPI_get_hca_hndl() failed", rc); return -1; /* --- */ err_hca_name: return -1; }
ib_api_status_t osm_vendor_get_guid_ca_and_port(IN osm_vendor_t * const p_vend, IN ib_net64_t const guid, OUT VAPI_hca_hndl_t * p_hca_hndl, OUT VAPI_hca_id_t * p_hca_id, OUT uint8_t * p_hca_idx, OUT uint32_t * p_port_num) { ib_api_status_t status; VAPI_hca_id_t *p_ca_ids = NULL; VAPI_ret_t vapi_res; VAPI_hca_hndl_t hca_hndl; VAPI_hca_vendor_t hca_vendor; VAPI_hca_cap_t hca_cap; IB_gid_t *p_port_gid = NULL; uint16_t maxNumGids; ib_net64_t port_guid; uint32_t ca, portIdx, ca_count; OSM_LOG_ENTER(p_vend->p_log); CL_ASSERT(p_vend); /* * 1) Determine the number of CA's * 2) Allocate an array big enough to hold the ca info objects. * 3) Call again to retrieve the guids. */ status = __osm_vendor_get_ca_ids(p_vend, &p_ca_ids, &ca_count); if (status != IB_SUCCESS) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "osm_vendor_get_guid_ca_and_port: ERR 3D16: " "Fail to get CA Ids.\n"); goto Exit; } /* * For each CA, retrieve the CA info attributes */ for (ca = 0; ca < ca_count; ca++) { /* get the HCA handle */ vapi_res = EVAPI_get_hca_hndl(p_ca_ids[ca], &hca_hndl); if (vapi_res != VAPI_OK) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "osm_vendor_get_guid_ca_and_port: ERR 3D17: " "Fail to get HCA handle (%u).\n", vapi_res); goto Exit; } /* get the CA attributes - to know how many ports it has: */ if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) { osm_log(p_vend->p_log, OSM_LOG_DEBUG, "osm_vendor_get_guid_ca_and_port: " "Querying CA %s.\n", p_ca_ids[ca]); } /* query and get the HCA capability */ vapi_res = VAPI_query_hca_cap(hca_hndl, &hca_vendor, &hca_cap); if (vapi_res != VAPI_OK) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "osm_vendor_get_guid_ca_and_port: ERR 3D18: " "Fail to get HCA Capabilities (%u).\n", vapi_res); goto Exit; } /* go over all ports - to obtail their guids */ for (portIdx = 0; portIdx < hca_cap.phys_port_num; portIdx++) { vapi_res = VAPI_query_hca_gid_tbl(hca_hndl, portIdx + 1, 0, &maxNumGids, NULL); p_port_gid = (IB_gid_t *) malloc(maxNumGids * sizeof(IB_gid_t)); /* get the port guid */ vapi_res = VAPI_query_hca_gid_tbl(hca_hndl, portIdx + 1, maxNumGids, &maxNumGids, p_port_gid); if (vapi_res != VAPI_OK) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "osm_vendor_get_guid_ca_and_port: ERR 3D19: " "Fail to get HCA Port GID (%d).\n", vapi_res); goto Exit; } /* convert to SF style */ __osm_vendor_gid_to_guid(p_port_gid[0], (VAPI_gid_t *) & port_guid); /* finally did we find it ? */ if (port_guid == guid) { *p_hca_hndl = hca_hndl; memcpy(p_hca_id, p_ca_ids[ca], sizeof(VAPI_hca_id_t)); *p_hca_idx = ca; *p_port_num = portIdx + 1; status = IB_SUCCESS; goto Exit; } free(p_port_gid); p_port_gid = NULL; } /* ALL PORTS */ } /* all HCAs */ osm_log(p_vend->p_log, OSM_LOG_ERROR, "osm_vendor_get_guid_ca_and_port: ERR 3D20: " "Fail to find HCA and Port for Port Guid 0x%" PRIx64 "\n", cl_ntoh64(guid)); status = IB_INVALID_GUID; Exit: if (p_ca_ids != NULL) free(p_ca_ids); if (p_port_gid != NULL) free(p_port_gid); OSM_LOG_EXIT(p_vend->p_log); return (status); }
/********************************************************************** * Initialize an Info Struct for the Given HCA by its Id **********************************************************************/ static ib_api_status_t __osm_ca_info_init(IN osm_vendor_t * const p_vend, IN VAPI_hca_id_t ca_id, OUT osm_ca_info_t * const p_ca_info) { ib_api_status_t status = IB_ERROR; VAPI_ret_t vapi_res; VAPI_hca_hndl_t hca_hndl; VAPI_hca_vendor_t hca_vendor; VAPI_hca_cap_t hca_cap; VAPI_hca_port_t hca_port; uint8_t port_num; IB_gid_t *p_port_gid; uint16_t maxNumGids; OSM_LOG_ENTER(p_vend->p_log); /* get the HCA handle */ vapi_res = EVAPI_get_hca_hndl(ca_id, &hca_hndl); if (vapi_res != VAPI_OK) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "__osm_ca_info_init: ERR 3D05: " "Fail to get HCA handle (%u).\n", vapi_res); goto Exit; } if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) { osm_log(p_vend->p_log, OSM_LOG_DEBUG, "__osm_ca_info_init: " "Querying CA %s.\n", ca_id); } /* query and get the HCA capability */ vapi_res = VAPI_query_hca_cap(hca_hndl, &hca_vendor, &hca_cap); if (vapi_res != VAPI_OK) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "__osm_ca_info_init: ERR 3D06: " "Fail to get HCA Capabilities (%u).\n", vapi_res); goto Exit; } /* get the guid of the HCA */ memcpy(&(p_ca_info->guid), hca_cap.node_guid, 8 * sizeof(u_int8_t)); p_ca_info->attr_size = 1; p_ca_info->p_attr = (ib_ca_attr_t *) malloc(sizeof(ib_ca_attr_t)); memcpy(&(p_ca_info->p_attr->ca_guid), hca_cap.node_guid, 8 * sizeof(u_int8_t)); /* now obtain the attributes of the ports */ p_ca_info->p_attr->num_ports = hca_cap.phys_port_num; p_ca_info->p_attr->p_port_attr = (ib_port_attr_t *) malloc(hca_cap.phys_port_num * sizeof(ib_port_attr_t)); for (port_num = 0; port_num < p_ca_info->p_attr->num_ports; port_num++) { /* query the port attributes */ vapi_res = VAPI_query_hca_port_prop(hca_hndl, port_num + 1, &hca_port); if (vapi_res != VAPI_OK) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "__osm_ca_info_init: ERR 3D07: " "Fail to get HCA Port Attributes (%d).\n", vapi_res); goto Exit; } /* first call to know the size of the gid table */ vapi_res = VAPI_query_hca_gid_tbl(hca_hndl, port_num + 1, 0, &maxNumGids, NULL); p_port_gid = (IB_gid_t *) malloc(maxNumGids * sizeof(IB_gid_t)); vapi_res = VAPI_query_hca_gid_tbl(hca_hndl, port_num + 1, maxNumGids, &maxNumGids, p_port_gid); if (vapi_res != VAPI_OK) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "__osm_ca_info_init: ERR 3D12: " "Fail to get HCA Port GID (%d).\n", vapi_res); goto Exit; } __osm_vendor_gid_to_guid(p_port_gid[0], (IB_gid_t *) & p_ca_info->p_attr-> p_port_attr[port_num].port_guid); p_ca_info->p_attr->p_port_attr[port_num].lid = hca_port.lid; p_ca_info->p_attr->p_port_attr[port_num].link_state = hca_port.state; p_ca_info->p_attr->p_port_attr[port_num].sm_lid = hca_port.sm_lid; free(p_port_gid); } status = IB_SUCCESS; Exit: OSM_LOG_EXIT(p_vend->p_log); return (status); }