Browse Source

bitmain: Migrate BITMAIN_MAX_WORK_NUM to runtime packet_max_work

Luke Dashjr 10 years ago
parent
commit
b367b4343d
2 changed files with 36 additions and 7 deletions
  1. 33 2
      driver-bitmain.c
  2. 3 5
      driver-bitmain.h

+ 33 - 2
driver-bitmain.c

@@ -1361,6 +1361,9 @@ static bool bitmain_detect_one(const char * devpath)
 	info = bitmain->device_data;
 
 	drv_set_defaults(&bitmain_drv, bitmain_set_device_funcs_init, info, devpath, NULL, 1);
+	
+	if (!info->packet_max_work)
+		return_via_applog(shin, , LOG_ERR, "%s: Device not configured (did you forget --set bitmain:model=S5 ?)", bitmain_drv.dname);
 
 	if (!btm_init(bitmain, devpath))
 		goto shin;
@@ -1478,7 +1481,7 @@ static bool bitmain_queue_append(struct thr_info * const thr, struct work * cons
 	HASH_ADD(hh, master_thr->work_list, device_id, sizeof(work->device_id), work);
 	++info->ready_to_queue;
 	
-	if (!(info->ready_to_queue == BITMAIN_MAX_WORK_NUM || info->fifo_space == info->ready_to_queue || info->fifo_space == info->max_fifo_space)) {
+	if (!(info->ready_to_queue >= info->packet_max_work || info->fifo_space == info->ready_to_queue || info->fifo_space == info->max_fifo_space)) {
 		applog(LOG_DEBUG, "%s: %s now has ready_to_queue=%d; deferring send", dev->dev_repr, __func__, info->ready_to_queue);
 		return true;
 	}
@@ -1745,8 +1748,31 @@ voltage_usage:
 	return NULL;
 }
 
+static bool bitmain_set_packet_max_work(struct cgpu_info * const dev, const unsigned i)
+{
+	struct bitmain_info * const info = dev->device_data;
+	uint8_t * const new_queuebuf = realloc(info->queuebuf, BITMAIN_TASK_HEADER_SIZE + (i * BITMAIN_WORK_SIZE) + BITMAIN_TASK_FOOTER_SIZE);
+	if (!new_queuebuf)
+		return false;
+	info->packet_max_work = i;
+	info->queuebuf = new_queuebuf;
+	return true;
+}
+
+static const char *bitmain_set_packet_max_work_opt(struct cgpu_info * const proc, const char * const optname, const char *newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
+{
+	const int i = atoi(newvalue);
+	if (i < 1)
+		return "Invalid setting";
+	if (!bitmain_set_packet_max_work(proc->device, i))
+		return "realloc failure";
+	return NULL;
+}
+
 static const char *bitmain_set_model(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
 {
+	struct cgpu_info * const dev = proc->device;
+	
 	if (toupper(newvalue[0]) != 'S') {
 unknown_model:
 		return "Unknown model";
@@ -1759,16 +1785,20 @@ unknown_model:
 		++endptr;
 	if (endptr[0] && !isspace(endptr[0]))
 		goto unknown_model;
+	
 	switch (Sn) {
 		case 1:
+			bitmain_set_packet_max_work(dev, 8);
 			break;
 		case 2:
+			bitmain_set_packet_max_work(dev, 0x40);
 			break;
 		case 3:
+			bitmain_set_packet_max_work(dev, 8);
 			break;
 		case 4:
-			break;
 		case 5:
+			bitmain_set_packet_max_work(dev, 0x40);
 			break;
 	}
 	return NULL;
@@ -1781,6 +1811,7 @@ static const struct bfg_set_device_definition bitmain_set_device_funcs_init[] =
 	{"clock", bitmain_set_clock, "clock frequency"},
 	{"reg_data", bitmain_set_reg_data, "reg_data (eg: x0d82)"},
 	{"voltage", bitmain_set_voltage, "voltage (must be specified as 'x' and hex data; eg: x0725)"},
+	{"packet_max_work", bitmain_set_packet_max_work_opt, NULL},
 	{NULL},
 };
 

+ 3 - 5
driver-bitmain.h

@@ -63,7 +63,6 @@
 #define BITMAIN_LATENCY 1
 
 #ifdef BITMAIN_TYPE_S1
-#define BITMAIN_MAX_WORK_NUM       8
 #define BITMAIN_MAX_WORK_QUEUE_NUM 64
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 1
 #define BITMAIN_MAX_NONCE_NUM      8
@@ -76,7 +75,6 @@
 #endif
 
 #ifdef BITMAIN_TYPE_S2
-#define BITMAIN_MAX_WORK_NUM       64
 #define BITMAIN_MAX_WORK_QUEUE_NUM 4096
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 32
 #define BITMAIN_MAX_NONCE_NUM      128
@@ -89,7 +87,6 @@
 #endif
 
 #ifdef BITMAIN_TYPE_S3
-#define BITMAIN_MAX_WORK_NUM       8
 #define BITMAIN_MAX_WORK_QUEUE_NUM 1024
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 2
 #define BITMAIN_MAX_NONCE_NUM      128
@@ -102,7 +99,6 @@
 #endif
 
 #ifdef BITMAIN_TYPE_S4
-#define BITMAIN_MAX_WORK_NUM       64
 #define BITMAIN_MAX_WORK_QUEUE_NUM 4096
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 32
 #define BITMAIN_MAX_NONCE_NUM      128
@@ -227,6 +223,8 @@ struct bitmain_info {
 	uint32_t nonce_error;
 	uint32_t last_nonce_error;
 	uint8_t reg_data[4];
+	
+	unsigned packet_max_work;  // BITMAIN_MAX_WORK_NUM
 
 	int fan_num;
 	int fan[BITMAIN_MAX_FAN_NUM];
@@ -259,7 +257,7 @@ struct bitmain_info {
 	int hw_version[4];
 
 	int ready_to_queue;
-	uint8_t queuebuf[BITMAIN_TASK_HEADER_SIZE + (BITMAIN_MAX_WORK_NUM * BITMAIN_WORK_SIZE) + BITMAIN_TASK_FOOTER_SIZE];
+	uint8_t *queuebuf;
 	
 	bool reset;
 	bool work_restart;