Commit 065c1038a9855acca6ba6eb0a11521a2b4bf5e4d

kanoi 2013-06-04T22:34:56

Merge pull request #438 from kanoi/master ICA/BAS buffered USB

diff --git a/driver-bflsc.c b/driver-bflsc.c
index 9177d57..76bf3f5 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -471,6 +471,12 @@ static int write_to_dev(struct cgpu_info *bflsc, int dev, char *buf, int buflen,
 	struct DataForwardToChain data;
 	int len;
 
+	/*
+	 * The protocol is syncronous so any previous excess can be
+	 * discarded and assumed corrupt data or failed USB transfers
+	 */
+	usb_buffer_clear(bflsc);
+
 	if (dev == 0)
 		return usb_write(bflsc, buf, buflen, amount, cmd);
 
@@ -949,6 +955,8 @@ reinit:
 	mutex_init(&bflsc->device_mutex);
 	rwlock_init(&sc_info->stat_lock);
 
+	usb_buffer_enable(bflsc);
+
 	return true;
 
 unshin:
diff --git a/driver-icarus.c b/driver-icarus.c
index f4d50cb..2d18333 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -432,7 +432,6 @@ static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct
 		if (first)
 			copy_time(tv_finish, &read_finish);
 
-		// TODO: test if there is more data? to read a 2nd nonce?
 		if (amt >= read_amount)
 			return ICA_NONCE_OK;
 
@@ -830,6 +829,8 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
 
 	set_timing_mode(this_option_offset, icarus);
 
+	usb_buffer_enable(icarus);
+
 	return true;
 
 unshin:
@@ -898,6 +899,9 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	rev(ob_bin, 32);
 	rev(ob_bin + 52, 12);
 
+	// We only want results for the work we are about to send
+	usb_buffer_clear(icarus);
+
 	err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDWORK);
 	if (err < 0 || amount != sizeof(ob_bin)) {
 		applog(LOG_ERR, "%s%i: Comms error (werr=%d amt=%d)",
@@ -956,6 +960,20 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	hash_count++;
 	hash_count *= info->fpga_count;
 
+#if 0
+	// This appears to only return zero nonce values
+	if (usb_buffer_size(icarus) > 3) {
+		memcpy((char *)&nonce, icarus->usbdev->buffer, sizeof(nonce_bin));
+		nonce = htobe32(nonce);
+		applog(LOG_WARNING, "%s%d: attempting to submit 2nd nonce = 0x%08lX",
+				icarus->drv->name, icarus->device_id,
+				(long unsigned int)nonce);
+		curr_hw_errors = icarus->hw_errors;
+		submit_nonce(thr, work, nonce);
+		was_hw_error = (curr_hw_errors > icarus->hw_errors);
+	}
+#endif
+
 	if (opt_debug || info->do_icarus_timing)
 		timersub(&tv_finish, &tv_start, &elapsed);