Professional Documents
Culture Documents
h"
#include "math.h"
#include "miner.h"
#include "bf16-communication.h"
#include "bf16-ctrldevice.h"
#include "bf16-mspcontrol.h"
#include "bf16-spidevice.h"
#include "bf16-uartdevice.h"
#include "driver-bitfury16.h"
#ifdef FILELOG
#define LOGFILE "/var/log/cgminer.log"
#endif
#define DISABLE_SEND_CMD_ERROR
#define RENONCE_COUNT 29
/* statistics intervals */
#define AVG_TIME_DELTA 5.0
#define AVG_TIME_INTERVAL 5.0
/* threads delay */
#define CHIPWORKER_DELAY 1000000
#define NONCEWORKER_DELAY 30000
#define RENONCEWORKER_DELAY 30000
#define HWMONITOR_DELAY 1000000
#define STATISTICS_DELAY 400000
#define ALARM_DELAY 500000
/* renonce configuration */
int opt_bf16_renonce = RENONCE_ONE_CHIP;
/* fan speed */
int opt_bf16_fan_speed = -1;
/* target temp */
int opt_bf16_target_temp = -1;
/* alarm temp */
int opt_bf16_alarm_temp = -1;
#ifdef MINER_X5
bool opt_bf16_manual_pid_enabled = false;
bool manual_pid_enabled = false;
#ifdef MINER_X6
bool opt_bf16_manual_pid_disabled = false;
bool manual_pid_enabled = false;
#ifdef FILELOG
static int filelog(struct bitfury16_info *info, const char* format, ...)
{
char fmt[1024];
char datetime[64];
struct timeval tv = {0, 0};
struct tm *tm;
if (info->logfile == NULL)
return -1;
gettimeofday(&tv, NULL);
const time_t tmp_time = tv.tv_sec;
int ms = (int)(tv.tv_usec / 1000);
tm = localtime(&tmp_time);
memset(fmt, 0, sizeof(fmt));
sprintf(fmt, "%s%s\n", datetime, format);
va_list args;
va_start(args, format);
mutex_lock(&info->logfile_mutex);
vfprintf(info->logfile, fmt, args);
fflush(info->logfile);
mutex_unlock(&info->logfile_mutex);
va_end(args);
return 0;
}
#endif
return 0;
}
#ifdef MINER_X6
if (opt_bf16_power_management_disabled == false) {
bcm250_id = (bcm250_id + 1) % BCM250_NUM;
chip_id = info-
>chipboard[board_id].bcm250[bcm250_id].first_good_chip;
} else {
chip_id = info-
>chipboard[board_id].bcm250[bcm250_id].first_good_chip;
}
#endif
} else
chip_id++;
chip_address->bcm250_id = bcm250_id;
chip_address->chip_id = chip_id;
}
#ifdef MINER_X6
if (opt_bf16_power_management_disabled == false) {
if ((info->chipboard[board_id].p_chain2_enabled == 0) &&
(info->chipboard[board_id].power2_disabled == true)) {
if (chip_count == info->chipboard[board_id].chips_num / 2)
break;
} else {
if (chip_count == info->chipboard[board_id].chips_num)
break;
}
} else {
if (chip_count == info->chipboard[board_id].chips_num)
break;
}
#endif
}
renonce_chip_address[board_id].bcm250_id = bcm250_id;
renonce_chip_address[board_id].chip_id = chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status
= UNINITIALIZED;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
gettimeofday(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "%s: changed renonce chip address to: [%d:%d:%2d]",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
#endif
return 0;
} else {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status =
DISABLED;
#ifdef FILELOG
filelog(info, "%s: failed to find working renonce chip. disabling...",
bitfury->drv->name);
#endif
return -1;
}
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_good_dx++;
info->chipboard[board_id].bcm250[bcm250_id].nonces_good_dx++;
info->chipboard[board_id].nonces_good_dx++;
info->nonces_good_dx++;
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_bad_dx++;
info->chipboard[board_id].bcm250[bcm250_id].nonces_bad_dx++;
info->chipboard[board_id].nonces_bad_dx++;
info->nonces_bad_dx++;
}
static void increase_re_nonces(struct bitfury16_info *info, bf_chip_address_t
chip_address)
{
uint8_t board_id = chip_address.board_id;
uint8_t bcm250_id = chip_address.bcm250_id;
uint8_t chip_id = chip_address.chip_id;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_dx++;
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_dx++;
info->chipboard[board_id].nonces_re_dx++;
info->nonces_re_dx++;
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_good_dx+
+;
if (renonce_chip(chip_address) == 0) {
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_good_dx++;
info->chipboard[board_id].nonces_re_good_dx++;
info->nonces_re_good_dx++;
}
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_bad_dx+
+;
if (renonce_chip(chip_address) == 0) {
info->chipboard[board_id].bcm250[bcm250_id].nonces_re_bad_dx++;
info->chipboard[board_id].nonces_re_bad_dx++;
info->nonces_re_bad_dx++;
}
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_dx++;
if ((renonce_chip(chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED)) {
info->chipboard[board_id].bcm250[bcm250_id].nonces_dx++;
info->chipboard[board_id].nonces_dx++;
info->nonces_dx++;
}
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch_dx++;
info->chipboard[board_id].bcm250[bcm250_id].task_switch_dx++;
info->chipboard[board_id].task_switch_dx++;
info->task_switch_dx++;
}
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time =
curr_time;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors++;
if ((renonce_chip(chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED))
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status =
UNINITIALIZED;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status =
FAILING;
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate =
0;
}
}
return channel_path;
}
int8_t board_id = 0;
int8_t bcm250_id = 0;
int8_t chip_id = 0;
char buff[16];
if (address == NULL)
return -1;
/* board_id */
char* start = strchr(address, '[');
char* end = strchr(address, ':');
if ((start == NULL) || (end == NULL))
return -1;
uint8_t len = end - start;
memset(buff, 0, sizeof(buff));
cg_memcpy(buff, start + 1, len);
board_id = atoi(buff);
/* bcm250_id */
start = end;
end = strchr(start + 1, ':');
if (end == NULL)
return -1;
len = end - start;
memset(buff, 0, sizeof(buff));
cg_memcpy(buff, start + 1, len);
bcm250_id = atoi(buff);
/* chip_id */
start = end;
end = strchr(start + 1, ']');
if (end == NULL)
return -1;
len = end - start;
memset(buff, 0, sizeof(buff));
cg_memcpy(buff, start + 1, len);
chip_id = atoi(buff);
return 0;
}
static void update_bcm250_map(struct cgpu_info *bitfury, uint8_t board_id)
{
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury-
>device_data);
#ifdef MINER_X5
info->chipboard[board_id].board_type = CHIPBOARD_X5;
switch (info->chipboard[board_id].board_ver) {
/* 23 chip board version */
case 5:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][0].chips_num = BF16_NUM - 2;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
bcm250_map[board_id][2].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][2].chips_num = BF16_NUM - 2;
break;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][0].chips_num = BF16_NUM - 2;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
bcm250_map[board_id][2].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][2].chips_num = BF16_NUM - 1;
break;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][0].chips_num = BF16_NUM - 1;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
bcm250_map[board_id][2].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][2].chips_num = BF16_NUM - 1;
break;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][0].chips_num = BF16_NUM - 1;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
break;
bcm250_map[board_id][1].first_good_chip = 6;
bcm250_map[board_id][1].chips_num = 5;
break;
#ifdef MINER_X6
info->chipboard[board_id].board_type = CHIPBOARD_X6;
switch (info->chipboard[board_id].board_ver) {
/* 46 chip board version */
case 4:
info->chipboard[board_id].board_rev = CHIPBOARD_REV2;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][0].chips_num = BF16_NUM - 2;
bcm250_map[board_id][1].first_good_chip = 1;
bcm250_map[board_id][1].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][1].chips_num = BF16_NUM - 2;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][3].last_good_chip = BF16_NUM - 2;
bcm250_map[board_id][3].chips_num = BF16_NUM - 2;
bcm250_map[board_id][4].first_good_chip = 1;
bcm250_map[board_id][4].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][4].chips_num = BF16_NUM - 1;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][0].chips_num = BF16_NUM - 1;
bcm250_map[board_id][1].first_good_chip = 1;
bcm250_map[board_id][1].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][1].chips_num = BF16_NUM - 2;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][3].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][3].chips_num = BF16_NUM - 1;
bcm250_map[board_id][4].first_good_chip = 1;
bcm250_map[board_id][4].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][4].chips_num = BF16_NUM - 1;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
bcm250_map[board_id][0].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][0].chips_num = BF16_NUM - 1;
bcm250_map[board_id][1].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][1].chips_num = BF16_NUM - 1;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][3].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][3].chips_num = BF16_NUM - 1;
bcm250_map[board_id][4].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][4].chips_num = BF16_NUM - 1;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
bcm250_map[board_id][1].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][1].chips_num = BF16_NUM - 1;
bcm250_map[board_id][2].last_good_chip = 5;
bcm250_map[board_id][2].chips_num = 5;
bcm250_map[board_id][4].last_good_chip = BF16_NUM - 1;
bcm250_map[board_id][4].chips_num = BF16_NUM - 1;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
bcm250_map[board_id][5].last_good_chip = 5;
bcm250_map[board_id][5].chips_num = 5;
break;
uint8_t bcm250_channel_path[3][CHANNEL_DEPTH] = {
{ BF250_CHAN1, BF250_CHAN1, BF250_LOCAL, BF250_NONE },
{ BF250_CHAN1, BF250_CHAN1, BF250_CHAN1, BF250_LOCAL },
{ BF250_CHAN1, BF250_CHAN1, BF250_CHAN2, BF250_LOCAL },
};
bcm250_map[board_id][0].first_good_chip = 0;
bcm250_map[board_id][0].last_good_chip = 1;
bcm250_map[board_id][0].chips_num = 1;
bcm250_map[board_id][2].first_good_chip = 0;
bcm250_map[board_id][2].last_good_chip = BF16_NUM;
bcm250_map[board_id][2].chips_num = BF16_NUM;
bcm250_map[board_id][3].first_good_chip = 0;
bcm250_map[board_id][3].last_good_chip = 1;
bcm250_map[board_id][3].chips_num = 1;
cg_memcpy(bcm250_map[board_id][3].channel_path,
bcm250_channel_path[0], sizeof(bcm250_map[board_id][3].channel_path));
cg_memcpy(bcm250_map[board_id][4].channel_path,
bcm250_channel_path[1], sizeof(bcm250_map[board_id][4].channel_path));
bcm250_map[board_id][5].first_good_chip = 0;
bcm250_map[board_id][5].last_good_chip = BF16_NUM;
bcm250_map[board_id][5].chips_num = BF16_NUM;
cg_memcpy(bcm250_map[board_id][5].channel_path,
bcm250_channel_path[2], sizeof(bcm250_map[board_id][5].channel_path));
break;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
gettimeofday(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
gettimeofday(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].switch_time, NULL);
}
}
}
info->work_list = workd_list_init();
info->stale_work_list = workd_list_init();
info->noncework_list = noncework_list_init();
if (opt_bf16_renonce != RENONCE_DISABLED) {
info->renoncework_list = renoncework_list_init();
info->renonce_id = 1;
info->renonce_list = renonce_list_init();
}
if (info->chipboard[board_id].detected == true) {
applog(LOG_NOTICE, "%s: BOARD%d detected", bitfury->drv->name,
board_id + 1);
info->chipboard[board_id].bcm250 = cgcalloc(BCM250_NUM,
sizeof(bf_bcm250_t));
cmd_buffer_init(&info->chipboard[board_id].cmd_buffer);
get_board_info(bitfury, board_id);
update_bcm250_map(bitfury, board_id);
info->chipboard_num++;
info->chipboard[board_id].bcm250_num = BCM250_NUM;
cg_memcpy(&info->chipboard[board_id].pid, &pid,
sizeof(bf_pid_t));
uint8_t chips_num = 0;
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
info->chipboard[board_id].bcm250[bcm250_id].channel_path
= init_channel_path(board_id, bcm250_id,
&info-
>chipboard[board_id].bcm250[bcm250_id].channel_depth, info->channel_length);
info->chipboard[board_id].bcm250[bcm250_id].first_good_chip
= bcm250_map[board_id][bcm250_id].first_good_chip;
info->chipboard[board_id].bcm250[bcm250_id].last_good_chip
= bcm250_map[board_id][bcm250_id].last_good_chip;
info->chipboard[board_id].bcm250[bcm250_id].chips_num
= bcm250_map[board_id][bcm250_id].chips_num;
chips_num += bcm250_map[board_id][bcm250_id].chips_num;
info->chipboard[board_id].chips_num = chips_num;
info->chips_num += info->chipboard[board_id].chips_num;
} else
applog(LOG_NOTICE, "%s: BOARD%d not found", bitfury->drv->name,
board_id + 1);
workd_list_deinit(info->work_list, bitfury);
workd_list_deinit(info->stale_work_list, bitfury);
noncework_list_deinit(info->noncework_list);
if (opt_bf16_renonce != RENONCE_DISABLED) {
renoncework_list_deinit(info->renoncework_list);
info->renonce_id = 1;
renonce_list_deinit(info->renonce_list);
}
cmd_buffer_deinit(&info->chipboard[board_id].cmd_buffer);
}
free(info->chipboard);
}
/* board loop */
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
applog(LOG_NOTICE, "%s: CHIPBOARD [%d]:", bitfury->drv->name,
board_id);
/* concentrator loop */
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
applog(LOG_NOTICE, "%s: BCM250 [%d]:", bitfury->drv->name,
bcm250_id);
spi_emit_reset(board_id + 1);
/* build channel */
create_channel(board_id + 1, info-
>chipboard[board_id].bcm250[bcm250_id].channel_path, info->channel_length);
uint8_t result;
bool fail;
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip;
chip_id++) {
fail = false;
bf_chip_address_t chip_address = { board_id, bcm250_id,
chip_id };
if (fail == false)
applog(LOG_NOTICE, "%s: CHIP [%2d]: OK", bitfury-
>drv->name, chip_id);
else
applog(LOG_NOTICE, "%s: CHIP [%2d]: FAIL", bitfury-
>drv->name, chip_id);
}
/* destroy channel */
destroy_channel(board_id + 1, info-
>chipboard[board_id].bcm250[bcm250_id].channel_depth);
}
}
deinit_x5(bitfury);
}
/* build channel */
create_channel(board_id + 1, info-
>chipboard[board_id].bcm250[bcm250_id].channel_path, info->channel_length);
uint8_t result;
bool fail = false;
if (fail == false)
applog(LOG_NOTICE, "%s: CHIP [%2d]: OK", bitfury->drv->name, chip_id);
else
applog(LOG_NOTICE, "%s: CHIP [%2d]: FAIL", bitfury->drv->name,
chip_id);
/* destroy channel */
destroy_channel(board_id + 1, info-
>chipboard[board_id].bcm250[bcm250_id].channel_depth);
deinit_x5(bitfury);
}
if (hotplug)
return;
bitfury->drv = &bitfury16_drv;
bitfury->deven = DEV_ENABLED;
bitfury->threads = 1;
bitfury->device_data = info;
#ifdef MINER_X6
manual_pid_enabled = !opt_bf16_manual_pid_disabled;
#endif
/* open devices */
if (open_spi_device(SPI_CHANNEL1) < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, spi0_device_name);
if (open_spi_device(SPI_CHANNEL2) < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, spi1_device_name);
if (open_ctrl_device() < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, ctrl_device_name);
if (open_uart_device(UART_CHANNEL1) < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, uart1_device_name);
if (open_uart_device(UART_CHANNEL2) < 0)
quit(1, "%s: %s() failed to open [%s] device",
bitfury->drv->name, __func__, uart2_device_name);
if (info->chipboard[board_id].detected == true) {
memset(buff, 0, sizeof(buff));
if (device_uart_txrx(board_id + 1, "S", buff) < 0)
quit(1, "%s: %s() failed to get BOARD%d status",
bitfury->drv->name, __func__, board_id + 1);
/* concentrator loop */
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
uint8_t first_good_chip = info-
>chipboard[board_id].bcm250[bcm250_id].first_good_chip;
uint8_t last_good_chip = info-
>chipboard[board_id].bcm250[bcm250_id].last_good_chip;
/* chips loop */
for (chip_id = first_good_chip; chip_id <
last_good_chip; chip_id++)
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = DISABLED;
}
#ifdef MINER_X6
info->chipboard[board_id].power1_enable_time = time(NULL);
info->chipboard[board_id].power2_enable_time = time(NULL);
info->chipboard[board_id].power1_disable_count = 1;
info->chipboard[board_id].power2_disable_count = 1;
#endif
}
}
if (opt_bf16_set_clock == true) {
applog(LOG_INFO, "%s: setting clock [%02x] to all chips",
bitfury->drv->name, bf16_chip_clock);
bitfury16_set_clock(bitfury);
quit(0, "Done.");
}
if (opt_bf16_test_chip != NULL) {
bf_chip_address_t chip_address = { 0, 0, 0 };
bitfury16_test_chip(bitfury, chip_address);
quit(0, "Done.");
}
/* fan speed */
if ((opt_bf16_fan_speed != -1) &&
(manual_pid_enabled == true)) {
manual_pid_enabled = false;
}
set_fan_speed(bitfury);
/* alarm temp */
if (opt_bf16_alarm_temp == -1) {
if (device_uart_transfer(board_id + 1, "C") < 0)
quit(1, "%s: %s() failed to set BOARD%d alarm temp",
bitfury->drv->name, __func__, board_id +
1);
if (renonce_chips != info->renonce_chips) {
applog(LOG_ERR, "%s: expected to find [%d] renonce chips, but
found only [%d]",
bitfury->drv->name, opt_bf16_renonce, renonce_chips);
info->renonce_chips = renonce_chips;
}
} else {
for (board_id = 0; board_id < CHIPBOARD_NUM; board_id++) {
renonce_chip_address[board_id].board_id = -1;
renonce_chip_address[board_id].bcm250_id = -1;
renonce_chip_address[board_id].chip_id = -1;
}
}
if (renonce_chip_address[board_id].chip_id >=
last_good_chip)
renonce_chip_address[board_id].chip_id =
last_good_chip - 1;
else if (renonce_chip_address[board_id].chip_id <
first_good_chip)
renonce_chip_address[board_id].chip_id =
first_good_chip;
}
}
}
#ifdef FILELOG
info->logfile = fopen(LOGFILE, "a");
if (info->logfile == NULL)
applog(LOG_ERR, "%s: failed to open logfile [%s]: %s",
bitfury->drv->name, LOGFILE, strerror(errno));
else
mutex_init(&info->logfile_mutex);
#endif
/* close devices */
close_spi_device(SPI_CHANNEL1);
close_spi_device(SPI_CHANNEL2);
close_ctrl_device();
close_uart_device(UART_CHANNEL1);
close_uart_device(UART_CHANNEL2);
#ifdef FILELOG
fclose(info->logfile);
#endif
free(info);
free(bitfury);
return;
}
mutex_init(&info->nonces_good_lock);
if (!add_cgpu(bitfury))
quit(1, "%s: %s() failed to add_cgpu",
bitfury->drv->name, __func__);
info->initialised = true;
if (cmd_buffer->status != EMPTY)
return -1;
switch (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status) {
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
chip_address, chip_address,
work, 0, CHIP_CMD_TOGGLE, 3, toggle);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error
prepare toggle_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
break;
uint8_t clock_buf[4];
memset(clock_buf, 0, sizeof(clock_buf));
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
chip_address, chip_address,
work, 0, CHIP_CMD_SET_CLOCK, 3, clock_buf);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error
prepare set_clock_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
break;
uint8_t noncemask[4];
memset(noncemask, 0, sizeof(noncemask));
ret = cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
chip_address, chip_address,
work, 0, CHIP_CMD_SET_MASK, 3, noncemask);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d], error
prepare set_mask_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
break;
L_LOCK(info->work_list);
L_LOCK(info->stale_work_list);
if (info->work_list->count > 0) {
memset(info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.task, 0,
sizeof(info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.task));
workd_list_push(info->stale_work_list, WORKD(wdata));
workd_list_remove(info->work_list, &info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork);
gen_task_data(info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.payload.midstate,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.payload.m7,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.payload.ntime,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.payload.nbits, mask,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.task);
ret = cmd_buffer_push(cmd_buffer,
info-
>chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork, 0,
CHIP_CMD_TASK_WRITE, 79,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork.task);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:
%2d], error prepare send_task_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
}
#if 0
else
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d],
error prepare send_task_cmd: no works available",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
#endif
L_UNLOCK(info->stale_work_list);
L_UNLOCK(info->work_list);
}
break;
if (((renonce_chip(chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED)) &&
(timediff_us(info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, curr_time) >
CHIP_TASK_STATUS_INTERVAL)) {
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], prepare
task_status_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
ret = cmd_buffer_push(cmd_buffer,
info-
>chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
work, 0, CHIP_CMD_TASK_STATUS, 0, NULL);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time.tv_sec =
curr_time.tv_sec;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time.tv_usec =
curr_time.tv_usec;
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d],
error prepare task_status_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
}
break;
ret = cmd_buffer_push(cmd_buffer,
info-
>chipboard[board_id].bcm250[bcm250_id].channel_depth, chip_address, chip_address,
work, 0, CHIP_CMD_READ_NONCE, 0, NULL);
if (ret < 0)
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d],
error prepare read_nonce_cmd",
bitfury->drv->name,
board_id, bcm250_id, chip_id);
}
break;
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count <
CHIP_ERROR_FAIL_LIMIT) {
if (time_diff >= info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count *
CHIP_RECOVERY_INTERVAL) {
if (change_renonce_chip_address(bitfury,
chip_address) == 0) {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status =
UNINITIALIZED;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time =
curr_time_t;
gettimeofday(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
}
} else {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status =
UNINITIALIZED;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time =
curr_time_t;
gettimeofday(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count++;
}
} else {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status =
UNINITIALIZED;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time =
curr_time_t;
gettimeofday(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_time, NULL);
gettimeofday(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].switch_time, NULL);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count++;
#ifdef FILELOG
filelog(info, "BF16: chip [%d:%d:%2d] recovered
time_diff: [%d], "
"recovery_count: [%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
time_diff,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
}
/* mark chip as DISABLED and never communicate to it again */
else if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status != DISABLED) {
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status
= DISABLED;
#ifdef FILELOG
filelog(info, "BF16: disabling chip [%d:%d:%2d] recovery_count:
[%d], error_rate: [%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
break;
case DISABLED:
default:
break;
}
return ret;
}
uint8_t nonces = 0;
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status <
FAILING) {
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while ((rdata != NULL) && (nonces < renonce_count)) {
uint8_t ret = 1;
switch (RENONCE(rdata)->stage) {
case RENONCE_STAGE0:
case RENONCE_STAGE2:
/* generate chip work with new mask */
cg_memcpy(RENONCE(rdata)->owork.task + 19*4,
&nonce_mask, sizeof(nonce_mask));
if (ret == 0) {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = TASK_SWITCHED;
RENONCE(rdata)->sent = true;
RENONCE(rdata)->received = false;
nonces++;
}
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
}
return nonces;
}
cmd_buffer_push_create_channel(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_path,
info->channel_length);
if (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status <
FAILING) {
uint8_t toggle[4] = { 0xa5, 0x00, 0x00, 0x02 };
cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
renonce_chip_address[board_id],
renonce_chip_address[board_id],
work, 0, CHIP_CMD_TOGGLE, 3, toggle);
uint8_t clock_buf[4];
memset(clock_buf, 0, sizeof(clock_buf));
gen_clock_data(bf16_renonce_chip_clock, 1, clock_buf);
cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
renonce_chip_address[board_id],
renonce_chip_address[board_id],
work, 0, CHIP_CMD_SET_CLOCK, 3, clock_buf);
uint8_t noncemask[4];
memset(noncemask, 0, sizeof(noncemask));
cmd_buffer_push(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth,
renonce_chip_address[board_id],
renonce_chip_address[board_id],
work, 0, CHIP_CMD_SET_MASK, 3, noncemask);
cmd_buffer_push_destroy_channel(cmd_buffer,
info->chipboard[board_id].
bcm250[renonce_chip_address[board_id].bcm250_id].channel_depth);
}
/* concentrator loop */
for (bcm250_id = 0; bcm250_id < BCM250_NUM; bcm250_id++) {
uint8_t first_good_chip = info-
>chipboard[board_id].bcm250[bcm250_id].first_good_chip;
uint8_t last_good_chip = info-
>chipboard[board_id].bcm250[bcm250_id].last_good_chip;
cmd_buffer_push_create_channel(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_path,
info->channel_length);
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip; chip_id++) {
bf_chip_address_t chip_address = { board_id, bcm250_id,
chip_id };
chip_task_update(bitfury, chip_address);
}
cmd_buffer_push_destroy_channel(cmd_buffer,
info->chipboard[board_id].bcm250[bcm250_id].channel_depth);
}
if (do_renonce == true) {
uint8_t count = (cmd_buffer->free_bytes - (2 + 11 + 11 + 11 + 8)) /
136;
if (count < renonce_count) {
if (count > 0)
renonce_task_update(bitfury, board_id, count);
} else if (renonce_count > 0)
renonce_task_update(bitfury, board_id, renonce_count);
}
cmd_buffer->status = TX_READY;
}
if (cmd_buffer->status == EMPTY) {
if ((opt_bf16_renonce == RENONCE_DISABLED) ||
(renonce_chip_address[board_id].board_id == -1)) {
do_renonce[board_id]++;
} else {
if (renonce_count >= RENONCE_COUNT) {
renonce_task_update(bitfury, board_id,
RENONCE_COUNT);
do_renonce[board_id] = 0;
cmd_buffer->status = TX_READY;
} else {
fill_cmd_buffer_loop(bitfury, board_id, true,
renonce_count);
do_renonce[board_id]++;
}
}
}
}
}
switch (info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status) {
case UNINITIALIZED:
case TOGGLE_SET:
case CLOCK_SET:
case MASK_SET:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], send_cmd
[%s]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code));
else {
#ifndef DISABLE_SEND_CMD_ERROR
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]: error
send_cmd [%s]. "
"checksum: expected: [%02x]; received: [%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code),
cmd_status.checksum_expected,
cmd_status.checksum_received);
#endif
case TASK_SENT:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], send_cmd
[%s]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code));
} else {
/* task not switched */
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none_dx++;
info-
>chipboard[board_id].bcm250[bcm250_id].status_cmd_none_dx++;
info->chipboard[board_id].status_cmd_none_dx++;
info->status_cmd_none_dx++;
if ((timediff_us(info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].switch_time, curr_time) >
CHIP_TASK_SWITCH_INTERVAL) &&
(info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, cmd_status.chip_address);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = time(NULL);
#ifdef FILELOG
filelog(info, "BF16: no task switch for chip [%d:%d:
%2d], "
"error count: [%d], recovery_count: [%d],
error_rate: [%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
} else {
#ifndef DISABLE_SEND_CMD_ERROR
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]: error
send_cmd [%s]. "
"checksum: expected: [%02x]; received: [%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code),
cmd_status.checksum_expected,
cmd_status.checksum_received);
#endif
case TASK_SWITCHED:
applog(LOG_DEBUG, "%s: chipworker_thr: chip [%d:%d:%2d], send_cmd
[%s]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code));
if (cmd_status.checksum_error == false) {
if ((renonce_chip(cmd_status.chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_processed >=
CHIP_RESTART_LIMIT) {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = UNINITIALIZED;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_processed = 0;
} else
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = MASK_SET;
}
return 1;
} else {
#ifndef DISABLE_SEND_CMD_ERROR
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]: error
send_cmd [%s]. "
"checksum: expected: [%02x]; received: [%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
get_cmd_description(cmd_status.cmd_code),
cmd_status.checksum_expected,
cmd_status.checksum_received);
#endif
break;
case FAILING:
case DISABLED:
default:
break;
}
return 0;
}
uint8_t i;
uint32_t found_nonces[12];
if ((renonce_chip(cmd_status.chip_address) == 1) &&
(opt_bf16_renonce != RENONCE_DISABLED)) {
if ((time_diff >= RENONCE_CHIP_FAILING_INTERVAL) &&
(info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, cmd_status.chip_address);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
#ifdef FILELOG
filelog(info, "BF16: no good nonces from renonce chip
[%d:%d:%2d], "
"error count: [%d] recovery_count: [%d],
error_rate: [%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
} else {
if ((time_diff >= CHIP_FAILING_INTERVAL) &&
(info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING)) {
increase_errors(info, cmd_status.chip_address);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
#ifdef FILELOG
filelog(info, "BF16: no good nonces from chip [%d:%d:
%2d], "
"error count: [%d], recovery_count: [%d],
error_rate: [%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
}
RENONCE(rdata)->received = true;
break;
}
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
}
increase_total_nonces(info, cmd_status.chip_address);
L_LOCK(info->renonce_list);
if (info->renonce_list->count < RENONCE_QUEUE_LEN) {
renonce_list_push(info->renonce_list,
info->renonce_id++,
found_nonces[i],
cmd_status.chip_address,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].owork);
} else
increase_re_bad_nonces(info,
cmd_status.chip_address);
L_UNLOCK(info->renonce_list);
cg_memcpy(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].owork,
&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].cwork, sizeof(bf_works_t));
if (cmd_status.nonce_checksum_error != 0) {
if ((renonce_chip(cmd_status.chip_address) == 0) ||
(opt_bf16_renonce == RENONCE_DISABLED)) {
applog(LOG_ERR, "%s: chipworker_thr: chip [%d:%d:%2d]:
error receiving data. "
"nonce checksum: expected: [%02x]; received:
[%02x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
cmd_status.checksum_expected,
cmd_status.checksum_received);
return 0;
}
if (cmd_buffer->status == EXECUTED) {
/* process extracted data */
uint16_t cmd_number = cmd_buffer->cmd_list->count;
for (i = 0; i < cmd_number; i++) {
uint32_t nonces[12];
/* analyze nonces */
if ((cmd_status.cmd_code & CHIP_CMD_READ_NONCE) &&
(task_switch == 1)) {
process_nonces(bitfury, cmd_status, nonces);
}
}
cmd_buffer_clear(cmd_buffer);
}
}
if (info->chipboard[board_id].cmd_buffer.status ==
EMPTY)
fill_cmd_buffer(bitfury, board_id);
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_ERR, "%s: chipworker_thr: board %d buffer
prepare: time elapsed: [%.6f]",
bitfury->drv->name, board_id,
timediff(start_time, stop_time));
#endif
gettimeofday(&start_time, NULL);
/* send buffer to chipboard */
if (info->chipboard[board_id].cmd_buffer.status ==
TX_READY) {
spi_emit_reset(board_id + 1);
cmd_buffer_exec(board_id + 1, &info-
>chipboard[board_id].cmd_buffer);
info->chipboard[board_id].bytes_transmitted_dx
+= info->chipboard[board_id].cmd_buffer.tx_offset;
info->chipboard[board_id].bytes_transmitted
+= info->chipboard[board_id].cmd_buffer.tx_offset;
}
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_ERR, "%s: chipworker_thr: board %d TX/RX
time: [%.6f]",
bitfury->drv->name, board_id,
timediff(start_time, stop_time));
#endif
gettimeofday(&start_time, NULL);
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_ERR, "%s: chipworker_thr: board %d buffer
processing: time elapsed: [%.6f]",
bitfury->drv->name, board_id,
timediff(start_time, stop_time));
#endif
}
}
} else
cgsleep_us(CHIPWORKER_DELAY);
}
uint32_t nonce_cnt = 0;
nonce_cnt++;
submit_tested_work(info->thr, &NONCEWORK(nwdata)-
>owork.work);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count > 0) {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "BF16: good nonce for chip [%d:%d:%2d]
"
"setting recovery_count to [0],
error_rate: [%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
increase_good_nonces(info, NONCEWORK(nwdata)-
>chip_address);
mutex_lock(&info->nonces_good_lock);
info->nonces_good_cg++;
mutex_unlock(&info->nonces_good_lock);
} else if (test_nonce(&NONCEWORK(nwdata)->cwork.work,
NONCEWORK(nwdata)->nonce)) {
applog(LOG_DEBUG, "%s: nonceworker_thr: chip [%d:%d:%2d],
valid nonce [%08x]",
bitfury->drv->name,
board_id, bcm250_id, chip_id,
NONCEWORK(nwdata)->nonce);
submit_tested_work(info->thr, &NONCEWORK(nwdata)-
>cwork.work);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count > 0) {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "BF16: good nonce for chip [%d:%d:%2d]
"
"setting recovery_count to 0, error_rate:
[%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
increase_good_nonces(info, NONCEWORK(nwdata)-
>chip_address);
mutex_lock(&info->nonces_good_lock);
info->nonces_good_cg++;
mutex_unlock(&info->nonces_good_lock);
} else {
time_t curr_time = time(NULL);
time_t time_diff = curr_time - info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
#ifdef FILELOG
filelog(info, "BF16: no good nonces from chip [%d:%d:
%2d], "
"error count: [%d], recovery_count: [%d],
error_rate: [%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
if (opt_bf16_renonce != RENONCE_DISABLED) {
/* add failed nonce to renonce list */
increase_bad_nonces(info, NONCEWORK(nwdata)-
>chip_address);
L_LOCK(info->renonce_list);
if (info->renonce_list->count < RENONCE_QUEUE_LEN) {
renonce_list_push(info->renonce_list,
info->renonce_id++,
NONCEWORK(nwdata)->nonce,
NONCEWORK(nwdata)->chip_address,
NONCEWORK(nwdata)->cwork,
NONCEWORK(nwdata)->owork);
} else
increase_re_bad_nonces(info, NONCEWORK(nwdata)-
>chip_address);
L_UNLOCK(info->renonce_list);
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_DEBUG, "%s: nonceworker_thr: nonces processed [%d]: time
elapsed: [%.6f]",
bitfury->drv->name,
nonce_cnt, timediff(start_time, stop_time));
#endif
cgsleep_us(NONCEWORKER_DELAY);
}
if (owork == true) {
if (test_nonce(&RENONCE(rdata)->owork.work, RENONCEWORK(rnwdata)-
>nonce)) {
applog(LOG_DEBUG, "%s: renonceworker_thr: restored renonce:
nonce: [%08x]",
bitfury->drv->name,
RENONCEWORK(rnwdata)->nonce);
submit_tested_work(info->thr, &RENONCE(rdata)->owork.work);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count > 0) {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "BF16: good nonce for renonce chip [%d:%d:
%2d] "
"setting recovery_count to 0, error_rate:
[%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
increase_re_good_nonces(info, RENONCE(rdata)->src_address);
increase_re_good_nonces(info, renonce_chip_address[board_id]);
mutex_lock(&info->nonces_good_lock);
info->nonces_good_cg++;
mutex_unlock(&info->nonces_good_lock);
RENONCE(rdata)->match = true;
} else {
time_t curr_time = time(NULL);
time_t time_diff = curr_time - info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
#ifdef FILELOG
filelog(info, "BF16: no good nonces from renonce chip [%d:
%d:%2d], "
"error count: [%d] recovery_count: [%d],
error_rate: [%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].errors,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
}
} else {
if (test_nonce(&RENONCE(rdata)->cwork.work, RENONCEWORK(rnwdata)-
>nonce)) {
applog(LOG_DEBUG, "%s: renonceworker_thr: restored renonce:
nonce: [%08x]",
bitfury->drv->name,
RENONCEWORK(rnwdata)->nonce);
submit_tested_work(info->thr, &RENONCE(rdata)->cwork.work);
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time = time(NULL);
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count > 0) {
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].recovery_count = 0;
#ifdef FILELOG
filelog(info, "BF16: good nonce for renonce chip [%d:%d:
%2d] "
"setting recovery_count to 0, error_rate:
[%d]",
board_id, bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].error_rate);
#endif
}
increase_re_good_nonces(info, RENONCE(rdata)->src_address);
increase_re_good_nonces(info, renonce_chip_address[board_id]);
mutex_lock(&info->nonces_good_lock);
info->nonces_good_cg++;
mutex_unlock(&info->nonces_good_lock);
RENONCE(rdata)->match = true;
} else {
time_t curr_time = time(NULL);
time_t time_diff = curr_time - info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_nonce_time;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status = FAILING;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].last_error_time = curr_time;
return RENONCE(rdata)->match;
}
uint32_t nonce_cnt = 0;
/* find nonce by id */
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while (rdata != NULL) {
if (match_nonce(RENONCEWORK(rnwdata)->nonce,
RENONCE(rdata)->nonce, mask_bits)) {
if (RENONCE(rdata)->match == false) {
switch (RENONCE(rdata)->stage) {
case RENONCE_STAGE0:
if (test_renonce(bitfury, rdata,
rnwdata, true) == true)
info->stage0_match++;
else
info->stage0_mismatch++;
break;
case RENONCE_STAGE1:
case RENONCE_STAGE2:
case RENONCE_STAGE3:
/* test old work first */
if (test_renonce(bitfury, rdata,
rnwdata, true) == true) {
if (RENONCE(rdata)->stage ==
RENONCE_STAGE1)
info->stage1_mismatch++;
if (RENONCE(rdata)->stage ==
RENONCE_STAGE2)
info->stage2_match++;
if (RENONCE(rdata)->stage ==
RENONCE_STAGE3)
info->stage3_mismatch++;
} else {
if (test_renonce(bitfury,
rdata, rnwdata, false) == true) {
if (RENONCE(rdata)-
>stage == RENONCE_STAGE1)
info-
>stage1_match++;
if (RENONCE(rdata)-
>stage == RENONCE_STAGE2)
info-
>stage2_mismatch++;
if (RENONCE(rdata)-
>stage == RENONCE_STAGE3)
info-
>stage3_match++;
}
}
break;
default:
applog(LOG_ERR, "%s:
renonceworker_thr: invalid renonce stage arrived: [%d]",
bitfury->drv->name,
RENONCE(rdata)->stage);
}
}
nonce_list_push(id_list, RENONCE(rdata)->id);
if (RENONCE(rdata)->match == true)
break;
}
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while (rdata != NULL) {
if (RENONCE(rdata)->match == true) {
bf_data_t* rndata = rdata->next;
renonce_list_remove(info->renonce_list, rdata);
rdata = rndata;
continue;
}
/* update stage */
bf_data_t* ndata = id_list->head;
while (ndata != NULL) {
if (NONCE(ndata)->nonce == RENONCE(rdata)->id) {
RENONCE(rdata)->stage++;
RENONCE(rdata)->sent = false;
RENONCE(rdata)->received = false;
break;
}
ndata = ndata->next;
}
rdata = rdata->next;
}
L_UNLOCK(info->renonce_list);
/* clear id list */
bf_data_t* ndata = id_list->head;
while (ndata != NULL) {
nonce_list_pop(id_list);
ndata = id_list->head;
}
gettimeofday(&stop_time, NULL);
#if 0
applog(LOG_DEBUG, "%s: renonceworker_thr: nonces processed [%d]: time
elapsed: [%.6f]",
bitfury->drv->name,
nonce_cnt, timediff(start_time, stop_time));
#endif
cgsleep_us(RENONCEWORKER_DELAY);
}
pTerm = 2 * error;
pid->i_state += error;
if(pid->i_state > pid->i_max)
pid->i_state = pid->i_max;
else if(pid->i_state < pid->i_min)
pid->i_state = pid->i_min;
iTerm = pid->i_state;
if (info->chipboard[board_id].detected == true) {
memset(buff, 0, sizeof(buff));
if (device_uart_txrx(board_id + 1, "S", buff) < 0)
quit(1, "%s: %s() failed to get BOARD%d status",
bitfury->drv->name, __func__, board_id + 1);
info->chipboard[board_id].p_chain1 = info-
>chipboard[board_id].u_chain1 * info->chipboard[board_id].i_chain1;
info->chipboard[board_id].p_chain2 = info-
>chipboard[board_id].u_chain2 * info->chipboard[board_id].i_chain2;
#ifdef MINER_X6
float i_board = info->chipboard[board_id].i_chain1 + info-
>chipboard[board_id].i_chain2;
#endif
info->chipboard[board_id].p_board = ((info-
>chipboard[board_id].u_board + U_LOSS) * i_board + 2.0 +
info->chipboard[board_id].p_fan);
if (info->chipboard[board_id].a_temp == 1)
a_temp = true;
if ((info->chipboard[board_id].a_ichain1 == 1) ||
(info->chipboard[board_id].a_ichain2 == 1))
a_ichain = true;
reinit_x5(info, false);
}
info->ialarm_count = 1;
info->ialarm_buzzer = false;
info->ialarm_start = time(NULL);
reinit_x5(info, false);
}
}
info->a_temp = a_temp;
info->a_ichain = a_ichain;
if (info->a_temp == true)
applog(LOG_ERR, "%s: ALARM: board temp: [%5.1f] alarm temp:
[%5.1f]",
bitfury->drv->name, max_temp, t_alarm);
if (info->a_ichain == true) {
curr_time = time(NULL);
reinit_x5(info, false);
}
#endif
#ifdef MINER_X6
if ((info->chipboard[board_id].p_chain1_enabled
== 0) &&
(info-
>chipboard[board_id].power1_disabled == false)){
enable_power_chain(bitfury, board_id, 1);
info-
>chipboard[board_id].power1_enable_time = time(NULL);
recovery = true;
}
if ((info->chipboard[board_id].p_chain2_enabled
== 0) &&
(info-
>chipboard[board_id].power2_disabled == false)) {
enable_power_chain(bitfury, board_id, 2);
info-
>chipboard[board_id].power2_enable_time = time(NULL);
recovery = true;
}
#endif
}
}
reinit_x5(info, false);
}
}
}
#ifdef MINER_X6
uint8_t disabled_chips_chain1 = 0;
uint8_t total_chips_chain1 = 0;
uint8_t disabled_chips_chain2 = 0;
uint8_t total_chips_chain2 = 0;
#endif
for (bcm250_id = 0; bcm250_id < BCM250_NUM;
bcm250_id++) {
uint8_t first_good_chip = info-
>chipboard[board_id].bcm250[bcm250_id].first_good_chip;
uint8_t last_good_chip = info-
>chipboard[board_id].bcm250[bcm250_id].last_good_chip;
/* chips loop */
for (chip_id = first_good_chip; chip_id <
last_good_chip; chip_id++) {
#ifdef MINER_X5
total_chips++;
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status == DISABLED)
disabled_chips++;
#endif
#ifdef MINER_X6
if (bcm250_id < BCM250_NUM / 2) {
total_chips_chain1++;
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status == DISABLED)
disabled_chips_chain1++;
}
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status == DISABLED)
disabled_chips_chain2++;
}
#endif
}
}
#ifdef MINER_X5
/* disable chain power if all chips failed */
if ((total_chips == disabled_chips) &&
(info->chipboard[board_id].p_chain1_enabled ==
1)) {
disable_power_chain(bitfury, board_id, 0);
info->chipboard[board_id].power_disabled =
true;
info->chipboard[board_id].power_disable_time =
curr_time;
info->chipboard[board_id].chips_disabled =
info->chipboard[board_id].chips_num;
}
reinit_x5(info, true);
applog(LOG_NOTICE, "%s: reenabled power on
BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1,
(int)disable_interval);
#ifdef FILELOG
filelog(info, "%s: reenabled power on BOARD%d:
time interval [%d]",
bitfury->drv->name,
board_id + 1,
(int)disable_interval);
#endif
}
#endif
#ifdef MINER_X6
/* disable power on chain 1 only if chips on both
chains failed
* as chain 2 data channel depends on chain 1
*/
if ((total_chips_chain1 == disabled_chips_chain1) &&
(info->chipboard[board_id].p_chain1_enabled ==
1) &&
(info->chipboard[board_id].power2_disabled ==
true)) {
disable_power_chain(bitfury, board_id, 0);
info->chipboard[board_id].power1_disabled =
true;
info->chipboard[board_id].power2_disabled =
true;
info->chipboard[board_id].power1_disable_time =
curr_time;
info->chipboard[board_id].power2_disable_time =
curr_time;
info->chipboard[board_id].chips_disabled =
info->chipboard[board_id].chips_num;
} else
if ((total_chips_chain2 == disabled_chips_chain2) &&
(info->chipboard[board_id].p_chain2_enabled ==
1)) {
disable_power_chain(bitfury, board_id, 2);
info->chipboard[board_id].power2_disabled =
true;
info->chipboard[board_id].power2_disable_time =
curr_time;
info->chipboard[board_id].chips_disabled =
info->chipboard[board_id].chips_num / 2;
}
reinit_x5(info, true);
applog(LOG_NOTICE, "%s: reenabled power on
BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1,
(int)disable_interval);
#ifdef FILELOG
filelog(info, "%s: reenabled power on BOARD%d:
time interval [%d]",
bitfury->drv->name,
board_id + 1,
(int)disable_interval);
#endif
} else
if ((info->chipboard[board_id].p_chain2_enabled == 0)
&&
(info->chipboard[board_id].power2_disabled ==
true) &&
(curr_time - info-
>chipboard[board_id].power2_disable_time >= info-
>chipboard[board_id].power2_disable_count * CHAIN_REENABLE_INTERVAL)) {
time_t disable_interval = curr_time - info-
>chipboard[board_id].power2_disable_time;
info->chipboard[board_id].power2_disable_time =
curr_time;
info->chipboard[board_id].chips_disabled =
0;
reinit_x5(info, true);
applog(LOG_NOTICE, "%s: reenabled chainboard 2
on BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1,
(int)disable_interval);
#ifdef FILELOG
filelog(info, "%s: reenabled chainboard 2 on
BOARD%d: time interval [%d]",
bitfury->drv->name,
board_id + 1,
(int)disable_interval);
#endif
}
#endif
/* switch renonce chip to next board */
if ((info->renonce_chips == 1) &&
(renonce_chip_address[board_id].board_id ==
board_id) &&
#ifdef MINER_X5
(info->chipboard[board_id].power_disabled ==
true)) {
#endif
#ifdef MINER_X6
(info->chipboard[board_id].power1_disabled ==
true) &&
(info->chipboard[board_id].power2_disabled ==
true)) {
#endif
uint8_t next_board_id = (board_id + 1) %
CHIPBOARD_NUM;
uint8_t next_bcm250_id =
renonce_chip_address[board_id].bcm250_id;
uint8_t next_chip_id =
renonce_chip_address[board_id].chip_id;
info-
>chipboard[next_board_id].bcm250[next_bcm250_id].chips[next_chip_id].status =
UNINITIALIZED;
cgsleep_us(HWMONITOR_DELAY);
}
cgsleep_ms(1000);
led_red_disable(info);
led_green_disable(info);
buzzer_disable(info);
if (idle == true)
info->a_net = true;
else
info->a_net = false;
/* enable buzzer */
if (timediff_us(info->buzzer_switch, curr_time) >=
BUZZER_INTERVAL) {
if (info->buzzer_enabled == true)
buzzer_disable(info);
else
buzzer_enable(info);
}
} else if ((info->a_ichain == false) && (info->a_net == false)) {
if (info->led_red_enabled == true)
led_red_disable(info);
if (info->buzzer_enabled == true)
buzzer_disable(info);
}
if (info->ialarm_buzzer == false) {
buzzer_enable(info);
cgsleep_ms(1000);
buzzer_disable(info);
info->ialarm_buzzer = true;
}
/* enable buzzer */
if (curr_time_t - info->ialarm_start >= info->ialarm_count *
ICHAIN_ALARM_INTERVAL) {
buzzer_enable(info);
cgsleep_ms(1000);
buzzer_disable(info);
}
} else if ((info->a_temp == false) && (info->a_net == false)) {
if (info->led_red_enabled == true)
led_red_disable(info);
if (info->buzzer_enabled == true)
buzzer_disable(info);
}
/* blink green lamp if there are enabled pools present and no alarms
active */
if ((info->a_net == false) && (info->a_temp == false) && (info-
>a_ichain == false)) {
if (info->led_red_enabled == true)
led_red_disable(info);
cgsleep_us(ALARM_DELAY);
}
led_red_disable(info);
led_green_disable(info);
buzzer_disable(info);
float u_board;
float i_total;
float p_total;
float u_chip;
float p_chip;
u_board = 0.0;
i_total = 0.0;
p_total = 0.0;
u_chip = 0.0;
p_chip = 0.0;
info->chips_failed = 0;
info->chips_disabled = 0;
/* concentrator loop */
for (bcm250_id = 0; bcm250_id < BCM250_NUM;
bcm250_id++) {
uint8_t first_good_chip = info-
>chipboard[board_id].bcm250[bcm250_id].first_good_chip;
uint8_t last_good_chip = info-
>chipboard[board_id].bcm250[bcm250_id].last_good_chip;
info-
>chipboard[board_id].bcm250[bcm250_id].chips_failed = 0;
/* chips loop */
for (chip_id = first_good_chip; chip_id <
last_good_chip; chip_id++) {
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status >= FAILING) {
info-
>chipboard[board_id].bcm250[bcm250_id].chips_failed++;
info-
>chipboard[board_id].chips_failed++;
info->chips_failed++;
}
if (opt_bf16_stats_enabled) {
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_good,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_good_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_diff,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_diff_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_bad,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_bad_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
if (opt_bf16_renonce !=
RENONCE_DISABLED) {
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_re,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_re_good,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_good_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_re_bad,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_bad_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
}
}
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_good_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_diff_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_bad_dx = 0;
if (opt_bf16_renonce != RENONCE_DISABLED)
{
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_good_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces_re_bad_dx = 0;
}
if (opt_bf16_stats_enabled) {
if (opt_bf16_renonce !=
RENONCE_DISABLED)
applog(LOG_NOTICE, "STATS:
chp [%d:%d:%2d], tsk/s [%4.0f], "
"ncs/s [%4.0f],
sts/s [%3.0f], none/s [%3.0f], hr/s [%8.3f] hr+/s [%8.3f] rhr/s [%8.3f]",
board_id,
bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none,
CHIP_COEFF * info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate,
CHIP_COEFF * info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_good,
CHIP_COEFF *
(info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_good +
info->chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_re_good));
else
applog(LOG_NOTICE, "STATS:
chp [%d:%d:%2d], tsk/s [%4.0f], "
"ncs/s [%3.0f],
sts/s [%3.0f], none/s [%3.0f], hr/s [%8.3f] hr+/s [%8.3f]",
board_id,
bcm250_id, chip_id,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].task_switch,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].nonces,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd,
info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status_cmd_none,
CHIP_COEFF * info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate,
CHIP_COEFF * info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].hashrate_good);
}
}
if (opt_bf16_stats_enabled) {
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].task_switch,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].task_switch_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].status_cmd,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].status_cmd_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].status_cmd_none,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].status_cmd_none_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].nonces,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].nonces_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].hashrate,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].nonces_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].hashrate_good,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].nonces_good_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].hashrate_diff,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].nonces_diff_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].hashrate_bad,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].nonces_bad_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
if (opt_bf16_renonce != RENONCE_DISABLED)
{
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].hashrate_re,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].nonces_re_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].hashrate_re_good,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].nonces_re_good_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].bcm250[bcm250_id].hashrate_re_bad,
(float)info-
>chipboard[board_id].bcm250[bcm250_id].nonces_re_bad_dx,
(float)(time2 -
time1), AVG_TIME_INTERVAL);
}
}
info-
>chipboard[board_id].bcm250[bcm250_id].task_switch_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].status_cmd_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].status_cmd_none_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].nonces_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].nonces_good_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].nonces_diff_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].nonces_bad_dx = 0;
if (opt_bf16_renonce != RENONCE_DISABLED) {
info-
>chipboard[board_id].bcm250[bcm250_id].nonces_re_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].nonces_re_good_dx = 0;
info-
>chipboard[board_id].bcm250[bcm250_id].nonces_re_bad_dx = 0;
}
}
if (opt_bf16_stats_enabled) {
get_average(&info-
>chipboard[board_id].task_switch,
(float)info-
>chipboard[board_id].task_switch_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].status_cmd,
(float)info-
>chipboard[board_id].status_cmd_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].status_cmd_none,
(float)info-
>chipboard[board_id].status_cmd_none_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].nonces,
(float)info-
>chipboard[board_id].nonces_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
}
get_average(&info->chipboard[board_id].hashrate,
(float)info-
>chipboard[board_id].nonces_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].hashrate_good,
(float)info-
>chipboard[board_id].nonces_good_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].hashrate_diff,
(float)info-
>chipboard[board_id].nonces_diff_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].hashrate_bad,
(float)info-
>chipboard[board_id].nonces_bad_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
info->chipboard[board_id].task_switch_dx = 0;
info->chipboard[board_id].status_cmd_dx = 0;
info->chipboard[board_id].status_cmd_none_dx = 0;
info->chipboard[board_id].nonces_dx = 0;
info->chipboard[board_id].nonces_good_dx = 0;
info->chipboard[board_id].nonces_diff_dx = 0;
info->chipboard[board_id].nonces_bad_dx = 0;
u_board += (info->chipboard[board_id].u_board
+ U_LOSS);
#ifdef MINER_X5
i_total += (info-
>chipboard[board_id].i_chain1);
u_chip += (info-
>chipboard[board_id].u_chain1);
p_chip += (info-
>chipboard[board_id].p_chain1);
#endif
#ifdef MINER_X6
i_total += (info->chipboard[board_id].i_chain1
+ info->chipboard[board_id].i_chain2);
u_chip += (info->chipboard[board_id].u_chain1
+ info->chipboard[board_id].u_chain2);
p_chip += (info->chipboard[board_id].p_chain1
+ info->chipboard[board_id].p_chain2);
#endif
p_total += info->chipboard[board_id].p_board;
if (opt_bf16_renonce != RENONCE_DISABLED) {
get_average(&info-
>chipboard[board_id].hashrate_re,
(float)info-
>chipboard[board_id].nonces_re_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].hashrate_re_good,
(float)info-
>chipboard[board_id].nonces_re_good_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
get_average(&info-
>chipboard[board_id].hashrate_re_bad,
(float)info-
>chipboard[board_id].nonces_re_bad_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
info->chipboard[board_id].nonces_re_dx =
0;
info->chipboard[board_id].nonces_re_good_dx =
0;
info->chipboard[board_id].nonces_re_bad_dx =
0;
}
get_average(&info->chipboard[board_id].txrx_speed,
(float)info-
>chipboard[board_id].bytes_transmitted_dx,
(float)(time2 - time1),
AVG_TIME_INTERVAL);
info->chipboard[board_id].bytes_transmitted_dx = 0;
if (opt_bf16_stats_enabled) {
if (opt_bf16_renonce != RENONCE_DISABLED) {
applog(LOG_NOTICE, "STATS: board [%d]
hrate: good: [%8.3f] re_good: [%8.3f] => "
"[%8.3f] toren: [%8.3f] bad:
[%8.3f] total: [%8.3f]",
board_id,
CHIP_COEFF * (info-
>chipboard[board_id].hashrate_good),
CHIP_COEFF * (info-
>chipboard[board_id].hashrate_re_good),
CHIP_COEFF * (info-
>chipboard[board_id].hashrate_good + info->chipboard[board_id].hashrate_re_good),
CHIP_COEFF * (info-
>chipboard[board_id].hashrate - info->chipboard[board_id].hashrate_good),
CHIP_COEFF * (info-
>chipboard[board_id].hashrate_bad),
CHIP_COEFF * (info-
>chipboard[board_id].hashrate));
} else {
applog(LOG_NOTICE, "STATS: board [%d]
hrate: good: [%8.3f] "
"bad: [%8.3f] total:
[%8.3f]",
board_id,
CHIP_COEFF * (info-
>chipboard[board_id].hashrate_good),
CHIP_COEFF * (info-
>chipboard[board_id].hashrate_bad),
CHIP_COEFF * (info-
>chipboard[board_id].hashrate));
}
#ifdef MINER_X5
applog(LOG_NOTICE, "STATS: TX/RX: [%5.3f]
Mbit/s UB: [%3.1f] "
"U1: [%3.1f] I1: [%3.1f] T: [%3.1f]
RPM: [%4d] FAN: [%3d]",
8.0 * info-
>chipboard[board_id].txrx_speed / 1000000,
info->chipboard[board_id].u_board +
U_LOSS,
info->chipboard[board_id].u_chain1,
info->chipboard[board_id].i_chain1,
info->chipboard[board_id].temp,
info->chipboard[board_id].rpm,
info-
>chipboard[board_id].fan_speed);
#endif
#ifdef MINER_X6
applog(LOG_NOTICE, "STATS: TX/RX: [%5.3f]
Mbit/s UB: [%3.1f] "
"U1: [%3.1f] U2: [%3.1f] I1:
[%3.1f] I2: [%3.1f] T: [%3.1f] RPM: [%4d] FAN: [%3d]",
8.0 * info-
>chipboard[board_id].txrx_speed / 1000000,
info->chipboard[board_id].u_board +
U_LOSS,
info->chipboard[board_id].u_chain1,
info->chipboard[board_id].u_chain2,
info->chipboard[board_id].i_chain1,
info->chipboard[board_id].i_chain2,
info->chipboard[board_id].temp,
info->chipboard[board_id].rpm,
info-
>chipboard[board_id].fan_speed);
#endif
if (opt_bf16_stats_enabled) {
get_average(&info->task_switch,
(float)info->task_switch_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->status_cmd,
(float)info->status_cmd_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->status_cmd_none,
(float)info->status_cmd_none_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->chipboard[board_id].nonces,
(float)info->chipboard[board_id].nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
}
get_average(&info->hashrate,
(float)info->nonces_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_good,
(float)info->nonces_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_diff,
(float)info->nonces_diff_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_bad,
(float)info->nonces_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
info->task_switch_dx = 0;
info->status_cmd_dx = 0;
info->status_cmd_none_dx = 0;
info->nonces_dx = 0;
info->nonces_good_dx = 0;
info->nonces_diff_dx = 0;
info->nonces_bad_dx = 0;
if (opt_bf16_renonce != RENONCE_DISABLED) {
get_average(&info->hashrate_re,
(float)info->nonces_re_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_re_good,
(float)info->nonces_re_good_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
get_average(&info->hashrate_re_bad,
(float)info->nonces_re_bad_dx,
(float)(time2 - time1), AVG_TIME_INTERVAL);
info->nonces_re_dx = 0;
info->nonces_re_good_dx = 0;
info->nonces_re_bad_dx = 0;
}
time1 = time2;
gettimeofday(&stop_time, NULL);
if (opt_bf16_stats_enabled) {
if (opt_bf16_renonce != RENONCE_DISABLED) {
applog(LOG_NOTICE, "STATS: rencs: [%d] stale: [%d]
nws: [%d] rnws: [%d] failed: [%d]",
info->renonce_list->count,
info->stale_work_list->count,
info->noncework_list->count,
info->renoncework_list->count,
info->chips_failed);
#if 1
applog(LOG_NOTICE, "STATS: m0: [%lu] mm0: [%lu] m1:
[%lu] mm1: [%lu] m2: [%lu] mm2: [%lu] "
"m3: [%lu] mm3: [%lu] um: [%lu]",
info->stage0_match / (time2 - time0),
info->stage0_mismatch / (time2 - time0),
info->stage1_match / (time2 - time0),
info->stage1_mismatch / (time2 - time0),
info->stage2_match / (time2 - time0),
info->stage2_mismatch / (time2 - time0),
info->stage3_match / (time2 - time0),
info->stage3_mismatch / (time2 - time0),
info->unmatched / (time2 - time0));
#endif
} else {
applog(LOG_NOTICE, "STATS: stale: [%d] nws: [%d]",
info->stale_work_list->count, info-
>noncework_list->count);
cgsleep_us(STATISTICS_DELAY);
}
info->thr = thr;
if (opt_bf16_renonce != RENONCE_DISABLED) {
if (thr_info_create(&(info->renonceworker_thr), NULL,
bitfury_renonceworker, (void *)bitfury)) {
applog(LOG_ERR, "%s: %s() renonceworker thread create failed",
bitfury->drv->name, __func__);
return false;
}
pthread_detach(info->renonceworker_thr.pth);
return true;
}
mutex_lock(&info->nonces_good_lock);
if (info->nonces_good_cg) {
hashcount += 0xffffffffull * info->nonces_good_cg;
info->nonces_good_cg = 0;
}
mutex_unlock(&info->nonces_good_lock);
return hashcount;
}
static void prepare_work(struct cgpu_info *bitfury, struct work *work, bool rolled)
{
struct bitfury16_info *info = (struct bitfury16_info *)bitfury->device_data;
bf_workd_t* wdata = cgmalloc(sizeof(bf_workd_t));
wdata->work = work;
wdata->rolled = rolled;
wdata->generated = time(NULL);
workd_list_push(info->work_list, wdata);
}
if (info->initialised == false) {
cgsleep_us(30);
return true;
}
L_LOCK(info->work_list);
uint16_t work_count = info->work_list->count;
L_UNLOCK(info->work_list);
if (work_count < WORK_QUEUE_LEN)
need = WORK_QUEUE_LEN - work_count;
else
return true;
L_LOCK(info->work_list);
do {
if (roll == 0) {
usework = work;
rolled = false;
} else {
usework = copy_work_noffset(work, roll);
rolled = true;
}
if (need > 0)
return false;
else
return true;
}
if (info->initialised == false)
return;
bf_works_t works;
wdata = info->work_list->head;
flushed++;
}
L_UNLOCK(info->stale_work_list);
L_UNLOCK(info->work_list);
if (opt_bf16_renonce != RENONCE_DISABLED) {
/* flush renonces list */
L_LOCK(info->renonce_list);
bf_data_t* rdata = info->renonce_list->head;
while (rdata != NULL) {
renonce_list_pop(info->renonce_list);
rdata = info->renonce_list->head;
}
L_UNLOCK(info->renonce_list);
if (info->initialised == false)
return NULL;
#ifdef MINER_X5
root = api_add_string(root, "Device name", "Bitfury X5", true);
#endif
#ifdef MINER_X6
root = api_add_string(root, "Device name", "Bitfury X6", true);
#endif
root = api_add_uint8(root, "Boards number", &info->chipboard_num, false);
root = api_add_uint8(root, "Boards detected", &info->chipboard_num, false);
root = api_add_uint8(root, "Chips number", &info->chips_num, false);
/* U avg */
sprintf(value, "%.1f", info->u_avg);
root = api_add_string(root, "U avg", value, true);
/* I total */
sprintf(value, "%.1f", info->i_total);
root = api_add_string(root, "I total", value, true);
/* P total */
sprintf(value, "%.1f", info->p_total);
root = api_add_string(root, "P total", value, true);
if (opt_bf16_renonce != RENONCE_DISABLED) {
/* Efficiency */
sprintf(value, "%.3f",
(info->a_net == true) ?
0.0 :
info->p_total / (CHIP_COEFF * (info->hashrate_good +
info->hashrate_re_good)));
root = api_add_string(root, "Efficiency", value, true);
/* Chip GHS total avg */
sprintf(value, "%.1f", CHIP_COEFF * info->hashrate / (info->chips_num -
info->renonce_chips - info->chips_failed));
root = api_add_string(root, "Chip GHS total avg", value, true);
/* U Chip avg */
sprintf(value, "%.3f", info->u_chip / (info->chips_num - info-
>chips_disabled));
root = api_add_string(root, "U Chip avg", value, true);
/* I Chip avg */
sprintf(value, "%.1f", (info->a_net == true) ? 0.0 : info->p_chip / info-
>u_chip);
root = api_add_string(root, "I Chip avg", value, true);
/* P Chip avg */
sprintf(value, "%.2f", info->p_chip / (info->chips_num - info-
>chips_disabled));
root = api_add_string(root, "P Chip avg", value, true);
/* chips loop */
for (chip_id = first_good_chip; chip_id < last_good_chip;
chip_id++, i++) {
bf_chip_address_t chip_address;
chip_address.board_id = board_id;
chip_address.bcm250_id = bcm250_id;
chip_address.chip_id = chip_id;
if (info-
>chipboard[board_id].bcm250[bcm250_id].chips[chip_id].status < FAILING) {
if ((opt_bf16_renonce != RENONCE_DISABLED) &&
(renonce_chip(chip_address) == 1))
value[i] = 'O';
else
value[i] = 'o';
} else {
if ((opt_bf16_renonce != RENONCE_DISABLED) &&
(renonce_chip(chip_address) == 1))
value[i] = 'X';
else
value[i] = 'x';
}
}
if (bcm250_id != BCM250_NUM - 1)
value[i++] = ' ';
}
/* board hardware id */
sprintf(data, "Board%d HWID", board_id);
root = api_add_string(root, data, info->chipboard[board_id].board_hwid,
true);
/* MSP hw data */
/* T */
sprintf(data, "Board%d T", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].temp);
root = api_add_string(root, data, value, true);
/* UB */
sprintf(data, "Board%d UB", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].u_board);
root = api_add_string(root, data, value, true);
/* P1 */
sprintf(data, "Board%d P1", board_id);
root = api_add_uint8(root, data, &info-
>chipboard[board_id].p_chain1_enabled, false);
/* P2 */
sprintf(data, "Board%d P2", board_id);
root = api_add_uint8(root, data, &info-
>chipboard[board_id].p_chain2_enabled, false);
/* U1 */
sprintf(data, "Board%d U1", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].u_chain1);
root = api_add_string(root, data, value, true);
/* U2 */
sprintf(data, "Board%d U2", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].u_chain2);
root = api_add_string(root, data, value, true);
/* I1 */
sprintf(data, "Board%d I1", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].i_chain1);
root = api_add_string(root, data, value, true);
/* I2 */
sprintf(data, "Board%d I2", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].i_chain2);
root = api_add_string(root, data, value, true);
/* RPM */
sprintf(data, "Board%d PRM", board_id);
root = api_add_uint32(root, data, &info->chipboard[board_id].rpm,
true);
/* A */
sprintf(data, "Board%d T_Alarm", board_id);
root = api_add_uint8(root, data, &info->chipboard[board_id].a_temp,
true);
/* AI */
sprintf(data, "Board%d AI", board_id);
sprintf(value, "%.1f", info->chipboard[board_id].i_alarm);
root = api_add_string(root, data, value, true);
/* AT */
sprintf(data, "Board%d AT", board_id);
sprintf(value, "%.0f", info->chipboard[board_id].t_alarm);
root = api_add_string(root, data, value, true);
/* AG */
sprintf(data, "Board%d AG", board_id);
sprintf(value, "%.0f", info->chipboard[board_id].t_gisteresis);
root = api_add_string(root, data, value, true);
/* FM */
sprintf(data, "Board%d FM", board_id);
#ifdef MINER_X5
sprintf(value, "%c", info->chipboard[board_id].fan_mode);
#endif
#ifdef MINER_X6
if (manual_pid_enabled == true)
sprintf(value, "A");
else
sprintf(value, "%c", info->chipboard[board_id].fan_mode);
#endif
root = api_add_string(root, data, value, true);
/* TT */
sprintf(data, "Board%d TT", board_id);
sprintf(value, "%.0f", info->chipboard[board_id].target_temp);
root = api_add_string(root, data, value, true);
}
return root;
}
bitfury->shutdown = true;
cgsleep_ms(300);
mutex_destroy(&info->nonces_good_lock);
/* close devices */
close_spi_device(SPI_CHANNEL1);
close_spi_device(SPI_CHANNEL2);
close_ctrl_device();
close_uart_device(UART_CHANNEL1);
close_uart_device(UART_CHANNEL2);
#ifdef FILELOG
filelog(info, "%s: cgminer stopped", bitfury->drv->name);
fclose(info->logfile);
mutex_destroy(&info->logfile_mutex);
#endif