Browse Source

avalon: add some code on match work

Xiangfu 13 years ago
parent
commit
7d7b1f6c49
2 changed files with 67 additions and 75 deletions
  1. 11 22
      driver-avalon.c
  2. 56 53
      driver-avalon.h

+ 11 - 22
driver-avalon.c

@@ -9,26 +9,6 @@
  * any later version.  See COPYING for more details.
  */
 
-/*
- * Those code should be works fine with V2 and V3 bitstream of Avalon.
- * Operation:
- *   No detection implement.
- *   Input: 64B = 32B midstate + 20B fill bytes + last 12 bytes of block head.
- *   Return: send back 32bits immediately when Avalon found a valid nonce.
- *           no query protocol implemented here, if no data send back in ~11.3
- *           seconds (full cover time on 32bit nonce range by 380MH/s speed)
- *           just send another work.
- * Notice:
- *   1. Avalon will start calculate when you push a work to them, even they
- *      are busy.
- *   2. The 2 FPGAs on Avalon will distribute the job, one will calculate the
- *      0 ~ 7FFFFFFF, another one will cover the 80000000 ~ FFFFFFFF.
- *   3. It's possible for 2 FPGAs both find valid nonce in the meantime, the 2
- *      valid nonce will all be send back.
- *   4. Avalon will stop work when: a valid nonce has been found or 32 bits
- *      nonce range is completely calculated.
- */
-
 #include "config.h"
 
 #include <limits.h>
@@ -170,14 +150,23 @@ static int avalon_get_result(uint8_t *nonce_bin, int fd,
 static int avalon_decode_nonce(struct work **work, uint32_t *nonce,
 			       uint8_t *nonce_bin)
 {
+	int i;
 	/* FIXME: should be modify to avalon data format */
 	memcpy((uint8_t *)nonce, nonce_bin, AVALON_READ_SIZE);
 #if !defined (__BIG_ENDIAN__) && !defined(MIPSEB)
 	*nonce = swab32(*nonce);
 #endif
 
-	/* TODO: find the nonce work, return index */
-	return 0;
+	for (i = 0; i < AVALON_GET_WORK_COUNT; i++) {
+		/* TODO: find the nonce work, return index */
+		if (!memcmp((uint8_t *)nonce,
+			     work[i]->data + 64,
+			     4/* should be 12 */))
+			break;
+	}
+	i -= 1;
+
+	return i;
 }
 
 static inline void avalon_create_task(uint8_t *ob_bin, struct work *work)

+ 56 - 53
driver-avalon.h

@@ -1,4 +1,6 @@
 /*
+ * Copyright 2013 Xiangfu <xiangfu@openmobilefree.com>
+ *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
  * Software Foundation; either version 3 of the License, or (at your option)
@@ -35,8 +37,61 @@ struct avalon_result {
 	uint32_t reserved;
 } __attribute__((packed));
 
+struct AVALON_HISTORY {
+	struct timeval finish;
+	double sumXiTi;
+	double sumXi;
+	double sumTi;
+	double sumXi2;
+	uint32_t values;
+	uint32_t hash_count_min;
+	uint32_t hash_count_max;
+};
+
+enum timing_mode { MODE_DEFAULT, MODE_SHORT, MODE_LONG, MODE_VALUE };
+
+// Store the last INFO_HISTORY data sets
+// [0] = current data, not yet ready to be included as an estimate
+// Each new data set throws the last old set off the end thus
+// keeping a ongoing average of recent data
+#define INFO_HISTORY 10
+
+struct AVALON_INFO {
+	// time to calculate the golden_ob
+	uint64_t golden_hashes;
+	struct timeval golden_tv;
+
+	struct AVALON_HISTORY history[INFO_HISTORY+1];
+	uint32_t min_data_count;
+
+	// seconds per Hash
+	double Hs;
+	int read_count;
+
+	enum timing_mode timing_mode;
+	bool do_avalon_timing;
+
+	double fullnonce;
+	int count;
+	double W;
+	uint32_t values;
+	uint64_t hash_count_range;
+
+	// Determine the cost of history processing
+	// (which will only affect W)
+	uint64_t history_count;
+	struct timeval history_time;
+
+	// avalon-options
+	int baud;
+	int work_division;
+	int asic_count;
+	uint32_t nonce_mask;
+};
+
 #define AVALON_MINER_THREADS 1
-#define AVALON_GET_WORK_COUNT 1	/* FIXME: should be ~20 */
+/* FIXME: should be ~20 */
+#define AVALON_GET_WORK_COUNT 1
 
 #define AVALON_IO_SPEED 115200
 /* FIXME:  The size of a successful task-write and nonce-read */
@@ -107,58 +162,6 @@ ASSERT1(sizeof(uint32_t) == 4);
 // The value above used is doubled each history until it exceeds:
 #define MAX_MIN_DATA_COUNT 100
 
-// Store the last INFO_HISTORY data sets
-// [0] = current data, not yet ready to be included as an estimate
-// Each new data set throws the last old set off the end thus
-// keeping a ongoing average of recent data
-#define INFO_HISTORY 10
-
-struct AVALON_HISTORY {
-	struct timeval finish;
-	double sumXiTi;
-	double sumXi;
-	double sumTi;
-	double sumXi2;
-	uint32_t values;
-	uint32_t hash_count_min;
-	uint32_t hash_count_max;
-};
-
-enum timing_mode { MODE_DEFAULT, MODE_SHORT, MODE_LONG, MODE_VALUE };
-
-struct AVALON_INFO {
-	// time to calculate the golden_ob
-	uint64_t golden_hashes;
-	struct timeval golden_tv;
-
-	struct AVALON_HISTORY history[INFO_HISTORY+1];
-	uint32_t min_data_count;
-
-	// seconds per Hash
-	double Hs;
-	int read_count;
-
-	enum timing_mode timing_mode;
-	bool do_avalon_timing;
-
-	double fullnonce;
-	int count;
-	double W;
-	uint32_t values;
-	uint64_t hash_count_range;
-
-	// Determine the cost of history processing
-	// (which will only affect W)
-	uint64_t history_count;
-	struct timeval history_time;
-
-	// avalon-options
-	int baud;
-	int work_division;
-	int asic_count;
-	uint32_t nonce_mask;
-};
-
 #define END_CONDITION 0x0000ffff
 
 #define AVA_GETS_ERROR -1