Browse Source

gc3355: Refactor to remove SHA2 code specific to the 5-Chip GridSeed Orb

Code was not completed or functional and unlikely to be completed
Does not affect DualMiner ASICs
Nate Woolls 11 years ago
parent
commit
60cca3e21f
4 changed files with 47 additions and 179 deletions
  1. 1 1
      driver-dualminer.c
  2. 15 39
      driver-gridseed.c
  3. 30 138
      gc3355.c
  4. 1 1
      gc3355.h

+ 1 - 1
driver-dualminer.c

@@ -295,7 +295,7 @@ bool dualminer_job_prepare(struct thr_info *thr, struct work *work, __maybe_unus
 	if (opt_scrypt)
 	if (opt_scrypt)
 		gc3355_scrypt_prepare_work(state->ob_bin, work);
 		gc3355_scrypt_prepare_work(state->ob_bin, work);
 	else
 	else
-		gc3355_sha2_prepare_work(state->ob_bin, work, false);
+		gc3355_sha2_prepare_work(state->ob_bin, work);
 
 
 	return true;
 	return true;
 }
 }

+ 15 - 39
driver-gridseed.c

@@ -19,7 +19,6 @@
 #include "gc3355.h"
 #include "gc3355.h"
 
 
 #define GRIDSEED_DEFAULT_FREQUENCY  600
 #define GRIDSEED_DEFAULT_FREQUENCY  600
-#define GRIDSEED_MAX_QUEUED          10
 #define GRIDSEED_HASH_SPEED			0.0851128926	// in ms
 #define GRIDSEED_HASH_SPEED			0.0851128926	// in ms
 
 
 BFG_REGISTER_DRIVER(gridseed_drv)
 BFG_REGISTER_DRIVER(gridseed_drv)
@@ -135,12 +134,9 @@ bool gridseed_thread_prepare(struct thr_info *thr)
 {
 {
 	thr->cgpu_data = calloc(1, sizeof(*thr->cgpu_data));
 	thr->cgpu_data = calloc(1, sizeof(*thr->cgpu_data));
 	
 	
-	if (opt_scrypt)
-	{
-		struct cgpu_info *device = thr->cgpu;
-		device->min_nonce_diff = 1./0x10000;
-	}
-	
+	struct cgpu_info *device = thr->cgpu;
+	device->min_nonce_diff = 1./0x10000;
+
 	return true;
 	return true;
 }
 }
 
 
@@ -148,8 +144,8 @@ static
 void gridseed_thread_shutdown(struct thr_info *thr)
 void gridseed_thread_shutdown(struct thr_info *thr)
 {
 {
 	struct cgpu_info *device = thr->cgpu;
 	struct cgpu_info *device = thr->cgpu;
+
 	gc3355_close(device->device_fd);
 	gc3355_close(device->device_fd);
-	
 	free(thr->cgpu_data);
 	free(thr->cgpu_data);
 }
 }
 
 
@@ -163,22 +159,12 @@ bool gridseed_prepare_work(struct thr_info __maybe_unused *thr, struct work *wor
 {
 {
 	struct cgpu_info *device = thr->cgpu;
 	struct cgpu_info *device = thr->cgpu;
 	struct gc3355_orb_info *info = device->device_data;
 	struct gc3355_orb_info *info = device->device_data;
-
-	int work_size = opt_scrypt ? 156 : 52;
-	unsigned char cmd[work_size];
+	unsigned char cmd[156];
 	
 	
-	cgtime(&info->scanhash_time);
-
-	//from GC3355 docs if we are using FIFO
-	work->id = 12345678;
+	timer_set_now(&info->scanhash_time);
 
 
-	if (opt_scrypt)
-	{
-		gc3355_scrypt_reset(device->device_fd);
-		gc3355_scrypt_prepare_work(cmd, work);
-	}
-	else
-		gc3355_sha2_prepare_work(cmd, work, true);
+	gc3355_scrypt_reset(device->device_fd);
+	gc3355_scrypt_prepare_work(cmd, work);
 	
 	
 	// send work
 	// send work
 	if (sizeof(cmd) != gc3355_write(device->device_fd, cmd, sizeof(cmd)))
 	if (sizeof(cmd) != gc3355_write(device->device_fd, cmd, sizeof(cmd)))
@@ -204,7 +190,8 @@ int64_t gridseed_estimate_hashes(struct thr_info *thr)
 	struct cgpu_info *device = thr->cgpu;
 	struct cgpu_info *device = thr->cgpu;
 	struct gc3355_orb_info *info = device->device_data;
 	struct gc3355_orb_info *info = device->device_data;
 	struct timeval old_scanhash_time = info->scanhash_time;
 	struct timeval old_scanhash_time = info->scanhash_time;
-	cgtime(&info->scanhash_time);
+
+	timer_set_now(&info->scanhash_time);
 	int elapsed_ms = ms_tdiff(&info->scanhash_time, &old_scanhash_time);
 	int elapsed_ms = ms_tdiff(&info->scanhash_time, &old_scanhash_time);
 
 
 	return GRIDSEED_HASH_SPEED * (double)elapsed_ms * (double)(info->freq * info->chips);
 	return GRIDSEED_HASH_SPEED * (double)elapsed_ms * (double)(info->freq * info->chips);
@@ -222,20 +209,11 @@ int64_t gridseed_scanhash(struct thr_info *thr, struct work *work, int64_t __may
 
 
 	while (!thr->work_restart && (read = gc3355_read(fd, (char *)buf, GC3355_READ_SIZE)) > 0)
 	while (!thr->work_restart && (read = gc3355_read(fd, (char *)buf, GC3355_READ_SIZE)) > 0)
 	{
 	{
-		if (buf[0] == 0x55)
+		if ((buf[0] == 0x55) && (buf[1] == 0x20))
 		{
 		{
-			switch(buf[1]) {
-				case 0xaa:
-					// Queue length result
-					// could watch for watchdog reset here
-					break;
-				case 0x10: // BTC result
-				case 0x20: // LTC result
-				{
-					gridseed_submit_nonce(thr, buf, work);
-					break;
-				}
-			}
+			// LTC result
+			gridseed_submit_nonce(thr, buf, work);
+			break;
 		}
 		}
 		else
 		else
 		{
 		{
@@ -261,9 +239,7 @@ char *gridseed_set_device(struct cgpu_info *device, char *option, char *setting,
 	if (strcasecmp(option, "clock") == 0)
 	if (strcasecmp(option, "clock") == 0)
 	{
 	{
 		info->freq = val;
 		info->freq = val;
-		int fd = device->device_fd;
-		
-		gc3355_set_pll_freq(fd, val);
+		gc3355_set_pll_freq(device->device_fd, val);
 		
 		
 		return NULL;
 		return NULL;
 	}
 	}

+ 30 - 138
gc3355.c

@@ -34,8 +34,6 @@ int opt_sha2_units = -1;
 int opt_pll_freq = 0; // default is set in gc3355_set_pll_freq
 int opt_pll_freq = 0; // default is set in gc3355_set_pll_freq
 
 
 #define GC3355_CHIP_NAME  "gc3355"
 #define GC3355_CHIP_NAME  "gc3355"
-#define DEFAULT_ORB_SHA2_CORES  16
-
 
 
 // General GC3355 commands
 // General GC3355 commands
 
 
@@ -504,96 +502,26 @@ void gc3355_scrypt_only_init(int fd)
 	gc3355_scrypt_only_reset(fd);
 	gc3355_scrypt_only_reset(fd);
 }
 }
 
 
-static
-void gc3355_open_sha2_cores(int fd, int sha2_cores)
-{
-	unsigned char cmd[24], c1, c2;
-	uint16_t	mask;
-	int i;
-	
-	mask = 0x00;
-	for (i = 0; i < sha2_cores; i++)
-		mask = mask << 1 | 0x01;
-	
-	if (mask == 0)
-		return;
-	
-	c1 = mask & 0x00ff;
-	c2 = mask >> 8;
-	
-	memset(cmd, 0, sizeof(cmd));
-	memcpy(cmd, "\x55\xaa\xef\x02", 4);
-	for (i = 4; i < 24; i++) {
-		cmd[i] = ((i % 2) == 0) ? c1 : c2;
-		gc3355_write(fd, cmd, sizeof(cmd));
-		cgsleep_ms(GC3355_COMMAND_DELAY_MS);
-	}
-	return;
-}
-
-static
-void gc3355_init_sha2_nonce(int fd)
-{
-	char **cmds, *p;
-	uint32_t nonce, step;
-	int i;
-	
-	cmds = calloc(sizeof(char *) *(GC3355_ORB_DEFAULT_CHIPS + 1), 1);
-	
-	if (unlikely(!cmds))
-		quit(1, "Failed to calloc init nonce commands data array");
-	
-	step = 0xffffffff / GC3355_ORB_DEFAULT_CHIPS;
-	
-	for (i = 0; i < GC3355_ORB_DEFAULT_CHIPS; i++)
-	{
-		p = calloc(8, 1);
-		
-		if (unlikely(!p))
-			quit(1, "Failed to calloc init nonce commands data");
-		
-		memcpy(p, "\x55\xaa\x00\x00", 4);
-		
-		p[2] = i;
-		nonce = htole32(step * i);
-		memcpy(p + 4, &nonce, sizeof(nonce));
-		cmds[i] = p;
-	}
-	
-	cmds[i] = NULL;
-	gc3355_send_cmds_bin(fd, (const char **)cmds, 8);
-	
-	for (i = 0; i < GC3355_ORB_DEFAULT_CHIPS; i++)
-		free(cmds[i]);
-	
-	free(cmds);
-	return;
-}
-
 void gc3355_sha2_init(int fd)
 void gc3355_sha2_init(int fd)
 {
 {
 	gc3355_send_cmds(fd, sha2_gating_cmd);
 	gc3355_send_cmds(fd, sha2_gating_cmd);
 	gc3355_send_cmds(fd, sha2_init_cmd);
 	gc3355_send_cmds(fd, sha2_init_cmd);
 }
 }
 
 
-static
-void gc3355_reset_chips(int fd)
-{
-	// reset chips
-	gc3355_send_cmds(fd, gcp_chip_reset_cmd);
-	gc3355_send_cmds(fd, sha2_chip_reset_cmd);
-}
-
 void gc3355_init_device(int fd, int pll_freq, bool scrypt_only, bool detect_only, bool usbstick)
 void gc3355_init_device(int fd, int pll_freq, bool scrypt_only, bool detect_only, bool usbstick)
 {
 {
-	gc3355_reset_chips(fd);
+	gc3355_send_cmds(fd, gcp_chip_reset_cmd);
 
 
-	if (usbstick)
-		gc3355_reset_dtr(fd);
+	// zzz
+	cgsleep_ms(GC3355_COMMAND_DELAY_MS);
 
 
 	if (usbstick)
 	if (usbstick)
 	{
 	{
+		gc3355_send_cmds(fd, sha2_chip_reset_cmd);
+
 		// initialize units
 		// initialize units
+		gc3355_reset_dtr(fd);
+
 		if (opt_scrypt && scrypt_only)
 		if (opt_scrypt && scrypt_only)
 			gc3355_scrypt_only_init(fd);
 			gc3355_scrypt_only_init(fd);
 		else
 		else
@@ -601,46 +529,28 @@ void gc3355_init_device(int fd, int pll_freq, bool scrypt_only, bool detect_only
 			gc3355_sha2_init(fd);
 			gc3355_sha2_init(fd);
 			gc3355_scrypt_init(fd);
 			gc3355_scrypt_init(fd);
 		}
 		}
-
-		//set freq
-		gc3355_set_pll_freq(fd, pll_freq);
 	}
 	}
 	else
 	else
 	{
 	{
-		// zzz
-		cgsleep_ms(GC3355_COMMAND_DELAY_MS);
-		
 		// initialize units
 		// initialize units
 		gc3355_send_cmds(fd, multichip_init_cmd);
 		gc3355_send_cmds(fd, multichip_init_cmd);
 		gc3355_scrypt_init(fd);
 		gc3355_scrypt_init(fd);
-
-		//set freq
-		gc3355_set_pll_freq(fd, pll_freq);
-		
-		//init sha2 nonce
-		gc3355_init_sha2_nonce(fd);
 	}
 	}
 
 
+	//set freq
+	gc3355_set_pll_freq(fd, pll_freq);
+
 	// zzz
 	// zzz
 	cgsleep_ms(GC3355_COMMAND_DELAY_MS);
 	cgsleep_ms(GC3355_COMMAND_DELAY_MS);
 
 
-	if (!detect_only)
+	if (usbstick && !detect_only)
 	{
 	{
 		if (!opt_scrypt)
 		if (!opt_scrypt)
-		{
-			if (usbstick)
-				// open sha2 units
-				gc3355_open_sha2_units(fd, opt_sha2_units);
-			else
-			{
-				// open sha2 cores
-				gc3355_open_sha2_cores(fd, DEFAULT_ORB_SHA2_CORES);
-			}
-		}
+			// open sha2 units
+			gc3355_open_sha2_units(fd, opt_sha2_units);
 
 
-		if (usbstick)
-			// set request to send (RTS) status
-			set_serial_rts(fd, BGV_HIGH);
+		// set request to send (RTS) status
+		set_serial_rts(fd, BGV_HIGH);
 	}
 	}
 }
 }
 
 
@@ -683,40 +593,22 @@ void gc3355_scrypt_prepare_work(unsigned char cmd[156], struct work *work)
 	memcpy(cmd + 152, &(workid), 4);
 	memcpy(cmd + 152, &(workid), 4);
 }
 }
 
 
-void gc3355_sha2_prepare_work(unsigned char cmd[52], struct work *work, bool simple)
+void gc3355_sha2_prepare_work(unsigned char cmd[52], struct work *work)
 {
 {
-	if (simple)
-	{
-		// command header
-		cmd[0] = 0x55;
-		cmd[1] = 0xaa;
-		cmd[2] = 0x0f;
-		cmd[3] = 0x01; // SHA header sig
-		
-		memcpy(cmd + 4, work->midstate, 32);
-		memcpy(cmd + 36, work->data + 64, 12);
-		
-		// taskid
-		int workid = work->id;
-		memcpy(cmd + 48, &(workid), 4);
-	}
-	else
-	{
-		// command header
-		cmd[0] = 0x55;
-		cmd[1] = 0xaa;
-		cmd[2] = 0x0f;
-		cmd[3] = 0x00; // Scrypt header sig - used by DualMiner in Dual Mode
-		
-		uint8_t temp_bin[64];
-		memset(temp_bin, 0, 64);
-		
-		memcpy(temp_bin, work->midstate, 32);
-		memcpy(temp_bin + 52, work->data + 64, 12);
-		
-		memcpy(cmd + 8, work->midstate, 32);
-		memcpy(cmd + 40, temp_bin + 52, 12);
-	}
+	// command header
+	cmd[0] = 0x55;
+	cmd[1] = 0xaa;
+	cmd[2] = 0x0f;
+	cmd[3] = 0x00; // Scrypt header sig - used by DualMiner in Dual Mode
+
+	uint8_t temp_bin[64];
+	memset(temp_bin, 0, 64);
+
+	memcpy(temp_bin, work->midstate, 32);
+	memcpy(temp_bin + 52, work->data + 64, 12);
+
+	memcpy(cmd + 8, work->midstate, 32);
+	memcpy(cmd + 40, temp_bin + 52, 12);
 }
 }
 
 
 int64_t gc3355_get_firmware_version(int fd)
 int64_t gc3355_get_firmware_version(int fd)

+ 1 - 1
gc3355.h

@@ -57,7 +57,7 @@ extern
 void gc3355_scrypt_only_reset(int fd);
 void gc3355_scrypt_only_reset(int fd);
 
 
 extern void gc3355_scrypt_prepare_work(unsigned char cmd[156], struct work *);
 extern void gc3355_scrypt_prepare_work(unsigned char cmd[156], struct work *);
-extern void gc3355_sha2_prepare_work(unsigned char cmd[52], struct work *, bool simple);
+extern void gc3355_sha2_prepare_work(unsigned char cmd[52], struct work *);
 extern int64_t gc3355_get_firmware_version(int fd);
 extern int64_t gc3355_get_firmware_version(int fd);
 extern void gc3355_set_pll_freq(int fd, int pll_freq);
 extern void gc3355_set_pll_freq(int fd, int pll_freq);