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;
}
Example #2
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;
}
Example #3
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;
}
/****************************************************************************** 
 * 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;
}
Example #5
0
/** ========================================================================= */
static int bind_single_class(struct oib_port *port,
						struct oib_class_args *mgmt_class, uint64_t *mask)
{
	int rereg = 0;
	int err;
    uint32_t aid;
    struct umad_reg_attr reg_attr;
	uint8_t mclass = mgmt_class->mgmt_class;
	uint8_t class_ver = mgmt_class->class_version;

	if (mclass >= OIB_MAX_CLASS ) {
		OUTPUT_ERROR("bad mgmt class : 0x%x\n", mclass);
		return EINVAL;
	}
	if (class_ver >= OIB_MAX_CLASS_VERSION ) {
		OUTPUT_ERROR("bad mgmt class version : 0x%x\n", class_ver);
		return EINVAL;
	}

	memset(&reg_attr, 0, sizeof(reg_attr));
    reg_attr.mgmt_class = mclass;
    reg_attr.mgmt_class_version = class_ver;
    reg_attr.flags = 0; 
    memcpy(reg_attr.method_mask, mask, sizeof(reg_attr.method_mask));
    reg_attr.rmpp_version = 0;
    if (mgmt_class->oui) {
        //memcpy(&reg_attr.oui, mgmt_class->oui, sizeof(reg_attr.oui));
        reg_attr.oui = ((uint32_t)mgmt_class->oui[0]) << 16;
        reg_attr.oui |= ((uint32_t)mgmt_class->oui[1]) << 8;
        reg_attr.oui |= (uint32_t)(mgmt_class->oui[2]);
    }

	// Exceptions to default values.
	switch (mgmt_class->mgmt_class) {
	case UMAD_CLASS_SUBN_ADM:
		if (!mgmt_class->kernel_rmpp) {
			reg_attr.flags = UMAD_USER_RMPP;
		}
		reg_attr.rmpp_version = 1;
		break;
    default:
		{
			/* Check for all RMPP based vendor classes */
			if (mgmt_class->mgmt_class >= 0x30 && mgmt_class->mgmt_class <= 0x4F)
			{
				if (!mgmt_class->kernel_rmpp) {
					reg_attr.flags = UMAD_USER_RMPP;
				}
				reg_attr.rmpp_version = 1;
			}
			break;
		}
	}

	if (port->umad_agents[class_ver][mclass] != OIB_INVALID_AGENTID) {
		OUTPUT_ERROR("WARNINIG re-register of class 0x%x; version 0x%x; was %d\n",
					mclass, class_ver, port->umad_agents[class_ver][mclass]);
		umad_unregister(port->umad_fd, port->umad_agents[class_ver][mclass]);
		rereg = 1;
	}

	if ((err = umad_register2(port->umad_fd, &reg_attr, &aid)) !=0) {
		OUTPUT_ERROR("Can't register agent for class 0x%x; version 0x%x; %s\n",
					mclass, class_ver, strerror(err));
		return err;
	}

	if (rereg)
		OUTPUT_ERROR("WARNINIG re-register new %d\n", aid);

	// Store the agent id; be able to correlate it to mgmt class/version.
	port->umad_agents[class_ver][mclass] = (int)aid;

    return 0;
}