Browse Source

Merge branch 'icarus-dev' of github.com:ckolivas/cgminer into icarus-dev

nfactor-troky
Con Kolivas 12 years ago
parent
commit
22e677f4d6
  1. 17
      01-cgminer.rules
  2. 7
      ASIC-README
  3. 29
      FPGA-README
  4. 2
      Makefile.am
  5. 61
      README
  6. 4
      cgminer.c
  7. 35
      configure.ac
  8. 19
      driver-bflsc.c
  9. 10
      driver-bitforce.c
  10. 357
      driver-icarus.c
  11. 2
      driver-ztex.c
  12. 86
      usbtest.py
  13. 118
      usbutils.c
  14. 51
      usbutils.h

17
01-cgminer.rules

@ -1,3 +1,20 @@
# Butterfly Labs FPGA and ASIC devices # Butterfly Labs FPGA and ASIC devices
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
# ModMinerQuad
ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
# Lancelot and Avalon
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
# Icarus
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
# AsicminerUSB
ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
# Cairnsmore1
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="0230", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
# Ztex
ATTRS{idVendor}=="221a", ATTRS{idProduct}=="0100", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"

7
ASIC-README

@ -44,17 +44,12 @@ If your distribution does not have the plugdev group you can create it with:
sudo groupadd plugdev sudo groupadd plugdev
In order for the BFL devices to instantly be owned by the plugdev group and In order for the BFL devices to instantly be owned by the plugdev group and
accessible by anyone from the plugdev group you can either copy the file accessible by anyone from the plugdev group you can copy the file
"01-cgminer.rules" from the cgminer archive into the /etc/udev/rules.d "01-cgminer.rules" from the cgminer archive into the /etc/udev/rules.d
directory with the following command: directory with the following command:
sudo cp 01-cgminer.rules /etc/udev/rules.d/ sudo cp 01-cgminer.rules /etc/udev/rules.d/
Or you can manually create a file/add to a rules.d file with following rules
(most users won't want to do this manually):
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
After this you can either manually restart udev and re-login, or more easily After this you can either manually restart udev and re-login, or more easily
just reboot. just reboot.

29
FPGA-README

@ -2,16 +2,14 @@
This README contains extended details about FPGA mining with cgminer This README contains extended details about FPGA mining with cgminer
For ModMinerQuad (MMQ) and BitForce (BFL) For ModMinerQuad (MMQ) BitForce (BFL) and Icarus (ICA, BLT, LLT, AMU, CMR)
----------------------------------------- --------------------------------------------------------------------------
When mining on windows, the driver being used will determine if mining will work. When mining on windows, the driver being used will determine if mining will work.
If the driver doesn't allow mining, you will get a "USB init," error message If the driver doesn't allow mining, you will get a "USB init," error message
i.e. one of: i.e. one of:
open device failed, err %d, you need to install a Windows USB driver for the device open device failed, err %d, you need to install a Windows USB driver for the device
or
kernel detach failed :(
or or
claim interface %d failed, err %d claim interface %d failed, err %d
@ -32,19 +30,16 @@ with cgminer (not the libusbx version)
When mining on linux, but not using 'sudo' and not logged into 'root' you When mining on linux, but not using 'sudo' and not logged into 'root' you
may get a USB priviledge error (-3), so you may also need to do the following: may get a USB priviledge error (-3), so you may also need to do the following:
Create /etc/udev/rules.d/01-cgminer.rules sudo cp 01-cgminer.rules /etc/udev/rules.d/
With:
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"
And also: And also:
sudo usermod -G plugdev -a `whoami` sudo usermod -G plugdev -a `whoami`
Then reboot ...
If your linux distro doesn't have the 'plugdev' group, you can create it like: If your linux distro doesn't have the 'plugdev' group, you can create it like:
sudo groupadd plugdev sudo groupadd plugdev
Then reboot ...
- -
There is a hidden option in cgminer to dump out a lot of information There is a hidden option in cgminer to dump out a lot of information
@ -53,8 +48,7 @@ problems:
--usb-dump 0 --usb-dump 0
It will only help if you have a working MMQ or BFL device attached to the It will only help if you have a working FPGA device listed above
computer
ModMinerQuad (MMQ) ModMinerQuad (MMQ)
@ -190,8 +184,8 @@ the MH/s value reported with the changed firmware - and the MH/s reported
will be less than the firmware speed since you lose work on every block change. will be less than the firmware speed since you lose work on every block change.
Icarus (ICA) Icarus (ICA, BLT, LLT, AMU, CMR)
------------ --------------------------------
There are two hidden options in cgminer when Icarus support is compiled in: There are two hidden options in cgminer when Icarus support is compiled in:
@ -245,8 +239,8 @@ scan hash time, for the first 5 nonce's or one minute (whichever is longer)
In 'default' or 'value' mode the 'constants' are calculated once at the start, based on the default In 'default' or 'value' mode the 'constants' are calculated once at the start, based on the default
value or the value specified value or the value specified
The optional additional =N specifies to set the default abort at N 1/10ths of a second, not the The optional additional =N specifies to set the default abort at N * 100ms, not the calculated
calculated value, which is 112 for 2.6316ns value, which is ~112 for 2.6316ns
To determine the hash time value for a non Icarus Rev3 device or an Icarus Rev3 with a different To determine the hash time value for a non Icarus Rev3 device or an Icarus Rev3 with a different
bitstream to the default one, use 'long' mode and give it at least a few hundred shares, or use bitstream to the default one, use 'long' mode and give it at least a few hundred shares, or use
@ -258,6 +252,9 @@ Icarus Rev3 requires and also is less than ~840MH/s and greater than 2MH/s
If an FPGA device does hash faster than ~840MH/s it should work correctly if you supply the If an FPGA device does hash faster than ~840MH/s it should work correctly if you supply the
correct hash time nanoseconds value correct hash time nanoseconds value
The Icarus code will automatically detect Icarus, Lancelot, AsicminerUSB and Cairnsmore1
FPGA devices and set default settings to match those devices if you don't specify them
The timing code itself will affect the Icarus performance since it increases the delay after The timing code itself will affect the Icarus performance since it increases the delay after
work is completed or aborted until it starts again work is completed or aborted until it starts again
The increase is, however, extremely small and the actual increase is reported with the The increase is, however, extremely small and the actual increase is reported with the

2
Makefile.am

@ -25,7 +25,7 @@ bin_SCRIPTS = $(top_srcdir)/*.cl
cgminer_LDFLAGS = $(PTHREAD_FLAGS) cgminer_LDFLAGS = $(PTHREAD_FLAGS)
cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \ cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
@OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \ @OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
@UDEV_LIBS@ @LIBUSB_LIBS@ @MM_LIBS@ \ @LIBUSB_LIBS@ @MM_LIBS@ \
@MATH_LIBS@ lib/libgnu.a ccan/libccan.a @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
if HAVE_WINDOWS if HAVE_WINDOWS

61
README

@ -111,7 +111,7 @@ CGMiner specific configuration options:
--disable-adl Override detection and disable building with adl --disable-adl Override detection and disable building with adl
--enable-bflsc Compile support for BFL ASICs (default disabled) --enable-bflsc Compile support for BFL ASICs (default disabled)
--enable-bitforce Compile support for BitForce FPGAs(default disabled) --enable-bitforce Compile support for BitForce FPGAs(default disabled)
--enable-icarus Compile support for Icarus Board(default disabled) --enable-icarus Compile support for Icarus bitstream FPGAs(default disabled)
--enable-modminer Compile support for ModMiner FPGAs(default disabled) --enable-modminer Compile support for ModMiner FPGAs(default disabled)
--enable-ztex Compile support for Ztex Board(default disabled) --enable-ztex Compile support for Ztex Board(default disabled)
--enable-avalon Compile support for Avalon (default disabled) --enable-avalon Compile support for Avalon (default disabled)
@ -235,13 +235,14 @@ ASIC and FPGA mining boards (BFL ASIC, BitForce, Icarus, ModMiner, Ztex)
only options: only options:
Cgminer will automatically find all of your BFL ASIC, BitForce FPGAs, Cgminer will automatically find all of your BFL ASIC, BitForce FPGAs,
ModMiner FPGAs or Ztex FPGAs ModMiner FPGAs, Icarus bitstream FPGAs or Ztex FPGAs
The --usb option can restrict how many BFL ASIC, BitForce FPGAs or
ModMiner FPGAs it finds: The --usb option can restrict how many BFL ASIC, BitForce FPGAs,
ModMiner FPGAs or Icarus bitstream FPGAs it finds:
--usb 1:2,1:3,1:4,1:* --usb 1:2,1:3,1:4,1:*
or or
--usb BAS:1,BFL:1,MMQ:0 --usb BAS:1,BFL:1,MMQ:0,ICA:0
or or
--usb :10 --usb :10
@ -260,15 +261,16 @@ This is useful if you unplug a device then plug it back in the same port,
it usually reappears with the same bus_number but a different device_address it usually reappears with the same bus_number but a different device_address
You can see the list of all USB devices on linux with 'sudo lsusb' You can see the list of all USB devices on linux with 'sudo lsusb'
Cgminer will list the recognised USB devices with the '--usb-dump 0' option Cgminer will list the recognised USB devices with the '-n' option or the
'--usb-dump 0' option
The '--usb-dump N' option with a value of N greater than 0 will dump a lot The '--usb-dump N' option with a value of N greater than 0 will dump a lot
of details about each recognised USB device of details about each recognised USB device
If you wish to see all USB devices, include the --usb-list-all option If you wish to see all USB devices, include the --usb-list-all option
The second version The second version
--usb BAS:1,BFL:1,MMQ:0 --usb BAS:1,BFL:1,MMQ:0,ICA:0
allows you to specify how many devices to choose based on each device allows you to specify how many devices to choose based on each device
driver cgminer has - there are currently 3 USB drivers: BAS, BFL & MMQ driver cgminer has - there are currently 4 USB drivers: BAS, BFL, MMQ & ICA
N.B. you can only specify which device driver to limit, not the type of N.B. you can only specify which device driver to limit, not the type of
each device, e.g. with BAS:n you can limit how many BFL ASIC devices will each device, e.g. with BAS:n you can limit how many BFL ASIC devices will
be checked, but you cannot limit the number of each type of BFL ASIC be checked, but you cannot limit the number of each type of BFL ASIC
@ -283,28 +285,8 @@ not scan for any more
If one of the 10 devices stops working, hotplug - if enabled, as is default If one of the 10 devices stops working, hotplug - if enabled, as is default
- will scan normally again until it has 10 devices - will scan normally again until it has 10 devices
--usb :0 will disable all USB I/O other than to initialise libusb
--scan-serial|-S <arg> Serial port to probe for Icarus mining device
This option is only for Icarus bitstream FPGAs
By default, cgminer will scan for autodetected Icarus unless at least one
-S is specified for that driver. If you specify -S and still want cgminer
to scan, you must also use "-S auto". If you want to prevent cgminer from
scanning without specifying a device, you can use "-S noauto". Note that
presently, autodetection only works on Linux, and might only detect one
device depending on the version of udev being used.
On linux <arg> is usually of the format /dev/ttyUSBn
On windows <arg> is usually of the format \\.\COMn
(where n = the correct device number for the Icarus device)
The official supplied binaries are compiled with support for all FPGAs.
To force the code to only attempt detection with a specific driver,
prepend the argument with the driver name followed by a colon.
For example, "icarus:/dev/ttyUSB0" or using the short name: "ica:/dev/ttyUSB0"
This option not longer matters since Icarus is the only serial-USB
device that uses it
For other FPGA details see the FPGA-README For other FPGA details see the FPGA-README
@ -657,27 +639,6 @@ A: Cgminer currently supports 2 ASICs: Avalon and BitForce SC devices. They
are Application Specify Integrated Circuit devices and provide the highest are Application Specify Integrated Circuit devices and provide the highest
performance per unit power due to being dedicated to only one purpose. performance per unit power due to being dedicated to only one purpose.
Q: How do I get my Icarus/Lancelot/Cairnsmore device to auto-recognise?
A: On linux, if the /dev/ttyUSB* devices don't automatically appear, the only
thing that needs to be done is to load the driver for them:
Icarus: sudo modprobe pl2303 vendor=0x067b product=0x230
Lancelot: sudo modprobe ftdi_sio vendor=0x0403 product=0x6001
Cairnsmore: sudo modprobe ftdi_sio product=0x8350 vendor=0x0403
On windows you must install the pl2303 or ftdi driver required for the device
pl2303: http://prolificusa.com/pl-2303hx-drivers/
ftdi: http://www.ftdichip.com/Drivers/VCP.htm
Q: On linux I can see the /dev/ttyUSB* devices for my Icarus FPGAs, but
cgminer can't mine on them
A: Make sure you have the required priviledges to access the /dev/ttyUSB* devices:
sudo ls -las /dev/ttyUSB*
will give output like:
0 crw-rw---- 1 root dialout 188, 0 2012-09-11 13:49 /dev/ttyUSB0
This means your account must have the group 'dialout' or root priviledges
To permanently give your account the 'dialout' group:
sudo usermod -G dialout -a `whoami`
Then logout and back in again
Q: Can I mine scrypt with FPGAs or ASICs? Q: Can I mine scrypt with FPGAs or ASICs?
A: No. A: No.

4
cgminer.c

@ -60,7 +60,7 @@
#if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER) #if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER)
# define USE_FPGA # define USE_FPGA
#if defined(USE_ICARUS) || defined(USE_AVALON) #if defined(USE_AVALON)
# define USE_FPGA_SERIAL # define USE_FPGA_SERIAL
#endif #endif
#elif defined(USE_ZTEX) #elif defined(USE_ZTEX)
@ -1089,7 +1089,7 @@ static struct opt_table opt_config_table[] = {
#ifdef USE_FPGA_SERIAL #ifdef USE_FPGA_SERIAL
OPT_WITH_ARG("--scan-serial|-S", OPT_WITH_ARG("--scan-serial|-S",
add_serial, NULL, NULL, add_serial, NULL, NULL,
"Serial port to probe for Icarus FPGA Mining device"), "Serial port to probe for Avalon Mining device"),
#endif #endif
OPT_WITH_ARG("--scan-time|-s", OPT_WITH_ARG("--scan-time|-s",
set_int_0_to_9999, opt_show_intval, &opt_scantime, set_int_0_to_9999, opt_show_intval, &opt_scantime,

35
configure.ac

@ -303,14 +303,14 @@ else
]) ])
fi fi
AM_CONDITIONAL([NEED_FPGAUTILS], [test x$avalon$icarus$bitforce$modminer$ztex != xnonononono]) AM_CONDITIONAL([NEED_FPGAUTILS], [test x$avalon$modminer$ztex != xnonono])
AM_CONDITIONAL([NEED_USBUTILS_C], [test x$bitforce$modminer$bflsc != xnonono]) AM_CONDITIONAL([NEED_USBUTILS_C], [test x$bitforce$modminer$bflsc$icarus != xnononono])
AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes]) AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue]) AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue])
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue]) AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue])
if test "x$bitforce$modminer$bflsc" != xnonono; then if test "x$bitforce$modminer$bflsc$icarus" != xnononono; then
AC_DEFINE([USE_USBUTILS], [1], [Defined to 1 if usbutils support required]) AC_DEFINE([USE_USBUTILS], [1], [Defined to 1 if usbutils support required])
fi fi
@ -321,26 +321,6 @@ else
JANSSON_LIBS=-ljansson JANSSON_LIBS=-ljansson
fi fi
if test "x$icarus" != xno; then
AC_ARG_WITH([libudev], [AC_HELP_STRING([--without-libudev], [Autodetect FPGAs using libudev (default enabled)])],
[libudev=$withval],
[libudev=auto]
)
if test "x$libudev" != "xno"; then
AC_CHECK_HEADER([libudev.h],[
libudev=yes
UDEV_LIBS=-ludev
AC_DEFINE([HAVE_LIBUDEV], [1], [Defined to 1 if libudev is wanted])
], [
if test "x$libudev" = "xyes"; then
AC_MSG_ERROR([libudev not found])
fi
libudev=no
])
fi
fi
AM_CONDITIONAL([HAVE_LIBUDEV], [test x$libudev != xno])
PKG_PROG_PKG_CONFIG() PKG_PROG_PKG_CONFIG()
if test "x$have_cgminer_sdk" = "xtrue"; then if test "x$have_cgminer_sdk" = "xtrue"; then
@ -353,7 +333,7 @@ if test "x$have_cgminer_sdk" = "xtrue"; then
PKG_CONFIG_PATH="$CGMINER_SDK/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" PKG_CONFIG_PATH="$CGMINER_SDK/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
fi fi
if test "x$ztex$modminer$bitforce$bflsc" != xnononono; then if test "x$ztex$modminer$bitforce$bflsc$icarus" != xnonononono; then
case $target in case $target in
*-*-freebsd*) *-*-freebsd*)
LIBUSB_LIBS="-lusb" LIBUSB_LIBS="-lusb"
@ -441,7 +421,6 @@ AC_SUBST(PDCURSES_LIBS)
AC_SUBST(WS2_LIBS) AC_SUBST(WS2_LIBS)
AC_SUBST(MM_LIBS) AC_SUBST(MM_LIBS)
AC_SUBST(MATH_LIBS) AC_SUBST(MATH_LIBS)
AC_SUBST(UDEV_LIBS)
AC_SUBST(ADL_CPPFLAGS) AC_SUBST(ADL_CPPFLAGS)
AC_CONFIG_FILES([ AC_CONFIG_FILES([
@ -538,16 +517,12 @@ else
echo " Ztex.FPGAs...........: Disabled" echo " Ztex.FPGAs...........: Disabled"
fi fi
if test "x$icarus" != xno; then
echo " libudev.detection....: $libudev"
fi
echo echo
echo "Compilation............: make (or gmake)" echo "Compilation............: make (or gmake)"
echo " CPPFLAGS.............: $CPPFLAGS" echo " CPPFLAGS.............: $CPPFLAGS"
echo " CFLAGS...............: $CFLAGS $LIBUSB_CFLAGS" echo " CFLAGS...............: $CFLAGS $LIBUSB_CFLAGS"
echo " LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS" echo " LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS"
echo " LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $LIBUSB_LIBS" echo " LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $LIBUSB_LIBS"
echo echo
echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')" echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
echo " prefix...............: $prefix" echo " prefix...............: $prefix"

19
driver-bflsc.c

@ -487,7 +487,7 @@ static bool getok(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amo
{ {
char buf[BFLSC_BUFSIZ+1]; char buf[BFLSC_BUFSIZ+1];
*err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, amount, cmd); *err = usb_read_nl(bflsc, buf, sizeof(buf)-1, amount, cmd);
if (*err < 0 || *amount < (int)BFLSC_OK_LEN) if (*err < 0 || *amount < (int)BFLSC_OK_LEN)
return false; return false;
else else
@ -496,7 +496,7 @@ static bool getok(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amo
static bool getokerr(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amount, char *buf, size_t bufsiz) static bool getokerr(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amount, char *buf, size_t bufsiz)
{ {
*err = usb_ftdi_read_nl(bflsc, buf, bufsiz-1, amount, cmd); *err = usb_read_nl(bflsc, buf, bufsiz-1, amount, cmd);
if (*err < 0 || *amount < (int)BFLSC_OK_LEN) if (*err < 0 || *amount < (int)BFLSC_OK_LEN)
return false; return false;
else { else {
@ -529,7 +529,7 @@ static void bflsc_send_flush_work(struct cgpu_info *bflsc, int dev)
} }
} }
/* return True = attempted usb_ftdi_read_ok() /* return True = attempted usb_read_ok()
* set ignore to true means no applog/ignore errors */ * set ignore to true means no applog/ignore errors */
static bool bflsc_qres(struct cgpu_info *bflsc, char *buf, size_t bufsiz, int dev, int *err, int *amount, bool ignore) static bool bflsc_qres(struct cgpu_info *bflsc, char *buf, size_t bufsiz, int dev, int *err, int *amount, bool ignore)
{ {
@ -550,7 +550,7 @@ static bool bflsc_qres(struct cgpu_info *bflsc, char *buf, size_t bufsiz, int de
// of course all other I/O must also be failing ... // of course all other I/O must also be failing ...
} else { } else {
readok = true; readok = true;
*err = usb_ftdi_read_ok(bflsc, buf, bufsiz-1, amount, C_GETRESULTS); *err = usb_read_ok(bflsc, buf, bufsiz-1, amount, C_GETRESULTS);
mutex_unlock(&(bflsc->device_mutex)); mutex_unlock(&(bflsc->device_mutex));
if (*err < 0 || *amount < 1) { if (*err < 0 || *amount < 1) {
@ -695,7 +695,7 @@ static bool getinfo(struct cgpu_info *bflsc, int dev)
return false; return false;
} }
err = usb_ftdi_read_ok(bflsc, buf, sizeof(buf)-1, &amount, C_GETDETAILS); err = usb_read_ok(bflsc, buf, sizeof(buf)-1, &amount, C_GETDETAILS);
if (err < 0 || amount < 1) { if (err < 0 || amount < 1) {
if (err < 0) { if (err < 0) {
applog(LOG_ERR, "%s detect (%s) get details return invalid/timed out (%d:%d)", applog(LOG_ERR, "%s detect (%s) get details return invalid/timed out (%d:%d)",
@ -830,7 +830,7 @@ reinit:
goto unshin; goto unshin;
} }
err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY); err = usb_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY);
if (err < 0 || amount < 1) { if (err < 0 || amount < 1) {
init_count++; init_count++;
cgtime(&init_now); cgtime(&init_now);
@ -897,17 +897,20 @@ reinit:
sc_info->scan_sleep_time = BAM_SCAN_TIME; sc_info->scan_sleep_time = BAM_SCAN_TIME;
sc_info->results_sleep_time = BAM_RES_TIME; sc_info->results_sleep_time = BAM_RES_TIME;
sc_info->default_ms_work = BAM_WORK_TIME; sc_info->default_ms_work = BAM_WORK_TIME;
bflsc->usbdev->ident = IDENT_BAM;
} else { } else {
if (sc_info->sc_devs[0].engines < 34) { // 16 * 2 + 2 if (sc_info->sc_devs[0].engines < 34) { // 16 * 2 + 2
newname = BFLSC_JALAPENO; newname = BFLSC_JALAPENO;
sc_info->scan_sleep_time = BAJ_SCAN_TIME; sc_info->scan_sleep_time = BAJ_SCAN_TIME;
sc_info->results_sleep_time = BAJ_RES_TIME; sc_info->results_sleep_time = BAJ_RES_TIME;
sc_info->default_ms_work = BAJ_WORK_TIME; sc_info->default_ms_work = BAJ_WORK_TIME;
bflsc->usbdev->ident = IDENT_BAJ;
} else if (sc_info->sc_devs[0].engines < 130) { // 16 * 8 + 2 } else if (sc_info->sc_devs[0].engines < 130) { // 16 * 8 + 2
newname = BFLSC_LITTLESINGLE; newname = BFLSC_LITTLESINGLE;
sc_info->scan_sleep_time = BAL_SCAN_TIME; sc_info->scan_sleep_time = BAL_SCAN_TIME;
sc_info->results_sleep_time = BAL_RES_TIME; sc_info->results_sleep_time = BAL_RES_TIME;
sc_info->default_ms_work = BAL_WORK_TIME; sc_info->default_ms_work = BAL_WORK_TIME;
bflsc->usbdev->ident = IDENT_BAL;
} }
} }
@ -1095,7 +1098,7 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
return false; return false;
} }
err = usb_ftdi_read_nl(bflsc, temp_buf, sizeof(temp_buf)-1, &amount, C_GETTEMPERATURE); err = usb_read_nl(bflsc, temp_buf, sizeof(temp_buf)-1, &amount, C_GETTEMPERATURE);
if (err < 0 || amount < 1) { if (err < 0 || amount < 1) {
mutex_unlock(&(bflsc->device_mutex)); mutex_unlock(&(bflsc->device_mutex));
if (err < 0) { if (err < 0) {
@ -1117,7 +1120,7 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
return false; return false;
} }
err = usb_ftdi_read_nl(bflsc, volt_buf, sizeof(volt_buf)-1, &amount, C_GETTEMPERATURE); err = usb_read_nl(bflsc, volt_buf, sizeof(volt_buf)-1, &amount, C_GETTEMPERATURE);
if (err < 0 || amount < 1) { if (err < 0 || amount < 1) {
mutex_unlock(&(bflsc->device_mutex)); mutex_unlock(&(bflsc->device_mutex));
if (err < 0) { if (err < 0) {

10
driver-bitforce.c

@ -200,7 +200,7 @@ reinit:
goto unshin; goto unshin;
} }
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY)) < 0 || amount < 1) { if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY)) < 0 || amount < 1) {
init_count++; init_count++;
cgtime(&init_now); cgtime(&init_now);
if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) { if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
@ -395,7 +395,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
return false; return false;
} }
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETTEMPERATURE)) < 0 || amount < 1) { if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETTEMPERATURE)) < 0 || amount < 1) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
if (err < 0) { if (err < 0) {
applog(LOG_ERR, "%s%i: Error: Get temp return invalid/timed out (%d:%d)", applog(LOG_ERR, "%s%i: Error: Get temp return invalid/timed out (%d:%d)",
@ -470,7 +470,7 @@ re_send:
return false; return false;
} }
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) { if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%d: read request send work status failed (%d:%d)", applog(LOG_ERR, "%s%d: read request send work status failed (%d:%d)",
bitforce->drv->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
@ -524,7 +524,7 @@ re_send:
return false; return false;
} }
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) { if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%d: read send work status failed (%d:%d)", applog(LOG_ERR, "%s%d: read send work status failed (%d:%d)",
bitforce->drv->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
@ -573,7 +573,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
mutex_lock(&bitforce->device_mutex); mutex_lock(&bitforce->device_mutex);
usb_write(bitforce, BITFORCE_WORKSTATUS, BITFORCE_WORKSTATUS_LEN, &amount, C_REQUESTWORKSTATUS); usb_write(bitforce, BITFORCE_WORKSTATUS, BITFORCE_WORKSTATUS_LEN, &amount, C_REQUESTWORKSTATUS);
usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETWORKSTATUS); usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETWORKSTATUS);
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
cgtime(&now); cgtime(&now);

357
driver-icarus.c

@ -1,7 +1,6 @@
/* /*
* Copyright 2012 Luke Dashjr * Copyright 2012-2013 Andrew Smith
* Copyright 2012 Xiangfu <xiangfu@openmobilefree.com> * Copyright 2012 Xiangfu <xiangfu@openmobilefree.com>
* Copyright 2012 Andrew Smith
* *
* This program is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License as published by the Free
@ -29,30 +28,25 @@
* nonce range is completely calculated. * nonce range is completely calculated.
*/ */
#include "config.h"
#include "miner.h"
#include <float.h>
#include <limits.h> #include <limits.h>
#include <pthread.h> #include <pthread.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <strings.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h> #include <unistd.h>
#ifndef WIN32
#include <termios.h> #include "config.h"
#include <sys/stat.h>
#include <fcntl.h> #ifdef WIN32
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif
#else
#include <windows.h> #include <windows.h>
#include <io.h>
#endif #endif
#include "elist.h" #include "compat.h"
#include "fpgautils.h" #include "miner.h"
#include "usbutils.h"
// The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h // The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h
#define ICARUS_IO_SPEED 115200 #define ICARUS_IO_SPEED 115200
@ -67,41 +61,51 @@
#define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1] #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
ASSERT1(sizeof(uint32_t) == 4); ASSERT1(sizeof(uint32_t) == 4);
#define ICARUS_READ_TIME(baud) ((double)ICARUS_READ_SIZE * (double)8.0 / (double)(baud)) // TODO: USB? Different calculation? - see usbstats to work it out e.g. 1/2 of normal send time
// or even use that number? 1/2
// #define ICARUS_READ_TIME(baud) ((double)ICARUS_READ_SIZE * (double)8.0 / (double)(baud))
// maybe 1ms?
#define ICARUS_READ_TIME(baud) (0.001)
// Fraction of a second, USB timeout is measured in // USB ms timeout to wait
// i.e. 10 means 1/10 of a second #define ICARUS_WAIT_TIMEOUT 100
#define TIME_FACTOR 10
// It's 10 per second, thus value = 10/TIME_FACTOR =
#define ICARUS_READ_FAULT_DECISECONDS 1
// In timing mode: Default starting value until an estimate can be obtained // In timing mode: Default starting value until an estimate can be obtained
// 5 seconds allows for up to a ~840MH/s device // 5000 ms allows for up to a ~840MH/s device
#define ICARUS_READ_COUNT_TIMING (5 * TIME_FACTOR) #define ICARUS_READ_COUNT_TIMING 5000
#define ICARUS_READ_COUNT_MIN ICARUS_WAIT_TIMEOUT
#define SECTOMS(s) ((int)((s) * 1000))
// How many ms below the expected completion time to abort work
// extra in case the last read is delayed
#define ICARUS_READ_REDUCE ((int)(ICARUS_WAIT_TIMEOUT * 1.5))
// For a standard Icarus REV3 (to 5 places) // For a standard Icarus REV3 (to 5 places)
// Since this rounds up a the last digit - it is a slight overestimate // Since this rounds up a the last digit - it is a slight overestimate
// Thus the hash rate will be a VERY slight underestimate // Thus the hash rate will be a VERY slight underestimate
// (by a lot less than the displayed accuracy) // (by a lot less than the displayed accuracy)
// Minor inaccuracy of these numbers doesn't affect the work done,
// only the displayed MH/s
#define ICARUS_REV3_HASH_TIME 0.0000000026316 #define ICARUS_REV3_HASH_TIME 0.0000000026316
#define LANCELOT_HASH_TIME 0.0000000025000
#define ASICMINERUSB_HASH_TIME 0.0000000029761
#define NANOSEC 1000000000.0 #define NANOSEC 1000000000.0
// Icarus Rev3 doesn't send a completion message when it finishes // Icarus Rev3 doesn't send a completion message when it finishes
// the full nonce range, so to avoid being idle we must abort the // the full nonce range, so to avoid being idle we must abort the
// work (by starting a new work) shortly before it finishes // work (by starting a new work item) shortly before it finishes
// //
// Thus we need to estimate 2 things: // Thus we need to estimate 2 things:
// 1) How many hashes were done if the work was aborted // 1) How many hashes were done if the work was aborted
// 2) How high can the timeout be before the Icarus is idle, // 2) How high can the timeout be before the Icarus is idle,
// to minimise the number of work started // to minimise the number of work items started
// We set 2) to 'the calculated estimate' - 1 // We set 2) to 'the calculated estimate' - ICARUS_READ_REDUCE
// to ensure the estimate ends before idle // to ensure the estimate ends before idle
// //
// The simple calculation used is: // The simple calculation used is:
// Tn = Total time in seconds to calculate n hashes // Tn = Total time in seconds to calculate n hashes
// Hs = seconds per hash // Hs = seconds per hash
// Xn = number of hashes // Xn = number of hashes
// W = code overhead per work // W = code/usb overhead per work
// //
// Rough but reasonable estimate: // Rough but reasonable estimate:
// Tn = Hs * Xn + W (of the form y = mx + b) // Tn = Hs * Xn + W (of the form y = mx + b)
@ -123,7 +127,7 @@ ASSERT1(sizeof(uint32_t) == 4);
#define HISTORY_SEC 60 #define HISTORY_SEC 60
// Minimum how many points a single ICARUS_HISTORY should have // Minimum how many points a single ICARUS_HISTORY should have
#define MIN_DATA_COUNT 5 #define MIN_DATA_COUNT 5
// The value above used is doubled each history until it exceeds: // The value MIN_DATA_COUNT used is doubled each history until it exceeds:
#define MAX_MIN_DATA_COUNT 100 #define MAX_MIN_DATA_COUNT 100
static struct timeval history_sec = { HISTORY_SEC, 0 }; static struct timeval history_sec = { HISTORY_SEC, 0 };
@ -163,7 +167,8 @@ struct ICARUS_INFO {
// seconds per Hash // seconds per Hash
double Hs; double Hs;
int read_count; // ms til we abort
int read_time;
enum timing_mode timing_mode; enum timing_mode timing_mode;
bool do_icarus_timing; bool do_icarus_timing;
@ -195,7 +200,8 @@ static struct ICARUS_INFO **icarus_info;
// //
// Code increments this each time we start to look at a device // Code increments this each time we start to look at a device
// However, this means that if other devices are checked by // However, this means that if other devices are checked by
// the Icarus code (e.g. BFL) they will count in the option offset // the Icarus code (e.g. Avalon only as at 20130517)
// they will count in the option offset
// //
// This, however, is deterministic so that's OK // This, however, is deterministic so that's OK
// //
@ -203,13 +209,21 @@ static struct ICARUS_INFO **icarus_info;
// that would be random since an Icarus may fail and thus we'd // that would be random since an Icarus may fail and thus we'd
// not be able to predict the option order // not be able to predict the option order
// //
// This also assumes that serial_detect() checks them sequentially // Devices are checked in the order libusb finds them which is ?
// and in the order specified on the command line
// //
static int option_offset = -1; static int option_offset = -1;
struct device_drv icarus_drv; struct device_drv icarus_drv;
static void icarus_initialise(struct cgpu_info *icarus, int baud)
{
if (icarus->usbinfo.nodev)
return;
if (baud) {
}
}
static void rev(unsigned char *s, size_t l) static void rev(unsigned char *s, size_t l)
{ {
size_t i, j; size_t i, j;
@ -222,81 +236,63 @@ static void rev(unsigned char *s, size_t l)
} }
} }
#define icarus_open2(devpath, baud, purge) serial_open(devpath, baud, ICARUS_READ_FAULT_DECISECONDS, purge) #define ICA_NONCE_ERROR -1
#define icarus_open(devpath, baud) icarus_open2(devpath, baud, false) #define ICA_NONCE_OK 0
#define ICA_NONCE_RESTART 1
#define ICA_NONCE_TIMEOUT 2
#define ICA_GETS_ERROR -1 static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct timeval *tv_start, struct timeval *tv_finish, struct thr_info *thr, int read_time)
#define ICA_GETS_OK 0
#define ICA_GETS_RESTART 1
#define ICA_GETS_TIMEOUT 2
static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct thr_info *thr, int read_count)
{ {
ssize_t ret = 0; struct timeval read_start, read_finish;
int err, amt;
int rc = 0; int rc = 0;
int read_amount = ICARUS_READ_SIZE; int read_amount = ICARUS_READ_SIZE;
bool first = true; bool first = true;
// Read reply 1 byte at a time to get earliest tv_finish cgtime(tv_start);
while (true) { while (true) {
ret = read(fd, buf, 1); cgtime(&read_start);
if (ret < 0) err = usb_read_timeout(icarus, (char *)buf, read_amount, &amt, ICARUS_WAIT_TIMEOUT, C_GETRESULTS);
return ICA_GETS_ERROR; cgtime(&read_finish);
if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) {
applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id);
dev_error(icarus, REASON_DEV_COMMS_ERROR);
return ICA_NONCE_ERROR;
}
if (first) if (first)
cgtime(tv_finish); copy_time(tv_finish, &read_finish);
if (ret >= read_amount) // TODO: test if there is more data? to read a 2nd nonce?
return ICA_GETS_OK; if (amt >= ICARUS_READ_SIZE)
return ICA_NONCE_OK;
if (ret > 0) { if (amt > 0) {
buf += ret; buf += amt;
read_amount -= ret; read_amount -= amt;
first = false; first = false;
continue; continue;
} }
rc++; rc += SECTOMS(tdiff(&read_finish, &read_start));
if (rc >= read_count) { if (rc >= read_time) {
if (opt_debug) { if (opt_debug) {
applog(LOG_DEBUG, applog(LOG_DEBUG,
"Icarus Read: No data in %.2f seconds", "Icarus Read: No data in %d ms", rc);
(float)rc/(float)TIME_FACTOR);
} }
return ICA_GETS_TIMEOUT; return ICA_NONCE_TIMEOUT;
} }
if (thr && thr->work_restart) { if (thr && thr->work_restart) {
if (opt_debug) { if (opt_debug) {
applog(LOG_DEBUG, applog(LOG_DEBUG,
"Icarus Read: Work restart at %.2f seconds", "Icarus Read: Work restart at %d ms", rc);
(float)(rc)/(float)TIME_FACTOR);
} }
return ICA_GETS_RESTART; return ICA_NONCE_RESTART;
} }
} }
} }
static int icarus_write(int fd, const void *buf, size_t bufLen)
{
size_t ret;
ret = write(fd, buf, bufLen);
if (unlikely(ret != bufLen))
return 1;
return 0;
}
#define icarus_close(fd) close(fd)
static void do_icarus_close(struct thr_info *thr)
{
struct cgpu_info *icarus = thr->cgpu;
icarus_close(icarus->device_fd);
icarus->device_fd = -1;
}
static const char *timing_mode_str(enum timing_mode timing_mode) static const char *timing_mode_str(enum timing_mode timing_mode)
{ {
switch(timing_mode) { switch(timing_mode) {
@ -346,17 +342,17 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
} }
info->Hs = 0; info->Hs = 0;
info->read_count = 0; info->read_time = 0;
if (strcasecmp(buf, MODE_SHORT_STR) == 0) { if (strcasecmp(buf, MODE_SHORT_STR) == 0) {
info->Hs = ICARUS_REV3_HASH_TIME; info->Hs = ICARUS_REV3_HASH_TIME;
info->read_count = ICARUS_READ_COUNT_TIMING; info->read_time = ICARUS_READ_COUNT_TIMING;
info->timing_mode = MODE_SHORT; info->timing_mode = MODE_SHORT;
info->do_icarus_timing = true; info->do_icarus_timing = true;
} else if (strcasecmp(buf, MODE_LONG_STR) == 0) { } else if (strcasecmp(buf, MODE_LONG_STR) == 0) {
info->Hs = ICARUS_REV3_HASH_TIME; info->Hs = ICARUS_REV3_HASH_TIME;
info->read_count = ICARUS_READ_COUNT_TIMING; info->read_time = ICARUS_READ_COUNT_TIMING;
info->timing_mode = MODE_LONG; info->timing_mode = MODE_LONG;
info->do_icarus_timing = true; info->do_icarus_timing = true;
@ -365,13 +361,13 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
info->fullnonce = info->Hs * (((double)0xffffffff) + 1); info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
if ((eq = strchr(buf, '=')) != NULL) if ((eq = strchr(buf, '=')) != NULL)
info->read_count = atoi(eq+1); info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT;
if (info->read_count < 1) if (info->read_time < ICARUS_READ_COUNT_MIN)
info->read_count = (int)(info->fullnonce * TIME_FACTOR) - 1; info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE;
if (unlikely(info->read_count < 1)) if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN))
info->read_count = 1; info->read_time = ICARUS_READ_COUNT_MIN;
info->timing_mode = MODE_VALUE; info->timing_mode = MODE_VALUE;
info->do_icarus_timing = false; info->do_icarus_timing = false;
@ -382,10 +378,13 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
info->fullnonce = info->Hs * (((double)0xffffffff) + 1); info->fullnonce = info->Hs * (((double)0xffffffff) + 1);
if ((eq = strchr(buf, '=')) != NULL) if ((eq = strchr(buf, '=')) != NULL)
info->read_count = atoi(eq+1); info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT;
if (info->read_time < ICARUS_READ_COUNT_MIN)
info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE;
if (info->read_count < 1) if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN))
info->read_count = (int)(info->fullnonce * TIME_FACTOR) - 1; info->read_time = ICARUS_READ_COUNT_MIN;
info->timing_mode = MODE_DEFAULT; info->timing_mode = MODE_DEFAULT;
info->do_icarus_timing = false; info->do_icarus_timing = false;
@ -393,8 +392,8 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
info->min_data_count = MIN_DATA_COUNT; info->min_data_count = MIN_DATA_COUNT;
applog(LOG_DEBUG, "Icarus: Init: %d mode=%s read_count=%d Hs=%e", applog(LOG_DEBUG, "Icarus: Init: %d mode=%s read_time=%dms Hs=%e",
icarus->device_id, timing_mode_str(info->timing_mode), info->read_count, info->Hs); icarus->device_id, timing_mode_str(info->timing_mode), info->read_time, info->Hs);
} }
static uint32_t mask(int work_division) static uint32_t mask(int work_division)
@ -508,13 +507,12 @@ static void get_options(int this_option_offset, int *baud, int *work_division, i
} }
} }
static bool icarus_detect_one(const char *devpath) static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{ {
int this_option_offset = ++option_offset; int this_option_offset = ++option_offset;
char devpath[20];
struct ICARUS_INFO *info; struct ICARUS_INFO *info;
struct timeval tv_start, tv_finish; struct timeval tv_start, tv_finish;
int fd;
// Block 171874 nonce = (0xa2870100) = 0x000187a2 // Block 171874 nonce = (0xa2870100) = 0x000187a2
// N.B. golden_ob MUST take less time to calculate // N.B. golden_ob MUST take less time to calculate
@ -528,30 +526,52 @@ static bool icarus_detect_one(const char *devpath)
const char golden_nonce[] = "000187a2"; const char golden_nonce[] = "000187a2";
const uint32_t golden_nonce_val = 0x000187a2; const uint32_t golden_nonce_val = 0x000187a2;
unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE]; unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE];
char *nonce_hex; char *nonce_hex;
int baud, work_division, fpga_count; int baud, work_division, fpga_count;
struct cgpu_info *icarus;
int ret, err, amount, tries;
get_options(this_option_offset, &baud, &work_division, &fpga_count); get_options(this_option_offset, &baud, &work_division, &fpga_count);
applog(LOG_DEBUG, "Icarus Detect: Attempting to open %s", devpath); icarus = calloc(1, sizeof(struct cgpu_info));
if (unlikely(!icarus))
quit(1, "Failed to calloc icarus in icarus_detect_one");
icarus->drv = &icarus_drv;
icarus->deven = DEV_ENABLED;
icarus->threads = 1;
if (!usb_init(icarus, dev, found))
goto shin;
fd = icarus_open2(devpath, baud, true); // TODO: set options based on ident if options not supplied
if (unlikely(fd == -1)) { // add a flag to say options were set by parameters
applog(LOG_ERR, "Icarus Detect: Failed to open %s", devpath);
return false; sprintf(devpath, "%d:%d",
} (int)(icarus->usbinfo.bus_number),
(int)(icarus->usbinfo.device_address));
icarus->device_path = strdup(devpath);
hex2bin(ob_bin, golden_ob, sizeof(ob_bin)); hex2bin(ob_bin, golden_ob, sizeof(ob_bin));
icarus_write(fd, ob_bin, sizeof(ob_bin));
cgtime(&tv_start);
memset(nonce_bin, 0, sizeof(nonce_bin)); tries = 0;
icarus_gets(nonce_bin, fd, &tv_finish, NULL, 1); while (++tries) {
icarus_initialise(icarus, baud);
err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDTESTWORK);
if (err == LIBUSB_SUCCESS && amount == sizeof(ob_bin))
break;
icarus_close(fd); if (tries > 2)
goto unshin;
}
memset(nonce_bin, 0, sizeof(nonce_bin));
ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, NULL, 1);
if (ret != ICA_NONCE_OK)
goto unshin;
nonce_hex = bin2hex(nonce_bin, sizeof(nonce_bin)); nonce_hex = bin2hex(nonce_bin, sizeof(nonce_bin));
if (strncmp(nonce_hex, golden_nonce, 8)) { if (strncmp(nonce_hex, golden_nonce, 8)) {
@ -560,7 +580,7 @@ static bool icarus_detect_one(const char *devpath)
"Test failed at %s: get %s, should: %s", "Test failed at %s: get %s, should: %s",
devpath, nonce_hex, golden_nonce); devpath, nonce_hex, golden_nonce);
free(nonce_hex); free(nonce_hex);
return false; goto unshin;
} }
applog(LOG_DEBUG, applog(LOG_DEBUG,
"Icarus Detect: " "Icarus Detect: "
@ -569,14 +589,14 @@ static bool icarus_detect_one(const char *devpath)
free(nonce_hex); free(nonce_hex);
/* We have a real Icarus! */ /* We have a real Icarus! */
struct cgpu_info *icarus; if (!add_cgpu(icarus))
icarus = calloc(1, sizeof(struct cgpu_info)); goto unshin;
icarus->drv = &icarus_drv;
icarus->device_path = strdup(devpath); update_usb_stats(icarus);
icarus->device_fd = -1;
icarus->threads = 1;
add_cgpu(icarus);
icarus_info = realloc(icarus_info, sizeof(struct ICARUS_INFO *) * (total_devices + 1)); icarus_info = realloc(icarus_info, sizeof(struct ICARUS_INFO *) * (total_devices + 1));
if (unlikely(!icarus_info))
quit(1, "Failed to realloc ICARUS_INFO");
applog(LOG_INFO, "Found Icarus at %s, mark as %d", applog(LOG_INFO, "Found Icarus at %s, mark as %d",
devpath, icarus->device_id); devpath, icarus->device_id);
@ -605,11 +625,23 @@ static bool icarus_detect_one(const char *devpath)
set_timing_mode(this_option_offset, icarus); set_timing_mode(this_option_offset, icarus);
return true; return true;
unshin:
usb_uninit(icarus);
free(icarus->device_path);
shin:
free(icarus);
return false;
} }
static void icarus_detect() static void icarus_detect()
{ {
serial_detect(&icarus_drv, icarus_detect_one); usb_detect(&icarus_drv, icarus_detect_one);
} }
static bool icarus_prepare(struct thr_info *thr) static bool icarus_prepare(struct thr_info *thr)
@ -618,18 +650,6 @@ static bool icarus_prepare(struct thr_info *thr)
struct timeval now; struct timeval now;
icarus->device_fd = -1;
int fd = icarus_open(icarus->device_path, icarus_info[icarus->device_id]->baud);
if (unlikely(-1 == fd)) {
applog(LOG_ERR, "Failed to open Icarus on %s",
icarus->device_path);
return false;
}
icarus->device_fd = fd;
applog(LOG_INFO, "Opened Icarus on %s", icarus->device_path);
cgtime(&now); cgtime(&now);
get_datestamp(icarus->init, &now); get_datestamp(icarus->init, &now);
@ -639,9 +659,8 @@ static bool icarus_prepare(struct thr_info *thr)
static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
__maybe_unused int64_t max_nonce) __maybe_unused int64_t max_nonce)
{ {
struct cgpu_info *icarus; struct cgpu_info *icarus = thr->cgpu;
int fd; int ret, err, amount;
int ret;
struct ICARUS_INFO *info; struct ICARUS_INFO *info;
@ -658,43 +677,32 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
struct ICARUS_HISTORY *history0, *history; struct ICARUS_HISTORY *history0, *history;
int count; int count;
double Hs, W, fullnonce; double Hs, W, fullnonce;
int read_count; int read_time;
int64_t estimate_hashes; int64_t estimate_hashes;
uint32_t values; uint32_t values;
int64_t hash_count_range; int64_t hash_count_range;
elapsed.tv_sec = elapsed.tv_usec = 0; // Device is gone
if (icarus->usbinfo.nodev)
icarus = thr->cgpu;
if (icarus->device_fd == -1)
if (!icarus_prepare(thr)) {
applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id);
dev_error(icarus, REASON_DEV_COMMS_ERROR);
// fail the device if the reopen attempt fails
return -1; return -1;
}
fd = icarus->device_fd; info = icarus_info[icarus->device_id];
elapsed.tv_sec = elapsed.tv_usec = 0;
memset(ob_bin, 0, sizeof(ob_bin)); memset(ob_bin, 0, sizeof(ob_bin));
memcpy(ob_bin, work->midstate, 32); memcpy(ob_bin, work->midstate, 32);
memcpy(ob_bin + 52, work->data + 64, 12); memcpy(ob_bin + 52, work->data + 64, 12);
rev(ob_bin, 32); rev(ob_bin, 32);
rev(ob_bin + 52, 12); rev(ob_bin + 52, 12);
#ifndef WIN32
tcflush(fd, TCOFLUSH); err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDWORK);
#endif if (err < 0 || amount != sizeof(ob_bin)) {
ret = icarus_write(fd, ob_bin, sizeof(ob_bin));
if (ret) {
do_icarus_close(thr);
applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id); applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id);
dev_error(icarus, REASON_DEV_COMMS_ERROR); dev_error(icarus, REASON_DEV_COMMS_ERROR);
return 0; /* This should never happen */ icarus_initialise(icarus, info->baud);
return 0;
} }
cgtime(&tv_start);
if (opt_debug) { if (opt_debug) {
ob_hex = bin2hex(ob_bin, sizeof(ob_bin)); ob_hex = bin2hex(ob_bin, sizeof(ob_bin));
applog(LOG_DEBUG, "Icarus %d sent: %s", applog(LOG_DEBUG, "Icarus %d sent: %s",
@ -704,19 +712,14 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
/* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */ /* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */
memset(nonce_bin, 0, sizeof(nonce_bin)); memset(nonce_bin, 0, sizeof(nonce_bin));
info = icarus_info[icarus->device_id]; ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, thr, info->read_time);
ret = icarus_gets(nonce_bin, fd, &tv_finish, thr, info->read_count); if (ret == ICA_NONCE_ERROR)
if (ret == ICA_GETS_ERROR) {
do_icarus_close(thr);
applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id);
dev_error(icarus, REASON_DEV_COMMS_ERROR);
return 0; return 0;
}
work->blk.nonce = 0xffffffff; work->blk.nonce = 0xffffffff;
// aborted before becoming idle, get new work // aborted before becoming idle, get new work
if (ret == ICA_GETS_TIMEOUT || ret == ICA_GETS_RESTART) { if (ret == ICA_NONCE_TIMEOUT || ret == ICA_NONCE_RESTART) {
timersub(&tv_finish, &tv_start, &elapsed); timersub(&tv_finish, &tv_start, &elapsed);
// ONLY up to just when it aborted // ONLY up to just when it aborted
@ -739,19 +742,11 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
} }
memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin)); memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin));
nonce = htobe32(nonce);
#if !defined (__BIG_ENDIAN__) && !defined(MIPSEB)
nonce = swab32(nonce);
#endif
curr_hw_errors = icarus->hw_errors; curr_hw_errors = icarus->hw_errors;
submit_nonce(thr, work, nonce); submit_nonce(thr, work, nonce);
was_hw_error = (curr_hw_errors > icarus->hw_errors); was_hw_error = (curr_hw_errors > icarus->hw_errors);
// Force a USB close/reopen on any hw error
if (was_hw_error)
do_icarus_close(thr);
hash_count = (nonce & info->nonce_mask); hash_count = (nonce & info->nonce_mask);
hash_count++; hash_count++;
hash_count *= info->fpga_count; hash_count *= info->fpga_count;
@ -804,7 +799,7 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
memset(history0, 0, sizeof(struct ICARUS_HISTORY)); memset(history0, 0, sizeof(struct ICARUS_HISTORY));
// We just completed a history data set // We just completed a history data set
// So now recalc read_count based on the whole history thus we will // So now recalc read_time based on the whole history thus we will
// initially get more accurate until it completes INFO_HISTORY // initially get more accurate until it completes INFO_HISTORY
// total data sets // total data sets
count = 0; count = 0;
@ -837,10 +832,10 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
memset(history0, 0, sizeof(struct ICARUS_HISTORY)); memset(history0, 0, sizeof(struct ICARUS_HISTORY));
fullnonce = W + Hs * (((double)0xffffffff) + 1); fullnonce = W + Hs * (((double)0xffffffff) + 1);
read_count = (int)(fullnonce * TIME_FACTOR) - 1; read_time = SECTOMS(fullnonce) - ICARUS_READ_REDUCE;
info->Hs = Hs; info->Hs = Hs;
info->read_count = read_count; info->read_time = read_time;
info->fullnonce = fullnonce; info->fullnonce = fullnonce;
info->count = count; info->count = count;
@ -853,9 +848,9 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
else if (info->timing_mode == MODE_SHORT) else if (info->timing_mode == MODE_SHORT)
info->do_icarus_timing = false; info->do_icarus_timing = false;
// applog(LOG_WARNING, "Icarus %d Re-estimate: read_count=%d fullnonce=%fs history count=%d Hs=%e W=%e values=%d hash range=0x%08lx min data count=%u", icarus->device_id, read_count, fullnonce, count, Hs, W, values, hash_count_range, info->min_data_count); // applog(LOG_WARNING, "Icarus %d Re-estimate: read_time=%d fullnonce=%fs history count=%d Hs=%e W=%e values=%d hash range=0x%08lx min data count=%u", icarus->device_id, read_time, fullnonce, count, Hs, W, values, hash_count_range, info->min_data_count);
applog(LOG_WARNING, "Icarus %d Re-estimate: Hs=%e W=%e read_count=%d fullnonce=%.3fs", applog(LOG_WARNING, "Icarus %d Re-estimate: Hs=%e W=%e read_time=%dms fullnonce=%.3fs",
icarus->device_id, Hs, W, read_count, fullnonce); icarus->device_id, Hs, W, read_time, fullnonce);
} }
info->history_count++; info->history_count++;
cgtime(&tv_history_finish); cgtime(&tv_history_finish);
@ -876,7 +871,7 @@ static struct api_data *icarus_api_stats(struct cgpu_info *cgpu)
// care since hashing performance is way more important than // care since hashing performance is way more important than
// locking access to displaying API debug 'stats' // locking access to displaying API debug 'stats'
// If locking becomes an issue for any of them, use copy_data=true also // If locking becomes an issue for any of them, use copy_data=true also
root = api_add_int(root, "read_count", &(info->read_count), false); root = api_add_int(root, "read_time", &(info->read_time), false);
root = api_add_double(root, "fullnonce", &(info->fullnonce), false); root = api_add_double(root, "fullnonce", &(info->fullnonce), false);
root = api_add_int(root, "count", &(info->count), false); root = api_add_int(root, "count", &(info->count), false);
root = api_add_hs(root, "Hs", &(info->Hs), false); root = api_add_hs(root, "Hs", &(info->Hs), false);
@ -896,9 +891,9 @@ static struct api_data *icarus_api_stats(struct cgpu_info *cgpu)
return root; return root;
} }
static void icarus_shutdown(struct thr_info *thr) static void icarus_shutdown(__maybe_unused struct thr_info *thr)
{ {
do_icarus_close(thr); // TODO: ?
} }
struct device_drv icarus_drv = { struct device_drv icarus_drv = {

2
driver-ztex.c

@ -7,7 +7,7 @@
* Copyright (C) 2009-2011 ZTEX GmbH. * Copyright (C) 2009-2011 ZTEX GmbH.
* http://www.ztex.de * http://www.ztex.de
* *
* This work is based upon the icarus.c worker which is * This work is based upon the icarus.c worker which was
* Copyright 2012 Luke Dashjr * Copyright 2012 Luke Dashjr
* Copyright 2012 Xiangfu <xiangfu@openmobilefree.com> * Copyright 2012 Xiangfu <xiangfu@openmobilefree.com>
* *

86
usbtest.py

@ -0,0 +1,86 @@
#!/usr/bin/env python2.7
#
# Original version supplied to me (Kano/kanoi) by xiangfu
#
# Modified to allow supplying the data to send
#
# Linux usAge: ./ubstest.py /dev/ttyUSB0 0xhexcodes|string|icarus
# OR python ubstest.py /dev/ttyUSB0 0xhexcodes|string|icarus
#
# Windows usAge: ./ubstest.py COM1 0xhexcodes|string|icarus
#
# sends the data sepcified to the USB device and waits
# for a reply then displays it
#
# the data can be:
# 0xhexcodes: e.g. 0x68656c6c6f20776f726c640a
# would send "hello world\n"
#
# string: e.g. sendsometext
#
# icarus: sends 2 known block payloads for an icarus device
# and shows the expected and actual answers if it's
# a working V3 icarus
import sys
import serial
import binascii
if len(sys.argv) < 2:
sys.stderr.write("usAge: " + sys.argv[0] + " device strings...\n")
sys.stderr.write(" where device is either like /dev/ttyUSB0 or COM1\n")
sys.stderr.write(" and strings are either '0xXXXX' or 'text'\n")
sys.stderr.write(" if the first string is 'icarus' the rest are ignored\n")
sys.stderr.write(" and 2 valid icarus test payloads are sent with results displayed\n")
sys.stderr.write("\nAfter any command is sent it waits up to 30 seconds for a reply\n");
sys.exit("Aborting")
# Open with a 10 second timeout - just to be sure
ser = serial.Serial(sys.argv[1], 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, 10, False, False, 5, False, None)
if sys.argv[2] == "icarus":
# This show how Icarus use the block and midstate data
# This will produce nonce 063c5e01
block = "0000000120c8222d0497a7ab44a1a2c7bf39de941c9970b1dc7cdc400000079700000000e88aabe1f353238c668d8a4df9318e614c10c474f8cdf8bc5f6397b946c33d7c4e7242c31a098ea500000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
midstate = "33c5bf5751ec7f7e056443b5aee3800331432c83f404d9de38b94ecbf907b92d"
rdata2 = block.decode('hex')[95:63:-1]
rmid = midstate.decode('hex')[::-1]
payload = rmid + rdata2
print("Push payload to icarus: " + binascii.hexlify(payload))
ser.write(payload)
b=ser.read(4)
print("Result:(should be: 063c5e01): " + binascii.hexlify(b))
# Just another test
payload2 = "ce92099c5a80bb81c52990d5c0924c625fd25a535640607d5a4bdf8174e2c8d500000000000000000000000080000000000000000b290c1a42313b4f21b5bcb8"
print("Push payload to icarus: " + payload2)
ser.write(payload2.decode('hex'))
b=ser.read(4)
print("Result:(should be: 8e0b31c5): " + binascii.hexlify(b))
else:
data = ""
for arg in sys.argv[2::]:
if arg[0:2:] == '0x':
data += arg[2::].decode('hex')
else:
data += arg
print("Sending: 0x" + binascii.hexlify(data))
ser.write(data)
# If you're expecting more than one linefeed terminated reply,
# you'll only see the first one
# AND with no linefeed, this will wait the 10 seconds before returning
print("Waiting up to 10 seconds ...")
b=ser.readline()
print("Result: hex 0x" + binascii.hexlify(b))
# This could mess up the display - do it last
print("Result: asc '" + b + "'")
ser.close()

118
usbutils.c

@ -57,11 +57,13 @@
#define BITFORCE_TIMEOUT_MS 999 #define BITFORCE_TIMEOUT_MS 999
#define MODMINER_TIMEOUT_MS 200 #define MODMINER_TIMEOUT_MS 200
#define AVALON_TIMEOUT_MS 500 #define AVALON_TIMEOUT_MS 500
#define ICARUS_TIMEOUT_MS 500
#else #else
#define BFLSC_TIMEOUT_MS 200 #define BFLSC_TIMEOUT_MS 200
#define BITFORCE_TIMEOUT_MS 200 #define BITFORCE_TIMEOUT_MS 200
#define MODMINER_TIMEOUT_MS 100 #define MODMINER_TIMEOUT_MS 100
#define AVALON_TIMEOUT_MS 200 #define AVALON_TIMEOUT_MS 200
#define ICARUS_TIMEOUT_MS 200
#endif #endif
#ifdef USE_BFLSC #ifdef USE_BFLSC
@ -94,20 +96,35 @@ static struct usb_endpoints ava_eps[] = {
}; };
#endif #endif
// TODO: Add support for (at least) Isochronous endpoints
static struct usb_find_devices find_dev[] = {
/*
#ifdef USE_ICARUS #ifdef USE_ICARUS
{ DRV_ICARUS, "ICA", 0x067b, 0x0230, true, EPI(3), EPO(2), 1 }, static struct usb_endpoints ica_eps[] = {
{ DRV_ICARUS, "LOT", 0x0403, 0x6001, false, EPI(0), EPO(0), 1 }, { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(3), 0 },
{ DRV_ICARUS, "CM1", 0x067b, 0x0230, false, EPI(0), EPO(0), 1 }, { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0 }
};
static struct usb_endpoints amu_eps[] = {
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 },
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(1), 0 }
};
static struct usb_endpoints llt_eps[] = {
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 },
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0 }
};
static struct usb_endpoints cmr_eps[] = {
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 },
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0 }
};
#endif #endif
*/
#define IDVENDOR_FTDI 0x0403
// TODO: Add support for (at least) Isochronous endpoints
static struct usb_find_devices find_dev[] = {
#ifdef USE_BFLSC #ifdef USE_BFLSC
{ {
.drv = DRV_BFLSC, .drv = DRV_BFLSC,
.name = "BAS", .name = "BAS",
.idVendor = 0x0403, .ident = IDENT_BAS,
.idVendor = IDVENDOR_FTDI,
.idProduct = 0x6014, .idProduct = 0x6014,
.iManufacturer = "Butterfly Labs", .iManufacturer = "Butterfly Labs",
.iProduct = "BitFORCE SHA256 SC", .iProduct = "BitFORCE SHA256 SC",
@ -122,7 +139,8 @@ static struct usb_find_devices find_dev[] = {
{ {
.drv = DRV_BITFORCE, .drv = DRV_BITFORCE,
.name = "BFL", .name = "BFL",
.idVendor = 0x0403, .ident = IDENT_BFL,
.idVendor = IDVENDOR_FTDI,
.idProduct = 0x6014, .idProduct = 0x6014,
.iManufacturer = "Butterfly Labs Inc.", .iManufacturer = "Butterfly Labs Inc.",
.iProduct = "BitFORCE SHA256", .iProduct = "BitFORCE SHA256",
@ -137,6 +155,7 @@ static struct usb_find_devices find_dev[] = {
{ {
.drv = DRV_MODMINER, .drv = DRV_MODMINER,
.name = "MMQ", .name = "MMQ",
.ident = IDENT_MMQ,
.idVendor = 0x1fc9, .idVendor = 0x1fc9,
.idProduct = 0x0003, .idProduct = 0x0003,
.kernel = 0, .kernel = 0,
@ -150,7 +169,8 @@ static struct usb_find_devices find_dev[] = {
{ {
.drv = DRV_AVALON, .drv = DRV_AVALON,
.name = "AVA", .name = "AVA",
.idVendor = 0x0403, .ident = IDENT_AVA,
.idVendor = IDVENDOR_FTDI,
.idProduct = 0x6001, .idProduct = 0x6001,
.kernel = 0, .kernel = 0,
.config = 1, .config = 1,
@ -159,12 +179,78 @@ static struct usb_find_devices find_dev[] = {
.epcount = ARRAY_SIZE(ava_eps), .epcount = ARRAY_SIZE(ava_eps),
.eps = ava_eps }, .eps = ava_eps },
#endif #endif
#ifdef USE_ICARUS
{
.drv = DRV_ICARUS,
.name = "ICA",
.ident = IDENT_ICA,
.idVendor = 0x067b,
.idProduct = 0x2303,
.kernel = 0,
.config = 1,
.interface = 0,
.timeout = ICARUS_TIMEOUT_MS,
.epcount = ARRAY_SIZE(ica_eps),
.eps = ica_eps },
{
.drv = DRV_ICARUS,
.name = "AMU",
.ident = IDENT_AMU,
.idVendor = 0x10c4,
.idProduct = 0xea60,
.kernel = 0,
.config = 1,
.interface = 0,
.timeout = ICARUS_TIMEOUT_MS,
.epcount = ARRAY_SIZE(amu_eps),
.eps = amu_eps },
{
.drv = DRV_ICARUS,
.name = "BLT",
.ident = IDENT_BLT,
.idVendor = IDVENDOR_FTDI,
.idProduct = 0x6001,
.iProduct = "FT232R USB UART",
.kernel = 0,
.config = 1,
.interface = 0,
.timeout = ICARUS_TIMEOUT_MS,
.epcount = ARRAY_SIZE(llt_eps),
.eps = llt_eps },
// For any that don't match the above "BLT"
{
.drv = DRV_ICARUS,
.name = "LLT",
.ident = IDENT_LLT,
.idVendor = IDVENDOR_FTDI,
.idProduct = 0x6001,
.kernel = 0,
.config = 1,
.interface = 0,
.timeout = ICARUS_TIMEOUT_MS,
.epcount = ARRAY_SIZE(llt_eps),
.eps = llt_eps },
{
.drv = DRV_ICARUS,
.name = "CMR",
.ident = IDENT_CMR,
.idVendor = 0x067b,
.idProduct = 0x0230,
.iProduct = "Cairnsmore1",
.kernel = 0,
.config = 1,
.interface = 0,
.timeout = ICARUS_TIMEOUT_MS,
.epcount = ARRAY_SIZE(cmr_eps),
.eps = cmr_eps },
#endif
#ifdef USE_ZTEX #ifdef USE_ZTEX
// This is here so cgminer -n shows them // This is here so cgminer -n shows them
// the ztex driver (as at 201303) doesn't use usbutils // the ztex driver (as at 201303) doesn't use usbutils
{ {
.drv = DRV_ZTEX, .drv = DRV_ZTEX,
.name = "ZTX", .name = "ZTX",
.ident = IDENT_ZTX,
.idVendor = 0x221a, .idVendor = 0x221a,
.idProduct = 0x0100, .idProduct = 0x0100,
.kernel = 0, .kernel = 0,
@ -174,7 +260,7 @@ static struct usb_find_devices find_dev[] = {
.epcount = 0, .epcount = 0,
.eps = NULL }, .eps = NULL },
#endif #endif
{ DRV_LAST, NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, NULL } { DRV_LAST, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, NULL }
}; };
#ifdef USE_BFLSC #ifdef USE_BFLSC
@ -321,6 +407,7 @@ static const char *C_QUEJOBSTATUS_S = "QueJobStatus";
static const char *C_QUEFLUSH_S = "QueFlush"; static const char *C_QUEFLUSH_S = "QueFlush";
static const char *C_QUEFLUSHREPLY_S = "QueFlushReply"; static const char *C_QUEFLUSHREPLY_S = "QueFlushReply";
static const char *C_REQUESTVOLTS_S = "RequestVolts"; static const char *C_REQUESTVOLTS_S = "RequestVolts";
static const char *C_SENDTESTWORK_S = "SendTestWork";
#ifdef EOL #ifdef EOL
#undef EOL #undef EOL
@ -789,6 +876,7 @@ static void cgusb_check_init()
usb_commands[C_QUEFLUSH] = C_QUEFLUSH_S; usb_commands[C_QUEFLUSH] = C_QUEFLUSH_S;
usb_commands[C_QUEFLUSHREPLY] = C_QUEFLUSHREPLY_S; usb_commands[C_QUEFLUSHREPLY] = C_QUEFLUSHREPLY_S;
usb_commands[C_REQUESTVOLTS] = C_REQUESTVOLTS_S; usb_commands[C_REQUESTVOLTS] = C_REQUESTVOLTS_S;
usb_commands[C_SENDTESTWORK] = C_SENDTESTWORK_S;
stats_initialised = true; stats_initialised = true;
} }
@ -1256,6 +1344,11 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
cgusb = calloc(1, sizeof(*cgusb)); cgusb = calloc(1, sizeof(*cgusb));
cgusb->found = found; cgusb->found = found;
if (found->idVendor == IDVENDOR_FTDI)
cgusb->usb_type = USB_TYPE_FTDI;
cgusb->ident = found->ident;
cgusb->descriptor = calloc(1, sizeof(*(cgusb->descriptor))); cgusb->descriptor = calloc(1, sizeof(*(cgusb->descriptor)));
err = libusb_get_device_descriptor(dev, cgusb->descriptor); err = libusb_get_device_descriptor(dev, cgusb->descriptor);
@ -1837,9 +1930,10 @@ static void rejected_inc(struct cgpu_info *cgpu)
#define USB_MAX_READ 8192 #define USB_MAX_READ 8192
int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool ftdi, bool readonce) int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce)
{ {
struct cg_usb_device *usbdev = cgpu->usbdev; struct cg_usb_device *usbdev = cgpu->usbdev;
bool ftdi = (usbdev->usb_type == USB_TYPE_FTDI);
#if DO_USB_STATS #if DO_USB_STATS
struct timeval tv_start; struct timeval tv_start;
#endif #endif

51
usbutils.h

@ -50,9 +50,26 @@ struct usb_endpoints {
bool found; bool found;
}; };
enum sub_ident {
IDENT_BAJ,
IDENT_BAL,
IDENT_BAS,
IDENT_BAM,
IDENT_BFL,
IDENT_MMQ,
IDENT_AVA,
IDENT_ICA,
IDENT_AMU,
IDENT_BLT,
IDENT_LLT,
IDENT_CMR,
IDENT_ZTX
};
struct usb_find_devices { struct usb_find_devices {
int drv; int drv;
const char *name; const char *name;
enum sub_ident ident;
uint16_t idVendor; uint16_t idVendor;
uint16_t idProduct; uint16_t idProduct;
char *iManufacturer; char *iManufacturer;
@ -65,11 +82,18 @@ struct usb_find_devices {
struct usb_endpoints *eps; struct usb_endpoints *eps;
}; };
enum usb_types {
USB_TYPE_STD = 0,
USB_TYPE_FTDI
};
struct cg_usb_device { struct cg_usb_device {
struct usb_find_devices *found; struct usb_find_devices *found;
libusb_device_handle *handle; libusb_device_handle *handle;
pthread_mutex_t *mutex; pthread_mutex_t *mutex;
struct libusb_device_descriptor *descriptor; struct libusb_device_descriptor *descriptor;
enum usb_types usb_type;
enum sub_ident ident;
uint16_t usbver; uint16_t usbver;
int speed; int speed;
char *prod_string; char *prod_string;
@ -136,6 +160,7 @@ enum usb_cmds {
C_QUEFLUSH, C_QUEFLUSH,
C_QUEFLUSHREPLY, C_QUEFLUSHREPLY,
C_REQUESTVOLTS, C_REQUESTVOLTS,
C_SENDTESTWORK,
C_MAX C_MAX
}; };
@ -150,29 +175,32 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *)); void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));
struct api_data *api_usb_stats(int *count); struct api_data *api_usb_stats(int *count);
void update_usb_stats(struct cgpu_info *cgpu); void update_usb_stats(struct cgpu_info *cgpu);
int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool ftdi, bool readonce); int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce);
int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds); int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds);
int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned int timeout, enum usb_cmds cmd); int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned int timeout, enum usb_cmds cmd);
void usb_cleanup(); void usb_cleanup();
void usb_initialise(); void usb_initialise();
#define usb_read(cgpu, buf, bufsiz, read, cmd) \ #define usb_read(cgpu, buf, bufsiz, read, cmd) \
_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, false) _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
#define usb_read_once(cgpu, buf, bufsiz, read, cmd) \ #define usb_read_once(cgpu, buf, bufsiz, read, cmd) \
_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, true) _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true)
#define usb_read_nl(cgpu, buf, bufsiz, read, cmd) \ #define usb_read_nl(cgpu, buf, bufsiz, read, cmd) \
_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false, false) _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false)
#define usb_read_ok(cgpu, buf, bufsiz, read, cmd) \
_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, false)
#define usb_read_ep(cgpu, ep, buf, bufsiz, read, cmd) \ #define usb_read_ep(cgpu, ep, buf, bufsiz, read, cmd) \
_usb_read(cgpu, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, false) _usb_read(cgpu, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
#define usb_read_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \ #define usb_read_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false, false) _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false)
#define usb_read_ep_timeout(cgpu, ep, buf, bufsiz, read, timeout, cmd) \ #define usb_read_ep_timeout(cgpu, ep, buf, bufsiz, read, timeout, cmd) \
_usb_read(cgpu, ep, buf, bufsiz, read, timeout, NULL, cmd, false, false) _usb_read(cgpu, ep, buf, bufsiz, read, timeout, NULL, cmd, false)
#define usb_write(cgpu, buf, bufsiz, wrote, cmd) \ #define usb_write(cgpu, buf, bufsiz, wrote, cmd) \
_usb_write(cgpu, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd) _usb_write(cgpu, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
@ -186,15 +214,6 @@ void usb_initialise();
#define usb_write_ep_timeout(cgpu, ep, buf, bufsiz, wrote, timeout, cmd) \ #define usb_write_ep_timeout(cgpu, ep, buf, bufsiz, wrote, timeout, cmd) \
_usb_write(cgpu, ep, buf, bufsiz, wrote, timeout, cmd) _usb_write(cgpu, ep, buf, bufsiz, wrote, timeout, cmd)
#define usb_ftdi_read(cgpu, buf, bufsiz, read, cmd) \
_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true, false)
#define usb_ftdi_read_nl(cgpu, buf, bufsiz, read, cmd) \
_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, true, false)
#define usb_ftdi_read_ok(cgpu, buf, bufsiz, read, cmd) \
_usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, true, false)
#define usb_transfer(cgpu, typ, req, val, idx, cmd) \ #define usb_transfer(cgpu, typ, req, val, idx, cmd) \
_usb_transfer(cgpu, typ, req, val, idx, DEVTIMEOUT, cmd) _usb_transfer(cgpu, typ, req, val, idx, DEVTIMEOUT, cmd)

Loading…
Cancel
Save