Commit 5cbeda38b93127d31d3d59ed83200b8859cf48bf

Mikeqin 2014-05-08T19:10:04

Automatic detect the small miners

diff --git a/driver-avalon2.c b/driver-avalon2.c
index 189d669..02468b6 100644
--- a/driver-avalon2.c
+++ b/driver-avalon2.c
@@ -238,7 +238,7 @@ static int decode_pkg(struct thr_info *thr, struct avalon2_ret *ar, uint8_t *pkg
 			miner = be32toh(miner);
 			pool_no = be32toh(pool_no);
 			if (miner >= AVA2_DEFAULT_MINERS ||
-			    modular_id >= AVA2_DEFAULT_MINERS || 
+			    modular_id >= AVA2_DEFAULT_MINERS ||
 			    pool_no >= total_pools ||
 			    pool_no < 0) {
 				applog(LOG_DEBUG, "Avalon2: Wrong miner/pool/id no %d,%d,%d", miner, pool_no, modular_id);
@@ -560,7 +560,7 @@ static bool avalon2_detect_one(const char *devpath)
 
 	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
 		modular[i] = 0;
-		strcpy(mm_version[i], "NONE");
+		strcpy(mm_version[i], AVA2_MM_VERNULL);
 		/* Send out detect pkg */
 		memset(detect_pkg.data, 0, AVA2_P_DATA_LEN);
 		tmp = be32toh(i);
@@ -783,23 +783,61 @@ static struct api_data *avalon2_api_stats(struct cgpu_info *cgpu)
 	int i, a, b;
 	char buf[24];
 	double hwp;
+	int devtype[AVA2_DEFAULT_MODULARS];
+	int minerindex = 0;
+
 	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
+		devtype[i] = AVA2_ID_AVAX;
+		if(strncmp((char*)&(info->mm_version[i]), AVA2_FW2_PREFIXSTR, 2) == 0){
+			devtype[i] = AVA2_ID_AVA2;
+		}
+		else if(strncmp((char*)&(info->mm_version[i]), AVA2_FW3_PREFIXSTR, 2) == 0){
+			devtype[i] = AVA2_ID_AVA3;
+		}
+		else if(strncmp((char*)&(info->mm_version[i]), AVA2_MM_VERNULL, 4) == 0){
+			continue;
+		}
+
 		sprintf(buf, "ID%d MM Version", i + 1);
 		root = api_add_string(root, buf, &(info->mm_version[i]), false);
 	}
-	for (i = 0; i < AVA2_DEFAULT_MINERS * AVA2_DEFAULT_MODULARS; i++) {
-		sprintf(buf, "Match work count%02d", i + 1);
-		root = api_add_int(root, buf, &(info->matching_work[i]), false);
+
+	minerindex = 0;
+	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++){
+		if(devtype[i] == AVA2_ID_AVA2){
+			for (i = minerindex; i < (minerindex + AVA2_DEFAULT_MINERS); i++) {
+				sprintf(buf, "Match work count%02d", i+1);
+				root = api_add_int(root, buf, &(info->matching_work[i]), false);
+			}
+			minerindex += AVA2_DEFAULT_MINERS;
+		}else
+		if(devtype[i] == AVA2_ID_AVA3){
+			for (i = minerindex; i < (minerindex + AVA2_AVA3_MINERS); i++) {
+				sprintf(buf, "Match work count%02d", i+1);
+				root = api_add_int(root, buf, &(info->matching_work[i]), false);
+			}
+			minerindex += AVA2_AVA3_MINERS;
+		}
+		else{
+			minerindex += AVA2_DEFAULT_MINERS;
+		}
 	}
+
 	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
+		if(devtype[i] == AVA2_ID_AVAX)
+			continue;
 		sprintf(buf, "Local works%d", i + 1);
 		root = api_add_int(root, buf, &(info->local_works[i]), false);
 	}
 	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
+		if(devtype[i] == AVA2_ID_AVAX)
+			continue;
 		sprintf(buf, "Hardware error works%d", i + 1);
 		root = api_add_int(root, buf, &(info->hw_works[i]), false);
 	}
 	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
+		if(devtype[i] == AVA2_ID_AVAX)
+			continue;
 		a = info->hw_works[i];
 		b = info->local_works[i];
 		hwp = b ? ((double)a / (double)b) : 0;
@@ -808,27 +846,36 @@ static struct api_data *avalon2_api_stats(struct cgpu_info *cgpu)
 		root = api_add_percent(root, buf, &hwp, true);
 	}
 	for (i = 0; i < 2 * AVA2_DEFAULT_MODULARS; i++) {
+		if(devtype[i/2] == AVA2_ID_AVAX)
+			continue;
 		sprintf(buf, "Temperature%d", i + 1);
 		root = api_add_int(root, buf, &(info->temp[i]), false);
 	}
 	for (i = 0; i < 2 * AVA2_DEFAULT_MODULARS; i++) {
+		if(devtype[i/2] == AVA2_ID_AVAX)
+			continue;
 		sprintf(buf, "Fan%d", i + 1);
 		root = api_add_int(root, buf, &(info->fan[i]), false);
 	}
 	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
+		if(devtype[i] == AVA2_ID_AVAX)
+			continue;
 		sprintf(buf, "Voltage%d", i + 1);
 		root = api_add_int(root, buf, &(info->get_voltage[i]), false);
 	}
 	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
+		if(devtype[i] == AVA2_ID_AVAX)
+			continue;
 		sprintf(buf, "Frequency%d", i + 1);
 		root = api_add_int(root, buf, &(info->get_frequency[i]), false);
 	}
 	for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
+		if(devtype[i] == AVA2_ID_AVAX)
+			continue;
 		sprintf(buf, "Power good %02x", i + 1);
-	root = api_add_int(root, buf, &(info->power_good[i]), false);
+		root = api_add_int(root, buf, &(info->power_good[i]), false);
 	}
 
-
 	return root;
 }
 
diff --git a/driver-avalon2.h b/driver-avalon2.h
index c641dbc..ee0f74c 100644
--- a/driver-avalon2.h
+++ b/driver-avalon2.h
@@ -22,6 +22,7 @@
 #define AVA2_IO_SPEED		115200
 
 #define AVA2_DEFAULT_MINERS	10
+#define AVA2_AVA3_MINERS	5
 #define AVA2_DEFAULT_MODULARS	4
 
 #define AVA2_PWM_MAX	0x3FF
@@ -69,6 +70,16 @@
 #define AVA2_P_TEST_RET		26
 /* Avalon2 protocol package type */
 
+/* Avalon2/3 prefix */
+#define AVA2_FW2_PREFIXSTR	"20"
+#define AVA2_FW3_PREFIXSTR	"33"
+
+#define AVA2_MM_VERNULL		"NONE"
+
+#define AVA2_ID_AVA2		(0x3255)
+#define AVA2_ID_AVA3		(0x3233)
+#define AVA2_ID_AVAX		(0x3200)
+
 struct avalon2_pkg {
 	uint8_t head[2];
 	uint8_t type;