Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Bitfury16 driver update #719

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

/* Compile:
* gcc api-example.c -Icompat/jansson-2.6/src -Icompat/libusb-1.0/libusb -o cgminer-api
* gcc api-example.c -Icompat/jansson-2.9/src -o cgminer-api
*/

#include "config.h"
Expand All @@ -23,7 +23,7 @@
#include <sys/types.h>

#include "compat.h"
#include "miner.h"
#include "util.h"

#if defined(unix) || defined(__APPLE__)
#include <errno.h>
Expand Down
48 changes: 23 additions & 25 deletions bf16-bitfury16.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,6 @@ int8_t cmd_buffer_push(bf_cmd_buffer_t* cmd_buffer, const uint8_t depth,
return -2;

bf_command_t command;
memset(&command, 0, sizeof(bf_command_t));

uint8_t buff[192];
memset(buff, 0, sizeof(buff));

if (cmd_code != CHIP_CMD_CREATE_CHANNEL) {
res = spi_command_init(&command, depth, chip_address, cmd_code, data_length, tx);
Expand All @@ -361,7 +357,10 @@ int8_t cmd_buffer_push(bf_cmd_buffer_t* cmd_buffer, const uint8_t depth,

cg_memcpy(&CMD(cdata)->chip_address, &chip_address, sizeof(bf_chip_address_t));
cg_memcpy(&CMD(cdata)->src_address, &src_address, sizeof(bf_chip_address_t));
cg_memcpy(&CMD(cdata)->work, &work, sizeof(bf_works_t));

if (cmd_code & CHIP_CMD_TASK_WRITE)
cg_memcpy(&CMD(cdata)->work, &work, sizeof(bf_works_t));

CMD(cdata)->id = id;
CMD(cdata)->depth = command.depth;
CMD(cdata)->checksum = command.checksum;
Expand All @@ -382,10 +381,9 @@ int8_t cmd_buffer_push(bf_cmd_buffer_t* cmd_buffer, const uint8_t depth,
}

/* init send buffer */
if (cmd_code != CHIP_CMD_CREATE_CHANNEL) {
cg_memcpy(buff, command.tx, command.data_length);
cg_memcpy(cmd_buffer->tx_buffer + cmd_buffer->tx_offset, buff, CMD(cdata)->data_length);
} else
if (cmd_code != CHIP_CMD_CREATE_CHANNEL)
cg_memcpy(cmd_buffer->tx_buffer + cmd_buffer->tx_offset, command.tx, CMD(cdata)->data_length);
else
cg_memcpy(cmd_buffer->tx_buffer + cmd_buffer->tx_offset, tx, CMD(cdata)->data_length);

#if 0
Expand Down Expand Up @@ -516,9 +514,7 @@ int8_t cmd_buffer_pop(bf_cmd_buffer_t* cmd_buffer, bf_cmd_status_t* cmd_status,
if (cmd_buffer->cmd_list->head == NULL)
return -3;

uint8_t buff[192];
bf_command_t chip_command;
memset(buff, 0, sizeof(buff));
memset(chip_command.rx, 0, sizeof(chip_command.rx));

/* extract command from list */
Expand All @@ -534,25 +530,30 @@ int8_t cmd_buffer_pop(bf_cmd_buffer_t* cmd_buffer, bf_cmd_status_t* cmd_status,
chip_command.nonce_checksum_error = false;

/* extract chip return data */
cg_memcpy(buff, cmd_buffer->rx_buffer + cmd_buffer->rx_offset, CMD(cdata)->data_length);
cmd_buffer->rx_offset += CMD(cdata)->data_length;
uint16_t rx_offset;
if (CMD(cdata)->cmd_code & CHIP_CMD_READ_NONCE) {
cg_memcpy(chip_command.rx, buff + CMD(cdata)->data_length - (49 + 2 + extra_bytes(chip_command.depth)),
49 + 2 + extra_bytes(chip_command.depth));
rx_offset = cmd_buffer->rx_offset + CMD(cdata)->data_length - (49 + 2 + extra_bytes(chip_command.depth));
cg_memcpy(chip_command.rx, cmd_buffer->rx_buffer + rx_offset, 49 + 2 + extra_bytes(chip_command.depth));

memset(nonces, 0, 12 * sizeof(uint32_t));
analyze_rx_data(&chip_command, cmd_status, nonces);
} else if (CMD(cdata)->cmd_code == CHIP_CMD_CREATE_CHANNEL) {
cg_memcpy(chip_command.rx, buff, CMD(cdata)->data_length);
cg_memcpy(chip_command.rx, cmd_buffer->rx_buffer + cmd_buffer->rx_offset, CMD(cdata)->data_length);
} else {
cg_memcpy(chip_command.rx, buff + CMD(cdata)->data_length - (2 + extra_bytes(chip_command.depth)),
2 + extra_bytes(chip_command.depth));
rx_offset = cmd_buffer->rx_offset + CMD(cdata)->data_length - (2 + extra_bytes(chip_command.depth));
cg_memcpy(chip_command.rx, cmd_buffer->rx_buffer + rx_offset, 2 + extra_bytes(chip_command.depth));
analyze_rx_data(&chip_command, cmd_status, NULL);
}

cmd_buffer->rx_offset += CMD(cdata)->data_length;

/* prepare cmd_status */
cg_memcpy(&cmd_status->chip_address, &CMD(cdata)->chip_address, sizeof(bf_chip_address_t));
cg_memcpy(&cmd_status->src_address, &CMD(cdata)->src_address, sizeof(bf_chip_address_t));
cg_memcpy(&cmd_status->work, &CMD(cdata)->work, sizeof(bf_works_t));

if (CMD(cdata)->cmd_code & CHIP_CMD_TASK_WRITE)
cg_memcpy(&cmd_status->work, &CMD(cdata)->work, sizeof(bf_works_t));

cmd_status->id = CMD(cdata)->id;
cmd_status->cmd_code = CMD(cdata)->cmd_code;

Expand Down Expand Up @@ -698,21 +699,18 @@ uint8_t gen_task_data(uint32_t* midstate, uint32_t merkle, uint32_t ntime,
for (i = 0; i < 8; i++) {
tmp = midstate[i];
tmp ^= 0xaaaaaaaa;
tmp = ntohl(tmp);
cg_memcpy(task + i*4, &tmp, sizeof(tmp));
*(uint32_t *)(task + i*4) = ntohl(tmp);
}

ms3steps16(midstate, w, (uint32_t*)task);

for (i = 0; i < 3; i++) {
tmp = w[i];
tmp ^= 0xaaaaaaaa;
tmp = ntohl(tmp);
cg_memcpy(task + (12 + i)*4, &tmp, sizeof(tmp));
*(uint32_t *)(task + (12 + i)*4) = ntohl(tmp);
}

mask = ntohl(mask);
cg_memcpy(task + 19*4, &mask, sizeof(mask));
*(uint32_t *)(task + 19*4) = ntohl(mask);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion bf16-mspcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void parse_board_detect(struct cgpu_info *bitfury, uint8_t board_id, char* data)
struct bitfury16_info *info = (struct bitfury16_info *)(bitfury->device_data);
char* start = data;

char val[4];
char val[16];
memset(val, 0, sizeof(val));

/* BRD_DET*/
Expand Down
34 changes: 25 additions & 9 deletions bf16-spidevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ int8_t spi_init(device_t* attr, spi_channel_id_t channel_id, int8_t mode, uint32
break;
}

attr->mode = mode;
attr->mode = mode;
attr->speed = speed;
attr->bits = 8;
attr->size = size;
attr->rx = malloc(size);
attr->tx = malloc(size);
attr->bits = 32;
attr->size = size;
attr->rx = malloc(size);
attr->tx = malloc(size);

int fd;
if ((fd = open(attr->device, O_RDWR)) < 0) {
Expand Down Expand Up @@ -74,10 +74,24 @@ int8_t spi_init(device_t* attr, spi_channel_id_t channel_id, int8_t mode, uint32

void spi_transfer(device_t *attr)
{
uint16_t i;
uint32_t tx_buff[SPI_BUFFER_SIZE / 4];
uint32_t rx_buff[SPI_BUFFER_SIZE / 4];

memset(tx_buff, 0, sizeof(tx_buff));
memset(rx_buff, 0, sizeof(rx_buff));

uint32_t datalen = (attr->datalen % 4 == 0) ?
attr->datalen :
(4 * (attr->datalen / 4 + 1));

for (i = 0; i <= datalen / 4; i++)
tx_buff[i] = ntohl(*(uint32_t *)(attr->tx + 4*i));

struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long) (attr->tx),
.rx_buf = (unsigned long) (attr->rx),
.len = attr->datalen,
.tx_buf = (unsigned long) (tx_buff),
.rx_buf = (unsigned long) (rx_buff),
.len = datalen,
.delay_usecs = attr->delay,
.speed_hz = attr->speed,
.bits_per_word = attr->bits
Expand All @@ -86,6 +100,9 @@ void spi_transfer(device_t *attr)
if (ioctl(attr->fd, SPI_IOC_MESSAGE(1), &tr) < 0)
quit(1, "BF16: %s() failed to send SPI message: %s", __func__, strerror(errno));

for (i = 0; i < attr->datalen / 4; i++)
*(uint32_t *)(attr->rx + 4*i) = ntohl(rx_buff[i]);

#if 0
uint16_t i;
char data[2*4096];
Expand All @@ -99,7 +116,6 @@ void spi_transfer(device_t *attr)
sprintf(data, "%s%02x", data, attr->rx[i]);
applog(LOG_DEBUG, "BF16: RX <- [%s]", data);
#endif

}

void spi_release(device_t *attr)
Expand Down
2 changes: 1 addition & 1 deletion bf16-spidevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "bf16-device.h"

#define SPI_BUFFER_SIZE 4096
#define SPI_SPEED 20000000
#define SPI_SPEED 12000000

typedef enum {
SPI_CHANNEL1 = 1,
Expand Down
4 changes: 2 additions & 2 deletions bf16-uartdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ int8_t uart_init(device_t* attr, uart_channel_id_t channel_id, int8_t mode, uint
attr->speed = speed;
attr->bits = 8;
attr->size = size;
attr->rx = malloc(size);
attr->tx = malloc(size);
attr->rx = malloc(size + 1);
attr->tx = malloc(size + 1);

int fd;
if ((fd = open(attr->device, O_RDWR | O_NOCTTY | O_NDELAY)) < 0)
Expand Down
14 changes: 1 addition & 13 deletions cgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ static char *set_int_0_to_7680(const char *arg, int *i)
return set_int_range(arg, i, 0, 7680);
}

#if defined(USE_AVALON4) || defined(USE_AVALON7)
#if defined(USE_AVALON4)
static char *set_int_1_to_60(const char *arg, int *i)
{
return set_int_range(arg, i, 1, 60);
Expand Down Expand Up @@ -1464,18 +1464,6 @@ static struct opt_table opt_config_table[] = {
OPT_WITHOUT_ARG("--avalon7-iic-detect",
opt_set_bool, &opt_avalon7_iic_detect,
"Enable Avalon7 detect through iic controller"),
OPT_WITH_ARG("--avalon7-freqadj-time",
set_int_1_to_60, opt_show_intval, &opt_avalon7_freqadj_time,
"Set Avalon7 check interval when run in AVA7_FREQ_TEMPADJ_MODE"),
OPT_WITH_ARG("--avalon7-delta-temp",
opt_set_intval, opt_show_intval, &opt_avalon7_delta_temp,
"Set Avalon7 delta temperature when reset freq in AVA7_FREQ_TEMPADJ_MODE"),
OPT_WITH_ARG("--avalon7-delta-freq",
opt_set_intval, opt_show_intval, &opt_avalon7_delta_freq,
"Set Avalon7 delta freq when adjust freq in AVA7_FREQ_TEMPADJ_MODE"),
OPT_WITH_ARG("--avalon7-freqadj-temp",
opt_set_intval, opt_show_intval, &opt_avalon7_freqadj_temp,
"Set Avalon7 check temperature when run into AVA7_FREQ_TEMPADJ_MODE"),
OPT_WITH_ARG("--avalon7-nonce-mask",
set_int_24_to_32, opt_show_intval, &opt_avalon7_nonce_mask,
"Set A3212 nonce mask, range 24-32."),
Expand Down
Loading