Browse Source

bitmain: Migrate BITMAIN_MAX_NONCE_NUM to runtime packet_max_nonce

Luke Dashjr 10 years ago
parent
commit
bbe4dc9db9
2 changed files with 22 additions and 6 deletions
  1. 18 1
      driver-bitmain.c
  2. 4 5
      driver-bitmain.h

+ 18 - 1
driver-bitmain.c

@@ -79,6 +79,7 @@ struct cgpu_info *btm_alloc_cgpu(struct device_drv *drv, int threads)
 		.voltage[0] = BITMAIN_DEFAULT_VOLTAGE0,
 		.voltage[1] = BITMAIN_DEFAULT_VOLTAGE1,
 		
+		.packet_max_nonce = BITMAIN_MAX_PACKET_MAX_NONCE,
 		.poll_prio_threshold = UINT_MAX,
 		
 		.diff = 255,
@@ -1000,7 +1001,7 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info
 				applog(LOG_DEBUG, "bitmain_parse_rxnonce fifo space=%d", info->fifo_space);
 
 #ifndef WIN32
-				if(nonce_num < BITMAIN_MAX_NONCE_NUM)
+				if(nonce_num < info->packet_max_nonce)
 					cgsleep_ms(5);
 #endif
 			}
@@ -1770,6 +1771,17 @@ static const char *bitmain_set_packet_max_work_opt(struct cgpu_info * const proc
 	return NULL;
 }
 
+static
+const char *bitmain_set_packet_max_nonce_opt(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 bitmain_info *info = proc->device_data;
+	const int i = atoi(newvalue);
+	if (i < 0 || i > BITMAIN_MAX_PACKET_MAX_NONCE)
+		return "Invalid setting";
+	info->packet_max_nonce = i;
+	return NULL;
+}
+
 static
 const char *bitmain_set_poll_prio_threshold_opt(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
 {
@@ -1802,19 +1814,23 @@ unknown_model:
 	switch (Sn) {
 		case 1:
 			bitmain_set_packet_max_work(dev, 8);
+			info->packet_max_nonce = 8;
 			info->poll_prio_threshold = 0x40;
 			break;
 		case 2:
 			bitmain_set_packet_max_work(dev, 0x40);
+			info->packet_max_nonce = 0x80;
 			info->poll_prio_threshold = 0x1000;
 			break;
 		case 3:
 			bitmain_set_packet_max_work(dev, 8);
+			info->packet_max_nonce = 0x80;
 			info->poll_prio_threshold = 0x400;
 			break;
 		case 4:
 		case 5:
 			bitmain_set_packet_max_work(dev, 0x40);
+			info->packet_max_nonce = 0x80;
 			info->poll_prio_threshold = 0x1000;
 			break;
 	}
@@ -1829,6 +1845,7 @@ static const struct bfg_set_device_definition bitmain_set_device_funcs_init[] =
 	{"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},
+	{"packet_max_nonce", bitmain_set_packet_max_nonce_opt, NULL},
 	{"poll_prio_threshold", bitmain_set_poll_prio_threshold_opt, NULL},
 	{NULL},
 };

+ 4 - 5
driver-bitmain.h

@@ -64,7 +64,6 @@
 
 #ifdef BITMAIN_TYPE_S1
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 1
-#define BITMAIN_MAX_NONCE_NUM      8
 #define BITMAIN_MAX_CHAIN_NUM      8
 #define BITMAIN_MAX_TEMP_NUM       32
 #define BITMAIN_MAX_FAN_NUM        32
@@ -75,7 +74,6 @@
 
 #ifdef BITMAIN_TYPE_S2
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 32
-#define BITMAIN_MAX_NONCE_NUM      128
 #define BITMAIN_MAX_CHAIN_NUM      16
 #define BITMAIN_MAX_TEMP_NUM       32
 #define BITMAIN_MAX_FAN_NUM        32
@@ -86,7 +84,6 @@
 
 #ifdef BITMAIN_TYPE_S3
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 2
-#define BITMAIN_MAX_NONCE_NUM      128
 #define BITMAIN_MAX_CHAIN_NUM      8
 #define BITMAIN_MAX_TEMP_NUM       32
 #define BITMAIN_MAX_FAN_NUM        32
@@ -97,7 +94,6 @@
 
 #ifdef BITMAIN_TYPE_S4
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 32
-#define BITMAIN_MAX_NONCE_NUM      128
 #define BITMAIN_MAX_CHAIN_NUM      16
 #define BITMAIN_MAX_TEMP_NUM       32
 #define BITMAIN_MAX_FAN_NUM        32
@@ -110,6 +106,8 @@
 #define BITMAIN_TASK_FOOTER_SIZE   2
 #define BITMAIN_WORK_SIZE          0x30
 
+#define BITMAIN_MAX_PACKET_MAX_NONCE  0x80
+
 struct bitmain_packet_head {
 	uint8_t token_type;
 	uint8_t version;
@@ -199,7 +197,7 @@ struct bitmain_rxnonce_data {
 	uint16_t fifo_space;
 	uint16_t diff;
 	uint64_t total_nonce_num;
-	struct bitmain_rxnonce_nonce nonces[BITMAIN_MAX_NONCE_NUM];
+	struct bitmain_rxnonce_nonce nonces[BITMAIN_MAX_PACKET_MAX_NONCE];
 	uint16_t crc;
 } __attribute__((packed, aligned(4)));
 
@@ -222,6 +220,7 @@ struct bitmain_info {
 	
 	unsigned packet_max_work;  // BITMAIN_MAX_WORK_NUM
 	unsigned poll_prio_threshold;  // BITMAIN_MAX_WORK_QUEUE_NUM
+	unsigned packet_max_nonce;     // BITMAIN_MAX_NONCE_NUM
 
 	int fan_num;
 	int fan[BITMAIN_MAX_FAN_NUM];