static
bool ztex_lowl_probe(const struct lowlevel_device_info * const info)
{
	const char * const product = info->product;
	const char * const serial = info->serial;
	if (info->lowl != &lowl_usb)
	{
		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
		applog(LOG_DEBUG, "%s: Matched \"%s\" serial \"%s\", but lowlevel driver is not usb!",
		       __func__, product, serial);
		return false;
	}
	
	libusb_device * const usbdev = info->lowl_data;
	
	const enum ztex_check_result err = libztex_checkDevice(usbdev);
	switch (err)
	{
		case CHECK_ERROR:
			applogr(false, LOG_ERR, "%s: Can not check device %s", ztex_drv.dname, info->devid);
		case CHECK_IS_NOT_ZTEX:
			return false;
		case CHECK_OK:
			break;
		case CHECK_RESCAN:
			bfg_need_detect_rescan = true;
			return false;
	}
	
	int fpgacount;
	struct libztex_device *ztex_master;
	struct cgpu_info *ztex;
	
	ztex_master = libztex_prepare_device2(usbdev);
	if (!ztex_master)
		applogr(false, LOG_ERR, "%s: libztex_prepare_device2 failed on %s", ztex_drv.dname, info->devid);
	
	if (bfg_claim_usb(&ztex_drv, true, ztex_master->usbbus, ztex_master->usbaddress))
		return false;
	ztex_master->root = ztex_master;
	fpgacount = libztex_numberOfFpgas(ztex_master);
	ztex_master->handles = fpgacount;
	ztex = ztex_setup(ztex_master, fpgacount);

	if (fpgacount > 1)
		pthread_mutex_init(&ztex->device_ztex->mutex, NULL);
	
	return true;
}
Ejemplo n.º 2
0
static void ztex_detect(void)
{
	int cnt;
	int i,j;
	int fpgacount;
	struct libztex_dev_list **ztex_devices;
	struct libztex_device *ztex_slave;
	struct cgpu_info *ztex;

	cnt = libztex_scanDevices(&ztex_devices);
	if (cnt > 0)
		applog(LOG_WARNING, "Found %d ztex board%s", cnt, cnt > 1 ? "s" : "");

	for (i = 0; i < cnt; i++) {
		ztex = calloc(1, sizeof(struct cgpu_info));
		ztex->api = &ztex_api;
		ztex->device_ztex = ztex_devices[i]->dev;
		ztex->threads = 1;
		ztex->device_ztex->fpgaNum = 0;
		ztex->device_ztex->root = ztex->device_ztex;
		add_cgpu(ztex);

		fpgacount = libztex_numberOfFpgas(ztex->device_ztex);

		if (fpgacount > 1)
			pthread_mutex_init(&ztex->device_ztex->mutex, NULL);

		for (j = 1; j < fpgacount; j++) {
			ztex = calloc(1, sizeof(struct cgpu_info));
			ztex->api = &ztex_api;
			ztex_slave = calloc(1, sizeof(struct libztex_device));
			memcpy(ztex_slave, ztex_devices[i]->dev, sizeof(struct libztex_device));
			ztex->device_ztex = ztex_slave;
			ztex->threads = 1;
			ztex_slave->fpgaNum = j;
			ztex_slave->root = ztex_devices[i]->dev;
			ztex_slave->repr[strlen(ztex_slave->repr) - 1] = ('1' + j);
			add_cgpu(ztex);
		}

		applog(LOG_WARNING,"%s: Found Ztex (fpga count = %d) , mark as %d", ztex->device_ztex->repr, fpgacount, ztex->device_id);
	}

	if (cnt > 0)
		libztex_freeDevList(ztex_devices);
}