Browse Source

usbutils/icarus include more locking to usbdev access

nfactor-troky
Kano 12 years ago
parent
commit
9ecef180d1
  1. 66
      driver-icarus.c
  2. 47
      usbutils.c
  3. 3
      usbutils.h

66
driver-icarus.c

@ -251,6 +251,8 @@ static void _transfer(struct cgpu_info *icarus, uint8_t request_type, uint8_t bR
static void icarus_initialise(struct cgpu_info *icarus, int baud) static void icarus_initialise(struct cgpu_info *icarus, int baud)
{ {
uint16_t wValue, wIndex; uint16_t wValue, wIndex;
enum sub_ident ident;
int interface;
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
@ -258,14 +260,19 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
usb_set_cps(icarus, baud / 10); usb_set_cps(icarus, baud / 10);
usb_enable_cps(icarus); usb_enable_cps(icarus);
switch (icarus->usbdev->ident) { interface = usb_interface(icarus);
ident = usb_ident(icarus);
switch (ident) {
case IDENT_BLT: case IDENT_BLT:
case IDENT_LLT: case IDENT_LLT:
case IDENT_CMR1: case IDENT_CMR1:
case IDENT_CMR2: case IDENT_CMR2:
usb_set_pps(icarus, BLT_PREF_PACKET);
// Reset // Reset
transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_RESET, transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_RESET,
icarus->usbdev->found->interface, C_RESET); interface, C_RESET);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
@ -278,7 +285,7 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
// Set data control // Set data control
transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_DATA, FTDI_VALUE_DATA_BLT, transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_DATA, FTDI_VALUE_DATA_BLT,
icarus->usbdev->found->interface, C_SETDATA); interface, C_SETDATA);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
@ -287,8 +294,7 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
wValue = FTDI_VALUE_BAUD_BLT; wValue = FTDI_VALUE_BAUD_BLT;
wIndex = FTDI_INDEX_BAUD_BLT; wIndex = FTDI_INDEX_BAUD_BLT;
if (icarus->usbdev->ident == IDENT_CMR1 || if (ident == IDENT_CMR1 || ident == IDENT_CMR2) {
icarus->usbdev->ident == IDENT_CMR2) {
switch (baud) { switch (baud) {
case 115200: case 115200:
wValue = FTDI_VALUE_BAUD_CMR_115; wValue = FTDI_VALUE_BAUD_CMR_115;
@ -306,43 +312,42 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
// Set the baud // Set the baud
transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, wValue, transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, wValue,
(wIndex & 0xff00) | icarus->usbdev->found->interface, (wIndex & 0xff00) | interface, C_SETBAUD);
C_SETBAUD);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
// Set Modem Control // Set Modem Control
transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM, FTDI_VALUE_MODEM, transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM, FTDI_VALUE_MODEM,
icarus->usbdev->found->interface, C_SETMODEM); interface, C_SETMODEM);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
// Set Flow Control // Set Flow Control
transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW, FTDI_VALUE_FLOW, transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW, FTDI_VALUE_FLOW,
icarus->usbdev->found->interface, C_SETFLOW); interface, C_SETFLOW);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
// Clear any sent data // Clear any sent data
transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_TX, transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_TX,
icarus->usbdev->found->interface, C_PURGETX); interface, C_PURGETX);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
// Clear any received data // Clear any received data
transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_RX, transfer(icarus, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_RX,
icarus->usbdev->found->interface, C_PURGERX); interface, C_PURGERX);
icarus->usbdev->PrefPacketSize = BLT_PREF_PACKET;
break; break;
case IDENT_ICA: case IDENT_ICA:
usb_set_pps(icarus, ICA_PREF_PACKET);
// Set Data Control // Set Data Control
transfer(icarus, PL2303_CTRL_OUT, PL2303_REQUEST_CTRL, PL2303_VALUE_CTRL, transfer(icarus, PL2303_CTRL_OUT, PL2303_REQUEST_CTRL, PL2303_VALUE_CTRL,
icarus->usbdev->found->interface, C_SETDATA); interface, C_SETDATA);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
@ -350,30 +355,29 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
// Set Line Control // Set Line Control
uint32_t ica_data[2] = { PL2303_VALUE_LINE0, PL2303_VALUE_LINE1 }; uint32_t ica_data[2] = { PL2303_VALUE_LINE0, PL2303_VALUE_LINE1 };
_transfer(icarus, PL2303_CTRL_OUT, PL2303_REQUEST_LINE, PL2303_VALUE_LINE, _transfer(icarus, PL2303_CTRL_OUT, PL2303_REQUEST_LINE, PL2303_VALUE_LINE,
icarus->usbdev->found->interface, interface, &ica_data[0], PL2303_VALUE_LINE_SIZE, C_SETLINE);
&ica_data[0], PL2303_VALUE_LINE_SIZE, C_SETLINE);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
// Vendor // Vendor
transfer(icarus, PL2303_VENDOR_OUT, PL2303_REQUEST_VENDOR, PL2303_VALUE_VENDOR, transfer(icarus, PL2303_VENDOR_OUT, PL2303_REQUEST_VENDOR, PL2303_VALUE_VENDOR,
icarus->usbdev->found->interface, C_VENDOR); interface, C_VENDOR);
icarus->usbdev->PrefPacketSize = ICA_PREF_PACKET;
break; break;
case IDENT_AMU: case IDENT_AMU:
usb_set_pps(icarus, AMU_PREF_PACKET);
// Enable the UART // Enable the UART
transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_IFC_ENABLE, transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_IFC_ENABLE,
CP210X_VALUE_UART_ENABLE, CP210X_VALUE_UART_ENABLE,
icarus->usbdev->found->interface, C_ENABLE_UART); interface, C_ENABLE_UART);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
// Set data control // Set data control
transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_DATA, CP210X_VALUE_DATA, transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_DATA, CP210X_VALUE_DATA,
icarus->usbdev->found->interface, C_SETDATA); interface, C_SETDATA);
if (icarus->usbinfo.nodev) if (icarus->usbinfo.nodev)
return; return;
@ -381,15 +385,11 @@ static void icarus_initialise(struct cgpu_info *icarus, int baud)
// Set the baud // Set the baud
uint32_t data = CP210X_DATA_BAUD; uint32_t data = CP210X_DATA_BAUD;
_transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_BAUD, 0, _transfer(icarus, CP210X_TYPE_OUT, CP210X_REQUEST_BAUD, 0,
icarus->usbdev->found->interface, interface, &data, sizeof(data), C_SETBAUD);
&data, sizeof(data), C_SETBAUD);
icarus->usbdev->PrefPacketSize = AMU_PREF_PACKET;
break; break;
default: default:
quit(1, "icarus_intialise() called with invalid %s cgid %i ident=%d", quit(1, "icarus_intialise() called with invalid %s cgid %i ident=%d",
icarus->drv->name, icarus->cgminer_id, icarus->drv->name, icarus->cgminer_id, ident);
icarus->usbdev->ident);
} }
} }
@ -483,6 +483,7 @@ static const char *timing_mode_str(enum timing_mode timing_mode)
static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus) static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
{ {
struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data); struct ICARUS_INFO *info = (struct ICARUS_INFO *)(icarus->device_data);
enum sub_ident ident;
double Hs; double Hs;
char buf[BUFSIZ+1]; char buf[BUFSIZ+1];
char *ptr, *comma, *eq; char *ptr, *comma, *eq;
@ -512,7 +513,8 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
buf[max] = '\0'; buf[max] = '\0';
} }
switch (icarus->usbdev->ident) { ident = usb_ident(icarus);
switch (ident) {
case IDENT_ICA: case IDENT_ICA:
info->Hs = ICARUS_REV3_HASH_TIME; info->Hs = ICARUS_REV3_HASH_TIME;
break; break;
@ -530,7 +532,7 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus)
break; break;
default: default:
quit(1, "Icarus get_options() called with invalid %s ident=%d", quit(1, "Icarus get_options() called with invalid %s ident=%d",
icarus->drv->name, icarus->usbdev->ident); icarus->drv->name, ident);
} }
info->read_time = 0; info->read_time = 0;
@ -616,6 +618,7 @@ static void get_options(int this_option_offset, struct cgpu_info *icarus, int *b
{ {
char buf[BUFSIZ+1]; char buf[BUFSIZ+1];
char *ptr, *comma, *colon, *colon2; char *ptr, *comma, *colon, *colon2;
enum sub_ident ident;
size_t max; size_t max;
int i, tmp; int i, tmp;
@ -642,7 +645,8 @@ static void get_options(int this_option_offset, struct cgpu_info *icarus, int *b
buf[max] = '\0'; buf[max] = '\0';
} }
switch (icarus->usbdev->ident) { ident = usb_ident(icarus);
switch (ident) {
case IDENT_ICA: case IDENT_ICA:
case IDENT_BLT: case IDENT_BLT:
case IDENT_LLT: case IDENT_LLT:
@ -664,7 +668,7 @@ static void get_options(int this_option_offset, struct cgpu_info *icarus, int *b
break; break;
default: default:
quit(1, "Icarus get_options() called with invalid %s ident=%d", quit(1, "Icarus get_options() called with invalid %s ident=%d",
icarus->drv->name, icarus->usbdev->ident); icarus->drv->name, ident);
} }
if (*buf) { if (*buf) {

47
usbutils.c

@ -2944,6 +2944,53 @@ void usb_disable_cps(struct cgpu_info *cgpu)
DEVUNLOCK(cgpu, pstate); DEVUNLOCK(cgpu, pstate);
} }
/*
* The value returned (0) when usbdev is NULL
* doesn't matter since it also means the next call to
* any usbutils function will fail with a nodev
*/
int usb_interface(struct cgpu_info *cgpu)
{
int interface = 0;
int pstate;
DEVLOCK(cgpu, pstate);
if (cgpu->usbdev)
interface = cgpu->usbdev->found->interface;
DEVUNLOCK(cgpu, pstate);
return interface;
}
enum sub_ident usb_ident(struct cgpu_info *cgpu)
{
enum sub_ident ident = IDENT_UNK;
int pstate;
DEVLOCK(cgpu, pstate);
if (cgpu->usbdev)
ident = cgpu->usbdev->ident;
DEVUNLOCK(cgpu, pstate);
return ident;
}
void usb_set_pps(struct cgpu_info *cgpu, uint16_t PrefPacketSize)
{
int pstate;
DEVLOCK(cgpu, pstate);
if (cgpu->usbdev)
cgpu->usbdev->PrefPacketSize = PrefPacketSize;
DEVUNLOCK(cgpu, pstate);
}
// Need to set all devices with matching usbdev // Need to set all devices with matching usbdev
void usb_set_dev_start(struct cgpu_info *cgpu) void usb_set_dev_start(struct cgpu_info *cgpu)
{ {

3
usbutils.h

@ -309,6 +309,9 @@ 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);
void usb_enable_cps(struct cgpu_info *cgpu); void usb_enable_cps(struct cgpu_info *cgpu);
void usb_disable_cps(struct cgpu_info *cgpu); void usb_disable_cps(struct cgpu_info *cgpu);
int usb_interface(struct cgpu_info *cgpu);
enum sub_ident usb_ident(struct cgpu_info *cgpu);
void usb_set_pps(struct cgpu_info *cgpu, uint16_t PrefPacketSize);
void usb_set_dev_start(struct cgpu_info *cgpu); void usb_set_dev_start(struct cgpu_info *cgpu);
void usb_cleanup(); void usb_cleanup();
void usb_initialise(); void usb_initialise();

Loading…
Cancel
Save