/ hf_protocol_be.h
hf_protocol_be.h
  1  //
  2  // Copyright 2013, 2014 HashFast Technologies LLC
  3  //
  4  // This program is free software; you can redistribute it and/or modify it
  5  // under the terms of the GNU General Public License as published by the Free
  6  // Software Foundation; either version 3 of the License, or (at your option)
  7  // any later version. See COPYING for more details.
  8  //
  9  // Big endian versions of packed structures
 10  //
 11  // Version 1.0
 12  //
 13  
 14  #ifndef _HF_PROTOCOL_BE_H_
 15  #define _HF_PROTOCOL_BE_H_
 16  
 17  // Generic header
 18  struct hf_header {
 19  	uint8_t  preamble;                      // Always 0xaa
 20  	uint8_t  operation_code;
 21  	uint8_t  chip_address;
 22  	uint8_t  core_address;
 23  	uint16_t hdata;                         // Header specific data
 24  	uint8_t  data_length;                   // .. of data frame to follow, in 4 byte blocks, 0=no data
 25  	uint8_t  crc8;                          // Computed across bytes 1-6 inclusive
 26  } __attribute__((packed,aligned(4)));           // 8 bytes total
 27  
 28  // Header specific to OP_PLL_CONFIG
 29  struct hf_pll_config {
 30  	uint8_t  preamble;
 31  	uint8_t  operation_code;
 32  	uint8_t  chip_address;
 33  
 34  	uint8_t  pll_reset:1;
 35  	uint8_t  pll_bypass:1;
 36  	uint8_t  pll_divr:6;
 37  
 38  	uint8_t  pll_divf;
 39  
 40  	uint8_t  pll_fse:1;                     // Must always be 1
 41  	uint8_t  pll_range:3;
 42  	uint8_t  pll_divq:3;
 43  	uint8_t  spare1:1;                      // Must always be 0
 44  
 45  	uint8_t  data_length;                   // Always 0
 46  	uint8_t  crc8;                          // Computed across bytes 1-6 inclusive
 47  } __attribute__((packed,aligned(4)));           // 8 bytes total
 48  
 49  // OP_HASH serial data
 50  struct hf_hash_serial {
 51  	uint8_t  midstate[32];                  // Computed from first half of block header
 52  	uint8_t  merkle_residual[4];            // From block header
 53  	uint32_t timestamp;                     // From block header
 54  	uint32_t bits;                          // Actual difficulty target for block header
 55  	uint32_t starting_nonce;                // Usually set to 0
 56  	uint32_t nonce_loops;                   // How many nonces to search, or 0 for 2^32
 57  	uint16_t ntime_loops;                   // How many times to roll timestamp, or 0
 58  	uint8_t  search_difficulty;             // Search difficulty to use, # of '0' digits required
 59  	uint8_t  option;
 60  	uint8_t  group;
 61  	uint8_t  spare3[3];
 62  } __attribute__((packed,aligned(4)));
 63  
 64  // OP_HASH usb data - header+data = 64 bytes
 65  struct hf_hash_usb {
 66  	uint8_t  midstate[32];                  // Computed from first half of block header
 67  	uint8_t  merkle_residual[4];            // From block header
 68  	uint32_t timestamp;                     // From block header
 69  	uint32_t bits;                          // Actual difficulty target for block header
 70  	uint32_t starting_nonce;                // Usually set to 0
 71  	uint32_t nonce_loops;                   // How many nonces to search, or 0 for 2^32
 72  	uint16_t ntime_loops;                   // How many times to roll timestamp, or 0
 73  	uint8_t  search_difficulty;             // Search difficulty to use, # of '0' digits required
 74  	uint8_t  group;                         // Non-zero for valid group
 75  } __attribute__((packed,aligned(4)));
 76  
 77  // OP_NONCE data
 78  struct hf_candidate_nonce {
 79  	uint32_t nonce;                         // Candidate nonce
 80  	uint16_t sequence;                      // Sequence number from corresponding OP_HASH
 81  	uint16_t ntime;                         // ntime offset, if ntime roll occurred, in LS 12 bits
 82  						// If b12 set, search forward next 128 nonces to find solution(s)
 83  } __attribute__((packed,aligned(4)));
 84  
 85  // OP_CONFIG data
 86  // This is usually internal data only, for serial drivers only
 87  // Users shouldn't normally need to interpret this, but in the event a Big Endian
 88  // user requires access to this data, the following structure will get all
 89  // the fields in the right place, but byte swaps will be required for the
 90  // uint16_t's and the uint32_t.
 91  struct hf_config_data {
 92  	uint16_t forward_all_privileged_packets:1;  // Forward priv pkts -- diagnostic
 93  	uint16_t pwm_active_level:1;                // Active level of PWM outputs, if used
 94  	uint16_t send_status_on_pending_empty:1;    // Schedule status whenever core pending goes idle
 95  	uint16_t send_status_on_core_idle:1;        // Schedule status whenever core goes idle
 96  	uint16_t enable_periodic_status:1;          // Send periodic status
 97  	uint16_t status_period:11;                  // Periodic status time, msec
 98  
 99  	uint8_t  status_batch_delay;                // Batching delay, time to wait before sending status
100  	uint8_t  disable_sensors:1;                 // Diagnostic
101  	uint8_t  watchdog:7;                        // Watchdog timeout, seconds
102  
103  	uint8_t  rx_ignore_header_crc:1;            // Ignore rx header crc's (diagnostic)
104  	uint8_t  rx_header_timeout:7;               // Header timeout in char times
105  	uint8_t  rx_ignore_data_crc:1;              // Ignore rx data crc's (diagnostic)
106  	uint8_t  rx_data_timeout:7;                 // Data timeout in char times / 16
107  	uint8_t  stat_diagnostic:1;                 // Never set this
108  	uint8_t  stats_interval:7;                  // Minimum interval to report statistics (seconds)
109  	uint8_t  measure_interval;                  // Die temperature measurement interval (msec)
110  
111  	uint32_t forward_all_packets:1;             // Forward everything - diagnostic.
112  	uint32_t clock_diagnostic:1;                // Never set this
113  	uint32_t trim:4;                            // Trim value for temperature measurements
114  	uint32_t pwm_phases:2;                      // phases - 1
115  	uint32_t voltage_sample_points:8;           // Bit mask for sample points (up to 5 bits set)
116  	uint32_t max_nonces_per_frame:4;            // Maximum # of nonces to combine in a single frame
117  	uint32_t one_usec:12;                       // How many LF clocks per usec.
118  
119  	uint16_t pwm_period;                        // Period of PWM outputs, in reference clock cycles
120  	uint16_t pwm_pulse_period;                  // Initial count, phase 0
121  } __attribute__((packed,aligned(4)));
122  
123  // OP_GROUP data
124  struct hf_group_data {
125  	uint16_t nonce_msoffset;                    // This value << 16 added to starting nonce
126  	uint16_t ntime_offset;                      // This value added to timestamp
127  } __attribute__((packed,aligned(4)));
128  
129  // Structure of the monitor fields for G-1, returned in OP_STATUS, core bitmap follows this
130  struct hf_g1_monitor { 
131  	uint16_t die_temperature;                   // Die temperature ADC count
132  	uint8_t  core_voltage[6];                   // Core voltage
133  						// [0] = main sensor
134  						// [1]-[5] = other positions
135  } __attribute__((packed,aligned(4)));
136  
137  // What comes back in the body of an OP_STATISTICS frame (On die statistics)
138  struct hf_statistics {
139  	uint8_t rx_header_crc;                      // Header CRC error's
140  	uint8_t rx_body_crc;                        // Data CRC error's
141  	uint8_t rx_header_timeouts;                 // Header timeouts
142  	uint8_t rx_body_timeouts;                   // Data timeouts
143  	uint8_t core_nonce_fifo_full;               // Core nonce Q overrun events
144  	uint8_t array_nonce_fifo_full;              // System nonce Q overrun events
145  	uint8_t stats_overrun;                      // Overrun in statistics reporting
146  	uint8_t spare;
147  } __attribute__((packed,aligned(4)));
148  
149  
150  ////////////////////////////////////////////////////////////////////////////////
151  // USB protocol data structures
152  ////////////////////////////////////////////////////////////////////////////////
153  
154  // Convenience header specific to OP_USB_INIT
155  struct hf_usb_init_header {
156  	uint8_t  preamble;                      // Always 0xaa
157  	uint8_t  operation_code;
158  	uint8_t  spare1;
159  
160  	uint8_t  shed_supported:1;              // Host supports gwq status shed_count
161  	uint8_t  do_atspeed_core_tests:1;       // Do core tests at speed, return second bitmap
162  	uint8_t  no_asic_initialization:1;      // Do not perform automatic ASIC initialization
163  	uint8_t  pll_bypass:1;                  // Force PLL bypass, hash clock = ref clock
164  	uint8_t  user_configuration:1;          // Use the following configuration data
165  	uint8_t  protocol:3;                    // Which protocol to use
166  
167  	uint16_t hash_clock;                    // Requested hash clock frequency
168  
169  	uint8_t  data_length;                   // .. of data frame to follow, in 4 byte blocks
170  	uint8_t  crc8;                          // Computed across bytes 1-6 inclusive
171  } __attribute__((packed,aligned(4)));           // 8 bytes total
172  
173  // Options (only if present) that may be appended to the above header
174  // Each option involving a numerical value will only be in effect if the value is non-zero
175  // This allows the user to select only those options desired for modification. Do not
176  // use this facility unless you are an expert - loading inconsistent settings will not work.
177  struct hf_usb_init_options {
178  	uint16_t group_ntime_roll;                  // Total ntime roll amount per group
179  	uint16_t core_ntime_roll;                   // Total core ntime roll amount
180  	uint8_t  low_operating_temp_limit;          // Lowest normal operating limit
181  	uint8_t  high_operating_temp_limit;         // Highest normal operating limit
182  	uint16_t spare;
183  } __attribute__((packed,aligned(4)));
184  
185  // Base item returned from device for OP_USB_INIT
186  struct hf_usb_init_base { 
187  	uint16_t firmware_rev;                      // Firmware revision #
188  	uint16_t hardware_rev;                      // Hardware revision #
189  	uint32_t serial_number;                     // Board serial number
190  	uint8_t  operation_status;                  // Reply status for OP_USB_INIT (0 = success)
191  	uint8_t  extra_status_1;                    // Extra reply status information, code specific
192  	uint16_t sequence_modulus;                  // Sequence numbers are to be modulo this
193  	uint16_t hash_clockrate;                    // Actual hash clock rate used (nearest Mhz)
194  	uint16_t inflight_target;                   // Target inflight amount for GWQ protocol
195  } __attribute__((packed,aligned(4)));
196  
197  // The above base item (16 bytes) is followed by the struct hf_config_data (16 bytes) actually
198  // used internally (so users may modify non-critical fields by doing subsequent
199  // OP_CONFIG operations). This is followed by a device specific "core good" bitmap (unless the
200  // user disabled initialization), and optionally by an at-speed "core good" bitmap.
201  
202  
203  // Information in an OP_DIE_STATUS frame. This is for one die - there are four per ASIC.
204  // Board level phase current and voltage sensors are likely to disappear in later production models.
205  struct hf_g1_die_data {
206  	struct hf_g1_monitor die;                   // Die sensors - 8 bytes
207  	uint16_t phase_currents[4];                 // Phase currents (0 if unavailable)
208  	uint16_t voltage;                           // Voltage at device boundary (0 if unavailable)
209  	uint16_t temperature;                       // Regulator temp sensor
210  	uint16_t tacho;                             // See documentation
211  	uint16_t spare;
212  } __attribute__((packed,aligned(4)));               // 24 bytes total
213  
214  // Information for an OP_GWQ_STATUS frame
215  // If sequence_head == sequence_tail, then there is no active work and sequence_head is invalid
216  struct hf_gwq_data {
217  	uint64_t hash_count;                        // Add this to host's cumulative hash count
218  	uint16_t sequence_head;                     // The latest, internal, active sequence #
219  	uint16_t sequence_tail;                     // The latest, internal, inactive sequence #
220  	uint16_t shed_count;                        // # of cores have been shedded for thermal control
221  	uint16_t spare;
222  } __attribute__((packed,aligned(4)));
223  
224  
225  // Information for an OP_USB_STATS1 frame - Communication statistics
226  struct hf_usb_stats1 {
227  	// USB incoming
228  	uint16_t usb_rx_preambles;
229  	uint16_t usb_rx_receive_byte_errors;
230  	uint16_t usb_rx_bad_hcrc;
231  
232  	// USB outgoing
233  	uint16_t usb_tx_attempts;
234  	uint16_t usb_tx_packets;
235  	uint16_t usb_tx_timeouts;
236  	uint16_t usb_tx_incompletes;
237  	uint16_t usb_tx_endpointstalled;
238  	uint16_t usb_tx_disconnected;
239  	uint16_t usb_tx_suspended;
240  
241  	// Internal UART transmit
242  	uint16_t uart_tx_queue_dma;
243  	uint16_t uart_tx_interrupts;
244  
245  	// Internal UART receive
246  	uint16_t uart_rx_preamble_ints;
247  	uint16_t uart_rx_missed_preamble_ints;
248  	uint16_t uart_rx_header_done;
249  	uint16_t uart_rx_data_done;
250  	uint16_t uart_rx_bad_hcrc;
251  	//uint16_t uart_rx_bad_crc32;
252  	uint16_t uart_rx_bad_dma;
253  	uint16_t uart_rx_short_dma;
254  	uint16_t uart_rx_buffers_full;
255  
256  	uint8_t  max_tx_buffers;                        // Maximum # of send buffers ever used
257  	uint8_t  max_rx_buffers;                        // Maximum # of receive buffers ever used
258  } __attribute__((packed,aligned(4)));
259  
260  // Information for an OP_USB_NOTICE frame
261  struct hf_usb_notice_data {
262  	uint32_t extra_data;                        // Depends on notification code
263  	char     message[];                         // NULL terminated, little endian byte order
264  };
265  
266  
267  #endif