Remove requirement for ifndefs for avalon2 from the generic driver work function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
diff --git a/cgminer.c b/cgminer.c
index 53577f3..734dacc 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -7819,17 +7819,13 @@ void hash_driver_work(struct thr_info *mythr)
struct timeval diff;
int64_t hashes;
-#ifndef USE_AVALON2
mythr->work_update = false;
-#endif
hashes = drv->scanwork(mythr);
-#ifndef USE_AVALON2
/* Reset the bool here in case the driver looks for it
* synchronously in the scanwork loop. */
mythr->work_restart = false;
-#endif
if (unlikely(hashes == -1 )) {
applog(LOG_ERR, "%s %d failure, disabling!", drv->name, cgpu->device_id);
diff --git a/driver-avalon2.c b/driver-avalon2.c
index 4d15cf4..d2724a8 100644
--- a/driver-avalon2.c
+++ b/driver-avalon2.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Con Kolivas <kernel@kolivas.org>
+ * Copyright 2013-2014 Con Kolivas <kernel@kolivas.org>
* Copyright 2012-2014 Xiangfu <xiangfu@openmobilefree.com>
* Copyright 2012 Luke Dashjr
* Copyright 2012 Andrew Smith
@@ -242,7 +242,6 @@ static inline int mm_cmp_1404(struct avalon2_info *info, int modular)
return strncmp(info->mm_version[modular] + 2, mm_1404, 4) > 0 ? 0 : 1;
}
-extern void submit_nonce2_nonce(struct thr_info *thr, struct pool *pool, struct pool *real_pool, uint32_t nonce2, uint32_t nonce);
static int decode_pkg(struct thr_info *thr, struct avalon2_ret *ar, uint8_t *pkg)
{
struct cgpu_info *avalon2;
@@ -813,86 +812,88 @@ static void copy_pool_stratum(struct pool *pool)
cg_wunlock(&(pool_stratum.data_lock));
}
-static int64_t avalon2_scanhash(struct thr_info *thr)
+static void avalon2_update(struct cgpu_info *avalon2)
{
+ struct avalon2_info *info = avalon2->device_data;
+ struct thr_info *thr = avalon2->thr[0];
struct avalon2_pkg send_pkg;
- struct timeval current_stratum;
-
+ uint32_t tmp, range, start;
struct pool *pool;
- struct cgpu_info *avalon2 = thr->cgpu;
- struct avalon2_info *info = avalon2->device_data;
- int64_t h;
- uint32_t tmp, range, start;
- int i;
+ applog(LOG_DEBUG, "Avalon2: New stratum: restart: %d, update: %d, first: %d",
+ thr->work_restart, thr->work_update, info->first);
+ thr->work_update = false;
+ thr->work_restart = false;
+ get_work(thr, thr->id); /* Make sure pool is ready */
+
+ pool = current_pool();
+ if (!pool->has_stratum)
+ quit(1, "Avalon2: Miner Manager have to use stratum pool");
+ if (pool->coinbase_len > AVA2_P_COINBASE_SIZE) {
+ applog(LOG_ERR, "Avalon2: Miner Manager pool coinbase length have to less then %d", AVA2_P_COINBASE_SIZE);
+ return;
+ }
+ if (pool->merkles > AVA2_P_MERKLES_COUNT) {
+ applog(LOG_ERR, "Avalon2: Miner Manager merkles have to less then %d", AVA2_P_MERKLES_COUNT);
+ return;
+ }
- if (thr->work_restart || thr->work_update || !info->first) {
- applog(LOG_DEBUG, "Avalon2: New stratum: restart: %d, update: %d, first: %d",
- thr->work_restart, thr->work_update, info->first);
- thr->work_update = false;
- thr->work_restart = false;
- get_work(thr, thr->id); /* Make sure pool is ready */
-
- pool = current_pool();
- if (!pool->has_stratum)
- quit(1, "Avalon2: Miner Manager have to use stratum pool");
- if (pool->coinbase_len > AVA2_P_COINBASE_SIZE) {
- applog(LOG_ERR, "Avalon2: Miner Manager pool coinbase length have to less then %d", AVA2_P_COINBASE_SIZE);
- return 0;
- }
- if (pool->merkles > AVA2_P_MERKLES_COUNT) {
- applog(LOG_ERR, "Avalon2: Miner Manager merkles have to less then %d", AVA2_P_MERKLES_COUNT);
- return 0;
- }
+ cgtime(&info->last_stratum);
+ cg_rlock(&pool->data_lock);
+ info->pool_no = pool->pool_no;
+ copy_pool_stratum(pool);
+ avalon2_stratum_pkgs(info->fd, pool, thr);
+ cg_runlock(&pool->data_lock);
+
+ /* Configuer the parameter from outside */
+ adjust_fan(info);
+ info->set_voltage = opt_avalon2_voltage_min;
+ info->set_frequency = opt_avalon2_freq_min;
+
+ /* Set the Fan, Voltage and Frequency */
+ memset(send_pkg.data, 0, AVA2_P_DATA_LEN);
+
+ tmp = be32toh(info->fan_pwm);
+ memcpy(send_pkg.data, &tmp, 4);
+
+ applog(LOG_ERR, "Avalon2: Temp max: %d, Cut off temp: %d",
+ get_current_temp_max(info), opt_avalon2_overheat);
+ if (get_current_temp_max(info) >= opt_avalon2_overheat)
+ tmp = encode_voltage(0);
+ else
+ tmp = encode_voltage(info->set_voltage);
+ tmp = be32toh(tmp);
+ memcpy(send_pkg.data + 4, &tmp, 4);
+
+ tmp = be32toh(info->set_frequency);
+ memcpy(send_pkg.data + 8, &tmp, 4);
+
+ /* Configure the nonce2 offset and range */
+ range = 0xffffffff / total_devices;
+ start = range * avalon2->device_id;
+
+ tmp = be32toh(start);
+ memcpy(send_pkg.data + 12, &tmp, 4);
+
+ tmp = be32toh(range);
+ memcpy(send_pkg.data + 16, &tmp, 4);
+
+ /* Package the data */
+ avalon2_init_pkg(&send_pkg, AVA2_P_SET, 1, 1);
+ while (avalon2_send_pkg(info->fd, &send_pkg, thr) != AVA2_SEND_OK)
+ ;
- cgtime(&info->last_stratum);
- cg_rlock(&pool->data_lock);
- info->pool_no = pool->pool_no;
- copy_pool_stratum(pool);
- avalon2_stratum_pkgs(info->fd, pool, thr);
- cg_runlock(&pool->data_lock);
-
- /* Configuer the parameter from outside */
- adjust_fan(info);
- info->set_voltage = opt_avalon2_voltage_min;
- info->set_frequency = opt_avalon2_freq_min;
-
- /* Set the Fan, Voltage and Frequency */
- memset(send_pkg.data, 0, AVA2_P_DATA_LEN);
-
- tmp = be32toh(info->fan_pwm);
- memcpy(send_pkg.data, &tmp, 4);
-
- applog(LOG_ERR, "Avalon2: Temp max: %d, Cut off temp: %d",
- get_current_temp_max(info), opt_avalon2_overheat);
- if (get_current_temp_max(info) >= opt_avalon2_overheat)
- tmp = encode_voltage(0);
- else
- tmp = encode_voltage(info->set_voltage);
- tmp = be32toh(tmp);
- memcpy(send_pkg.data + 4, &tmp, 4);
-
- tmp = be32toh(info->set_frequency);
- memcpy(send_pkg.data + 8, &tmp, 4);
-
- /* Configure the nonce2 offset and range */
- range = 0xffffffff / total_devices;
- start = range * avalon2->device_id;
-
- tmp = be32toh(start);
- memcpy(send_pkg.data + 12, &tmp, 4);
-
- tmp = be32toh(range);
- memcpy(send_pkg.data + 16, &tmp, 4);
-
- /* Package the data */
- avalon2_init_pkg(&send_pkg, AVA2_P_SET, 1, 1);
- while (avalon2_send_pkg(info->fd, &send_pkg, thr) != AVA2_SEND_OK)
- ;
+ if (unlikely(info->first < 2))
+ info->first++;
+}
- if (unlikely(info->first < 2))
- info->first++;
- }
+static int64_t avalon2_scanhash(struct thr_info *thr)
+{
+ struct timeval current_stratum;
+ struct cgpu_info *avalon2 = thr->cgpu;
+ struct avalon2_info *info = avalon2->device_data;
+ int64_t h;
+ int i;
/* Stop polling the device if there is no stratum in 3 minutes, network is down */
cgtime(¤t_stratum);
@@ -1059,6 +1060,8 @@ struct device_drv avalon2_drv = {
.reinit_device = avalon2_init,
.thread_prepare = avalon2_prepare,
.hash_work = hash_driver_work,
+ .flush_work = avalon2_update,
+ .update_work = avalon2_update,
.scanwork = avalon2_scanhash,
.thread_shutdown = avalon2_shutdown,
};