예제 #1
0
파일: ps4_ib_pp.c 프로젝트: JonBau/pscom
/* INOUT hca_port_idx == -1: scan for first active hca_port */
static
int psib_open_hca_port(IN VAPI_hca_hndl_t hca_hndl, IN int hca_port_idx,
		       OUT VAPI_hca_port_t *hca_port,
		       OUT IB_port_t *hca_port_idx_out)
{
    VAPI_ret_t rc;
    IB_port_t port;

    assert(hca_port);

    if (hca_port_idx > 0) {
	port = hca_port_idx;
	rc = VAPI_query_hca_port_prop(hca_hndl, port, hca_port);
	if (rc != VAPI_OK) goto err_VAPI_query_hca_port_prop;

	if (hca_port->state != PORT_ACTIVE) goto err_linkdown;
    } else {
	port = 1;
	while (1) {
	    rc = VAPI_query_hca_port_prop(hca_hndl, port, hca_port);
	    if (rc == VAPI_OK) {
		if (hca_port->state == PORT_ACTIVE)
		    break;
	    }
	    if (++port > 32) goto err_alllinkdown;
	}
    }

    if (psib_debug) {
	printf("Using HCA Port: %d\n", port);
    }
    *hca_port_idx_out = port;

    return 0;
    /* --- */
 err_alllinkdown:
    psib_err("HCA all Ports are down!");
    return -1;
    /* --- */
 err_linkdown:
    {
	char msg[100];
	snprintf(msg, 99, "HCA Port %d is down!\n", port);
	psib_err(msg);
    }
    return -1;
    /* --- */
 err_VAPI_query_hca_port_prop:
    psib_err_rc("VAPI_query_hca_port_prop() failed", rc);
    return -1;
}
/*
 * Initialize the QP etc.
 * Given in res: port_num, max_outs_sq, max_outs_rq
 */
VAPI_ret_t osmt_mtl_get_qp_resources(IN OUT osmt_mtl_mad_res_t * res)
{
	VAPI_ret_t ret;
	VAPI_hca_port_t hca_port_info;
	VAPI_qp_init_attr_t qp_init_attr;
	VAPI_qp_prop_t qp_prop;
	VAPI_cqe_num_t act_num;

	/* Get HCA LID */
	ret =
	    VAPI_query_hca_port_prop(res->hca_hndl, res->port_num,
				     &hca_port_info);
	VAPI_CHECK_RET;
	res->slid = hca_port_info.lid;

	/* Get a PD */
	ret = VAPI_alloc_pd(res->hca_hndl, &(res->pd_hndl));
	VAPI_CHECK_RET;

	/* Create CQ for RQ and SQ *//* TBD - Check we have enough act nums */
	ret =
	    VAPI_create_cq(res->hca_hndl, res->max_outs_sq + 1,
			   &(res->sq_cq_hndl), &act_num);
	VAPI_CHECK_RET;
	ret =
	    VAPI_create_cq(res->hca_hndl, res->max_outs_rq + 1,
			   &(res->rq_cq_hndl), &act_num);
	VAPI_CHECK_RET;

	/* register event handlers for polling(block mode) internal use */
	/* ret= EVAPI_set_comp_eventh(res->hca_hndl,res->rq_cq_hndl, */
	/*                            EVAPI_POLL_CQ_UNBLOCK_HANDLER,NULL,&(res->rq_cq_eventh)); */
	/* VAPI_CHECK_RET; */
	/* ret= EVAPI_set_comp_eventh(res->hca_hndl,res->sq_cq_hndl, */
	/*                            EVAPI_POLL_CQ_UNBLOCK_HANDLER,NULL,&(res->sq_cq_eventh)); */
	/* VAPI_CHECK_RET; */

	/* Create QP */
	qp_init_attr.cap.max_oust_wr_sq = res->max_outs_sq + 1;
	qp_init_attr.cap.max_oust_wr_rq = res->max_outs_rq + 1;
	qp_init_attr.cap.max_sg_size_sq = 4;
	qp_init_attr.cap.max_sg_size_rq = 4;

	qp_init_attr.pd_hndl = res->pd_hndl;
	qp_init_attr.rdd_hndl = 0;
	qp_init_attr.rq_cq_hndl = res->rq_cq_hndl;
	qp_init_attr.rq_sig_type = VAPI_SIGNAL_ALL_WR;	/* That's default for IB */
	qp_init_attr.sq_cq_hndl = res->sq_cq_hndl;
	qp_init_attr.sq_sig_type = VAPI_SIGNAL_REQ_WR;
	qp_init_attr.ts_type = VAPI_TS_UD;

	ret =
	    VAPI_create_qp(res->hca_hndl, &qp_init_attr, &(res->qp_hndl),
			   &qp_prop);
	VAPI_CHECK_RET;
	res->qp_id.qp_num = qp_prop.qp_num;

	return (VAPI_OK);
}
예제 #3
0
파일: ib.c 프로젝트: carriercomm/ix
int initIB(ArgStruct *p)
{
  VAPI_ret_t          ret;

  /* Open HCA */

  /* open hca just in case it was not opened by system earlier */
  ret = VAPI_open_hca("InfiniHost0", &hca_hndl); 

  ret = EVAPI_get_hca_hndl("InfiniHost0", &hca_hndl);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error opening Infiniband HCA: %s\n", VAPI_strerror(ret));
    return -1;
  } else {
    LOGPRINTF("Opened Infiniband HCA\n");
  }

  /* Get HCA properties */

  port_num=1;
  ret = VAPI_query_hca_port_prop(hca_hndl, (IB_port_t)port_num, 
                                 (VAPI_hca_port_t *)&hca_port);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error querying Infiniband HCA: %s\n", VAPI_strerror(ret));
    return -1;
  } else {
    LOGPRINTF("Queried Infiniband HCA\n");
  }
  lid = hca_port.lid;
  LOGPRINTF("  lid = %d\n", lid);


  /* Allocate Protection Domain */

  ret = VAPI_alloc_pd(hca_hndl, &pd_hndl);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error allocating PD: %s\n", VAPI_strerror(ret));
    return -1;
  } else {
    LOGPRINTF("Allocated Protection Domain\n");
  }


  /* Create send completion queue */
  
  num_cqe = 30000; /* Requested number of completion q elements */
  ret = VAPI_create_cq(hca_hndl, num_cqe, &s_cq_hndl, &act_num_cqe);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error creating send CQ: %s\n", VAPI_strerror(ret));
    return -1;
  } else {
    LOGPRINTF("Created Send Completion Queue with %d elements\n", act_num_cqe);
  }


  /* Create recv completion queue */
  
  num_cqe = 20000; /* Requested number of completion q elements */
  ret = VAPI_create_cq(hca_hndl, num_cqe, &r_cq_hndl, &act_num_cqe);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error creating recv CQ: %s\n", VAPI_strerror(ret));
    return -1;
  } else {
    LOGPRINTF("Created Recv Completion Queue with %d elements\n", act_num_cqe);
  }


  /* Placeholder for MR */


  /* Create Queue Pair */

  qp_init_attr.cap.max_oust_wr_rq = max_wq; /* Max outstanding WR on RQ      */
  qp_init_attr.cap.max_oust_wr_sq = max_wq; /* Max outstanding WR on SQ      */
  qp_init_attr.cap.max_sg_size_rq = 1; /* Max scatter/gather entries on RQ */
  qp_init_attr.cap.max_sg_size_sq = 1; /* Max scatter/gather entries on SQ */
  qp_init_attr.pd_hndl            = pd_hndl; /* Protection domain handle   */
  qp_init_attr.rdd_hndl           = 0; /* Reliable datagram domain handle  */
  qp_init_attr.rq_cq_hndl         = r_cq_hndl; /* CQ handle for RQ         */
  qp_init_attr.rq_sig_type        = VAPI_SIGNAL_REQ_WR; /* Signalling type */
  qp_init_attr.sq_cq_hndl         = s_cq_hndl; /* CQ handle for RQ         */
  qp_init_attr.sq_sig_type        = VAPI_SIGNAL_REQ_WR; /* Signalling type */
  qp_init_attr.ts_type            = IB_TS_RC; /* Transmission type         */
  
  ret = VAPI_create_qp(hca_hndl, &qp_init_attr, &qp_hndl, &qp_prop);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error creating Queue Pair: %s\n", VAPI_strerror(ret));
    return -1;
  } else {
    LOGPRINTF("Created Queue Pair, max outstanding WR on RQ: %d, on SQ: %d\n",
              qp_prop.cap.max_oust_wr_rq, qp_prop.cap.max_oust_wr_sq);
  }


  /* Exchange lid and qp_num with other node */
  
  if( write(p->commfd, &lid, sizeof(lid) ) != sizeof(lid) ) {
    fprintf(stderr, "Failed to send lid over socket\n");
    return -1;
  }
  if( write(p->commfd, &qp_prop.qp_num, sizeof(qp_prop.qp_num) ) != sizeof(qp_prop.qp_num) ) {
    fprintf(stderr, "Failed to send qpnum over socket\n");
    return -1;
  }
  if( read(p->commfd, &d_lid, sizeof(d_lid) ) != sizeof(d_lid) ) {
    fprintf(stderr, "Failed to read lid from socket\n");
    return -1;
  }
  if( read(p->commfd, &d_qp_num, sizeof(d_qp_num) ) != sizeof(d_qp_num) ) {
    fprintf(stderr, "Failed to read qpnum from socket\n");
    return -1;
  }
  
  LOGPRINTF("Local: lid=%d qp_num=%d Remote: lid=%d qp_num=%d\n",
         lid, qp_prop.qp_num, d_lid, d_qp_num);


  /* Bring up Queue Pair */
  
  /******* INIT state ******/

  QP_ATTR_MASK_CLR_ALL(qp_attr_mask);

  qp_attr.qp_state = VAPI_INIT;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_QP_STATE);

  qp_attr.pkey_ix = 0;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_PKEY_IX);

  qp_attr.port = port_num;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_PORT);

  qp_attr.remote_atomic_flags = VAPI_EN_REM_WRITE | VAPI_EN_REM_READ;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_REMOTE_ATOMIC_FLAGS);

  ret = VAPI_modify_qp(hca_hndl, qp_hndl, &qp_attr, &qp_attr_mask, &qp_cap);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error modifying QP to INIT: %s\n", VAPI_strerror(ret));
    return -1;
  }

  LOGPRINTF("Modified QP to INIT\n");

  /******* RTR (Ready-To-Receive) state *******/

  QP_ATTR_MASK_CLR_ALL(qp_attr_mask);

  qp_attr.qp_state = VAPI_RTR;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_QP_STATE);

  qp_attr.qp_ous_rd_atom = 1;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_QP_OUS_RD_ATOM);

  qp_attr.dest_qp_num = d_qp_num;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_DEST_QP_NUM);

  qp_attr.av.sl = 0;
  qp_attr.av.grh_flag = FALSE;
  qp_attr.av.dlid = d_lid;
  qp_attr.av.static_rate = 0;
  qp_attr.av.src_path_bits = 0;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_AV);

  qp_attr.path_mtu = p->prot.ib_mtu;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_PATH_MTU);

  qp_attr.rq_psn = 0;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_RQ_PSN);

  qp_attr.pkey_ix = 0;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_PKEY_IX);

  qp_attr.min_rnr_timer = 5;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_MIN_RNR_TIMER);
  
  ret = VAPI_modify_qp(hca_hndl, qp_hndl, &qp_attr, &qp_attr_mask, &qp_cap);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error modifying QP to RTR: %s\n", VAPI_strerror(ret));
    return -1;
  }

  LOGPRINTF("Modified QP to RTR\n");

  /* Sync before going to RTS state */
  Sync(p);

  /******* RTS (Ready-to-Send) state *******/

  QP_ATTR_MASK_CLR_ALL(qp_attr_mask);

  qp_attr.qp_state = VAPI_RTS;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_QP_STATE);

  qp_attr.sq_psn = 0;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_SQ_PSN);

  qp_attr.timeout = 31;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_TIMEOUT);

  qp_attr.retry_count = 1;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_RETRY_COUNT);

  qp_attr.rnr_retry = 1;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_RNR_RETRY);

  qp_attr.ous_dst_rd_atom = 1;
  QP_ATTR_MASK_SET(qp_attr_mask, QP_ATTR_OUS_DST_RD_ATOM);

  ret = VAPI_modify_qp(hca_hndl, qp_hndl, &qp_attr, &qp_attr_mask, &qp_cap);
  if(ret != VAPI_OK) {
    fprintf(stderr, "Error modifying QP to RTS: %s\n", VAPI_strerror(ret));
    return -1;
  }
  
  LOGPRINTF("Modified QP to RTS\n");

  /* If using event completion, register event completion handler and request
   * the initial notification
   */
  if( p->prot.comptype == NP_COMP_EVENT ) {

    EVAPI_set_comp_eventh(hca_hndl, r_cq_hndl, event_handler, p, &ceh_hndl);
    VAPI_req_comp_notif(hca_hndl, r_cq_hndl, VAPI_NEXT_COMP);

  }
 
  return 0;
}
예제 #4
0
/**********************************************************************
 * 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);
}