Exemplo n.º 1
0
void
mad_rpc_close_port(void *port_id)
{
	struct ibmad_port *p = port_id;

	umad_close_port(p->port_id);
	free(p);
}
Exemplo n.º 2
0
void *
mad_rpc_open_port(char *dev_name, int dev_port,
		  int *mgmt_classes, int num_classes)
{
	struct ibmad_port *p;
	int port_id;

	if (num_classes >= MAX_CLASS) {
		IBWARN("too many classes %d requested", num_classes);
		errno = EINVAL;
		return NULL;
	}

	if (umad_init() < 0) {
		IBWARN("can't init UMAD library");
		errno = ENODEV;
		return NULL;
	}

	p = malloc(sizeof(*p));
	if (!p) {
		errno = ENOMEM;
		return NULL;
	}
	memset(p, 0, sizeof(*p));

	if ((port_id = umad_open_port(dev_name, dev_port)) < 0) {
		IBWARN("can't open UMAD port (%s:%d)", dev_name, dev_port);
		if (!errno)
			errno = EIO;
		free(p);
		return NULL;
	}

	while (num_classes--) {
		int rmpp_version = 0;
		int mgmt = *mgmt_classes++;
		int agent;

		if (mgmt == IB_SA_CLASS)
			rmpp_version = 1;
		if (mgmt < 0 || mgmt >= MAX_CLASS ||
		    (agent = mad_register_port_client(port_id, mgmt,
						      rmpp_version)) < 0) {
			IBWARN("client_register for mgmt %d failed", mgmt);
			if(!errno)
				errno = EINVAL;
			umad_close_port(port_id);
  			free(p);
  			return NULL;
		}
		p->class_agents[mgmt] = agent;
	}

	p->port_id = port_id;
	return p;
}
int main(int argc, char **argv)
{
	char *guid_file = "port_guids.list";
	int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS };
	ib_portid_t dport_id;
	int port, agent;
	uint8_t *umad;
	int len;

	if (argc > 1)
		guid_file = argv[1];

	srcport = mad_rpc_open_port(NULL, 0, mgmt_classes, 2);
	if (!srcport)
		err("Failed to open port");

	resolve_sm_portid(NULL, 0, &dport_id);
	dport_id.qp = 1;
	if (!dport_id.qkey)
		dport_id.qkey = IB_DEFAULT_QP1_QKEY;

	len = umad_size() + 256;
	umad = calloc(1, len);
	if (!umad) {
		err("cannot alloc mem for umad: %s\n", strerror(errno));
		return -1;
	}
	port = mad_rpc_portid(srcport);

	agent = umad_register(port, IB_SA_CLASS, 2, 0, NULL);

	rereg_and_test_port(guid_file, port, agent, &dport_id, TMO);

	free(umad);
	umad_unregister(port, agent);
	umad_close_port(port);
	umad_done();

	return 0;
}
Exemplo n.º 4
0
/** ========================================================================= */
int oib_close_port(struct oib_port *port)
{
	int i,j;

    oib_sa_clear_regs_unsafe(port);

    destroy_sa_qp(port);

	close_verbs_ctx(port);

	for (i = 0; i < OIB_MAX_CLASS_VERSION; i++) {
		for (j = 0; j < OIB_MAX_CLASS; j++) {
			if (port->umad_agents[i][j] != OIB_INVALID_AGENTID) {
				umad_unregister(port->umad_fd, port->umad_agents[i][j]);
			}
		}
	}

	umad_close_port(port->umad_fd);
	sem_destroy(&port->umad_port_cache_lock);
	free(port);

	return 0;
}
Exemplo n.º 5
0
static int port_is_opa(char *hfi_name, int port_num)
{
	int fd;
	int rc;
	int pkey_index;
    uint32_t aid;
	uint8_t base_version;
	umad_port_t umad_port;

	if (umad_get_port(hfi_name, port_num, &umad_port) != 0)
		return 0;

	pkey_index = find_pkey_from_umad_port(&umad_port, 0x7fff);
	umad_release_port(&umad_port);

	if (pkey_index < 0)
		return 0;

    if ((fd = umad_open_port(hfi_name, port_num)) < 0)
		return 0;

	if (register_ib_smi_dr(fd, &aid) != 0) {
		rc = 0;
		goto close;
	}

	base_version = get_base_version_from_ni(fd, aid, pkey_index);

	umad_unregister(fd, (int)aid);

	rc = (base_version == 0x80);

close:
	umad_close_port(fd);
	return rc;
}
/****************************************************************************** 
 * join_multicast_group
 ******************************************************************************/
int join_multicast_group(subn_adm_method method,struct mcast_parameters *params) {

	int portid = -1;
	int agentid = -1;
	void *umad_buff = NULL;
	void *mad = NULL;
	int length = MAD_SIZE;
	int test_result = 0;

	// mlid will be assigned to the new LID after the join 
	if (umad_init() < 0) {
		fprintf(stderr, "failed to init the UMAD library\n");
		goto cleanup;
	}
	/* use casting to loose the "const char0 *" */
	portid = umad_open_port((char*)params->ib_devname,params->ib_port);
	if (portid < 0) {
		fprintf(stderr,"failed to open UMAD port %d\n",params->ib_port);
		goto cleanup;
	}

	agentid = umad_register(portid,MANAGMENT_CLASS_SUBN_ADM, 2, 0, 0);
	if (agentid < 0) {
		fprintf(stderr,"failed to register UMAD agent for MADs\n");
		goto cleanup;
	}

	umad_buff = umad_alloc(1, umad_size() + MAD_SIZE);
	if (!umad_buff) {
		fprintf(stderr, "failed to allocate MAD buffer\n");
		goto cleanup;
	}

	mad = umad_get_mad(umad_buff);
	prepare_mcast_mad(method,params,(struct sa_mad_packet_t *)mad);

	if (umad_set_addr(umad_buff,params->sm_lid,1,params->sm_sl,QP1_WELL_KNOWN_Q_KEY) < 0) {
		fprintf(stderr, "failed to set the destination address of the SMP\n");
		goto cleanup;
	}

	if (umad_send(portid,agentid,umad_buff,MAD_SIZE,100,5) < 0) {
		fprintf(stderr, "failed to send MAD\n");
		goto cleanup;
	}

	if (umad_recv(portid,umad_buff,&length,5000) < 0) {
		fprintf(stderr, "failed to receive MAD response\n");
		goto cleanup;
	}

	if (check_mad_status((struct sa_mad_packet_t*)mad)) {
		fprintf(stderr, "failed to get mlid from MAD\n");
		goto cleanup;
	}

	//  "Join multicast group" message was sent 
	if (method == SUBN_ADM_METHOD_SET) {
		get_mlid_from_mad((struct sa_mad_packet_t*)mad,&params->mlid);
		params->mcast_state |= MCAST_IS_JOINED;

	//  "Leave multicast group" message was sent 
	} else { 
		params->mcast_state &= ~MCAST_IS_JOINED;
	}

cleanup:
	if (umad_buff)
		umad_free(umad_buff);

	if (portid >= 0) {
		if (agentid >= 0) {
			if (umad_unregister(portid, agentid)) {
				fprintf(stderr, "failed to deregister UMAD agent for MADs\n");
				test_result = 1;
			}
		}

		if (umad_close_port(portid)) {
			fprintf(stderr, "failed to close UMAD portid\n");
			test_result = 1;
		}
	}

	return test_result;
}
Exemplo n.º 7
0
/** ========================================================================= */
int oib_open_port(struct oib_port **port, char *hfi_name, uint8_t port_num)
{
	int i,j;
	int err;
	struct oib_port *rc;

	if (init_sub_lib())
		return (EIO);

	if ((rc = calloc(1, sizeof(*rc))) == NULL)
		return (ENOMEM);

    if ((rc->umad_fd = umad_open_port(hfi_name, port_num)) < 0) {
        OUTPUT_ERROR ("can't open UMAD port (%s:%d)\n", hfi_name, port_num);
        err = EIO;
		goto free_rc;
    }

	if (!port_is_opa(hfi_name, port_num)) {
		umad_close_port(rc->umad_fd);

		if (hfi_name) {
			OUTPUT_ERROR ("Port is not OPA (%s:%d)\n", hfi_name, port_num);
			err = EIO;
			goto free_rc;
		}

		/* hfi was wild carded, attempt to open the first OPA HFI */
		rc->umad_fd = open_first_opa_hfi(port_num, rc->hfi_name, sizeof(rc->hfi_name));
		if (rc->umad_fd < 0) {
			OUTPUT_ERROR ("OPA port not found (%d)\n", port_num);
			err = EIO;
			goto free_rc;
		}
	} else if (!hfi_name) {
		/* get the actual name from a null hfi_name */
		umad_port_t umad_port;

		if (umad_get_port(NULL, port_num, &umad_port) < 0) {
			OUTPUT_ERROR ("Failed to get umad port name (<null>:%d)\n", port_num);
			err = EIO;
			goto close_port;
		}

		snprintf(rc->hfi_name, sizeof(rc->hfi_name), "%s", umad_port.ca_name);

		umad_release_port(&umad_port);
	} else {
		snprintf(rc->hfi_name, sizeof(rc->hfi_name), "%s", hfi_name);
	}

	rc->hfi_port_num = port_num;
    rc->num_userspace_recv_buf = DEFAULT_USERSPACE_RECV_BUF;
    rc->num_userspace_send_buf = DEFAULT_USERSPACE_SEND_BUF;

	for (i = 0; i < OIB_MAX_CLASS_VERSION; i++) {
		for (j = 0; j < OIB_MAX_CLASS; j++) {
			rc->umad_agents[i][j] = OIB_INVALID_AGENTID;
		}
	}

	if (sem_init(&rc->umad_port_cache_lock,0,1) != 0) {
		OUTPUT_ERROR("failed to init umad_port_cache_lock\n");
		err = EIO;
        goto close_port;
	}

	if ((err = open_verbs_ctx(rc)) != 0)
		goto destroy_cache_lock;

	if ((err = cache_port_details(rc)) != 0)
		goto close_verbs;

    if ((err = start_port_thread(rc)) != 0)
        goto release_cache;

	rc->hfi_num = oib_get_hfiNum(rc->hfi_name);

    LIST_INIT(&rc->pending_reg_msg_head);
	*port = rc;
	return (0);

release_cache:
    umad_release_port(&rc->umad_port_cache);
close_verbs:
    close_verbs_ctx(rc);
destroy_cache_lock:
    sem_destroy(&rc->umad_port_cache_lock);
close_port:
    umad_close_port(rc->umad_fd);
free_rc:
	free(rc);
	return (err);
}
Exemplo n.º 8
0
static void done(int fd)
{
	umad_close_port(fd);
	umad_done();
}