static int64_t hfa_scanwork(struct thr_info *thr) { struct cgpu_info *hashfast = thr->cgpu; struct hashfast_info *info = hashfast->device_data; int64_t hashes; int jobs, ret; if (unlikely(hashfast->usbinfo.nodev)) { applog(LOG_WARNING, "HFA %d: device disappeared, disabling", hashfast->device_id); return -1; } if (unlikely(thr->work_restart)) { restart: thr->work_restart = false; ret = hfa_send_frame(hashfast, HF_USB_CMD(OP_WORK_RESTART), 0, (uint8_t *)NULL, 0); if (unlikely(!ret)) { ret = hfa_reset(hashfast, info); if (unlikely(!ret)) { applog(LOG_ERR, "HFA %d: Failed to reset after write failure, disabling", hashfast->device_id); return -1; } } } jobs = hfa_jobs(info); if (!jobs) { ret = restart_wait(thr, 100); if (unlikely(!ret)) goto restart; jobs = hfa_jobs(info); } if (jobs) { applog(LOG_DEBUG, "HFA %d: Sending %d new jobs", hashfast->device_id, jobs); } while (jobs-- > 0) { struct hf_hash_usb op_hash_data; struct work *work; uint64_t intdiff; int i, sequence; uint32_t *p; /* This is a blocking function if there's no work */ work = get_work(thr, thr->id); /* Assemble the data frame and send the OP_HASH packet */ memcpy(op_hash_data.midstate, work->midstate, sizeof(op_hash_data.midstate)); memcpy(op_hash_data.merkle_residual, work->data + 64, 4); p = (uint32_t *)(work->data + 64 + 4); op_hash_data.timestamp = *p++; op_hash_data.bits = *p++; op_hash_data.starting_nonce = 0; op_hash_data.nonce_loops = 0; op_hash_data.ntime_loops = 0; /* Set the number of leading zeroes to look for based on diff. * Diff 1 = 32, Diff 2 = 33, Diff 4 = 34 etc. */ intdiff = (uint64_t)work->device_diff; for (i = 31; intdiff; i++, intdiff >>= 1); op_hash_data.search_difficulty = i; op_hash_data.group = 0; if ((sequence = info->hash_sequence_head + 1) >= info->num_sequence) sequence = 0; ret = hfa_send_frame(hashfast, OP_HASH, sequence, (uint8_t *)&op_hash_data, sizeof(op_hash_data)); if (unlikely(!ret)) { ret = hfa_reset(hashfast, info); if (unlikely(!ret)) { applog(LOG_ERR, "HFA %d: Failed to reset after write failure, disabling", hashfast->device_id); return -1; } } mutex_lock(&info->lock); info->hash_sequence_head = sequence; info->works[info->hash_sequence_head] = work; mutex_unlock(&info->lock); applog(LOG_DEBUG, "HFA %d: OP_HASH sequence %d search_difficulty %d work_difficulty %g", hashfast->device_id, info->hash_sequence_head, op_hash_data.search_difficulty, work->work_difficulty); } mutex_lock(&info->lock); hashes = info->hash_count; info->hash_count = 0; mutex_unlock(&info->lock); return hashes; }
static int64_t hfa_scanwork(struct thr_info *thr) { struct cgpu_info *hashfast = thr->cgpu; struct hashfast_info *info = hashfast->device_data; int jobs, ret, cycles = 0; int64_t hashes; if (unlikely(hashfast->usbinfo.nodev)) { applog(LOG_WARNING, "%s %d: device disappeared, disabling", hashfast->drv->name, hashfast->device_id); return -1; } if (unlikely(last_getwork - hashfast->last_device_valid_work > 60)) { applog(LOG_WARNING, "%s %d: No valid hashes for over 1 minute, attempting to reset", hashfast->drv->name, hashfast->device_id); if (info->hash_clock_rate > HFA_CLOCK_DEFAULT) { info->hash_clock_rate -= 5; if (info->hash_clock_rate < opt_hfa_hash_clock) opt_hfa_hash_clock = info->hash_clock_rate; applog(LOG_WARNING, "%s %d: Decreasing clock speed to %d with reset", hashfast->drv->name, hashfast->device_id, info->hash_clock_rate); } ret = hfa_reset(hashfast, info); if (!ret) { applog(LOG_ERR, "%s %d: Failed to reset after hash failure, disabling", hashfast->drv->name, hashfast->device_id); return -1; } applog(LOG_NOTICE, "%s %d: Reset successful", hashfast->drv->name, hashfast->device_id); } if (unlikely(thr->work_restart)) { restart: info->last_restart = time(NULL); thr->work_restart = false; ret = hfa_send_frame(hashfast, HF_USB_CMD(OP_WORK_RESTART), 0, (uint8_t *)NULL, 0); if (unlikely(!ret)) { ret = hfa_reset(hashfast, info); if (unlikely(!ret)) { applog(LOG_ERR, "%s %d: Failed to reset after write failure, disabling", hashfast->drv->name, hashfast->device_id); return -1; } } /* Give a full allotment of jobs after a restart, not waiting * for the status update telling us how much to give. */ jobs = info->usb_init_base.inflight_target; } else { /* Only adjust die clocks if there's no restart since two * restarts back to back get ignored. */ hfa_temp_clock(hashfast, info); jobs = hfa_jobs(hashfast, info); } /* Wait on restart_wait for up to 0.5 seconds or submit jobs as soon as * they're required. */ while (!jobs && ++cycles < 5) { ret = restart_wait(thr, 100); if (unlikely(!ret)) goto restart; jobs = hfa_jobs(hashfast, info); } if (jobs) { applog(LOG_DEBUG, "%s %d: Sending %d new jobs", hashfast->drv->name, hashfast->device_id, jobs); } while (jobs-- > 0) { struct hf_hash_usb op_hash_data; struct work *work; uint64_t intdiff; int i, sequence; uint32_t *p; /* This is a blocking function if there's no work */ work = get_work(thr, thr->id); /* Assemble the data frame and send the OP_HASH packet */ memcpy(op_hash_data.midstate, work->midstate, sizeof(op_hash_data.midstate)); memcpy(op_hash_data.merkle_residual, work->data + 64, 4); p = (uint32_t *)(work->data + 64 + 4); op_hash_data.timestamp = *p++; op_hash_data.bits = *p++; op_hash_data.starting_nonce = 0; op_hash_data.nonce_loops = 0; op_hash_data.ntime_loops = 0; /* Set the number of leading zeroes to look for based on diff. * Diff 1 = 32, Diff 2 = 33, Diff 4 = 34 etc. */ intdiff = (uint64_t)work->device_diff; for (i = 31; intdiff; i++, intdiff >>= 1); op_hash_data.search_difficulty = i; op_hash_data.group = 0; if ((sequence = info->hash_sequence_head + 1) >= info->num_sequence) sequence = 0; ret = hfa_send_frame(hashfast, OP_HASH, sequence, (uint8_t *)&op_hash_data, sizeof(op_hash_data)); if (unlikely(!ret)) { ret = hfa_reset(hashfast, info); if (unlikely(!ret)) { applog(LOG_ERR, "%s %d: Failed to reset after write failure, disabling", hashfast->drv->name, hashfast->device_id); return -1; } } mutex_lock(&info->lock); info->hash_sequence_head = sequence; info->works[info->hash_sequence_head] = work; mutex_unlock(&info->lock); applog(LOG_DEBUG, "%s %d: OP_HASH sequence %d search_difficulty %d work_difficulty %g", hashfast->drv->name, hashfast->device_id, info->hash_sequence_head, op_hash_data.search_difficulty, work->work_difficulty); } /* Only count 2/3 of the hashes to smooth out the hashrate for cycles * that have no hashes added. */ mutex_lock(&info->lock); hashes = info->hash_count / 3 * 2; info->calc_hashes += hashes; info->hash_count -= hashes; mutex_unlock(&info->lock); return hashes; }