/ driver-avalon.h
driver-avalon.h
1 /* 2 * Copyright 2013 Avalon project 3 * Copyright 2013-2014 Con Kolivas <kernel@kolivas.org> 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License as published by the Free 7 * Software Foundation; either version 3 of the License, or (at your option) 8 * any later version. See COPYING for more details. 9 */ 10 11 #ifndef AVALON_H 12 #define AVALON_H 13 14 #ifdef USE_AVALON 15 16 #include "util.h" 17 18 #define AVALON_RESET_FAULT_DECISECONDS 1 19 #define AVALON_MINER_THREADS 1 20 21 #define AVALON_IO_SPEED 115200 22 #define AVALON_HASH_TIME_FACTOR ((float)1.67/0x32) 23 #define AVALON_RESET_PITCH (300*1000*1000) 24 25 26 #define AVALON_A3256 110 27 #define AVALON_A3255 55 28 29 #define AVALON_FAN_FACTOR 120 30 #define AVALON_PWM_MAX 0xA0 31 #define AVALON_DEFAULT_FAN_MIN 20 32 #define AVALON_DEFAULT_FAN_MAX 100 33 #define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */ 34 #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */ 35 36 #define AVALON_TEMP_TARGET 50 37 #define AVALON_TEMP_HYSTERESIS 3 38 #define AVALON_TEMP_OVERHEAT 60 39 40 /* Avalon-based BitBurner. */ 41 #define BITBURNER_DEFAULT_CORE_VOLTAGE 1200 /* in millivolts */ 42 #define BITBURNER_MIN_COREMV 1000 43 /* change here if you want to risk killing it :) */ 44 #define BITBURNER_MAX_COREMV 1400 45 46 /* BitFury-based BitBurner. */ 47 #define BITBURNER_FURY_DEFAULT_CORE_VOLTAGE 900 /* in millivolts */ 48 #define BITBURNER_FURY_MIN_COREMV 700 49 /* change here if you want to risk killing it :) */ 50 #define BITBURNER_FURY_MAX_COREMV 1100 51 52 53 #define AVALON_DEFAULT_TIMEOUT 0x2D 54 #define AVALON_MIN_FREQUENCY 256 55 #define AVALON_MAX_FREQUENCY 2000 56 #define AVALON_TIMEOUT_FACTOR 12690 57 #define AVALON_DEFAULT_FREQUENCY 282 58 #define AVALON_DEFAULT_MINER_NUM 0x20 59 #define AVALON_MAX_MINER_NUM 0x100 60 #define AVALON_DEFAULT_ASIC_NUM 0xA 61 62 /* Default number of miners for Bitburner Fury is for a stack of 8 boards, 63 but it will work acceptably for smaller stacks, too */ 64 #define BITBURNER_FURY_DEFAULT_MINER_NUM 128 65 #define BITBURNER_FURY_DEFAULT_FREQUENCY 256 66 #define BITBURNER_FURY_DEFAULT_TIMEOUT 50 67 68 #define AVALON_AUTO_CYCLE 1024 69 70 #define AVALON_FTDI_READSIZE 510 71 #define AVALON_READBUF_SIZE 8192 72 /* Set latency to just less than full 64 byte packet size at 115200 baud */ 73 #define AVALON_LATENCY 4 74 75 struct avalon_task { 76 uint8_t reset :1; 77 uint8_t flush_fifo :1; 78 uint8_t fan_eft :1; 79 uint8_t timer_eft :1; 80 uint8_t asic_num :4; 81 uint8_t fan_pwm_data; 82 uint8_t timeout_data; 83 uint8_t miner_num; 84 85 uint8_t nonce_elf :1; 86 uint8_t gate_miner_elf :1; 87 uint8_t asic_pll :1; 88 uint8_t gate_miner :1; 89 uint8_t _pad0 :4; 90 uint8_t _pad1[3]; 91 uint32_t _pad2; 92 93 uint8_t midstate[32]; 94 uint8_t data[12]; 95 } __attribute__((packed, aligned(4))); 96 97 struct avalon_result { 98 uint32_t nonce; 99 uint8_t data[12]; 100 uint8_t midstate[32]; 101 102 uint8_t fan0; 103 uint8_t fan1; 104 uint8_t fan2; 105 uint8_t temp0; 106 uint8_t temp1; 107 uint8_t temp2; 108 uint8_t _pad0[2]; 109 110 uint16_t fifo_wp; 111 uint16_t fifo_rp; 112 uint8_t chip_num; 113 uint8_t pwm_data; 114 uint8_t timeout; 115 uint8_t miner_num; 116 } __attribute__((packed, aligned(4))); 117 118 struct avalon_info { 119 int baud; 120 int miner_count; 121 int asic_count; 122 int timeout; 123 124 int fan0; 125 int fan1; 126 int fan2; 127 128 int temp0; 129 int temp1; 130 int temp2; 131 int temp_history_count; 132 int temp_history_index; 133 int temp_sum; 134 int temp_old; 135 int fan_pwm; 136 137 int core_voltage; 138 139 int no_matching_work; 140 int matching_work[AVALON_MAX_MINER_NUM]; 141 142 int frequency; 143 uint32_t asic; 144 uint32_t ctlr_ver; 145 146 struct thr_info *thr; 147 pthread_t read_thr; 148 pthread_t write_thr; 149 pthread_mutex_t lock; 150 pthread_mutex_t qlock; 151 cgsem_t qsem; 152 cgtimer_t cgsent; 153 int send_delay; 154 155 int nonces; 156 int auto_queued; 157 int auto_nonces; 158 int auto_hw; 159 int increment; 160 int decrement; 161 162 int idle; 163 bool reset; 164 bool overheat; 165 bool optimal; 166 167 uint8_t version1; 168 uint8_t version2; 169 uint8_t version3; 170 }; 171 172 #define BITBURNER_VERSION1 1 173 #define BITBURNER_VERSION2 0 174 #define BITBURNER_VERSION3 0 175 176 #define AVALON_WRITE_SIZE (sizeof(struct avalon_task)) 177 #define AVALON_READ_SIZE (sizeof(struct avalon_result)) 178 #define AVALON_ARRAY_SIZE 3 179 #define BITBURNER_ARRAY_SIZE 4 180 181 #define AVA_GETS_ERROR -1 182 #define AVA_GETS_OK 0 183 184 #define AVA_SEND_ERROR -1 185 #define AVA_SEND_OK 0 186 187 #define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon) 188 189 #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud)) 190 #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1] 191 ASSERT1(sizeof(uint32_t) == 4); 192 193 extern struct avalon_info **avalon_info; 194 extern int opt_avalon_temp; 195 extern int opt_avalon_overheat; 196 extern int opt_avalon_fan_min; 197 extern int opt_avalon_fan_max; 198 extern int opt_avalon_freq_min; 199 extern int opt_avalon_freq_max; 200 extern bool opt_avalon_auto; 201 extern int opt_bitburner_core_voltage; 202 extern int opt_bitburner_fury_core_voltage; 203 extern char *set_avalon_fan(char *arg); 204 extern char *set_avalon_freq(char *arg); 205 206 #endif /* USE_AVALON */ 207 #endif /* AVALON_H */