Merge pull request #499 from someone42/master changes to bitburner driver for bitburner fury boards
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
diff --git a/cgminer.c b/cgminer.c
index f406f88..c0b8d2e 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1245,7 +1245,10 @@ static struct opt_table opt_config_table[] = {
"Set avalon target temperature"),
OPT_WITH_ARG("--bitburner-voltage",
opt_set_intval, NULL, &opt_bitburner_core_voltage,
- "Set BitBurner core voltage, in millivolts"),
+ "Set BitBurner (Avalon) core voltage, in millivolts"),
+ OPT_WITH_ARG("--bitburner-fury-voltage",
+ opt_set_intval, NULL, &opt_bitburner_fury_core_voltage,
+ "Set BitBurner Fury core voltage, in millivolts"),
#endif
#ifdef USE_KLONDIKE
OPT_WITH_ARG("--klondike-options",
diff --git a/driver-avalon.c b/driver-avalon.c
index 341a635..09e6dfa 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -49,6 +49,7 @@ int opt_avalon_fan_max = AVALON_DEFAULT_FAN_MAX_PWM;
int opt_avalon_freq_min = AVALON_MIN_FREQUENCY;
int opt_avalon_freq_max = AVALON_MAX_FREQUENCY;
int opt_bitburner_core_voltage = BITBURNER_DEFAULT_CORE_VOLTAGE;
+int opt_bitburner_fury_core_voltage = BITBURNER_FURY_DEFAULT_CORE_VOLTAGE;
bool opt_avalon_auto;
static int option_offset = -1;
@@ -209,6 +210,55 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
return ret;
}
+static int bitburner_send_task(const struct avalon_task *at, struct cgpu_info *avalon)
+
+{
+ uint8_t buf[AVALON_WRITE_SIZE + 4 * AVALON_DEFAULT_ASIC_NUM];
+ int ret, ep = C_AVALON_TASK;
+ cgtimer_t ts_start;
+ size_t nr_len;
+
+ if (at->nonce_elf)
+ nr_len = AVALON_WRITE_SIZE + 4 * at->asic_num;
+ else
+ nr_len = AVALON_WRITE_SIZE;
+
+ memset(buf, 0, nr_len);
+ memcpy(buf, at, AVALON_WRITE_SIZE);
+
+#if defined(__BIG_ENDIAN__) || defined(MIPSEB)
+ uint8_t tt = 0;
+
+ tt = (buf[0] & 0x0f) << 4;
+ tt |= ((buf[0] & 0x10) ? (1 << 3) : 0);
+ tt |= ((buf[0] & 0x20) ? (1 << 2) : 0);
+ tt |= ((buf[0] & 0x40) ? (1 << 1) : 0);
+ tt |= ((buf[0] & 0x80) ? (1 << 0) : 0);
+ buf[0] = tt;
+
+ tt = (buf[4] & 0x0f) << 4;
+ tt |= ((buf[4] & 0x10) ? (1 << 3) : 0);
+ tt |= ((buf[4] & 0x20) ? (1 << 2) : 0);
+ tt |= ((buf[4] & 0x40) ? (1 << 1) : 0);
+ tt |= ((buf[4] & 0x80) ? (1 << 0) : 0);
+ buf[4] = tt;
+#endif
+
+ if (at->reset) {
+ ep = C_AVALON_RESET;
+ nr_len = 1;
+ }
+ if (opt_debug) {
+ applog(LOG_DEBUG, "Avalon: Sent(%u):", (unsigned int)nr_len);
+ hexdump(buf, nr_len);
+ }
+ cgsleep_prepare_r(&ts_start);
+ ret = avalon_write(avalon, (char *)buf, nr_len, ep);
+ cgsleep_us_r(&ts_start, 3000); // 3 ms = 333 tasks per second, or 1.4 TH/s
+
+ return ret;
+}
+
static bool avalon_decode_nonce(struct thr_info *thr, struct cgpu_info *avalon,
struct avalon_info *info, struct avalon_result *ar,
struct work *work)
@@ -414,12 +464,12 @@ static bool get_options(int this_option_offset, int *baud, int *miner_count,
if (*colon) {
tmp = atoi(colon);
- if (tmp > 0 && tmp <= AVALON_DEFAULT_MINER_NUM) {
+ if (tmp > 0 && tmp <= AVALON_MAX_MINER_NUM) {
*miner_count = tmp;
} else {
quit(1, "Invalid avalon-options for "
"miner_count (%s) must be 1 ~ %d",
- colon, AVALON_DEFAULT_MINER_NUM);
+ colon, AVALON_MAX_MINER_NUM);
}
}
@@ -620,12 +670,20 @@ static void avalon_initialise(struct cgpu_info *avalon)
avalon->drv->name, avalon->device_id, err);
}
+static bool is_bitburner(struct cgpu_info *avalon)
+{
+ enum sub_ident ident;
+
+ ident = usb_ident(avalon);
+ return ident == IDENT_BTB || ident == IDENT_BBF;
+}
+
static bool bitburner_set_core_voltage(struct cgpu_info *avalon, int core_voltage)
{
uint8_t buf[2];
int err;
- if (usb_ident(avalon) == IDENT_BTB) {
+ if (is_bitburner(avalon)) {
buf[0] = (uint8_t)core_voltage;
buf[1] = (uint8_t)(core_voltage >> 8);
err = usb_transfer_data(avalon, FTDI_TYPE_OUT, BITBURNER_REQUEST,
@@ -651,7 +709,7 @@ static int bitburner_get_core_voltage(struct cgpu_info *avalon)
int err;
int amount;
- if (usb_ident(avalon) == IDENT_BTB) {
+ if (is_bitburner(avalon)) {
err = usb_transfer_read(avalon, FTDI_TYPE_IN, BITBURNER_REQUEST,
BITBURNER_VALUE, BITBURNER_INDEX_GET_VOLTAGE,
(char *)buf, sizeof(buf), &amount,
@@ -780,7 +838,18 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
BITBURNER_MAX_COREMV);
} else
bitburner_set_core_voltage(avalon, opt_bitburner_core_voltage);
+ } else if (usb_ident(avalon) == IDENT_BBF) {
+ if (opt_bitburner_fury_core_voltage < BITBURNER_FURY_MIN_COREMV ||
+ opt_bitburner_fury_core_voltage > BITBURNER_FURY_MAX_COREMV) {
+ quit(1, "Invalid bitburner-fury-voltage %d must be %dmv - %dmv",
+ opt_bitburner_fury_core_voltage,
+ BITBURNER_FURY_MIN_COREMV,
+ BITBURNER_FURY_MAX_COREMV);
+ } else
+ bitburner_set_core_voltage(avalon, opt_bitburner_fury_core_voltage);
+ }
+ if (is_bitburner(avalon)) {
bitburner_get_version(avalon);
}
@@ -1181,7 +1250,7 @@ static void *bitburner_send_tasks(void *userdata)
avalon_reset_auto(info);
}
- ret = avalon_send_task(&at, avalon);
+ ret = bitburner_send_task(&at, avalon);
if (unlikely(ret == AVA_SEND_ERROR)) {
applog(LOG_ERR, "%s%i: Comms error(buffer)",
@@ -1211,7 +1280,7 @@ static bool avalon_prepare(struct thr_info *thr)
int array_size = AVALON_ARRAY_SIZE;
void *(*write_thread_fn)(void *) = avalon_send_tasks;
- if (usb_ident(avalon) == IDENT_BTB) {
+ if (is_bitburner(avalon)) {
array_size = BITBURNER_ARRAY_SIZE;
write_thread_fn = bitburner_send_tasks;
}
@@ -1356,7 +1425,7 @@ static void avalon_update_temps(struct cgpu_info *avalon, struct avalon_info *in
info->temp_sum += avalon->temp;
applog(LOG_DEBUG, "Avalon: temp_index: %d, temp_count: %d, temp_old: %d",
info->temp_history_index, info->temp_history_count, info->temp_old);
- if (usb_ident(avalon) == IDENT_BTB) {
+ if (is_bitburner(avalon)) {
info->core_voltage = bitburner_get_core_voltage(avalon);
}
if (info->temp_history_index == info->temp_history_count) {
@@ -1378,7 +1447,7 @@ static void get_avalon_statline_before(char *buf, size_t bufsiz, struct cgpu_inf
struct avalon_info *info = avalon->device_data;
int lowfan = 10000;
- if (usb_ident(avalon) == IDENT_BTB) {
+ if (is_bitburner(avalon)) {
int temp = info->temp0;
if (info->temp2 > temp)
temp = info->temp2;
@@ -1464,7 +1533,7 @@ static int64_t avalon_scanhash(struct thr_info *thr)
/* Check for nothing but consecutive bad results or consistently less
* results than we should be getting and reset the FPGA if necessary */
- if (usb_ident(avalon) != IDENT_BTB) {
+ if (!is_bitburner(avalon)) {
if (avalon->results < -miner_count && !info->reset) {
applog(LOG_ERR, "%s%d: Result return rate low, resetting!",
avalon->drv->name, avalon->device_id);
@@ -1525,7 +1594,7 @@ static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
sprintf(mcw, "match_work_count%d", i + 1);
root = api_add_int(root, mcw, &(info->matching_work[i]), false);
}
- if (usb_ident(cgpu) == IDENT_BTB) {
+ if (is_bitburner(cgpu)) {
root = api_add_int(root, "core_voltage", &(info->core_voltage), false);
snprintf(buf, sizeof(buf), "%"PRIu8".%"PRIu8".%"PRIu8,
info->version1, info->version2, info->version3);
@@ -1553,7 +1622,7 @@ static char *avalon_set_device(struct cgpu_info *avalon, char *option, char *set
}
if (strcasecmp(option, "millivolts") == 0 || strcasecmp(option, "mv") == 0) {
- if (usb_ident(avalon) != IDENT_BTB) {
+ if (!is_bitburner(avalon)) {
sprintf(replybuf, "%s cannot set millivolts", avalon->drv->name);
return replybuf;
}
diff --git a/driver-avalon.h b/driver-avalon.h
index 54dc5e2..e506388 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -33,11 +33,18 @@
#define AVALON_TEMP_HYSTERESIS 3
#define AVALON_TEMP_OVERHEAT 60
+/* Avalon-based BitBurner. */
#define BITBURNER_DEFAULT_CORE_VOLTAGE 1200 /* in millivolts */
#define BITBURNER_MIN_COREMV 1000
/* change here if you want to risk killing it :) */
#define BITBURNER_MAX_COREMV 1400
+/* BitFury-based BitBurner. */
+#define BITBURNER_FURY_DEFAULT_CORE_VOLTAGE 900 /* in millivolts */
+#define BITBURNER_FURY_MIN_COREMV 700
+/* change here if you want to risk killing it :) */
+#define BITBURNER_FURY_MAX_COREMV 1100
+
#define AVALON_DEFAULT_TIMEOUT 0x2D
#define AVALON_MIN_FREQUENCY 256
@@ -45,6 +52,7 @@
#define AVALON_TIMEOUT_FACTOR 12690
#define AVALON_DEFAULT_FREQUENCY 282
#define AVALON_DEFAULT_MINER_NUM 0x20
+#define AVALON_MAX_MINER_NUM 0x100
#define AVALON_DEFAULT_ASIC_NUM 0xA
#define AVALON_AUTO_CYCLE 1024
@@ -122,7 +130,7 @@ struct avalon_info {
int core_voltage;
int no_matching_work;
- int matching_work[AVALON_DEFAULT_MINER_NUM];
+ int matching_work[AVALON_MAX_MINER_NUM];
int frequency;
uint32_t ctlr_ver;
@@ -179,6 +187,7 @@ extern int opt_avalon_freq_min;
extern int opt_avalon_freq_max;
extern bool opt_avalon_auto;
extern int opt_bitburner_core_voltage;
+extern int opt_bitburner_fury_core_voltage;
extern char *set_avalon_fan(char *arg);
extern char *set_avalon_freq(char *arg);
diff --git a/usbutils.c b/usbutils.c
index cd7152d..24d686d 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -311,6 +311,18 @@ static struct usb_find_devices find_dev[] = {
INTINFO(ava_ints) },
{
.drv = DRIVER_avalon,
+ .name = "BBF",
+ .ident = IDENT_BBF,
+ .idVendor = IDVENDOR_FTDI,
+ .idProduct = 0x6001,
+ .iManufacturer = "Burnin Electronics",
+ .iProduct = "BitBurner Fury",
+ .config = 1,
+ .timeout = AVALON_TIMEOUT_MS,
+ .latency = 10,
+ INTINFO(ava_ints) },
+ {
+ .drv = DRIVER_avalon,
.name = "AVA",
.ident = IDENT_AVA,
.idVendor = IDVENDOR_FTDI,
diff --git a/usbutils.h b/usbutils.h
index 19e64c5..ff136e4 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -144,6 +144,7 @@ enum sub_ident {
IDENT_MMQ,
IDENT_AVA,
IDENT_BTB,
+ IDENT_BBF,
IDENT_KLN,
IDENT_ICA,
IDENT_AMU,