Browse Source

USB move usbdev info that needs to stay around into usbinfo

Kano 13 years ago
parent
commit
7fbc3770b4
6 changed files with 62 additions and 55 deletions
  1. 2 2
      api.c
  2. 12 12
      driver-bitforce.c
  3. 12 12
      driver-modminer.c
  4. 1 2
      miner.h
  5. 26 25
      usbutils.c
  6. 9 2
      usbutils.h

+ 2 - 2
api.c

@@ -1575,7 +1575,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
 		root = api_add_diff(root, "Difficulty Rejected", &(cgpu->diff_rejected), false);
 		root = api_add_diff(root, "Last Share Difficulty", &(cgpu->last_share_diff), false);
 #if defined(USE_MODMINER) || defined(USE_BITFORCE)
-		root = api_add_bool(root, "No Device", &(cgpu->nodev), false);
+		root = api_add_bool(root, "No Device", &(cgpu->usbinfo.nodev), false);
 #endif
 
 		root = print_data(root, buf, isjson, precom);
@@ -1793,7 +1793,7 @@ static void pgaenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
 #endif
 
 #if defined(USE_MODMINER) || defined(USE_BITFORCE)
-	if (cgpu->nodev) {
+	if (cgpu->usbinfo.nodev) {
 		message(io_data, MSG_USBNODEV, id, NULL, isjson);
 		return;
 	}

+ 12 - 12
driver-bitforce.c

@@ -92,7 +92,7 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
 		applog(LOG_DEBUG, "%s%i: reset got err %d",
 			bitforce->drv->name, bitforce->device_id, err);
 
-	if (bitforce->nodev)
+	if (bitforce->usbinfo.nodev)
 		goto failed;
 
 	// Set data control
@@ -102,7 +102,7 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
 		applog(LOG_DEBUG, "%s%i: setdata got err %d",
 			bitforce->drv->name, bitforce->device_id, err);
 
-	if (bitforce->nodev)
+	if (bitforce->usbinfo.nodev)
 		goto failed;
 
 	// Set the baud
@@ -113,7 +113,7 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
 		applog(LOG_DEBUG, "%s%i: setbaud got err %d",
 			bitforce->drv->name, bitforce->device_id, err);
 
-	if (bitforce->nodev)
+	if (bitforce->usbinfo.nodev)
 		goto failed;
 
 	// Set Flow Control
@@ -123,7 +123,7 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
 		applog(LOG_DEBUG, "%s%i: setflowctrl got err %d",
 			bitforce->drv->name, bitforce->device_id, err);
 
-	if (bitforce->nodev)
+	if (bitforce->usbinfo.nodev)
 		goto failed;
 
 	// Set Modem Control
@@ -133,7 +133,7 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
 		applog(LOG_DEBUG, "%s%i: setmodemctrl got err %d",
 			bitforce->drv->name, bitforce->device_id, err);
 
-	if (bitforce->nodev)
+	if (bitforce->usbinfo.nodev)
 		goto failed;
 
 	// Clear any sent data
@@ -143,7 +143,7 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
 		applog(LOG_DEBUG, "%s%i: purgetx got err %d",
 			bitforce->drv->name, bitforce->device_id, err);
 
-	if (bitforce->nodev)
+	if (bitforce->usbinfo.nodev)
 		goto failed;
 
 	// Clear any received data
@@ -178,14 +178,14 @@ static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devic
 	if (!usb_init(bitforce, dev, found)) {
 		applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
 			bitforce->drv->dname,
-			(int)libusb_get_bus_number(dev),
-			(int)libusb_get_device_address(dev));
+			(int)(bitforce->usbinfo.bus_number),
+			(int)(bitforce->usbinfo.device_address));
 		goto shin;
 	}
 
 	sprintf(devpath, "%d:%d",
-			(int)(bitforce->usbdev->bus_number),
-			(int)(bitforce->usbdev->device_address));
+			(int)(bitforce->usbinfo.bus_number),
+			(int)(bitforce->usbinfo.device_address));
 
 
 	// Allow 2 complete attempts if the 1st time returns an unrecognised reply
@@ -361,7 +361,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
 	char *s;
 
 	// Device is gone
-	if (bitforce->nodev)
+	if (bitforce->usbinfo.nodev)
 		return false;
 
 	/* Do not try to get the temperature if we're polling for a result to
@@ -683,7 +683,7 @@ static int64_t bitforce_scanhash(struct thr_info *thr, struct work *work, int64_
 	int64_t ret;
 
 	// Device is gone
-	if (bitforce->nodev)
+	if (bitforce->usbinfo.nodev)
 		return -1;
 
 	send_ret = bitforce_send_work(thr, work);

+ 12 - 12
driver-modminer.c

@@ -129,14 +129,14 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
 	if (!usb_init(modminer, dev, found)) {
 		applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
 			modminer->drv->dname,
-			(int)libusb_get_bus_number(dev),
-			(int)libusb_get_device_address(dev));
+			(int)(modminer->usbinfo.bus_number),
+			(int)(modminer->usbinfo.device_address));
 		goto shin;
 	}
 
 	sprintf(devpath, "%d:%d",
-			(int)(modminer->usbdev->bus_number),
-			(int)(modminer->usbdev->device_address));
+			(int)(modminer->usbinfo.bus_number),
+			(int)(modminer->usbinfo.device_address));
 
 	do_ping(modminer);
 
@@ -204,15 +204,15 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
 		tmp->name = devname;
 
 		sprintf(devpath, "%d:%d:%d",
-			(int)(modminer->usbdev->bus_number),
-			(int)(modminer->usbdev->device_address),
+			(int)(modminer->usbinfo.bus_number),
+			(int)(modminer->usbinfo.device_address),
 			i);
 
 		tmp->device_path = strdup(devpath);
 		tmp->usbdev = modminer->usbdev;
 		// Only the first copy gets the already used stats
 		if (!added)
-			tmp->usbstat = modminer->usbstat;
+			tmp->usbinfo.usbstat = modminer->usbinfo.usbstat;
 		tmp->fpgaid = (char)i;
 		tmp->modminer_mutex = modminer->modminer_mutex;
 		tmp->deven = DEV_ENABLED;
@@ -640,7 +640,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te
 	int err, amount;
 
 	// Device is gone
-	if (modminer->nodev)
+	if (modminer->usbinfo.nodev)
 		return clocknodev;
 
 	// Only do once if multiple shares per work or multiple reasons
@@ -828,7 +828,7 @@ static void check_temperature(struct thr_info *thr)
 	int amount;
 
 	// Device is gone
-	if (modminer->nodev)
+	if (modminer->usbinfo.nodev)
 		return;
 
 	if (state->one_byte_temp) {
@@ -916,7 +916,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
 	int temploop;
 
 	// Device is gone
-	if (modminer->nodev)
+	if (modminer->usbinfo.nodev)
 		return -1;
 
 	// If we are overheated it will just keep checking for results
@@ -1079,7 +1079,7 @@ static int64_t modminer_scanhash(struct thr_info *thr, struct work *work, int64_
 	struct timeval tv1, tv2;
 
 	// Device is gone
-	if (thr->cgpu->nodev)
+	if (thr->cgpu->usbinfo.nodev)
 		return -1;
 
 	// Don't start new work if overheated
@@ -1092,7 +1092,7 @@ static int64_t modminer_scanhash(struct thr_info *thr, struct work *work, int64_
 			check_temperature(thr);
 
 			// Device is gone
-			if (thr->cgpu->nodev)
+			if (thr->cgpu->usbinfo.nodev)
 				return -1;
 
 			if (state->overheated == true) {

+ 1 - 2
miner.h

@@ -400,8 +400,7 @@ struct cgpu_info {
 #endif
 	};
 #if defined(USE_MODMINER) || defined(USE_BITFORCE)
-	int usbstat;
-	bool nodev;
+	struct cg_usb_info usbinfo;
 #endif
 #ifdef USE_MODMINER
 	char fpgaid;

+ 26 - 25
usbutils.c

@@ -641,7 +641,7 @@ static void add_used(libusb_device *dev, bool lock)
 			mutex_unlock(list_lock);
 
 		sprintf(buf, "add_used() duplicate bus_number %d device_address %d",
-				bus_number, device_address);
+				(int)bus_number, (int)device_address);
 		quit(1, buf);
 	}
 
@@ -692,7 +692,7 @@ static void release(uint8_t bus_number, uint8_t device_address, bool lock)
 			mutex_unlock(list_lock);
 
 		sprintf(buf, "release() unknown: bus_number %d device_address %d",
-				bus_number, device_address);
+				(int)bus_number, (int)device_address);
 		quit(1, buf);
 	}
 
@@ -752,26 +752,26 @@ void usb_uninit(struct cgpu_info *cgpu)
 void release_cgpu(struct cgpu_info *cgpu)
 {
 	struct cg_usb_device *cgusb = cgpu->usbdev;
-	uint8_t bus_number;
-	uint8_t device_address;
 	int i;
 
-	cgpu->nodev = true;
+	cgpu->usbinfo.nodev = true;
+	cgpu->usbinfo.nodev_count++;
+	gettimeofday(&(cgpu->usbinfo.last_nodev), NULL);
 
 	// Any devices sharing the same USB device should be marked also
 	// Currently only MMQ shares a USB device
 	for (i = 0; i < total_devices; i++)
 		if (devices[i] != cgpu && devices[i]->usbdev == cgusb) {
-			devices[i]->nodev = true;
+			devices[i]->usbinfo.nodev = true;
+			devices[i]->usbinfo.nodev_count++;
+			memcpy(&(devices[i]->usbinfo.last_nodev),
+				&(cgpu->usbinfo.last_nodev), sizeof(struct timeval));
 			devices[i]->usbdev = NULL;
 		}
 
-	bus_number = cgusb->bus_number;
-	device_address = cgusb->device_address;
-
 	usb_uninit(cgpu);
 
-	release(bus_number, device_address, true);
+	release(cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address, true);
 }
 
 bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found)
@@ -783,12 +783,12 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
 	unsigned char strbuf[STRBUFLEN+1];
 	int err, i, j, k;
 
+	cgpu->usbinfo.bus_number = libusb_get_bus_number(dev);
+	cgpu->usbinfo.device_address = libusb_get_device_address(dev);
+
 	cgusb = calloc(1, sizeof(*cgusb));
 	cgusb->found = found;
 
-	cgusb->bus_number = libusb_get_bus_number(dev);
-	cgusb->device_address = libusb_get_device_address(dev);
-
 	cgusb->descriptor = calloc(1, sizeof(*(cgusb->descriptor)));
 
 	err = libusb_get_device_descriptor(dev, cgusb->descriptor);
@@ -828,7 +828,8 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
 		switch(err) {
 			case LIBUSB_ERROR_BUSY:
 				applog(LOG_WARNING, "USB init, %s device %d:%d in use",
-						found->name, cgusb->bus_number, cgusb->device_address);
+						found->name, (int)(cgpu->usbinfo.bus_number),
+						(int)(cgpu->usbinfo.device_address));
 				break;
 			default:
 				applog(LOG_DEBUG, "USB init, failed to set config to %d, err %d",
@@ -908,7 +909,7 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
 //	cgusb->fwVersion <- for temp1/temp2 decision? or serial? (driver-modminer.c)
 //	cgusb->interfaceVersion
 
-	applog(LOG_DEBUG, "USB init device bus_number=%d device_address=%d usbver=%04x prod='%s' manuf='%s' serial='%s'", (int)(cgusb->bus_number), (int)(cgusb->device_address), cgusb->usbver, cgusb->prod_string, cgusb->manuf_string, cgusb->serial_string);
+	applog(LOG_DEBUG, "USB init device bus_number=%d device_address=%d usbver=%04x prod='%s' manuf='%s' serial='%s'", (int)(cgpu->usbinfo.bus_number), (int)(cgpu->usbinfo.device_address), cgusb->usbver, cgusb->prod_string, cgusb->manuf_string, cgusb->serial_string);
 
 	cgpu->usbdev = cgusb;
 
@@ -1134,7 +1135,7 @@ static void newstats(struct cgpu_info *cgpu)
 {
 	int i;
 
-	cgpu->usbstat = ++next_stat;
+	cgpu->usbinfo.usbstat = ++next_stat;
 
 	usb_stats = realloc(usb_stats, sizeof(*usb_stats) * next_stat);
 	usb_stats[next_stat-1].name = cgpu->drv->name;
@@ -1148,11 +1149,11 @@ static void newstats(struct cgpu_info *cgpu)
 void update_usb_stats(__maybe_unused struct cgpu_info *cgpu)
 {
 #if DO_USB_STATS
-	if (cgpu->usbstat < 1)
+	if (cgpu->usbinfo.usbstat < 1)
 		newstats(cgpu);
 
 	// we don't know the device_id until after add_cgpu()
-	usb_stats[cgpu->usbstat - 1].device_id = cgpu->device_id;
+	usb_stats[cgpu->usbinfo.usbstat - 1].device_id = cgpu->device_id;
 #endif
 }
 
@@ -1163,10 +1164,10 @@ static void stats(struct cgpu_info *cgpu, struct timeval *tv_start, struct timev
 	double diff;
 	int item;
 
-	if (cgpu->usbstat < 1)
+	if (cgpu->usbinfo.usbstat < 1)
 		newstats(cgpu);
 
-	details = &(usb_stats[cgpu->usbstat - 1].details[cmd * 2 + seq]);
+	details = &(usb_stats[cgpu->usbinfo.usbstat - 1].details[cmd * 2 + seq]);
 
 	diff = tdiff(tv_finish, tv_start);
 
@@ -1201,10 +1202,10 @@ static void rejected_inc(struct cgpu_info *cgpu)
 	struct cg_usb_stats_details *details;
 	int item = CMD_ERROR;
 
-	if (cgpu->usbstat < 1)
+	if (cgpu->usbinfo.usbstat < 1)
 		newstats(cgpu);
 
-	details = &(usb_stats[cgpu->usbstat - 1].details[C_REJECTED * 2 + 0]);
+	details = &(usb_stats[cgpu->usbinfo.usbstat - 1].details[C_REJECTED * 2 + 0]);
 
 	details->item[item].count++;
 }
@@ -1222,7 +1223,7 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro
 	int err, got, tot, i;
 	bool first = true;
 
-	if (cgpu->nodev) {
+	if (cgpu->usbinfo.nodev) {
 		*buf = '\0';
 		*processed = 0;
 #if DO_USB_STATS
@@ -1330,7 +1331,7 @@ int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pr
 #endif
 	int err, sent;
 
-	if (cgpu->nodev) {
+	if (cgpu->usbinfo.nodev) {
 		*processed = 0;
 #if DO_USB_STATS
 		rejected_inc(cgpu);
@@ -1364,7 +1365,7 @@ int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest
 #endif
 	int err;
 
-	if (cgpu->nodev) {
+	if (cgpu->usbinfo.nodev) {
 #if DO_USB_STATS
 		rejected_inc(cgpu);
 #endif

+ 9 - 2
usbutils.h

@@ -67,8 +67,6 @@ struct cg_usb_device {
 	libusb_device_handle *handle;
 	pthread_mutex_t *mutex;
 	struct libusb_device_descriptor *descriptor;
-	uint8_t bus_number;
-	uint8_t device_address;
 	uint16_t usbver;
 	int speed;
 	char *prod_string;
@@ -78,6 +76,15 @@ struct cg_usb_device {
 	unsigned char interfaceVersion;	// ??
 };
 
+struct cg_usb_info {
+	uint8_t bus_number;
+	uint8_t device_address;
+	int usbstat;
+	bool nodev;
+	int nodev_count;
+	struct timeval last_nodev;
+};
+
 enum usb_cmds {
 	C_REJECTED = 0,
 	C_PING,