Commit 37dff9987c98398767f18c47bd83f6301c1c6902

Con Kolivas 2014-05-05T10:27:20

Support variable numbers of chips with NFU and BXM drivers

diff --git a/driver-bitfury.c b/driver-bitfury.c
index 368ea7b..581fa0e 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -389,13 +389,23 @@ static void nfu_close(struct cgpu_info *bitfury)
 
 static bool nfu_reinit(struct cgpu_info *bitfury, struct bitfury_info *info)
 {
-	spi_clear_buf(info);
-	spi_add_break(info);
-	spi_set_freq(info);
-	spi_send_conf(info);
-	spi_send_init(info);
-	spi_reset(bitfury, info);
-	return info->spi_txrx(bitfury, info);
+	bool ret;
+
+	int i;
+
+	for (i = 0; i < info->chips; i++) {
+		spi_clear_buf(info);
+		spi_add_break(info);
+		spi_add_fasync(info, i);
+		spi_set_freq(info);
+		spi_send_conf(info);
+		spi_send_init(info);
+		spi_reset(bitfury, info);
+		ret = info->spi_txrx(bitfury, info);
+		if (!ret)
+			break;
+	}
+	return ret;
 }
 
 static bool nfu_set_spi_settings(struct cgpu_info *bitfury, struct bitfury_info *info)
@@ -406,6 +416,16 @@ static bool nfu_set_spi_settings(struct cgpu_info *bitfury, struct bitfury_info 
 		mcp->acsv, mcp->cstdd, mcp->ldbtcsd, mcp->sdbd, mcp->bpst, mcp->spimode);
 }
 
+static void nfu_alloc_arrays(struct bitfury_info *info)
+{
+	info->payload = calloc(sizeof(struct bitfury_payload), info->chips);
+	info->oldbuf = calloc(sizeof(unsigned int) * 17, info->chips);
+	info->job_switched = calloc(sizeof(bool), info->chips);
+	info->second_run = calloc(sizeof(bool), info->chips);
+	info->work = calloc(sizeof(struct work *), info->chips);
+	info->owork = calloc(sizeof(struct work *), info->chips);
+}
+
 static bool nfu_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 {
 	struct mcp_settings *mcp = &info->mcp;
@@ -423,6 +443,7 @@ static bool nfu_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 		sprintf(info->product, "NF%u", info->chips);
 		bitfury->drv->name = info->product;
 	}
+	nfu_alloc_arrays(info);
 
 	info->spi_txrx = &mcp_spi_txrx;
 	mcp2210_get_gpio_settings(bitfury, mcp);
@@ -531,7 +552,7 @@ static bool nfu_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	       bitfury->drv->name, bitfury->device_id, bitfury->device_path);
 	spi_clear_buf(info);
 
-	info->total_nonces = 1;
+	info->total_nonces = info->chips;
 out:
 	if (!ret)
 		nfu_close(bitfury);
@@ -766,6 +787,10 @@ static bool bxm_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	if (!ret)
 		goto out;
 	info->osc6_bits = opt_bxm_bits;
+	/* Only have 2 chip devices for now */
+	info->chips = 2;
+	nfu_alloc_arrays(info);
+
 	ret = bxm_reinit(bitfury, info);
 	if (!ret)
 		goto out;
@@ -1336,28 +1361,10 @@ static int64_t nfu_scan(struct thr_info *thr, struct cgpu_info *bitfury,
 			struct bitfury_info *info)
 {
 	int64_t ret = 0;
+	int i;
 
-	bitfury_check_work(thr, bitfury, info, 0);
-
-	ret = bitfury_rate(info);
-
-	if (unlikely(bitfury->usbinfo.nodev)) {
-		applog(LOG_WARNING, "%s %d: Device disappeared, disabling thread",
-		       bitfury->drv->name, bitfury->device_id);
-		ret = -1;
-	}
-
-	return ret;
-}
-
-static int64_t bxm_scan(struct thr_info *thr, struct cgpu_info *bitfury,
-			struct bitfury_info *info)
-{
-	int64_t ret = 0;
-	int chip_n;
-
-	for (chip_n = 0; chip_n < 2; chip_n++)
-		bitfury_check_work(thr, bitfury, info, chip_n);
+	for (i = 0; i < info->chips; i++)
+		bitfury_check_work(thr, bitfury, info, i);
 
 	ret = bitfury_rate(info);
 
@@ -1403,10 +1410,8 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
 			ret = bxf_scan(bitfury, info);
 			break;
 		case IDENT_NFU:
-			ret = nfu_scan(thr, bitfury, info);
-			break;
 		case IDENT_BXM:
-			ret = bxm_scan(thr, bitfury, info);
+			ret = nfu_scan(thr, bitfury, info);
 			break;
 		default:
 			ret = 0;
diff --git a/driver-bitfury.h b/driver-bitfury.h
index 00db7c1..ccd322a 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -100,12 +100,14 @@ struct bitfury_info {
 	char spibuf[SPIBUF_SIZE];
 	unsigned int spibufsz;
 	int osc6_bits;
-	struct bitfury_payload payload[2];
-	unsigned oldbuf[17 * 2];
-	bool job_switched[2];
-	bool second_run[2];
-	struct work *work[2];
-	struct work *owork[2];
+
+	/* Chip sized arrays */
+	struct bitfury_payload *payload;
+	unsigned int *oldbuf; // 17 vals per chip
+	bool *job_switched;
+	bool *second_run;
+	struct work **work;
+	struct work **owork;
 
 	bool (*spi_txrx)(struct cgpu_info *, struct bitfury_info *info);
 };