Пример #1
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;
}
Пример #2
0
static void setup(char *CA, SInt16 port, int *fd, int *agent)
{
	umad_init();

	*fd = umad_open_port(CA, port);
	if (UNLIKELY((*fd) < 0)) {
		FATAL("umad_open_port() failed with error %d: %s", -(*fd), strerror(-(*fd)));
	}

#define MGMT_VERSION	MAD_HEADER_CLASS_VERSION_SA
#define RMPP_VERSION	1

	*agent = umad_register((*fd), IB_SA_CLASS, MGMT_VERSION, RMPP_VERSION, NULL);
	if (UNLIKELY((*agent) < 0)) {
		FATAL("umad_register() failed with error %d: %s", -(*agent), strerror(-(*agent)));
	}
}
Пример #3
0
static int open_first_opa_hfi(int port_num, char *hfi_name, size_t name_len)
{
	int ca_cnt;
	char hfis[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN];

	ca_cnt = oib_get_hfi_names(hfis, UMAD_MAX_DEVICES);
	if (ca_cnt < 0)
		return ca_cnt;

	ca_cnt = umad_open_port(hfis[0], port_num);

	if (ca_cnt >= 0) {
		strncpy(hfi_name, hfis[0], name_len);
		hfi_name[name_len-1] = '\0';
	}

	return ca_cnt;
}
Пример #4
0
void
madrpc_init(char *dev_name, int dev_port, int *mgmt_classes, int num_classes)
{
	if (umad_init() < 0)
		IBPANIC("can't init UMAD library");

	if ((mad_portid = umad_open_port(dev_name, dev_port)) < 0)
		IBPANIC("can't open UMAD port (%s:%d)", dev_name, dev_port);

	if (num_classes >= MAX_CLASS)
		IBPANIC("too many classes %d requested", num_classes);

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

		if (mgmt == IB_SA_CLASS)
			rmpp_version = 1;
		if (mad_register_client(mgmt, rmpp_version) < 0)
			IBPANIC("client_register for mgmt class %d failed", mgmt);
	}
}
Пример #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;
}
Пример #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);
}