Browse Source

icarus: Pass device representation to icarus_{gets,write} so logging can use it rather than fd numbers

Luke Dashjr 11 years ago
parent
commit
0b3816ed88
4 changed files with 29 additions and 30 deletions
  1. 4 4
      driver-antminer.c
  2. 4 4
      driver-cairnsmore.c
  3. 19 20
      driver-icarus.c
  4. 2 2
      driver-icarus.h

+ 4 - 4
driver-antminer.c

@@ -92,7 +92,7 @@ char *antminer_get_clock(struct cgpu_info *cgpu, char *replybuf)
 	applog(LOG_DEBUG, "%"PRIpreprv": Get clock: %02x%02x%02x%02x", cgpu->proc_repr, rdreg_buf[0], rdreg_buf[1], rdreg_buf[2], rdreg_buf[3]);
 	applog(LOG_DEBUG, "%"PRIpreprv": Get clock: %02x%02x%02x%02x", cgpu->proc_repr, rdreg_buf[0], rdreg_buf[1], rdreg_buf[2], rdreg_buf[3]);
 	
 	
 	timer_set_now(&tv_now);
 	timer_set_now(&tv_now);
-	int err = icarus_write(cgpu->device_fd, rdreg_buf, sizeof(rdreg_buf));
+	int err = icarus_write(cgpu->proc_repr, cgpu->device_fd, rdreg_buf, sizeof(rdreg_buf));
 	
 	
 	if (err != 0)
 	if (err != 0)
 	{
 	{
@@ -103,7 +103,7 @@ char *antminer_get_clock(struct cgpu_info *cgpu, char *replybuf)
 	applog(LOG_DEBUG, "%"PRIpreprv": Get clock: OK", cgpu->proc_repr);
 	applog(LOG_DEBUG, "%"PRIpreprv": Get clock: OK", cgpu->proc_repr);
 	
 	
 	memset(rebuf, 0, sizeof(rebuf));
 	memset(rebuf, 0, sizeof(rebuf));
-	err = icarus_gets(rebuf, cgpu->device_fd, &tv_now, NULL, 10, ANTMINER_STATUS_LEN);
+	err = icarus_gets(cgpu->proc_repr, rebuf, cgpu->device_fd, &tv_now, NULL, 10, ANTMINER_STATUS_LEN);
 	
 	
 	// Timeout is ok - checking specifically for an error here
 	// Timeout is ok - checking specifically for an error here
 	if (err == ICA_GETS_ERROR)
 	if (err == ICA_GETS_ERROR)
@@ -153,7 +153,7 @@ const char *antminer_set_clock(struct cgpu_info * const cgpu, const char * const
 	
 	
 	applog(LOG_DEBUG, "%"PRIpreprv": Set clock: %02x%02x%02x%02x", cgpu->proc_repr, cmd_buf[0], cmd_buf[1], cmd_buf[2], cmd_buf[3]);
 	applog(LOG_DEBUG, "%"PRIpreprv": Set clock: %02x%02x%02x%02x", cgpu->proc_repr, cmd_buf[0], cmd_buf[1], cmd_buf[2], cmd_buf[3]);
 	
 	
-	int err = icarus_write(cgpu->device_fd, cmd_buf, sizeof(cmd_buf));
+	int err = icarus_write(cgpu->proc_repr, cgpu->device_fd, cmd_buf, sizeof(cmd_buf));
 		
 		
 	if (err != 0)
 	if (err != 0)
 	{
 	{
@@ -183,7 +183,7 @@ void antminer_flash_led(const struct cgpu_info *antminer)
 	cmd_buf[offset + 3] = crc5usb(cmd_buf, sizeof(cmd_buf));
 	cmd_buf[offset + 3] = crc5usb(cmd_buf, sizeof(cmd_buf));
 
 
 	const int fd = antminer->device_fd;
 	const int fd = antminer->device_fd;
-	icarus_write(fd, (char *)(&cmd_buf), sizeof(cmd_buf));
+	icarus_write(antminer->proc_repr, fd, (char *)(&cmd_buf), sizeof(cmd_buf));
 }
 }
 
 
 static
 static

+ 4 - 4
driver-cairnsmore.c

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright 2012-2014 Luke Dashjr
+ * Copyright 2012-2015 Luke Dashjr
  *
  *
  * This program is free software; you can redistribute it and/or modify it
  * 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
  * under the terms of the GNU General Public License as published by the Free
@@ -78,7 +78,7 @@ static bool cairnsmore_send_cmd(int fd, uint8_t cmd, uint8_t data, bool probe)
 	return write(fd, pkt, sizeof(pkt)) == sizeof(pkt);
 	return write(fd, pkt, sizeof(pkt)) == sizeof(pkt);
 }
 }
 
 
-bool cairnsmore_supports_dynclock(int fd)
+bool cairnsmore_supports_dynclock(const char * const repr, const int fd)
 {
 {
 	if (!cairnsmore_send_cmd(fd, 0, 1, true))
 	if (!cairnsmore_send_cmd(fd, 0, 1, true))
 		return false;
 		return false;
@@ -92,7 +92,7 @@ bool cairnsmore_supports_dynclock(int fd)
 			.work_restart = false,
 			.work_restart = false,
 			.work_restart_notifier = {-1, -1},
 			.work_restart_notifier = {-1, -1},
 		};
 		};
-		icarus_gets((unsigned char*)&nonce, fd, &tv_finish, &dummy, 1, ICARUS_DEFAULT_READ_SIZE);
+		icarus_gets(repr, (unsigned char*)&nonce, fd, &tv_finish, &dummy, 1, ICARUS_DEFAULT_READ_SIZE);
 	}
 	}
 	applog(LOG_DEBUG, "Cairnsmore dynclock detection... Got %08x", nonce);
 	applog(LOG_DEBUG, "Cairnsmore dynclock detection... Got %08x", nonce);
 	switch (nonce) {
 	switch (nonce) {
@@ -133,7 +133,7 @@ static bool cairnsmore_init(struct thr_info *thr)
 	struct ICARUS_INFO *info = cm1->device_data;
 	struct ICARUS_INFO *info = cm1->device_data;
 	struct icarus_state *state = thr->cgpu_data;
 	struct icarus_state *state = thr->cgpu_data;
 
 
-	if (cairnsmore_supports_dynclock(cm1->device_fd)) {
+	if (cairnsmore_supports_dynclock(cm1->proc_repr, cm1->device_fd)) {
 		info->dclk_change_clock_func = cairnsmore_change_clock_func;
 		info->dclk_change_clock_func = cairnsmore_change_clock_func;
 
 
 		dclk_prepare(&info->dclk);
 		dclk_prepare(&info->dclk);

+ 19 - 20
driver-icarus.c

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright 2012-2014 Luke Dashjr
+ * Copyright 2012-2015 Luke Dashjr
  * Copyright 2012 Xiangfu
  * Copyright 2012 Xiangfu
  * Copyright 2014 Nate Woolls
  * Copyright 2014 Nate Woolls
  * Copyright 2012 Andrew Smith
  * Copyright 2012 Andrew Smith
@@ -163,14 +163,14 @@ uint32_t icarus_nonce32toh(const struct ICARUS_INFO * const info, const uint32_t
 #define icarus_open(devpath, baud)  icarus_open2(devpath, baud, false)
 #define icarus_open(devpath, baud)  icarus_open2(devpath, baud, false)
 
 
 static
 static
-void icarus_log_protocol(int fd, const void *buf, size_t bufLen, const char *prefix)
+void icarus_log_protocol(const char * const repr, const void *buf, size_t bufLen, const char *prefix)
 {
 {
 	char hex[(bufLen * 2) + 1];
 	char hex[(bufLen * 2) + 1];
 	bin2hex(hex, buf, bufLen);
 	bin2hex(hex, buf, bufLen);
-	applog(LOG_DEBUG, "%s fd=%d: DEVPROTO: %s %s", icarus_drv.dname, fd, prefix, hex);
+	applog(LOG_DEBUG, "%"PRIpreprv": DEVPROTO: %s %s", repr, prefix, hex);
 }
 }
 
 
-int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct thr_info *thr, int read_count, int read_size)
+int icarus_gets(const char * const repr, unsigned char *buf, int fd, struct timeval *tv_finish, struct thr_info *thr, int read_count, int read_size)
 {
 {
 	ssize_t ret = 0;
 	ssize_t ret = 0;
 	int rc = 0;
 	int rc = 0;
@@ -195,7 +195,7 @@ int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct th
 		{
 		{
 			ev.data.fd = thr->work_restart_notifier[0];
 			ev.data.fd = thr->work_restart_notifier[0];
 			if (-1 == epoll_ctl(epollfd, EPOLL_CTL_ADD, thr->work_restart_notifier[0], &ev))
 			if (-1 == epoll_ctl(epollfd, EPOLL_CTL_ADD, thr->work_restart_notifier[0], &ev))
-				applog(LOG_ERR, "%s: Error adding work restart fd to epoll", __func__);
+				applog(LOG_ERR, "%"PRIpreprv": Error adding work restart fd to epoll", repr);
 			else
 			else
 			{
 			{
 				epoll_timeout *= read_count;
 				epoll_timeout *= read_count;
@@ -204,7 +204,7 @@ int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct th
 		}
 		}
 	}
 	}
 	else
 	else
-		applog(LOG_ERR, "%s: Error creating epoll", __func__);
+		applog(LOG_ERR, "%"PRIpreprv": Error creating epoll", repr);
 	}
 	}
 #endif
 #endif
 
 
@@ -237,7 +237,7 @@ int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct th
 				close(epollfd);
 				close(epollfd);
 
 
 			if (opt_dev_protocol && opt_debug)
 			if (opt_dev_protocol && opt_debug)
-				icarus_log_protocol(fd, buf, read_size, "RECV");
+				icarus_log_protocol(repr, buf, read_size, "RECV");
 
 
 			return ICA_GETS_OK;
 			return ICA_GETS_OK;
 		}
 		}
@@ -252,7 +252,7 @@ int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct th
 		if (thr && thr->work_restart) {
 		if (thr && thr->work_restart) {
 			if (epollfd != -1)
 			if (epollfd != -1)
 				close(epollfd);
 				close(epollfd);
-			applog(LOG_DEBUG, "%s: Interrupted by work restart", __func__);
+			applog(LOG_DEBUG, "%"PRIpreprv": Interrupted by work restart", repr);
 			return ICA_GETS_RESTART;
 			return ICA_GETS_RESTART;
 		}
 		}
 
 
@@ -260,20 +260,20 @@ int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct th
 		if (rc >= read_count) {
 		if (rc >= read_count) {
 			if (epollfd != -1)
 			if (epollfd != -1)
 				close(epollfd);
 				close(epollfd);
-			applog(LOG_DEBUG, "%s: No data in %.2f seconds",
-			       __func__,
+			applog(LOG_DEBUG, "%"PRIpreprv": No data in %.2f seconds",
+			       repr,
 			       (float)rc * epoll_timeout / 1000.);
 			       (float)rc * epoll_timeout / 1000.);
 			return ICA_GETS_TIMEOUT;
 			return ICA_GETS_TIMEOUT;
 		}
 		}
 	}
 	}
 }
 }
 
 
-int icarus_write(int fd, const void *buf, size_t bufLen)
+int icarus_write(const char * const repr, int fd, const void *buf, size_t bufLen)
 {
 {
 	size_t ret;
 	size_t ret;
 
 
 	if (opt_dev_protocol && opt_debug)
 	if (opt_dev_protocol && opt_debug)
-		icarus_log_protocol(fd, buf, bufLen, "SEND");
+		icarus_log_protocol(repr, buf, bufLen, "SEND");
 
 
 	if (unlikely(fd == -1))
 	if (unlikely(fd == -1))
 		return 1;
 		return 1;
@@ -437,7 +437,6 @@ int icarus_excess_nonce_size(int fd, struct ICARUS_INFO *info)
 	// Read excess_size from Icarus
 	// Read excess_size from Icarus
 	struct timeval tv_now;
 	struct timeval tv_now;
 	timer_set_now(&tv_now);
 	timer_set_now(&tv_now);
-	//icarus_gets(excess_bin, fd, &tv_now, NULL, 1, excess_size);
 	int bytes_read = read(fd, excess_bin, excess_size);
 	int bytes_read = read(fd, excess_bin, excess_size);
 	// Number of bytes that were still available
 	// Number of bytes that were still available
 
 
@@ -463,9 +462,9 @@ int icarus_probe_work_division(const int fd, const char * const repr, struct ICA
 		"BFGMiner Probe\0\0"
 		"BFGMiner Probe\0\0"
 		"BFG\0\x64\x61\x01\x1a\xc9\x06\xa9\x51\xfb\x9b\x3c\x73";
 		"BFG\0\x64\x61\x01\x1a\xc9\x06\xa9\x51\xfb\x9b\x3c\x73";
 	
 	
-	icarus_write(fd, pkt, sizeof(pkt));
+	icarus_write(repr, fd, pkt, sizeof(pkt));
 	memset(res_bin, 0, sizeof(res_bin));
 	memset(res_bin, 0, sizeof(res_bin));
-	if (ICA_GETS_OK == icarus_gets(res_bin, fd, &tv_finish, NULL, info->read_count, info->read_size))
+	if (ICA_GETS_OK == icarus_gets(repr, res_bin, fd, &tv_finish, NULL, info->read_count, info->read_size))
 	{
 	{
 		memcpy(&res, res_bin, sizeof(res));
 		memcpy(&res, res_bin, sizeof(res));
 		res = icarus_nonce32toh(info, res);
 		res = icarus_nonce32toh(info, res);
@@ -553,14 +552,14 @@ struct cgpu_info *icarus_detect_custom(const char *devpath, struct device_drv *a
 	if (!info->ignore_golden_nonce)
 	if (!info->ignore_golden_nonce)
 	{
 	{
 		hex2bin(ob_bin, info->golden_ob, sizeof(ob_bin));
 		hex2bin(ob_bin, info->golden_ob, sizeof(ob_bin));
-		icarus_write(fd, ob_bin, sizeof(ob_bin));
+		icarus_write(devpath, fd, ob_bin, sizeof(ob_bin));
 		cgtime(&tv_start);
 		cgtime(&tv_start);
 		
 		
 		memset(nonce_bin, 0, sizeof(nonce_bin));
 		memset(nonce_bin, 0, sizeof(nonce_bin));
 		// Do not use info->read_size here, instead read exactly ICARUS_NONCE_SIZE
 		// Do not use info->read_size here, instead read exactly ICARUS_NONCE_SIZE
 		// We will then compare the bytes left in fd with info->read_size to determine
 		// We will then compare the bytes left in fd with info->read_size to determine
 		// if this is a valid device
 		// if this is a valid device
-		icarus_gets(nonce_bin, fd, &tv_finish, NULL, info->probe_read_count, ICARUS_NONCE_SIZE);
+		icarus_gets(devpath, nonce_bin, fd, &tv_finish, NULL, info->probe_read_count, ICARUS_NONCE_SIZE);
 		
 		
 		// How many bytes were left after reading the above nonce
 		// How many bytes were left after reading the above nonce
 		int bytes_left = icarus_excess_nonce_size(fd, info);
 		int bytes_left = icarus_excess_nonce_size(fd, info);
@@ -784,7 +783,7 @@ bool icarus_job_start(struct thr_info *thr)
 	
 	
 	cgtime(&state->tv_workstart);
 	cgtime(&state->tv_workstart);
 
 
-	ret = icarus_write(fd, ob_bin, info->ob_size);
+	ret = icarus_write(icarus->proc_repr, fd, ob_bin, info->ob_size);
 	if (ret) {
 	if (ret) {
 		do_icarus_close(thr);
 		do_icarus_close(thr);
 		applog(LOG_ERR, "%"PRIpreprv": Comms error (werr=%d)", icarus->proc_repr, ret);
 		applog(LOG_ERR, "%"PRIpreprv": Comms error (werr=%d)", icarus->proc_repr, ret);
@@ -848,7 +847,7 @@ void handle_identify(struct thr_info * const thr, int ret, const bool was_first_
 			
 			
 			// Try to get more nonces (ignoring work restart)
 			// Try to get more nonces (ignoring work restart)
 			memset(nonce_bin, 0, sizeof(nonce_bin));
 			memset(nonce_bin, 0, sizeof(nonce_bin));
-			ret = icarus_gets(nonce_bin, fd, &tv_now, NULL, (info->fullnonce - delapsed) * 10, info->read_size);
+			ret = icarus_gets(icarus->proc_repr, nonce_bin, fd, &tv_now, NULL, (info->fullnonce - delapsed) * 10, info->read_size);
 			if (ret == ICA_GETS_OK)
 			if (ret == ICA_GETS_OK)
 			{
 			{
 				memcpy(&nonce, nonce_bin, sizeof(nonce));
 				memcpy(&nonce, nonce_bin, sizeof(nonce));
@@ -950,7 +949,7 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 keepwaiting:
 keepwaiting:
 			/* Icarus will return info->read_size bytes nonces or nothing */
 			/* Icarus will return info->read_size bytes nonces or nothing */
 			memset(nonce_bin, 0, sizeof(nonce_bin));
 			memset(nonce_bin, 0, sizeof(nonce_bin));
-			ret = icarus_gets(nonce_bin, fd, &state->tv_workfinish, thr, read_count, info->read_size);
+			ret = icarus_gets(icarus->proc_repr, nonce_bin, fd, &state->tv_workfinish, thr, read_count, info->read_size);
 			switch (ret) {
 			switch (ret) {
 				case ICA_GETS_RESTART:
 				case ICA_GETS_RESTART:
 					// The prepared work is invalid, and the current work is abandoned
 					// The prepared work is invalid, and the current work is abandoned

+ 2 - 2
driver-icarus.h

@@ -162,8 +162,8 @@ struct icarus_state {
 };
 };
 
 
 extern struct cgpu_info *icarus_detect_custom(const char *devpath, struct device_drv *, struct ICARUS_INFO *);
 extern struct cgpu_info *icarus_detect_custom(const char *devpath, struct device_drv *, struct ICARUS_INFO *);
-extern int icarus_gets(unsigned char *, int fd, struct timeval *tv_finish, struct thr_info *, int read_count, int read_size);
-extern int icarus_write(int fd, const void *buf, size_t bufLen);
+extern int icarus_gets(const char *repr, unsigned char *, int fd, struct timeval *tv_finish, struct thr_info *, int read_count, int read_size);
+extern int icarus_write(const char *repr, int fd, const void *buf, size_t bufLen);
 extern bool icarus_init(struct thr_info *);
 extern bool icarus_init(struct thr_info *);
 extern void do_icarus_close(struct thr_info *thr);
 extern void do_icarus_close(struct thr_info *thr);
 extern bool icarus_job_start(struct thr_info *);
 extern bool icarus_job_start(struct thr_info *);