mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-13 16:27:54 +00:00
Always use a usb read buffer instead of having to explicitly enable it.
This commit is contained in:
parent
6c2a8d8be7
commit
8fb7a0d1be
@ -780,7 +780,6 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
|
|||||||
/* Even though this is an FTDI type chip, we want to do the parsing
|
/* Even though this is an FTDI type chip, we want to do the parsing
|
||||||
* all ourselves so set it to std usb type */
|
* all ourselves so set it to std usb type */
|
||||||
avalon->usbdev->usb_type = USB_TYPE_STD;
|
avalon->usbdev->usb_type = USB_TYPE_STD;
|
||||||
usb_buffer_enable(avalon);
|
|
||||||
|
|
||||||
/* We have a real Avalon! */
|
/* We have a real Avalon! */
|
||||||
avalon_initialise(avalon);
|
avalon_initialise(avalon);
|
||||||
|
@ -888,8 +888,6 @@ reinit:
|
|||||||
mutex_init(&bflsc->device_mutex);
|
mutex_init(&bflsc->device_mutex);
|
||||||
rwlock_init(&sc_info->stat_lock);
|
rwlock_init(&sc_info->stat_lock);
|
||||||
|
|
||||||
usb_buffer_enable(bflsc);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
unshin:
|
unshin:
|
||||||
|
@ -146,8 +146,6 @@ static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_device
|
|||||||
* hashrate to adapt quickly on starting. */
|
* hashrate to adapt quickly on starting. */
|
||||||
info->total_nonces = 1;
|
info->total_nonces = 1;
|
||||||
|
|
||||||
usb_buffer_enable(bitfury);
|
|
||||||
|
|
||||||
if (!bitfury_open(bitfury))
|
if (!bitfury_open(bitfury))
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
|
||||||
|
@ -347,7 +347,6 @@ static bool hfa_initialise(struct cgpu_info *hashfast)
|
|||||||
if (hashfast->usbinfo.nodev)
|
if (hashfast->usbinfo.nodev)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
usb_buffer_enable(hashfast);
|
|
||||||
hfa_clear_readbuf(hashfast);
|
hfa_clear_readbuf(hashfast);
|
||||||
|
|
||||||
err = usb_transfer(hashfast, 0, 9, 1, 0, C_ATMEL_RESET);
|
err = usb_transfer(hashfast, 0, 9, 1, 0, C_ATMEL_RESET);
|
||||||
@ -916,7 +915,6 @@ static void hfa_shutdown(struct thr_info *thr)
|
|||||||
pthread_join(info->read_thr, NULL);
|
pthread_join(info->read_thr, NULL);
|
||||||
hfa_free_all_work(info);
|
hfa_free_all_work(info);
|
||||||
hfa_clear_readbuf(hashfast);
|
hfa_clear_readbuf(hashfast);
|
||||||
usb_buffer_disable(hashfast);
|
|
||||||
free(info->works);
|
free(info->works);
|
||||||
free(info->die_statistics);
|
free(info->die_statistics);
|
||||||
free(info->die_status);
|
free(info->die_status);
|
||||||
|
@ -822,8 +822,6 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
|
|||||||
if (!usb_init(icarus, dev, found))
|
if (!usb_init(icarus, dev, found))
|
||||||
goto shin;
|
goto shin;
|
||||||
|
|
||||||
usb_buffer_enable(icarus);
|
|
||||||
|
|
||||||
get_options(this_option_offset, icarus, &baud, &work_division, &fpga_count);
|
get_options(this_option_offset, icarus, &baud, &work_division, &fpga_count);
|
||||||
|
|
||||||
hex2bin((void *)(&workdata), golden_ob, sizeof(workdata));
|
hex2bin((void *)(&workdata), golden_ob, sizeof(workdata));
|
||||||
|
121
usbutils.c
121
usbutils.c
@ -1309,9 +1309,6 @@ static struct cg_usb_device *free_cgusb(struct cg_usb_device *cgusb)
|
|||||||
|
|
||||||
free(cgusb->found);
|
free(cgusb->found);
|
||||||
|
|
||||||
if (cgusb->buffer)
|
|
||||||
free(cgusb->buffer);
|
|
||||||
|
|
||||||
free(cgusb);
|
free(cgusb);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -2503,6 +2500,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
|
|||||||
double max, done;
|
double max, done;
|
||||||
int bufleft, err, got, tot, pstate;
|
int bufleft, err, got, tot, pstate;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
bool dobuffer;
|
||||||
char *search;
|
char *search;
|
||||||
int endlen;
|
int endlen;
|
||||||
unsigned char *ptr, *usbbuf = cgpu->usbinfo.bulkbuf;
|
unsigned char *ptr, *usbbuf = cgpu->usbinfo.bulkbuf;
|
||||||
@ -2531,17 +2529,12 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
|
|||||||
timeout = usbdev->found->timeout;
|
timeout = usbdev->found->timeout;
|
||||||
|
|
||||||
if (end == NULL) {
|
if (end == NULL) {
|
||||||
if (usbdev->buffer && usbdev->bufamt) {
|
tot = usbdev->bufamt;
|
||||||
tot = usbdev->bufamt;
|
bufleft = bufsiz - tot;
|
||||||
bufleft = bufsiz - tot;
|
if (tot)
|
||||||
memcpy(usbbuf, usbdev->buffer, tot);
|
memcpy(usbbuf, usbdev->buffer, tot);
|
||||||
ptr = usbbuf + tot;
|
ptr = usbbuf + tot;
|
||||||
usbdev->bufamt = 0;
|
usbdev->bufamt = 0;
|
||||||
} else {
|
|
||||||
tot = 0;
|
|
||||||
bufleft = bufsiz;
|
|
||||||
ptr = usbbuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = LIBUSB_SUCCESS;
|
err = LIBUSB_SUCCESS;
|
||||||
initial_timeout = timeout;
|
initial_timeout = timeout;
|
||||||
@ -2592,7 +2585,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// N.B. usbdev->buffer was emptied before the while() loop
|
// N.B. usbdev->buffer was emptied before the while() loop
|
||||||
if (usbdev->buffer && tot > (int)bufsiz) {
|
if (tot > (int)bufsiz) {
|
||||||
usbdev->bufamt = tot - bufsiz;
|
usbdev->bufamt = tot - bufsiz;
|
||||||
memcpy(usbdev->buffer, usbbuf + bufsiz, usbdev->bufamt);
|
memcpy(usbdev->buffer, usbbuf + bufsiz, usbdev->bufamt);
|
||||||
tot -= usbdev->bufamt;
|
tot -= usbdev->bufamt;
|
||||||
@ -2607,23 +2600,19 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
|
|||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usbdev->buffer && usbdev->bufamt) {
|
tot = usbdev->bufamt;
|
||||||
tot = usbdev->bufamt;
|
bufleft = bufsiz - tot;
|
||||||
bufleft = bufsiz - tot;
|
if (tot)
|
||||||
memcpy(usbbuf, usbdev->buffer, tot);
|
memcpy(usbbuf, usbdev->buffer, tot);
|
||||||
ptr = usbbuf + tot;
|
ptr = usbbuf + tot;
|
||||||
usbdev->bufamt = 0;
|
usbdev->bufamt = 0;
|
||||||
} else {
|
|
||||||
tot = 0;
|
|
||||||
bufleft = bufsiz;
|
|
||||||
ptr = usbbuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
endlen = strlen(end);
|
endlen = strlen(end);
|
||||||
err = LIBUSB_SUCCESS;
|
err = LIBUSB_SUCCESS;
|
||||||
initial_timeout = timeout;
|
initial_timeout = timeout;
|
||||||
max = ((double)timeout) / 1000.0;
|
max = ((double)timeout) / 1000.0;
|
||||||
cgtime(&read_start);
|
cgtime(&read_start);
|
||||||
|
|
||||||
while (bufleft > 0) {
|
while (bufleft > 0) {
|
||||||
got = 0;
|
got = 0;
|
||||||
err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
|
err = usb_bulk_transfer(usbdev->handle, intinfo, epinfo,
|
||||||
@ -2670,38 +2659,36 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usbdev->buffer) {
|
dobuffer = false;
|
||||||
bool dobuffer = false;
|
|
||||||
|
|
||||||
if ((search = find_end(usbbuf, usbbuf, tot, tot, (char *)end, endlen, true))) {
|
if ((search = find_end(usbbuf, usbbuf, tot, tot, (char *)end, endlen, true))) {
|
||||||
// end finishes after bufsiz
|
// end finishes after bufsiz
|
||||||
if ((search + endlen - (char *)usbbuf) > (int)bufsiz) {
|
if ((search + endlen - (char *)usbbuf) > (int)bufsiz) {
|
||||||
usbdev->bufamt = tot - bufsiz;
|
usbdev->bufamt = tot - bufsiz;
|
||||||
dobuffer = true;
|
dobuffer = true;
|
||||||
} else {
|
|
||||||
// extra data after end
|
|
||||||
if (*(search + endlen)) {
|
|
||||||
usbdev->bufamt = tot - (search + endlen - (char *)usbbuf);
|
|
||||||
dobuffer = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// no end, but still bigger than bufsiz
|
// extra data after end
|
||||||
if (tot > (int)bufsiz) {
|
if (*(search + endlen)) {
|
||||||
usbdev->bufamt = tot - bufsiz;
|
usbdev->bufamt = tot - (search + endlen - (char *)usbbuf);
|
||||||
dobuffer = true;
|
dobuffer = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (dobuffer) {
|
// no end, but still bigger than bufsiz
|
||||||
tot -= usbdev->bufamt;
|
if (tot > (int)bufsiz) {
|
||||||
memcpy(usbdev->buffer, usbbuf + tot, usbdev->bufamt);
|
usbdev->bufamt = tot - bufsiz;
|
||||||
usbbuf[tot] = '\0';
|
dobuffer = true;
|
||||||
applog(LOG_DEBUG, "USB: %s%i read2 buffering %d extra bytes",
|
|
||||||
cgpu->drv->name, cgpu->device_id, usbdev->bufamt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dobuffer) {
|
||||||
|
tot -= usbdev->bufamt;
|
||||||
|
memcpy(usbdev->buffer, usbbuf + tot, usbdev->bufamt);
|
||||||
|
usbbuf[tot] = '\0';
|
||||||
|
applog(LOG_DEBUG, "USB: %s%i read2 buffering %d extra bytes",
|
||||||
|
cgpu->drv->name, cgpu->device_id, usbdev->bufamt);
|
||||||
|
}
|
||||||
|
|
||||||
*processed = tot;
|
*processed = tot;
|
||||||
memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz);
|
memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz);
|
||||||
|
|
||||||
@ -3031,44 +3018,6 @@ int _usb_ftdi_set_latency(struct cgpu_info *cgpu, int intinfo)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_buffer_enable(struct cgpu_info *cgpu)
|
|
||||||
{
|
|
||||||
struct cg_usb_device *cgusb;
|
|
||||||
int pstate;
|
|
||||||
|
|
||||||
DEVWLOCK(cgpu, pstate);
|
|
||||||
|
|
||||||
cgusb = cgpu->usbdev;
|
|
||||||
if (cgusb && !cgusb->buffer) {
|
|
||||||
cgusb->bufamt = 0;
|
|
||||||
cgusb->buffer = malloc(USB_MAX_READ+1);
|
|
||||||
if (!cgusb->buffer)
|
|
||||||
quit(1, "Failed to malloc buffer for USB %s%i",
|
|
||||||
cgpu->drv->name, cgpu->device_id);
|
|
||||||
cgusb->bufsiz = USB_MAX_READ;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEVWUNLOCK(cgpu, pstate);
|
|
||||||
}
|
|
||||||
|
|
||||||
void usb_buffer_disable(struct cgpu_info *cgpu)
|
|
||||||
{
|
|
||||||
struct cg_usb_device *cgusb;
|
|
||||||
int pstate;
|
|
||||||
|
|
||||||
DEVWLOCK(cgpu, pstate);
|
|
||||||
|
|
||||||
cgusb = cgpu->usbdev;
|
|
||||||
if (cgusb && cgusb->buffer) {
|
|
||||||
cgusb->bufamt = 0;
|
|
||||||
cgusb->bufsiz = 0;
|
|
||||||
free(cgusb->buffer);
|
|
||||||
cgusb->buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEVWUNLOCK(cgpu, pstate);
|
|
||||||
}
|
|
||||||
|
|
||||||
void usb_buffer_clear(struct cgpu_info *cgpu)
|
void usb_buffer_clear(struct cgpu_info *cgpu)
|
||||||
{
|
{
|
||||||
int pstate;
|
int pstate;
|
||||||
|
@ -181,6 +181,8 @@ enum usb_types {
|
|||||||
USB_TYPE_FTDI
|
USB_TYPE_FTDI
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define USB_MAX_READ 8192
|
||||||
|
|
||||||
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;
|
||||||
@ -196,7 +198,7 @@ struct cg_usb_device {
|
|||||||
char *serial_string;
|
char *serial_string;
|
||||||
unsigned char fwVersion; // ??
|
unsigned char fwVersion; // ??
|
||||||
unsigned char interfaceVersion; // ??
|
unsigned char interfaceVersion; // ??
|
||||||
char *buffer;
|
char buffer[USB_MAX_READ];
|
||||||
uint32_t bufsiz;
|
uint32_t bufsiz;
|
||||||
uint32_t bufamt;
|
uint32_t bufamt;
|
||||||
cgtimer_t cgt_last_write;
|
cgtimer_t cgt_last_write;
|
||||||
@ -205,8 +207,6 @@ struct cg_usb_device {
|
|||||||
|
|
||||||
#define USB_NOSTAT 0
|
#define USB_NOSTAT 0
|
||||||
|
|
||||||
#define USB_MAX_READ 8192
|
|
||||||
|
|
||||||
#define USB_TMO_0 50
|
#define USB_TMO_0 50
|
||||||
#define USB_TMO_1 100
|
#define USB_TMO_1 100
|
||||||
#define USB_TMO_2 500
|
#define USB_TMO_2 500
|
||||||
@ -394,8 +394,6 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe
|
|||||||
int usb_ftdi_cts(struct cgpu_info *cgpu);
|
int usb_ftdi_cts(struct cgpu_info *cgpu);
|
||||||
int _usb_ftdi_set_latency(struct cgpu_info *cgpu, int intinfo);
|
int _usb_ftdi_set_latency(struct cgpu_info *cgpu, int intinfo);
|
||||||
#define usb_ftdi_set_latency(_cgpu) _usb_ftdi_set_latency(_cgpu, DEFAULT_INTINFO)
|
#define usb_ftdi_set_latency(_cgpu) _usb_ftdi_set_latency(_cgpu, DEFAULT_INTINFO)
|
||||||
void usb_buffer_enable(struct cgpu_info *cgpu);
|
|
||||||
void usb_buffer_disable(struct cgpu_info *cgpu);
|
|
||||||
void usb_buffer_clear(struct cgpu_info *cgpu);
|
void usb_buffer_clear(struct cgpu_info *cgpu);
|
||||||
uint32_t usb_buffer_size(struct cgpu_info *cgpu);
|
uint32_t usb_buffer_size(struct cgpu_info *cgpu);
|
||||||
void usb_set_cps(struct cgpu_info *cgpu, int cps);
|
void usb_set_cps(struct cgpu_info *cgpu, int cps);
|
||||||
|
Loading…
Reference in New Issue
Block a user