Browse Source

Merge commit '569a6f6' into cg_merges_20130602

Luke Dashjr 12 years ago
parent
commit
55990935c3
2 changed files with 36 additions and 14 deletions
  1. 34 14
      driver-avalon.c
  2. 2 0
      driver-avalon.h

+ 34 - 14
driver-avalon.c

@@ -173,7 +173,7 @@ static int avalon_send_task(int fd, const struct avalon_task *at,
 	buf[4] = tt;
 	buf[4] = tt;
 #endif
 #endif
 	if (likely(avalon)) {
 	if (likely(avalon)) {
-		info = avalon_infos[avalon->device_id];
+		info = avalon->device_data;
 		delay = nr_len * 10 * 1000000000ULL;
 		delay = nr_len * 10 * 1000000000ULL;
 		delay = delay / info->baud;
 		delay = delay / info->baud;
 	}
 	}
@@ -291,7 +291,7 @@ static bool avalon_decode_nonce(struct thr_info *thr, struct avalon_result *ar,
 	if (!work)
 	if (!work)
 		return false;
 		return false;
 
 
-	info = avalon_infos[avalon->device_id];
+	info = avalon->device_data;
 	info->matching_work[work->subid]++;
 	info->matching_work[work->subid]++;
 	*nonce = htole32(ar->nonce);
 	*nonce = htole32(ar->nonce);
 	submit_nonce(thr, work, *nonce);
 	submit_nonce(thr, work, *nonce);
@@ -388,7 +388,7 @@ static void avalon_idle(struct cgpu_info *avalon)
 	struct avalon_task at;
 	struct avalon_task at;
 
 
 	int fd = avalon->device_fd;
 	int fd = avalon->device_fd;
-	struct avalon_info *info = avalon_infos[avalon->device_id];
+	struct avalon_info *info = avalon->device_data;
 	int avalon_get_work_count = info->miner_count;
 	int avalon_get_work_count = info->miner_count;
 
 
 	i = 0;
 	i = 0;
@@ -544,6 +544,25 @@ static void get_options(int this_option_offset, int *baud, int *miner_count,
 	}
 	}
 }
 }
 
 
+/* Non blocking clearing of anything in the buffer */
+static void avalon_clear_readbuf(int fd)
+{
+	ssize_t ret;
+
+	do {
+		struct timeval timeout;
+		char buf[AVALON_FTDI_READSIZE];
+		fd_set rd;
+
+		timeout.tv_sec = timeout.tv_usec = 0;
+		FD_ZERO(&rd);
+		FD_SET((SOCKETTYPE)fd, &rd);
+		ret = select(fd + 1, &rd, NULL, NULL, &timeout);
+		if (ret > 0)
+			ret = read(fd, buf, AVALON_FTDI_READSIZE);
+	} while (ret > 0);
+}
+
 static bool avalon_detect_one(const char *devpath)
 static bool avalon_detect_one(const char *devpath)
 {
 {
 	struct avalon_info *info;
 	struct avalon_info *info;
@@ -565,6 +584,7 @@ static bool avalon_detect_one(const char *devpath)
 		applog(LOG_ERR, "Avalon Detect: Failed to open %s", devpath);
 		applog(LOG_ERR, "Avalon Detect: Failed to open %s", devpath);
 		return false;
 		return false;
 	}
 	}
+	avalon_clear_readbuf(fd);
 
 
 	/* We have a real Avalon! */
 	/* We have a real Avalon! */
 	avalon = calloc(1, sizeof(struct cgpu_info));
 	avalon = calloc(1, sizeof(struct cgpu_info));
@@ -588,12 +608,12 @@ static bool avalon_detect_one(const char *devpath)
 	applog(LOG_INFO, "Avalon Detect: Found at %s, mark as %d",
 	applog(LOG_INFO, "Avalon Detect: Found at %s, mark as %d",
 	       devpath, avalon->device_id);
 	       devpath, avalon->device_id);
 
 
-	avalon_infos[avalon->device_id] = (struct avalon_info *)
-		malloc(sizeof(struct avalon_info));
+	avalon_infos[avalon->device_id] = calloc(sizeof(struct avalon_info), 1);
 	if (unlikely(!(avalon_infos[avalon->device_id])))
 	if (unlikely(!(avalon_infos[avalon->device_id])))
-		quit(1, "Failed to malloc avalon_infos");
+		quit(1, "Failed to calloc avalon_infos");
 
 
-	info = avalon_infos[avalon->device_id];
+	avalon->device_data = avalon_infos[avalon->device_id];
+	info = avalon->device_data;
 
 
 	memset(info, 0, sizeof(struct avalon_info));
 	memset(info, 0, sizeof(struct avalon_info));
 
 
@@ -634,12 +654,12 @@ static void __avalon_init(struct cgpu_info *avalon)
 
 
 static void avalon_init(struct cgpu_info *avalon)
 static void avalon_init(struct cgpu_info *avalon)
 {
 {
+	struct avalon_info *info = avalon->device_data;
 	struct avalon_result ar;
 	struct avalon_result ar;
 	int fd, ret;
 	int fd, ret;
 
 
 	avalon->device_fd = -1;
 	avalon->device_fd = -1;
-	fd = avalon_open(avalon->device_path,
-			     avalon_infos[avalon->device_id]->baud);
+	fd = avalon_open(avalon->device_path, info->baud);
 	if (unlikely(fd == -1)) {
 	if (unlikely(fd == -1)) {
 		applog(LOG_ERR, "Avalon: Failed to open on %s",
 		applog(LOG_ERR, "Avalon: Failed to open on %s",
 		       avalon->device_path);
 		       avalon->device_path);
@@ -659,7 +679,7 @@ static void avalon_init(struct cgpu_info *avalon)
 static bool avalon_prepare(struct thr_info *thr)
 static bool avalon_prepare(struct thr_info *thr)
 {
 {
 	struct cgpu_info *avalon = thr->cgpu;
 	struct cgpu_info *avalon = thr->cgpu;
-	struct avalon_info *info = avalon_infos[avalon->device_id];
+	struct avalon_info *info = avalon->device_data;
 	struct timeval now;
 	struct timeval now;
 
 
 	free(avalon->works);
 	free(avalon->works);
@@ -689,7 +709,7 @@ static void avalon_free_work(struct thr_info *thr)
 	if (unlikely(!avalon->works))
 	if (unlikely(!avalon->works))
 		return;
 		return;
 	works = avalon->works;
 	works = avalon->works;
-	info = avalon_infos[avalon->device_id];
+	info = avalon->device_data;
 
 
 	for (i = 0; i < info->miner_count * 4; i++) {
 	for (i = 0; i < info->miner_count * 4; i++) {
 		if (works[i]) {
 		if (works[i]) {
@@ -703,7 +723,7 @@ static void do_avalon_close(struct thr_info *thr)
 {
 {
 	struct avalon_result ar;
 	struct avalon_result ar;
 	struct cgpu_info *avalon = thr->cgpu;
 	struct cgpu_info *avalon = thr->cgpu;
-	struct avalon_info *info = avalon_infos[avalon->device_id];
+	struct avalon_info *info = avalon->device_data;
 
 
 	avalon_free_work(thr);
 	avalon_free_work(thr);
 	nmsleep(1000);
 	nmsleep(1000);
@@ -816,7 +836,7 @@ static int64_t avalon_scanhash(struct thr_info *thr)
 
 
 	avalon = thr->cgpu;
 	avalon = thr->cgpu;
 	works = avalon->works;
 	works = avalon->works;
-	info = avalon_infos[avalon->device_id];
+	info = avalon->device_data;
 	avalon_get_work_count = info->miner_count;
 	avalon_get_work_count = info->miner_count;
 
 
 	if (unlikely(avalon->device_fd == -1)) {
 	if (unlikely(avalon->device_fd == -1)) {
@@ -969,7 +989,7 @@ static int64_t avalon_scanhash(struct thr_info *thr)
 static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
 static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
 {
 {
 	struct api_data *root = NULL;
 	struct api_data *root = NULL;
-	struct avalon_info *info = avalon_infos[cgpu->device_id];
+	struct avalon_info *info = cgpu->device_data;
 	int i;
 	int i;
 
 
 	root = api_add_int(root, "baud", &(info->baud), false);
 	root = api_add_int(root, "baud", &(info->baud), false);

+ 2 - 0
driver-avalon.h

@@ -28,6 +28,8 @@
 #define AVALON_DEFAULT_MINER_NUM 0x20
 #define AVALON_DEFAULT_MINER_NUM 0x20
 #define AVALON_DEFAULT_ASIC_NUM 0xA
 #define AVALON_DEFAULT_ASIC_NUM 0xA
 
 
+#define AVALON_FTDI_READSIZE 512
+
 struct avalon_task {
 struct avalon_task {
 	uint8_t reset		:1;
 	uint8_t reset		:1;
 	uint8_t flush_fifo	:1;
 	uint8_t flush_fifo	:1;