static bool hfa_get_packet(struct cgpu_info *hashfast, struct hf_header *h) { uint8_t hcrc; bool ret; if (unlikely(hashfast->usbinfo.nodev)) return false; ret = hfa_get_header(hashfast, h, &hcrc); if (unlikely(!ret)) goto out; if (unlikely(h->crc8 != hcrc)) { applog(LOG_WARNING, "HFA %d: Bad CRC %d vs %d, discarding packet", hashfast->device_id, h->crc8, hcrc); ret = false; goto out; } if (h->data_length > 0) ret = hfa_get_data(hashfast, (char *)(h + 1), h->data_length); if (unlikely(!ret)) { applog(LOG_WARNING, "HFA %d: Failed to get data associated with header", hashfast->device_id); } out: return ret; }
static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info) { struct hf_usb_init_header usb_init[2], *hu = usb_init; struct hf_usb_init_base *db; struct hf_usb_init_options *ho; int retries = 0, i; char buf[1024]; struct hf_header *h = (struct hf_header *)buf; uint8_t hcrc; bool ret; /* Hash clock rate in Mhz */ info->hash_clock_rate = opt_hfa_hash_clock ? opt_hfa_hash_clock : 550; info->group_ntime_roll = opt_hfa_ntime_roll ? opt_hfa_ntime_roll : 1; info->core_ntime_roll = 1; // Assemble the USB_INIT request memset(hu, 0, sizeof(*hu)); hu->preamble = HF_PREAMBLE; hu->operation_code = OP_USB_INIT; hu->protocol = PROTOCOL_GLOBAL_WORK_QUEUE; // Protocol to use // Force PLL bypass hu->pll_bypass = opt_hfa_pll_bypass; hu->hash_clock = info->hash_clock_rate; // Hash clock rate in Mhz if (info->group_ntime_roll > 1 && info->core_ntime_roll) { ho = (struct hf_usb_init_options *)(hu + 1); memset(ho, 0, sizeof(*ho)); ho->group_ntime_roll = info->group_ntime_roll; ho->core_ntime_roll = info->core_ntime_roll; hu->data_length = sizeof(*ho) / 4; } hu->crc8 = hfa_crc8((uint8_t *)hu); applog(LOG_INFO, "HFA%d: Sending OP_USB_INIT with GWQ protocol specified", hashfast->device_id); if (!hfa_send_packet(hashfast, (struct hf_header *)hu, HF_USB_CMD(OP_USB_INIT))) return false; // Check for the correct response. // We extend the normal timeout - a complete device initialization, including // bringing power supplies up from standby, etc., can take over a second. tryagain: for (i = 0; i < 30; i++) { ret = hfa_get_header(hashfast, h, &hcrc); if (ret) break; } if (!ret) { applog(LOG_WARNING, "HFA %d: OP_USB_INIT failed!", hashfast->device_id); return false; } if (h->crc8 != hcrc) { applog(LOG_WARNING, "HFA %d: OP_USB_INIT failed! CRC mismatch", hashfast->device_id); return false; } if (h->operation_code != OP_USB_INIT) { // This can happen if valid packet(s) were in transit *before* the OP_USB_INIT arrived // at the device, so we just toss the packets and keep looking for the response. applog(LOG_WARNING, "HFA %d: OP_USB_INIT: Tossing packet, valid but unexpected type %d", hashfast->device_id, h->operation_code); hfa_get_data(hashfast, buf, h->data_length); if (retries++ < 3) goto tryagain; return false; } applog(LOG_DEBUG, "HFA %d: Good reply to OP_USB_INIT", hashfast->device_id); applog(LOG_DEBUG, "HFA %d: OP_USB_INIT: %d die in chain, %d cores, device_type %d, refclk %d Mhz", hashfast->device_id, h->chip_address, h->core_address, h->hdata & 0xff, (h->hdata >> 8) & 0xff); // Save device configuration info->asic_count = h->chip_address; info->core_count = h->core_address; info->device_type = (uint8_t)h->hdata; info->ref_frequency = (uint8_t)(h->hdata >> 8); info->hash_sequence_head = 0; info->hash_sequence_tail = 0; info->device_sequence_tail = 0; // Size in bytes of the core bitmap in bytes info->core_bitmap_size = (((info->asic_count * info->core_count) + 31) / 32) * 4; // Get the usb_init_base structure if (!hfa_get_data(hashfast, (char *)&info->usb_init_base, U32SIZE(info->usb_init_base))) { applog(LOG_WARNING, "HFA %d: OP_USB_INIT failed! Failure to get usb_init_base data", hashfast->device_id); return false; } db = &info->usb_init_base; applog(LOG_INFO, "HFA %d: firmware_rev: %d.%d", hashfast->device_id, (db->firmware_rev >> 8) & 0xff, db->firmware_rev & 0xff); applog(LOG_INFO, "HFA %d: hardware_rev: %d.%d", hashfast->device_id, (db->hardware_rev >> 8) & 0xff, db->hardware_rev & 0xff); applog(LOG_INFO, "HFA %d: serial number: %d", hashfast->device_id, db->serial_number); applog(LOG_INFO, "HFA %d: hash clockrate: %d Mhz", hashfast->device_id, db->hash_clockrate); applog(LOG_INFO, "HFA %d: inflight_target: %d", hashfast->device_id, db->inflight_target); applog(LOG_INFO, "HFA %d: sequence_modulus: %d", hashfast->device_id, db->sequence_modulus); info->num_sequence = db->sequence_modulus; // Now a copy of the config data used if (!hfa_get_data(hashfast, (char *)&info->config_data, U32SIZE(info->config_data))) { applog(LOG_WARNING, "HFA %d: OP_USB_INIT failed! Failure to get config_data", hashfast->device_id); return false; } // Now the core bitmap info->core_bitmap = malloc(info->core_bitmap_size); if (!info->core_bitmap) quit(1, "Failed to malloc info core bitmap in hfa_reset"); if (!hfa_get_data(hashfast, (char *)info->core_bitmap, info->core_bitmap_size / 4)) { applog(LOG_WARNING, "HFA %d: OP_USB_INIT failed! Failure to get core_bitmap", hashfast->device_id); return false; } // See if the initialization suceeded if (db->operation_status) { applog(LOG_WARNING, "HFA %d: OP_USB_INIT failed! Operation status %d (%s)", hashfast->device_id, db->operation_status, (db->operation_status < sizeof(hf_usb_init_errors)/sizeof(hf_usb_init_errors[0])) ? hf_usb_init_errors[db->operation_status] : "Unknown error code"); return false; } return true; }