Browse Source

Semi-Merge commit 'b53fa54' into cg_merges_20121208 (noop, warnings were already fixed)

Conflicts:
	driver-ztex.c
	libztex.c
Luke Dashjr 13 years ago
parent
commit
2fcc8b4aea
3 changed files with 32 additions and 23 deletions
  1. 6 8
      driver-ztex.c
  2. 24 13
      libztex.c
  3. 2 2
      libztex.h

+ 6 - 8
driver-ztex.c

@@ -165,7 +165,7 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
 	work->data[64 + 12 + 3] = (hdata->nonce >> 24) & 0xff;
 	work->data[64 + 12 + 3] = (hdata->nonce >> 24) & 0xff;
 
 
 	swap32yes(swap32, data32, 80 / 4);
 	swap32yes(swap32, data32, 80 / 4);
-	
+
 	sha2(swap, 80, hash1, false);
 	sha2(swap, 80, hash1, false);
 	sha2(hash1, 32, hash2, false);
 	sha2(hash1, 32, hash2, false);
 	if (htobe32(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
 	if (htobe32(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
@@ -193,7 +193,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 
 
 	memcpy(sendbuf, work->data + 64, 12);
 	memcpy(sendbuf, work->data + 64, 12);
 	memcpy(sendbuf + 12, work->midstate, 32);
 	memcpy(sendbuf + 12, work->midstate, 32);
-	
+
 	ztex_selectFpga(ztex);
 	ztex_selectFpga(ztex);
 	i = libztex_sendHashData(ztex, sendbuf);
 	i = libztex_sendHashData(ztex, sendbuf);
 	if (i < 0) {
 	if (i < 0) {
@@ -210,7 +210,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 		}
 		}
 	}
 	}
 	ztex_releaseFpga(ztex);
 	ztex_releaseFpga(ztex);
-	
+
 	applog(LOG_DEBUG, "%s: sent hashdata", ztex->repr);
 	applog(LOG_DEBUG, "%s: sent hashdata", ztex->repr);
 
 
 	lastnonce = calloc(1, sizeof(uint32_t)*ztex->numNonces);
 	lastnonce = calloc(1, sizeof(uint32_t)*ztex->numNonces);
@@ -227,7 +227,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 		free(lastnonce);
 		free(lastnonce);
 		return -1;
 		return -1;
 	}
 	}
-	
+
 	overflow = false;
 	overflow = false;
 
 
 	applog(LOG_DEBUG, "%s: entering poll loop", ztex->repr);
 	applog(LOG_DEBUG, "%s: entering poll loop", ztex->repr);
@@ -301,9 +301,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 					}
 					}
 				}
 				}
 			}
 			}
-
 		}
 		}
-
 	}
 	}
 
 
 	dclk_preUpdate(&ztex->dclk);
 	dclk_preUpdate(&ztex->dclk);
@@ -322,7 +320,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 
 
 	free(lastnonce);
 	free(lastnonce);
 	free(backlog);
 	free(backlog);
-	
+
 	return noncecnt;
 	return noncecnt;
 }
 }
 
 
@@ -361,7 +359,7 @@ static bool ztex_prepare(struct thr_info *thr)
 
 
 	gettimeofday(&now, NULL);
 	gettimeofday(&now, NULL);
 	get_datestamp(cgpu->init, &now);
 	get_datestamp(cgpu->init, &now);
-	
+
 	ztex_selectFpga(ztex);
 	ztex_selectFpga(ztex);
 	if (libztex_configureFpga(ztex) != 0) {
 	if (libztex_configureFpga(ztex) != 0) {
 		libztex_resetFpga(ztex);
 		libztex_resetFpga(ztex);

+ 24 - 13
libztex.c

@@ -53,7 +53,8 @@
 #define CAPABILITY_MULTI_FPGA 0,7
 #define CAPABILITY_MULTI_FPGA 0,7
 
 
 static int libztex_get_string_descriptor_ascii(libusb_device_handle *dev, uint8_t desc_index,
 static int libztex_get_string_descriptor_ascii(libusb_device_handle *dev, uint8_t desc_index,
-		unsigned char *data, int length) {
+		unsigned char *data, int length)
+{
 	int i, cnt;
 	int i, cnt;
 	uint16_t langid;
 	uint16_t langid;
 	unsigned char buf[260];
 	unsigned char buf[260];
@@ -94,7 +95,8 @@ static int libztex_get_string_descriptor_ascii(libusb_device_handle *dev, uint8_
 	return LIBUSB_SUCCESS;
 	return LIBUSB_SUCCESS;
 }
 }
 
 
-enum check_result {
+enum check_result
+{
 	CHECK_ERROR,
 	CHECK_ERROR,
 	CHECK_IS_NOT_ZTEX,
 	CHECK_IS_NOT_ZTEX,
 	CHECK_OK,
 	CHECK_OK,
@@ -498,9 +500,11 @@ int libztex_configureFpga(struct libztex_device *ztex)
 	return rv;
 	return rv;
 }
 }
 
 
-int libztex_numberOfFpgas(struct libztex_device *ztex) {
+int libztex_numberOfFpgas(struct libztex_device *ztex)
+{
 	int cnt;
 	int cnt;
 	unsigned char buf[3];
 	unsigned char buf[3];
+
 	if (ztex->numberOfFpgas < 0) {
 	if (ztex->numberOfFpgas < 0) {
 		if (libztex_checkCapability(ztex, CAPABILITY_MULTI_FPGA)) {
 		if (libztex_checkCapability(ztex, CAPABILITY_MULTI_FPGA)) {
 			cnt = libusb_control_transfer(ztex->hndl, 0xc0, 0x50, 0, 0, buf, 3, 1000);
 			cnt = libusb_control_transfer(ztex->hndl, 0xc0, 0x50, 0, 0, buf, 3, 1000);
@@ -520,15 +524,17 @@ int libztex_numberOfFpgas(struct libztex_device *ztex) {
 	return ztex->numberOfFpgas;
 	return ztex->numberOfFpgas;
 }
 }
 
 
-int libztex_selectFpga(struct libztex_device *ztex) {
+int libztex_selectFpga(struct libztex_device *ztex)
+{
 	int cnt, fpgacnt = libztex_numberOfFpgas(ztex->root);
 	int cnt, fpgacnt = libztex_numberOfFpgas(ztex->root);
-	int number = ztex->fpgaNum;
+	int16_t number = ztex->fpgaNum;
+
 	if (number < 0 || number >= fpgacnt) {
 	if (number < 0 || number >= fpgacnt) {
 		applog(LOG_WARNING, "%s: Trying to select wrong fpga (%d in %d)", ztex->repr, number, fpgacnt);
 		applog(LOG_WARNING, "%s: Trying to select wrong fpga (%d in %d)", ztex->repr, number, fpgacnt);
 		return 1;
 		return 1;
 	}
 	}
 	if (ztex->root->selectedFpga != number && libztex_checkCapability(ztex->root, CAPABILITY_MULTI_FPGA)) {
 	if (ztex->root->selectedFpga != number && libztex_checkCapability(ztex->root, CAPABILITY_MULTI_FPGA)) {
-		cnt = libusb_control_transfer(ztex->root->hndl, 0x40, 0x51, number, 0, NULL, 0, 500);
+		cnt = libusb_control_transfer(ztex->root->hndl, 0x40, 0x51, (uint16_t)number, 0, NULL, 0, 500);
 		if (unlikely(cnt < 0)) {
 		if (unlikely(cnt < 0)) {
 			applog(LOG_ERR, "Ztex check device: Failed to set fpga with err %d", cnt);
 			applog(LOG_ERR, "Ztex check device: Failed to set fpga with err %d", cnt);
 			return cnt;
 			return cnt;
@@ -538,7 +544,8 @@ int libztex_selectFpga(struct libztex_device *ztex) {
 	return 0;
 	return 0;
 }
 }
 
 
-int libztex_setFreq(struct libztex_device *ztex, uint16_t freq) {
+int libztex_setFreq(struct libztex_device *ztex, uint16_t freq)
+{
 	int cnt;
 	int cnt;
 	uint16_t oldfreq = ztex->dclk.freqM;
 	uint16_t oldfreq = ztex->dclk.freqM;
 
 
@@ -572,7 +579,8 @@ int libztex_resetFpga(struct libztex_device *ztex)
 	return libusb_control_transfer(ztex->hndl, 0x40, 0x31, 0, 0, NULL, 0, 1000);
 	return libusb_control_transfer(ztex->hndl, 0x40, 0x31, 0, 0, NULL, 0, 1000);
 }
 }
 
 
-int libztex_suspend(struct libztex_device *ztex) {
+int libztex_suspend(struct libztex_device *ztex)
+{
 	if (ztex->suspendSupported) {
 	if (ztex->suspendSupported) {
 		return libusb_control_transfer(ztex->hndl, 0x40, 0x84, 0, 0, NULL, 0, 1000);
 		return libusb_control_transfer(ztex->hndl, 0x40, 0x84, 0, 0, NULL, 0, 1000);
 	} else {
 	} else {
@@ -580,7 +588,8 @@ int libztex_suspend(struct libztex_device *ztex) {
 	}
 	}
 }
 }
 
 
-int libztex_prepare_device(struct libusb_device *dev, struct libztex_device** ztex) {
+int libztex_prepare_device(struct libusb_device *dev, struct libztex_device** ztex)
+{
 	struct libztex_device *newdev = *ztex;
 	struct libztex_device *newdev = *ztex;
 	int i, cnt, err;
 	int i, cnt, err;
 	unsigned char buf[64];
 	unsigned char buf[64];
@@ -609,7 +618,7 @@ int libztex_prepare_device(struct libusb_device *dev, struct libztex_device** zt
 		applog(LOG_ERR, "Ztex check device: Failed to read ztex descriptor with err %d", cnt);
 		applog(LOG_ERR, "Ztex check device: Failed to read ztex descriptor with err %d", cnt);
 		return cnt;
 		return cnt;
 	}
 	}
-	
+
 	if (buf[0] != 40 || buf[1] != 1 || buf[2] != 'Z' || buf[3] != 'T' || buf[4] != 'E' || buf[5] != 'X') {
 	if (buf[0] != 40 || buf[1] != 1 || buf[2] != 'Z' || buf[3] != 'T' || buf[4] != 'E' || buf[5] != 'X') {
 		applog(LOG_ERR, "Ztex check device: Error reading ztex descriptor");
 		applog(LOG_ERR, "Ztex check device: Error reading ztex descriptor");
 		return 2;
 		return 2;
@@ -826,11 +835,12 @@ int libztex_sendHashData(struct libztex_device *ztex, unsigned char *sendbuf)
 	}
 	}
 	if (unlikely(cnt < 0))
 	if (unlikely(cnt < 0))
 		applog(LOG_ERR, "%s: Failed sendHashData with err %d", ztex->repr, cnt);
 		applog(LOG_ERR, "%s: Failed sendHashData with err %d", ztex->repr, cnt);
-	
+
 	return cnt;
 	return cnt;
 }
 }
 
 
-int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data nonces[]) {
+int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data nonces[])
+{
 	int bufsize = 12 + ztex->extraSolutions * 4;
 	int bufsize = 12 + ztex->extraSolutions * 4;
 	int cnt = 0, i, j, ret, len;
 	int cnt = 0, i, j, ret, len;
 	unsigned char *rbuf;
 	unsigned char *rbuf;
@@ -863,7 +873,7 @@ int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data n
 		memcpy((char*)&nonces[i].goldenNonce[0], &rbuf[i*bufsize], 4);
 		memcpy((char*)&nonces[i].goldenNonce[0], &rbuf[i*bufsize], 4);
 		nonces[i].goldenNonce[0] -= ztex->offsNonces;
 		nonces[i].goldenNonce[0] -= ztex->offsNonces;
 		//applog(LOG_DEBUG, "W %d:0 %0.8x", i, nonces[i].goldenNonce[0]);
 		//applog(LOG_DEBUG, "W %d:0 %0.8x", i, nonces[i].goldenNonce[0]);
-		
+
 		memcpy((char*)&nonces[i].nonce, &rbuf[(i*bufsize)+4], 4);
 		memcpy((char*)&nonces[i].nonce, &rbuf[(i*bufsize)+4], 4);
 		nonces[i].nonce -= ztex->offsNonces;
 		nonces[i].nonce -= ztex->offsNonces;
 		memcpy((char*)&nonces[i].hash7, &rbuf[(i*bufsize)+8], 4);
 		memcpy((char*)&nonces[i].hash7, &rbuf[(i*bufsize)+8], 4);
@@ -891,3 +901,4 @@ void libztex_freeDevList(struct libztex_dev_list **devs)
 	}
 	}
 	free(devs);
 	free(devs);
 }
 }
+

+ 2 - 2
libztex.h

@@ -44,7 +44,7 @@ struct libztex_fpgastate {
 struct libztex_device {
 struct libztex_device {
 	pthread_mutex_t	mutex;
 	pthread_mutex_t	mutex;
 	struct libztex_device *root;
 	struct libztex_device *root;
-	int fpgaNum;
+	int16_t fpgaNum;
 	bool valid;
 	bool valid;
 	struct libusb_device_descriptor descriptor;
 	struct libusb_device_descriptor descriptor;
 	libusb_device_handle *hndl; 
 	libusb_device_handle *hndl; 
@@ -66,7 +66,7 @@ struct libztex_device {
 
 
 	struct dclk_data dclk;
 	struct dclk_data dclk;
 
 
-	int numberOfFpgas;
+	int16_t numberOfFpgas;
 	int selectedFpga;
 	int selectedFpga;
 	bool parallelConfigSupport;
 	bool parallelConfigSupport;