Example #1
0
static void hashratio_update_work(struct cgpu_info *hashratio)
{
	struct hashratio_info *info = hashratio->device_data;
	struct thr_info *thr = hashratio->thr[0];
	struct hashratio_pkg send_pkg;
	uint32_t tmp, range, start;
	struct work *work;
	struct pool *pool;

	applog(LOG_DEBUG, "hashratio: New stratum: restart: %d, update: %d",
		thr->work_restart, thr->work_update);
	thr->work_update = false;
	thr->work_restart = false;

	work = get_work(thr, thr->id); /* Make sure pool is ready */
	discard_work(work); /* Don't leak memory */

	pool = current_pool();
	if (!pool->has_stratum)
		quit(1, "hashratio: Miner Manager have to use stratum pool");
	if (pool->coinbase_len > HRTO_P_COINBASE_SIZE)
		quit(1, "hashratio: Miner Manager pool coinbase length have to less then %d", HRTO_P_COINBASE_SIZE);
	if (pool->merkles > HRTO_P_MERKLES_COUNT)
		quit(1, "hashratio: Miner Manager merkles have to less then %d", HRTO_P_MERKLES_COUNT);

	info->pool_no = pool->pool_no;

	cgtime(&info->last_stratum);
	cg_rlock(&pool->data_lock);
	info->pool_no = pool->pool_no;
	copy_pool_stratum(info, pool);
	hashratio_stratum_pkgs(hashratio, pool);
	cg_runlock(&pool->data_lock);

	/* Configure the parameter from outside */
	memset(send_pkg.data, 0, HRTO_P_DATA_LEN);

	// fan. We're not measuring temperature so set a safe but not max value
	info->fan_pwm = HRTO_PWM_MAX * 2 / 3;
	tmp = be32toh(info->fan_pwm);
	memcpy(send_pkg.data, &tmp, 4);

	// freq
	tmp = be32toh(info->default_freq);
	memcpy(send_pkg.data + 4, &tmp, 4);
	applog(LOG_DEBUG, "set freq: %d", info->default_freq);

	/* Configure the nonce2 offset and range */
	range = 0xffffffff / (total_devices + 1);
	start = range * (hashratio->device_id + 1);

	tmp = be32toh(start);
	memcpy(send_pkg.data + 8, &tmp, 4);

	tmp = be32toh(range);
	memcpy(send_pkg.data + 12, &tmp, 4);

	/* Package the data */
	hashratio_init_pkg(&send_pkg, HRTO_P_SET, 1, 1);
	hashratio_send_pkgs(hashratio, &send_pkg);
}
Example #2
0
static int64_t hashratio_scanhash(struct thr_info *thr)
{
	struct hashratio_pkg send_pkg;

	struct pool *pool;
	struct cgpu_info *hashratio = thr->cgpu;
	struct hashratio_info *info = hashratio->device_data;
	struct hashratio_ret ret_pkg;
	
	uint32_t tmp, range, start;
	int i;
	
	if (thr->work_restart || thr->work_update || info->first) {
		info->new_stratum = true;
		applog(LOG_DEBUG, "hashratio: New stratum: restart: %d, update: %d, first: %d",
		       thr->work_restart, thr->work_update, info->first);
		thr->work_update = false;
		thr->work_restart = false;
		if (unlikely(info->first))
			info->first = false;

		get_work(thr, thr->id); /* Make sure pool is ready */

		pool = current_pool();
		if (!pool->has_stratum)
			quit(1, "hashratio: Miner Manager have to use stratum pool");
		if (pool->coinbase_len > HRTO_P_COINBASE_SIZE)
			quit(1, "hashratio: Miner Manager pool coinbase length have to less then %d", HRTO_P_COINBASE_SIZE);
		if (pool->merkles > HRTO_P_MERKLES_COUNT)
			quit(1, "hashratio: Miner Manager merkles have to less then %d", HRTO_P_MERKLES_COUNT);

		info->diff = (int)pool->swork.diff - 1;
		info->pool_no = pool->pool_no;

		cg_wlock(&pool->data_lock);
		hashratio_stratum_pkgs(info->fd, pool, thr);
		cg_wunlock(&pool->data_lock);
		
		/* Configuer the parameter from outside */
		memset(send_pkg.data, 0, HRTO_P_DATA_LEN);
		
		// fan
		info->fan_pwm = HRTO_PWM_MAX;
		tmp = be32toh(info->fan_pwm);
		memcpy(send_pkg.data, &tmp, 4);

		// freq
		tmp = be32toh(info->default_freq);
		memcpy(send_pkg.data + 4, &tmp, 4);
		applog(LOG_DEBUG, "set freq: %d", info->default_freq);
		
		/* Configure the nonce2 offset and range */
		range = 0xffffffff / total_devices;
		start = range * hashratio->device_id;

		tmp = be32toh(start);
		memcpy(send_pkg.data + 8, &tmp, 4);

		tmp = be32toh(range);
		memcpy(send_pkg.data + 12, &tmp, 4);

		/* Package the data */
		hashratio_init_pkg(&send_pkg, HRTO_P_SET, 1, 1);
		while (hashratio_send_pkg(info->fd, &send_pkg, thr) != HRTO_SEND_OK)
			;
		
		info->new_stratum = false;
	}

	polling(thr);
	
	return (int64_t)info->local_work * 64 * 0xffffffff;
}