static gboolean
poll_orientation (gpointer user_data)
{
    DrvData *data = user_data;
    int accel_x, accel_y, accel_z;
    AccelReadings readings;

    accel_x = sysfs_get_int (data->dev, "in_accel_x_raw") * data->scale;
    accel_y = sysfs_get_int (data->dev, "in_accel_y_raw") * data->scale;
    accel_z = sysfs_get_int (data->dev, "in_accel_z_raw") * data->scale;

    //FIXME report errors
    if (g_strcmp0 ("i2c-SMO8500:00", g_udev_device_get_sysfs_attr (data->dev, "name")) == 0) {
        /* Quirk for i2c-SMO8500:00 device,
         * swap x and y */
        readings.accel_x = accel_y;
        readings.accel_y = accel_x;
        readings.accel_z = accel_z;
    } else {
        readings.accel_x = accel_x;
        readings.accel_y = accel_y;
        readings.accel_z = accel_z;
    }

    drv_data->callback_func (&iio_poll_accel, (gpointer) &readings, drv_data->user_data);

    return G_SOURCE_CONTINUE;
}
예제 #2
0
static int fill_tgt_context(char *subsys, char *id,
			    struct boot_context *context)
{
	int rc;

	rc = sysfs_get_int(id, subsys, "flags", &context->target_flags);
	/*
	 * Per spec we would need to check against Bit 0
	 * (Block Valid Flag), but some firmware only
	 * sets Bit 1 (Firmware Booting Selected).
	 * So any setting is deemed okay.
	 */
	if (!rc && (context->nic_flags == 0))
		rc = ENODEV;
	if (rc)
		return rc;

	rc = sysfs_get_str(id, subsys, "target-name", context->targetname,
			   sizeof(context->targetname));
	if (rc)
		return rc;

	rc = sysfs_get_str(id, subsys, "ip-addr", context->target_ipaddr,
			   sizeof(context->target_ipaddr));
	if (rc)
		return rc;

	memset(&context->boot_target, 0, sizeof(context->boot_target));
	snprintf(context->boot_target, sizeof(context->boot_target), "%s", id);

	/*
	 * We can live without the rest of they do not exist. If we
	 * failed to get them we will figure it out when we login.
	 */
	if (sysfs_get_int(id, subsys, "port", &context->target_port))
		context->target_port = ISCSI_LISTEN_PORT;

	sysfs_get_str(id, subsys, "lun", context->lun,
		      sizeof(context->lun));
	sysfs_get_str(id, subsys, "chap-name", context->chap_name,
		      sizeof(context->chap_name));
	sysfs_get_str(id, subsys, "chap-secret", context->chap_password,
		      sizeof(context->chap_password));
	sysfs_get_str(id, subsys, "rev-chap-name", context->chap_name_in,
		      sizeof(context->chap_name_in));
	sysfs_get_str(id, subsys, "rev-chap-name-secret",
		      context->chap_password_in,
		      sizeof(context->chap_password_in));
	return 0;
}
예제 #3
0
static int find_boot_flag(char *subsys, char *list[], ssize_t size,
			  int *boot_idx)
{
	int rc = ENODEV;
	int i, flag = 0;

	for (i = 0; i < size; i++, flag = -1) {
		rc = sysfs_get_int(list[i], subsys, "flags", &flag);
		if (rc)
			continue;

		if (flag & IBFT_SYSFS_FLAG_FW_SEL_BOOT) {
			*boot_idx = i;
			rc = 0;
			break;
		}
		rc = ENODEV;
		flag = 0;

	}

	return rc;
}
예제 #4
0
static int get_targets(struct list_head *list, char *rootdir, char *subsys)
{
	struct boot_context *context;
	int rc = 0, i, nic_idx, nic;
	char initiator_dir[FILENAMESZ];

	memset(&initiator_dir, 0 , FILENAMESZ);
	snprintf(initiator_dir, FILENAMESZ, "%sinitiator", rootdir);

	if (!file_exist(initiator_dir))
		return ENODEV;

	nic_cnt = 0;
	tgt_cnt = 0;

	/* Find the targets and the ethernets */
	nftw(rootdir, find_sysfs_dirs, 20, 1);
	for (i = 0; i < tgt_cnt; i++) {
		context = calloc(1, sizeof(*context));
		if (!context) {
			rc = ENOMEM;
			break;
		}

		rc = fill_tgt_context(subsys, target_list[i], context);
		if (rc)
			goto cleanup;

		rc = sysfs_get_int(target_list[i], subsys, "nic-assoc",
				   &nic_idx);
		if (rc)
			goto cleanup;

		for (nic = 0; nic < nic_cnt; nic++) {
			int id;

			rc = sysfs_get_int(nic_list[nic], subsys, "index",
					   &id);
			if (!rc && (id == nic_idx))
				break;
		}

		if (nic == nic_cnt) {
			printf("Invalid nic-assoc of %d. Max id %d.\n",
			       nic_idx, nic_cnt);
			goto cleanup;
		}

		rc = fill_nic_context(subsys, nic_list[nic], context);
		if (rc)
			goto cleanup;

		fill_initiator_context(subsys, context);
		list_add_tail(&context->list, list);
		continue;
cleanup:
		free(context);
		context = NULL;
	}

	if (rc) {
		if (context)
			free(context);
		/*
		 * If there are some valid targets return them. Most likely,
		 * the driver/ibft-implementation reported partial info
		 * for targets/initiators that were not used for boot.
		 */
		if (!list_empty(list))
			rc = 0;
	}

	deallocate_lists();
	return rc;
}
예제 #5
0
/*
 * Routines to fill in the context values.
 */
static int fill_nic_context(char *subsys, char *id,
			    struct boot_context *context)
{
	int rc;

	rc = sysfs_get_int(id, subsys, "flags", &context->nic_flags);
	/*
	 * Per spec we would need to check against Bit 0
	 * (Block Valid Flag), but some firmware only
	 * sets Bit 1 (Firmware Booting Selected).
	 * So any setting is deemed okay.
	 */
	if (!rc && (context->nic_flags == 0))
		rc = ENODEV;
	if (rc)
		return rc;

	rc = sysfs_get_str(id, subsys, "mac", context->mac,
			   sizeof(context->mac));
	if (rc)
		return rc;

	/*
	 * Some offload cards like bnx2i use different MACs for the net and
	 * iscsi functions, so we have to follow the sysfs links.
	 *
	 * Other ibft implementations may not be tied to a pci function,
	 * so there will not be any device/net link, so we drop down to
	 * the MAC matching.
	 *
	 * And finally, some cards like be2iscsi and qla4xxx do not have
	 * any linux network subsys representation. These hosts will
	 * not have the ibft subsys. Instead the subsys is the scsi host
	 * number.
	 */
	if (!strcmp(IBFT_SUBSYS, subsys)) {
		rc = get_iface_from_device(id, context);
		if (rc) {
			rc = net_get_netdev_from_hwaddress(context->mac,
							   context->iface);
			if (rc)
				return rc;
		}
	} else
		strlcpy(context->scsi_host_name, subsys,
			sizeof(context->scsi_host_name));

	memset(&context->boot_nic, 0, sizeof(context->boot_nic));
	snprintf(context->boot_nic, sizeof(context->boot_nic), "%s", id);

	sysfs_get_str(id, subsys, "ip-addr", context->ipaddr,
		      sizeof(context->ipaddr));
	sysfs_get_str(id, subsys, "vlan", context->vlan,
		      sizeof(context->vlan));
	sysfs_get_str(id, subsys, "subnet-mask", context->mask,
		      sizeof(context->mask));
	sysfs_get_str(id, subsys, "gateway", context->gateway,
		      sizeof(context->gateway));
	sysfs_get_str(id, subsys, "primary-dns", context->primary_dns,
		      sizeof(context->primary_dns));
	sysfs_get_str(id, subsys, "secondary-dns", context->secondary_dns,
		      sizeof(context->secondary_dns));
	sysfs_get_str(id, subsys, "dhcp", context->dhcp,
		      sizeof(context->dhcp));
	sysfs_get_int(id, subsys, "origin", (int *)&context->origin);
	return 0;
}