Browse Source

First draft of port of avalon driver to new cgminer queued infrastructure.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
71bae003bc
  1. 34
      cgminer.c
  2. 1060
      driver-avalon.c
  3. 136
      driver-avalon.h
  4. 22
      fpgautils.c
  5. 2
      fpgautils.h
  6. 77
      hexdump.c
  7. 17
      miner.h

34
cgminer.c

@ -48,6 +48,7 @@ @@ -48,6 +48,7 @@
#include "driver-opencl.h"
#include "bench_block.h"
#include "scrypt.h"
#include "driver-avalon.h"
#if defined(unix)
#include <errno.h>
@ -55,9 +56,9 @@ @@ -55,9 +56,9 @@
#include <sys/wait.h>
#endif
#if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_MODMINER)
#if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER)
# define USE_FPGA
#if defined(USE_ICARUS)
#if defined(USE_ICARUS) || defined(USE_AVALON)
# define USE_FPGA_SERIAL
#endif
#elif defined(USE_ZTEX)
@ -138,6 +139,9 @@ bool opt_disable_pool; @@ -138,6 +139,9 @@ bool opt_disable_pool;
char *opt_icarus_options = NULL;
char *opt_icarus_timing = NULL;
bool opt_worktime;
#ifdef USE_AVALON
char *opt_avalon_options = NULL;
#endif
#ifdef USE_USBUTILS
char *opt_usb_select = NULL;
int opt_usbdump = -1;
@ -833,6 +837,15 @@ static char *set_icarus_timing(const char *arg) @@ -833,6 +837,15 @@ static char *set_icarus_timing(const char *arg)
}
#endif
#ifdef USE_AVALON
static char *set_avalon_options(const char *arg)
{
opt_set_charp(arg, &opt_avalon_options);
return NULL;
}
#endif
#ifdef USE_USBUTILS
static char *set_usb_select(const char *arg)
{
@ -1032,6 +1045,11 @@ static struct opt_table opt_config_table[] = { @@ -1032,6 +1045,11 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--icarus-timing",
set_icarus_timing, NULL, NULL,
opt_hidden),
#endif
#ifdef USE_AVALON
OPT_WITH_ARG("--avalon-options",
set_avalon_options, NULL, NULL,
opt_hidden),
#endif
OPT_WITHOUT_ARG("--load-balance",
set_loadbalance, &pool_strategy,
@ -1359,6 +1377,9 @@ static char *opt_verusage_and_exit(const char *extra) @@ -1359,6 +1377,9 @@ static char *opt_verusage_and_exit(const char *extra)
#ifdef USE_ICARUS
"icarus "
#endif
#ifdef USE_AVALON
"avalon "
#endif
#ifdef USE_MODMINER
"modminer "
#endif
@ -6792,6 +6813,10 @@ extern struct device_drv bitforce_drv; @@ -6792,6 +6813,10 @@ extern struct device_drv bitforce_drv;
extern struct device_drv icarus_drv;
#endif
#ifdef USE_AVALON
extern struct device_drv avalon_api;
#endif
#ifdef USE_MODMINER
extern struct device_drv modminer_drv;
#endif
@ -7311,6 +7336,11 @@ int main(int argc, char *argv[]) @@ -7311,6 +7336,11 @@ int main(int argc, char *argv[])
icarus_drv.drv_detect();
#endif
#ifdef USE_AVALON
if (!opt_scrypt)
avalon_api.drv_detect();
#endif
#ifdef USE_BFLSC
if (!opt_scrypt)
bflsc_drv.drv_detect();

1060
driver-avalon.c

File diff suppressed because it is too large Load Diff

136
driver-avalon.h

@ -0,0 +1,136 @@ @@ -0,0 +1,136 @@
/*
* Copyright 2013 Avalon project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
#ifndef AVALON_H
#define AVALON_H
#ifdef USE_AVALON
#define AVALON_TIME_FACTOR 10
#define AVALON_RESET_FAULT_DECISECONDS 1
#define AVALON_MINER_THREADS 1
#define AVALON_IO_SPEED 115200
#define AVALON_HASH_TIME_FACTOR ((float)1.67/0x32)
#define AVALON_RESET_PITCH (300*1000*1000)
#define AVALON_FAN_FACTOR 120
#define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */
#define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */
#define AVALON_DEFAULT_TIMEOUT 0x32
#define AVALON_DEFAULT_FREQUENCY 256
#define AVALON_DEFAULT_MINER_NUM 0x20
#define AVALON_DEFAULT_ASIC_NUM 0xA
struct avalon_task {
uint8_t reset :1;
uint8_t flush_fifo :1;
uint8_t fan_eft :1;
uint8_t timer_eft :1;
uint8_t asic_num :4;
uint8_t fan_pwm_data;
uint8_t timeout_data;
uint8_t miner_num;
uint8_t nonce_elf :1;
uint8_t gate_miner_elf :1;
uint8_t asic_pll :1;
uint8_t gate_miner :1;
uint8_t _pad0 :4;
uint8_t _pad1[3];
uint32_t _pad2;
uint8_t midstate[32];
uint8_t data[12];
} __attribute__((packed, aligned(4)));
struct avalon_result {
uint32_t nonce;
uint8_t data[12];
uint8_t midstate[32];
uint8_t fan0;
uint8_t fan1;
uint8_t fan2;
uint8_t temp0;
uint8_t temp1;
uint8_t temp2;
uint8_t _pad0[2];
uint16_t fifo_wp;
uint16_t fifo_rp;
uint8_t chip_num;
uint8_t pwm_data;
uint8_t timeout;
uint8_t miner_num;
} __attribute__((packed, aligned(4)));
struct avalon_info {
int read_count;
int baud;
int miner_count;
int asic_count;
int timeout;
int fan0;
int fan1;
int fan2;
int temp0;
int temp1;
int temp2;
int temp_max;
int temp_history_count;
int temp_history_index;
int temp_sum;
int temp_old;
int fan_pwm;
int no_matching_work;
int matching_work[AVALON_DEFAULT_MINER_NUM];
struct work *bulk0[AVALON_DEFAULT_MINER_NUM];
struct work *bulk1[AVALON_DEFAULT_MINER_NUM];
struct work *bulk2[AVALON_DEFAULT_MINER_NUM];
struct work *bulk3[AVALON_DEFAULT_MINER_NUM];
int frequency;
};
#define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
#define AVALON_READ_SIZE (sizeof(struct avalon_result))
#define AVA_GETS_ERROR -1
#define AVA_GETS_OK 0
#define AVA_GETS_RESTART 1
#define AVA_GETS_TIMEOUT 2
#define AVA_SEND_ERROR -1
#define AVA_SEND_OK 0
#define AVA_SEND_BUFFER_EMPTY 1
#define AVA_SEND_BUFFER_FULL 2
#define AVA_BUFFER_FULL 0
#define AVA_BUFFER_EMPTY 1
#define avalon_open2(devpath, baud, purge) serial_open(devpath, baud, AVALON_RESET_FAULT_DECISECONDS, purge)
#define avalon_open(devpath, baud) avalon_open2(devpath, baud, true)
#define avalon_close(fd) close(fd)
#define avalon_buffer_full(fd) get_serial_cts(fd)
#define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
#define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
ASSERT1(sizeof(uint32_t) == 4);
extern struct avalon_info **avalon_info;
#endif /* USE_AVALON */
#endif /* AVALON_H */

22
fpgautils.c

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
/*
* Copyright 2013 Con Kolivas <kernel@kolivas.org>
* Copyright 2012 Luke Dashjr
* Copyright 2012 Andrew Smith
*
@ -19,6 +20,7 @@ @@ -19,6 +20,7 @@
#ifndef WIN32
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
@ -32,10 +34,12 @@ @@ -32,10 +34,12 @@
#ifdef HAVE_LIBUDEV
#include <libudev.h>
#include <sys/ioctl.h>
#endif
#include "elist.h"
#include "logging.h"
#include "miner.h"
#include "fpgautils.h"
#ifdef HAVE_LIBUDEV
@ -382,6 +386,14 @@ int serial_open(const char *devpath, unsigned long baud, signed short timeout, b @@ -382,6 +386,14 @@ int serial_open(const char *devpath, unsigned long baud, signed short timeout, b
switch (baud) {
case 0:
break;
case 19200:
cfsetispeed(&my_termios, B19200);
cfsetospeed(&my_termios, B19200);
break;
case 38400:
cfsetispeed(&my_termios, B38400);
cfsetospeed(&my_termios, B38400);
break;
case 57600:
cfsetispeed(&my_termios, B57600);
cfsetospeed(&my_termios, B57600);
@ -570,4 +582,14 @@ size_t _select_write(int fd, char *buf, size_t siz, struct timeval *timeout) @@ -570,4 +582,14 @@ size_t _select_write(int fd, char *buf, size_t siz, struct timeval *timeout)
return wrote;
}
int get_serial_cts(int fd)
{
int flags;
if (!fd)
return -1;
ioctl(fd, TIOCMGET, &flags);
return (flags & TIOCM_CTS) ? 1 : 0;
}
#endif // ! WIN32

2
fpgautils.h

@ -36,6 +36,8 @@ extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol); @@ -36,6 +36,8 @@ extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
extern FILE *open_bitstream(const char *dname, const char *filename);
extern int get_serial_cts(int fd);
#ifndef WIN32
extern const struct timeval tv_timeout_default;
extern const struct timeval tv_inter_char_default;

77
hexdump.c

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
/*
* hexdump implementation without depenecies to *printf()
* output is equal to 'hexdump -C'
* should be compatible to 64bit architectures
*
* Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define hex_print(p) applog(LOG_DEBUG, "%s", p)
static char nibble[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
#define BYTES_PER_LINE 0x10
void hexdump(const uint8_t *p, unsigned int len)
{
unsigned int i, addr;
unsigned int wordlen = sizeof(void*);
unsigned char v, line[BYTES_PER_LINE * 5];
for (addr = 0; addr < len; addr += BYTES_PER_LINE) {
/* clear line */
for (i = 0; i < sizeof(line); i++) {
if (i == wordlen * 2 + 52 ||
i == wordlen * 2 + 69) {
line[i] = '|';
continue;
}
if (i == wordlen * 2 + 70) {
line[i] = '\0';
continue;
}
line[i] = ' ';
}
/* print address */
for (i = 0; i < wordlen * 2; i++) {
v = addr >> ((wordlen * 2 - i - 1) * 4);
line[i] = nibble[v & 0xf];
}
/* dump content */
for (i = 0; i < BYTES_PER_LINE; i++) {
int pos = (wordlen * 2) + 3 + (i / 8);
if (addr + i >= len)
break;
v = p[addr + i];
line[pos + (i * 3) + 0] = nibble[v >> 4];
line[pos + (i * 3) + 1] = nibble[v & 0xf];
/* character printable? */
line[(wordlen * 2) + 53 + i] =
(v >= ' ' && v <= '~') ? v : '.';
}
hex_print(line);
}
}

17
miner.h

@ -120,9 +120,11 @@ static inline int fsync (int fd) @@ -120,9 +120,11 @@ static inline int fsync (int fd)
#if (!defined(WIN32) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) \
|| (defined(WIN32) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)))
#define bswap_16 __builtin_bswap16
#define bswap_32 __builtin_bswap32
#define bswap_64 __builtin_bswap64
#ifndef bswap_16
#define bswap_16 __builtin_bswap16
#define bswap_32 __builtin_bswap32
#define bswap_64 __builtin_bswap64
#endif
#else
#if HAVE_BYTESWAP_H
#include <byteswap.h>
@ -421,8 +423,12 @@ struct cgpu_info { @@ -421,8 +423,12 @@ struct cgpu_info {
#ifdef USE_USBUTILS
struct cg_usb_device *usbdev;
#endif
#ifdef USE_ICARUS
#if defined(USE_ICARUS) || defined(USE_AVALON)
int device_fd;
#endif
#ifdef USE_AVALON
struct work **works;
int queued;
#endif
};
#ifdef USE_USBUTILS
@ -786,6 +792,9 @@ extern bool opt_restart; @@ -786,6 +792,9 @@ extern bool opt_restart;
extern char *opt_icarus_options;
extern char *opt_icarus_timing;
extern bool opt_worktime;
#ifdef USE_AVALON
extern char *opt_avalon_options;
#endif
#ifdef USE_USBUTILS
extern char *opt_usb_select;
extern int opt_usbdump;

Loading…
Cancel
Save