Merge pull request #347 from denis2342/ztex Ztex: more whitespace and style fixes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
diff --git a/driver-ztex.c b/driver-ztex.c
index 40afb05..ae58ec8 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -170,7 +170,7 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
for (i = 0; i < 80 / 4; i++)
swap32[i] = swab32(data32[i]);
-
+
sha2(swap, 80, hash1, false);
sha2(hash1, 32, hash2, false);
#if defined(__BIGENDIAN__) || defined(MIPSEB)
@@ -202,7 +202,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
memcpy(sendbuf, work->data + 64, 12);
memcpy(sendbuf + 12, work->midstate, 32);
-
+
ztex_selectFpga(ztex);
i = libztex_sendHashData(ztex, sendbuf);
if (i < 0) {
@@ -219,7 +219,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
}
}
ztex_releaseFpga(ztex);
-
+
applog(LOG_DEBUG, "%s: sent hashdata", ztex->repr);
lastnonce = calloc(1, sizeof(uint32_t)*ztex->numNonces);
@@ -235,7 +235,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
applog(LOG_ERR, "%s: failed to allocate backlog[%d]", ztex->repr, backlog_max);
return -1;
}
-
+
overflow = false;
applog(LOG_DEBUG, "%s: entering poll loop", ztex->repr);
@@ -315,9 +315,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
}
}
}
-
}
-
}
ztex->errorRate[ztex->freqM] = ztex->errorCount[ztex->freqM] / ztex->errorWeight[ztex->freqM] * (ztex->errorWeight[ztex->freqM] < 100? ztex->errorWeight[ztex->freqM] * 0.01: 1.0);
@@ -338,7 +336,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
free(lastnonce);
free(backlog);
-
+
return noncecnt;
}
@@ -358,7 +356,7 @@ static bool ztex_prepare(struct thr_info *thr)
gettimeofday(&now, NULL);
get_datestamp(cgpu->init, &now);
-
+
ztex_selectFpga(ztex);
if (libztex_configureFpga(ztex) != 0) {
libztex_resetFpga(ztex);
diff --git a/libztex.c b/libztex.c
index 21c8c04..2a20468 100644
--- a/libztex.c
+++ b/libztex.c
@@ -50,7 +50,8 @@
#define CAPABILITY_MULTI_FPGA 0,7
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;
uint16_t langid;
unsigned char buf[260];
@@ -91,7 +92,8 @@ static int libztex_get_string_descriptor_ascii(libusb_device_handle *dev, uint8_
return LIBUSB_SUCCESS;
}
-enum check_result {
+enum check_result
+{
CHECK_ERROR,
CHECK_IS_NOT_ZTEX,
CHECK_OK,
@@ -495,9 +497,11 @@ int libztex_configureFpga(struct libztex_device *ztex)
return rv;
}
-int libztex_numberOfFpgas(struct libztex_device *ztex) {
+int libztex_numberOfFpgas(struct libztex_device *ztex)
+{
int cnt;
unsigned char buf[3];
+
if (ztex->numberOfFpgas < 0) {
if (libztex_checkCapability(ztex, CAPABILITY_MULTI_FPGA)) {
cnt = libusb_control_transfer(ztex->hndl, 0xc0, 0x50, 0, 0, buf, 3, 1000);
@@ -517,9 +521,11 @@ int libztex_numberOfFpgas(struct libztex_device *ztex) {
return ztex->numberOfFpgas;
}
-int libztex_selectFpga(struct libztex_device *ztex) {
+int libztex_selectFpga(struct libztex_device *ztex)
+{
int cnt, fpgacnt = libztex_numberOfFpgas(ztex->root);
int16_t number = ztex->fpgaNum;
+
if (number < 0 || number >= fpgacnt) {
applog(LOG_WARNING, "%s: Trying to select wrong fpga (%d in %d)", ztex->repr, number, fpgacnt);
return 1;
@@ -535,7 +541,8 @@ int libztex_selectFpga(struct libztex_device *ztex) {
return 0;
}
-int libztex_setFreq(struct libztex_device *ztex, uint16_t freq) {
+int libztex_setFreq(struct libztex_device *ztex, uint16_t freq)
+{
int cnt;
uint16_t oldfreq = ztex->freqM;
@@ -563,7 +570,8 @@ int libztex_resetFpga(struct libztex_device *ztex)
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) {
return libusb_control_transfer(ztex->hndl, 0x40, 0x84, 0, 0, NULL, 0, 1000);
} else {
@@ -571,7 +579,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;
int i, cnt, err;
unsigned char buf[64];
@@ -599,7 +608,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);
return cnt;
}
-
+
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");
return 2;
@@ -823,11 +832,12 @@ int libztex_sendHashData(struct libztex_device *ztex, unsigned char *sendbuf)
}
if (unlikely(cnt < 0))
applog(LOG_ERR, "%s: Failed sendHashData with err %d", ztex->repr, 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 cnt = 0, i, j, ret, len;
unsigned char *rbuf;
@@ -860,7 +870,7 @@ int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data n
memcpy((char*)&nonces[i].goldenNonce[0], &rbuf[i*bufsize], 4);
nonces[i].goldenNonce[0] -= ztex->offsNonces;
//applog(LOG_DEBUG, "W %d:0 %0.8x", i, nonces[i].goldenNonce[0]);
-
+
memcpy((char*)&nonces[i].nonce, &rbuf[(i*bufsize)+4], 4);
nonces[i].nonce -= ztex->offsNonces;
memcpy((char*)&nonces[i].hash7, &rbuf[(i*bufsize)+8], 4);
@@ -888,3 +898,4 @@ void libztex_freeDevList(struct libztex_dev_list **devs)
}
free(devs);
}
+