static bool get_options(int this_option_offset, struct cgpu_info *gridseed, char *options, int *baud, int *freq, int *chips, int *modules, int *usefifo, int *btcore) { unsigned char *ss, *p, *end, *comma, *colon; int tmp; if (options == NULL) return false; applog(LOG_NOTICE, "GridSeed options: '%s'", options); ss = strdup(options); p = ss; end = p + strlen(p); another: comma = strchr(p, ','); if (comma != NULL) *comma = '\0'; colon = strchr(p, '='); if (colon == NULL) goto next; *colon = '\0'; tmp = atoi(colon+1); if (strcasecmp(p, "baud")==0) { *baud = (tmp != 0) ? tmp : *baud; } else if (strcasecmp(p, "freq")==0) { *freq = gc3355_find_freq_index(colon+1); } else if (strcasecmp(p, "chips")==0) { *chips = (tmp != 0) ? tmp : *chips; } else if (strcasecmp(p, "modules")==0) { *modules = (tmp != 0) ? tmp : *modules; } else if (strcasecmp(p, "usefifo")==0) { *usefifo = tmp; } else if (strcasecmp(p, "btc")==0) { *btcore = tmp; } next: if (comma != NULL) { p = comma + 1; if (p < end) goto another; } free(ss); return true; }
static bool get_freq(GRIDSEED_INFO *info, char *options) { char *ss, *p, *end, *comma, *colon; int tmp; if (options == NULL) return false; applog(LOG_NOTICE, "GridSeed freq options: '%s'", options); ss = strdup(options); p = ss; end = p + strlen(p); another: comma = strchr(p, ','); if (comma != NULL) *comma = '\0'; colon = strchr(p, '='); if (colon == NULL) goto next; *colon = '\0'; tmp = atoi(colon+1); if (strcasecmp(p, info->serial)==0) { applog(LOG_NOTICE, "%s unique frequency: %i", p, tmp); int i; for(i=0; opt_frequency[i] != -1; i++) { if (tmp == opt_frequency[i]) info->freq = tmp; } } next: if (comma != NULL) { p = comma + 1; if (p < end) goto another; } free(ss); int freq_idx = gc3355_find_freq_index(info->freq); info->freq = opt_frequency[freq_idx]; memcpy(info->freq_cmd, bin_frequency[freq_idx], 8); return true; }
static bool gridseed_detect_one(libusb_device *dev, struct usb_find_devices *found) { struct cgpu_info *gridseed; GRIDSEED_INFO *info; int err, wrote, def_freq_inx; unsigned char rbuf[GRIDSEED_READ_SIZE]; #if 0 const char detect_cmd[] = "55aa0f01" "4a548fe471fa3a9a1371144556c3f64d" "2500b4826008fe4bbf7698c94eba7946" "ce22a72f4f6726141a0b3287eeeeeeee"; unsigned char detect_data[52]; #else const char detect_cmd[] = "55aac000909090900000000001000000"; unsigned char detect_data[16]; #endif gridseed = usb_alloc_cgpu(&gridseed_drv, GRIDSEED_MINER_THREADS); if (!usb_init(gridseed, dev, found)) goto shin; libusb_reset_device(gridseed->usbdev->handle); info = (GRIDSEED_INFO*)calloc(sizeof(GRIDSEED_INFO), 1); if (unlikely(!info)) quit(1, "Failed to calloc gridseed_info data"); gridseed->device_data = (void *)info; info->baud = GRIDSEED_DEFAULT_BAUD; info->freq = GRIDSEED_DEFAULT_FREQUENCY; def_freq_inx = gc3355_find_freq_index(GRIDSEED_DEFAULT_FREQUENCY); memcpy(info->freq_cmd, bin_frequency[def_freq_inx], 8); info->chips = GRIDSEED_DEFAULT_CHIPS; info->voltage = 0; info->per_chip_stats = 0; info->serial = strdup(gridseed->usbdev->serial_string); memset(info->nonce_count, 0, sizeof(info->nonce_count)); memset(info->error_count, 0, sizeof(info->error_count)); get_options(info, opt_gridseed_options); get_freq(info, opt_gridseed_freq); get_chips(info, opt_gridseed_chips); update_usb_stats(gridseed); gridseed->usbdev->usb_type = USB_TYPE_STD; gridseed_initialise(gridseed, info); /* get MCU firmware version */ hex2bin(detect_data, detect_cmd, sizeof(detect_data)); if (gc3355_write_data(gridseed, detect_data, sizeof(detect_data))) { applog(LOG_DEBUG, "Failed to write work data to %i, err %d", gridseed->device_id, err); goto unshin; } /* waiting for return */ if (gc3355_get_data(gridseed, rbuf, GRIDSEED_READ_SIZE)) { applog(LOG_DEBUG, "No response from %i", gridseed->device_id); goto unshin; } if (memcmp(rbuf, "\x55\xaa\xc0\x00\x90\x90\x90\x90", GRIDSEED_READ_SIZE-4) != 0) { applog(LOG_DEBUG, "Bad response from %i", gridseed->device_id); goto unshin; } info->fw_version = le32toh(*(uint32_t *)(rbuf+8)); applog(LOG_NOTICE, "Device found, firmware version %08X, driver version %s", info->fw_version, gridseed_version); gc3355_init(gridseed, info); gridseed->algorithm = default_algorithm; if (!add_cgpu(gridseed)) goto unshin; return true; unshin: usb_uninit(gridseed); free(gridseed->device_data); gridseed->device_data = NULL; shin: gridseed = usb_free_cgpu(gridseed); return false; }
static bool get_options(GRIDSEED_INFO *info, char *options) { char *ss, *p, *end, *comma, *colon; int tmp, pll_r = 0, pll_f = 0, pll_od = 0; if (options == NULL) return false; applog(LOG_NOTICE, "GridSeed options: '%s'", options); ss = strdup(options); p = ss; end = p + strlen(p); another: comma = strchr(p, ','); if (comma != NULL) *comma = '\0'; colon = strchr(p, '='); if (colon == NULL) goto next; *colon = '\0'; tmp = atoi(colon+1); if (strcasecmp(p, "baud")==0) { info->baud = (tmp != 0) ? tmp : info->baud; } else if (strcasecmp(p, "freq")==0) { int i; for(i=0; opt_frequency[i] != -1; i++) { if (tmp == opt_frequency[i]) info->freq = tmp; } } else if (strcasecmp(p, "pll_r")==0) { pll_r = (tmp != 0) ? tmp : pll_r; pll_r = MAX(0, MIN(31, pll_r)); } else if (strcasecmp(p, "pll_f")==0) { pll_f = (tmp != 0) ? tmp : pll_f; pll_f = MAX(0, MIN(127, pll_f)); } else if (strcasecmp(p, "pll_od")==0) { pll_od = (tmp != 0) ? tmp : pll_od; pll_od = MAX(0, MIN(4, pll_od)); } else if (strcasecmp(p, "chips")==0) { info->chips = (tmp != 0) ? tmp : info->chips; info->chips = MAX(0, MIN(GRIDSEED_MAX_CHIPS, info->chips)); } else if (strcasecmp(p, "voltage")==0) { info->voltage = (tmp != 0) ? tmp : info->voltage; } else if (strcasecmp(p, "per_chip_stats")==0) { info->per_chip_stats = (tmp != 0) ? tmp : info->per_chip_stats; } next: if (comma != NULL) { p = comma + 1; if (p < end) goto another; } free(ss); if (pll_r != 0 || pll_f != 0 || pll_od != 0) { int f_ref = GRIDSEED_F_IN / (pll_r + 1); int f_vco = f_ref * (pll_f + 1); int f_out = f_vco / (1 << pll_od); int pll_bs = (f_out >= 500) ? 1 : 0; int cfg_pm = 1, pll_clk_gate = 1; uint32_t cmd = (cfg_pm << 0) | (pll_clk_gate << 2) | (pll_r << 16) | (pll_f << 21) | (pll_od << 28) | (pll_bs << 31); info->freq = f_out; memcpy(info->freq_cmd, "\x55\xaa\xef\x00", 4); *(uint32_t *)(info->freq_cmd + 4) = htole32(cmd); } else { int freq_idx = gc3355_find_freq_index(info->freq); info->freq = opt_frequency[freq_idx]; memcpy(info->freq_cmd, bin_frequency[freq_idx], 8); } return true; }
static struct cgpu_info *gridseed_detect_one(libusb_device *dev, struct usb_find_devices *found) { struct cgpu_info *gridseed; GRIDSEED_INFO *info; int this_option_offset; int baud, freq, chips, modules, usefifo, btcore; int err, wrote; bool configured; unsigned char rbuf[GRIDSEED_READ_SIZE]; unsigned char *p; #if 0 const char detect_cmd[] = "55aa0f01" "4a548fe471fa3a9a1371144556c3f64d" "2500b4826008fe4bbf7698c94eba7946" "ce22a72f4f6726141a0b3287eeeeeeee"; unsigned char detect_data[52]; #else const char detect_cmd[] = "55aac000909090900000000001000000"; unsigned char detect_data[16]; #endif gridseed = usb_alloc_cgpu(&gridseed_drv, GRIDSEED_MINER_THREADS); if (!usb_init(gridseed, dev, found)) goto shin; libusb_reset_device(gridseed->usbdev->handle); baud = GRIDSEED_DEFAULT_BAUD; chips = GRIDSEED_DEFAULT_CHIPS; modules = GRIDSEED_DEFAULT_MODULES; freq = gc3355_find_freq_index(GRIDSEED_DEFAULT_FREQUENCY); usefifo = GRIDSEED_DEFAULT_USEFIFO; btcore = GRIDSEED_DEFAULT_BTCORE; this_option_offset = 0; configured = get_options(this_option_offset, gridseed, opt_gridseed_options, &baud, &freq, &chips, &modules, &usefifo, &btcore); info = (GRIDSEED_INFO*)calloc(sizeof(GRIDSEED_INFO), 1); if (unlikely(!info)) quit(1, "Failed to calloc gridseed_info data"); gridseed->device_data = (void *)info; update_usb_stats(gridseed); //if (configured) { info->baud = baud; info->freq = freq; info->chips = chips; info->modules = modules; info->usefifo = usefifo; info->btcore = btcore; //} gridseed->usbdev->usb_type = USB_TYPE_STD; gridseed_initialise(gridseed, info); /* send testing work to chips */ hex2bin(detect_data, detect_cmd, sizeof(detect_data)); if (gc3355_write_data(gridseed, detect_data, sizeof(detect_data))) { applog(LOG_DEBUG, "Failed to write work data to %i, err %d", gridseed->device_id, err); goto unshin; } /* waiting for return */ if (gc3355_get_data(gridseed, rbuf, GRIDSEED_READ_SIZE)) { applog(LOG_DEBUG, "No response from %i", gridseed->device_id); goto unshin; } if (memcmp(rbuf, "\x55\xaa\xc0\x00\x90\x90\x90\x90", GRIDSEED_READ_SIZE-4) != 0) { applog(LOG_DEBUG, "Bad response from %i", gridseed->device_id); goto unshin; } p = bin2hex(rbuf+GRIDSEED_READ_SIZE-4, 4); applog(LOG_NOTICE, "Device found, firmware version 0x%s, driver version %s", p, gridseed_version); free(p); if (!add_cgpu(gridseed)) goto unshin; return gridseed; unshin: usb_uninit(gridseed); free(gridseed->device_data); gridseed->device_data = NULL; shin: gridseed = usb_free_cgpu(gridseed); return NULL; }